Hi Kenji,
The information you need to pull together to do this is in a couple of different places.
First you set up a CellTypesCache
object to access the data
from allensdk.core.cell_types_cache import CellTypesCache
ctc = CellTypesCache(manifest_file='cell_types/manifest.json')
Next, you can get the ephys features for all the cells, the data for a single cell (from the NWB file), and the sweep-level information for that cell.
# pick a cell to analyze
specimen_id = 628700262
# download the ephys data and sweep metadata
features = ctc.get_ephys_features()
# get the features just for the cell we are interested in
cell_features = [f for f in features if f["specimen_id"] == specimen_id][0]
# get the ephys data and sweep-level info
data_set = ctc.get_ephys_data(specimen_id)
sweeps = ctc.get_ephys_sweeps(specimen_id)
The cell_features
variable is a dictionary of features. To get sweeps just above rheobase, you can get the rheobase stimulus amplitude by either getting it from the rheobase sweep
rheobase_sweep_number = cell_features["rheobase_sweep_number"]
rheobase_sweep_info = [s for s in sweeps if s["sweep_number"] == rheobase_sweep_number][0]
rheobase_amplitude = rheobase_sweep_info["stimulus_absolute_amplitude"]
Or you could know that the cell-level property threshold_i_long_square
is also the rheobase amplitude
also_the_rheobase_amplitude = cell_features["threshold_i_long_square"]
Now you can grab the sweeps that (1) are long squares, (2) have spikes, and (3) are above rheobase by some amount (say +10 pA), then sort them by their amplitudes.
my_sweeps = [s for s in sweeps
if s["stimulus_name"] == "Long Square"
and s["stimulus_absolute_amplitude"] > rheobase_amplitude + 10
and s["num_spikes"] > 0]
sorted_sweeps = sorted(my_sweeps, key=lambda x: x["stimulus_absolute_amplitude"])
Get the spike times and sweep data for the first one in that list by
my_sweep_number = sorted_sweeps[0]["sweep_number"]
spike_times = data_set.get_spike_times(my_sweep_number)
sweep_data = data_set.get_sweep(my_sweep_number)
And then you can go through and find the right times and intervals by getting the t
and v
vectors as in the page you linked.