1- from hdmf .utils import docval , popargs , get_docval
1+ import warnings
2+
3+ from hdmf .utils import docval , popargs , get_docval , get_data_shape
24
35from . import register_class , CORE_NAMESPACE
46from .core import MultiContainerInterface
@@ -21,9 +23,7 @@ class SpatialSeries(TimeSeries):
2123 __nwbfields__ = ('reference_frame' ,)
2224
2325 @docval (* get_docval (TimeSeries .__init__ , 'name' ), # required
24- {'name' : 'data' , 'type' : ('array_data' , 'data' , TimeSeries ), 'shape' : (
25- (None , ), (None , 1 ), (None , 2 ), (None , 3 )
26- ), # required
26+ {'name' : 'data' , 'type' : ('array_data' , 'data' , TimeSeries ), 'shape' : ((None , ), (None , None )), # required
2727 'doc' : ('The data values. Can be 1D or 2D. The first dimension must be time. If 2D, there can be 1, 2, '
2828 'or 3 columns, which represent x, y, and z.' )},
2929 {'name' : 'reference_frame' , 'type' : str , # required
@@ -38,8 +38,26 @@ def __init__(self, **kwargs):
3838 """
3939 name , data , reference_frame , unit = popargs ('name' , 'data' , 'reference_frame' , 'unit' , kwargs )
4040 super (SpatialSeries , self ).__init__ (name , data , unit , ** kwargs )
41+
42+ # NWB 2.5 restricts length of second dimension to be <= 3
43+ allowed_data_shapes = ((None , ), (None , 1 ), (None , 2 ), (None , 3 ))
44+ data_shape = get_data_shape (data )
45+ if not any (self ._validate_data_shape (data_shape , a ) for a in allowed_data_shapes ):
46+ warnings .warn ("SpatialSeries '%s' has data shape %s which is not compliant with NWB 2.5 and greater. "
47+ "The second dimension should have length <= 3 to represent at most x, y, z." %
48+ (name , str (data_shape )))
49+
4150 self .reference_frame = reference_frame
4251
52+ @staticmethod
53+ def _validate_data_shape (valshape , argshape ):
54+ if not len (valshape ) == len (argshape ):
55+ return False
56+ for a , b in zip (valshape , argshape ):
57+ if b not in (a , None ):
58+ return False
59+ return True
60+
4361
4462@register_class ('BehavioralEpochs' , CORE_NAMESPACE )
4563class BehavioralEpochs (MultiContainerInterface ):
0 commit comments