NeurodataWithoutBorders / pynwb

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

Can't read electrode table #737

Closed VBaratham closed 5 years ago

VBaratham commented 5 years ago

After writing a file containing a dataset with an 'electrodes' attribute, then reading the file back from disk, trying to do anything with the 'electrodes' attribute of the dataset throws an error:

Traceback (most recent call last):
  File "electrodes_mwe.py", line 41, in <module>
    print(electrodes.fields)
  File "/home/vyassa/src/pynwb/src/pynwb/core.py", line 150, in __repr__
    template += "  {}: {} \n".format(k, self.__smart_str(v))
  File "/home/vyassa/src/pynwb/src/pynwb/core.py", line 175, in __smart_str
    return str(np.array(v))
  File "/home/vyassa/src/pynwb/src/pynwb/core.py", line 289, in __getitem__
    return self.data[args]
  File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
  File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
  File "/home/vyassa/anaconda2/envs/mars/lib/python3.5/site-packages/h5py/_hl/dataset.py", line 476, in __getitem__
    selection = sel.select(self.shape, args, dsid=self.id)
  File "/home/vyassa/anaconda2/envs/mars/lib/python3.5/site-packages/h5py/_hl/selections.py", line 94, in select
    sel[args]
  File "/home/vyassa/anaconda2/envs/mars/lib/python3.5/site-packages/h5py/_hl/selections.py", line 261, in __getitem__
    start, count, step, scalar = _handle_simple(self.shape,args)
  File "/home/vyassa/anaconda2/envs/mars/lib/python3.5/site-packages/h5py/_hl/selections.py", line 451, in _handle_simple
    x,y,z = _translate_int(int(arg), length)
  File "/home/vyassa/anaconda2/envs/mars/lib/python3.5/site-packages/h5py/_hl/selections.py", line 471, in _translate_int
    raise ValueError("Index (%s) out of range (0-%s)" % (exp, length-1))
ValueError: Index (2) out of range (0-1)

Steps to Reproduce

from pynwb import NWBFile, NWBHDF5IO                                                                                  
from pynwb.ecephys import ElectricalSeries, LFP                                                                       
from datetime import datetime                                                                                         
import numpy as np                                                                                                    

nwb = NWBFile(                                                                                                        
    session_description='foo',                                                                                        
    identifier='Simulation_v0',                                                                                       
    session_start_time=datetime.now(),                                                                                
    file_create_date=datetime.now(),                                                                                  
    experimenter='asdf',                                                                                              
    experiment_description='adsf',                                                                                    
    session_id='Simulation_v0',                                                                                       
    institution='wqre',                                                                                               
    lab='sdfpo',                                                                                                      
    pharmacology='dskoe',                                                                                             
    notes='kdoe',                                                                                                     
    surgery='dkoie'                                                                                                   
)                                                                                                                     

device = nwb.create_device(name='testdevice')                                                                         
e_group = nwb.create_electrode_group(name='devicename', description='', location='', device=device)                   
electrode = nwb.add_electrode(0, x=.0, y=0.0, z=0.0, imp=1.0, location='0', filtering='Low pass', group=e_group)      
electrode = nwb.add_electrode(1, x=.0, y=0.0, z=1.0, imp=1.0, location='1', filtering='Low pass', group=e_group)      
e_region = nwb.create_electrode_table_region(region=[0], description='')                                              

raw_data = np.ones(shape=(100, 1))                                                                                    
raw_e_series = ElectricalSeries(name='testdevice', data=raw_data, electrodes=e_region, starting_time=0.0, rate=1000.0\
)                                                                                                                     
nwb.add_acquisition(LFP(name='Raw'))                                                                                  
nwb.acquisition['Raw'].add_electrical_series(raw_e_series)                                                            

io = NWBHDF5IO('electrodes_mwe.nwb', 'w')                                                                             
io.write(nwb)                                                                                                         
io.close()                                                                                                            

io = NWBHDF5IO('electrodes_mwe.nwb', 'a')                                                                             
nwb = io.read()                                                                                                       

electrodes = nwb.acquisition['Raw']['testdevice'].electrodes                                                          
print(electrodes.fields)  

Environment

Checklist

bendichter commented 5 years ago

Hey @VBaratham thanks for the the bug report. This is actually an issue with printing the table after reading it. We fixed the bug here https://github.com/NeurodataWithoutBorders/pynwb/pull/736 and I'll cut a new release as soon as it is incorporated.

bendichter commented 5 years ago

duplicate of #734