Skip to content

Commit 7bd72bb

Browse files
authored
Fix missing invalid time intervals (#1069)
* Refactor and clean up NWBFile IO mapper * Map invalid times * Map timestamps interval * Add invalid times test
1 parent 425dc57 commit 7bd72bb

File tree

3 files changed

+46
-14
lines changed

3 files changed

+46
-14
lines changed

src/pynwb/io/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ def __init__(self, spec):
2727
self.map_spec('unit', data_spec.get_attribute('unit'))
2828
self.map_spec('resolution', data_spec.get_attribute('resolution'))
2929
self.map_spec('conversion', data_spec.get_attribute('conversion'))
30+
3031
timestamps_spec = self.spec.get_dataset('timestamps')
3132
self.map_spec('timestamps_unit', timestamps_spec.get_attribute('unit'))
33+
self.map_spec('interval', timestamps_spec.get_attribute('interval'))
34+
3235
startingtime_spec = self.spec.get_dataset('starting_time')
3336
self.map_spec('starting_time_unit', startingtime_spec.get_attribute('unit'))
3437
self.map_spec('rate', startingtime_spec.get_attribute('rate'))

src/pynwb/io/file.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,43 @@ def __init__(self, spec):
1313

1414
acq_spec = self.spec.get_group('acquisition')
1515
self.unmap(acq_spec)
16-
raw_ts_spec = acq_spec.get_neurodata_type('NWBDataInterface')
17-
self.map_spec('acquisition', raw_ts_spec)
16+
self.map_spec('acquisition', acq_spec.get_neurodata_type('NWBDataInterface'))
17+
1818
self.map_spec('analysis', self.spec.get_group('analysis').get_neurodata_type('NWBContainer'))
1919

20+
# map constructor arg and property 'stimulus' -> stimulus__presentation
2021
stimulus_spec = self.spec.get_group('stimulus')
2122
self.unmap(stimulus_spec)
2223
self.map_spec('stimulus', stimulus_spec.get_group('presentation').get_neurodata_type('TimeSeries'))
2324
self.map_spec('stimulus_template', stimulus_spec.get_group('templates').get_neurodata_type('TimeSeries'))
2425

2526
intervals_spec = self.spec.get_group('intervals')
27+
self.map_spec('intervals', intervals_spec.get_neurodata_type('TimeIntervals'))
28+
2629
epochs_spec = intervals_spec.get_group('epochs')
2730
self.map_spec('epochs', epochs_spec)
31+
2832
trials_spec = intervals_spec.get_group('trials')
2933
self.map_spec('trials', trials_spec)
30-
self.map_spec('intervals', intervals_spec.get_neurodata_type('TimeIntervals'))
34+
35+
invalid_times_spec = intervals_spec.get_group('invalid_times')
36+
self.map_spec('invalid_times', invalid_times_spec)
3137

3238
general_spec = self.spec.get_group('general')
39+
3340
icephys_spec = general_spec.get_group('intracellular_ephys')
3441
self.map_spec('ic_electrodes', icephys_spec.get_neurodata_type('IntracellularElectrode'))
35-
ecephys_spec = general_spec.get_group('extracellular_ephys')
3642
self.map_spec('sweep_table', icephys_spec.get_neurodata_type('SweepTable'))
43+
44+
ecephys_spec = general_spec.get_group('extracellular_ephys')
3745
self.map_spec('electrodes', ecephys_spec.get_group('electrodes'))
3846
self.map_spec('electrode_groups', ecephys_spec.get_neurodata_type('ElectrodeGroup'))
39-
self.map_spec(
40-
'ogen_sites',
41-
general_spec.get_group('optogenetics').get_neurodata_type('OptogeneticStimulusSite'))
42-
self.map_spec(
43-
'imaging_planes',
44-
general_spec.get_group('optophysiology').get_neurodata_type('ImagingPlane'))
47+
48+
self.map_spec('ogen_sites',
49+
general_spec.get_group('optogenetics').get_neurodata_type('OptogeneticStimulusSite'))
50+
51+
self.map_spec('imaging_planes',
52+
general_spec.get_group('optophysiology').get_neurodata_type('ImagingPlane'))
4553

4654
general_datasets = ['data_collection',
4755
'experiment_description',
@@ -62,17 +70,18 @@ def __init__(self, spec):
6270
for dataset_name in general_datasets:
6371
self.map_spec(dataset_name, general_spec.get_dataset(dataset_name))
6472

65-
proc_spec = self.spec.get_group('processing')
66-
self.unmap(proc_spec)
67-
self.map_spec('processing', proc_spec.get_neurodata_type('ProcessingModule'))
68-
# self.unmap(general_spec.get_dataset('stimulus'))
73+
# note: constructor arg and property 'stimulus' is already mapped above, so use a different name here
6974
self.map_spec('stimulus_notes', general_spec.get_dataset('stimulus'))
7075
self.map_spec('source_script_file_name', general_spec.get_dataset('source_script').get_attribute('file_name'))
7176

7277
self.map_spec('subject', general_spec.get_group('subject'))
7378
self.map_spec('devices', general_spec.get_group('devices').get_neurodata_type('Device'))
7479
self.map_spec('lab_meta_data', general_spec.get_neurodata_type('LabMetaData'))
7580

81+
proc_spec = self.spec.get_group('processing')
82+
self.unmap(proc_spec)
83+
self.map_spec('processing', proc_spec.get_neurodata_type('ProcessingModule'))
84+
7685
scratch_spec = self.spec.get_group('scratch')
7786
self.unmap(scratch_spec)
7887
self.map_spec('scratch_datas', scratch_spec.get_neurodata_type('ScratchData'))

tests/integration/ui_write/test_core.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,26 @@ def getContainer(self, nwbfile):
2727
return nwbfile.trials
2828

2929

30+
class TestInvalidTimes(base.TestMapRoundTrip):
31+
32+
def setUpContainer(self):
33+
# this will get ignored
34+
return DynamicTable('trials', 'a placeholder table')
35+
36+
def addContainer(self, nwbfile):
37+
nwbfile.add_invalid_times_column('foo', 'an int column')
38+
nwbfile.add_invalid_times_column('bar', 'a float column')
39+
nwbfile.add_invalid_times_column('baz', 'a string column')
40+
nwbfile.add_invalid_times_column('qux', 'a boolean column')
41+
nwbfile.add_invalid_time_interval(start_time=0., stop_time=1., foo=27, bar=28.0, baz="29", qux=True)
42+
nwbfile.add_invalid_time_interval(start_time=2., stop_time=3., foo=37, bar=38.0, baz="39", qux=False)
43+
# reset the thing
44+
self.container = nwbfile.invalid_times
45+
46+
def getContainer(self, nwbfile):
47+
return nwbfile.invalid_times
48+
49+
3050
class TestUnits(base.TestMapRoundTrip):
3151

3252
def setUpContainer(self):

0 commit comments

Comments
 (0)