biopsykit.io.carwatch_logs module

Module providing functions to load and save logs from the CARWatch app.

biopsykit.io.carwatch_logs.load_logs_all_subjects(base_folder, has_subject_folders=True, log_filename_pattern=None, return_df=True)[source]

Load log files from all subjects in a folder.

This function iterates through the base folder and looks for subfolders (if has_subject_folders is True), or for .csv files or .zip files matching the log file name pattern.

Files from all subjects are then loaded and returned as one DataFrame (if return_df is True) or a dictionary (if return_df is False).

Parameters
  • base_folder (str or Path) – path to base folder containing log files

  • has_subject_folders (boolean, optional) – True if log files are stored in subfolders per subject, False if they are all stored in one top-level folder

  • log_filename_pattern (str, optional) – file name pattern of log files as regex string or None if files have default filename pattern: “logs_(.*?)”. A custom filename pattern needs to contain a capture group to extract the subject ID

  • return_df (bool, optional) – True to return data from all subjects combined as one dataframe, False to return a dictionary with data per subject. Default: True

Returns

dataframe with log data for all subjects (if return_df is True). or dictionary with log data per subject

Return type

DataFrame or dict

biopsykit.io.carwatch_logs.load_log_one_subject(path, log_filename_pattern=None, overwrite_unzipped_logs=False)[source]

Load log files from one subject.

Parameters
  • path (Path or str) – path to folder containing log files from subject or path to log file from subject

  • log_filename_pattern (str, optional) – file name pattern of log files as regex string or None if file has default filename pattern: “logs_(.*?)”. A custom filename pattern needs to contain a capture group to extract the subject ID

  • overwrite_unzipped_logs (bool, optional) – True to overwrite already unzipped log files, False to not overwrite. Only relevant if log files are provided as zip files. Default: False

Returns

dataframe with log data for one subject

Return type

DataFrame

biopsykit.io.carwatch_logs.log_folder_to_dataframe(folder_path)[source]

Load log data from folder of one subject and return it as dataframe.

Parameters

folder_path (Path or str) – path to folder containing log files from subject

Returns

dataframe with log data for one subject

Return type

DataFrame

biopsykit.io.carwatch_logs.save_log_data(log_data, path, subject_id=None, overwrite=False, show_skipped=False)[source]

Save log data for a single subject or for all subjects at once.

The behavior of this function depends on the input passed to log_data:

  • If log_data is a DataFrame with a MultiIndex it is assumed that the dataframe contains data from multiple subjects and will be exported accordingly as one combined csv file.

  • If log_data is a DataFrame without MultiIndex it is assumed that the dataframe only contains data from one single subject and will be exported accordingly as csv file.

Parameters
  • log_data (DataFrame or LogData) – log data to save

  • path (Path or str) –

    path for export. The expected format of path depends on log_data:

    • If log_data is log data from a single subject path needs to specify a folder. The log data will then be exported to “path/logs_<subject_id>.csv”.

    • If log_data is log data from multiple subjects path needs to specify a file. The combined log data of all subjects will then be exported to “path”.

  • subject_id (str, optional) – subject ID or None to get subject ID from LogData object

  • overwrite (bool, optional) – True to overwrite file if it already exists, False otherwise. Default: False

  • show_skipped (bool, optional) – True to print message if log data was already exported and will be skipped, False otherwise. Default: False