You can write Python scripts that call the GMrecordsApp application to create high-level workflows.
In the example below we create a Python script to run several subcommands to download and process ground motions recorded close to the epicenter of a magnitude 4.5 earthquake, and then export the results to CSV files and generate a report summarizing the results.
The configuration and parameter files are in the docs/contents/tutorials directory.
In this tutorial, the commands are written to be executed in Jupyter Notebooks.
Within a Jupyter Notebook, commands can be redirected to the terminal with the ! symbol and we make ue of this functionality here.
In this example we specify parameters in the project configuration to produce a small dataset.
We use only the FDSN fetcher and limit the station distance to 0.1 degrees.
The configuration files are in the conf/scripting directory.
First, we list the available projects in the current directory.
!gmrecordsprojects--list
INFO 2025-08-08 17:42:20 | gmrecords._initialize: Logging level includes INFO.
INFO 2025-08-08 17:42:20 | gmrecords._initialize: PROJECTS_PATH: /builds/ghsc/esi/groundmotion-processing/docs/contents/tutorials/.gmprocess
INFO 2025-08-08 17:42:20 | projects.main: Running subcommand 'projects'
Project: cli-tutorial **Current Project**
Conf Path: /builds/ghsc/esi/groundmotion-processing/docs/contents/tutorials/conf/cli
Data Path: /builds/ghsc/esi/groundmotion-processing/docs/contents/tutorials/data/cli
Project: scripting-tutorial
Conf Path: /builds/ghsc/esi/groundmotion-processing/docs/contents/tutorials/conf/scripting
Data Path: /builds/ghsc/esi/groundmotion-processing/docs/contents/tutorials/data/scripting
The PROJECTS_PATH shows the location of the projects configuration file where the information for the projects is stored.
Second, we use the projects subcommand to select the project configuration scripting-tutorial.
!gmrecordsprojects--switchscripting-tutorial
INFO 2025-08-08 17:42:22 | gmrecords._initialize: Logging level includes INFO.
INFO 2025-08-08 17:42:22 | gmrecords._initialize: PROJECTS_PATH: /builds/ghsc/esi/groundmotion-processing/docs/contents/tutorials/.gmprocess
INFO 2025-08-08 17:42:22 | projects.main: Running subcommand 'projects'
Switched to project:
Project: scripting-tutorial **Current Project**
Conf Path: /builds/ghsc/esi/groundmotion-processing/docs/contents/tutorials/conf/scripting
Data Path: /builds/ghsc/esi/groundmotion-processing/docs/contents/tutorials/data/scripting
Third, we create the directory to hold the data.
Note
We include the directory with the processing parameters for the project in the source code.
At this point we have an empty data/scripting directory.
The conf/scripting directory has two files: fetchers/yml and user.yml.
These configuration files hold parameters that override default values provided with the source code.
See Configuration File for more information.
In this example we will consider ground motions recorded for a magnitude 4.5 earthquake east of San Francisco, California.
We have cached a snippet of the results of running gmrecordsdownload--eventidnc73291880 in the tests/data/tutorials directory.
Consequently, we simply copy the data from tests/data/tutorials/nc73291880 to data/scripting/nc73291880.
Now, we need to create a dictionary with the arguments common to all subcommands.
We must include arguments that normally are given default values by the command line argument parser.
INFO 2025-08-08 17:42:27 | gmrecords._initialize: Logging level includes INFO.
INFO 2025-08-08 17:42:27 | gmrecords._initialize: PROJECTS_PATH: /builds/ghsc/esi/groundmotion-processing/docs/contents/tutorials/.gmprocess
INFO 2025-08-08 17:42:27 | process_waveforms.main: Running subcommand 'process_waveforms'
INFO 2025-08-08 17:42:27 | process_waveforms.main: Number of events to process: 1
INFO 2025-08-08 17:42:27 | process_waveforms.main: Processing tag: default
INFO 2025-08-08 17:42:27 | process_waveforms.main: Processing waveforms for event nc73291880 (1 of 1)...
INFO 2025-08-08 17:42:27 | process_waveforms._process_event: Processing 'unprocessed' streams for event nc73291880...
INFO 2025-08-08 17:42:28 | processing.process_streams: Stream: BK.BRIB.01.HN
INFO 2025-08-08 17:42:40 | stream_workspace.add_streams: Adding waveforms for BK.BRIB.01.HN
INFO 2025-08-08 17:42:40 | base._summarize_files_created: No new files created.
INFO 2025-08-08 17:42:40 | gmrecords._initialize: Logging level includes INFO.
INFO 2025-08-08 17:42:40 | gmrecords._initialize: PROJECTS_PATH: /builds/ghsc/esi/groundmotion-processing/docs/contents/tutorials/.gmprocess
INFO 2025-08-08 17:42:40 | compute_station_metrics.main: Running subcommand 'compute_station_metrics'
INFO 2025-08-08 17:42:40 | compute_station_metrics.main: Computing station metrics for event nc73291880 (1 of 1)...
INFO 2025-08-08 17:42:43 | compute_station_metrics._event_station_metrics: Added station metrics to workspace files with tag 'default'.
INFO 2025-08-08 17:42:43 | base._summarize_files_created: No new files created.
INFO 2025-08-08 17:42:43 | gmrecords._initialize: Logging level includes INFO.
INFO 2025-08-08 17:42:43 | gmrecords._initialize: PROJECTS_PATH: /builds/ghsc/esi/groundmotion-processing/docs/contents/tutorials/.gmprocess
INFO 2025-08-08 17:42:43 | compute_waveform_metrics.main: Running subcommand 'compute_waveform_metrics'
INFO 2025-08-08 17:42:43 | compute_waveform_metrics.main: Computing waveform metrics for event nc73291880 (1 of 1)...
INFO 2025-08-08 17:42:44 | compute_waveform_metrics._compute_event_waveform_metrics: Calculating waveform metrics for BK.BRIB.01.HN...
INFO 2025-08-08 17:44:09 | compute_waveform_metrics._compute_event_waveform_metrics: Adding waveform metrics to workspace files with tag 'default'.
INFO 2025-08-08 17:44:09 | base._summarize_files_created: No new files created.
INFO 2025-08-08 17:44:10 | gmrecords._initialize: Logging level includes INFO.
INFO 2025-08-08 17:44:10 | gmrecords._initialize: PROJECTS_PATH: /builds/ghsc/esi/groundmotion-processing/docs/contents/tutorials/.gmprocess
INFO 2025-08-08 17:44:10 | generate_station_maps.main: Running subcommand 'generate_station_maps'
INFO 2025-08-08 17:44:10 | generate_station_maps.main: Generating station maps for event nc73291880 (1 of 1)...
INFO 2025-08-08 17:44:11 | base._summarize_files_created: The following files have been created:
INFO 2025-08-08 17:44:11 | base._summarize_files_created: File type: Station map
INFO 2025-08-08 17:44:11 | base._summarize_files_created: /builds/ghsc/esi/groundmotion-processing/docs/contents/tutorials/data/scripting/nc73291880/stations_map.html
This will produce CSV files with the waveform metrics in the data/scripting directory.