Long Square AnalysisΒΆ

Detect Long Square Features

lsq analysis

Out:

/home/docs/checkouts/readthedocs.org/user_builds/ipfx/checkouts/v1.0.0.1/docs/gallery/analysis_examples/lsq_analysis.py:30: VisibleDeprecationWarning: Function create_ephys_data_set is deprecated. Instead of using ipfx.data_set_utils.create_data_set, use ipfx.dataset.create.create_ephys_data_set
  data_set = create_data_set(sweep_info=sweep_info, nwb_file=nwb_file)
/home/docs/checkouts/readthedocs.org/user_builds/ipfx/envs/v1.0.0.1/lib/python3.7/site-packages/hdmf/spec/namespace.py:470: UserWarning: ignoring namespace 'hdmf-common' because it already exists
  warn("ignoring namespace '%s' because it already exists" % ns['name'])
/home/docs/checkouts/readthedocs.org/user_builds/ipfx/envs/v1.0.0.1/lib/python3.7/site-packages/hdmf/spec/namespace.py:470: UserWarning: ignoring namespace 'core' because it already exists
  warn("ignoring namespace '%s' because it already exists" % ns['name'])
/home/docs/checkouts/readthedocs.org/user_builds/ipfx/checkouts/v1.0.0.1/ipfx/dataset/create.py:124: VisibleDeprecationWarning: Class EphysDataSet is deprecated. Import EphysDataSet from ipfx.dataset.ephys_dataset rather than ipfx.ephys_dataset
  data=nwb_data,
tau: 0.019018985944621015
v_baseline: -67.88411102294921
input_resistance: 196.8751847743988
vm_for_sag: -86.21875
fi_fit_slope: 0.35241306261377875
sag: 0.1976930797100067
rheobase_i: 70.0

from ipfx.data_set_utils import create_data_set
from ipfx.feature_extractor import (
    SpikeFeatureExtractor, SpikeTrainFeatureExtractor
)
import ipfx.stimulus_protocol_analysis as spa
from ipfx.epochs import get_stim_epoch

from allensdk.api.queries.cell_types_api import CellTypesApi

import os
import matplotlib.pyplot as plt

# Download and access the experimental data
ct = CellTypesApi()
nwb_file = os.path.join(
    os.path.dirname(os.getcwd()),
    "data",
    "nwb2_H17.03.008.11.03.05.nwb"
)
specimen_id = 595570553
sweep_info = ct.get_ephys_sweeps(specimen_id)

# build a data set and find the long squares
data_set = create_data_set(sweep_info=sweep_info, nwb_file=nwb_file)
lsq_table = data_set.filtered_sweep_table(
    stimuli=data_set.ontology.long_square_names
)
lsq_set = data_set.sweep_set(lsq_table.sweep_number)

# find the start and end time of the stimulus
# (treating the first sweep as representative)
stim_start_index, stim_end_index = get_stim_epoch(lsq_set.i[0])
stim_start_time = lsq_set.t[0][stim_start_index]
stim_end_time = lsq_set.t[0][stim_end_index]

# build the extractors
spx = SpikeFeatureExtractor(start=stim_start_time, end=stim_end_time)
spfx = SpikeTrainFeatureExtractor(start=stim_start_time, end=stim_end_time)

# run the analysis and print out a few of the features
lsqa = spa.LongSquareAnalysis(spx, spfx, subthresh_min_amp=-100.0)
data = lsqa.analyze(lsq_set)

fields_to_print = [
    'tau',
    'v_baseline',
    'input_resistance',
    'vm_for_sag',
    'fi_fit_slope',
    'sag',
    'rheobase_i'
]

for field in fields_to_print:
    print("%s: %s" % (field, str(data[field])))

# plot stim amp vs. firing rate
spiking_sweeps = data['spiking_sweeps'].sort_values(by='stim_amp')
plt.plot(spiking_sweeps.stim_amp,
         spiking_sweeps.avg_rate)
plt.xlabel('Stimulus amplitude (pA)')
plt.ylabel('Average firing rate (Hz)')

plt.show()

Total running time of the script: ( 0 minutes 13.856 seconds)

Gallery generated by Sphinx-Gallery