credit.metrics#

credit.metrics — verification metrics for CREDIT training and rollout.

This package hosts two metric generations:

  • credit.metrics.gen_1.metrics — the legacy flat-tensor metrics (LatWeightedMetrics and friends) used by the Gen 1 / LES / WRF trainers. They are re-exported here so the historical import from credit.metrics import LatWeightedMetrics keeps working after the credit/metrics.py module was folded into this package.

  • credit.metrics.base — the Gen 2 per-variable metrics (BaseVariableMetric / BaseCombinedMetric and the built-in RMSEMetric / MSEMetric / MAEMetric / BiasMetric) that score the postblock full_data_dict in physical units, mirroring credit.losses.base.BaseLoss.

Construction is config-driven via load_metric(), dispatched on conf["metrics"]["type"] (mirroring credit.losses.load_loss()).

Submodules#

Attributes#

Functions#

__getattr__(name)

register_metric(metric_type)

Decorator that adds an external metric class to the metric registry.

load_metric(conf[, validation])

Load a metric (or combined metric) from the config.

Package Contents#

credit.metrics.logger#
credit.metrics.DEFAULT_METRIC_TYPES = ('rmse', 'r2score', 'bias')#
credit.metrics.__getattr__(name)#
credit.metrics.register_metric(metric_type)#

Decorator that adds an external metric class to the metric registry.

The class must inherit from credit.metrics.base.BaseVariableMetric (or otherwise accept the Gen 2 full_data_dict forward contract).

Parameters:

metric_type – Key used in the config metrics section.

Example (Python decorator):

from credit.metrics import register_metric
from credit.metrics.base import BaseVariableMetric

@register_metric("my_metric")
class MyMetric(BaseVariableMetric):
    ...

Example (config custom_objects):

custom_objects:
  MyMetric:
    object_type: metric
    module_path: mypackage.metrics

metrics:
  type: combined
  args:
    metrics: {rmse: {}, MyMetric: {}}
credit.metrics.load_metric(conf, validation=False)#

Load a metric (or combined metric) from the config.

Dispatches on conf["metrics"]["type"], mirroring credit.losses.load_loss(). The Gen 2 combined type returns a credit.metrics.base.BaseCombinedMetric holding one or more credit.metrics.base.BaseVariableMetric subclasses; any other registered type returns a single metric instance. When the metrics section is omitted, the default combined metric contains rmse, r2score, and bias with uniform variable weighting.

Parameters:
  • conf (dict) –

    Configuration dictionary. An optional metrics section uses the new-style {type, args} format; when omitted, rmse, r2score, and bias are loaded with uniform variable weighting:

    metrics:
      type: combined
      args:
        metrics: {rmse: {}, mae: {}, bias: {}}
        var_weighting: "inverse_variance"
        scaler_path: "/path/scaler.json"
        use_latitude_weights: true
        latitude_weights: "/path/static.zarr"
    

  • validation (bool, optional) – Reserved for API symmetry with credit.losses.load_loss(). Currently unused by the metric classes (metrics are not optimized).

Returns:

A metric instance callable as metrics(full_data_dict) -> dict[str, float].

Return type:

torch.nn.Module

Raises:

ValueError – If the requested metric type is not in _METRIC_REGISTRY.