Skip to content

Commit 16fc13d

Browse files
Merge pull request #207 from NeurodataWithoutBorders/check_angle
check CompassDirection angle
2 parents 9a736d8 + 4d38a35 commit 16fc13d

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

nwbinspector/checks/behavior.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Checks for types belonging to the pynwb.behavior module."""
2-
from pynwb.behavior import SpatialSeries
2+
from pynwb.behavior import SpatialSeries, CompassDirection
33

44
from ..register_checks import register_check, Importance, InspectorMessage
55

@@ -11,3 +11,13 @@ def check_spatial_series_dims(spatial_series: SpatialSeries):
1111
return InspectorMessage(
1212
message="SpatialSeries should have 1 column (x), 2 columns (x, y), or 3 columns (x, y, z)."
1313
)
14+
15+
16+
@register_check(importance=Importance.BEST_PRACTICE_VIOLATION, neurodata_type=SpatialSeries)
17+
def check_compass_direction_unit(compass_direction: CompassDirection):
18+
for spatial_series in compass_direction.spatial_series.values():
19+
if spatial_series.unit not in ("degrees", "radians"):
20+
yield InspectorMessage(
21+
message=f"SpatialSeries objects inside a CompassDirection object should be angular and should have a "
22+
f"unit of 'degrees' or 'radians', but '{spatial_series.name}' has units '{spatial_series.unit}'."
23+
)

tests/unit_tests/test_behavior.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
from pynwb.behavior import SpatialSeries
1+
from pynwb.behavior import SpatialSeries, CompassDirection
22
import numpy as np
33

4-
from nwbinspector import InspectorMessage, Importance, check_spatial_series_dims
4+
from nwbinspector import InspectorMessage, Importance
5+
from nwbinspector.checks.behavior import check_compass_direction_unit, check_spatial_series_dims
56

67

78
def test_check_spatial_series_dims():
@@ -47,3 +48,36 @@ def test_pass_check_spatial_series_dims_1d():
4748
)
4849

4950
assert check_spatial_series_dims(spatial_series) is None
51+
52+
53+
def test_trigger_check_compass_direction_unit():
54+
obj = CompassDirection(
55+
spatial_series=SpatialSeries(
56+
name="SpatialSeries",
57+
description="description",
58+
data=np.ones((10,)),
59+
rate=3.0,
60+
reference_frame="reference_frame",
61+
)
62+
)
63+
64+
assert (
65+
check_compass_direction_unit(obj)[0].message == f"SpatialSeries objects inside a CompassDirection object "
66+
f"should be angular and should have a unit of 'degrees' or 'radians', but 'SpatialSeries' has units 'meters'."
67+
)
68+
69+
70+
def test_pass_check_compass_direction_unit():
71+
for unit in ("radians", "degrees"):
72+
obj = CompassDirection(
73+
spatial_series=SpatialSeries(
74+
name="SpatialSeries",
75+
description="description",
76+
data=np.ones((10,)),
77+
rate=3.0,
78+
reference_frame="reference_frame",
79+
unit=unit,
80+
)
81+
)
82+
83+
assert check_compass_direction_unit(obj) is None

0 commit comments

Comments
 (0)