def setUpContainer(self): self.setUpElectrode() return CurrentClampSeries(name="ccs", data=[1, 2, 3, 4, 5], starting_time=123.6, rate=10e3, electrode=self.elec, gain=0.126, bias_current=1.2, bridge_balance=2.3, capacitance_compensation=3.45)
def test_init(self): electrode_name = GetElectrode() cCS = CurrentClampSeries('test_cCS', 'a hypothetical source', list(), 'unit', electrode_name, 1.0, 2.0, 3.0, 4.0, timestamps=list()) self.assertEqual(cCS.name, 'test_cCS') self.assertEqual(cCS.source, 'a hypothetical source') self.assertEqual(cCS.unit, 'unit') self.assertEqual(cCS.electrode, electrode_name) self.assertEqual(cCS.gain, 1.0) self.assertEqual(cCS.bias_current, 2.0) self.assertEqual(cCS.bridge_balance, 3.0) self.assertEqual(cCS.capacitance_compensation, 4.0)
def test_unit_warning(self): electrode_name = GetElectrode() msg = "Unit for CurrentClampSeries 'test_cCS' is ignored and will be set to 'volts' as per NWB 2.1.0." with self.assertWarnsWith(UserWarning, msg): cCS = CurrentClampSeries('test_cCS', list(), electrode_name, 1.0, "stimset", 2.0, 3.0, 4.0, timestamps=list(), unit='unit') self.assertEqual(cCS.unit, 'volts')
def test_init(self): electrode_name = GetElectrode() cCS = CurrentClampSeries('test_cCS', list(), electrode_name, 1.0, "stimset", 2.0, 3.0, 4.0, timestamps=list()) self.assertEqual(cCS.name, 'test_cCS') self.assertEqual(cCS.unit, 'volts') self.assertEqual(cCS.electrode, electrode_name) self.assertEqual(cCS.stimulus_description, "stimset") self.assertEqual(cCS.gain, 1.0) self.assertEqual(cCS.bias_current, 2.0) self.assertEqual(cCS.bridge_balance, 3.0) self.assertEqual(cCS.capacitance_compensation, 4.0)
def create_acquisition_series(self, electrode): series = [] for sweep_name in self.nwb_data.get_sweep_names(): sweep_number = self.nwb_data.get_sweep_number(sweep_name) acquisition = self.nwb_data.get_acquisition(sweep_number) stim_code = self.nwb_data.get_stim_code(sweep_number) stim_code_ext = self.get_stim_code_ext(stim_code, sweep_number) scale_factor = self.notebook.get_value("Scale Factor", sweep_number, None) clamp_mode = self.get_clamp_mode(sweep_number) if clamp_mode == self.V_CLAMP_MODE: acquisition_series = VoltageClampSeries( name=sweep_name, sweep_number=sweep_number, data=acquisition['data'], unit=acquisition['unit'], conversion=acquisition['conversion'], resolution=np.nan, starting_time=np.nan, rate=acquisition['rate'], electrode=electrode, gain=scale_factor, capacitance_slow=np.nan, resistance_comp_correction=np.nan, capacitance_fast=np.nan, resistance_comp_bandwidth=np.nan, resistance_comp_prediction=np.nan, comments=acquisition['comment'], whole_cell_capacitance_comp=np.nan, whole_cell_series_resistance_comp=np.nan, stimulus_description=stim_code_ext) elif clamp_mode == self.I_CLAMP_MODE: bridge_balance = self.notebook.get_value( "Bridge Bal Value", sweep_number, np.nan) bias_current = self.notebook.get_value("I-Clamp Holding Level", sweep_number, np.nan) acquisition_series = CurrentClampSeries( name=sweep_name, sweep_number=sweep_number, data=acquisition['data'], unit=acquisition['unit'], conversion=acquisition['conversion'], resolution=np.nan, starting_time=np.nan, rate=acquisition['rate'], comments=acquisition['comment'], electrode=electrode, gain=scale_factor, bias_current=bias_current, bridge_balance=bridge_balance, stimulus_description=stim_code_ext, capacitance_compensation=np.nan) series.append(acquisition_series) return series
nwbfile.add_stimulus(vcss) ####################### # Here, we will use :py:class:`~pynwb.icephys.CurrentClampSeries` to store current clamp # data and then add it to our NWBFile as acquired data using the :py:class:`~pynwb.file.NWBFile` method # :py:meth:`~pynwb.file.NWBFile.add_acquisition`. from pynwb.icephys import CurrentClampSeries ccs = CurrentClampSeries(name="ccs", data=[0.1, 0.2, 0.3, 0.4, 0.5], conversion=1e-12, resolution=np.nan, starting_time=123.6, rate=20e3, electrode=elec, gain=0.02, bias_current=1e-12, bridge_balance=70e6, capacitance_compensation=1e-12, sweep_number=0) nwbfile.add_acquisition(ccs) ####################### # And voltage clamp data from the second sweep using # :py:class:`~pynwb.icephys.VoltageClampSeries`. from pynwb.icephys import VoltageClampSeries vcs = VoltageClampSeries(name="vcs",
def nwbfile_to_test(): """ Create a simple nwbfile for testing Returns ------- nwbfile """ nwbfile = pynwb.NWBFile(session_description="test nwb data", identifier='test session', session_start_time=datetime.datetime.now(), file_create_date=datetime.datetime.now()) device = nwbfile.create_device(name='electrode_0') electrode = nwbfile.create_icephys_electrode(name="electrode 0", description='fancy electrode', device=device) stimulus_data = [0, 3, 3, 3, 0] stimulus_meta_data = { "name": "stimulus", "sweep_number": 4, "unit": "A", "gain": 32.0, "resolution": 1.0, "conversion": 1.0E-3, "starting_time": 1.5, "rate": 7000.0, "stimulus_description": "STIMULUS_CODE" } stimulus_series = CurrentClampStimulusSeries(data=stimulus_data, electrode=electrode, **stimulus_meta_data) nwbfile.add_stimulus(stimulus_series) response_data = [1, 2, 3, 4, 5] response_meta_data = { "name": "acquisition", "sweep_number": 4, "unit": "V", "gain": 32.0, "resolution": 1.0, "conversion": 1.0E-3, "bridge_balance": 500.0, "bias_current": 100.0, "starting_time": 1.5, "rate": 7000.0, "stimulus_description": "STIMULUS_CODE" } acquisition_series = CurrentClampSeries(data=response_data, electrode=electrode, **response_meta_data) nwbfile.add_acquisition(acquisition_series) return nwbfile
def _addAcquisition(self): """ Adds an acquisition class as defined by PyNWB to the NWB File. Written for experiments conducted from a single channel. For multiple channels, refer to https://github.com/AllenInstitute/ipfx/blob/master/ipfx/x_to_nwb/ABFConverter.py """ for idx, abfFile in enumerate(self.abfFiles): if self.acquisitionChannelName is None: channelList = abfFile.adcNames channelIndices = range(len(channelList)) else: if self.acquisitionChannelName in abfFile.adcNames: channelList = abfFile.adcNames channelIndices = [channelList.index(self.acquisitionChannelName)] else: raise ValueError(f"Channel {self.acquisitionChannelName} could not be found.") for i in range(abfFile.sweepCount): for channelIndex in channelIndices: if self.debug: print(f"acquisition: abfFile={abfFile.abfFilePath}, sweep={i}, channelIndex={channelIndex}, channelName={channelList[channelIndex]}") # Collect data from pyABF abfFile.setSweep(i, channel=channelIndex) seriesName = f"Index_{idx}_{i}_{channelIndex}" responseGain = self.responseGain responseOffset = self.responseOffset data = abfFile.sweepY * responseGain + responseOffset conversion, unit = self._unitConversion(abfFile.sweepUnitsY) electrode = self.electrode resolution = np.nan starting_time = 0.0 rate = float(abfFile.dataRate) # Create a JSON file for the description field description = json.dumps({"file_name": os.path.basename(self.fileNames[idx]), "file_version": abfFile.abfVersionString, "sweep_number": i, "protocol": abfFile.protocol, "protocol_path": abfFile.protocolPath, "comments": self._getComments(abfFile)}, sort_keys=True, indent=4) # Create an acquisition class # Note: voltage input produces current output; current input produces voltage output data = createCompressedDataset(data) if self.clampMode == 1: acquisition = CurrentClampSeries(name=seriesName, data=data, sweep_number=i, electrode=electrode, gain=responseGain, resolution=resolution, conversion=conversion, starting_time=starting_time, rate=rate, unit=unit, description=description, bias_current=np.nan, bridge_balance=np.nan, capacitance_compensation=np.nan, ) elif self.clampMode == 0: acquisition = VoltageClampSeries(name=seriesName, data=data, sweep_number=i, electrode=electrode, gain=responseGain, resolution=resolution, conversion=conversion, starting_time=starting_time, rate=rate, unit=unit, description=description, capacitance_fast=np.nan, capacitance_slow=np.nan, resistance_comp_bandwidth=np.nan, resistance_comp_correction=np.nan, resistance_comp_prediction=np.nan, whole_cell_capacitance_comp=np.nan, whole_cell_series_resistance_comp=np.nan ) else: raise ValueError(f"Unsupported clamp mode {self.clampMode}") self.NWBFile.add_acquisition(acquisition)
stimulus = CurrentClampStimulusSeries( name="ccss", data=sweepADC, unit='pA', electrode=elec, rate=10e4, gain=float(metadata['Gain'][5:8]), starting_time=0.0, description='DC%s' % dc) acquisition = CurrentClampSeries( name='ccs', data=sweepDAC, electrode=elec, unit='mV', rate=10e4, gain=0.00, starting_time=0.0, bias_current=np.nan, bridge_balance=np.nan, capacitance_compensation=np.nan) nwbFile.add_trial(start_time=float(start), stop_time=float(end), Stimulus=stimulus, Acquisition=acquisition, CellNo=metadata['Cell No.'], RMP=metadata['RMP'], Layer=metadata['Layer'], Tau=metadata['Tau'], Gain=metadata['Gain'],
def _addAcquisition(self): """ Adds an acquisition class as defined by PyNWB to the NWB File. Written for experiments conducted from a single channel. For multiple channels, refer to https://github.com/AllenInstitute/ipfx/blob/master/ipfx/x_to_nwb/ABFConverter.py """ sweepGlobal = 0 for idx, abfFile in enumerate(self.abfFiles): for i in range(abfFile.sweepCount): # Collect data from pyABF abfFile.setSweep(i) seriesName = "Index_" + str(i + sweepGlobal) data = abfFile.sweepY conversion, unit = self._unitConversion(abfFile.sweepUnitsY) electrode = self.electrode gain = 1.0 # hard coded for White Noise data resolution = np.nan starting_time = 0.0 rate = float(abfFile.dataRate) # Create a JSON file for the description field description = json.dumps( { "file_name": os.path.basename(self.fileNames[idx]), "file_version": abfFile.abfVersionString, "sweep_number": i, "protocol": abfFile.protocol, "protocol_path": abfFile.protocolPath, "comments": self._getComments(abfFile) }, sort_keys=True, indent=4) # Create an acquisition class # Note: voltage input produces current output; current input produces voltage output if self.clampMode == 0: acquisition = CurrentClampSeries( name=seriesName, data=data, sweep_number=i, unit=unit, electrode=electrode, gain=gain, resolution=resolution, conversion=conversion, starting_time=starting_time, rate=rate, description=description, bias_current=np.nan, bridge_balance=np.nan, capacitance_compensation=np.nan, ) elif self.clampMode == 1: acquisition = VoltageClampSeries( name=seriesName, data=data, sweep_number=i, unit=unit, electrode=electrode, gain=gain, resolution=resolution, conversion=conversion, starting_time=starting_time, rate=rate, description=description, capacitance_fast=np.nan, capacitance_slow=np.nan, resistance_comp_bandwidth=np.nan, resistance_comp_correction=np.nan, resistance_comp_prediction=np.nan, whole_cell_capacitance_comp=np.nan, whole_cell_series_resistance_comp=np.nan) self.NWBFile.add_acquisition(acquisition) sweepGlobal += abfFile.sweepCount return True