Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: TimeSeries.__init__: incorrect shape for 'timestamps' (got '(2, 356918)', expected '(None,)') #1775

Open
3 tasks done
sayali7 opened this issue Sep 16, 2023 · 2 comments
Labels
category: question questions about code or code behavior

Comments

@sayali7
Copy link

sayali7 commented Sep 16, 2023

What happened?

Hi,
I was trying to load .nwb file and I'm unable to open it because of the following error:

ValueError: TimeSeries.__init__: incorrect shape for 'timestamps' (got '(2, 356918)', expected '(None,)')

I saw an earlier post about this here ([https://github.com//issues/1180]), but I didn't find the solution.

Steps to Reproduce

from pynwb import NWBHDF5IO, NWBFile

io = NWBHDF5IO("./mouse485342.spikes.nwb", mode="r", load_namespaces=True)
nwbfile = io.read()

Traceback

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
~/.local/lib/python3.10/site-packages/hdmf/build/objectmapper.py in construct(self, **kwargs)
   1255         try:
-> 1256             obj = self.__new_container__(cls, builder.source, parent, builder.attributes.get(self.__spec.id_key()),
   1257                                          **kwargs)

~/.local/lib/python3.10/site-packages/hdmf/build/objectmapper.py in __new_container__(self, cls, container_source, parent, object_id, **kwargs)
   1268         # the automatic construct process during read, rather than by the user
-> 1269         obj.__init__(**kwargs)
   1270         obj._in_construct_mode = False  # reset to False to indicate that the construction of the object is complete

~/.local/lib/python3.10/site-packages/hdmf/utils.py in func_call(*args, **kwargs)
    642             def func_call(*args, **kwargs):
--> 643                 pargs = _check_args(args, kwargs)
    644                 return func(args[0], **pargs)

~/.local/lib/python3.10/site-packages/hdmf/utils.py in _check_args(args, kwargs)
    635                     msg = '%s: %s' % (func.__qualname__, ', '.join(parse_err))
--> 636                     raise ExceptionType(msg)
    637 

ValueError: TimeSeries.__init__: incorrect shape for 'timestamps' (got '(2, 356918)', expected '(None,)')

The above exception was the direct cause of the following exception:

ConstructError                            Traceback (most recent call last)
/tmp/ipykernel_13858/3106899465.py in <module>
      1 io = NWBHDF5IO("./mouse485342.spikes.nwb", mode="r", load_namespaces=True)
----> 2 nwbfile = io.read()

~/.local/lib/python3.10/site-packages/hdmf/backends/hdf5/h5tools.py in read(self, **kwargs)
    477                                        % (self.source, self.__mode))
    478         try:
--> 479             return super().read(**kwargs)
    480         except UnsupportedOperation as e:
    481             if str(e) == 'Cannot build data. There are no values.':  # pragma: no cover

~/.local/lib/python3.10/site-packages/hdmf/utils.py in func_call(*args, **kwargs)
    642             def func_call(*args, **kwargs):
    643                 pargs = _check_args(args, kwargs)
--> 644                 return func(args[0], **pargs)
    645         else:
    646             def func_call(*args, **kwargs):

~/.local/lib/python3.10/site-packages/hdmf/backends/io.py in read(self, **kwargs)
     58             # TODO also check that the keys are appropriate. print a better error message
     59             raise UnsupportedOperation('Cannot build data. There are no values.')
---> 60         container = self.__manager.construct(f_builder)
     61         container.read_io = self
     62         if self.herd_path is not None:

~/.local/lib/python3.10/site-packages/hdmf/utils.py in func_call(*args, **kwargs)
    642             def func_call(*args, **kwargs):
    643                 pargs = _check_args(args, kwargs)
--> 644                 return func(args[0], **pargs)
    645         else:
    646             def func_call(*args, **kwargs):

~/.local/lib/python3.10/site-packages/hdmf/build/manager.py in construct(self, **kwargs)
    282                 # we are at the top of the hierarchy,
    283                 # so it must be time to resolve parents
--> 284                 result = self.__type_map.construct(builder, self, None)
    285                 self.__resolve_parents(result)
    286             self.prebuilt(result, builder)

~/.local/lib/python3.10/site-packages/hdmf/utils.py in func_call(*args, **kwargs)
    642             def func_call(*args, **kwargs):
    643                 pargs = _check_args(args, kwargs)
--> 644                 return func(args[0], **pargs)
    645         else:
    646             def func_call(*args, **kwargs):

~/.local/lib/python3.10/site-packages/hdmf/build/manager.py in construct(self, **kwargs)
    793             raise ValueError('No ObjectMapper found for builder of type %s' % dt)
    794         else:
--> 795             return obj_mapper.construct(builder, build_manager, parent)
    796 
    797     @docval({"name": "container", "type": AbstractContainer, "doc": "the container to convert to a Builder"},

~/.local/lib/python3.10/site-packages/hdmf/utils.py in func_call(*args, **kwargs)
    642             def func_call(*args, **kwargs):
    643                 pargs = _check_args(args, kwargs)
--> 644                 return func(args[0], **pargs)
    645         else:
    646             def func_call(*args, **kwargs):

~/.local/lib/python3.10/site-packages/hdmf/build/objectmapper.py in construct(self, **kwargs)
   1224         cls = manager.get_cls(builder)
   1225         # gather all subspecs
-> 1226         subspecs = self.__get_subspec_values(builder, self.spec, manager)
   1227         # get the constructor argument that each specification corresponds to
   1228         const_args = dict()

~/.local/lib/python3.10/site-packages/hdmf/build/objectmapper.py in __get_subspec_values(self, builder, spec, manager)
   1153                         ret[subspec] = self.__flatten(sub_builder, subspec, manager)
   1154             # now process groups and datasets
-> 1155             self.__get_sub_builders(groups, spec.groups, manager, ret)
   1156             self.__get_sub_builders(datasets, spec.datasets, manager, ret)
   1157         elif isinstance(spec, DatasetSpec):

~/.local/lib/python3.10/site-packages/hdmf/build/objectmapper.py in __get_sub_builders(self, sub_builders, subspecs, manager, ret)
   1204                 if dt is None:
   1205                     # recurse
-> 1206                     ret.update(self.__get_subspec_values(sub_builder, subspec, manager))
   1207                 else:
   1208                     ret[subspec] = manager.construct(sub_builder)

~/.local/lib/python3.10/site-packages/hdmf/build/objectmapper.py in __get_subspec_values(self, builder, spec, manager)
   1153                         ret[subspec] = self.__flatten(sub_builder, subspec, manager)
   1154             # now process groups and datasets
-> 1155             self.__get_sub_builders(groups, spec.groups, manager, ret)
   1156             self.__get_sub_builders(datasets, spec.datasets, manager, ret)
   1157         elif isinstance(spec, DatasetSpec):

~/.local/lib/python3.10/site-packages/hdmf/build/objectmapper.py in __get_sub_builders(self, sub_builders, subspecs, manager, ret)
   1196                 sub_builder = builder_dt.get(dt)
   1197                 if sub_builder is not None:
-> 1198                     sub_builder = self.__flatten(sub_builder, subspec, manager)
   1199                     ret[subspec] = sub_builder
   1200             else:

~/.local/lib/python3.10/site-packages/hdmf/build/objectmapper.py in __flatten(self, sub_builder, subspec, manager)
   1209 
   1210     def __flatten(self, sub_builder, subspec, manager):
-> 1211         tmp = [manager.construct(b) for b in sub_builder]
   1212         if len(tmp) == 1 and not subspec.is_many():
   1213             tmp = tmp[0]

~/.local/lib/python3.10/site-packages/hdmf/build/objectmapper.py in <listcomp>(.0)
   1209 
   1210     def __flatten(self, sub_builder, subspec, manager):
-> 1211         tmp = [manager.construct(b) for b in sub_builder]
   1212         if len(tmp) == 1 and not subspec.is_many():
   1213             tmp = tmp[0]

~/.local/lib/python3.10/site-packages/hdmf/utils.py in func_call(*args, **kwargs)
    642             def func_call(*args, **kwargs):
    643                 pargs = _check_args(args, kwargs)
--> 644                 return func(args[0], **pargs)
    645         else:
    646             def func_call(*args, **kwargs):

~/.local/lib/python3.10/site-packages/hdmf/build/manager.py in construct(self, **kwargs)
    278             if parent_builder is not None:
    279                 parent = self._get_proxy_builder(parent_builder)
--> 280                 result = self.__type_map.construct(builder, self, parent)
    281             else:
    282                 # we are at the top of the hierarchy,

~/.local/lib/python3.10/site-packages/hdmf/utils.py in func_call(*args, **kwargs)
    642             def func_call(*args, **kwargs):
    643                 pargs = _check_args(args, kwargs)
--> 644                 return func(args[0], **pargs)
    645         else:
    646             def func_call(*args, **kwargs):

~/.local/lib/python3.10/site-packages/hdmf/build/manager.py in construct(self, **kwargs)
    793             raise ValueError('No ObjectMapper found for builder of type %s' % dt)
    794         else:
--> 795             return obj_mapper.construct(builder, build_manager, parent)
    796 
    797     @docval({"name": "container", "type": AbstractContainer, "doc": "the container to convert to a Builder"},

~/.local/lib/python3.10/site-packages/hdmf/utils.py in func_call(*args, **kwargs)
    642             def func_call(*args, **kwargs):
    643                 pargs = _check_args(args, kwargs)
--> 644                 return func(args[0], **pargs)
    645         else:
    646             def func_call(*args, **kwargs):

~/.local/lib/python3.10/site-packages/hdmf/build/objectmapper.py in construct(self, **kwargs)
   1224         cls = manager.get_cls(builder)
   1225         # gather all subspecs
-> 1226         subspecs = self.__get_subspec_values(builder, self.spec, manager)
   1227         # get the constructor argument that each specification corresponds to
   1228         const_args = dict()

~/.local/lib/python3.10/site-packages/hdmf/build/objectmapper.py in __get_subspec_values(self, builder, spec, manager)
   1153                         ret[subspec] = self.__flatten(sub_builder, subspec, manager)
   1154             # now process groups and datasets
-> 1155             self.__get_sub_builders(groups, spec.groups, manager, ret)
   1156             self.__get_sub_builders(datasets, spec.datasets, manager, ret)
   1157         elif isinstance(spec, DatasetSpec):

~/.local/lib/python3.10/site-packages/hdmf/build/objectmapper.py in __get_sub_builders(self, sub_builders, subspecs, manager, ret)
   1196                 sub_builder = builder_dt.get(dt)
   1197                 if sub_builder is not None:
-> 1198                     sub_builder = self.__flatten(sub_builder, subspec, manager)
   1199                     ret[subspec] = sub_builder
   1200             else:

~/.local/lib/python3.10/site-packages/hdmf/build/objectmapper.py in __flatten(self, sub_builder, subspec, manager)
   1209 
   1210     def __flatten(self, sub_builder, subspec, manager):
-> 1211         tmp = [manager.construct(b) for b in sub_builder]
   1212         if len(tmp) == 1 and not subspec.is_many():
   1213             tmp = tmp[0]

~/.local/lib/python3.10/site-packages/hdmf/build/objectmapper.py in <listcomp>(.0)
   1209 
   1210     def __flatten(self, sub_builder, subspec, manager):
-> 1211         tmp = [manager.construct(b) for b in sub_builder]
   1212         if len(tmp) == 1 and not subspec.is_many():
   1213             tmp = tmp[0]

~/.local/lib/python3.10/site-packages/hdmf/utils.py in func_call(*args, **kwargs)
    642             def func_call(*args, **kwargs):
    643                 pargs = _check_args(args, kwargs)
--> 644                 return func(args[0], **pargs)
    645         else:
    646             def func_call(*args, **kwargs):

~/.local/lib/python3.10/site-packages/hdmf/build/manager.py in construct(self, **kwargs)
    278             if parent_builder is not None:
    279                 parent = self._get_proxy_builder(parent_builder)
--> 280                 result = self.__type_map.construct(builder, self, parent)
    281             else:
    282                 # we are at the top of the hierarchy,

~/.local/lib/python3.10/site-packages/hdmf/utils.py in func_call(*args, **kwargs)
    642             def func_call(*args, **kwargs):
    643                 pargs = _check_args(args, kwargs)
--> 644                 return func(args[0], **pargs)
    645         else:
    646             def func_call(*args, **kwargs):

~/.local/lib/python3.10/site-packages/hdmf/build/manager.py in construct(self, **kwargs)
    793             raise ValueError('No ObjectMapper found for builder of type %s' % dt)
    794         else:
--> 795             return obj_mapper.construct(builder, build_manager, parent)
    796 
    797     @docval({"name": "container", "type": AbstractContainer, "doc": "the container to convert to a Builder"},

~/.local/lib/python3.10/site-packages/hdmf/utils.py in func_call(*args, **kwargs)
    642             def func_call(*args, **kwargs):
    643                 pargs = _check_args(args, kwargs)
--> 644                 return func(args[0], **pargs)
    645         else:
    646             def func_call(*args, **kwargs):

~/.local/lib/python3.10/site-packages/hdmf/build/objectmapper.py in construct(self, **kwargs)
   1258         except Exception as ex:
   1259             msg = 'Could not construct %s object due to: %s' % (cls.__name__, ex)
-> 1260             raise ConstructError(builder, msg) from ex
   1261         return obj
   1262 

ConstructError: (root/processing/running/running_speed GroupBuilder {'attributes': {'comments': 'no comments', 'description': 'no description', 'help': 'General time series object', 'namespace': 'core', 'neurodata_type': 'TimeSeries'}, 'groups': {}, 'datasets': {'data': root/processing/running/running_speed/data DatasetBuilder {'attributes': {'conversion': 1.0, 'resolution': 0.0, 'unit': 'cm/s'}, 'data': <HDF5 dataset "data": shape (356918,), type "<f8">}, 'timestamps': root/processing/running/running_speed/timestamps DatasetBuilder {'attributes': {'interval': 1, 'unit': 'Seconds'}, 'data': <HDF5 dataset "timestamps": shape (2, 356918), type "<f8">}}, 'links': {}}, "Could not construct TimeSeries object due to: TimeSeries.__init__: incorrect shape for 'timestamps' (got '(2, 356918)', expected '(None,)')")

Operating System

Linux

Python Executable

Python

Python Version

3.10

Package Versions

pynwb: 2.5.0
hdmf: 3.9.0

Code of Conduct

@rly
Copy link
Contributor

rly commented Sep 17, 2023

@sayali7 Where did this NWB file come from? The timestamps field should be one dimensional, not two dimensional, so the file is not a valid NWB file.

@sayali7
Copy link
Author

sayali7 commented Sep 17, 2023

@rly The data was published with this 2021 paper, and can be downloaded from here. I tried reading the file called "mouse485342.spikes.nwb". I am not sure how else to read this data, if you have any alternative suggestions I would greatly appreciate it.

Thanks!

@stephprince stephprince added the category: question questions about code or code behavior label Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: question questions about code or code behavior
Projects
None yet
Development

No branches or pull requests

3 participants