Repository navigation
2. Explanation of code
The config file is used to specify project-specific settings that serve as "global" variables across the individual scripts. Aside from the Orchestra file (described below), the config file is the only script that requires editing to run the Acc Post Processing project.
The variables in the config file are organised into categories: Overall variables, folders and files for the project, as well as variables specific to each individual script. Each variable is clearly marked with EDIT or DO NOT EDIT, along with a description of the expected information.
The following variables should be edited as a minimum:
-
PROJECT→ The name of the project for which data is being post-processed.
-
PROCESSING→ Specify if the files were processed through Wave or Pampro.
-
ROOT_FOLDER→ The folder path to the main project directory, which should contain the _results, _analysis, _logs, _releases, _feedback and _data folders.
-
TIMEZONE→ If you wish to adjust data for clock changes, edit this variable to reflect the local timezone where data was collected. Refer to the Timezones documentation for further specifications.
Once the variables in the config file are updated, they typically do not need to be changed again unless there are any updates to post-processing decisions.
Processing level: The script can create minute level, hourly, daily and summary release files. NOTE: If you useg the minute-level output, you can only create the minute-level release file. These files cannot be used to generate hourly, daily and summary files. To generate the hourly, daily and summary release files, you must use the hourly-level output. Modify the following variables in the config file to specify the processing level:
-
SUB_SET_PREFIXES- ["1h", "metadata"] → To create hourly, daily and summary release files.
- ["1m", "metadata"] → To create minute-level release files.
-
count_prefixes- ['1h'] → To create hourly, daily and summary release files.
- ['1m'] → To create minute-level release files.
Use wear log: If your study includes a wear log specifying the days the monitor was worn, you can use it to only process data from those days. Indicate in the config log that a wear log was used and specify the name of the wear log. The following needs editing if a wear log was used:
-
USE_WEAR_LOG→ Edit to 'Yes' if you want to include a wear log. -
WEAR_LOG_FOLDER→ Specify the name of the folder (and any subfolders) where the wear log is saved. This folder must be located within the root folder defined in the config file. Provide only the folder name and subfolder name, not the full path. -
WEAR_LOG→ Edit to the name of the wear log. The wear log needs to be saved in a CSV format within theWEAR_LOG_FOLDER.
Impute sleep data: If a monitor was worn for 6+ hours during the day but not during the night, you can impute sleep data to include this participant despite the missing sleep data. To enable sleep imputation, update the config log as follows:
-
IMPUTE_DATA→ Set to 'Yes' if you want to impute sleep data. -
IMPUTE_HOURS→ Specifies the hours to be imputed if missing. This is set to [1, 2, 3, 4, 5, 6] where each represents an hour of the night (e.g., 1=00:00-01:00, 2=01:00-02:00 etc.). It is recommended not to change this variable. -
MIN_DAY_HOURS→ The minimum number of hours a monitor must be worn in a day for sleep data to be imputed. The default is 6 hours, as commonly used by the MRC Epidemiology unit, but this can be adjusted if needed.
The Acc Post Processing code can be executed through an orchestra file. This orchestra file allows you to run multiple Python scripts using "switches" to enable or disable specific parts of the code, providing a centralised way to manage all scripts from a single point. By turning the "switches" on/off, you can choose to run only certain sections of the code or the entire script, depending on your needs. Below is a description of the individual parts/scripts.
If accelerometer data is processed through Pampro, you need to run the pampro merge metafiles code to merge all the meta data files. Pampro processing creates multiple meta data files including analysis_meta_file and qc_meta_file, which must be combined into a single meta data file before proceeding to run the Filelist_Generation script.
If data is processed through Wave, only one metadata file is generated, and the Pampro_Merge_Metafiles should not be run.
If accelerometer data is processed through Pampro, you need to run the pampro collate anomalies code to collate all anomaly files (if any are present) and merge on meta data to produce information on how much data is lost due to anomalies.
If data is processed through Wave the anomalies files are not created as separate files and the Pampro_Collate_Anomalies should not be run.
The filelist generation code creates a list of all Wave/Pampro output files stored in the _results folder. This file list is used to identify which files require post-processing. In the config file, the variable ONLY_NEW_FILES determines which files to include in the list:
-
ONLY_NEW_FILES = 'No'→ All files in the _results folder will be added to the file list and processed. -
ONLY_NEW_FILES = 'Yes'→ Only files that have not yet been post-processed will be included.
The filelist generation code also creates subfolders within existing folders if they do not already exist. If any files were not calibrated during processing, the code will identify these and create a file list, which will be saved in a Filelists folder within the _results named No_Analysis_Files.txt.
The generic exhaustive post-processing code performs some generic updates to the Wave/Pampro output. It generates one file per participant, which is saved in the Individual_PartPro_files (time resolution folder) within the Summary_Files folder in the _results directory. This part of the script must be run before the collapsing phase can take place.
This script collapses the Individual_PartPro_files created in the GENERIC_EXH_POSTPROCESSING step into summary and daily level files (one line per participant and one line per day per participant). They also create a trimmed hourly/minute file. These outputs will be saved in the Individual_Summary_files, Individual_Trimmed_files and Individual_Daily_files (time resolution folders) within the Summary_Files folder in the _results directory. A data dictionary is generated and outputted in each of these folders.
This script append the summary, daily and hourly/minule level files from each participant. The appended files are outputted in the Summary_Files folder within the _results directory.
This script performs basic checks on the summary and hourly level data to identify potential issues (e.g., duplicate files, extreme outliers and monitor-related problems). A verification log is created in the _logs folder, with the logs name reflecting the date the code was run. While running this verifications is not necessary for preparing release files, it can be beneficial for quality checking the data.
This script prepare the summary, daily and hourly/minute level releases, outputting them in the _releases folder. A data dictionary for each of the files will also be generated and stored in this folder.
This script specifies files that should be removed from the release outputs (e.g., duplicates or where the data is queried and not needed in the final release). In the config file, you can indicate whether to run a housekeeping script.
-
RUN_HOUSEKEEPING = 'Yes'→ This will include the housekeeping script and e.g., drop any duplicates specified here. -
RUN_HOUSEKEEPING = 'No'→ This will not include the housekeeping script.
If you wish to remove any files from the release files, add the filenames to the housekeeping list as shown in the example below.
Once a filename is added to the list (and if RUN_HOUSEKEEPING = 'Yes'), re-run the script that creates the release files. New release files will be generated without the specified files. These files will also be removed during the next verification checks, preventing them from reappearing as files to be checked.
You can use a corruption file to adjust the pwear value for specific hours of the day based on verification checks (e.g., if an hour is identified as noise and unlikely to represent human movement).
A sample file, corruption_conditions.csv, is included with the Acc Post Processing code and is saved in the _analysis folder with the other scripts by default. You can move the file to any folder. This file allows you to specify the following details for the hours you want to adjust:
- DATE: The specific date
- hourofday: The hour of the day to adjust
- dayofweek: The day of the week.
- file_id: The file_id of the file to adjust.
NOTE: If you are creating minute-level release files, you can also specify the variable minuteofhour in the corruption_conditions.csv file. Otherwise, leave this field blank.
To enable corruption adjustments:
- Set the
RUN_CORRUPTIONS_HOUSEKEEPINGvariable in the config file to 'Yes'. - Specify the full file path (including the filename and extension) for the corruption file in the
CORRUPTION_CONDITION_FILE_PATHvariable.
Hours that are seen as noise are flagged when running the verification checks and will be logged in the verification log. To remove these hours, add them to the corruption_condition.csv and re-run the Acc Post Processing code from the GENERIC_exh_postprocessing.