Experiment Handler
- class floatcsep.experiment.Experiment(name=None, time_config=None, region_config=None, catalog=None, models=None, tests=None, postprocess=None, default_test_kwargs=None, rundir='results', report_hook=None, **kwargs)[source]
Bases:
object
Main 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
timewindows_ti()
andtimewindows_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
/floatcsep
default 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
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
catalog (str)
models (str)
tests (str)
rundir (str)
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
Experiment
class instance
- 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_input_cat(tstring, model)[source]
Filters the complete experiment catalog to an input sub-catalog filtered to the beginning of the test time-window.
- set_models(model_config, order=None)[source]
Parse the models’ configuration file/dict. Instantiates all the models as
floatcsep.model.Model
and 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 sequentially 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_test_cat(tstring)[source]
Filters the complete experiment catalog to a test sub-catalog bounded by the test time-window. Writes it to filepath defined in
Experiment.registry
- Parameters:
tstring (str) – Time window string
- Return type:
None
- set_tests(test_config)[source]
Parse the tests’ configuration file/dict. Instantiate them as
floatcsep.evaluation.Evaluation
and 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
Experiment
instance into a .yml file.Note
This instance can then be reinstantiated using
from_yml()
- Parameters:
- Return type:
None
Returns: