Skip to content

Commit a8349ec

Browse files
Merge pull request #144 from NeurodataWithoutBorders/fix_session_start_time_bug
[Bug]: session_start_time not readable
2 parents 63b2d85 + f9794e9 commit a8349ec

File tree

7 files changed

+21
-34
lines changed

7 files changed

+21
-34
lines changed

nwbinspector/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
from .checks.time_series import *
77
from .checks.tables import *
88
from .checks.ecephys import *
9+
from .checks.ogen import *

nwbinspector/nwbinspector.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ def inspect_all(
276276
importlib.import_module(module)
277277
# Filtering of checks should apply after external modules are imported, in case those modules have their own checks
278278
checks = configure_checks(config=config, ignore=ignore, select=select, importance_threshold=importance_threshold)
279-
280279
if n_jobs != 1:
281280

282281
# max_workers for threading is a different concept to number of processes; from the documentation

nwbinspector/register_checks.py

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@
66
from typing import Optional
77

88
import h5py
9+
from pynwb import NWBFile
10+
from pynwb.file import Subject
11+
from pynwb.ecephys import Device, ElectrodeGroup
12+
13+
KNOWN_LOCATIONS = {
14+
NWBFile: "/",
15+
Subject: "/subject",
16+
Device: "/general/devices",
17+
ElectrodeGroup: "/general/extracellular_ephys/",
18+
# TODO: add ophys equivalents
19+
}
920

1021

1122
class Importance(Enum):
@@ -71,7 +82,7 @@ class InspectorMessage:
7182
check_function_name: str = ""
7283
object_type: str = ""
7384
object_name: str = ""
74-
location: str = ""
85+
location: Optional[str] = None
7586
file_path: str = ""
7687

7788

@@ -154,7 +165,7 @@ def auto_parse(check_function, obj, result: Optional[InspectorMessage] = None):
154165
return auto_parsed_result
155166

156167

157-
def parse_location(neurodata_object) -> str:
168+
def parse_location(neurodata_object) -> Optional[str]:
158169
"""Infer the human-readable path of the object within an NWBFile by tracing its parents."""
159170
if neurodata_object.parent is None:
160171
return "/"
@@ -165,22 +176,4 @@ def parse_location(neurodata_object) -> str:
165176
for field in neurodata_object.fields.values():
166177
if isinstance(field, h5py.Dataset):
167178
return "/".join(field.parent.name.split("/")[:-1]) + "/"
168-
try:
169-
# General case for nested modules not containing Datasets
170-
level = neurodata_object
171-
level_names = []
172-
while level.parent.name != "root":
173-
level_names.append(level.parent.name)
174-
level = level.parent
175-
# Determine which field of the NWBFile contains the previous recent level
176-
invalid_field_names = ["timestamps_reference_time", "session_start_time"]
177-
possible_fields = level.parent.fields
178-
for field_name in invalid_field_names:
179-
if field_name in possible_fields:
180-
possible_fields.pop(field_name)
181-
for field_name, field in possible_fields.items():
182-
if level.name in field:
183-
level_names.append(field_name)
184-
return "/" + "/".join(level_names[::-1]) + "/"
185-
except Exception:
186-
return ""
179+
return KNOWN_LOCATIONS.get(type(neurodata_object))

tests/test_inspector.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616
check_regular_timestamps,
1717
check_data_orientation,
1818
check_timestamps_match_first_dimension,
19+
check_session_start_time_old_date,
20+
check_description,
21+
available_checks,
1922
)
20-
from nwbinspector.nwbinspector import inspect_all, inspect_nwb, configure_checks
23+
from nwbinspector.nwbinspector import inspect_all, inspect_nwb
2124
from nwbinspector.register_checks import Severity, InspectorMessage, register_check
2225
from nwbinspector.utils import FilePathType
2326
from nwbinspector.tools import make_minimal_nwbfile
@@ -402,7 +405,6 @@ def iterable_check_function(table: DynamicTable):
402405
check_function_name="iterable_check_function",
403406
object_type="TimeIntervals",
404407
object_name="test_table",
405-
location="/acquisition/",
406408
file_path=self.nwbfile_paths[0],
407409
),
408410
InspectorMessage(
@@ -411,7 +413,6 @@ def iterable_check_function(table: DynamicTable):
411413
check_function_name="iterable_check_function",
412414
object_type="TimeIntervals",
413415
object_name="test_table",
414-
location="/acquisition/",
415416
file_path=self.nwbfile_paths[0],
416417
),
417418
]

tests/unit_tests/test_ecephys.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ def test_check_electrical_series_wrong_dims(self):
8989
check_function_name="check_electrical_series_dims",
9090
object_type="ElectricalSeries",
9191
object_name="elec_series",
92-
location="/acquisition/",
9392
)
9493

9594
def test_check_electrical_series_flipped(self):
@@ -112,7 +111,6 @@ def test_check_electrical_series_flipped(self):
112111
check_function_name="check_electrical_series_dims",
113112
object_type="ElectricalSeries",
114113
object_name="elec_series",
115-
location="/acquisition/",
116114
)
117115

118116
def test_pass(self):
@@ -138,7 +136,6 @@ def test_trigger_check_electrical_series_reference_electrodes_table(self):
138136
dyn_tab.add_column("name", "desc")
139137
for i in range(5):
140138
dyn_tab.add_row(name=1)
141-
142139
dynamic_table_region = DynamicTableRegion(
143140
name="electrodes", description="I am wrong", data=[0, 1, 2, 3, 4], table=dyn_tab
144141
)

tests/unit_tests/test_nwbfile_metadata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def test_check_subject_sex():
204204
check_function_name="check_subject_sex",
205205
object_type="Subject",
206206
object_name="subject",
207-
location="",
207+
location="/subject",
208208
)
209209

210210

tests/unit_tests/test_ophys.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
check_roi_response_series_dims,
1212
check_roi_response_series_link_to_plane_segmentation,
1313
)
14-
from nwbinspector.register_checks import InspectorMessage, Importance, Severity
14+
from nwbinspector.register_checks import InspectorMessage, Importance
1515

1616

1717
class TestCheckRoiResponseSeries(TestCase):
@@ -84,7 +84,6 @@ def test_check_flipped_dims(self):
8484
check_function_name="check_roi_response_series_dims",
8585
object_type="RoiResponseSeries",
8686
object_name="RoiResponseSeries",
87-
location="/processing/ophys/",
8887
)
8988

9089
def test_check_wrong_dims(self):
@@ -110,7 +109,6 @@ def test_check_wrong_dims(self):
110109
check_function_name="check_roi_response_series_dims",
111110
object_type="RoiResponseSeries",
112111
object_name="RoiResponseSeries",
113-
location="/processing/ophys/",
114112
)
115113

116114
def test_pass_check_roi_response_series_dims(self):
@@ -134,7 +132,6 @@ def test_check_roi_response_series_link_to_plane_segmentation(self):
134132
dt.add_column("a", "desc")
135133
for _ in range(5):
136134
dt.add_row(a=1)
137-
138135
dtr = DynamicTableRegion(name="n", description="desc", data=[0, 1, 2, 3, 4], table=dt)
139136
roi_resp_series = RoiResponseSeries(
140137
name="RoiResponseSeries",
@@ -152,7 +149,6 @@ def test_check_roi_response_series_link_to_plane_segmentation(self):
152149
check_function_name="check_roi_response_series_link_to_plane_segmentation",
153150
object_type="RoiResponseSeries",
154151
object_name="RoiResponseSeries",
155-
location="/processing/ophys/",
156152
)
157153

158154
def test_pass_check_roi_response_series_link_to_plane_segmentation(self):

0 commit comments

Comments
 (0)