NeurodataWithoutBorders / pynwb

A Python API for working with Neurodata stored in the NWB Format
https://pynwb.readthedocs.io
Other
177 stars 84 forks source link

`RuntimeError: Unable to resolve reference` with `NWBHDF5IO.write` #939

Closed lungsi closed 5 years ago

lungsi commented 5 years ago

1) Bug

mynwbfile looks like this

root <class 'pynwb.file.NWBFile'>                                                                  
Fields:                                                                                            
  acquisition: { DummyTest_axon <class 'pynwb.base.TimeSeries'>,  DummyTest_soma <class 'pynwb.base.TimeSeries'> }                                                                                    
  analysis: { }                                                                                    
  devices: { }                                                                                     
  electrode_groups: { }                                                                            
  epoch_tags: {'0', '1', '2_epoch_responses', 'DummyTest', 'axon', 'cells', 'epoch0axon', 'epoch0soma', 'epoch1axon', 'epoch1soma', 'soma'}                                                           
  epochs: epochs <class 'pynwb.epoch.TimeIntervals'>                                               
  experiment_description: described experiment/test description                                    
  experimenter: name of the experimenter/username                                                  
  ic_electrodes: { }                                                                               
  imaging_planes: { }                                                                              
  institution: name of the institution                                                             
  lab: name of the lab                                                                             
  lab_meta_data: { }                                                                               
  modules: { }                                                                                     
  ogen_sites: { }                                                                                  
  session_id: 2520542702082615599                                                                  
  stimulus: { DummyTest_stimulus <class 'pynwb.base.TimeSeries'> }                                 
  stimulus_template: { }                                                 
  time_intervals: { }

I can access data from mynwbfile.

Following io = NWBHDF5IO("test.h5", mode="w") doing io.write(mynwbfile) results in

Traceback (most recent call last):                                                                 
  File "test.py", line 799, in test_nwb
  io.write(mynwbfile)                                                                                                                      
  File "/envs/py27/local/lib/python2.7/site-packages/hdmf/utils.py", line 388, in func_call return func(self, **parsed['args'])                                                            
  File "/envs/py27/local/lib/python2.7/site-packages/hdmf/backends/hdf5/h5tools.py", line 196, in write call_docval_func(super(HDF5IO, self).write, kwargs)                                            
  File "/envs/py27/local/lib/python2.7/site-packages/hdmf/utils.py", line 281, in call_docval_func return func(*fargs, **fkwargs)                                                                 
  File "/envs/py27/local/lib/python2.7/site-packages/hdmf/utils.py", line 388, in func_call return func(self, **parsed['args'])                                                            
  File "/envs/py27/local/lib/python2.7/site-packages/hdmf/backends/io.py", line 40, in write self.write_builder(f_builder, **kwargs)                                                        
  File "/envs/py27/local/lib/python2.7/site-packages/hdmf/utils.py", line 388, in func_call return func(self, **parsed['args'])                                                            
  File "/envs/py27/local/lib/python2.7/site-packages/hdmf/backends/hdf5/h5tools.py", line 416, in write_builder self.__add_refs()
  File "/envs/py27/local/lib/python2.7/site-packages/hdmf/backends/hdf5/h5tools.py", line 434, in __add_refs raise RuntimeError('Unable to resolve reference')                                              
RuntimeError: Unable to resolve reference

Environment

Please describe your environment according to the following bullet points.

bendichter commented 5 years ago

@lungsi It's going to be hard to diagnose this without more information. Could you please include either a minimal script to generate the NWB file or a link to the file on google drive or similar?

lungsi commented 5 years ago

I think I might have found out the cause for the error.

In mynwbfile above the TimeSeries objects for the epochs are not the same as those located in those available under .acquisition. Instead, the TimeSeries object I have associated with the epochs are a snippet.

When I try to write mynwbfile but pass the whole TimeSeries rather than its snippet, I don't get the above RuntimeError: Unable to resolve reference and the file get written.

I guess that means the TimeSeries associated with an epoch must be same as one of the TimeSeries available in .acquisitions. It cannot be a snippet. Am I right?

bendichter commented 5 years ago

Yes, that's right. In fact, pynwb automatically forms a link from the epochs table to the TimeSeries objects it references instead of storing that TimeSeries object twice, so these is no need to store snippets.

ajtritt commented 5 years ago

Also, the TimeSeries don't need to be .acquisitions, they can be from any part of the file.