Calibrator#

class dtcg.integration.calibration.Calibrator(model_matrix=None, datacube_l1=None, gdir=None)[source]#

Bases: object

Bindings for calibrating OGGM models.

Parameters:

model_matrix (dict)

model_matrix#

Matrix of model calibration parameters for different run configurations.

Type:

dict, default None

datacube_l1#
Type:

Any, default None

gdir#

An OGGM glacier directory.

Type:

GlacierDirectory, default None

Methods

__init__([model_matrix, datacube_l1, gdir])

add_annual_cumulative(ds, var[, year_coord, ...])

add_snowline_attrs(ds[, inf_values])

add_specific_mb(ds, mb_model, fls, ...)

Get specific mass-balance in mm w.e.

add_specific_mb_attrs(ds, unit)

calculate_and_add_total_runoff(ds)

Get total annual and monthly runoff from runoff components.

calibrate(gdir[, model_matrix, datacube_l1, ...])

Calibrate the mass balance model and create L2 datacubes using a model matrix.

get_calibrated_datacubes(mb_model_class, ...)

Calibrate models and generate datacubes.

get_mcs_parameter_sample(gdir, ...[, ...])

Defines the distribution of the observation and model parameters and create a sample for the Monte Carlo simulation.

get_nearest_datetime(dates, target_date)

Get the nearest datetime.

get_ref_mb(gdir[, ref_mb_period, ...])

Get observed mass balance for a specific reference period.

set_model_matrix(name, model, geo_period, ...)

Set model parameters for calibration.

__init__(
model_matrix=None,
datacube_l1=None,
gdir=None,
)[source]#
Parameters:

model_matrix (dict)

add_annual_cumulative(
ds,
var,
year_coord='calendar_year',
cumulative_suffix='calendar_cumulative',
)[source]#
Parameters:
  • ds

  • var

  • year_coord

  • cumulative_suffix

add_snowline_attrs(ds, inf_values=None)[source]#
Parameters:
  • ds

  • inf_values

add_specific_mb(
ds,
mb_model,
fls,
time_resolution,
unit,
)[source]#

Get specific mass-balance in mm w.e. from a volume change time series.

Parameters:
  • ds

  • mb_model

  • fls

  • time_resolution

  • unit

add_specific_mb_attrs(ds, unit)[source]#
Parameters:
  • ds

  • unit

calculate_and_add_total_runoff(ds)[source]#

Get total annual and monthly runoff from runoff components.

Parameters:

ds

calibrate(
gdir,
model_matrix=None,
datacube_l1=None,
ignore_errors=False,
**kwargs,
)[source]#

Calibrate the mass balance model and create L2 datacubes using a model matrix.

Parameters:
  • gdir (GlacierDirectory) – Glacier directory.

  • model_matrix (dict) – Model parameters for various calibration runs.

  • datacube_l1 (xr.Dataset) – If the reference mass balance should be derived from an observation data, which is available in a L1 datacube.

  • ignore_errors (bool) – If True any exception raised during the calibration is ignored.

  • kwargs (dict) – kwargs passed on to Calibrator.get_calibrated_datacubes

Returns:

Containing the created L2 datacubes for each set of configuration parameters in model_matrix

Return type:

dict

get_calibrated_datacubes(
mb_model_class,
ref_mb,
ref_mb_err,
ref_mb_unit='kg m-2 yr-1',
ref_mb_period='',
gdir=None,
first_guess_settings='',
datacube_types='monthly',
calibration_filesuffix='',
calibration_strategy='',
mcs_sampling_settings=None,
calibration_parameters_control=None,
calibration_parameters_mcs=None,
quantiles=None,
climate_input_filesuffix='',
show_log=False,
multiprocessing_during_datacube_creation=True,
**kwargs,
)[source]#

Calibrate models and generate datacubes.

Uses the provided reference mass balance to calibrate models and generate model datacubes. These also include an uncertainty propagation through a Monte Carlo simulation.

Parameters:
  • gdir (GlacierDirectory) – OGGM glacier directory.

  • mb_model_class (oggm.core.massbalance.MassBalanceModel) – OGGM mass balance model class.

  • ref_mb (float) – Reference mass balance.

  • ref_mb_err (float) – Reference mass balance uncertainty.

  • ref_mb_unit (str, default "kg m-2 yr-1") – Unit used for the reference mass balance.

  • ref_mb_period (str, optional) – Measurement period for the reference mass balance.

  • first_guess_settings (str, optional) – the mb parameters which should be used as a first guess

  • datacube_types (str or list[str], default "monthly") –

    Desired datacube types. Select one or provide a list. Options are:

    • monthly: monthly volume, area, length and mass balance.

    • annual_hydro: annual volume, area, length and mass balance, and annual and monthly runoff components.

    • daily_smb: daily mass balance.

  • calibration_filesuffix (str) – The filesuffix used for all outputs of this method.

  • calibration_strategy (str) – Text describing the current calibration strategy, e.g. “OGGM model X calibrated with data from Y over the period Z.”

  • mcs_sampling_settings (dict, default None) – Settings for Monte Carlo simulation parameter sampling. For default values look at signature of Calibrator.get_mcs_parameter_sample.

  • calibration_parameters_control (dict, default None) –

    The order of calibration parameters for the control run. If None, defaults to:

    {
        "calibrate_param1": "melt_f",
        "calibrate_param2": "prcp_fac",
        "calibrate_param3": "temp_bias",
    }
    

  • calibration_parameters_mcs (dict, default None) –

    The order of calibration parameters for the Monte Carlo simulation runs. If None, defaults to:

    {
        "calibrate_param1": "prcp_fac",
        "calibrate_param2": "melt_f",
        "calibrate_param3": "temp_bias",
    }
    

  • quantiles (list, default None) – The quantiles used for the aggregation of the Monte Carlo simulation results, including labels for the final datacube. If None, defaults to [0.05, 0.15, 0.25, 0.50, 0.75, 0.85, 0.95].

  • climate_input_filesuffix (str, optional) – The filesuffix of the climate input file.

  • show_log (bool, default False) – Show some basic logs during execution if True.

  • kwargs (dict) – kwargs to pass to the mb_model_class instance.

  • multiprocessing_during_datacube_creation (bool)

Returns:

The model datacubes generated by using the provided data for calibration, including uncertainties.

Return type:

dict

get_mcs_parameter_sample(
gdir,
control_filesuffix,
nr_samples=16,
ref_mb_err_sample_interval=1.0,
prcp_fac_sample_interval=0.5,
temp_bias_sample_interval=0.5,
melt_f_sample_interval=0.25,
)[source]#

Defines the distribution of the observation and model parameters and create a sample for the Monte Carlo simulation.

Parameters:
  • gdir (GlacierDirectory)

  • control_filesuffix (str) – The filesuffix for the control run’s settings, which used only the most likely values of the default calibration.

  • nr_samples (int, default 2^4.) – Number of samples. Must be a multiple of 2. The total number of generated samples equals nr_samples * (4 + 2), where 4 is the number of variables used for sampling (ref_mb, prcp_fac, melt_f, temp_bias).

  • ref_mb_err_sample_interval (float, default 1.0) – Multiplication factor applied to ref_mb_err. It assumes ref_mb has a normal distribution.

  • prcp_fac_sample_interval (float, default 0.5) –

    The width of the bounds which are added and subtracted from the prcp_fac of the control run. A uniform distribution

    is used for sampling.

  • temp_bias_sample_interval (float, default 0.5) –

    The width of the bounds which are added and subtracted from the temp_bias of the control run. A uniform distribution

    is used for sampling.

  • melt_f_sample_interval (float, default 0.5) –

    The width of the bounds which are added and subtracted from the melt_f of the control run. A uniform distribution

    is used for sampling.

Return type:

tuple

get_nearest_datetime(dates, target_date)[source]#

Get the nearest datetime.

Parameters:
  • dates (array_like) – A range of dates that can be converted to datetime64.

  • target_date (str) – Date in the ISO-8601 format “YYYY-MM-DD”.

get_ref_mb(
gdir,
ref_mb_period=None,
datacube_l1=None,
source='Hugonnet',
)[source]#

Get observed mass balance for a specific reference period.

Parameters:
  • gdir (GlacierDirectory)

  • datacube_l1 (xr.Dataset) – If the reference mass balance should be derived from an observation data, which is available in a L1 datacube.

  • ref_mb_period (str) – Reference calibration period in the format <YYYY-MM-DD_YYYY-MM-DD>.

  • source (str) – Define the observation source

Returns:

ref_mb, ref_mb_unit, ref_mb_err, ref_mb_period: the reference mass balance to match with unit, associated uncertainty and valid period.

Return type:

tuple

set_model_matrix(
name,
model,
geo_period,
**kwargs,
)[source]#

Set model parameters for calibration.

Parameters:
  • name (str) – Name of configuration parameters. Ideally this should match the settings filesuffix.

  • model (oggm.core.massbalance.MassBalanceModel) – OGGM mass balance model class.

  • geo_period (str) – Reference mass balance period in the format YYYY-MM-DD_YYYY-MM-DD.

  • kwargs – Additional arguments passed to the mass balance model class.