From 7b73185129831770a8c54ed59f88536004f3cfcd Mon Sep 17 00:00:00 2001 From: Ryan Ly Date: Tue, 1 Oct 2024 12:23:57 -0700 Subject: [PATCH] Add "bounds" to SpatialSeries fields (#1907) --- CHANGELOG.md | 8 +++++++- docs/gallery/domain/plot_behavior.py | 4 ++-- src/pynwb/behavior.py | 10 ++++++---- src/pynwb/nwb-schema | 2 +- tests/integration/hdf5/test_behavior.py | 2 +- tests/unit/test_behavior.py | 4 ++-- 6 files changed, 19 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5909f577..b12defa2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # PyNWB Changelog +## PyNWB 3.0.0 (Upcoming) + +### Enhancements and minor changes +- Added support for NWB schema 2.8.0: + - Fixed support for `data__bounds` field to `SpatialSeries` to set optional boundary range (min, max) for each dimension of data. Removed `SpatialSeries.bounds` field that was not functional. @rly [#1907](https://github.com/NeurodataWithoutBorders/pynwb/pull/1907) + ## PyNWB 2.8.3 (Upcoming) ### Performance @@ -43,7 +49,7 @@ ## PyNWB 2.7.0 (May 2, 2024) ### Enhancements and minor changes -- Added `bounds` field to `SpatialSeries` to set optional boundary range (min, max) for each dimension of data. @mavaylon1 [#1869](https://github.com/NeurodataWithoutBorders/pynwb/pull/1869/files) +- Added `bounds` field to `SpatialSeries` to set optional boundary range (min, max) for each dimension of data. @mavaylon1 [#1869](https://github.com/NeurodataWithoutBorders/pynwb/pull/1869) - Added support for NWB schema 2.7.0. See [2.7.0 release notes](https://nwb-schema.readthedocs.io/en/latest/format_release_notes.html) for details - Deprecated `ImagingRetinotopy` neurodata type. @rly [#1813](https://github.com/NeurodataWithoutBorders/pynwb/pull/1813) - Modified `OptogeneticSeries` to allow 2D data, primarily in extensions of `OptogeneticSeries`. @rly [#1812](https://github.com/NeurodataWithoutBorders/pynwb/pull/1812) diff --git a/docs/gallery/domain/plot_behavior.py b/docs/gallery/domain/plot_behavior.py index 35fbae81f..8d5b38d2a 100644 --- a/docs/gallery/domain/plot_behavior.py +++ b/docs/gallery/domain/plot_behavior.py @@ -105,7 +105,7 @@ # # For position data ``reference_frame`` indicates the zero-position, e.g. # the 0,0 point might be the bottom-left corner of an enclosure, as viewed from the tracking camera. -# In :py:class:`~pynwb.behavior.SpatialSeries`, the ``bounds`` field allows the user to set +# In :py:class:`~pynwb.behavior.SpatialSeries`, the ``data__bounds`` field allows the user to set # the boundary range, i.e., (min, max), for each dimension of ``data``. The units are the same as in ``data``. # This field does not enforce a boundary on the dataset itself. @@ -115,7 +115,7 @@ name="SpatialSeries", description="Position (x, y) in an open field.", data=position_data, - bounds=[(0,50), (0,50)], + data__bounds=[(0,50), (0,50)], timestamps=timestamps, reference_frame="(0,0) is bottom left corner", ) diff --git a/src/pynwb/behavior.py b/src/pynwb/behavior.py index 1b3078535..432a86891 100644 --- a/src/pynwb/behavior.py +++ b/src/pynwb/behavior.py @@ -20,13 +20,13 @@ class SpatialSeries(TimeSeries): tracking camera. The unit of data will indicate how to interpret SpatialSeries values. """ - __nwbfields__ = ('reference_frame',) + __nwbfields__ = ('data__bounds', 'reference_frame',) @docval(*get_docval(TimeSeries.__init__, 'name'), # required {'name': 'data', 'type': ('array_data', 'data', TimeSeries), 'shape': ((None, ), (None, None)), # required 'doc': ('The data values. Can be 1D or 2D. The first dimension must be time. If 2D, there can be 1, 2, ' 'or 3 columns, which represent x, y, and z.')}, - {'name': 'bounds', 'type': list, 'shape': ((1, 2), (2, 2), (3, 2)), 'default': None, + {'name': 'data__bounds', 'type': ('data', 'array_data'), 'shape': ((1, 2), (2, 2), (3, 2)), 'default': None, 'doc': 'The boundary range (min, max) for each dimension of data.'}, {'name': 'reference_frame', 'type': str, # required 'doc': 'description defining what the zero-position is'}, @@ -38,7 +38,9 @@ def __init__(self, **kwargs): """ Create a SpatialSeries TimeSeries dataset """ - name, data, bounds, reference_frame, unit = popargs('name', 'data', 'bounds', 'reference_frame', 'unit', kwargs) + name, data, data__bounds, reference_frame, unit = popargs( + 'name', 'data', 'data__bounds', 'reference_frame', 'unit', kwargs + ) super().__init__(name, data, unit, **kwargs) # NWB 2.5 restricts length of second dimension to be <= 3 @@ -49,7 +51,7 @@ def __init__(self, **kwargs): "The second dimension should have length <= 3 to represent at most x, y, z." % (name, str(data_shape))) - self.bounds = bounds + self.data__bounds = data__bounds self.reference_frame = reference_frame @staticmethod diff --git a/src/pynwb/nwb-schema b/src/pynwb/nwb-schema index d65d42257..942672b61 160000 --- a/src/pynwb/nwb-schema +++ b/src/pynwb/nwb-schema @@ -1 +1 @@ -Subproject commit d65d42257003543c569ea7ac0cd6d7aee01c88d6 +Subproject commit 942672b613204d885d1c901f7f5fe996b9216925 diff --git a/tests/integration/hdf5/test_behavior.py b/tests/integration/hdf5/test_behavior.py index d4b230bcc..1525c43c9 100644 --- a/tests/integration/hdf5/test_behavior.py +++ b/tests/integration/hdf5/test_behavior.py @@ -11,7 +11,7 @@ def setUpContainer(self): return SpatialSeries( name='test_sS', data=np.ones((3, 2)), - bounds=[(-1,1),(-1,1),(-1,1)], + data__bounds=[(-1,1),(-1,1),(-1,1)], reference_frame='reference_frame', timestamps=[1., 2., 3.] ) diff --git a/tests/unit/test_behavior.py b/tests/unit/test_behavior.py index 6bcf1a9eb..4d30ca57d 100644 --- a/tests/unit/test_behavior.py +++ b/tests/unit/test_behavior.py @@ -12,13 +12,13 @@ def test_init(self): sS = SpatialSeries( name='test_sS', data=np.ones((3, 2)), - bounds=[(-1,1),(-1,1),(-1,1)], + data__bounds=[(-1,1),(-1,1),(-1,1)], reference_frame='reference_frame', timestamps=[1., 2., 3.] ) self.assertEqual(sS.name, 'test_sS') self.assertEqual(sS.unit, 'meters') - self.assertEqual(sS.bounds, [(-1,1),(-1,1),(-1,1)]) + self.assertEqual(sS.data__bounds, [(-1,1),(-1,1),(-1,1)]) self.assertEqual(sS.reference_frame, 'reference_frame') def test_set_unit(self):