Skip to content

Commit 4460a1b

Browse files
authored
Fix RoiResponseSeries dim warning and clarify other dim warnings (#1491)
* Fix incorrect warning #1490 * Print type and name of object when warning about dims
1 parent 18d4cad commit 4460a1b

File tree

9 files changed

+56
-34
lines changed

9 files changed

+56
-34
lines changed

CHANGELOG.md

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## PyNWB 2.1.0 (Upcoming)
44

55
### Breaking changes:
6-
- Raise a warning if `SpatialSeries.data` has more than 3 columns (#1455, #1480)
6+
- A warning is now raised if `SpatialSeries.data` has more than 3 columns. @bendichter, @rly (#1455, #1480)
77
- Updated ``TimeIntervals`` to use the new ``TimeSeriesReferenceVectorData`` type. This does not alter the overall
88
structure of ``TimeIntervals`` in a major way aside from changing the value of the ``neurodata_type`` attribute of the
99
``TimeIntervals.timeseries`` column from ``VectorData`` to ``TimeSeriesReferenceVectorData``. This change facilitates
@@ -26,30 +26,36 @@
2626
warnings when the constructor of a class mapped to an HDMF-common data type or an autogenerated data type class
2727
is passed positional arguments instead of all keyword arguments. @rly (#1484)
2828
- Moved logic that checks the 0th dimension of TimeSeries data equals the length of timestamps to a private method in the
29-
``TimeSeries`` class. This is to avoid raising a warning when an ImageSeries is used with external file. @weiglszonja (#1486)
29+
``TimeSeries`` class. This is to avoid raising a warning when an ImageSeries is used with external file.
30+
@weiglszonja (#1486)
31+
- Improved warning text when dimensions are not matched in `TimeSeries`, `ElectricalSeries`, and `RoiResponseSeries`.
32+
@rly (#1491)
3033

3134
### Documentation and tutorial enhancements:
3235
- Added tutorial on annotating data via ``TimeIntervals``. @oruebel (#1390)
33-
- Add copy button to code blocks @weiglszonja (#1460)
34-
- Create behavioral tutorial @weiglszonja (#1464)
35-
- Enhance display of icephys pandas tutorial by using ``dataframe_image`` to render and display large tables
36+
- Added copy button to code blocks @weiglszonja (#1460)
37+
- Created behavioral tutorial @weiglszonja (#1464)
38+
- Enhanced display of icephys pandas tutorial by using ``dataframe_image`` to render and display large tables
3639
as images. @oruebel (#1469)
37-
- Create tutorial about reading and exploring an existing `NWBFile` @weiglszonja (#1453)
40+
- Created tutorial about reading and exploring an existing `NWBFile` @weiglszonja (#1453)
3841
- Added new logo for PyNWB. @oruebel (#1461)
3942
- Minor text fixes. @oruebel @bendichter (#1443, #1462, #1463, #1466, #1472, #1473)
4043

4144
### Bug fixes:
4245
- Fixed input data types to allow only `float` for fields `conversion` and `offset` in definition of
4346
``TimeSeries``. @codycbakerphd (#1424)
47+
- Fixed incorrect warning in `RoiResponseSeries.__init__` about mismatch between the second dimension of data and
48+
the length of rois. @rly (#1491)
4449

4550

4651
## PyNWB 2.0.1 (March 16, 2022)
4752

4853
### Bug fixes:
49-
- Add `environment-ros3.yml` to `MANIFEST.in` for inclusion in source distributions. @rly (#1398)
50-
- Fix bad error check in ``IntracellularRecordingsTable.add_recording`` when adding ``IZeroClampSeries``. @oruebel (#1410)
51-
- Skip ros3 tests if internet access or the ros3 driver are not available. @oruebel (#1414)
52-
- Fix CI issues. @rly (#1427)
54+
- Added `environment-ros3.yml` to `MANIFEST.in` for inclusion in source distributions. @rly (#1398)
55+
- Fixed bad error check in ``IntracellularRecordingsTable.add_recording`` when adding ``IZeroClampSeries``.
56+
@oruebel (#1410)
57+
- Skipped ros3 tests if internet access or the ros3 driver are not available. @oruebel (#1414)
58+
- Fixed CI issues. @rly (#1427)
5359

5460
### Documentation and tutorial enhancements:
5561
- Enhanced ordering of sphinx gallery tutorials to use alphabetic ordering based on tutorial headings. @oruebel (#1399)
@@ -66,8 +72,8 @@
6672
- Minor text fixes. @bendichter (#1437, #1400)
6773

6874
### Minor improvements:
69-
- Improve constructor docstrings for Image types. @weiglszonja (#1418)
70-
- Add checks for data orientation in ``TimeSeries``, ``ElectricalSeries``, and ``RoiResponseSeries`` @bendichter (#1428)
75+
- Improved constructor docstrings for Image types. @weiglszonja (#1418)
76+
- Added checks for data orientation in ``TimeSeries``, ``ElectricalSeries``, and ``RoiResponseSeries`` @bendichter (#1428)
7177
- Added checks for data orientation in ``TimeSeries``, ``ElectricalSeries``, and ``RoiResponseSeries``.
7278
@bendichter (#1426)
7379
- Enhanced issue template forms on GitHub. @CodyCBakerPHD (#1434)

src/pynwb/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ def __init__(self, **kwargs):
190190
raise TypeError("either 'timestamps' or 'rate' must be specified")
191191

192192
if not self._check_time_series_dimension():
193-
warn("Length of data does not match length of timestamps. Your data may be transposed. Time should be on "
194-
"the 0th dimension")
193+
warn("%s '%s': Length of data does not match length of timestamps. Your data may be transposed. "
194+
"Time should be on the 0th dimension" % (self.__class__.__name__, self.name))
195195

196196
def _check_time_series_dimension(self):
197197
"""Check that the 0th dimension of data equals the length of timestamps, when applicable.

src/pynwb/ecephys.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,12 @@ def __init__(self, **kwargs):
8585
and data_shape[1] != len(args_to_set['electrodes'].data)
8686
):
8787
if data_shape[0] == len(args_to_set['electrodes'].data):
88-
warnings.warn("The second dimension of data does not match the length of electrodes, but instead the "
89-
"first does. Data is oriented incorrectly and should be transposed.")
88+
warnings.warn("%s '%s': The second dimension of data does not match the length of electrodes, "
89+
"but instead the first does. Data is oriented incorrectly and should be transposed."
90+
% (self.__class__.__name__, kwargs["name"]))
9091
else:
91-
warnings.warn("The second dimension of data does not match the length of electrodes. Your data may be "
92-
"transposed.")
92+
warnings.warn("%s '%s': The second dimension of data does not match the length of electrodes. "
93+
"Your data may be transposed." % (self.__class__.__name__, kwargs["name"]))
9394

9495
kwargs['unit'] = 'volts' # fixed value
9596
super().__init__(**kwargs)

src/pynwb/image.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ def __init__(self, **kwargs):
8181

8282
if not self._check_image_series_dimension():
8383
warnings.warn(
84-
"Length of data does not match length of timestamps. "
85-
"Your data may be transposed. Time should be on the 0th dimension"
84+
"%s '%s': Length of data does not match length of timestamps. Your data may be transposed. "
85+
"Time should be on the 0th dimension" % (self.__class__.__name__, self.name)
8686
)
8787

8888
def _check_time_series_dimension(self):

src/pynwb/ophys.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -354,14 +354,15 @@ def __init__(self, **kwargs):
354354
# check that key dimensions are known
355355
and data_shape[1] is not None and rois_shape[0] is not None
356356

357-
and data_shape[1] != rois_shape
357+
and data_shape[1] != rois_shape[0]
358358
):
359359
if data_shape[0] == rois_shape[0]:
360-
warnings.warn("The second dimension of data does not match the length of rois, but instead the "
361-
"first does. Data is oriented incorrectly and should be transposed.")
360+
warnings.warn("%s '%s': The second dimension of data does not match the length of rois, "
361+
"but instead the first does. Data is oriented incorrectly and should be transposed."
362+
% (self.__class__.__name__, kwargs["name"]))
362363
else:
363-
warnings.warn("The second dimension of data does not match the length of rois. Your data may be "
364-
"transposed.")
364+
warnings.warn("%s '%s': The second dimension of data does not match the length of rois. "
365+
"Your data may be transposed." % (self.__class__.__name__, kwargs["name"]))
365366
super().__init__(**kwargs)
366367
self.rois = rois
367368

tests/unit/test_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ def test_conflicting_time_args(self):
375375

376376
def test_dimension_warning(self):
377377
msg = (
378-
"Length of data does not match length of timestamps. Your data may be "
378+
"TimeSeries 'test_ts2': Length of data does not match length of timestamps. Your data may be "
379379
"transposed. Time should be on the 0th dimension"
380380
)
381381
with self.assertWarnsWith(UserWarning, msg):

tests/unit/test_ecephys.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ def test_dimensions_warning(self):
8585
)
8686
self.assertEqual(len(w), 1)
8787
assert (
88-
"The second dimension of data does not match the length of electrodes. Your data may be transposed."
88+
"ElectricalSeries 'test_ts1': The second dimension of data does not match the length of electrodes. "
89+
"Your data may be transposed."
8990
) in str(w[-1].message)
9091

9192
with warnings.catch_warnings(record=True) as w:
@@ -99,8 +100,8 @@ def test_dimensions_warning(self):
99100
)
100101
self.assertEqual(len(w), 1)
101102
assert (
102-
"The second dimension of data does not match the length of electrodes, but instead the first does. Data "
103-
"is oriented incorrectly and should be transposed."
103+
"ElectricalSeries 'test_ts1': The second dimension of data does not match the length of electrodes, "
104+
"but instead the first does. Data is oriented incorrectly and should be transposed."
104105
) in str(w[-1].message)
105106

106107

tests/unit/test_image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def test_dimension_warning(self):
7979
"""Test that a warning is raised when the dimensions of the data are not the
8080
same as the dimensions of the timestamps."""
8181
msg = (
82-
"Length of data does not match length of timestamps. Your data may be "
82+
"ImageSeries 'test_iS': Length of data does not match length of timestamps. Your data may be "
8383
"transposed. Time should be on the 0th dimension"
8484
)
8585
with self.assertWarnsWith(UserWarning, msg):

tests/unit/test_ophys.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,19 @@ def test_init(self):
294294

295295
def test_warnings(self):
296296
ps = create_plane_segmentation()
297-
rt_region = ps.create_roi_table_region(description='the second ROI', region=[0, 1])
297+
rt_region = ps.create_roi_table_region(description='the first two ROIs', region=[0, 1])
298+
299+
with warnings.catch_warnings(record=True) as w:
300+
# Cause all warnings to always be triggered.
301+
warnings.simplefilter("always")
302+
RoiResponseSeries(
303+
name="test_ts1",
304+
data=np.ones((6, 2)),
305+
rois=rt_region,
306+
rate=30000.,
307+
unit="n.a.",
308+
)
309+
self.assertEqual(w, [])
298310

299311
with warnings.catch_warnings(record=True) as w:
300312
# Cause all warnings to always be triggered.
@@ -308,7 +320,8 @@ def test_warnings(self):
308320
)
309321
self.assertEqual(len(w), 1)
310322
assert (
311-
"The second dimension of data does not match the length of rois. Your data may be transposed."
323+
"RoiResponseSeries 'test_ts1': The second dimension of data does not match the length of rois. "
324+
"Your data may be transposed."
312325
) in str(w[-1].message)
313326

314327
with warnings.catch_warnings(record=True) as w:
@@ -323,8 +336,8 @@ def test_warnings(self):
323336
)
324337
self.assertEqual(len(w), 1)
325338
assert (
326-
"The second dimension of data does not match the length of rois, but instead the first does. "
327-
"Data is oriented incorrectly and should be transposed."
339+
"RoiResponseSeries 'test_ts1': The second dimension of data does not match the length of rois, "
340+
"but instead the first does. Data is oriented incorrectly and should be transposed."
328341
) in str(w[-1].message)
329342

330343

0 commit comments

Comments
 (0)