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_foldersisTrue), 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(ifreturn_dfisTrue) or a dictionary (ifreturn_dfisFalse).- Parameters
base_folder (str or
Path) – path to base folder containing log fileshas_subject_folders (boolean, optional) –
Trueif log files are stored in subfolders per subject,Falseif they are all stored in one top-level folderlog_filename_pattern (str, optional) – file name pattern of log files as regex string or
Noneif files have default filename pattern: “logs_(.*?)”. A custom filename pattern needs to contain a capture group to extract the subject IDreturn_df (bool, optional) –
Trueto return data from all subjects combined as one dataframe,Falseto return a dictionary with data per subject. Default:True
- Returns
dataframe with log data for all subjects (if
return_dfisTrue). or dictionary with log data per subject- Return type
DataFrameor 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 (
Pathor str) – path to folder containing log files from subject or path to log file from subjectlog_filename_pattern (str, optional) – file name pattern of log files as regex string or
Noneif file has default filename pattern: “logs_(.*?)”. A custom filename pattern needs to contain a capture group to extract the subject IDoverwrite_unzipped_logs (bool, optional) –
Trueto overwrite already unzipped log files,Falseto not overwrite. Only relevant if log files are provided as zip files. Default:False
- Returns
dataframe with log data for one subject
- Return type
- biopsykit.io.carwatch_logs.log_folder_to_dataframe(folder_path)[source]¶
Load log data from folder of one subject and return it as 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_datais aDataFramewith aMultiIndexit is assumed that the dataframe contains data from multiple subjects and will be exported accordingly as one combined csv file.If
log_datais aDataFramewithoutMultiIndexit is assumed that the dataframe only contains data from one single subject and will be exported accordingly as csv file.
- Parameters
log_data (
DataFrameorLogData) – log data to savepath (
Pathor str) –path for export. The expected format of
pathdepends onlog_data:If
log_datais log data from a single subjectpathneeds to specify a folder. The log data will then be exported to “path/logs_<subject_id>.csv”.If
log_datais log data from multiple subjectspathneeds to specify a file. The combined log data of all subjects will then be exported to “path”.
subject_id (str, optional) – subject ID or
Noneto get subject ID fromLogDataobjectoverwrite (bool, optional) –
Trueto overwrite file if it already exists,Falseotherwise. Default:Falseshow_skipped (bool, optional) –
Trueto print message if log data was already exported and will be skipped,Falseotherwise. Default:False