allensdk.brain_observatory.ecephys.stimulus_table.ephys_pre_spikes module¶
Created on Fri Dec 16 15:11:23 2016
@author: Xiaoxuan Jia
-
allensdk.brain_observatory.ecephys.stimulus_table.ephys_pre_spikes.
apply_display_sequence
(sweep_frames_table, frame_display_sequence, start_key='Start', end_key='End', diff_key='dif', block_key='stimulus_block')[source]¶ Adjust raw sweep frames for a stimulus based on the display sequence for that stimulus.
Parameters: - sweep_frames_table : pd.DataFrame
Each row is a sweep. Has two columns, ‘start’ and ‘end’, which describe (in frames) when that sweep began and ended.
- frame_display_sequence : np.ndarray
2D array. Rows are display intervals. The 0th column is the start frame of that interval, the 1st the end frame.
Returns: - sweep_frames_table : pd.DataFrame
As above, but start and end frames have been adjusted based on the display sequence.
Notes
The frame values in the raw sweep_frames_table are given in 0-indexed offsets from the start of display for this stimulus. This domain only takes into account frames which are part of a display interval for that stimulus, so the frame ids need to be adjusted to lie on the global frame sequence.
-
allensdk.brain_observatory.ecephys.stimulus_table.ephys_pre_spikes.
apply_frame_times
(stimulus_table, frame_times, frames_per_second=None, extra_frame_time=False, map_columns=('Start', 'End'))[source]¶ Converts sweep times from frames to seconds.
Parameters: - stimulus_table : pd.DataFrame
Rows are sweeps. Columns are stimulus parameters as well as start and end frames for each sweep.
- frame_times : numpy.ndarrray
Gives the time in seconds at which each frame (indices) began.
- frames_per_second : numeric, optional
If provided, and extra_frame_time is True, will be used to calculcate the extra_frame_time.
- extra_frame_time : float, optional
If provided, an additional frame time will be appended. The time will be incremented by extra_frame_time from the previous last frame time, to denote the time at which the last frame ended. If False, no extra time will be appended. If None (default), the increment will be 1.0/fps.
- map_columns : tuple of str, optional
Which columns to replace with times. Defaults to ‘Start’ and ‘End
Returns: - stimulus_table : pd.DataFrame
As above, but with map_columns values converted to seconds from frames.
-
allensdk.brain_observatory.ecephys.stimulus_table.ephys_pre_spikes.
assign_sweep_values
(stim_table, sweep_table, on='sweep_number', drop=True, tmp_suffix='_stimtable_todrop')[source]¶ Left joins a stimulus table to a sweep table in order to associate epochs in time with stimulus characteristics.
Parameters: - stim_table : pd.DataFrame
Each row is a stimulus epoch, with start and end times and a foreign key onto a particular sweep.
- sweep_table : pd.DataFrame
Each row is a sweep. Should have columns in common with the stim_table - the resulting table will use values from the sweep_table.
- on : str, optional
Column on which to join.
- drop : bool, optional
If True (default), the join column (argument on) will be dropped from the output.
- tmp_suffix : str, optional
Will be used to identify overlapping columns. Should not appear in the name of any column in either dataframe.
-
allensdk.brain_observatory.ecephys.stimulus_table.ephys_pre_spikes.
build_stimuluswise_table
(stimulus, seconds_to_frames, start_key='Start', end_key='End', name_key='stimulus_name', block_key='stimulus_block', get_stimulus_name=None, extract_const_params_from_repr=False, drop_const_params=('name', 'autoLog', 'autoDraw', 'win'))[source]¶ Construct a table of sweeps, including their times on the experiment-global clock and the values of each relevant parameter.
Parameters: - stimulus : dict
Describes presentation of a stimulus on a particular experiment. Has a number of fields, of which we are using:
- stim_path : str
windows file path to the stimulus data
- sweep_frames : list of lists
rows are sweeps, columns are start and end frames of that sweep (in the stimulus-specific frame domain). C-order.
- sweep_order : list of int
indices are frames, values are the sweep on that frame
- display_sequence : list of list
rows are intervals in which the stimulus was displayed. Columns are start and end times (s, global) of the display. C-order.
- dimnames : list of str
Names of parameters for this stimulus (such as “Contrast”)
- sweep_table : list of tuple
Each element is a tuple of parameter values (1 per dimname) describing a single sweep.
- seconds_to_frames : function
Converts experiment seconds to frames
- start_key : str, optional
key to use for start frame indices. Defaults to ‘Start’
- end_key : str, optional
key to use for end frame indices. Defaults to ‘End’
- name_key : str, optional
key to use for stimulus name annotations. Defaults to ‘stimulus_name’
- block_key : str, optional
key to use for the 0-index position of this stimulus block
- get_stimulus_name : function | dict -> str, optional
extracts stimulus name from the stimulus dictionary. Default is read_stimulus_name_from_path
Returns: - list of pandas.DataFrame :
Each table corresponds to an entry in the display sequence. Rows are sweeps, columns are stimulus parameter values as well as “Start” and “End”.
-
allensdk.brain_observatory.ecephys.stimulus_table.ephys_pre_spikes.
create_stim_table
(stimuli, stimulus_tabler, spontaneous_activity_tabler, sort_key='Start', block_key='stimulus_block', index_key='stimulus_index')[source]¶ Build a full stimulus table
Parameters: - stimuli : list of dict
Each element is a stimulus dictionary, as provided by the stim.pkl file.
- stimulus_tabler : function
A function which takes a single stimulus dictionary as its argument and returns a stimulus table dataframe.
- spontaneous_activity_tabler : function
A function which takes a list of stimulus tables as arguments and returns a list of 0 or more tables describing spontaneous activity sweeps.
- sort_key : str, optional
Sort the final stimulus table in ascending order by this key. Defaults to ‘Start’.
Returns: - stim_table_full : pandas.DataFrame
Each row is a sweep. Has columns describing (in frames) the start and end times of each sweep. Other columns describe the values of stimulus parameters on those sweeps.
-
allensdk.brain_observatory.ecephys.stimulus_table.ephys_pre_spikes.
make_spontaneous_activity_tables
(stimulus_tables, start_key='Start', end_key='End', duration_threshold=0.0)[source]¶ Fills in frame gaps in a set of stimulus tables. Suitable for use as the spontaneous_activity_tabler in create_stim_table.
Parameters: - stimulus_tables : list of pd.DataFrame
Input tables - should have start_key and end_key columns.
- start_key : str, optional
Column name for the start of a sweep. Defaults to ‘Start’.
- end_key : str, optional
Column name for the end of a sweep. Defaults to ‘End’.
- duration_threshold : numeric or None
If not None (default is 0), remove spontaneous activity sweeps whose duration is less than this threshold.
Returns: - list :
Either empty, or contains a single pd.DataFrame. The rows of the dataframe are spontenous activity sweeps.
-
allensdk.brain_observatory.ecephys.stimulus_table.ephys_pre_spikes.
read_stimulus_name_from_path
(stimulus)[source]¶ Obtains a human-readable stimulus name by looking at the filename of the ‘stim_path’ item.
Parameters: - stimulus : dict
must contain a ‘stim_path’ item.
Returns: - str :
name of stimulus
-
allensdk.brain_observatory.ecephys.stimulus_table.ephys_pre_spikes.
split_column
(table, column, new_columns, drop_old=True)[source]¶ Divides a dataframe column into multiple columns.
Parameters: - table : pandas.DataFrame
Columns will be drawn from and assigned to this dataframe. This dataframe will NOT be modified inplace.
- column : str
This column will be split.
- new_columns : dict, mapping strings to functions
Each key will be the name of a new column, while its value (a function) will be used to build the new column’s values. The functions should map from a single value of the original column to a single value of the new column.
- drop_old : bool, optional
If True, the original column will be dropped from the table.
Returns: - table : pd.DataFrame
The modified table