bouter package¶
Submodules¶
bouter.angles module¶
-
bouter.angles.
angle_mean
(angles, axis=1)[source]¶ Correct calculation of a mean of an array of angles
- Parameters
angles –
axis – (Default value = 1)
-
bouter.angles.
quantize_directions
(angles, n_dirs=8)[source]¶ Bin angles into wedge bins
- Parameters
angles (array of angles) –
n_dirs (number of wedges to split circles into) –
- Returns
- Return type
bin indices of the angles
-
bouter.angles.
smooth_tail_angles
(tail_angles)[source]¶ Smooths out the tau jumps in tail angles, so that the angle between tail segments is smoothly changing
- Parameters
tail_angles – return:
-
bouter.angles.
smooth_tail_angles_series
(tail_angles_series)[source]¶ Smooths out the tau jumps in tail angles, so that the angle between tail segments is smoothly changing, applied on series
- Parameters
tail_angles – return:
tail_angles_series –
bouter.bout_stats module¶
bouter.decorators module¶
-
bouter.decorators.
cache_results
(cache_filename=None)[source]¶ Method decorator that caches an .h5 file with the results of the decorated function. This behavior can be disabled with the exp.cache_active flag. Function results are loaded if the new call arguments match the old call, or if the exp.default_cached flag is set. :param method: :param cache_filename: if not None, the cached value is written to a target (e.g. a log) :return:
bouter.descriptors module¶
All the hardcoded filenames and variable names.
bouter.df_utilities module¶
bouter.experiment module¶
-
class
bouter.experiment.
Experiment
(path, session_id=None, cache_active=False)[source]¶ Bases:
dict
- Parameters
path –
-
property
behavior_dt
¶
-
property
behavior_log
¶
-
copy_to_dir
(target_dir)[source]¶ Copy all the files pertaining to this experiment in a target directory. If it does not exist, make it.
-
property
estimator_log
¶
-
property
file_list
¶ As a property it automatically updates the cached files.
-
property
fish_id
¶
-
property
full_name
¶
-
invalidate_cache
()[source]¶ Invalidates the cached function results, but does not delete any files on disk
- Returns
-
property
params_filename
¶
-
property
processing_params
¶ As a property it automatically keeps the log in sync.
-
property
protocol_name
¶
-
property
protocol_parameters
¶ Goes around annoying problem of knowing experiment number and version as keywords for the stimulus parameters dictionary.
-
property
protocol_version
¶
-
property
stim_end_times
¶ Get start and end time of all stimuli in the log. :return: arrays with start and end times for all stimuli
-
property
stim_start_times
¶ Get start and end time of all stimuli in the log. :return: arrays with start and end times for all stimuli
-
property
stimulus_log
¶
bouter.multisession_exp module¶
-
class
bouter.multisession_exp.
MultiSessionExperiment
(path, **kwargs)[source]¶ Bases:
bouter.embedded.EmbeddedExperiment
Class to handle the scenario of multiple stytra sessions within the same experiment - typically, for plane-wise repetitions in 2p imaging.
bouter.utilities module¶
-
bouter.utilities.
bandpass
(timeseries, dt, f_min=12, f_max=62, n_taps=9, axis=0)[source]¶ Bandpass filtering used for tail motion, filters out unphysical frequencies for the fish tail
- Parameters
timeseries –
dt –
f_min –
f_max –
n_taps –
- Returns
-
bouter.utilities.
calc_vel
(dx, t)[source]¶ Calculates velocities from deltas and times, skipping over duplicated times
- Parameters
the differences in the parameter (dx) –
times at which the parameter was sampled (t) –
- Returns
- Return type
t_vel, vel
-
bouter.utilities.
crop
(traces, events, **kwargs)[source]¶ Apply cropping functions defined below depending on the dimensionality of the input (one cell or multiple cells). If input is pandas Series or DataFrame, it strips out the values first. :param traces: 1 (n_timepoints) or 2D (n_timepoints X n_cells) array,
pd.Series or pd.DataFrame with cells as columns.
- Parameters
args – see _crop_trace and _crop_block args
kwargs – see _crop_trace and _crop_block args
- Returns
-
bouter.utilities.
extract_segments_above_threshold
(trace, threshold=0.1, min_length=20, min_between=25, break_segment_on_nan=True) → Tuple[numpy.ndarray, numpy.ndarray][source]¶ Extract periods from a trace where it’s value is above threshold. The segments also can have a minimal length. Used for extracting bouts from vigor or velocity
- Parameters
trace – vigor or velocity
threshold – minimal value to be considered moving
min_length – minimal number of samples of continuous movement
min_between – minimal number of samples between two crossings
break_segment_on_nan – if a NaN is encountered, it breaks the segment
- Returns
segments: start and end indices of the segments above threshold connected: for each segment, whether it is connected to the previous. Segments are considered connected if there were no NaN values in the trace.
-
bouter.utilities.
fast_pearson
(x, y)[source]¶ Calculate correlation between two data series, excluding nan values. :param x: first array :param y: second array :return: pearson correlation
-
bouter.utilities.
fill_out_segments
(tail_angle_mat, continue_curvature=0, revert_pts=None)[source]¶ Fills out NaN values in a tail-tracking data matrix. Filling can consist on propagating the angle of the last tracked segment (continue_curvature=0) or on simulating the tail curvature by linearly-extrapolating the curvature of the last continue_curvature tracked segments.
- Parameters
tail_angle_mat – Data matrix (timepoints x n_segments) with the tail tracking data.
continue_curvature – Number of previous segments used for extrapolating curvature of each NaN segment.
- Returns
-
bouter.utilities.
polynomial_tail_coefficients
(segments, n_max_missing=7, degree=3)[source]¶ Fits a polynomial to the bout shape
- Parameters
n_max_missing –
degree – the polynomial degree
- Returns
-
bouter.utilities.
predictive_tail_fill
(thetas, smooth_wnd=1, max_taildiff=1.5707963267948966, start_from=4, fit_timepts=5, fit_tailpts=4)[source]¶
-
bouter.utilities.
reliability
(data_block)[source]¶ Function to calculate reliability of cell responses. Reliability is defined as the average of the across-trials correlation. This measure seems to generally converge after a number of 7-8 repetitions, so it is advisable to have such a repetition number to use it. :param data_block: block of cell responses (t x n_trials x n_cells) :return:
-
bouter.utilities.
resample
(df_in, resample_sec=0.005, fromzero=True)[source]¶ - Parameters
df_in –
resample_sec –
-
bouter.utilities.
revert_segment_filling
(fixed_mat, revert_pts)[source]¶ Revert the filling of a tail segments matrix. Provided a data matrix and array with the numbers of segments to be reverted at each timepoint, this function will reset the previously-filled values to NaNs.
- Parameters
fixed_mat – Data matrix (timepoints x n_segments) with the tail tracking data.
revert_pts – Array (timepoints) registering how many segments were filled for each timepoint.
- Returns