fino2py.reshaping package

Submodules

fino2py.reshaping.create_chunk module

This module provides a function to create a chunk of data from a DataFrame between specified start and end times and return a new DataFrame containing the mean values for each cardiovascular measure during that chunk.

Notes

  • The DataFrame must have been created by the read_raw_finometer_data function.

  • The time values must be in the format ‘HH:MM:SS’. There are functions to help normalise the time values in the fino2py.times module.

Example

baseline_1 = create_chunk(df, ‘Participant 1’, ‘Baseline’, ‘00:00:00’, ‘00:05:00’)

fino2py.reshaping.create_chunk.create_chunk(df: pandas.DataFrame, ID: str, tag: str, start: str | None, end: str | None) pandas.DataFrame[source]

Create a chunk of data from a dataframe between specified start and end times and return a new dataframe containing the mean values for each cardiovascular measure during that chunk.

Parameters:

dfpandas DataFrame

The dataframe containing the data to extract a chunk from.

IDstr

The participant ID to include in the output dataframe.

tagstr

The tag to include in the column names of the output dataframe.

startstr or None

The start time of the chunk in the format ‘HH:MM:SS’ or ‘HH:MM:SS.mmm’. If None, the chunk starts at the beginning of the dataframe.

endstr or None

The end time of the chunk in the format ‘HH:MM:SS’ or ‘HH:MM:SS.mmm’. If None, the chunk ends at the end of the dataframe.

Returns:

pandas DataFrame

A new dataframe containing the mean values for each column in the specified chunk of the input dataframe. The output dataframe has a row for the specified participant ID and columns with names that include the specified tag.

fino2py.reshaping.generate_protocol_averages module

Generate averages for each section of the experimental protocol from already ingested finometer data.

This module provides a function to calculate averages for each section of the experimental protocol. The resulting averages are concatenated into a single row, allowing for easy merging of participants into a single dataframe. Optionally, the function can save the reshaped data as a CSV file.

Notes

  • The frame parameter should be a pandas DataFrame object containing data produced by read_raw_finometer_data function.

  • The id parameter should be a string representing the participant ID (should also be produced by read_raw_finometer_data function).

  • The times parameter should be a dictionary of tuples representing the time periods for calculating averages. There are functions in the times section to help formatting times.

Example

# Import averaged finometer data frame, id = read_raw_finometer_data(‘/path/to/folder’)

# Define the time periods for calculating averages times = {

‘baseline’: (‘00:03:00, ‘00:10:00’), ‘task’: (‘00:10:00’, ‘00:19:00’), …

}

# Generate protocol averages averages = generate_protocol_averages(frame, id, times=times, save_csv=True)

fino2py.reshaping.generate_protocol_averages.generate_protocol_averages(frame, id, times=None, save_csv=None)[source]

A function that imports the finometer dataframes (which have already been processed from the raw data) to produce averages for each section of the experimental protocol concatenated into a single row so that participants can then be merged into a single dataframe.

Parameters:
  • frame (pandas.DataFrame) – The DataFrame containing the averaged finometer data

  • id (str) – The participant ID

  • save_csv (bool, optional) – If True, the imported data will be saved as a .csv file in the same folder as the .csv file, this is not always needed and should be used sparingly

  • times (dict, optional) – A dictionary of tuples of times, with the keys being the names of the time periods.

Returns:

A DataFrame with the mean values of the given columns during each time period of the study.

Return type:

pandas.DataFrame

Raises:
  • TypeError – If frame is not a pandas.DataFrame object If id is not a string

  • ValueError – If times is not provided as a dictionary with at least one key-value pair If there are not enough times provided for a given time period If there are too many times provided for a given time period

fino2py.reshaping.minute_by_minute module

This module provides a function for reshaping participant’s minute-by-minute data into a single row.

The main function, minute_by_minute, takes a DataFrame containing finometer data and performs reshaping of the data. It converts the index into a column named “Time (s)” to preserve the original time information. The DataFrame is then flattened, creating a new DataFrame with each minute’s data in separate columns. The column names are generated by appending “_minute_i” to the original column names, where “i” represents the minute index. The Participant ID is added as a column at the beginning of the new DataFrame, facilitating concatenation of participant data for sample-level analysis.

Note: The minute_by_minute function assumes that the input DataFrame contains the necessary columns and structure for reshaping.

Functions

minute_by_minute(df: pd.DataFrame, df_id: str) -> pd.DataFrame:

Reshape the participant’s minute-by-minute data into a single row. Returns a DataFrame with each minute’s data in separate columns.

dfpandas DataFrame

The DataFrame containing finometer data.

df_idstr

The Participant ID associated with the data.

pandas DataFrame

The reshaped minute-by-minute data DataFrame. Each minute’s data is in separate columns, with column names reflecting the original column names and minute indices. The Participant ID column is included at the beginning.

fino2py.reshaping.minute_by_minute.minute_by_minute(df: pandas.DataFrame, df_id: str) pandas.DataFrame[source]

Reshape the participant’s minute by minute data into a single row

This function takes a DataFrame containing finometer data (df). It converts the index of the DataFrame into a column named “Time (s)” to preserve the original time information.

The DataFrame is then flattened to create a new DataFrame (flat_frame) with each minute’s data in a separate column. The column names are generated by appending “_minute_i” to the original column names, where “i” represents the minute index.

The Participant ID (df_id) is added as a column at the beginning of the flat_frame DataFrame. This allows for participant data to be easily concatenated into a single DataFrame for sample level analysis.

Parameters:
  • df (pandas DataFrame) – The DataFrame containing the finometer data.

  • df_id (str) – The Participant ID associated with the data.

Returns:

The minute-by-minute analysis DataFrame.

The flat_frame DataFrame contains each minute’s data in separate columns, with column names reflecting the original column names and minute indices. The Participant ID column is included at the beginning.

Return type:

pandas DataFrame

fino2py.reshaping.minute_by_minute_from_folder module

Reshape finometer data into a minute-by-minute format from files in a folder.

This module provides a function to read the raw finometer data from the specified folder path and reshape the data into a minute-by-minute format. It utilizes the read_raw_finometer_data function to import the data and calculate the average of each measure over the selected time interval (default is 1 minute). The minute_by_minute function is then applied to reshape the data into a single row, with each column representing the average of a particular measure over each minute of the data collection.

Notes

  • The read_raw_finometer_data function is used to import the raw finometer data and calculate the average over the selected time interval.

  • The minute_by_minute function is applied to reshape the data into a single row for each minute.

  • If save_raw is True, the imported raw data is saved as a CSV file in the same folder as the data files.

  • If save is True, the minute-by-minute reshaped data is saved as a CSV file in the same folder as the data files.

Example

frame, id = minute_by_minute_from_folder(‘/path/to/folder’, int=’1T’, save_raw=True, save=True)

fino2py.reshaping.minute_by_minute_from_folder.minute_by_minute_from_folder(path: str, save_raw: bool = False, save: bool = False) Tuple[pandas.DataFrame, str][source]

This function reads the raw finometer data from the specified folder path and ‘reshapes’ the data into a minute-by-minute format. It uses the read_raw_finometer_data function to import the data and calculate the average of each measure over the selected time interval (1 minute in this case). Then, the minute_by_minute function is applied to reshape the data into a single row, with each column representing the average of a particular measure over each minute of the data collection.

Parameters:
  • path (str) – The path to the folder containing the finometer data files.

  • save_raw (bool, optional) – Specifies whether to save the imported raw data as a CSV file. The default is False.

  • save (bool, optional) – Specifies whether to save the minute-by-minute analysis result as a CSV file. The default is False.

Returns:

A tuple containing the minute-by-minute analysis DataFrame and the Participant ID associated with the data.

Return type:

Tuple[pd.DataFrame, str]

Notes

  • The read_raw_finometer_data function is used to import the raw finometer data and calculate the average over the selected time interval.

  • The minute_by_minute function is applied to reshape the data into a single row for each minute.

  • If save_raw is True, the imported raw data is saved as a CSV file in the same folder as the data files.

  • If save is True, the minute-by-minute analysis result is saved as a CSV file in the same folder as the data files.

Example

frame, id = minute_by_minute_from_folder(‘/path/to/folder’, int=’1T’, save_raw=True, save=True)

fino2py.reshaping.nova_concat module

fino2py.reshaping.nova_concat.nova_concat(data_dict: Dict) pandas.DataFrame[source]

Concatenate the minute-by-minute data for each participant into a single DataFrame.

This function takes a dictionary of minute-by-minute dataframes (data_dict) and concatenates them into a single DataFrame. The dictionary should be created using the read_raw_nova_data function. The Participant ID column is added at the beginning of the DataFrame to allow for sample-level analysis.

Parameters:

data_dict (Dict) – A dictionary containing Participant ID as keys and minute-by-minute dataframes as values.

Returns:

A concatenated DataFrame containing minute-by-minute data for all participants.

Return type:

pd.DataFrame

Example

# Import minute-by-minute data for each participant with a dictionary comprehension data_dict

concatenated_df = nova_concat(data_dict)

fino2py.reshaping.nova_minute_by_minute module

This module provides a function for reshaping participant’s minute-by-minute data into a single row.

The main function, nova_minute_by_minute, takes a DataFrame containing Novapress data and performs reshaping of the data. It sets the index as the “Time (s)” column to preserve the original time information. The DataFrame is then flattened, creating a new DataFrame with each minute’s data in separate columns. The column names are generated by appending “_minute_i” to the original column names, where “i” represents the minute index. The Participant ID is added as a column at the beginning of the new DataFrame, facilitating concatenation of participant data for sample-level analysis.

Note: The minute_by_minute function assumes that the input DataFrame contains the necessary columns and structure for reshaping. Also, as the NovaPress data is spread across multiple files, this function is all that’s required to reshape the data.

Functions

minute_by_minute(df: pd.DataFrame, df_id: str) -> pd.DataFrame:

Reshape the participant’s minute-by-minute data into a single row. Returns a DataFrame with each minute’s data in separate columns.

dfpandas DataFrame

The DataFrame containing finometer data.

df_idstr

The Participant ID associated with the data.

pandas DataFrame

The reshaped minute-by-minute data DataFrame. Each minute’s data is in separate columns, with column names reflecting the original column names and minute indices. The Participant ID column is included at the beginning.

fino2py.reshaping.nova_minute_by_minute.nova_minute_by_minute(df: pandas.DataFrame, df_id: str) pandas.DataFrame[source]

Reshape the participant’s minute by minute data into a single row

This function takes a DataFrame containing finometer data (df). It converts the index of the DataFrame into a column named “Time (s)” to preserve the original time information.

The DataFrame is then flattened to create a new DataFrame (flat_frame) with each minute’s data in a separate column. The column names are generated by appending “_minute_i” to the original column names, where “i” represents the minute index.

The Participant ID (df_id) is added as a column at the beginning of the flat_frame DataFrame. This allows for participant data to be easily concatenated into a single DataFrame for sample level analysis.

Parameters:
  • df (pandas DataFrame) – The DataFrame containing the finometer data.

  • df_id (str) – The Participant ID associated with the data.

Returns:

The minute-by-minute analysis DataFrame.

The flat_frame DataFrame contains each minute’s data in separate columns, with column names reflecting the original column names and minute indices. The Participant ID column is included at the beginning.

Return type:

pandas DataFrame

Module contents

This is the fino2py package for analyzing SmartMedical finometer data.