data Package

data Package

data

This package deals with data containers, and data loading functions.

data_loader Module

Allows the user to easily load sample patch clamp recordings that were previously downloaded by fit_neuron.data.dl_neuron_data.

In addition, the user may use is_noise() to filter current injections that are above an auto-correlation cutoff.

Warning

The functions load_neuron_files() and load_neuron_data() not work unless one of the following is true:

  1. The user has downloaded and unzipped the data via the following script:

    sudo python -m fit_neuron.data.dl_neuron_data
    
  2. The user manually downloaded and unzipped DataTextFiles.zip (currently available at https://xp-dev.com/svn/neuro_fit/fit_neuron/data/DataTextFiles.zip) and the user specifies the path of the DataTextFiles directory as keyword arguments to load_neuron_files() or load_neuron_data().

fit_neuron.data.data_loader.is_noise(input_current, correlation_cutoff=0.8)[source]

Given an array of equally spaced input current values, is the input noise or not? Use the Pearson auto-correlation coefficient of the input signal to determine this heuristically.

Parameters:
  • correlation_cutoff – threshold below which we classify an input current as being noise
  • input_current – a numpy array of equally spaced values
  • correlation_cutoff – threshold below which we classify an input current as being noise
Returns:

True if input_current is noise, False if not

>>> [file_id_list,input_list,voltage_list,time_delta] = load_neuron_files(neuron_num=1,file_num_list=range(1,16),show_print=False)
>>> is_noise(input_list[0])
False
>>> is_noise(input_list[13])
True
fit_neuron.data.data_loader.load_neuron_data(neuron_num, input_type='all', max_file_ct=inf, data_dir=None, verbose=False)[source]

This function loads and returns a subset of the data as defined by the input parameters. If the user want to load specific files, the user should use load_neuron_files().

Parameters:
  • neuron_num – number of neuron we want to load, integer from 1 to 12
  • input_type – input type is allowed to be “noise_only”, “no_noise_only”, or “all”
  • max_file_ct – maximum number of I/O files we are allowed to load
  • data_dir – path of DataTextFiles directory
Returns:

list of input arrays, list of voltage arrays, list of file paths used

If input_type is anything else, then load all data.

Usage:

>>> [file_id_list,input_list,voltage_list,time_delta] = load_neuron_data(neuron_num=1,input_type="noise_only",max_file_ct=5)
Loaded new data: stim13.txt
Loaded new data: stim14.txt
Loaded new data: stim15.txt
Loaded new data: stim16.txt
Loaded new data: stim17.txt

This last example shows that the first 12 stimulus files were filtered because they were not noisy inputs and the user specified to only load noisy inputs.

Here the user still requests 5 sweeps of data but does not require the inputs to be noisy:

>>> [file_id_list,input_list,voltage_list,time_delta] = load_neuron_data(neuron_num=1,input_type="all",max_file_ct=5)
Loaded new data: stim1.txt
Loaded new data: stim2.txt
Loaded new data: stim3.txt
Loaded new data: stim4.txt
Loaded new data: stim5.txt
fit_neuron.data.data_loader.load_neuron_files(neuron_num, file_num_list, show_print=False, data_dir=None)[source]

This function loads and returns data specified by the user.

Parameters:
  • neuron_num – number of neuron we want to load, integer from 1 to 12.
  • file_num_list – list of indices ranging from and including 1 to 99 corresponding to specific stim/sweep files we want to load.
  • show_print – bool determining whether we print the stim files loaded (the corresponding voltage files are also loaded, just not printed).
  • data_dir – path of DataTextFiles directory

Usage:

>>> [file_id_list,input_list,voltage_list,time_delta] = load_neuron_files(1,[1,2,3])
Loaded new data: stim1.txt
Loaded new data: stim2.txt
Loaded new data: stim3.txt

dl_neuron_data Module

A script that automatically downloads the test data to the directory of the fit_neuron.data package within dist-packages. The script may be run as:

sudo python -m fit_neuron.data.dl_neuron_data

The sample recordings contain data for 12 neurons. The functions in this file use urllib2 to download a zip file, which is then unzipped in the fit_neuron.data directory.

The user will need to be patient the first time the user attempts to call the data loading functions in this file, as a 300 MB zip file will be downloaded and then unzipped to txt files. The disk usage of the unzipped text files will be over 1 GB. Once the sample recordings are downloaded, the downloading and unzipping of the data will be skipped.

Note

While running this script is the easiest way for a user to start testing the fitting methods, the user may also download and unzip the data manually. In this case, the path of the top level directory (DataTextFiles by default) containing the data will need to be specified as a keyword argument when calling fit_neuron.data.data_loader.load_neuron_files() and fit_neuron.data.data_loader.load_neuron_data().

fit_neuron.data.dl_neuron_data.dl_file(url='https://xp-dev.com/svn/neuro_fit/fit_neuron/data/DataTextFiles.zip')[source]

Downloads a zip file containing test data into the current directory.

fit_neuron.data.dl_neuron_data.unzip_test_data()[source]

Unzips the data that comes with the module. This function needs to be called in order for the load_neuron_files() and load_neuron_data() functions to work. Once the data is unzipped, this function will automatically detect the existence of the folder with the data and will not execute anything anymore.

extract_spikes Module

extract_spikes

This module contains functions to extract spike times and spike shapes from voltage traces. These voltage traces may be recorded voltage traces, or they may be simulated voltage traces. The convention used here is that simulated voltage traces are numpy.nan valued whenever the neuron is spiking.

fit_neuron.data.extract_spikes.compute_Vr(spike_shapes, t_ref, dt)[source]

Finds the median reset voltage of the neuron t_ref seconds after the peak of the spike.

Note

The median value of the reset voltage at the time of the reset indices is actually used instead of the average, as the average is less robust to outliers.

fit_neuron.data.extract_spikes.compute_spike_shapes(raw_data, look_behind=0.003, look_ahead=0.025)[source]

Computes values of self.spike_shapes. The arguments specify amount of time in seconds to look ahead and behind of argmax of spike to include as part of the spike shape. The list of computed spike shapes are stored in spike_shapes.

Parameters:
  • look_behind – how much time before the upward zero crossing of the voltage do we consider in spike shape?
  • look_ahead – how much time after the upward zero crossing of voltage do we consider being in spike shape?

Note

The parameter look_behind is very important, for it will be used to determine the length of the spikes. The length of the spikes will be computed by computing the amount of time it takes for the voltage to return to it’s prior value at look_behind seconds before the spike event.

fit_neuron.data.extract_spikes.compute_t_ref(spike_shapes, dt)[source]

Returns the refractory period of the neuron by doing a simple calculation that computes the amount of time it takes for median spike shape to return to a voltage value that is below the median spike shape’s voltage a short period before the actual spike.

fit_neuron.data.extract_spikes.spk_from_bio(membrane_voltage_list)[source]

Computes list of arrays of spike indices from list of voltage traces. The spike indices are computed using the upward zero crossing criterion.

Parameters:membrane_voltage_list – list of arrays with units of mV
Returns:list of arrays of spike indices

Note

In order to get the spike times, the returned spike index arrays will need to be multiplied by dt. This step will need to be done in order to call functions from fit_neuron.evaluate.spkd_lib.

fit_neuron.data.extract_spikes.spk_from_sim(membrane_voltage_list)[source]

Takes a list of simulated voltage traces and returns list of spike indices. This function assumes convention that the voltage is nan corresponds to when the neuron is spiking.

Parameters:membrane_voltage_list – list of arrays of voltage traces
Returns:list of spike index arrays

Note

In order to get the spike times, the returned spike index arrays will need to be multiplied by dt. This step will to be done in order to call functions from fit_neuron.evaluate.spkd_lib.

my_data Module

This module contains class definitions for raw voltage trace data and processed voltage trace data that facilitates the estimation of LIF models. This class is not meant for generic use, as it is designed specifically for the estimation produces in fit_neuron.optimize. Processed data means that the indices corresponding to times during which the neuron was spiking have been removed. See raw_2_processed() on details of how this is done.

A sweep is a single pair of input current injections and membrane voltage.

class fit_neuron.data.my_data.MySweep(**kwargs)[source]

Generic class used by ProcessedData and RawData iterators (see ProcessedData.__getitem__()). Syntactic sugar for iterating over sweeps.

class fit_neuron.data.my_data.ProcessedData(dt=0.0001, input_current_list=[], membrane_voltage_list=[], reset_ind_list=[])[source]

Basic unit of processed data containing multiple sweeps for a single neuron.

Parameters:
  • dt – time step (seconds)
  • input_current_list – list of input current injection arrays
  • membrane_voltage_list – list of membrane voltage arrays
  • reset_ind_list – list of reset index arrays
Raises :

ValueError, raised if the lengths of input lists are not equal to each other.

Clients can iterate over sweeps as follows:

>>> x = np.zeros( (10) )
>>> y = np.ones( (10) )
>>> ind_arr = np.array( [3,6,9] )
>>> for sweep in ProcessedData(0.0001,[x,x],[y,y],[ind_arr,ind_arr]): 
...     print sweep.input_current
...     print sweep.membrane_voltage
...     print sweep.reset_ind
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
[ 1.  1.  1.  1.  1.  1.  1.  1.  1.  1.]
[3 6 9]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
[ 1.  1.  1.  1.  1.  1.  1.  1.  1.  1.]
[3 6 9]
class fit_neuron.data.my_data.RawData(dt=0.0001, input_current_list=[], membrane_voltage_list=[])[source]

Basic unit of raw data containing multiple sweeps for a single neuron.

Parameters:
  • dt – time step (seconds)
  • input_current_list – list of input current injection arrays
  • membrane_voltage_list – list of membrane voltage arrays
  • reset_ind_list – list of reset index arrays
Raises :

ValueError, raised if the lengths of input lists are not equal to each other.

Clients can iterate over sweeps as follows:

>>> x = np.zeros( (10) )
>>> y = np.ones( (10) )
>>> for sweep in RawData(0.0001,[x,x],[y,y]): 
...     print sweep.input_current
...     print sweep.membrane_voltage
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
[ 1.  1.  1.  1.  1.  1.  1.  1.  1.  1.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
[ 1.  1.  1.  1.  1.  1.  1.  1.  1.  1.]
fit_neuron.data.my_data.raw_2_processed(raw_data, look_behind=0.002)[source]

Takes raw data, removes the indices of the spikes, and returns the processed data.

Spikes are removed as follows:

  1. Use upward zero crossing criterion to find spike time.
  2. Look a fixed amound of time (determined by look_behind) before the spike time computed in step 1 and record the value of the voltage here. The spike is considered to have started here.
  3. Consider the spike to have ended after the neuron’s voltage drops to a value that is below the pre-spike voltage value computed in step 2.
  4. Remove chunk of data between endpoints determined by step 2 and step 3.
Parameters:
  • raw_data (RawData) – raw data
  • look_behind – controls how much we remove from each spike (see above procedure).
Return type:

ProcessedData

Note

The spike shapes are removed not only from the voltage traces, but are also removed from the corresponding indices of the current injections.

Table Of Contents

This Page