Experiment Handler
- class floatcsep.experiment.Experiment(name=None, doi=None, authors=None, journal=None, manuscript_doi=None, catalog_doi=None, last_run=None, floatcsep_version=None, pycsep_version=None, exp_time=None, LICENSE=None, time_config=None, region_config=None, catalog=None, models=None, tests=None, postprocess=None, default_test_kwargs=None, run_dir='results', run_mode='sequential', stage_dir='results', report_hook=None, **kwargs)[source]
Bases:
objectMain class that handles an Experiment’s context. Contains all the specifications, instructions and methods to carry out an experiment.
- Parameters:
name (str) – Experiment name
time_config (dict) –
Contains all the temporal specifications. It can contain the following keys:
start_date (
datetime.datetime): Experiment start dateend_date (
datetime.datetime): Experiment end dateexp_class (
str): ti (Time-Independent) or td (Time-Dependent)intervals (
int): Number of testing intervals/windowshorizon (
str,float): Time length of the forecasts (e.g. 1, 10, 1 year, 2 days). ti defaults to years, td to days.growth (
str): incremental or cumulativeoffset (
float): recurrence of forecast creation.
For further details, see
time_windows_ti()andtime_windows_td()region_config (dict) –
Contains all the spatial and magnitude specifications. It must contain the following keys:
region (
str,csep.core.regions.CartesianGrid2D): The geographical region, which can be specified as: (i) the name of acsep/floatcsepdefault region function (e.g.california_relm_region()) (ii) the name of a user function or (iii) the path to a lat/lon filemag_min (
float): Minimum magnitude of the experimentmag_max (
float): Maximum magnitude of the experimentmag_bin (
float): Magnitud bin sizemagnitudes (
list,numpy.ndarray): Explicit magnitude binsdepth_min (
float): Minimum depth. Defaults to -2depth_max (
float): Maximum depth. Defaults to 6000
model_config (str) – Path to the models’ configuration file
test_config (str) – Path to the evaluations’ configuration file
run_mode (str) – ‘sequential’ or ‘parallel’
default_test_kwargs (dict) – Default values for the testing (seed, number of simulations, etc.)
postprocess (dict) – Contains the instruction for postprocessing (e.g. plot forecasts, catalogs)
**kwargs – see Note
doi (str)
authors (str)
journal (str)
manuscript_doi (str)
catalog_doi (str)
last_run (str)
floatcsep_version (str)
pycsep_version (str)
exp_time (str)
LICENSE (str)
catalog (str)
models (str)
tests (str)
run_dir (str)
stage_dir (...)
report_hook (dict)
Note
Instead of using time_config and region_config, an Experiment can be instantiated using these dicts as keywords. (e.g.
Experiment( **time_config, **region_config),Experiment(start_date=start_date, intervals=1, region='csep-italy', ...)- classmethod from_yml(config_yml, repr_dir=None, **kwargs)[source]
Initializes an experiment from a .yml file. It must contain the.
attributes described in the
Experiment,read_time_config()andread_region_config()descriptions- Parameters:
- Returns:
An
Experimentclass instance
- get_test(name)[source]
Returns an Evaluation by its name string.
- Parameters:
name (str)
- Return type:
- make_repr()[source]
Creates a reproducibility configuration file, re-directing the forecasts/catalog paths, in order to reproduce the existing results and compare them with previous runs.
- Return type:
None
- read_results(test, window)[source]
Reads an Evaluation result for a given time window and returns a list of the results for all tested models.
- Parameters:
test (Evaluation)
window (str)
- Return type:
- set_models(model_config, order=None)[source]
Parse the models’ configuration file/dict. Instantiates all the models as
floatcsep.model.Modeland store them intoExperiment.models.
- set_tasks()[source]
Lazy definition of the experiment core tasks by wrapping instances, methods and arguments. Creates a graph with task nodes, while assigning task-parents to each node, depending on each Evaluation signature. The tasks can then be run in sequential as a list or asynchronous using the graph’s node dependencies. For instance:
A forecast can only be made if catalog was filtered to its window
A consistency test can be run if the forecast exists in a window
A comparison test requires the forecast and ref forecast
A sequential test requires the forecasts exist for all windows
A batch test requires all forecast exist for a given window.
- Return type:
None
- set_tests(test_config)[source]
Parse the tests’ configuration file/dict. Instantiate them as
floatcsep.evaluation.Evaluationand store them intoExperiment.tests.- Parameters:
test_config (dict, list, str) – configuration file or dictionary containing the evaluation initialization attributes, as defined in
Evaluation()- Return type:
- stage_models()[source]
Stages all the experiment’s models. See
floatcsep.model.Model.stage()- Return type:
None
- to_yml(filename, **kwargs)[source]
Serializes the
Experimentinstance into a .yml file.Note
This instance can then be reinstantiated using
from_yml()- Parameters:
- Return type:
None
Returns: