Skip to content

chirplab.py

Jeff Davis edited this page May 19, 2025 · 2 revisions

chirplab.py

chirplab.py serves as the entry point into both the GUI and command-line interfaces for Chirplab.


Input Parameters

chirplab.py (or chirplab.exe or equivalent when Chirplab is bundled as an executable) takes and processes input parameters when called on the command line. argparse is used for conventional argument handling.

  • 'project': If any parameters are passed to Chirplab, the first parameter must be the path to a Chirplab project file. chirplab.py will load the project file into CLProject.project. If a Chirplab project file is "opened with" Chirplab, the project file is passed in as the only parameter
  • '-s' or '--stimulus': The desired output path of a stimulus file, which is generated based on the output parameters of the given project file. If 'stimulus' is given, Chirplab will exit after generating the stimulus file
  • '-c': If the '-c' flag (for "command-line mode") is passed in, Chirplab will initialize the given project file and measurements, process all of the measurements, and save the measurement outputs, then exit
  • command-line overrides: There are a few additional parameters that can be passed to override values in the project file that is used for CLI processing
    • 'i' or '--input': override the file specified in CLProject.project['input']['file']
    • '--channel': override the input channel specified in `CLProject.project['input']['channel']
    • '-o': specify an output directory path where output measurement data will be saved. If '-o' is not specified, output measurement data will be saved to the same directory as the specified project file

If a Chirplab is called with no parameters, CLProject.project is initialized with CLProject.new_project() and runs in GUI mode.


Chirplab Initialization

After parsing input parameters, chirplab.py will:

  • set CLProject.gui_mode to True if the input parameters do not specify '-s' or '-c'. Other parts of the code can check gui_mode if behavior is different between GUI mode and CLI mode. If Chirplab is running in GUI mode and also in a bundled Windows .exe, some additional console window handling is applied to mitigate a Windows 11 terminal bug that interacts poorly wiht PyInstaller
  • in GUI mode, initialize a Qt app and set some Qt flags to optimize pyqtgraph interactions with high DPI screens
  • load the given project file or create a new project
  • call CLAnalysis.check_sox() to make sure SoX is available for reading/writing audio files. If SoX is not found and Chirplab is running on Windows, the user is prompted to download SoX
  • in GUI mode, create and show a CLGui.MainWindow. Otherwise, start command-line mode processing

Command-Line processing

When a project file and the '-c' flag are given, chirplab.py will process the measurements defined in the project file in command-line mode.

  • call CLMeasurements.init_measurements() to create a list of measurement objects, CLProject.measurements, for each measurement defined in the project
  • call CLAnalysis.generate_stimulus() to create the internal reference chirp stimulus signal and store it in CLProject.signals['stimulus']
  • read in the file specified in the project (or overridden with the '-i' switch) and store the data in CLProject.signals['raw_response'] and CLProject.IO['input']
  • call CLAnalysis.read_response() to detect, align, and trim the response signal from the raw response channel specified in CLProject.project['input']['channel'] (or overridden with the '--channel' switch) and storing it in CLProject.signals['response']
  • loop through each measurement, calling the measurement's .measure() method, followed by the measurement's .save_measurement_data() method. The data output directory is passed to .save_measurement_data(), either the input project file directory or the path specified by the '-o' override

Clone this wiki locally