Skip to content

Commit 564d9e3

Browse files
Deploy to GitHub pages
0 parents  commit 564d9e3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+8018
-0
lines changed

.buildinfo

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Sphinx build info version 1
2+
# This file records the configuration used when building these files. When it is not found, a full rebuild will be done.
3+
config: f281a4555231eb4de48eb734f1a4b949
4+
tags: 645f666f9bcd5a90fca523b33c5a78b7

.nojekyll

Whitespace-only changes.

_sources/architecture.rst.txt

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
########################################
2+
Hamlet Architecture and Testing Workflow
3+
########################################
4+
5+
Currently, Hamlet performs spatial-temporal hazard model checks and
6+
statistical evaluation of model consistency and performance against an observed
7+
earthquake catalog.
8+
9+
Hamlet follows this work process:
10+
11+
1. Read in :doc:`YAML configuration file <./yaml_config_file>`, that specifies:
12+
13+
- Which tests to be run
14+
15+
- What parameters for each test
16+
17+
- What input files:
18+
19+
- Seismic Source Model files
20+
21+
- Seismic catalog (observed earthquakes)
22+
23+
- GIS file of spatial bins (optional)
24+
25+
- What to output:
26+
27+
- Reports
28+
29+
- GIS files
30+
31+
2. Reads and process SSM:
32+
33+
1. Loads sources from a single logic tree branch
34+
35+
2. Sorts sources based on their type, with a list for each
36+
37+
3. Sorts the ruptures from all sources by magnitude and into spatial bins:
38+
39+
- Makes :class:`~openquake.hme.utils.bins.SpacemagBin` class that holds
40+
ruptures, observed earthquakes, and both model and empirical
41+
Magnitude-Frequency distributions for each bin.
42+
43+
4. Runs the tests:
44+
45+
- Basic sanity checks (e.g., whether the observed earthquake maximum
46+
magnitude exceeds the model maximum magnitude in each spatial bin)
47+
48+
- Statistical evaluation (i.e., model likelihoods based on the calculated
49+
probabilities of observing the earthquakes in a catalog given the SSM)
50+
51+
- Multiple tests can be run sequentially, without reloading the SSM.
52+
53+
5. Print/write output.
54+
55+
- HTML reports summarizing the results
56+
57+
- GIS files with the test results for each bin
58+
59+
- CSV files of the total model and catalog (within the source bins) MFDs
60+
61+
62+
At this pre-release stage, most of the development has focused on writing the
63+
test framework, rather than creating a broad suite of tests. However, the
64+
framework is functional at this point, and the development of a test suite is
65+
the next priority.

_sources/getting_started.md.txt

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Getting started with Hamlet
2+
3+
Hamlet is easy to use once the input data and configuration are prepared. The
4+
steps to do this are:
5+
6+
## Prepare the hazard model
7+
8+
The hazard model must be in the OpenQuake format. There must be a single XML
9+
file that describes the seismic source model logic tree, including the locations
10+
of the source XML files and other logic tree parameters.
11+
12+
### Decide how the model should be evaluated
13+
14+
Choose whether Hamlet should be run for the entire model as a whole, or for
15+
different components of the model (different logic tree branches, different
16+
seismic source types, etc.). This will control how the data preparation and
17+
testing are done.
18+
19+
### (Optional) Organize the hazard model with a `hamlet` directory
20+
21+
It is recommended to add a new `hamlet` directory with `data` and `output`
22+
sub-directories.
23+
24+
The `data` directory can hold the seismic catalogs and, if
25+
necessary, GIS files specifying the model domain and grid cells.
26+
27+
The `output` directory will hold the HTML reports and any other outputs that are
28+
written during the testing procedure.
29+
30+
The YAML configuration files can be placed in the main `hamlet` directory:
31+
32+
```
33+
model/
34+
in/
35+
ssm/
36+
gmm/
37+
out/
38+
hamlet/
39+
data/
40+
crustal_catalog.csv
41+
slab_catalog.csv
42+
full_catalog.csv (unused in testing)
43+
output/
44+
test_ssm_crustal.yml
45+
test_ssm_slab.yml
46+
```
47+
48+
However, the user is free to organize the Hamlet files in any way; there is no
49+
requirement that the files are in the same directory as the source model, as
50+
long as the paths to the source model and earthquake catalogs are correct in the
51+
YAML configuration file.
52+
53+
### (Optional) Make a new `git` branch for Hamlet
54+
55+
This may be a good way of organizing the results and running Hamlet in a
56+
continuous integration system.
57+
58+
For example, a `git` branch called `hamlet` can have a separate `hamlet`
59+
directory, as specified above. This directory does not exist in the `master`
60+
branch or other branches, and when changes are made to those branches, they can
61+
be pulled into the `hamlet` branch and be evaluated.
62+
63+
This can be configured in a continuous integration environment such that
64+
Hamlet is run on the CI server when the `hamlet` branch is committed, but not
65+
necessarily when commits to `master` or development branches are made.
66+
67+
68+
## Prepare the earthquake catalog(s)
69+
70+
The earthquake catalog should be declustered and, ideally, classified according
71+
to the source types of the earthquakes (i.e., subduction thrust, in-slab,
72+
crustal, etc.). The catalog should also be truncated to some acceptable
73+
completeness date that corresponds to the `investigation_time` parameter used
74+
during the Hamlet evaluations (in the future, completeness tables may be able to
75+
be used instead of a single date, but this is not currently implemented).
76+
77+
The catalog(s) must be CSV files, with columns describing the fields and one row
78+
for each earthquake.
79+
80+
If you are interested in running Hamlet separately for different seismic source
81+
types, then make separate catalogs for the different earthquake categories,
82+
i.e. make CSV files with only crustal events, only subduction megathrust
83+
events, only slab events, etc.
84+
85+
Alternately if the different branches in the model's logic tree would for some
86+
reason correspond to different subsets of the earthquake catalog, the catalog
87+
should be split into separate files for each subset.
88+
89+
90+
## Make the YAML configuration file(s)
91+
92+
See [YAML configuration file](./yaml_config_file.html) for more information.
93+
94+
## Run Hamlet
95+
96+
Once the model, seismic catalog(s) and YAML configuration file(s) (and Hamlet
97+
has been installed), Hamlet can be run like this:
98+
99+
```
100+
hamlet test_ssm_crustal.yml
101+
```
102+

_sources/index.rst.txt

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
==================================================
2+
Hamlet: Hazard Model Evaluation and Testing
3+
==================================================
4+
5+
Hamlet (``openquake.hme``) is a Python package developed (OK, in development)
6+
for qualitative and quantitative evaluation of Probabilistic Seismic Hazard
7+
Analysis (PSHA) models, with the intention of providing feedback to modelers
8+
during the model construction process, to aid model development. Hamlet is
9+
developed by the `GEM Foundation`_, and uses the OpenQuake_ software
10+
extensively.
11+
12+
Hamlet will incorporate several model test frameworks, including those
13+
developed by GEM and some of those developed outside of GEM such as the RELM_
14+
tests. Currently, and likely in the future, the model files will be required to
15+
be in the OpenQuake_ format, regardless of the format of their original
16+
implementation.
17+
18+
Most of the Hamlet evaluations are spatial in nature; the model domain is
19+
discretized into grid cells, and comparisons between observations and model
20+
predictions are performed in each grid cell, to highlight where in the domain
21+
the model matches the observations, and where it might need some refinement.
22+
23+
Additionally, unlike some other hazard model testing frameworks, Hamlet is
24+
designed to operate on separate components of a hazard model, so that each
25+
component can be evaluated against its corresponding data. For example, each
26+
branch of a source model logic tree can be tested independently, and each type
27+
of source (e.g., subduction megathrust, crustal, in-slab) can be tested
28+
independently as well, in the spatial framework described above.
29+
30+
Quickstart
31+
==========
32+
33+
Installation
34+
------------
35+
36+
Hamlet requires installation Python v.3.7+, the OpenQuake_ engine, and some
37+
additional dependencies as well. These are specified in the ``requirements.txt``
38+
file.
39+
40+
(*Note:* A few of the dependencies might be challenging to install. These are
41+
Rtree_ and h3-py_. You may have to install ``libspatialindex`` or
42+
``libspatialindex-dev`` on Linux or MacOS first, depending on your system, for
43+
``Rtree``. ``h3-py`` requires ``cc`` and ``make``, but then on Linux/MacOS can
44+
be installed easily. Please see the documentation for each.)
45+
46+
First, install the OpenQuake_ engine, following directions on that website. You
47+
probably want to install it into a virtual environment, and you may even want to
48+
have a separate virtual environment for running Hamlet than the OpenQuake_
49+
virtual environment that you normally use (this is up to you).
50+
51+
Then, clone the Hamlet repository, and from that directory, install the
52+
requirements::
53+
54+
pip install -r requirements.txt
55+
56+
and then install Hamlet::
57+
58+
pip install -e .
59+
60+
61+
Running Hamlet
62+
--------------
63+
64+
Hamlet only requires a seismic hazard model (implemented in OpenQuake_) and a
65+
processed seismic catalog (declustered, and ideally classified by source type)
66+
to run. Once installed, Hamlet can be run from the command line::
67+
68+
hamlet test_model.yml
69+
70+
``test_model.yml`` is a :doc:`configuration file <yaml_config_file>` in YAML_
71+
format that specifies the source model, seismic catalog, tests to be run, and
72+
other variables and parameters.
73+
74+
75+
Documentation
76+
=============
77+
.. toctree::
78+
:maxdepth: 2
79+
:caption: Contents:
80+
81+
getting_started
82+
architecture
83+
model_test_frameworks/model_test_frameworks
84+
85+
86+
87+
Indices and tables
88+
==================
89+
90+
* :ref:`genindex`
91+
* :ref:`modindex`
92+
* :ref:`search`
93+
94+
95+
.. _YAML: https://yaml.org
96+
.. _GEM Foundation: https://www.globalquakemodel.org
97+
.. _OpenQuake: https://github.com/GEM/oq-engine
98+
.. _RELM: http://cseptesting.org/documents/relm.php
99+
.. _h3-py: https://github.com/uber/h3-py
100+
.. _Rtree: https://toblerity.org/rtree/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
.. _gem-tests-evaluations:
2+
3+
4+
GEM Tests and Evaluations
5+
=========================
6+
7+
8+
These are developed by GEM, sometimes based on the literature, or sometimes
9+
based on our own ideas and implementations. See for
10+
more information, or :mod:`~openquake.hme.model_test_frameworks.gem` for the
11+
function documentation. Sanity checks (as detailed below) are also available
12+
from the GEM testing framework, for convenience during the workflow.
13+
14+
Magnitude-Frequency Distribution based tests
15+
--------------------------------------------
16+
17+
These tests evaluate a model based on the magnitude-frequency distribution (MFD)
18+
inside each grid cell, or in the model as a whole, (for the model component
19+
being tested).
20+
21+
22+
.. _gem-like-test:
23+
24+
*Likelihood test*
25+
26+
Currently, there are two implementations of the MFD likelihood tests, one
27+
'empirical', based on Monte Carlo sampling of the source model in each bin, and
28+
one based on the frequencies in the MFD itself.
29+
30+
In both of these tests, the likelihood of observing the seismicity in the
31+
catalog given the model MFD is calculated through the
32+
33+
Parameters (all are optional, as default values are supplied):
34+
35+
``likelihood_method``
36+
This is how the computations are performed. ``poisson`` uses the Poisson
37+
likelihood, and ``empirical`` uses a Monte Carlo sampling of the MFD. The
38+
default value is ``poisson``.
39+
40+
``investigation_time``
41+
This is how long the time period is for comparing the observed seismicity to
42+
the MFD. Unless you're doing something very crafty, the value should be in
43+
years, and should be the length of the observed earthquake catalog. In the
44+
future, a completeness table may be used instead of this parameter. The
45+
default value is ``1.``
46+
47+
``default_likelihood``
48+
This is the likelihood that results if no earthquake sources are present in
49+
the grid cell. If the cells are built using `h3` (the default option, if no
50+
GIS file for the test is supplied), this parameter will have no effect. The
51+
default value is ``1.``
52+
53+
54+
``not_modeled_val``
55+
This is the likelihood that results if the rate of earthquake production in
56+
that magnitude bin is zero, but there are earthquakes within the magnitude
57+
bin. Standard (or naive) statistical theory suggests that this value should
58+
be zero, as it is in the RELM tests, but because this value is multiplied by
59+
all of the other magnitude bins inside each spatial bin/grid cell, a single
60+
zero value will make the whole model likelihood zero. The default is
61+
``1e-5`` which is a bit more pragmatic.
62+
63+
64+
65+
.. _gem-model-mfd-test:
66+
67+
*Model MFD Evaluation*
68+
69+
The Model MFD evaluation sums up the MFDs from each
70+
:class:`~openquake.hme.utils.bins.SpacemagBin` and makes an MFD for the whole
71+
model, which is then compared to the observed MFD from the earthquake catalog.
72+
This is to produce a figure and currently does not yield any quantitative values
73+
or evaluate the entire model goodness of fit.
74+
75+
Parameters (all are optional):
76+
77+
``investigation_time``
78+
This is the duration of the comparison between the observed seismicity to
79+
the MFD. See :ref:`likelihood <gem-like-test>` above for more information.
80+
81+
``out_csv``
82+
This parameter specifies a filename. If this is given, a CSV table of the
83+
observed and modeled MFDs will be written.
84+
85+
``out_plot``
86+
This parameter specifies a filename. If this is given, a plot of the
87+
observed and modeled MFDs will be written. The file suffix will determine
88+
the plot format. Common formats include ``png``, ``svg`` and ``pdf``. See
89+
the ``matplotlib`` docs for more info.
90+
91+
92+
.._max_mag_check:
93+
94+
*Ensures that the model can produce the maximum observed seismcity in each cell*
95+
96+
This test is borrowed from the Sanity checks. It simply checks to see whether
97+
the sources inside each cell are capable of producing earthquakes as large as
98+
the largest observed earthquakes. Note that there can be some issues with very
99+
large earthquakes (with ruptures larger than the cell size) as the hypocenter
100+
for an observed event may be in a different cell than the most compatible
101+
hypocenter from the sources.
102+
103+
104+
.. _gem-moment-over-under-eval:
105+
106+
*Compares observed and stochastic moment release*
107+
108+
This evaluation generates many synthetic catalogs (stochastic event sets) and
109+
compares the total moment release in each cell for each of the catalogs to the
110+
observed moment release. This evalution helps highlight areas that are more or
111+
less seismically productive than the observations may support.
112+
113+
Parameters:
114+
115+
``investigation_time``: Duration of the catalog (and of the generated
116+
stochastic event sets).
117+
118+
``n_iters``: Number of iterations (stochastic event sets) generated. Note that
119+
generating these catalogs is fairly time-intensive in the current
120+
implementation. For large models, the number of iterations should be kept to
121+
under 50-100 until performance is improved.
122+

0 commit comments

Comments
 (0)