resurfemg.data_connector.converter_functions module

Copyright 2022 Netherlands eScience Center and University of Twente Licensed under the Apache License, version 2.0. See LICENSE for details.

This file contains standardized functions to work with various EMG file types from various hardware/software combinations, and convert them down to an array that can be further processed with other modules.

csv_from_jkmn_to_array(file_name)

LEGACY FUNCTION This function takes a file from the Jonkman lab in csv format and changes it into the shape the library functions work on.

Parameters:

file_name (str) – Filename of csv files

Returns arrayed:

Arrayed data

Rtype arrayed:

~numpy.ndarray

dvrmn_csv_freq_find(file_name)

LEGACY FUNCTION Extract the sampling rate of a Duiverman type csv of EMG. Note this data may be resampled down by a factor of 10.

Parameters:

file_name (str) – Filename of csv file

Returns fs:

Sampling frequency

Rtype fs:

int

dvrmn_csv_to_array(file_name)

LEGACY FUNCTION Transform an already preprocessed csv from the Duiverman lab into an EMG in the format our other functions can work on it. Note that some preprocessing steps are already applied so pipelines may need adjusting.

Parameters:

file_name (str) – Filename of csv file

Returns:

arrayed

Return type:

ndarray

load_adicht(file_path, record_idx, channel_idxs=None, resample_channels=None, verbose=True)

This function loads a .adicht file and returns the data as a numpy array.

Parameters:
  • file_path (str) – Path to the file to be loaded

  • verbose (bool) – Print verbose output

Returns data_df:

Pandas DataFrame of the loaded data

Rtype data_df:

~pandas.DataFrame

Returns metadata:

Metadata of the loaded data

Rtype metadata:

dict

load_csv(file_path, force_col_reading, verbose=True)

This function loads a .csv file and returns the data as a pandas DataFrame. The function also returns metadata such as the loaded channels.

Parameters:
  • file_path (str) – Path to the file to be loaded

  • force_col_reading (bool) – Force column reading for row based .csv files

  • verbose (bool) – Print verbose output

Returns data_df:

Pandas DataFrame of the loaded data

Rtype data_df:

~pandas.DataFrame

Returns metadata:

Metadata of the loaded data

Rtype metadata:

dict

load_file(file_path, verbose=True, **kwargs)

This function loads a file from a given path and returns the data as a numpy array. The function can handle .poly5, .mat, .csv, and .npy files. The function can also rename channels and drop channels from the data.

Parameters:
  • file_path (str) – Path to the file to be loaded

  • kwargs – Additional keyword arguments for specific file loaders:

  • key_name (str): Key name for loading .mat files.

  • force_col_reading (bool): If True, force reading columns for .csv files.

    Default is False.

  • record_idx (int): Record index for loading .adi* files. Default is 0.

  • channel_idxs (list): List of channel indices for loading .adi files.

  • labels (list): List of new channel names to rename the columns.

Returns np_float_data:

Numpy array of the loaded data

Return type:

ndarray

Returns data_df:

Pandas DataFrame of the loaded data

Return type:

DataFrame

Returns metadata:

Metadata of the loaded data

Return type:

dict

load_mat(file_path, key_name, verbose=True)

This function loads a .mat file and returns the data as a pandas DataFrame. The function also returns metadata such as the sampling rate, loaded channels, and units.

Parameters:
  • file_path (str) – Path to the file to be loaded

  • key_name (str) – Key name for .mat files

  • verbose (bool) – Print verbose output

Returns data_df:

Pandas DataFrame of the loaded data

Rtype data_df:

~pandas.DataFrame

Returns metadata:

Metadata of the loaded data

Rtype metadata:

dict

load_npy(file_path, verbose=True)

This function loads a .npy file and returns the data as a numpy array.

Parameters:
  • file_path (str) – Path to the file to be loaded

  • verbose (bool) – Print verbose output

Returns data_df:

Pandas DataFrame of the loaded data

Rtype data_df:

~pandas.DataFrame

Returns metadata:

Metadata of the loaded data

Rtype metadata:

dict

load_poly5(file_path, verbose=True)

This function loads a .Poly5 file and returns the data as a pandas DataFrame. The function also returns metadata such as the sampling rate, loaded channels, and units.

Parameters:
  • file_path (str) – Path to the file to be loaded

  • verbose (bool) – Print verbose output

Returns data_df:

Pandas DataFrame of the loaded data

Rtype data_df:

~pandas.DataFrame

Returns metadata:

Metadata of the loaded data

Rtype metadata:

dict

matlab5_jkmn_to_array(file_name)

LEGACY FUNCTION This file reads matlab5 files as produced in the Jonkman laboratory, on the Biopac system and returns arrays in the format and shape our the ReSurfEMG functions work on.

Parameters:

file_name (str) – Filename of matlab5 files

Returns arrayed:

Arrayed data

Rtype arrayed:

~numpy.ndarray

poly5unpad(to_be_read)

Converts a Poly5 read into an array without padding. This padding is a quirk in the python Poly5 interface that pads with zeros on the end.

Parameters:

to_be_read (str) – Filename of python read Poly5

Returns unpadded:

Unpadded array

Rtype unpadded:

~numpy.ndarray

poly_dvrman(file_name)

LEGACY FUNCTION This is a function to read in Duiverman type Poly5 files, which has 18 layers/pseudo-leads, and return an array of the twelve unprocessed leads for further pre-processing. The leads eliminated were RMS calculated on other leads (leads 6-12). The expected organization returned is from leads 0-5 EMG data, then the following leads # 6 Paw: airway pressure (not always recorded) # 7 Pes: esophageal pressure (not always recorded) # 8 Pga: gastric pressure (not always recorded) # 9 RR: respiratory rate I guess (very unreliable) # 10 HR: heart rate # 11 Tach: number of breath (not reliable)

Parameters:

file_name (str) – Filename of Poly5 Duiverman type file

Returns samps:

Arrayed data

Rtype samps:

~numpy.ndarray