bouter package

Submodules

bouter.angles module

bouter.angles.angle_dif(a, b)[source]
Parameters
  • a

  • b

Returns

Return type

type

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.cossin(theta)[source]

Expands theta into sine and cosine

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.reduce_to_pi(ar)[source]

Reduce angles to the -pi to pi range

bouter.angles.rot_mat(theta)[source]

The rotation matrix for an angle theta

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.angles.transform_affine(points, tm)[source]

Affine transform a point or an array of points with the matrix tm

Parameters
  • points

  • tm

bouter.angles.transform_affine_point(point, tm)[source]

bouter.bout_stats module

bouter.bout_stats.bout_stats(vigor, tail_sum, bouts, wnd_turn_pts)[source]

Compute statistics of bouts from vigor trace, tail sum, and bouts indexes.

bouter.bout_stats.count_peaks_between(ts, start_indices, end_indices, min_peak_dist=5)[source]

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.decorators.deprecated(message=None)[source]
bouter.decorators.get_method_default_kwargs(method)[source]

bouter.descriptors module

All the hardcoded filenames and variable names.

bouter.df_utilities module

bouter.df_utilities.get_n_segments(df, prefix=True)[source]
bouter.df_utilities.get_n_segments_embedded(df)[source]
bouter.df_utilities.tail_column_names(n_segments, i_fish=None)[source]

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
clear_cache()[source]
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
get_bouts()[source]
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
stimulus_starts_ends()[source]

Get start and end time of all stimuli in the log. :return: arrays with start and end times for all stimuli

update_processing_params(new_dict)[source]
bouter.experiment.root_sid_from_path(path, session_id=None)[source]

Read root and session id from several combinations of inputs. :param path: :param session_id: :return:

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.

load_session_log(log_name, session_idx)[source]

Function to load a log for a single session, specified by index- :param log_name: string specifying the type of log (e.g., “behavior_log” :param session_idx: int, index of session to load :return:

session_start_tstamps()[source]

Return timestamps for all the sessions in this folder.

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_corrcoef(mat)[source]
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.log_dt(log_df, i_start=10, i_end=110)[source]
bouter.utilities.mean_smooth(array, wnd)[source]
bouter.utilities.merge_bouts(bouts, min_dist)[source]
bouter.utilities.n_missing_segments(tail_angle_mat)[source]
bouter.utilities.nan_isolated(thetas)[source]
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.polynomial_tailsum(poly_coefs)[source]
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

Module contents

bouter.load_folder(folder, exp_class=<class 'bouter.experiment.Experiment'>)[source]

Load all experiments in the folder and subfolders

Parameters
  • folder – folder containing the _metadata.json files (also searches subfolders)

  • exp_class – the kind of experiment to make

Returns