Interface and documentation on how to create an interface to the HERMES software.
Project description
Getting Started
Entrypoint
All you need to in order to make your model compatible is to define an entry point, a simple function, for your model. With a predefined format for input and output from this entrypoint, hermes is then able to execute your model and store the results in the database using that funcion.
def entrypoint(input: dict) -> list:
# Call and execute your model here.
return output
Usage
The description of the formats used for the input and output of the entrypoint can be found in the input and output format sections. If you want, you can stop there, without installation of this package, as hermes doesn't need anything else. If you would like to have some kind of validation of the input and output of your entrypoint, you can install this package and read the validation section.
Input and Output Formats
The validate_entrypoint decorator will validate the input and output of the entrypoint, and raise an error if the input or output is not valid. The induced parameter is optional, and defaults to False. If set to True the input fields injection_observation and injection_plan will be validated as well.
Input Format
The input dictionary has the following fields:
model_input = {
'forecast_start': 'datetime'
'forecast_end': 'datetime',
'injection_observation': 'list[hydjson]',
'injection_plan': 'hydjson',
'bounding_polygon': 'wkt(str)',
'depth_min': 'float',
'depth_max': 'float'
'seismicity_observation': 'quakeml',
'model_parameters': 'dict'
}
Following a complete description of the input fields:
forecast_start: datetime.datetime
Date and time from when on the forecast should be made.
forecast_end: datetime.datetime
Date and time until when the forecast should be made.
injection_observation: list[dict] # HYDJSON format
A list of dictionaries in the HYDJSON format, containing the history of injections into the well.
injection_plan: str | dict # HYDJSON format
A dictionary in the HYDJSON format, containing the planned injections.
seismicity_observation: str # QUAKEML format
An XML string in the QUAKEML format, containing the seismic events catalog.
model_parameters: dict
A dictionary containing the parameters for the model. The keys are the names of the parameters, and the values are the values of the parameters.
bounding_polygon: str # WKT format
depth_min: float
depth_max: float
The geometry of the area of interest. The bounding_polygon is a string in the WKT format. It is the model's responsibility to discretize the area of interest and to calculate the forecast for each discretized volume.
Output Format
The output of the entrypoint should be a list of forecasts, where each entry in the list represents the forecast for one timestep. The forecasts can be one of two types, either Catalogs of events, including their magnitude, location and time, or a a parametric description of the seismicity, including at least a, b and mc values.
Each forecast should be returned either as a pd.DataFrame() object, or, if using the SeismoStats package, as a (Forecast)Catalog object or a (Forecast)GRRateGrid object.
In any case, they each need two attributes, starttime and endtime, which are datetime.datetime objects defining the timestep for which the forecast is made.
def entrypoint(input: dict) -> list:
catalog = pd.DataFrame(#your data here)
catalog.starttime = datetime.datetime(2020, 11, 24, 14, 47, 9)
catalog.endtime = datetime.datetime(2020, 11, 24, 15, 47, 9)
return [catalog]
Catalog
If returning a Catalog of events, the returned object should have at least the following columns:
time longitude latitude depth magnitude
0 2020-11-24 14:47:09.823149 8.474492 46.509983 1294.102992 -2.82
1 2020-11-24 15:28:54.648949 8.474545 46.510010 1268.102992 -2.94
2 2020-11-24 15:31:42.411869 8.474323 46.509967 1265.102992 -3.03
3 2020-11-24 15:35:01.114360 8.474359 46.509832 1260.102992 -2.95
4 2020-11-24 15:35:07.995789 8.474372 46.509814 1261.102992 -2.94
It is possible to return multiple realizations of catalogs for one timestep. In this case a catalog_id column is required, to distinguish between the different realizations:
time longitude latitude depth magnitude catalog_id
0 2020-11-24 14:47:09.823149 8.474492 46.509983 1294.102992 -2.82 0
1 2020-11-24 15:28:54.648949 8.474545 46.510010 1268.102992 -2.94 0
2 2020-11-24 15:31:42.411869 8.474323 46.509967 1265.102992 -3.03 0
3 2020-11-24 15:35:01.114360 8.474359 46.509832 1260.102992 -2.95 1
4 2020-11-24 15:35:07.995789 8.474372 46.509814 1261.102992 -2.94 1
GRRateGrid
If using a grid of Gutenberg-Richter rates, the returned object should have at least the following columns:
longitude_min longitude_max latitude_min latitude_max depth_min depth_max a b mc
0 8.472518 8.476478 46.508451 46.511185 1121.433 1421.434 -26.1 2.1 -2.91
Additional columns are allowed. Currently number_events, alpha are also stored if available.
Similar to the catalog, grid_id can be used to return probabilistic forecast, returning multiple possible realizations of a grid per timestep:
longitude_min longitude_max latitude_min latitude_max depth_min depth_max a alpha b mc grid_id
0 8.472518 8.476478 46.508451 46.511185 1121.434 1421.434 -26.1 -5.3 2.1 -2.91 0
1 8.472518 8.476478 46.508451 46.511185 1121.434 1421.434 -26.1 -5.3 2.1 -2.91 1
2 8.472518 8.476478 46.508451 46.511185 1121.434 1421.434 -26.1 -5.3 2.1 -2.91 2
3 8.472518 8.476478 46.508451 46.511185 1121.434 1421.434 -26.1 -5.3 2.0 -2.91 3
Validation
If you would like to have some kind of validation of the input and output of your entrypoint, you can install this package following these instructions.
The changes to the entrypoint are minimal:
from hermes import validate_entrypoint, ModelInput
@validate_entrypoint(induced=True)
def entrypoint(model_input: ModelInput):
# Call and execute your model here.
return output
Note, that you now don't have a dict anymore inside the function, but an object, with the fields of the input format as attributes. The validate_entrypoint decorator will validate the input and output of the entrypoint, and raise an error if the input or output is not valid.
The induced parameter is optional, and defaults to False. If set to True the input fields injection_observation and injection_plan will be validated as well. Note, that if you're using the validation for induced seismicity, you need to install the package with the extra 'hydws' dependency:
Installation
If you want to use the validation features, you can install the package by running the following command:
# basic installation
pip install git+https://gitlab.seismo.ethz.ch/indu/hermes-model.git
# installation with hydws dependency
pip install 'hermes-model[hydws] @ git+https://gitlab.seismo.ethz.ch/indu/hermes-model.git'
You can reference the dependency in your requirements.txt or setup.cfg file as well:
# basic dependency
hermes-model @ git+https://gitlab.seismo.ethz.ch/indu/hermes-model.git
# dependency with hydws
hermes-model[hydws] @ git+https://gitlab.seismo.ethz.ch/indu/hermes-model.git
Dependencies
The data formats we rely on are HYDJSON for the models forecasting induced seismicity, and QUAKEML for the events data. To work with those formats, we use the two packages hydws-client and SeismoStats respectively. It is not required to use them as well, but this package uses them to validate the input and output data, and they are very handy to work with quakeml and hydjson. hydws-client will only be installed, if you install the package with the extra 'hydws' dependency.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hermes_model-0.1.0.tar.gz.
File metadata
- Download URL: hermes_model-0.1.0.tar.gz
- Upload date:
- Size: 48.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
12968bdfc9b48db1ce5db590166aef1286fc8eee1e16c469f35b27dbd9a89e65
|
|
| MD5 |
10aa97358c36b0dcb85e4058e8bbb80c
|
|
| BLAKE2b-256 |
d3d35ef72f79664c8951cedd0bb89313d5ddff80e4e92418ad94ed3501190f42
|
Provenance
The following attestation bundles were made for hermes_model-0.1.0.tar.gz:
Publisher:
publish.yml on swiss-seismological-service/hermes-model
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hermes_model-0.1.0.tar.gz -
Subject digest:
12968bdfc9b48db1ce5db590166aef1286fc8eee1e16c469f35b27dbd9a89e65 - Sigstore transparency entry: 220414130
- Sigstore integration time:
-
Permalink:
swiss-seismological-service/hermes-model@d4b2e8c50735cb53845389019e852945c2c5172a -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/swiss-seismological-service
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d4b2e8c50735cb53845389019e852945c2c5172a -
Trigger Event:
push
-
Statement type:
File details
Details for the file hermes_model-0.1.0-py3-none-any.whl.
File metadata
- Download URL: hermes_model-0.1.0-py3-none-any.whl
- Upload date:
- Size: 32.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7ec8be103660fab6f0465787b310636afcfef3085cb5dae4d04f73bdff0e6c8
|
|
| MD5 |
33505cc118f15d086b512cd417ce8c6f
|
|
| BLAKE2b-256 |
4a38d1c1e0e73fecfc6c26d86c6d79edfdf4012392d4fba4d66078bb40a83bad
|
Provenance
The following attestation bundles were made for hermes_model-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on swiss-seismological-service/hermes-model
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hermes_model-0.1.0-py3-none-any.whl -
Subject digest:
e7ec8be103660fab6f0465787b310636afcfef3085cb5dae4d04f73bdff0e6c8 - Sigstore transparency entry: 220414132
- Sigstore integration time:
-
Permalink:
swiss-seismological-service/hermes-model@d4b2e8c50735cb53845389019e852945c2c5172a -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/swiss-seismological-service
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d4b2e8c50735cb53845389019e852945c2c5172a -
Trigger Event:
push
-
Statement type: