neurokin package#

Subpackages#

Submodules#

neurokin.kinematic_data module#

class neurokin.kinematic_data.KinematicDataRun(path)[source]#

Bases: object

This class represents the kinematics data recorded in a single run.

compute_gait_cycles_bounds(left_marker, right_marker, step_filter_freq: int = 3, prominence: float = 0.8, relative_height: float = 0.95)[source]#

Computes the lifting and landing frames of both feet using a left and a right marker, respectively. To increase robustness of the cycle estimation it first low-passes the signal.

Parameters:
  • left_marker – reference marker for the left foot, typically the left mtp

  • right_marker – reference marker for the right foot, typically the right mtp

  • step_filter_freq – used to filter out very jittery movement which should not represent steps

  • prominence – required minimal prominence of peaks

  • relative_height – Chooses the relative height at which the peak width is measured as a percentage of its prominence. 1.0 calculates the width of the peak at its lowest contour line while 0.5 evaluates at half the prominence height. Must be at least 0.

Returns:

convert_DLC_like_to_df(multiindex_df: pandas.MultiIndex | None = None)[source]#

Converts a DeepLabCut-like dataframe (MultiIndex) to a simple pandas dataframe. Saves the scorer identity and the bodyparts in the corresponding class attributes.

Parameters:

multiindex_df – the df to convert

Returns:

extract_features(configpath, get_binned=True, custom_feats=None)[source]#

Computes features on the markers dataframe based on the config file. If get_binned is True, it also computes the binned features as defined in the config file. :param configpath: path to the configuration for skeleton and features :param get_binned: should the binned dataframe be computed? :param custom_feats: pass here the custom features :return:

filter_marker_df(func=None, **kwargs)[source]#

Filters markers dataframe in place using a given function or defaults on a savgol filter with window_length 4 and polyorder 2. Pass the arguments to change the defaults. :param func: user-given filter function. Must be used as an applied function on a dataset :param kwargs: user-given parameters for the savgol filter, or the custom filter function. :return:

gait_param_to_csv(output_folder='./')[source]#

Writes the gait_param dataframe to a csv file with the name [INPUT_FILENAME]+_gait_param.csv

Returns:

load_kinematics(correct_shift: bool = False, correct_tilt: bool = False, to_shift: numpy.typing.ArrayLike | None = None, to_tilt: numpy.typing.ArrayLike | None = None, shift_reference_marker: str = '', tilt_reference_marker: str = '', source: str = 'c3d', fs: float | None = None)[source]#

Loads the kinematics from a c3d file into a dataframe with timeframes as rows and markers as columns

Parameters:
  • correct_shift – bool should there be a correction in the shift of one of the axis?

  • correct_tilt – bool should there be a correction in the tilt (linear trend) of one of the axis?

  • to_shift – which columns to perform the shift on if correct_shift is true

  • to_tilt – which columns to perform the tilt on if correct_shift is true

  • shift_reference_marker – which marker to use as a reference trajectory to compute the shift

  • tilt_reference_marker – which marker to use as a reference trajectory to compute the tilt

  • source – defines which source of kinematics data to load from, either c3d or dlc

Returns:

plot_step_partition(step_left, step_right, ax_l, ax_r)[source]#

Plots the step partition of a gait trace (ideally toe or foot trace). Fetches the class attributes so the steps computation has to happen before

Parameters:
  • step_left – name of the left trace body part

  • step_right – name of the right trace body part

  • ax_l – ax to plot the left trace on

  • ax_r – ax to plot the right trace on

Returns:

axes

print_step_partition(step_left, step_right, output_folder='./')[source]#

Creates and saves the step partition plot. See plot_step_partition method for details.

Parameters:
  • step_left – name of the left trace body part

  • step_right – name of the right trace body part

  • output_folder – where to save the figure

Returns:

stepwise_gait_features_to_csv(output_folder='./')[source]#

Writes the gait_param dataframe to a csv file with the name [INPUT_FILENAME]+_gait_param.csv

Returns:

neurokin.locomotion_states module#

class neurokin.locomotion_states.NeuralCorrelatesStates(timeslice: float, experiment_structure_filepath: str, skip_subjects: List[str] = [], skip_conditions: List[str] = [], skiprows: int = 2, framerate: float = 200)[source]#

Bases: object

This class allows to deal with unimodal and multimodal retrieval of sata based on states timestamps.

create_events_dataset(experiment_path, verbose=False, file_starts_with=None)[source]#

Takes the experiment structure and based on the runs listed there it looks for .csv files to import. Then based on the labels, creates a dataframe containing condition, date, animal, run and event. Each event contains the list of timestamps [start, end] for that specific run

Parameters:
  • experiment_path – folder where to find the dataset

  • verbose – if True it will print the currently processed run

  • file_starts_with – set if the files to fetch begin with a specific pattern

  • experiment_path

Returns:

dataframe containing data of each trial and timestamps of events

create_psd_dataset(nfft, nov, zscore=False)[source]#

Computes the Power Spectra Density of the neural correlates.

Parameters:
  • nfft – NFFT parameter to use for the Fourier Transform

  • nov – Overlap parameter to use for the Fourier Transform

  • verbose – if True it will print the currently processed run

Returns:

dictionary structured as condition, date, animal, run, event containing the PSD neural correlates.

create_raw_neural_dataset(experiment_path, stream_names: List[str], ch_of_interest: Dict[str, int], verbose=False)[source]#

Creates a pandas dataframe containing neural chunks corresponding to locomotor events in each run.

Parameters:
  • experiment_path – path to the dataset

  • stream_names – names of streams where the data is saved (TDT specific)

  • ch_of_interest – channel of interest. Neural chunks are for only one channel

  • verbose – whether to print info on the run currently processed

Returns:

plot_prep_psds_dataset(test_sbj_list, condense=True)[source]#

Creates a reduced dataframe of PSD ready to be plotted

Parameters:
  • test_sbj_list – list of subjects that belong in the experimental condition

  • condense – whether to retain the 5 states format or condense to the 3 format.

Returns:

plot_prep_states_distribution(test_sbj_list, condense=True, stat='std')[source]#

Fixed shortcut to generate a stats dictionary of the state distribution, ready to be plotted

Parameters:
  • test_sbj_list – list of subject IDs that belong to the test group

  • condense – bool if to condense from 5 categories to 3

Returns:

stats dictionary dataset structured as group, condition, state, stats {“mean”:, “upper_bound”, “lower_bound}

save_dataset(dataset, filename)[source]#

Saves dataset dictionary to pickle file

Parameters:
  • dataset – str name of which dataset to save

  • filename – filename without extension

Returns:

neurokin.neural_data module#

class neurokin.neural_data.NeuralData(path)[source]#

Bases: object

This class represents the neural data recording of a single recording experiment. It allows to load neural data from multiple recording systems and to perform basic analysis on the raw data.

compute_recording_duration()[source]#

Computes recording duration based on len of the dataset over the sampling frequency and sets it as a class attribute

Returns:

load_open_ephys(experiment, recording, channels=None, sync_present: bool = False, sync_ch: int | None = None, source_processor: str | None = None)[source]#

Loads OpenEphys data in the classes attributes

Parameters:
  • experiment – name of the experiment folder, as named by OE

  • recording – name of the recording folder, as named by OE

  • channels – which channels to load

  • sync_present – whether there is a sync channel or not (e.g. stimulation trace)

  • sync_ch – number where the sync or stimulation data is stored

  • source_processor – name of the source processor as named by OE

Returns:

load_tdt_data(sync_present: bool = False, stream_name='Wav1', stim_stream_name='Wav1', t1=0, t2=-1)[source]#

Loads TDT data in the classes attributes.

Parameters:
  • sync_present – whether there is a sync channel or not (e.g. stimulation trace)

  • stream_name – name of the stream where the neural data is stored

  • stim_stream_name – name of the stream where the sync or stimulation data is stored

  • t1 – first time in second from which to import

  • t2 – last time in second up until which to import

Returns:

pick_sync_data(idx)[source]#

In TDT loading, if the sync_data is accidentally a multichannel, use this to pick the correct one, based on a 0-based index.

Parameters:

idx – index of the correct sync data

Returns:

Module contents#