H - A Time-Dependent Experiment
Here, we run an experiment that accesses, containerizes and executes multiple time-dependent models, and then proceeds to evaluate the forecasts once they are created.
TL; DR
In a terminal, navigate to floatcsep/tutorials/case_h and type:
$ floatcsep run config.yml
After the calculation is complete, the results will be summarized in results/report.md.
The experiment region, catalog, forecasts and results can be viewed in the Experiment Dashboard with:
$ floatcsep view config.yml
For troubleshooting, run the experiment with:
$ floatcsep run config.yml --debug
Experiment Components
The experiment input files are:
case_h
├── catalog.csv
├── config.yml
├── tests.yml
└── models.yml
The
models.ymlcontains the instructions to clone and build the source codes from software repositories (e.g., gitlab, Github), and how to interface them with floatCSEP. Once downloaded and built, the experiment structure should look like this:
case_h
├── models
├── etas
└── ... (ETAS source code)
├── pymock_poisson
└── ... (Poisson-PyMock source code)
└── pymock_nb
└── ... (Negative-Binomial-PyMock source code)
├── catalog.csv
├── config.yml
├── tests.yml
├── custom_report.py
└── models.yml
Configuration
Models
As in Tutorial G, each Model requires to build and execute a source code to generate forecasts. The instructions for each model are located within models.yml, which we further explain here:
Note
The models.yml will define how to interface floatCSEP to each Model, implying that a Model should be developed, or adapted to ensure the interface requirements specified below.
The repository URL of each model and their specific versions if needed (e.g., commit hash, tag, release) are specified as:
tutorials/case_h/models.yml- etas: giturl: https://github.com/swiss-seismological-service/etas.git repo_hash: csep/v1.0.0 - Poisson Mock: giturl: https://github.com/pabloitu/pymock.git - Negbinom Mock: giturl: https://github.com/pabloitu/pymock.git
A
pathneeds to be indicated for each model, to both download the repository contents therein and from where the source code will be executed.tutorials/case_h/models.yml1- etas: 2 giturl: https://github.com/swiss-seismological-service/etas.git 3 repo_hash: csep/v1.0.0 4 path: models/etas
Important
The implies that the inputs (catalog and argument file) should be read by the model from a
{path}/inputfolder, and the forecast outputs stored into a folder{path}/forecasts.
There is some flexibility to interface floatCSEP with a model. For instance, a different filepath can be set for the argument file:
tutorials/case_h/models.yml1- etas: 2 giturl: https://github.com/swiss-seismological-service/etas.git 3 repo_hash: csep/v1.0.0 4 path: models/etas 5 build: conda 6 args_file: args.json
Note
floatCSEP can read .txt, .json and .yml format-styled argument files. In all cases, the minimum required arguments, should be formatted as:
#.txt start_date = {DATESTRING} end_date = {DATESTRING}
#.yml start_date: {DATESTRING} end_date: {DATESTRING}
//.json "start_date": "{DATESTRING}", "end_date": "{DATESTRING}"
floatcsep will dynamically modify the
start_dateandstart_datefor each time window run, and any extra arguments will just be added for all time-windows.
The
funcentry indicates how the models are invoked from a shell terminal.tutorials/case_h/models.yml- etas: func: etas-run - Poisson Mock: func: pymock - Negbinom Mock: func: pymock
Important
Please refer to Tutorial G for example of how to set up
funcfor the model and interface it to floatCSEP.A prefix for the resulting forecast filepaths can be specified beforehand for each model. Without specifying this, the default is
{model_name}(e.g., etas, Poisson Mock, Negbinom Mock).tutorials/case_h/models.yml- Poisson Mock: prefix: pymock - Negbinom Mock: prefix: pymock
The experiment will read the forecasts as:
{model_path}/forecasts/{prefix}_{start}_{end}.csv
where
startandendfollow either the%Y-%m-%dT%H:%M:%S.%f- ISO861 FORMAT, or the short date version%Y-%m-%dif the windows are set by midnight.Additional function arguments can be passed to the model with the entry
func_kwargs. Both Poisson Mock and Negbinom Mock use the same source code, but a different subclass can be defined withfunc_kwargs(in this case, a Negative-Binomial number distribution instead of Poisson).tutorials/case_h/models.yml- Poisson Mock: func_kwargs: n_sims: 1000 mag_min: 3.5 seed: 23 - Negbinom Mock: func_kwargs: n_sims: 1000 mag_min: 3.5 seed: 23 distribution: negbinom apply_mc_to_lambda: True
Note
For further details on how to configure time-dependent models, see Models Configuration
Time
The configuration is identical to time-independent models, with the exception that now a
horizoncan be defined instead ofintervals, which is the forecast time-window length. The experiment’s class should now be explicited asexp_class: tdtutorials/case_h/config.ymltime_config: start_date: 2016-8-25T00:00:00 end_date: 2016-8-26T00:00:00 horizon: 1days exp_class: td
Catalog
The catalog was obtained prior to the experiment using
query bsi, but it was filtered from 2006 onwards, so it has enough data for the model calibration.
Tests
Catalog-based evaluations found in
csep.core.catalog_evaluationscan be used.tutorials/case_h/tests.yml- Catalog_N-test: func: catalog_evaluations.number_test func_kwargs: verbose: False plot_func: - plot_test_distribution: plot_args: title: Number consistency test bins: 30 - plot_consistency_test: plot_args: title: Number consistency testNote
It is possible to assign two plotting functions to a test, whose
plot_argsandplot_kwargscan be placed indented beneath.
Custom Post-Process
A custom reporting function can be set within the
postprocessconfiguration to replace thegenerate_report():tutorials/case_h/config.ymlpostprocess: report: custom_report.py:mainThis option provides hook for a Python script and a function within as:
{python_sript}:{function_name}The script must be located within the same directory as the configuration file, whereas the function must receive a
floatcsep.experiment.Experimentas argument:def main(experiment): """ Args: experiment: a floatcsep.experiment.Experiment classIn this way, the report function use all the
Experimentattributes/methods to access catalogs, forecasts and test results. The scripttutorials/case_h/custom_report.pycan also be viewed directly in the GitHub repository, where it is exemplified how to access the experiment artifacts.
Running the experiment
The experiment can be run by simply navigating to the
tutorials/case_hfolder in the terminal and typing:$ floatcsep run config.ymlThis will automatically set all the calculation paths (testing catalogs, evaluation results, figures) and will create a summarized report in
results/report.md.To view the results in a dashboard, type:
$ floatcsep view config.yml
pyCSEP under the hood
Classes and functions used in this tutorial
Catalog:
csep.core.catalogs.CSEPCatalog
csep.load_catalog()Region:
csep.core.regions.italy_csep_regionForecast class:
csep.core.forecasts.CatalogForecast
csep.load_catalog_forecast()Test functions:
Result plotting functions:
csep.utils.plots.plot_number_test()
csep.utils.plots.plot_consistency_test()Where to learn pyCSEP further: