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

Unable to create some NWB objects and documentation / call mismatch #27

Closed ajtritt closed 7 years ago

ajtritt commented 7 years ago

Originally reported by: Loren Frank (Bitbucket: lmfrnk, GitHub: Unknown)


The call to create an interval series now requires a data element, but the documentation only specifies a name and a source.

In addition, with a data element specified, I now get the following error:

TypeError: either 'timestamps' or 'starting_time' and 'rate' must be specified.

I'm also getting similar errors when I execute nwbf.create_electrode_group(name, coord, desc, recording_device, area, 1.0):

File "/Users/loren/Src/NWB/franklab/convert_nspike.py", line 342, in electrode_group[day][tet_ind+1] = nwbf.create_electrode_group(name, coord, desc, recording_device, area, 1.0) File "/Users/loren/anaconda/lib/python3.5/site-packages/pynwb-0.0.1-py3.5.egg/form/utils.py", line 215, in func_call File "/Users/loren/anaconda/lib/python3.5/site-packages/pynwb-0.0.1-py3.5.egg/pynwb/file.py", line 260, in create_electrode_group File "/Users/loren/anaconda/lib/python3.5/site-packages/pynwb-0.0.1-py3.5.egg/form/utils.py", line 214, in func_call TypeError: missing argument 'channel_impedance', missing argument 'description', missing argument 'location', missing argument 'device'


ajtritt commented 7 years ago

Original comment by Loren Frank (Bitbucket: lmfrnk, GitHub: Unknown):


Perfect.

thanks,

Loren

Loren M. Frank

Professor
Howard Hughes Medical Institute Kavli Institute for Fundamental Neuroscience Department of Physiology University of California, San Francisco Office Phone: 415-502-7357

ajtritt commented 7 years ago

Original comment by Andrew Tritt (Bitbucket: ajtritt, GitHub: ajtritt):


Update and try again.

Andrew

ajtritt commented 7 years ago

Original comment by Loren Frank (Bitbucket: lmfrnk, GitHub: Unknown):


But ... the following fails:

#!python

                      s_tmp = SpikeEventSeries('cluster',
                                     'source',
                                     cluster_waveforms,
                                     (int(day), int(tet_num)),
                                     timestamps = np.asarray(spiketimes),
                                     description = '%sspikes day %d tetrode %d cell %d data' % (prefix, day, tet_num, cell_num))

with an error

Traceback (most recent call last): File "/Users/loren/Src/NWB/franklabnwb/convert_nspike.py", line 464, in description = '%sspikes day %d tetrode %d cell %d data' % (prefix, day, tet_num, cell_num)) File "/Users/loren/Src/NWB/pynwb/src/form/utils.py", line 231, in func_call return func(self, parsed['args']) File "/Users/loren/Src/NWB/pynwb/src/pynwb/ecephys.py", line 90, in init super(SpikeEventSeries, self).init(name, source, electrode_group, data, kwargs) File "/Users/loren/Src/NWB/pynwb/src/form/utils.py", line 230, in func_call raise TypeError(', '.join(parse_err)) TypeError: incorrect type for 'data' (got 'tuple', expected 'list, ndarray or TimeSeries'), incorrect number of dimensions for array electrode_group (got 2, expected 1)

And for reference,

In[2]: type(cluster_waveforms)

Out[2]: numpy.ndarray

ajtritt commented 7 years ago

Original comment by Loren Frank (Bitbucket: lmfrnk, GitHub: Unknown):


This now works; thanks much.

ajtritt commented 7 years ago

Original comment by Andrew Tritt (Bitbucket: ajtritt, GitHub: ajtritt):


Hey Loren,

I fixed the error and merged to dev. Please update and let me know if you have any other problems

Andrew

ajtritt commented 7 years ago

Original comment by Loren Frank (Bitbucket: lmfrnk, GitHub: Unknown):


I figured out that it needed to be a Device, but now I get:

Traceback (most recent call last): File "/Users/loren/Src/NWB/franklab/convert_nspike.py", line 356, in recording_device) File "/Users/loren/Src/NWB/pynwb/src/form/utils.py", line 231, in func_call return func(self, **parsed['args']) File "/Users/loren/Src/NWB/pynwb/src/pynwb/file.py", line 262, in create_electrode_group eg_args, eg_kwargs = fmt_docval_args(ElectrodeGroup.init, kwargs) NameError: name 'fmt_docval_args' is not defined

when I try to create the electrodegroup after creating a device.

Loren

-- Loren M. Frank

Professor
Howard Hughes Medical Institute Kavli Institute for Fundamental Neuroscience Department of Physiology University of California, San Francisco Office Phone: 415-502-7357

ajtritt commented 7 years ago

Original comment by Loren Frank (Bitbucket: lmfrnk, GitHub: Unknown):


Got it. One last bug:

TypeError: incorrect type for 'device' (got 'str', expected 'Device')

Loren

Loren M. Frank

Professor
Howard Hughes Medical Institute Kavli Institute for Fundamental Neuroscience Department of Physiology University of California, San Francisco Office Phone: 415-502-7357

ajtritt commented 7 years ago

Original comment by Andrew Tritt (Bitbucket: ajtritt, GitHub: ajtritt):


Hey Loren,

I hadn't updated the helper function on NWBFile. I just did that, and pushed it to dev. Please pull from dev and try again.

Thanks, Andrew

ajtritt commented 7 years ago

Original comment by Loren Frank (Bitbucket: lmfrnk, GitHub: Unknown):


Unfortunately I still get an error message, although I've checked the order of the calls carefully. The error is

raceback (most recent call last): File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydevd.py", line 1578, in globals = debugger.run(setup['file'], None, None, is_module) File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydevd.py", line 1015, in run pydev_imports.execfile(file, globals, locals) # execute the script File "/Applications/PyCharm CE.app/Contents/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "/Users/loren/Src/NWB/franklab/convert_nspike.py", line 356, in recording_device) File "/Users/loren/Src/NWB/pynwb/src/form/utils.py", line 214, in func_call raise TypeError(', '.join(parse_err)) TypeError: incorrect type for 'desc' (got 'list', expected 'str'), incorrect type for 'dev' (got 'list', expected 'str'), incorrect type for 'loc' (got 'list', expected 'str'), incorrect type for 'imp' (got 'list', expected 'float or tuple')

And here is a snippet of the code that is run:

#!python

tetinfo_file = "%s/%s%s" % (args.data_dir, prefix, tetinfo_file)
recording_device = "NSpike acquisition system"
channel_filtering = [np.nan, np.nan, np.nan, np.nan]
channel_impedance = [np.nan, np.nan, np.nan, np.nan]
electrode_group = dict()
mat = loadmat2(tetinfo_file)
#NOTE: day is 0 based, as is cell; only tetrode number has it's original numbering scheme
for day, day_struct in enumerate(mat.get('tetinfo')[0]):
    if len(day_struct[0]):
        electrode_group[day] = dict()
        # kenny's data has a day epoch tetrode structure but duplicates the info across epochs, so we can use the first
        # epoc for everything
        for tet_ind, tet_struct in enumerate(day_struct[0][0][0]):
            # go through the list of fields
            hemi = '?'
            coord = [np.nan, np.nan, np.nan]
            location = '?'
            sub_area = '?'
            if len(tet_struct[0]):
                tet = tet_struct[0][0]
                field_names = tet._fieldnames
                for field in tet._fieldnames:
                    if field == 'area':
                        area = tet.area[0]
                    if field == 'subarea' and len(tet.subarea):
                        sub_area = tet.subarea[0]
                    elif field == 'depth':
                        coord = [np.nan, np.nan, tet.depth[0][0][0][0] / 12 / 80 * 25.4] #convert to mm
                    elif field == 'hemisphere':
                        hemisphere = tet.hemisphere[0]
                location = area + ' ' + sub_area
                channel_location = [location, location, location, location]
                channel_coordinates = [coord, coord, coord, coord]
                name = "%02d-%02d" % (day, tet_ind + 1)
                description = "tetrode {tet_num} located in {hemi} hemisphere on day {day}".format(tet_num=tet_ind+1, hemi=hemisphere, day=day)
                channel_description = [description, description, description, description]
                electrode_group[day][tet_ind+1] = nwbf.create_electrode_group(name,
                                                                              channel_description,
                                                                              channel_location,
                                                                              channel_filtering,
                                                                              channel_coordinates,
                                                                              channel_impedance,
                                                                              description,
                                                                              location,
                                                                              recording_device)
ajtritt commented 7 years ago

Original comment by Andrew Tritt (Bitbucket: ajtritt, GitHub: ajtritt):


Loren,

The ElectrodeGroup has changed in accordance with changes we had to make to the spec.

http://pynwb.readthedocs.io/en/latest/pynwb.ecephys.html#pynwb.ecephys.ElectrodeGroup

We had to modify the Electrode Group spec to make it more flexible with respect to channels, so you will need to specify data for each channel. This structure will make some unnecessary redundancy for tetrodes, but it was decided on in the interest of making it easier for storing information about more complex devices, like probes and arrays.

Andrew

ajtritt commented 7 years ago

Original comment by Andrew Tritt (Bitbucket: ajtritt, GitHub: ajtritt):


Hi Loren,

Please pull from dev to get the latest changes, and see the most recent documentation for IntervalSeries. Things should work as they used to, but please make sure your calls are in accordance with the current state of the API docs.

http://pynwb.readthedocs.io/en/latest/pynwb.misc.html#pynwb.misc.IntervalSeries

Andrew