Skip to content

Commit

Permalink
Handle scaled scaling status
Browse files Browse the repository at this point in the history
When the scaling status is scaled, scaling has
already been applied so should not be applied again.
  • Loading branch information
adamreeve committed Apr 1, 2020
1 parent 1833970 commit 0f64f1f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions nptdms/scaling.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,10 @@ def _get_channel_scaling(properties):
num_scalings = _get_number_of_scalings(properties)
if num_scalings is None or num_scalings == 0:
return None
scaling_status = properties.get("NI_Scaling_Status", "unscaled")
if scaling_status == "scaled":
# Data is written with scaling already applied
return None

scalings = [None] * num_scalings
for scale_index in range(num_scalings):
Expand Down
15 changes: 15 additions & 0 deletions nptdms/test/test_scaling.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def test_linear_scaling():
expected_scaled_data = np.array([12.0, 14.0, 16.0])

properties = {
"NI_Scaling_Status": "unscaled",
"NI_Number_Of_Scales": 1,
"NI_Scale[0]_Scale_Type": "Linear",
"NI_Scale[0]_Linear_Slope": 2.0,
Expand Down Expand Up @@ -454,6 +455,20 @@ def test_scaling_from_root():
np.testing.assert_almost_equal(expected_scaled_data, scaled_data)


def test_scaling_status_scaled():
""" When the scaling status is scaled, data is already scaled so scaling should not be applied
"""
properties = {
"NI_Number_Of_Scales": 1,
"NI_Scale[0]_Scale_Type": "Linear",
"NI_Scale[0]_Linear_Slope": 2.0,
"NI_Scale[0]_Linear_Y_Intercept": 10.0,
"NI_Scaling_Status": "scaled",
}
scaling = get_scaling(properties, {}, {})
assert scaling is None


class StubTdmsData(object):
def __init__(self, data):
self.data = data
Expand Down

0 comments on commit 0f64f1f

Please sign in to comment.