Ejemplo n.º 1
0
 def setUpContainer(self):
     self.setUpElectrode()
     return VoltageClampStimulusSeries(name="vcss",
                                       data=[1, 2, 3, 4, 5],
                                       starting_time=123.6,
                                       rate=10e3,
                                       electrode=self.elec,
                                       gain=0.126)
Ejemplo n.º 2
0
    def test_init(self):
        electrode_name = GetElectrode()

        vCSS = VoltageClampStimulusSeries('test_vCSS', 'a hypothetical source', list(),
                                          'unit', electrode_name, 1.0, timestamps=list())
        self.assertEqual(vCSS.name, 'test_vCSS')
        self.assertEqual(vCSS.source, 'a hypothetical source')
        self.assertEqual(vCSS.unit, 'unit')
        self.assertEqual(vCSS.electrode, electrode_name)
Ejemplo n.º 3
0
    def test_init(self):
        electrode_name = GetElectrode()

        vCSS = VoltageClampStimulusSeries('test_vCSS',
                                          list(),
                                          electrode_name,
                                          1.0,
                                          timestamps=list())
        self.assertEqual(vCSS.name, 'test_vCSS')
        self.assertEqual(vCSS.unit, 'volts')
        self.assertEqual(vCSS.electrode, electrode_name)
Ejemplo n.º 4
0
    def test_unit_warning(self):
        electrode_name = GetElectrode()

        msg = "Unit for VoltageClampStimulusSeries 'test_vCSS' is ignored and will be set to 'volts' as per NWB 2.1.0."
        with self.assertWarnsWith(UserWarning, msg):
            vCSS = VoltageClampStimulusSeries('test_vCSS',
                                              list(),
                                              electrode_name,
                                              1.0,
                                              timestamps=list(),
                                              unit='unit')
        self.assertEqual(vCSS.unit, 'volts')
Ejemplo n.º 5
0
def create_icephys_stimulus_and_response(sweep_number, electrode,
                                         randomize_data):
    """
    Internal helper function to construct a dummy stimulus and response pair representing an
    intracellular recording:

    :param sweep_number: Integer sweep number of the recording
    :type sweep_number: int
    :param electrode: Intracellular electrode used
    :type electrode: pynwb.icephys.IntracellularElectrode
    :param randomize_data: Randomize data values in the stimulus and response
    :type randomize_data: bool

    :returns: Tuple of VoltageClampStimulusSeries with the stimulus and VoltageClampSeries with the response.
    """
    stimulus = VoltageClampStimulusSeries(
        name="ccss_" + str(sweep_number),
        data=[1, 2, 3, 4, 5] if not randomize_data else np.random.rand(10),
        starting_time=123.6 if not randomize_data else
        (np.random.rand() * 100),
        rate=10e3
        if not randomize_data else int(np.random.rand() * 10) * 1000 + 1000.,
        electrode=electrode,
        gain=0.1 if not randomize_data else np.random.rand(),
        sweep_number=sweep_number)
    # Create and ic-response
    response = VoltageClampSeries(
        name='vcs_' + str(sweep_number),
        data=[0.1, 0.2, 0.3, 0.4, 0.5]
        if not randomize_data else np.random.rand(10),
        conversion=1e-12,
        resolution=np.nan,
        starting_time=123.6 if not randomize_data else
        (np.random.rand() * 100),
        rate=20e3
        if not randomize_data else int(np.random.rand() * 20) * 1000. + 1000.,
        electrode=electrode,
        gain=0.02 if not randomize_data else np.random.rand(),
        capacitance_slow=100e-12,
        resistance_comp_correction=70.0 if not randomize_data else 70.0 +
        np.random.rand(),
        sweep_number=sweep_number)
    return stimulus, response
Ejemplo n.º 6
0
def test_acquisition_round_trip(nwb_filename):

    nwbfile = NWBFile(session_description='test ephys',
                      identifier='session_uuid',
                      session_start_time=datetime.datetime.now(),
                      file_create_date=datetime.datetime.now())
    device = nwbfile.create_device(name='electrode_0')

    electrode = nwbfile.create_ic_electrode(
        name="elec0", description=' some kind of electrode', device=device)

    data = np.array([1., 3.76, 0., 67, -2.89])
    meta_data = {
        "name": "test_acquisition_sweep",
        "sweep_number": 4,
        "unit": "volts",
        "gain": 32.0,
        "resolution": 1.0,
        "conversion": 1.0E-3,
        "starting_time": 1.5,
        "rate": 7000.0,
        "stimulus_description": "STIMULUS_CODE"
    }

    time_series = VoltageClampStimulusSeries(data=data,
                                             electrode=electrode,
                                             **meta_data)

    nwbfile.add_acquisition(time_series)

    with NWBHDF5IO(nwb_filename, mode='w') as io:
        io.write(nwbfile)
    nwbfile_in = NWBHDF5IO(nwb_filename, mode='r').read()
    time_series_in = nwbfile_in.get_acquisition(meta_data["name"])

    assert np.allclose(data, time_series_in.data)
    for k, v in meta_data.items():
        assert getattr(time_series_in, k) == v
Ejemplo n.º 7
0
                                  electrode=elec,
                                  gain=0.02,
                                  sweep_number=0)

nwbfile.add_stimulus(ccss)

#######################
# We now add another stimulus series but from a different sweep. TimeSeries
# having the same starting time belong to the same sweep.

from pynwb.icephys import VoltageClampStimulusSeries

vcss = VoltageClampStimulusSeries(name="vcss",
                                  data=[2, 3, 4, 5, 6],
                                  starting_time=234.5,
                                  rate=10e3,
                                  electrode=elec,
                                  gain=0.03,
                                  sweep_number=1)

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],
Ejemplo n.º 8
0
                     identifier='EXAMPLE_ID',
                     session_start_time=datetime.now(tzlocal()))

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

# Add an intracellular electrode
ex_electrode = ex_nwbfile.create_icephys_electrode(
    name="elec0",
    description='a mock intracellular electrode',
    device=ex_device)

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

# Create an ic-response
ex_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=ex_electrode,
                                 gain=0.02,
                                 capacitance_slow=100e-12,
                                 resistance_comp_correction=70.0)