oruebel / ndx-icephys-meta

NWB extensions for origanizing intracellular electrophysiology metadata
Other
6 stars 0 forks source link

Suggestion: Add super simple example to README #39

Closed rly closed 4 years ago

rly commented 4 years ago

The notebooks are great and well documented; however, I have found it useful to have a barebones almost minimum working demonstration of the new data types. I suggest such an example is added to the bottom of the README. Something like the following:

from datetime import datetime
from dateutil.tz import tzlocal
import numpy as np
from pynwb.icephys import VoltageClampStimulusSeries, VoltageClampSeries
from pynwb import NWBHDF5IO
from ndx_icephys_meta.icephys import ICEphysFile

nwbfile = ICEphysFile(session_description='my first recording',
                      identifier='EXAMPLE_ID',
                      session_start_time=datetime.now(tzlocal()))

# Add a device
device = nwbfile.create_device(name='Heka ITC-1600')

# Add an intracellular electrode
electrode = nwbfile.create_ic_electrode(name="elec0",
                                        description='a mock intracellular electrode',
                                        device=device)

# Create an ic-ephys stimulus
stimulus = VoltageClampStimulusSeries(
            name="stimulus",
            data=[1, 2, 3, 4, 5],
            starting_time=123.6,
            rate=10e3,
            electrode=electrode,
            gain=0.02,
            sweep_number=15)

# Create an ic-response
response = VoltageClampSeries(
            name='response',
            data=[0.1, 0.2, 0.3, 0.4, 0.5],
            conversion=1e-12,
            resolution=np.nan,
            starting_time=123.6,
            rate=20e3,
            electrode=electrode,
            gain=0.02,
            capacitance_slow=100e-12,
            resistance_comp_correction=70.0,
            sweep_number=15)

# Add an intracellular recording to the file
nwbfile.add_intracellular_recording(electrode=electrode,
                                    stimulus=stimulus,
                                    response=response)

# Add a list of sweeps to the sweeps table
nwbfile.add_ic_sweep(recordings=[0])

# Add a list of sweep table indices as a sweep sequence
nwbfile.add_ic_sweep_sequence(sweeps=[0])

# Add a list of sweep sequence table indices as a run
nwbfile.add_ic_run(sweep_sequences=[0])

# Add a list of run table indices as a condition
nwbfile.add_ic_condition(runs=[0])

# Write our test file
testpath = "test_icephys_file.h5"
with NWBHDF5IO(testpath, 'w') as io:
    io.write(nwbfile)

# Read the data back in
with NWBHDF5IO(testpath, 'r') as io:
    infile = io.read()
    print(infile)

I think the above should run. The downside of including code in the README is that it is not testable and it is quite long, but I think it is helpful for an at-a-glance overview of the extension and its usage nevertheless

oruebel commented 4 years ago

Sounds good. I updated your example slightly, i.e., the import for VoltageClampStimulusSeries was missing and no sweep was added. I'll add the example once I have it working with the latest HDMF.

lvsltz commented 4 years ago

Good idea! Two suggestions:

  1. remove the sweep_number, as this extension is basically replacing the sweeps table
  2. it is not clear where those zeros (in add_ic_sweep, add_ic_sweep_sequence etc) are coming from: they are the outputs of the previous nwbfile.add_* calls and this is not apparent. I'd do something like this:
    n = nwbfile.add_intracellular_recording(...)
    p = nwbfile.add_ic_sweep(recordings = n)
oruebel commented 4 years ago

@lvsltz thanks for the suggestion. I've updated the example accordingly.