User guide ‐ Run in PyCharm - CAS254/garmin_trimming_acc GitHub Wiki

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 the python code trimming acc files using PyCharm.

Required software

To successfully run the Garmin trim acc files 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.

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
  1. Leave the Name field empty.
  2. For Location, navigate to the folder where you want to run the script from.
  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 folder where you want to run the script from.
  6. Make sure that all other checkboxes remain unticked.
  7. Click Create.
  1. If a pop-up window appears asking whether to open the project in This Window or New Window, choose This Window.

Download Garmin trim acc files Code

  1. Navigate to the Garmin trim acc files main page on GitHub here.
  2. Click , then select Download ZIP.
  3. The ZIP file containing the Garmin trim acc files project will be saved in you Downloads folder.
  4. Move the downloaded zip file to the folder where you want to run the code from.
  5. Unzip the folder and ensure it is named Garmin_trim_acc_files-master.
    • Make sure the extraction process does not create an additional nested folder (e.g.,Garmin_trim_acc_files-master/Garmin_trim_acc_files-master).
  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 (Garmin_trim_acc_files-master, unless renamed) by typing cd Garmin_trim_acc_files-master and press enter.

  3. 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.
  4. Once pip is installed, run the following command to install all necessary packages: pip install -r requirements.txt and press Enter.

    • 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.
  5. 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 should be edited before executing the script.

To edit these files in PyCharm:

  1. Open the left-hand side of PyCharm, locate the project folder structure.
  2. Navigate to the Garmin_trim_acc_files-master folder, which contains all the .py file.
  3. Double-click on the trimming_acc_files.py to view and edit it in the PyCharm editor.

Editing trimming_acc_files.py

  1. Open trimming_acc_files.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/Garmin_trim_acc_files-master'.:
      • data_dir → Provide the folder path to the main data folder for the project. This directory should contain the participant folders with the .csv files exported from fitrockr.
      • data_dir → Provide the folder path to the folder where you want to save the trimmed accelerometer files.
      • sub_folders → If the participant folders with data exported from Fitrockr is saved within sub-folder in the data_dir (e.g., data_dir/controls and data_dir/patients) set this variable to 'Yes'. Set to 'No' if the participant folders are saved directly in the data_dir.
      • sub_folder_dont_include → If data is saved within sub_folders (as specified above) and there are some folders (e.g., _archieve) that you DON'T want to include, specify these here. Each folder name must be within ' ' and separated by , if multiple folders that should be excluded.

Save your changes:

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

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

The script is now configured and ready to run.

Run script

  1. Open the trimming_acc_files.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.

    • Alternatively, you can navigate to Run in the menu bar and select Run trimming_acc_files.py.
  3. 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.

  4. Once the script has completed, a message indicating the end of the process will be displayed. After this, you can safely close PyCharm.

Output

The process generates a trimmed accelerometer file for each participant in the data_dir folder. It will look through the output_dir first and only create a trimmed file for participants that does not already have a trimmed file. The trimmed files will be outputted in CSV format and these files can be processed through GGIR.