Skip to content

Commit

Permalink
[BC] fixed bugs in unit actualization for derivate/integrate
Browse files Browse the repository at this point in the history
  • Loading branch information
helene-t committed Oct 26, 2021
1 parent 5dfe21f commit 425e3b5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
6 changes: 6 additions & 0 deletions SciDataTool/Functions/conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down
2 changes: 0 additions & 2 deletions SciDataTool/Functions/omp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

from SciDataTool.Classes.Data1D import Data1D

import numpy as np
Expand Down
4 changes: 2 additions & 2 deletions SciDataTool/Methods/DataND/get_data_along.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 9 additions & 2 deletions Tests/Validation/test_get_data_along.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 425e3b5

Please sign in to comment.