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
  • climate_model (str) – Climate model to retrieve data for

  • variable (str) – Variable to retrieve data for

  • region (str) – Region to retrieve data for

  • scenario (str) – Scenario to retrieve data for

  • ensemble_member (str or None) – Ensemble member to retrieve data for

Returns

Path in which to save the data. If ensemble_member is None then it is not included in the filename.

Return type

str

load_data(climate_model, variable, region, scenario)

Load data from the database

Parameters
  • climate_model (str) – Climate model data to load

  • variable (str) – Variable to load

  • region (str) – Region to load

  • scenario (str) – Scenario to load

Returns

Loaded data

Return type

obj: scmdata.ScmRun

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

AssertionErrorensemble_member is not included in scmrun’s metadata

save_model_reported(res, key='all')

Save model reported data into the database

Parameters
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 in res.

save_summary_table(res, file_id)

Save summary table

Parameters
  • res (pd.DataFrame) – Summary table to save

  • file_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