sup3r.utilities.loss_metrics.ObsAssimilationLoss#
- class ObsAssimilationLoss(gen_features, true_features=None, blend_distance=1)[source]#
Bases:
Sup3rLossLoss for training with both dense and sparse ground truth where the obs locations are explicitly considered. This is designed to encourage matching observations where they exist while blending smoothly back to the dense background field over a Gaussian neighbourhood around each observation.
Assumes
true_featurescontainsgen_featuresfollowed by sparse observation versions of those same features in matching order. For example:gen_features = ['u_10m', 'v_10m'] true_features = ['u_10m', 'v_10m', 'u_10m_obs', 'v_10m_obs'] The loss is a single MAE term between generator output and a blended target field: 1. At obs locations, the target is the observed value. 2. Away from obs, the target relaxes back toward the dense background. 3. Between the two, a Gaussian kernel determines the observation influence out to ``blend_distance`` grid cells.- Parameters:
gen_features (list of str) – Generator output feature names (N features).
true_features (list of str | None) – True-data feature names. Must contain 2N entries: the first N match
gen_features(dense reference) and the last N are the corresponding sparse observation features (NaN where missing). Defaults togen_features + [f + '_obs' for f in gen_features].blend_distance (int) – Spatial distance in grid cells over which the Gaussian observation/background blend is applied. A value of 0 uses the observation exactly at observed cells and the background everywhere else.
Methods
call(x_true, x_gen)Evaluate the sparse observation loss.
from_config(config)get_config()Attributes
LOSS_METRICdtype- __call__(y_true, y_pred, sample_weight=None)#
Call self as a function.
- call(x_true, x_gen)[source]#
Evaluate the sparse observation loss.
- Parameters:
x_true (tf.Tensor) – True data of shape
(B, H, W, 2C)or(B, H, W, T, 2C). The first C channels are dense reference fields; the last C channels are sparse obs fields (NaN where no observation).x_gen (tf.Tensor) – Generator output of shape
(B, H, W, C)or(B, H, W, T, C).
- Returns:
tf.Tensor – Scalar (0-D) loss value.