Metrics Module

Classes:
Metric - Abstract Base Class from which all metrics must inherit.
class metrics.Bias

Calculate the bias between a reference and target dataset.

run(ref_dataset, target_dataset)

Calculate the bias between a reference and target dataset.

Note

Overrides BinaryMetric.run()

Parameters:
  • ref_dataset (dataset.Dataset) – The reference dataset to use in this metric run.
  • target_dataset (dataset.Dataset) – The target dataset to evaluate against the reference dataset in this metric run.
Returns:

The difference between the reference and target datasets.

Return type:

numpy.ndarray

class metrics.BinaryMetric

Abstract Base Class from which all binary metrics inherit.

run(ref_dataset, target_dataset)

Run the metric for the given reference and target datasets.

Parameters:
  • ref_dataset (dataset.Dataset) – The Dataset to use as the reference dataset when running the evaluation.
  • target_dataset (dataset.Dataset) – The Dataset to use as the target dataset when running the evaluation.
Returns:

The result of evaluation the metric on the reference and target dataset.

class metrics.Metric

Base Metric Class

class metrics.PatternCorrelation

Calculate the correlation coefficient between two datasets

run(ref_dataset, target_dataset)

Calculate the correlation coefficient between two dataset.

Note

Overrides BinaryMetric.run()

Parameters:
  • ref_dataset (dataset.Dataset) – The reference dataset to use in this metric run.
  • target_dataset (dataset.Dataset) – The target dataset to evaluate against the reference dataset in this metric run.
Returns:

The correlation coefficient between a reference and target dataset.

class metrics.RMSError

Calculate the Root Mean Square Difference (RMS Error), with the mean calculated over time and space.

run(reference_dataset, target_dataset)
Calculate the Root Mean Square Difference (RMS Error), with the mean
calculated over time and space.

Note

Overrides BinaryMetric.run()

Parameters:
  • reference_dataset (dataset.Dataset) – The reference dataset to use in this metric run
  • target_dataset (dataset.Dataset) – The target dataset to evaluate against the reference dataset in this metric run
Returns:

The RMS error, with the mean calculated over time and space

class metrics.SpatialPatternTaylorDiagram

Calculate the target to reference ratio of spatial standard deviation and pattern correlation

run(ref_dataset, target_dataset)

Calculate two metrics to plot a Taylor diagram to compare spatial patterns

Note

Overrides BinaryMetric.run()

Parameters:
  • ref_dataset (dataset.Dataset) – The reference dataset to use in this metric run.
  • target_dataset (dataset.Dataset) – The target dataset to evaluate against the reference dataset in this metric run.
Returns:

standard deviation ratio, pattern correlation coefficient

Return type:

:float:’float’,’float’

class metrics.StdDevRatio

Calculate the standard deviation ratio between two datasets.

run(ref_dataset, target_dataset)

Calculate the standard deviation ratio.

Note

Overrides BinaryMetric.run()

Parameters:
  • ref_dataset (dataset.Dataset) – The reference dataset to use in this metric run.
  • target_dataset (dataset.Dataset) – The target dataset to evaluate against the reference dataset in this metric run.
Returns:

The standard deviation ratio of the reference and target

class metrics.TemporalCorrelation

Calculate the temporal correlation coefficients and associated confidence levels between two datasets, using Pearson’s correlation.

run(reference_dataset, target_dataset)
Calculate the temporal correlation coefficients and associated
confidence levels between two datasets, using Pearson’s correlation.

Note

Overrides BinaryMetric.run()

Parameters:
  • reference_dataset (dataset.Dataset) – The reference dataset to use in this metric run
  • target_dataset (dataset.Dataset) – The target dataset to evaluate against the reference dataset in this metric run
Returns:

A 2D array of temporal correlation coefficients and a 2D array of confidence levels associated with the temporal correlation coefficients

class metrics.TemporalMeanBias

Calculate the bias averaged over time.

run(ref_dataset, target_dataset)

Calculate the bias averaged over time.

Note

Overrides BinaryMetric.run()

Parameters:
  • ref_dataset (dataset.Dataset) – The reference dataset to use in this metric run.
  • target_dataset (dataset.Dataset) – The target dataset to evaluate against the reference dataset in this metric run.
Returns:

The mean bias between a reference and target dataset over time.

class metrics.TemporalStdDev

Calculate the standard deviation over the time.

run(target_dataset)

Calculate the temporal std. dev. for a datasets.

Note

Overrides UnaryMetric.run()

Parameters:target_dataset (dataset.Dataset) – The target_dataset on which to calculate the temporal standard deviation.
Returns:The temporal standard deviation of the target dataset
Return type:ndarray
class metrics.UnaryMetric

Abstract Base Class from which all unary metrics inherit.

run(target_dataset)

Run the metric for a given target dataset.

Parameters:target_dataset (dataset.Dataset) – The dataset on which the current metric will be run.
Returns:The result of evaluating the metric on the target_dataset.
metrics.calc_bias(target_array, reference_array, average_over_time=False)

Calculate difference between two arrays

Parameters:
  • target_array (:class:'numpy.ma.core.MaskedArray') – an array to be evaluated, as model output
  • reference_array (:class:'numpy.ma.core.MaskedArray') – an array of reference dataset
  • average_over_time ('bool') – if True, calculated bias is averaged for the axis=0
Returns:

Biases array of the target dataset

Return type:

:class:’numpy.ma.core.MaskedArray’

metrics.calc_correlation(target_array, reference_array)

Calculate the correlation coefficient between two arrays.

Parameters:
  • target_array (:class:'numpy.ma.core.MaskedArray') – an array to be evaluated, as model output
  • reference_array (:class:'numpy.ma.core.MaskedArray') – an array of reference dataset
Returns:

pearson’s correlation coefficient between the two input arrays

Return type:

:class:’numpy.ma.core.MaskedArray’

metrics.calc_histogram_overlap(hist1, hist2)

from Lee et al. (2014) :param hist1: a histogram array :type hist1: :class:’numpy.ndarray’ :param hist2: a histogram array with the same size as hist1 :type hist2: :class:’numpy.ndarray’

metrics.calc_joint_histogram(data_array1, data_array2, bins_for_data1, bins_for_data2)

Calculate a joint histogram of two variables in data_array1 and data_array2 :param data_array1: the first variable :type data_array1: :class:’numpy.ma.core.MaskedArray’ :param data_array2: the second variable :type data_array2: :class:’numpy.ma.core.MaskedArray’ :param bins_for_data1: histogram bin edges for data_array1 :type bins_for_data1: :class:’numpy.ndarray’ :param bins_for_data2: histogram bin edges for data_array2 :type bins_for_data2: :class:’numpy.ndarray’

metrics.calc_rmse(target_array, reference_array)

Calculate ratio of standard deivations of the two arrays

Parameters:
  • target_array (:class:'numpy.ma.core.MaskedArray') – an array to be evaluated, as model output
  • reference_array (:class:'numpy.ma.core.MaskedArray') – an array of reference dataset
  • average_over_time ('bool') – if True, calculated bias is averaged for the axis=0
Returns:

root mean square error

Return type:

:class:’float’

metrics.calc_stddev(array, axis=None)

Calculate a sample standard deviation of an array along the array

Parameters:
  • array (:class:'numpy.ma.core.MaskedArray') – an array to calculate sample standard deviation
  • axis ('int') – Axis along which the sample standard deviation is computed.
Returns:

sample standard deviation of array

Return type:

:class:’numpy.ma.core.MaskedArray’

metrics.calc_stddev_ratio(target_array, reference_array)

Calculate ratio of standard deivations of the two arrays

Parameters:
  • target_array (:class:'numpy.ma.core.MaskedArray') – an array to be evaluated, as model output
  • reference_array (:class:'numpy.ma.core.MaskedArray') – an array of reference dataset
  • average_over_time ('bool') – if True, calculated bias is averaged for the axis=0
Returns:

(standard deviation of target_array)/(standard deviation of reference array)

Return type:

:class:’float’

metrics.wet_spell_analysis(reference_array, threshold=0.1, nyear=1, dt=3.0)

Characterize wet spells using sub-daily (hourly) data

Parameters:
  • reference_array (:class:'numpy.ma.core.MaskedArray') – an array to be analyzed
  • threshold ('float') – the minimum amount of rainfall [mm/hour]
  • nyear ('int') – the number of discontinous periods
  • dt ('float') – the temporal resolution of reference_array