Database API
Database of results handling
- class pyrcmip.database.Database(root_dir)
Bases:
object
On-disk database handler for outputs from SCMs
- get_out_filepath(climate_model, variable, region, scenario, ensemble_member=None)
Get filepath in which data has been saved
The filepath is the root directory joined with the other information provided. The filepath is also cleaned to remove spaces and special characters.
- Parameters
- Returns
Path in which to save the data. If
ensemble_member
isNone
then it is not included in the filename.- Return type
- load_data(climate_model, variable, region, scenario)
Load data from the database
- load_model_reported()
Load all model reported results
- Returns
All model reported results
- Return type
pd.DataFrame
- load_summary_tables()
Load all summary tables
- Returns
All summary tables
- Return type
pd.DataFrame
- save_condensed_file(scmrun)
Save results which have multiple ensemble members
- Parameters
scmrun (
scmdata.ScmRun
) – Results to save in the database- Raises
AssertionError –
ensemble_member
is not included inscmrun
’s metadata
- save_model_reported(res, key='all')
Save model reported data into the database
- Parameters
res (
pd.DataFrame
) – Model reported results to save. Should be the same format as the result ofpyrcmip.assessed_ranges.AssessedRanges.calculate_metric_from_results()
.key (str) – Identifier to use in the filename
- Raises
AssertionError – The columns of res are not as expected (i.e.
{"value", "ensemble_member", "RCMIP name", "unit", "climate_model"}
) or more than one climate model is included inres
.
- save_summary_table(res, file_id)
Save summary table
- Parameters
res (
pd.DataFrame
) – Summary table to savefile_id (str) – Identifier to use in the filename
- Raises
AssertionError – Columns of
res
are not as expected (i.e. not equal to{"assessed_range_label", "assessed_range_value", "climate_model", "climate_model_value", "metric", "percentage_difference", "unit"}
)
- save_to_database(scmrun)
Save a set of results to the database
The results are saved with one file for each
["climate_model", "variable", "region", "scenario", "ensemble_member"]
combination.- Parameters
scmrun (
scmdata.ScmRun
) – Results to save