This project provides a Python tool designed to support a workflow where a generative AI specialized in seismic monitoring analyzes standardized waveform images to detect seismic signals and estimate seismic phase arrivals.
The core idea is to reproduce the visual workflow of an experienced seismic analyst in a seismic monitoring room, allowing the AI to interpret waveform plots rather than raw time series data.
The tool performs waveform acquisition, standardized plotting, and automated zoom generation around candidate seismic phases to enable iterative AI-assisted phase picking.
The workflow is structured in two main stages.
The tool generates a full waveform plot from seismic data retrieved via FDSN services.
The generative AI receives this image and determines:
- whether a seismic signal is present
- whether a P phase is visible
- whether a S phase is visible
- approximate positions of the phases on the waveform
The AI returns approximate pick positions measured directly on the full waveform image.
Using the preliminary picks returned by the AI, the tool automatically generates high-resolution zoom plots centered on:
- the P phase
- the S phase
These zoomed images are then provided back to the AI for fine picking.
At this stage the AI returns:
- refined P pick
- refined S pick
- phase visibility (if the phase is not observable)
- uncertainty estimate (possibly asymmetric)
- polarity, when determinable
The project is based on several principles:
Instead of feeding raw waveform arrays directly into a model, the system presents carefully designed waveform plots that mimic the visual representation used by human analysts.
Plots are generated with controlled properties:
- high resolution
- consistent time axes
- precise tick spacing
- standardized scaling
This ensures both human readability and AI interpretability.
The picking process is intentionally split into two stages:
- coarse detection on the full waveform
- high-precision picking on zoomed views
This approach mirrors the workflow used in manual seismic analysis.
The current tool provides:
- waveform download via FDSN dataselect
- metadata caching via FDSN station
- per-channel MiniSEED export
- standardized waveform plots
- automatic P and S zoom generation
- configurable plotting parameters via JSON
The generative AI used in this project must return its picking results in a structured JSON file that can be used as input by waves2saian.py in --zoom mode.
This JSON is intended to represent the output of one AI interpretation step on waveform images.
The JSON file allows the tool to:
- associate AI picks with specific stations
- use AI-generated P and S picks to create high-resolution zoom plots
- optionally carry uncertainty, polarity, and suggested preprocessing parameters
The JSON file contains:
- an optional
eventsection - a mandatory
stationsarray - one object per station analyzed by the AI
An example is reported at the bottom of the instruction.txt file in this repository.
The following operational guidelines detail the setup and execution phases required to run the SAIAN pipeline, as extracted and translated from the reference document SAIAN_Workflow.pdf.
- Clone the repository into your local environment:
git clone git@github.com:INGV/saian.git
- Create a dedicated working directory in your preferred location (e.g.,
saian_working_dir). - Copy the
saian_config.jsonconfiguration file from the Git repository into your working directory. - Within the working directory, create a text file named
path_to_git_saian.txtcontaining the absolute path to your local Git repository.
- Interpreter: Python 3.12 or a library-compatible environment is strictly required.
- The pipeline leverages a
requirements.pyscript (which reads thepath_to_git_saian.txtfile) to validate that all required dependencies are present in your Python environment. - Best Practice: It is highly recommended to instantiate an isolated virtual environment (e.g., via
conda), install the necessary packages within it, and execute all subsequent pipeline commands from this environment.
- Access the Gemini web interface and navigate to the Gems section via the sidebar.
- Create a new Gem. Naming it SAIAN is optional but highly recommended for workflow clarity.
- Set the Description parameter to:
Makes picks on waveforms. - In the Instructions configuration block, paste the entire contents of the
instructions.txtfile found in the cloned Git repository. - Save the Gem configuration.
- Invoke the newly configured GEM and record its unique alphanumeric identifier from the browser URL (e.g., if the URL is
https://gemini.google.com/gem/873ddab7290d, the GEM ID is873ddab7290d).
By default, the saian_config.json file is configured to interface with the INGV web services.
- Select a target event from the INGV earthquake database (accessible via
https://terremoti.ingv.itor subsequent endpoints). - Retrieve and copy the Event ID. Note that supplying an Origin ID is strictly optional; if omitted, the scripts will automatically default to the "preferred" origin metadata.
- Open a terminal session and ensure your Python virtual environment is active.
- Navigate to your designated working directory.
- Execute the shell script using the following syntax:
/path_to_saian_repo/saian_run.sh [eventid] [originid] 0 100
Execution Subroutines:
- The script extracts a list of stations belonging to the
IVnetwork (Note: The script currently hardcodes the network variable, as well as theHHandEHchannels, passing them via the--networksand--channelsarguments to the underlying Python backend). - It filters for stations located within an epicentral distance range of 0 to 100 km (handled via the
--distancesflag). - It provisions a dedicated event directory named
waveforms_event_eid[eventid]_oid[originid]and creates station-specific subdirectories within it. - Waveforms are temporally sliced starting 5 seconds prior to the theoretical P-wave arrival and ending 20 seconds after the theoretical S-wave arrival (as dictated by the
saian_config.jsonparameters). - Outputs generated per station:
- A
.pngimage representing the "full cut", featuring the three seismic components stacked vertically. - The corresponding raw
.mseeddata files. - Extracted JSON metadata files.
- A
Important: Utilizing the Event ID and Origin ID precisely as they appear in the directory name generated during STEP 1 is mandatory for this execution phase.
Initiate the master automation controller:
python3 /path_to_SAIAN_git_dir/saian_auto_runner.py --eventid [eventid] --originid [originid] --gemid [GEM_ID]Operational Logic and User Interaction: From this point forward, the operational logic is strictly driven by the Python controller. It parses the event directory based on the provided Event ID and Origin ID, iterates through the station subdirectories, verifies their current processing state, and automatically resumes operations from the last completed checkpoint. The script will prompt the user when manual interaction is required.
- Initialization: Upon execution, the script will output the number of identified stations and ask:
Do you want to automatically skip already completed stations (Level 2)? (y/n):. Typingybypasses completed nodes and halts at the first incomplete station; typingnpresents them sequentially for manual skipping. - Browser Setup Requirement: Prior to processing, ensure you have an independent browser window open, separate from tabs running other active Gemini sessions. Keep this window visible alongside your terminal. Always ensure that the active Gemini model is set to the "Reasoning" tier, as browser sessions may cache settings if "Pro" or "Flash" models were active in adjacent tabs. Read terminal prompts carefully to navigate the multithreaded logic correctly.
Stage 1: Preliminary Phase Detection
- The script will instantiate the SAIAN GEM in a new browser tab. (Caution: The script opens new tabs but does not close legacy tabs; the user must manage tab cleanup manually).
- Ensure you are authenticated in the active browser session with an account authorized to access the designated GEM.
- The required prompt text is automatically copied to your system clipboard (or available in the terminal stdout as a fallback).
- Drag and drop the FULL waveform image into the Gemini interface, paste the copied prompt, and execute the query.
- When the GEM generates the JSON response, return to the terminal and type
y, then pressENTER. - The script will automatically create the
stage1.jsonfile in the correct directory path and open it in your system's default text editor. - Copy the JSON code block from Gemini, paste it into the opened text editor, save the file, and close it.
- Press
ENTERin the terminal to acknowledge completion. The controller will evaluate the JSON payload and automatically invokewaves2saian.pywith the--zoomflag to render high-resolution context subsets based on the Stage 1 picks.
Stage 2: High-Resolution Phase Refinement
- Once the zoom processing successfully completes, the script copies the Stage 2 instruction prompt to your clipboard and notifies you that the zoom files are ready.
- Drag and drop the newly generated ZOOM waveform images into the same Gemini instance, paste the Stage 2 prompt, and execute the query.
- Return to the terminal, type
y, and pressENTER. The script will open thestage2.jsonfile. - Copy the refined JSON output from Gemini, ensuring no extraneous markdown or characters are included, paste it into the editor, save, and close.
- Press
ENTERin the terminal. The script will log[Level 2] Processing completed (Stage 2 JSON present)and prompt:Move on to the next station? (y/n):. - Pressing
yinstructs the controller to proceed, which will open a new GEM instance in a new tab for the next station. Wait for the new tab to instantiate fully before closing the previous one; accidental closure of the active tab requires manual reopening.
Critical Stability Warnings:
- You may halt the process at any time by terminating the script.
- Never leave empty JSON files in the workspace directories. Saving a blank JSON file will trigger fatal parsing errors in the
waves2saiandependency, causing the master script to fail and forcing a manual rollback of the file state.