Skip to content

4. User guide ‐ Run as batch

CAS254 edited this page Mar 4, 2025 · 59 revisions

Running script as batch file

It is recommended to set up a virtual environment and run the project through this. Creating a virtual environment isolates the project's dependencies from the global python environment and ensures that the project only uses the required libraries in the correct versions. A virtual environment helps avoid conflicts between different projects on the same system.

To set up a virtual environment, you can use a Python IDE. In MRC Epidemiology Unit we recommend PyCharm. Follow the instructions in 3. User Guide - Run in PyCharm for downloading PyCharm and setting up a virtual environment. Complete the steps up to and including 'Installing requirements'. Once you have done these initial preparations, you can set up a batch script to run the project, so you don't have to interact with PyCharm when executing the script.

It is also possible to run the script through a batch file without having to download PyCharm. In this case, you would need to install the project's requirements through the Command Prompt using a command like pip install -r requirements.txt. This installs the dependencies directly into the global Python environment. This means the packages, including their versions, will be installed system-wide and could affect other Python projects and cause conflicts if different projects require different versions of the same packages.

For this reason we recommend setting up a virtual environment to keep project's dependencies isolated. Since we recommend using a virtual environment, further instructions on setting up the batch file without one are not provided.

Preparing batch file

A batch file is a text file that contains a list of commands for your computer to execute automatically. These files have a .bat extension. By double-clicking the batch file, your computer will run the Python scripts without needing to interact with a Python IDE (e.g., PyCharm).

Before running the script through the batch file, you will need to edit it to run the project-specific code. Follow the instructions below to modify the batch file:

Instructions for editing the batch file

  1. Open the "Acc_Post_Processing_Bat.bat" file:
    • Navigate to the _analysis folder where the "Acc_Post_Processing_Bat.bat" file is located.
    • Right click on the file and select one of the following options:
      • Edit with Notepad (++) (or any text editor of your choise)
      • Edit (this will automatically open the file in Notepad)

image

  1. Edit the Python Interpreter path:
    • Within the batch file, you will see two sets of "". The first set is where you will place the path to the Python interpreter.
    • To locate the Python interpreter (i.e., python.exe) for the virtual environment:
      • Navigate to the project's _analysis folder, then go to .venv. → Scripts.
      • Copy the full path to this folder, including python.exe, and paste it inside the first set of "".

image

  1. Edit the Python Script path:

    • In the second set of " ", you will place the path to the Acc_Post_Processing_Orchestra.py script. To find this path:
      • Navigate to the location of the Acc_Post_Processing_Orchestra.py file within the project.
      • Copy the full path, including the script name, and paste it inside the second set of "".
  2. Save the Batch File:

    • Once you have edited the paths, the batch file should not need editing again.
    • Save the batch file by pressing Ctrl + s or navigate to File > Save.
    • Close the text editor.

Editing the script

Project specific settings for post processing should be edited before executing the script. The only files in the project that may require editing are Config.py and Acc_Post_Processing_Orchestra.py. Follow the steps below to edit these files.

Editing Config.py

The Config.py file contains all study-specific settings for post processing. The settings are commented to explain their use, with variables that should be edited clearly marked with EDIT, and those that do not need editing marked with DO NOT EDIT.

  1. Open Config.py in Notepad:
    • Right-click on the Config.py file and select Edit with Notepad (any version of notepad is fine).
  2. Modify variables:
    • The following variables should be edited as a minimum. Use forward slashes / in the path, e.g., 'H:study_name/_analysis/Wave_PostProcessing-master'.:
      • PROJECT → Enter the name of the project for which data is being processed.
      • PROCESSING → Specify if the files were processed through Wave or Pampro.
      • ROOT_FOLDER → Provide the folder path to the main project directory. This directory should contain the _results, _analysis, _logs, _releases, _feedback and _data folders.
      • TIMEZONE → If you need to adjust for local clock changes, set this variable to the local time zone where the data was collected. Refer to the documentation on Timezones for more details.
  3. Save your changes:
    • Once all changes have been made, save the file by pressing Ctrl + s or by selecting File > Save All.
    • Close Notepad.

The config.py file is now updated with project-specific settings. It should not need further editing unless you wish to make change to the settings throughout the study.

Editing Acc_Post_Processing_Orchestra.py

The Acc_Post_Processing_Orchestra.py file controls which parts of the post-processing code will run. You need to specify which sections of the code you want to execute.

  1. Open Acc_Post_Processing_Orchestra.py in Notepad:
    • Right-click on the Acc_Post_Processing_Orchestra.py file and select Edit with Notepad (any version of notepad is fine).
  2. Edit the SWTICHES section:
    • In the SWITCHES section, change the RUN_ variables to 'Yes' if you want to run this part of the code, or 'No' if you do not want to run this part. Some parts of the code can run independently, while others depend on prior sections being executed. Refer to the explanation of code for a description of each part.

image

  1. Save your changes:
    • Once all changes have been made, save the file by pressing Ctrl + s or by selecting File > Save All.
    • Close Notepad.

The script is now configured and ready to run.

Run script

To execute the script, follow these steps:

  1. Run the batch file:
    • Double click the Acc_Post_Processing_Bat.bat file to start the script.
    • If a pop up window appears asking whether you are sure you want to run the script/app, click "Run anyway" to proceed.
image
  1. Monitor progress:
    • The batch script will execute the Acc Post Processing code. During this process, messages will appear in the Command Prompt window, showing the progress of the script as it runs through different parts of the file.
image
  1. Completion:
    • Once the script has finished running, a message will be displayed that the process is complete. Press 'Enter' to close the Command Prompt window.

image

Output

The process generates release files of the post-processed accelerometer data. It can produce release files on minute-level, hourly, daily and summary level. Each file will include data for all files/participants appended together. These files will be saved in the _releases folder. Each file will have an accompanying data dictionary. All files will be in CSV format.

If the RUN_VERIFICATION_CHECKS is activated to run in the Acc_Post_Processing_Orchestra.py file, a verification log will be produced. The log will be saved in the _logs folder. It provides summaries of the post processed data and notes any issues encountered during the processing of accelerometer files. Review the log to identify any files that may need removal before finalising the release files.

Clone this wiki locally