diff --git a/SciDataTool/Functions/conversions.py b/SciDataTool/Functions/conversions.py index 6de552dd..4aba5f44 100644 --- a/SciDataTool/Functions/conversions.py +++ b/SciDataTool/Functions/conversions.py @@ -110,8 +110,11 @@ def get_dim_prefix(unit_str): def get_unit_derivate(unit_str, axis_unit): + unit_str = unit_str.replace("*", "").replace(" ", "").replace("^", "") if axis_unit == "Hz": axis_unit = "s" + if axis_unit == "rad": + axis_unit = "m" p = 0 if "/" in unit_str: unit_num = unit_str.split("/")[0] @@ -153,8 +156,11 @@ def get_unit_derivate(unit_str, axis_unit): def get_unit_integrate(unit_str, axis_unit): + unit_str = unit_str.replace("*", "").replace(" ", "").replace("^", "") if axis_unit == "Hz": axis_unit = "s" + if axis_unit == "rad": + axis_unit = "m" p = 0 if "/" in unit_str: unit_num = unit_str.split("/")[0] diff --git a/SciDataTool/Functions/omp.py b/SciDataTool/Functions/omp.py index e45ae889..d73e8c54 100644 --- a/SciDataTool/Functions/omp.py +++ b/SciDataTool/Functions/omp.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from SciDataTool.Classes.Data1D import Data1D import numpy as np diff --git a/SciDataTool/Methods/DataND/get_data_along.py b/SciDataTool/Methods/DataND/get_data_along.py index 4f2eadcb..2197800f 100644 --- a/SciDataTool/Methods/DataND/get_data_along.py +++ b/SciDataTool/Methods/DataND/get_data_along.py @@ -87,9 +87,9 @@ def get_data_along(self, *args, unit="SI", is_norm=False, axis_data=[]): unit = self.unit for axis in axes_list: if axis.extension in ["antiderivate", "integrate"]: - unit = get_unit_integrate(self.unit, axis.corr_unit) + unit = get_unit_integrate(unit, axis.corr_unit) elif axis.extension == "derivate": - unit = get_unit_derivate(self.unit, axis.corr_unit) + unit = get_unit_derivate(unit, axis.corr_unit) return DataClass( name=self.name, diff --git a/Tests/Validation/test_get_data_along.py b/Tests/Validation/test_get_data_along.py index 23132eff..1b4696cf 100644 --- a/Tests/Validation/test_get_data_along.py +++ b/Tests/Validation/test_get_data_along.py @@ -183,6 +183,13 @@ def test_get_data_along_integrate(): assert_array_almost_equal(Field_rms.values, A / np.sqrt(2), decimal=15) assert Field_rms.unit == "m" + Field.unit = "N/m^2" + Time.unit = "m" + Field_int = Field.get_data_along("time=integrate", "angle=integrate") + assert Field_int.unit == "N" + Time.unit = "s" + Field.unit = "m" + # Anti-periodic signal Time0 = Time.get_axis_periodic(Nper=1, is_aper=True) ta0, at0 = np.meshgrid(Time0.get_values(is_smallestperiod=True), Angle.get_values()) @@ -310,7 +317,7 @@ def test_get_data_along_antiderivate(): # Angle derivation Field_anti_a = Field.get_data_along("time", "angle=antiderivate") - assert Field_anti_a.unit == "mrad", "wrong unit: " + Field_anti_a.unit + assert Field_anti_a.unit == "m2", "wrong unit: " + Field_anti_a.unit field_anti_a_check = Field_anti_a.values field_anti_a_ref = 5 / 3 * np.sin(2 * np.pi * f * ta.T + 3 * at.T) assert_array_almost_equal(field_anti_a_check, field_anti_a_ref, decimal=3) @@ -374,7 +381,7 @@ def test_get_data_along_derivate(): # Angle derivation Field_diff_a = Field.get_data_along("time", "angle=derivate") - assert Field_diff_a.unit == "m/rad" + assert Field_diff_a.unit == "" field_diff_a_check = Field_diff_a.values field_diff_a_ref = -5 * 3 * np.sin(2 * np.pi * f * ta.T + 3 * at.T) assert_array_almost_equal(field_diff_a_check, field_diff_a_ref, decimal=1)