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
isTrue
), 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_df
isTrue
) or a dictionary (ifreturn_df
isFalse
).- Parameters
base_folder (str or
Path
) – path to base folder containing log fileshas_subject_folders (boolean, optional) –
True
if log files are stored in subfolders per subject,False
if they are all stored in one top-level folderlog_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 IDreturn_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
isTrue
). 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 subjectlog_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 IDoverwrite_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
- 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_data
is aDataFrame
with aMultiIndex
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 aDataFrame
withoutMultiIndex
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
orLogData
) – log data to savepath (
Path
or str) –path for export. The expected format of
path
depends onlog_data
:If
log_data
is log data from a single subjectpath
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 subjectspath
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 fromLogData
objectoverwrite (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