Skip to content

Commit

Permalink
Fix channel_conversion use in TimeSeries.get_data_in_units (#1923)
Browse files Browse the repository at this point in the history
* fix channel_conversion in TimeSeries get_data_in_units

* update CHANGELOG

* simply loop range
  • Loading branch information
rohanshah authored Jun 26, 2024
1 parent 90e6048 commit 9a46106
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
- Simplified the introduction to NWB tutorial. @rly [#1914](https://github.com/NeurodataWithoutBorders/pynwb/pull/1914)
- Simplified the ecephys and ophys tutorials. [#1915](https://github.com/NeurodataWithoutBorders/pynwb/pull/1915)

### Bug fixes
- Fixed use of `channel_conversion` in `TimeSeries` `get_data_in_units`. @rohanshah [1923](https://github.com/NeurodataWithoutBorders/pynwb/pull/1923)


## PyNWB 2.8.0 (May 28, 2024)

Expand Down
2 changes: 1 addition & 1 deletion src/pynwb/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def get_data_in_units(self):
"""
if "channel_conversion" in self.fields:
scale_factor = self.conversion * self.channel_conversion[:, np.newaxis]
scale_factor = self.conversion * self.channel_conversion
else:
scale_factor = self.conversion
return np.asarray(self.data) * scale_factor + self.offset
Expand Down
18 changes: 11 additions & 7 deletions tests/unit/test_ecephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,22 +117,26 @@ def test_dimensions_warning(self):
) in str(w[-1].message)

def test_get_data_in_units(self):

data = np.asarray([[1, 1, 1, 1, 1], [1, 1, 1, 1, 1]])
conversion = 1.0
samples = 100
channels = 2
conversion = 10.0
offset = 3.0
channel_conversion = np.asarray([2.0, 2.0])
channel_conversion = np.random.rand(channels)

electrical_series = mock_ElectricalSeries(
data=data,
data=np.ones((samples, channels)),
conversion=conversion,
offset=offset,
channel_conversion=channel_conversion,
)

data_in_units = electrical_series.get_data_in_units()
expected_data = data * conversion * channel_conversion[:, np.newaxis] + offset

np.testing.assert_almost_equal(data_in_units, expected_data)
for channel_index in range(channels):
np.testing.assert_almost_equal(
data_in_units[:, channel_index],
np.ones(samples) * conversion * channel_conversion[channel_index] + offset
)


class SpikeEventSeriesConstructor(TestCase):
Expand Down

0 comments on commit 9a46106

Please sign in to comment.