probeinterface icon indicating copy to clipboard operation
probeinterface copied to clipboard

Integration with NWB

Open samuelgarcia opened this issue 5 years ago • 7 comments

@lfrank @bendichter

You both mention NWB backend for handling probe geometry description. I have NOT studied then yet. I will.

Are theses two codes linked somehow ?

https://github.com/NovelaNeuro/ndx-franklab-novela this seams to be a description of in house data management for recordings that also include probes description (with multi shank)

https://github.com/catalystneuro/ndx-spatial-coordinates/blob/main/src/spec/create_extension_spec.py being unfamilir wuth nwb I get the purposed on this, could you explain more ?

Would be a way to define some kind of offcial to describe probes in NWB. Maybe my question is naive because I am not aware of what have already been done.

samuelgarcia avatar Dec 02 '20 12:12 samuelgarcia

About the ndx-franklab-novela I will use lots of fields propose by this project.

samuelgarcia avatar Dec 02 '20 12:12 samuelgarcia

ndx-spatial-coordinates is a work-in-progress. It's a project with the Allen Institute that encompasses several related topics: probe configuration, anatomical atlas, and spatial transformations. We have started thinking about how to define objects in 2 and 3 d, so I thought it might be relevant for you. It's still a work-in-progress though, is likely to change, and currently has no documentation.

bendichter avatar Dec 02 '20 13:12 bendichter

Is it with Luke Campagnola ?

samuelgarcia avatar Dec 02 '20 16:12 samuelgarcia

Hi @bendichter. I have release today version 0.1.0 The actual package contain a "read_nwb(...)" function which is empty at the moment. When nwb format will have something about the spatial probe description it would be cool to implement this function as a proof of concept to test prointerface API.

samuelgarcia avatar Jan 11 '21 09:01 samuelgarcia

@D1o0g9s will be helping with this task

Some pseudo-code design for reading NWB without the use of the extension @D1o0g9s is putting together, as well as a modular step-by-step bite-size tasklist

1

read stuff in probeinterface.io

def read_from_nwb(nwbfile_path : str) -> Probe:  # or w/e name you want
with NWBHDF5IO(file, "r") as io:
     nwbfile = io.read()

    # figure out num_dims and num_contaacts,
    
    shape = nwbfile.electrodes.get("shape")
    # shape_params only necessary if shape is not None

    probe_object = Probe(ndim = num_dims, si_units="um")

    poisitions_2d = np.empty(shape=(num_contacts, num_dims))
    for j, column_name in enumerate(["rel_x", "rel_y", "rel_z"]):
           poisitions_2d[, j] = nwbfile.electrodes[column_name]

    probe_object.set_contacts(positioned_2d, shapes=shape, shape_params=shape_params)
    
    return probe_object

2

In neuroconv.tools.probeinterface

def add_probe_info(nwbfile : NWBFile):
    # map all probeinterface.Probe fields to electrode columns + use the ndx-probe extension for nicely describing probe geometry in the new Device object

def write_probe(probe: Probe, nwbfile_path : str, metadata : dict, overwrite : bool = False):
    with NWBHDF5IO(path=nwbfile_path, mode="w" if overwrite else "r+") as io:
        nwbfile = make_nwbfile_from_metadata(metadata) if overwrite else io.read() # this is typical basic neuroconv metadata strcture, mainly for session_start_time
        add_probe_info(nwbfile=nwbfile)
        io.write(nwbfile)

3

read more complete information (if available) in probeinterface.io

def read_from_nwb():  # or w/e name you want
with NWBHDF5IO(file, "r") as io:
     nwbfile = io.read()

     # all the previous stuff from #1

    # then read in all that stuff was that newly written through the use of # 2
    # goal being to be capable of a full roundtrip without any loss in information when using neuroconv.tools.probeinterface.write_probe to write a nwbfile, then using probe=read_from_nwb(nwbfile_path) to read it back

CodyCBakerPhD avatar Jul 27 '22 19:07 CodyCBakerPhD

https://github.com/SpikeInterface/ndx-probeinterface

alejoe91 avatar Aug 23 '23 08:08 alejoe91