-
Notifications
You must be signed in to change notification settings - Fork 84
/
epoch.py
41 lines (37 loc) · 2.2 KB
/
epoch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from hdmf.common.table import VectorData
from hdmf.common.io.table import DynamicTableMap
from .. import register_map
from pynwb.epoch import TimeIntervals
from pynwb.base import TimeSeriesReferenceVectorData
@register_map(TimeIntervals)
class TimeIntervalsMap(DynamicTableMap):
pass
@DynamicTableMap.constructor_arg('columns')
def columns_carg(self, builder, manager):
# handle the case when a TimeIntervals is read with a non-TimeSeriesReferenceVectorData "timeseries" column
# this is the case for NWB schema v2.4 and earlier, where the timeseries column was a regular VectorData.
timeseries_builder = builder.get('timeseries')
# if we have a timeseries column and the type is VectorData instead of TimeSeriesReferenceVectorData
if (timeseries_builder is not None and
timeseries_builder.attributes['neurodata_type'] != 'TimeSeriesReferenceVectorData'):
# override builder attributes
timeseries_builder.attributes['neurodata_type'] = 'TimeSeriesReferenceVectorData'
timeseries_builder.attributes['namespace'] = 'core'
# construct new columns list
columns = list()
for dset_builder in builder.datasets.values():
dset_obj = manager.construct(dset_builder) # these have already been constructed
# go through only the column datasets and replace the 'timeseries' column class in-place.
if isinstance(dset_obj, VectorData):
if dset_obj.name == 'timeseries':
# replacing the class in-place is possible because the VectorData and
# TimeSeriesReferenceVectorData have the same memory layout and the old and new
# schema are compatible (i.e., only the neurodata_type was changed in 2.5)
dset_obj.__class__ = TimeSeriesReferenceVectorData
# Execute init logic specific for TimeSeriesReferenceVectorData
dset_obj._init_internal()
columns.append(dset_obj)
# overwrite the columns constructor argument
return columns
# do not override
return None