Skip to content

Instantly share code, notes, and snippets.

@ajtritt
Created December 7, 2017 19:19
Show Gist options
  • Save ajtritt/68e1d2ee59986cb1b183b16707f1a459 to your computer and use it in GitHub Desktop.
Save ajtritt/68e1d2ee59986cb1b183b16707f1a459 to your computer and use it in GitHub Desktop.
Writing Intracellular Ephys data (for Bart Jongbloets)
""" import the pynwb packages"""
from pynwb import NWBFile, TimeSeries, get_manager
from pynwb.form.backends.hdf5 import HDF5IO
from pynwb.icephys import CurrentClampSeries
from pynwb.icephys import VoltageClampSeries
import datetime
import numpy as np
import os
experimentID = 'BJ5523'#folderPath.split('/')[-1]
nwbFile = NWBFile(session_description= 'NaN',
identifier='NaN',
session_start_time=datetime.datetime(2017, 2, 17, 13, 26, 23),
file_create_date='Tue Dec 5 17:33:51 2017',
experimenter='NaN',
experiment_description='NaN',
session_id='NaN',
institution='NaN',
lab='NaN',
source='Ephus (Janelia Farm) software generated files')
Amp1_VoltData = np.arange(1,1000)
Amp2_VoltData = np.arange(10,1010)
Amp1_AmpData = np.arange(20,1020)
Amp2_AmpData = np.arange(30,1030)
amp1 = nwbFile.create_intracellular_electrode(name = 'Amp1',
source = 'Amp_700B_1',
slice = 'Horizontal mouse slice 300um',
seal = '2000',
description = 'whole-cell',
location ='locX',
resistance = '10',
filtering = '2.2 Hz Bessel',
initial_access_resistance = '110',
device = 'Multiclamp 700B')
amp2 = nwbFile.create_intracellular_electrode(name = 'Amp2',
source = 'Amp_700B_2',
slice = 'Horizontal mouse slice 300um',
seal = '3000',
description = 'whole-cell',
location ='locX',
resistance = '15',
filtering = '2.2 Hz Bessel',
initial_access_resistance = '165',
device = 'Multiclamp 700B')
amp1Volt_ts = VoltageClampSeries(name = 'Amp1VoltClamp',
source = 'Multiclamp 700B',
data = Amp1_AmpData,
unit = 'picoAmpere',
electrode = amp1, # This is where it requires type:'IntracellularElectrode', which I though is the object amp1 or 2
gain = 10.0,
capacitance_fast = 0.0,
capacitance_slow = 0.0,
resistance_comp_bandwidth = 0.0,
resistance_comp_correction = 0.0,
resistance_comp_prediction = 0.0,
whole_cell_capacitance_comp = 0.0,
whole_cell_series_resistance_comp = 0.0,
resolution = 0.001,
conversion = 1000000000.0,
timestamps = np.arange(1,len(Amp1_AmpData)),
starting_time = 0.0,
rate = 10000.0)
amp1Amp_ts = CurrentClampSeries(name = 'Amp1CurrentClamp',
source = 'Multiclamp 700B',
data = Amp1_VoltData,
unit = 'milliVolt',
electrode = amp1,
gain = 10.0,
bias_current = 0.0,
bridge_balance = 0.0,
capacitance_compensation = 0.0,
resolution = 0.001,
conversion = 1000.0,
timestamps = np.arange(1,len(Amp1_VoltData)),
starting_time = 0.0,
rate = 10000.0)
amp2Volt_ts = VoltageClampSeries(name = 'Amp2VoltClamp',
source = 'Multiclamp 700B',
data = Amp2_AmpData,
unit = 'picoAmpere',
electrode = amp2, # This is where it requires type:'IntracellularElectrode', which I though is the object amp1 or 2
gain = 10.0,
capacitance_fast = 0.0,
capacitance_slow = 0.0,
resistance_comp_bandwidth = 0.0,
resistance_comp_correction = 0.0,
resistance_comp_prediction = 0.0,
whole_cell_capacitance_comp = 0.0,
whole_cell_series_resistance_comp = 0.0,
resolution = 0.001,
conversion = 1000000000.0,
timestamps = np.arange(1,len(Amp2_AmpData)),
starting_time = 0.0,
rate = 10000.0)
amp2Amp_ts = CurrentClampSeries(name = 'Amp2CurrentClamp',
source = 'Multiclamp 700B',
data = Amp2_VoltData,
unit = 'milliVolt',
electrode = amp2,
gain = 10.0,
bias_current = 0.0,
bridge_balance = 0.0,
capacitance_compensation = 0.0,
resolution = 0.001,
conversion = 1000.0,
timestamps = np.arange(1,len(Amp2_VoltData)),
starting_time = 0.0,
rate = 10000.0)
nwbFile.add_acquisition(amp1Volt_ts)
nwbFile.add_acquisition(amp2Volt_ts)
nwbFile.add_acquisition(amp1Amp_ts)
nwbFile.add_acquisition(amp2Amp_ts)
saveFileName = experimentID+'.nwb'
if os.path.exists(saveFileName):
os.remove(saveFileName)
manager = get_manager()
io = HDF5IO(saveFileName, manager)
io.write(nwbFile)
nwbfile = io.read(saveFileName)
print('Found the following acquisition timeseries')
for icets in nwbfile.acquisition:
print(icets.name)
print('Found the following intracellular electrodes')
for ice in nwbfile.ic_electrodes:
print(ice.name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment