Skip to content

3. User guide ‐ Run in PyCharm

CAS254 edited this page Mar 4, 2025 · 66 revisions

PyCharm

PyCharm is the preferred software within the MRC Epidemiology Unit for conducting command-line tasks. It is a free integrated development environment (IDE) available for both Windows and Linux machines. PyCharm simplifies the command-line workflow, making it accessible even for users less familiar with the command line. The steps below need to be completed to run Acc Post Processing using PyCharm.

Required software

To successfully run the Acc Post Processing code in PyCharm, ensure that both Python and PyCharm (community - free edition) are installed on your computer. If they are not already installed, please use the links below to download and install them. Be sure to select the correct version for your operating system.

It is recommended to install Python 3.12. Future versions may be incompatible, though compatibility will be tested as new versions are released.

Prepare folder structure

Create the following folders in your study directory (if they haven't already been created when running Wave/Pampro). While you can use different names, the following structure and naming is recommended:

  • _analysis: Store the Python script here after downloading it from GitHub.
  • _data: This folder contains the data being processed (Used when processing through Wave/Pampro)
  • _feedback
  • _logs: When running Acc Post Processing, you have the option to run verification checks. The results of these checks will be logged and saved in this folder.
  • _releases: Final release files, along with a data dictionary, will be saved in this folder.
  • _results: The output from processing through Wave/Pampro should be saved here. Subfolders will be created automatically during Acc Post Processing to organise the results.
image

If the code is run on Pampro output you will furthermore have to create the following folder:

*_anomalies: Anomalies found through processing accelerometry files through Pampro will be saved here.

Preparing PyCharm

It is recommended to set up a virtual environment in PyCharm to run the script. A virtual environment isolates the project's dependencies from the global Python environment, ensuring that the correct libraries and versions are used exclusively for this project.

Setting up a virtual environment

  1. Open PyCharm
  2. Navigate to Menu > File > New Project
image
  1. Leave the Name field empty.
  2. For Location, navigate to the _analysis folder and save the virtual environment here.
image
  1. Under Interpreter type, select Custom environment.
  2. Choose Generate new in the Environment section.
  3. In Type, select Virtualenv.
  4. In Base python, select the Python interpreter (You'll recognise it by the directory that includes python.exe).
  5. In Location, make sure the virtual environment (.venv) is saved inside the _analysis folder.
  6. Make sure that all other checkboxes remain unticked.
  7. Click Create.
image
  1. If a pop-up window appears asking whether to open the project in This Window or New Window, choose This Window.
image

Download Acc Post Processing Code

  1. Navigate to the Acc Post Processing main page on GitHub here.
  2. Click image, then select Download ZIP.
  3. The ZIP file containing the Acc Post Processing project will be saved in you Downloads folder.
  4. Move the downloaded zip file to the _analysis folder inside your study directory.
  5. Unzip the folder and ensure it is named Acc_Post_Processing-master.
    • Make sure the extraction process does not create an additional nested folder (e.g.,Acc_Post_Processing-master/Acc_Post_Processing-master). To avoid this, click Browse, choose a destination, and select the _analysis folder as the location for the extracted files.
  6. After unzipping, you can delete the original ZIP file.

Installing Requirements

To run the script, you will need to install some Python packages. Follow the steps below to do this:

  1. In PyCharm, navigate to the Terminal tab located at the bottom-left corner. This will open a terminal window displaying the directory for the virtual environment.
  2. Navigate to the folder you downloaded from GitHub (Acc_Post_Processing-master, unless renamed) by typing cd Acc_Post-Processing-master and press enter.

image

  1. Ensure that you have the pip package manager installed by typing python -m ensurepip and press enter.
    • This will check if pip is installed and download it if necessary.
    • Pip is a tool that simplifies the process of downloading, installing and updating Python packages.
  2. Once pip is installed, run the following command to install all necessary packages: pip install -r requirements.txt and press Enter.

image

  • The requirements.txt file contains a list of all the packages needed to run the script.
  • The terminal will display the installation process, showing the packages being downloaded and installed into you virtual environment.
  • The installation is complete once the terminal returns to the original directory path with a > symbol at the end. This process may take a few minutes.
  1. At this point, all the required packages have been installed, and you will not need to repeat this step for this project.

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.

To edit these files in PyCharm:

  1. Open the left-hand side of PyCharm, locate the project folder structure.
  2. Navigate to the Acc_Post_Processing-master folder, which contains all the project's .py files.
  3. Double-click on the file you wish to open (either Config.py or Acc_Post_Processing_Orchestra.py) to view and edit it in the PyCharm editor.

image

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 PyCharm
  2. Modify variables:
    • The following variables should be edited as a minimum. Use forward slashes / in the path, e.g., 'H:study_name/_analysis/Acc_Post_Processing-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.

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.

After editing the config.py file, open the Wave_PostProcessingOrchestra.py file.

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 PyCharm.
  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.

The script is now configured and ready to run.

Run script

  1. Open the Acc_Post_Processing_Orchestra.py file in PyCharm (If it's not already open).
  2. To run the script click the Run icon image at the top of the PyCharm window.

image

  • Alternatively, you can navigate to Run in the menu bar and select Run Acc_Post_Processing_Orchestra.py.

image

  1. As the script runs, progress messages will appear in the terminal window at the bottom of PyCharm, showing the script's execution through various stages.
image
  1. Once the script has completed, a message indicating the end of the process will be displayed. After this, you can safely close PyCharm.

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.