Locomotion Code Doc
- Locomotion.MWW_test(result, result_Ctr, exp_parameter='STN', mouse_type='Vglut2D2')
Return two-sided Mann-Whitney test for ON-laser period velocity between Ctr and ChR2.
- Parameters
result (df) – a data frame containing mean velocity for ChR2 mice.
result_Ctr (df) – a data frame containing mean velocity for Control mice.
mouse_type (str) – mouse type as a string e.g. FoxP2, D2, Vglut2 ..
- Returns
stat – MWW stat results
- Return type
obj
- Locomotion.align_right_left(right, left)
Correct if for any reason there has been a shift between labelings of right and left side
- Parameters
right (1-D array) – position in time detected from the right camera
left (1-D array) – position in time detected from the left camera
- Locomotion.annotate_conditions(ax, conditions, y=0.9, fontsize=30)
write grouping condition for each double column of “ON”-“OFF”.
- Parameters
ax (obj) – plot axis.
y (float) – y axes-fraction of the text.
conditions (list(str)) – conditions corresponding to each double column
- Return type
None.
- Locomotion.annotate_n_trials(ax, n_dict, key, xy=(0.5, 0.1), txt='N = ', fontsize=20)
Annotate the number of trials for the provided key within the n_dict.
- Parameters
ax (Axesplot) – matplotlib axis.
n_dict (dict-like) – dictionary of number of trials.
key (str, or tuple) – key for which the number needs to be retrieved.
xy (tuple(float), optional) – x and y coordinate of the text annotated in axes fraction. The default is (0.5, 0.1).
txt (str, optional) – Text informing about the number. The default is ‘N = ‘.
fontsize (float, optional) – fontsize of text. The default is 20.
- Returns
exists – Returns True if the key exists and False otherwise.
- Return type
bool
- Locomotion.annotate_n_trials_all_conditions(ax, n_trials_dict, y=0.02, fontsize=30)
write number of trials for each double column of “ON”-“OFF”.
- Parameters
ax (obj) – plot axis.
n_trials_dict (dict) – dictionary with values as number of trials and keys as condition of the column.
y (float) – y axes-fraction of the text.
- Return type
None.
- Locomotion.average_position_r_l(df, window, misdetection_dict, cor, body_part, plot_param)
Return three-level correction of the average between right and left side for multiple selected body-parts.
Extract the right and left trace for each selected body part, correct right and left traces with “compare_r_l_correct_misdetect”, then average over right and left and remove jitters by calling “correct_labeling_jitter”. Then return the moving average of all selected body-parts.
- Parameters
df (dataframe) – Dataframe derived from DLC for one session of one animal
window (int) – Moving average window for smoothing the position time series
misdetection_dict (dict-like) – dict-like containing constants for misdetection corrections
cor (str) – Which coordinate to work with. e.g. ‘x’ or ‘y’
body_part (list(str)) – Which body parts to average over.
plot_param (str) – Parameter for analysis e.g. position or velocity.
- Returns
corrected_averaged – Moving average of all selected body-parts.
- Return type
1-D array
- Locomotion.categorize_pre_x_and_v(result, back_front_boundary, v_threshold, pre_stim_inter)
Set threshold to velocity and x position averaged over pre_stim_inter.
- Parameters
result (dataframe) – dataframe containing information of all animals
back_front_boundary (float) – Threshold to set the position of the animal before the laser onset as either ‘back’ or ‘front’
v_threshold (float) – Threshold to set the velocity of the animal before the laser onset as either ‘pos’ or ‘neg’
pre_stim_inter (int) – Pre interval for averaging the positions/velocity and accelaration and report as pre_info
- Returns
result – the dataframe as the input but with the difference that pre_X_front_back and pre_velocity_sign set to binary(str) values accorfing to values.
- Return type
dataframe
- Locomotion.check_DLC_corresponds_to_laser(filepath_laser, filepath_DLC)
Return true if the filename except for the last elemet is the same between the DLC and the laser files.
- Locomotion.choose_n_from_colormap(cmap, minval=0.0, maxval=1.0, n_colors=100)
Return ‘n’ equally distanced colors from the colormap
- Locomotion.compare_analysis_file(path1, path2)
match experiment analysis filenames between two directories and report comparison
- Locomotion.compare_r_l_correct_misdetect(right_p, left_p, acc_deviance, t_s, internal_ctr_dev=0.5, percent_thresh_align=0.8, n_iter_jitter=1, jitter_threshold=0.5)
- Compare the right and left sides and correct if the difference between
the two is more than an acceptable amount.
- Parameters
right_p (1-D array) – Position in time detected from the right camera
left_p (1-D array) – Position in time detected from the left camera
acc_deviance (float) – Passed within misdetect dict-like. Acceptable deviance of the right and left side detections
t_s (int) – The number of procedeeing and post time bins to average from and correct the misdetection with
internal_ctr_dev (float) – The threshold (cm) by which it is allowed for left and right detections to differ.
percent_thresh_align (int) – The percentage above which it’s decided that there is a systematic shift between the right and left side detections.
- Returns
right (1-D array) – Corrected position in time detected from the right camera
left (1-D array) – Corrected position in time detected from the left camera
- Locomotion.convert_all_xlsx_to_csv(path)
conver all xlsx files to csvs under the given path
- Locomotion.convert_csv_to_xlsx(path)
Check if a .xlsx version of all the .csv files exists, if not convert to this format and remove the .csv to save space
- Locomotion.correct_accep_interval_range_for_beta(accep_interval_range, stim_type)
beta stimulation doesn’t include the last half cycle so it’s shorter. Therefore the acceptable range is coorected to be smaller
- Locomotion.correct_labeling_jitter(x, jitter_threshold, n_iter_jitter, t_s, acc_deviance=0, internal_ctr_dev=0, percent_thresh_align=0)
Correct the detections exceeding the max speed of the mouse.
The detected jitters are replaced by the average of before and after time stamps.
- Parameters
x (1-D array) – The time series that needs correction (usually the average of right and left cameras).
jitter_threshold (float) – The allowed maximum movement in one timebin with the max allowed velocity.
n_iter_jitter (int) – Number of times to repeat the correction algorithm.
t_s (int) – The number of timebins to average from when correcting the jitter point.
- Returns
x – The corrected time series.
- Return type
1-D array
- Locomotion.create_colormaps_for_beta_square_pulses(beta=['Oranges_r', 'Blues'], square=['Reds_r', 'Greens'])
create colormaps for square and beta stimulations by creating a spectrum between the two given colors.
- Parameters
beta (list(str), optional) – colormaps to be joined representing beta stimulations. The default is [‘Oranges_r’, ‘Blues’].
square (list(str), optional) – colormaps to be joined representing beta stimulations. The default is [‘Reds_r’, ‘Greens’].
- Returns
beta_cm (obj) – beta colormap.
square_cm (obj) – square colormap.
- Locomotion.create_df_from_data_summary(summary_files_list, intervals_dict, opto_par='ChR2', report_stats=True)
‘append the summary df of all files given in the list
- Locomotion.create_mouse_color_dict(mouse_dict, mouse_color_opto_dict)
Assign colors to each individual mouse in the mouse_dict.
- Parameters
mouse_dict (dict) – dictionary of mouse numbers for each mouse line and optogenetic expression.
mouse_color_opto_dict (dict) – dictionary of color lists for the different optogenetic expressions.
- Returns
mouse_color_dict – dictionary of colors for each mouse number in mouse_dict.
- Return type
dict
- Locomotion.create_pulse_specific_color_lists(pulse_cmap, stim_type_dict)
create color dict for different stimulation protocols
- Locomotion.create_x_position_pairs(ax, pad=0.2)
Create x pairs between pairs of x ticks.
- Parameters
ax (axes.SubplotBase) – The axes of the subplot..
pad (float, optional) – distancing from the tick positions. The default is 0.2.
- Returns
x_series – array of pairs of x positions.
- Return type
2D-array(float)
- Locomotion.csv_from_excel(filepath)
Convert xlsx file to csv
- Locomotion.delta_v_vs_laser_intensity(pre_direct, intervals_dict, opto_par='ChR2', stim_loc='STR', mouse_type='Vglut2D2', pulse='beta', measure='mean')
extract the (means, std) of the changes from baseline to when laser-ON velocity for different laser intensities. Note that this function requires sorted file hierarchy.
- Locomotion.derivative(x, delta_t, fps)
Take the derivative over delta_t.
- Locomotion.derivative_mov_ave(x, delta_t, window_veloc, fps)
Take the derivative with delta_t and do a moving average.
- Locomotion.epochs_stats(epochs, epochs_spont)
Return mean and confidence intervals of epochs
- Parameters
epochs (2D array(float)) – Trials containtning laser stimulation aligned in rows. n_col = pre_interval + interval + post_interval
epochs_spont (2D array(float)) – same as epochs only for spontaneous sessions with no laser stimulation.
Returns –
-------- –
epochs_mean (2D array(float)) – average of epochs for all trials (averaged over rows)
epochs_mean_spont (2D array(float)) – average of epochs_spont for all trials (averaged over rows)
confidence_inter (2D array(float)) – 95% confidence interval of epochs
confidence_inter_spont (2D array(float)) – 95% confidence interval of epochs_spont
- Locomotion.extract_epochs(bins, x, smallest_accep_inter, largest_accep_inter, pre_interval, interval, post_interval, session_length)
Extract the (pre | Laser ON | post) epochs.
Check reported (start,end) of trials from bins and discard trial with unacceptable duration. Return the stacked the corresponding frames of all trials from the measurment array x.
- Parameters
bins (2D-array(int)) – array of start and end times for trials
smallest_accep_inter (int) – Smallest acceptable duration of an interval in frames
largest_accep_inter (int) – Largest acceptable duration of an interval in frames
pre_interval (int) – Number of time bins to be taken into account before laser onset
interval (int) – Laser duration in timebins.
post_interval (int) – Number of time bins to be taken into account after laser onset
- Returns
epochs (2D array(float)) – Trials containtning laser stimulation aligned in rows. n_col = pre_interval + interval + post_interval
n_trials (int) – Number of trials
take (1D array(int)) – Array of indices corresponding to pre | on | post epoch frmaes.
- Locomotion.extract_epochs_over_trials(files_list_DLC, files_list_laser, direct, stim_loc, stim_type, scale_pix_to_cm, accep_interval_range, default_treadmill_velocity, spont_trial_dict, misdetection_dict, study_param_dict, pre_interval, interval, post_interval, pre_stim_inter, fps, n_timebin, window_veloc, window_pos, n_samples=25, spont=True)
Return all the epochs of all similar trials for one mouse.
- Parameters
files_list_DLC (list(str)) – List of paths to all DLC .csv files for sessions
files_list_laser (list(str)) – List of paths to all .csv files that have (start,end) laser times.
direct (str) – Path to the parent directory containing all stim_types
stim_loc (str) – the folder with the corresponding experiment brain location e.g. “STR”.
stim_type (str) – folder containing sessions for this particular protocol
scale_pix_to_cm (float) – Scaling coefficient converting pixels to cm
spont (str) – Either False –> for trials containing laser stimulation or ‘y’ –> for spontaneous trials with no laser
accep_interval_range (tuple(int)) – Smallest and largest acceptable trial sizes in timebins
spont_trial_dict (dict-like) – {‘max_distance’ : int (max n_timebins between sampled epochs for spontaneous), ‘min_distance’ : int (min #n_timebines between sampled epochs for spontaneous), ‘n_trials_spont’ : int (the average number of trials extracted from one spontaneous session)}
misdetection_dict (dict-like) – Dictionary of constants used in the misdetection correction algorithm: {‘acc_deviance’ : float (acceptable deviance between right and left detections), ‘internal_ctr_dev’ : float, ‘percent_thresh_align’ : int, ‘t_s’ : int (number of time steps before and after to look at), ‘n_iter_jitter’ : int (how many times go over data to find jitters and clear them out), ‘jitter_threshold’ : int (max_speed/fps)}
study_param_dict (dict-like) – Dictionary of values regarding coordinate (x,y), body part (list of body parts) and plot parameter (position, velocity, acceleration) packed from input of user
pre_interval (int) – Number of time bins to be taken into account before laser onset
interval (int) – Laser duration in timebins.
post_interval (int) – Number of time bins to be taken into account after laser onset
pre_stim_inter (int) – Pre interval for averaging the positions/velocity and accelaration and report as pre_info
fps (int) – Frame per second of the video
n_timebin (int) – Number of frames as timebins for the x derivative to yields velocity
window_veloc (int) – Velocity moving average window in frames
window_pos (int) – Position moving average window in frames
n_samples (int, optional) – Number of samples to extract from one spontaneous session. Only necessary for spont = ‘y’ cases.
- Returns
epochs (2D array(float)) – (pre | Laser ON | post) epochs with shape (n_trials, pre_interval+post_interval+interval+1)
pre_info (2D array(float)) – Three columns with averages of : pre_x , pre_v, pre_acceleration over pre_stim_interval duration. with shape (n_trials, 3)
- Locomotion.extract_epochs_over_trials_one_side_one_body_part(files_list_DLC, files_list_Laser, direct, stim_loc, stim_type, scale_pix_to_cm, accep_interval_range, treadmill_velocity, misdetection_dict, pre_interval, interval, post_interval, fps, n_timebin, window_veloc, window_pos, cor, body_part, plot_param, left_or_right='right')
Return all the epochs of all simillar trials for one mouse.
- Parameters
files_list_DLC (list(str)) – List of paths to all DLC .csv files for sessions
files_list_laser (list(str)) – List of paths to all .csv files that have (start,end) laser times.
direct (str) – Path to the parent directory containing all stim_types
stim_loc (str) – the folder with the corresponding experiment brain location e.g. “STR”.
stim_type (str) – Folder containing sessions for this protocol
scale_pix_to_cm (float) –
accep_interval_range (tuple(int)) – Smallest and largest acceptable trial sizes in timebins
misdetection_dict (dict-like) – dictionary of constants used in the misdetection correction algorithm: {‘acc_deviance’ : float (acceptable deviance between right and left detections), ‘internal_ctr_dev’ : float, ‘percent_thresh_align’ : int, ‘t_s’ : int (number of time steps before and after to look at), ‘n_iter_jitter’ : int (how many times go over data to find jitters and clear them out), ‘jitter_threshold’ : int (max_speed/fps)}
pre_interval (int) – Number of time bins to be taken into account before laser onset
interval (int) – Laser duration in timebins.
post_interval (int) – Number of time bins to be taken into account after laser onset
pre_stim_inter (int) – Pre interval for averaging the positions/velocity and accelaration and report as pre_info
fps (int) – Frame per second of the video
n_timebin (int) – Number of frames as timebins for the x derivative to yields velocity
window_veloc (int) – Velocity moving average window in frames
window_pos (int) – Position moving average window in frames
left_or_right (str, optional) – Either left side or right side. Default value is set to ‘right’.
- Returns
epochs – (pre | Laser ON | post) epochs with shape (n_trials, pre_interval+post_interval+interval+1)
- Return type
2D-array
- Locomotion.extract_info_from_npz_filename(filename)
extract info about experiment from the summary npz file
- Locomotion.extract_info_from_saved_data(filename, intervals_dict, opto_par='ChR2', report_stats=True)
- for the given filename extract information from filename and create the mean velocity pre/post laser
in a dataframe
- Parameters
filename (str) – DESCRIPTION.
intervals_dict (dict-like) –
- dict-like of interals:{‘pre_interval’int(.5*fps), # interval before laser onset
’interval’ : int(interval_in_sec * fps), # number of timebins of stimulation ‘post_interval’ : int(.5*fps*2), # interval after laser onset ‘pre_stim_inter’ : pre_stim_inter }
opto_par (str, optional) – e.g. ChR2 or Control. The default is ‘ChR2’.
report_stats (bool, optional) – whether report the statistical tests. Default is True.
- Returns
df (dataframe) – dataframe summerizing all data.
info (dict) – information about the file extracted from its name.
- Locomotion.extract_pre_laser_x_epochs_over_trials(files_list, files_list_laser, direct, stim_loc, stim_type, scale_pix_to_cm, window_pos, misdetection_dict, smallest_accep_inter, largest_accep_inter, pre_stim_inter)
Return all the x positions in epochs preceding to a ON-laser of all trials for one mouse.
- Parameters
files_list (list(str)) – List of the file names of the sessions
files_list_laser – List of file names for laser detections
pre_direct (str) – Path to the root directory of the project
stim_loc (str) – the folder with the corresponding experiment brain location e.g. “STR”.
stim_type (str) – Folder containing this specific protocol.
scale_pix_to_cm (float) – Scaling coeficient for pixels to cm.
window_pos (int) – Moving average window for position
misdetection_dict (dict-like) – dict-like containing constants for misdetection corrections
smallest_accep_inter (int) – Smallest acceptable duration of an interval in frames
largest_accep_inter (int) – Largest acceptable duration of an interval in frames
pre_stim_inter (int) – Pre interval for averaging the positions/velocity and accelaration and report as pre_info
- Returns
epochs – X positions prior to laser stimulation aligned in rows. n_col = pre_stim_inter
- Return type
2D array(float)
- Locomotion.filter_based_on_substring(string_list, contains, not_contains=[])
keep only strings that include the all the given substrings in contains
- Locomotion.find_filepaths_for_stim_type_and_loc_list(stim_loc_list, pre_direct, stim_type_list, opto_par)
- Parameters
stim_loc_list (list(str)) – stimulation locaiton list.
pre_direct (str) – path to the project root.
stim_type_list (list(str)) – stimulation type (pulse + intesity) list.
opto_par (str) – optogenetic expression.
- Returns
summary_files_list – list of file paths satisfying the input arguments.
- Return type
list(str)
- Locomotion.find_filepaths_of_corresponding_stim_loc_for_mouse_type(pre_direct, opto_par, stim_type_list, mouse_type_to_loc_dict)
Find filepaths of the summary files with corresponding stim type –> stim_loc –> mouse_type charecterestics.
- Parameters
pre_direct (str) – path to project root.
opto_par ({'ChR2', 'Control'}) – optogenetic expression.
stim_type_list (list(str)) – stim type protocol.
mouse_type_to_loc_dict (dict-like) – dictionary coupling mouse type to the desired stim location.
- Returns
summary_files_list – filepaths.
- Return type
list(str)
- Locomotion.find_files_containing_substring(path, substring)
Walk in all subfolders and return all files containing substring.
- Parameters
path (str) – path to lood under for files.
substring (str) – substring that is required to be contained in path.
- Returns
files – list of files under path containing substring.
- Return type
list(str)
- Locomotion.find_header_line_laser_file_csv(path)
Find which line includes the headers of ‘ON’ and ‘OFF in the csv file
- Locomotion.find_header_line_laser_file_excel(path)
Find which line includes the headers of ‘ON’ and ‘OFF in the excel file
- Locomotion.find_mouse_no(filepath)
extract the mouse number based on filename.
- Parameters
filepath (str) – path of the DLC file.
- Returns
mouse_no – mouse number.
- Return type
str
- Locomotion.find_session_day_tag(filepath)
extract the session tag that is e.g. [a, b, …][01, 02, ..] based on filename.
- Parameters
filepath (str) – path of the DLC file.
- Returns
day tag – 3 charecter tag assigned to one session of recording.
- Return type
str
- Locomotion.find_treadmill_velocity(filepath, default=15)
Determine the treadmill velocity based on filename.
- Parameters
filepath (str) – path of the DLC file.
- Returns
treadmill_velocity – The treadmill velocity in cm/s. If not specified in filename, default = 15 is returned.
- Return type
int
- Locomotion.flatten(t)
create a flattened list of the list of lists
- Locomotion.get_DLC_files(path)
Find DLC files
- Locomotion.get_extension(path)
return file extension from path
- Locomotion.get_input_cor_body_part(cor_list, body_part_list, plot_param_list)
Ask for the body part and coordinate from user.
- Parameters
cor_list (list(str)) – list of available coordinates e.g. ‘x’, ‘y’
body_part_list (list(str)) – list of DLC labeled body parts
plot_param_list (list(str)) – List of available parameters for analysis e.g position or velocity.
- Returns
study_param_dict – selected items from the options in the inputs
- Return type
dict-like
- Locomotion.get_laser_files(path)
Find laser files
- Locomotion.get_name(path)
Return filename from path
- Locomotion.get_nested_keys(dictionary)
Return the set of the keys of the dictionaries that are nested whithin the original dictionary
- Locomotion.get_pulse_list(protocol_dict, mouse_type, opto_par='ChR2')
get the list of all pulse types from the protocol dict for the specified mouse line
- Locomotion.get_set_of_sorted(d)
get set of dict values sort them and put back in dict
- Locomotion.get_sorted_laser_DLC_files(path)
print sorted files in laser and DLC folders to see if the match
- Locomotion.handle_legend_label(ax, label, stim_type, body_part, epochs, annotate_n)
Create the legend label based on the input parameters.
- Parameters
ax (object) – plot axis.
label (str) – Determining the variable to be reported as legend.
stim_type (str) – stimulation type and string joined with underscore.
body_part (list (str)) – list of tracked body parts.
epochs (nd-array (float)) – time epochs of all trials.
annotate_n (bool) – if True is True the number of trials is written as text in the plot otherwise it will be reported in the legend.
- Returns
ax (object) – plot axis.
label (TYPE) – text to be put in the plot object.
- Locomotion.input_plot(df, laser_t, mouse_type, mouse_no, trial_no, opto_par, pre_direct, exp_dict, t_window_dict, misdetection_dict, save_as_format='.pdf')
Get the specifics of the plot as input and call the corresponding plot function to plot the session.
- Parameters
df (Dataframe) – Dataframe derived from DLC for one session of one animal
laser_t (Dataframe) – Dataframe with laser onset and offset times as columns
mouse_type (str) – Mouse type. For example FoxP2
mouse_no (int) – Mouse number
trial_no (int) – Trial number specified in file name
opto_par (str) – Optogenetic specification. For example ChR2 or Control
pre_direct (str) – Path to the root directory of the project
exp_dict (dict-like) – Experiment dictionary for cor_list, body_part_list and plot_param_list
t_window_dict (dict-like) – Dictionary of time constants
misdetection_dict (dict-like) – Dictionary for misdetection algorithm constants
save_as_format (str, optional) – The extension of the saved figure
- Return type
None
- Locomotion.keep_corresponding_stim_loc_for_mouse_type(summary_files_list, mouse_type_to_loc_dict)
from the provided list of files only keep ones that correspond to the specified mouse_type –> stim_loc coupling in the dictionary
- Parameters
summary_files_list (list(str)) – filepaths.
mouse_type_to_loc_dict (dict-like) – dictionary coupling mouse type to the desired stim location .
- Returns
summary_files_list – filepaths.
- Return type
list(str)
- Locomotion.lighten_color(color, amount=0.5)
Lightens the given color by multiplying (1-luminosity) by the given amount. Input can be matplotlib color string, hex string, or RGB tuple.
Examples: >> lighten_color(‘g’, 0.3) >> lighten_color(‘#F034A3’, 0.6) >> lighten_color((.3,.55,.1), 0.5)
- Locomotion.list_all_files(path, extensions=['.xlsx', '.csv'])
List all the files with this extention in this directory
- Locomotion.min_and_mean_on_off(epochs, measure, pre_interval, interval, post_interval, pre_stim_inter)
Report the min or mean (specified by measure) velocity in the off-on periods.
- Parameters
epochs (2D array(float)) – Trial variables in rows. n_col = pre_interval + interval + post_interval
measure (str) – ‘mean’ or ‘min’
pre_interval (int) – Number of time bins to be taken into account before laser onset
interval (int) – Laser duration in timebins.
post_interval (int) – Number of time bins to be taken into account after laser onset
pre_stim_inter (int) – Unpacked in dict-like. Not used here.
- Returns
average_of_off_on_off – array of 3 columns. first column is the aversge of pre-intevsl, second the ‘measure’ during laser interval third again the average of post
- Return type
2D array
- Locomotion.min_velocity_diff_inten_box_plot(file_path_list, path_to_save, intervals_dict, pre_x_v_dict, ylim=[- 40, 15], save_as_format='.pdf')
Compare min velocity during laser for trials with positive and negative pre laser velocity.
Box plots to show this comparison for different intensity in same animal types.
- Parameters
file_path_list (list(str)) – list of paths to .npz files
path_to_save (str) – Path to save figure
intervals_dict (dict-like) –
- dict-like of interals:{‘pre_interval’int(.5*fps), # interval before laser onset
’interval’ : int(interval_in_sec * fps), # number of timebins of stimulation ‘post_interval’ : int(.5*fps*2), # interval after laser onset ‘pre_stim_inter’ : pre_stim_inter }
pre_x_v_dict (dict-like) –
- {‘back_front_boundary’(treadmill_len-elec_shock)/2, # set the limit below which is considered back of the treadmill
’v_threshold’ : 0, ‘pre_stim_inter’ : pre_stim_inter # number of timebins in the pre-stimulus period}
ylim (list(float), optional) – y axis limits for figure. Default is set to [-40,15]
save_as_format (str, optional) – format to save the figure. Default is set to ‘.pdf’
- Locomotion.min_velocity_mouse_type_box_plot(file_path_list, path_to_save, intervals_dict, pre_x_v_dict, ylim=[- 40, 15], save_as_format='.pdf')
Compare min velocity during laser.
Box plots to show this comparison FOR trials with positive and negative pre laser velocity for same intensity in different animal types.
- Parameters
file_path_list (list(str)) – list of paths to .npz files
path_to_save (str) – Path to save figure
intervals_dict (dict-like) –
- dict-like of interals:{‘pre_interval’int(.5*fps), # interval before laser onset
’interval’ : int(interval_in_sec * fps), # number of timebins of stimulation ‘post_interval’ : int(.5*fps*2), # interval after laser onset ‘pre_stim_inter’ : pre_stim_inter }
pre_x_v_dict (dict-like) –
- {‘back_front_boundary’(treadmill_len-elec_shock)/2, # set the limit below which is considered back of the treadmill
’v_threshold’ : 0, ‘pre_stim_inter’ : pre_stim_inter # number of timebins in the pre-stimulus period}
ylim (list(float), optional) – y axis limits for figure. Default is set to [-40,15]
save_as_format (str, optional) – format to save the figure. Default is set to ‘.pdf’
- Locomotion.move_unwanter_files_out_of_folder(path)
move all non csv xlsx files out of the Laser and DLC subdirectory
- Locomotion.moving_average_array(X, n)
Return the moving average over X with window n without changing dimesions of X
- Locomotion.no_files(files, mouse_no, dtype='DLC')
Report True the there are no ‘dtype’ files for this mouse
- Locomotion.plot_ON_OFF_measure(result, pre_direct, mouse_type, opto_par, stim_loc, stim_type, fps, back_front_boundary, v_threshold, pre_stim_inter, ylim=[- 1, 2], velocity_measure='norm_velocity (mean)', save_as_format='.pdf', axes=[], save=True, title=True, legend=False, group_by=['pre_velocity_sign', 'epoch'], conditions=['pos', 'neg'], colors=['teal', 'blueviolet'], alphas=[1, 1], lstyles=['-', '-'])
Plot the mean laser-ON laser-OFF velocity measure with distinction of the groupby elements provided prior to laser stim.
- Parameters
result (dataframe) – dataframe containing information of all animals
pre_direct (str) – Path to save the figure
opto_par (str) – optogenetic expression.
mouse_type (str) – mouse line.
stim_loc (str) – the folder with the corresponding experiment brain location e.g. “STR”.
stim_type (str) – Folder containing the experiment sessions
back_front_boundary (float) – Threshold to set the position of the animal before the laser onset as either ‘back’ or ‘front’
v_threshold (float) – Threshold to set the velocity of the animal before the laser onset as either ‘pos’ or ‘neg’
pre_stim_inter (int) – Pre interval for averaging the positions/velocity and accelaration and report as pre_info
ylim (list(float), optional) – Y axis limits for the figure, default set to [-20,15]
axes (list(Axes), optional) – list of 2 Axes. The default is an empty list.
velocity_measure (['norm_velocity (mean)', 'norm_velocity (min)']) – value reported in plot.
save_as_format (str, optional) – Format to save the figure default is ‘.pdf’
{[] (axes =) – if axes provided the two conditions are plotted in separate axes. Otherwise will be plotted on the same axis.
axes} – if axes provided the two conditions are plotted in separate axes. Otherwise will be plotted on the same axis.
optional – if axes provided the two conditions are plotted in separate axes. Otherwise will be plotted on the same axis.
save (bool(default: True)) – if save figure.
title (bool(default=True)) – if put title.
legend (bool(default=True)) – if put legend.
groupby ({['pre_velocity_sign', epoch'],) –
- [‘pre_accel_sign’, epoch’],
[‘pre_accel_sign’, epoch’], ..}, optional
The columns of result dataframe to group by. Note that when providing three columns the conditions list should be adjusted to include the conditions other that ‘epoch’ in each element. Default is [‘pre_velocity_sign’, epoch’].
conditions ({['pos', 'neg'],) – [[‘pos’, ‘front’], [‘neg’, ‘front’]], …}, optional The list of conditions to plot the measure for. the default is [‘pos’, ‘neg’].
colors (list of matplotlib colors, optional) – list of colors for different conditions. The default is colors = [‘teal’, ‘blueviolet’].
alphas (list(float), optional) – list of saturation alphas for the lines drawn. The elements should correspond to the number of elements in conditions.The default is [1, 1].
ls (list of matplotlib linestyles, optional.) – linestyles of each plotted line. The defautl is [‘-’, ‘-‘].
- Return type
None
- Locomotion.plot_ON_OFF_measure_with_x_distionction(result, pre_direct, mouse_type, opto_par, stim_loc, stim_type, fps, back_front_boundary, v_threshold, pre_stim_inter, ylim=[- 1, 2], velocity_measure='norm_velocity (mean)', save_as_format='.pdf', axes=[], save=False, title=False, legend=False, group_by=['pre_velocity_sign', 'pre_x_front_back', 'epoch'], conditions=[['pos', 'front'], ['neg', 'front']], colors=['teal', 'blueviolet'], alphas=[1, 1], lstyles=['-', '-'], position_conditions=['front', 'back'])
Plot the mean laser-ON laser-OFF velocity measure with distinction of the groupby elements provided prior to laser stim which includes position.
- Parameters
result (dataframe) – dataframe containing information of all animals
pre_direct (str) – Path to save the figure
opto_par (str) – optogenetic expression.
mouse_type (str) – mouse line.
stim_loc (str) – the folder with the corresponding experiment brain location e.g. “STR”.
stim_type (str) – Folder containing the experiment sessions
back_front_boundary (float) – Threshold to set the position of the animal before the laser onset as either ‘back’ or ‘front’
v_threshold (float) – Threshold to set the velocity of the animal before the laser onset as either ‘pos’ or ‘neg’
pre_stim_inter (int) – Pre interval for averaging the positions/velocity and accelaration and report as pre_info
ylim (list(float), optional) – Y axis limits for the figure, default set to [-20,15]
axes (list(Axes), optional) – list of 2 Axes. The default is an empty list.
velocity_measure (['norm_velocity (mean)', 'norm_velocity (min)']) – value reported in plot.
save_as_format (str, optional) – Format to save the figure default is ‘.pdf’
{[] (axes =) – if axes provided the two conditions are plotted in separate axes. Otherwise will be plotted on the same axis.
axes} – if axes provided the two conditions are plotted in separate axes. Otherwise will be plotted on the same axis.
optional – if axes provided the two conditions are plotted in separate axes. Otherwise will be plotted on the same axis.
save (bool(default: True)) – if save figure.
title (bool(default=True)) – if put title.
legend (bool(default=True)) – if put legend.
groupby ({['pre_velocity_sign', epoch'],) –
- [‘pre_accel_sign’, epoch’],
[‘pre_accel_sign’, epoch’], ..}, optional
The columns of result dataframe to group by. Note that when providing three columns the conditions list should be adjusted to include the conditions other that ‘epoch’ in each element. Default is [‘pre_velocity_sign’, ‘pre_x_front_back’, ‘epoch’].
conditions ({['pos', 'neg'],) – [[‘pos’, ‘front’], [‘neg’, ‘front’]], …}, optional The list of conditions to plot the measure for. the default is [[‘pos’, ‘front’], [‘neg’, ‘front’]].
colors (list of matplotlib colors, optional) – list of colors for different conditions. The default is colors = [‘teal’, ‘blueviolet’].
alphas (list(float), optional) – list of saturation alphas for the lines drawn. The elements should correspond to the number of elements in conditions.The default is [1, 1].
ls (list of matplotlib linestyles, optional.) – linestyles of each plotted line. The defautl is [‘-’, ‘-‘].
- Locomotion.plot_every_mouse_mean(epochs_mean_each_mouse)
plot mean of each mouse for epochs OFF-ON-OFF
- Locomotion.plot_pre_on_post(pre_direct, mouse_type, opto_par, stim_loc, stim_type, epochs, epochs_spont, treadmill_velocity, ylim, fps, n_timebin, window_pos, window_veloc, cor, body_part, plot_param, pre_interval, interval, post_interval, pre_stim_inter, average='all_mice', c_laser='deepskyblue', c_spont='k', save_as_format='.pdf', title=True, plot_spont=True, label='body-part', annotate_n=False, axvspan=True, multi_region=False, save_fig=True, ax=None, x_label_list=[], y_label_list=[], legend_loc='upper left', legend_fontsize=15, bbox_to_anch_leg=(0.1, 1))
Plot (pre Laser | Laser | post Laser) velocity/position/acceleration comparison between laser and spontaneous trials.
- Parameters
ax (ax) –
pre_direct (str) – Path to project directory
mouse_type (str) – Type of the animal that makes it different in the experiment e.g. for transgenic mice ‘FoxP2’ or ‘Vglut2’.
opto_par (str) – Optogentic parameter distinguishing injections. e.g. ‘Control’ or ‘ChR2’.
stim_loc (str) – the folder with the corresponding experiment brain location e.g. “STR”.
stim_type (str) – folder containing this specific protocol’s sessions e.g. ‘Square_1_mW’
epochs (2D array(float)) – Trials containtning laser stimulation aligned in rows. n_col is equal to pre_interval + interval + post_interval
epochs_spont (2D array(float)) – Spontaneous trials aligned in rows. n_col is equal to pre_interval + interval + post_interval
treadmill_velocity (float) – Treadmill velocity in cm/s
ylim (list(float)) – Y axis limits for the figure given as a list : [ymin, ymax]
fps (int) – frame per second of the video
n_timebin (int) – number of timebins for taking derivatives
window_pos (int) – Moving average window for position
window_veloc (int) – Moving average window for velocity
cor (str) – Which coordinate to work with. e.g. ‘x’ or ‘y’
body_part (list(str)) – Which body parts to average over.
plot_param (str) – Parameter for analysis e.g. position or velocity.
pre_interval (int) – Number of time bins to be taken into account before laser onset
interval (int) – Laser duration in timebins.
post_interval (int) – Number of time bins to be taken into account after laser onset
pre_stim_inter (int) – Pre interval for averaging the positions/velocity and accelaration and report as pre_info
average (str, optional) – Parameter specifying the output figure. Here default set to ‘Averg_trials_all_mice’.
c_laser (str, optional) – color for plotting trials with laser stimulation. Default value is set to ‘deepskyblue’.
c_spont (str, optional) – color for plotting trials with laser stimulation. Default value is set to ‘k’ which is black.
save_as_format (str, optional) – Format to save the figure with. Default set to ‘.pdf’
- Return type
None
- Locomotion.plot_two_protocols_with_mouse_distinction(mouse_type, mouse_list, stim_loc, stim_type1, stim_type2, opto_par)
Extract data over all mice of one group in two stim_types intensity and plot with subplots of individual animals
- Locomotion.plot_velocity_phase_space(result, pre_direct, mouse_type, opto_par, stim_loc, stim_type, fps, back_front_boundary, v_threshold, pre_stim_inter, xlim=[- 1, 3], ylim=[- 1, 3], velocity_measure='norm_velocity (mean)', save_as_format='.pdf')
Plot the phase space of laser-ON vs. laser-OFF velocity for all trials of all mice.
- Parameters
result (dataframe) – dataframe containing information of all animals pre_direct : str Path to save the figure
opto_par (str) – optogenetic expression.
mouse_type (str) – mouse line.
stim_loc (str) – the folder with the corresponding experiment brain location e.g. “STR”.
stim_type (str) – Folder containing the experiment sessions
back_front_boundary (float) – Threshold to set the position of the animal before the laser onset as either ‘back’ or ‘front’
v_threshold (float) – Threshold to set the velocity of the animal before the laser onset as either ‘pos’ or ‘neg’
pre_stim_inter (int) – Pre interval for averaging the positions/velocity and accelaration and report as pre_info
xlim (list(float), optional) – X axis limits for the figure, default set to [-25,32]
ylim (list(float), optional) – Y axis limits for the figure, default set to [-20,15]
velocity_measure (['norm_velocity (mean)', 'norm_velocity (min)']) – value reported in plot.
save_as_format (str, optional) – Format to save the figure default is ‘.pdf’
- Locomotion.plot_what_which_where(df, laser_t, mouse_type, mouse_no, trial_no, opto_par, pre_direct, misdetection_dict, cor, body_part, plot_param, fps, n_timebin, window_pos, window_veloc, save_as_format='.pdf')
Choose to see averaged velocity, position or acceleration for a chosen combination of body_parts for either x or y coordiante.
- Locomotion.plot_what_which_where_r_l(df, laser_t, mouse_type, mouse_no, trial_no, opto_par, pre_direct, misdetection_dict, cor, body_part, plot_param, fps, n_timebin, window_pos, window_veloc, save_as_format='.pdf')
Choose which body part/what measure/ x or y to see the left vs. right traces.
- Locomotion.position_r_l(df, window, misdetection_dict, cor, body_part, plot_param)
Remove jitters with “correct_labeling_jitter” on right and left on the selected body parts and return right and left separately.
- Parameters
df (dataframe) – Dataframe derived from DLC for one session of one animal
window (int) – Moving average window for smoothing the position time series
misdetection_dict (dict-like) – dict-like containing constants for misdetection corrections
cor (str) – Which coordinate to work with. e.g. ‘x’ or ‘y’
body_part (list(str)) – Which body parts to average over.
plot_param (str) – Parameter for analysis e.g. position or velocity.
- Returns
right_corrected (1-D array) – Moving average of right side for all selected body-parts
left_corrected (1-D array) – Moving average of left side for all selected body-parts
- Locomotion.produce_random_bins_for_spont(max_time, n_sample, pre_interval, interval, post_interval, max_distance, min_distance, n_trials_spont)
Produce a grid for start of bins then perturb to have randomly spaced trials with a minimum and maximum distance between them.
- Parameters
max_time (int) – number of timebins of the spontaneous session
n_sample (int) – number of trial samples that needs to be extracted from this session
max_distance (int) – maximum number of timebins between extracted trials
min_distance (int) – minimum number of timebins between extracted trials
- Returns
bins – an array with two columns each row containing (start,end) of each trial
- Return type
2D-array(int)
- Locomotion.read_DLC(filepath, scale_pix_to_cm)
Read DeepLabCut trackings of bodyparts.
- Parameters
filepath (str) – path of the DLC file.
scale_pix_to_cm (float) – scaling factor to transform DLC pixel values into cm.
- Raises
ValueError – Raises error if file type is not csv or xlsx.
- Returns
df – DLC output dataframe.
- Return type
dataframe
- Locomotion.read_laser(laser_file_name, DLC_file_name)
Read laser onset offset times for Square pulse stimulation
- Locomotion.read_laser_beta_stim(laser_t, min_t_between_stim=200)
Read laser onset offset times for laser detections of every beta cycle (Gilles’s)
- Locomotion.remove_epochs_with_unaccep_pre_post_interval(bins, pre_interval, post_interval, session_length)
Remove trials where extending the width to pre interval and post interval exceeds the session boundaries
- Locomotion.remove_xlsx_if_csv_exists(path)
remove matching xlsx if the equivalent csv file exists
- Locomotion.rename_laser_files_according_to_DLC(path)
rename matching the laser files to DLC files
Remove repeated axis labels
- Locomotion.rm_val_from_dict_if_exists_in_another(dictionary, ref_dictionary)
remove values that exist in the same key of the ref dictionary from dictionary and return
- Locomotion.run_one_intensity_save_data(pre_direct, scale_pix_to_cm, mouse_type, mouse_dict, stim_loc, stim_type, opto_par, treadmill_velocity, ylim, spont_trial_dict, misdetection_dict, intervals_dict, t_window_dict, accep_interval_range, study_param_dict, max_distance, min_distance, n_trials_spont, c_laser='deepskyblue', c_spont='k', fig=None, outer=None, n_inner=0, inner=None, axes=[], remove_empty_ax=True, label=None, annotate_n=False, title_manually=True, plot_spont=True, save_fig=True, suptitle_y=0.95, multi_region=False, axvspan=True, x_label_list=[], y_label_list=[])
Save data of epochs and individal mice to a npz file.
by running over all mice of one group and one intensity.
- Parameters
pre_direct (str) – path to rooot directory
scale_pix_to_cm (float) – SCaling coefficient for converting pixels to cm.
mouse_type (str) – mouse type such as FoxP2 etc
mouse_list (list(int)) – list of mouse identification numbers
stim_loc (str) – the folder with the corresponding experiment brain location e.g. “STR”.
stim_type (str) – the folder with the corresponding experiment protocol e.g. “Square_1_mW”.
opto_par (str) – ChR2 for ChR2 injected animals Control for Control group
treadmill_velocity (float) – Treadmill velocity in cm/s
ylim (list(float)) –
spont_trial_dict (dict-like) –
- dict-like with values{‘max_distance’int(4.5*fps), # max #n_timebines between sampled epochs for spontaneous
’min_distance’ : int(3*fps), # min #n_timebines between sampled epochs for spontaneous ‘n_trials_spont’ : 25 # the average number of trials extracted from one spontaneous session}
misdetection_dict (dict-like) – dictionary of constants used in the misdetection correction algorithm:
intervals_dict (dict-like) –
- dict-like of interals:{‘pre_interval’int(.5*fps), # interval before laser onset
’interval’ : int(interval_in_sec * fps), # number of timebins of stimulation ‘post_interval’ : int(.5*fps*2), # interval after laser onset ‘pre_stim_inter’ : pre_stim_inter }
t_window_dict (dict-like) – dict-like containing information about time contants of the project: t_window_dict = {fps : int, ‘n_timebin’ : int, ‘window_pos’ : int , ‘window_veloc’ : int}
accep_interval_range (tuple(int)) – Smallest and largest acceptable trial sizes in timebins
study_param_dict (dictionray) – dict-like of values regarding coordinate (x,y), body part (list of body parts) and plot parameter (position, velocity, acceleration) packed from input of user
max_distance (int) – maximum number of frames between sampled epochs for spontaneous
min_distance (int) – mainimum number of frames between sampled epochs for spontaneous
n_trials_spont (int) – number of spontaneous trials
- Locomotion.save_npz(pre_direct, mouse_type, opto_par, stim_loc, stim_type, fps, window, n_timebin, file_name_ext, epochs_all_mice, epochs_mean_each_mouse, epochs_spont_all_mice, epochs_tag, mouse_no_list, pre_info, cor, body_part, plot_param)
Save the trial epochs in one .npz file.
- Parameters
pre_direct (str) – path to rooot directory
mouse_type (str) – mouse type such as ‘FoxP2’ or ..
opto_par (str) – “ChR2” –> for ChR2 injected animals “Control” –> for Control group
stim_loc (str) – the folder with the corresponding experiment brain location e.g. “STR”.
stim_type (str) – the folder with the corresponding experiment protocol e.g. “Square_1_mW”.
pulse_inten (int) – Pulse intensity in mW
fps (int) – Frame per second
window (int) – Moving average window for position
n_timebin (int) – Number of frames to take derivative over
file_name_ext (str) – File name extension
epochs_all_mice (2D-array(float)) – (pre | Laser ON | post) epochs with shape (n_trials, pre_interval+post_interval+interval+1)
epochs_mean_each_mouse (2D-array(float)) – average of (pre | Laser ON | post) epochs with shape (n_animals, 3) averaged for individual animals
epochs_spont_all_mice (2D-array(float)) – (pre | Laser ON | post) spontaneous epochs with shape (n_trials, pre_interval+post_interval+interval+1)
epochs_tag (1D-array(str)) – trial tags of each extracted laser epoch.
pre_info (2D array(float)) – Three columns with averages of : pre_x , pre_v, pre_acceleration over pre_stim_interval duration. with shape (n_trials, 3)
cor_list (list(str)) – list of available coordinates e.g. ‘x’, ‘y’
body_part_list (list(str)) – list of DLC labeled body parts
plot_param_list (list(str)) – List of available parameters for analysis e.g position or velocity.
- Locomotion.save_npz_limb_and_tail(pre_direct, scale_pix_to_cm, mouse_type, mouse_list, stim_loc, stim_type, opto_par, misdetection_dict, pre_interval, interval, post_interval, t_window_dict, accep_interval_range, cor_list, body_part_list, plot_param_list)
Save data of epochs and individal mice to a npz file.
Run over all mice of one group and one intensity append epochs.
- Parameters
pre_direct (str) – path to rooot directory
scale_pix_to_cm (float) – Scaling coeficient for pixels to cm.
mouse_type (str) – mouse type such as FoxP2 or etc
mouse_list (list(int)) – list of mouse identification numbers
stim_loc (str) – the folder with the corresponding experiment brain location e.g. “STR”.
stim_type (str) – the folder with the corresponding experiment protocol e.g. Square_1_mW
opto_par (str) – ChR2 for ChR2 injected animals, Control for Control group
misdetection_dict (dict-like) – dictionary of constants used in the misdetection correction algorithm
pre_interval (int) – Number of time bins to be taken into account before laser onset
interval (int) – Laser duration in timebins.
post_interval (int) – Number of time bins to be taken into account after laser onset
t_window_dict (dict-like) – dictionary containing information about time contants of the project
accep_interval_range (tuple(int)) – Smallest and largest acceptable trial sizes in timebins
cor_list (list(str)) – list of available coordinates e.g. x, y
body_part_list (list(str)) – list of DLC labeled body parts
plot_param_list (list(str)) – List of available parameters for analysis e.g position or velocity
- Locomotion.save_pdf_png(fig, figname, size=(8, 6))
Save fig as pdf and png format
- Locomotion.set_ticks(ax)
set tick length and label fontsize
- Locomotion.set_x_ticks_one_ax(ax, label_list)
set x axis tick labels from list
- Parameters
ax (obj) – plot axis.
label_list (list (int)) – x axis tick labels.
- Returns
ax – plot axis.
- Return type
obj
- Locomotion.set_xy_ticks_one_ax(ax, x_label_list, y_label_list)
set x and y axis tick labels from list
- Parameters
ax (obj) – plot axis.
x_label_list (list (int)) – x axis tick labels.
y_label_list (list (int)) – y axis tick labels.
- Returns
ax – plot axis.
- Return type
obj
- Locomotion.set_y_ticks_one_ax(ax, label_list)
set y axis tick labels from list
- Parameters
ax (obj) – plot axis.
label_list (list (int)) – y axis tick labels.
- Returns
ax – plot axis.
- Return type
obj
- Locomotion.superimpose_intensities(opto_par_list, pulse_cmap_dict, protocol_dict, stim_loc_dict, pre_direct, scale_pix_to_cm, mouse_type, mouse_dict, treadmill_velocity, ylim, spont_trial_dict, misdetection_dict, intervals_dict, t_window_dict, accep_interval_range, study_param_dict, max_distance, min_distance, n_trials_spont, plot_spont=True, ylabel_x=0, xlabel_y=0.07, suptitle_y=0.98, c_spont='k', x_label_list=[], y_label_list=[])
Create a set of subplots with mice as rows and stimulation location as columns, superimposeing all intensities and creating new figures for different types of stimuli
- Locomotion.violin_plot_laser_ON_OFF(pre_direct, intervals_dict, opto_par, mouse_color_dict, mouse_type, subplot_parameter='stim_loc', fig_w=2, fig_h=4, velocity_measure='norm_velocity (mean)', stim_type_list=None, stim_loc_list=None, summary_files_list=None, savefig=True, pulse=None)
Plot distributions of normalized velocity in the laser ON and OFF epochs as subplots distinguishing the subplot_parameter.
- Parameters
pre_direct (str) – Path to the root directory of the project
intervals_dict (dict-like) –
- dict-like of intervals:{‘pre_interval’int(.5*fps), # interval before laser onset
’interval’ : int(interval_in_sec * fps), # number of timebins of stimulation ‘post_interval’ : int(.5*fps*2), # interval after laser onset ‘pre_stim_inter’ : pre_stim_inter
opto_par (str) – optogenetic expression.
mouse_color_dict (dict-like) – dictionary of colors for each mouse number.
mouse_type (str) – mouse line.
subplot_parameter (str, optional) – The parameter changing between the columns e.g. laser internsity or stim location. The default is ‘stim_loc’.
fig_w (float, optional) – individual double column width in inches. The default is 1.
fig_h (float, optional) – figure height in inches. The default is 4.
velocity_measure ({'norm_velocity (mean)', 'norm_velocity (min)'}, optional) – the measurement of the laser-ON and -OFF epochs.
stim_type_list (list(str), optional) – type of stimulation that includes the pulse type and intensity. The default is None.
stim_loc_list (list(str), optional) – list of stimulation brain structures.. The default is None.
summary_files_list (list(str), optional) – list of filepaths of experiments. The default is None where the function searches for the provided stim types and locs for the specified mouse type, otherwise input list is used.
savefig (bool, True) – if save generated figure.
pulse (str, optional) – stimulation type, to be added to the figname when subplot parameter is intensity
- Returns
ax – plot axis.
- Return type
obj
- Locomotion.violin_plot_summary(data_init, names, measure)
plot violin plot for different columns in data
- Locomotion.violin_plot_with_distiction(result, pre_direct, mouse_type, opto_par, stim_loc, stim_type, fps, back_front_boundary, v_threshold, pre_stim_inter, ylim=[- 1.5, 3], velocity_measure='norm_velocity (mean)', violin_alpha=0.5, x_distinction=True, save_as_format='.pdf', scale='area', colors=['teal', 'blueviolet'], velocity_conditions=['pos', 'neg'], position_conditions=['front', 'back'], alphas=[1, 0.6], ls=['-', '--'], column='pre_velocity_sign')
Plot violin plots with columns for pre laser velocity distinction and hue for back and front distinction on the treadmill.
- Parameters
result (dataframe) – dataframe containing information of all animals
pre_direct (str) – Path to save the figure
opto_par (str) – optogenetic expression.
mouse_type (str) – mouse line.
stim_loc (str) – the folder with the corresponding experiment brain location e.g. “STR”.
stim_type (str) – Folder containing the experiment sessions
back_front_boundary (float) – Threshold to set the position of the animal before the laser onset as either back or front
v_threshold (float) – Threshold to set the velocity of the animal before the laser onset as either pos or neg
pre_stim_inter (int) – Pre interval for averaging the positions/velocity and accelaration and report as pre_info
ylim (list(float), optional) –
Y axis limits for the figure, default set to [-1, 2] velocity_measure: [‘norm_velocity (mean)’, ‘norm_velocity (min)’]
value reported in plot.
alpha (float) – transparency of distribution
x_distinction (True, optional) – Whether separate x position as hue. Default is True
save_as_format (str, optional) – Format to save the figure default is ‘.pdf’
scale ({“area”, “count”, “width”}, optional) – The method used to scale the width of each violin. If area, each violin will have the same area. If count, the width of the violins will be scaled by the number of observations in that bin. If width, each violin will have the same width. The default is ‘area’.
colors (list of matplotlib colors, optional) – list of colors for different conditions. The default is [‘teal’, ‘blueviolet’].
velocity_conditions (list(str), optional) – The conditions for the pre_velocity_sign column of the data. The default is [‘pos’, ‘neg’].
position_conditions (list(str), optional) – The conditions for the pre_x_front_back column of the data. The default is [‘front’, ‘back’].
alphas (list(float), optional) – list of saturation alphas for the lines drawn. The elements should correspond to the number of elements in conditions.The default is [1, 1].
ls (list of matplotlib linestyles, optional.) – linestyles of each plotted line. The defautl is [‘-’, ‘-‘].
column (str, optional) – The measure that separates the columns of the catplot. The default is ‘pre_velocity_sign’.
- Return type
None.