geoprior.utils.target_utils#

Target-processing helpers for GeoPrior workflows.

Functions

as_tuple(obj, *[, names, model, ctx, ...])

Convert obj to an ordered tuple of outputs.

get_output_names([model, y, y_pred, ...])

Try to obtain stable output names (best-effort, Keras-3-safe).

update_compiled_metrics(model, y_true, y_pred, *)

Keras-3-safe compiled metrics updater.

geoprior.utils.target_utils.get_output_names(model=None, y=None, y_pred=None, *, exclude_keys={'aux', 'data_final', 'data_mean_raw', 'maps', 'phys_final', 'phys_mean_raw', 'physics'})[source]#

Try to obtain stable output names (best-effort, Keras-3-safe).

Lookup priority is: model._output_keys or model._output_names first, then model.output_names, then keys from y_pred, and finally keys from y.

geoprior.utils.target_utils.as_tuple(obj, *, names=None, model=None, ctx='value', strict=True, exclude_keys={'aux', 'data_final', 'data_mean_raw', 'maps', 'phys_final', 'phys_mean_raw', 'physics'}, to_numpy='never')[source]#

Convert obj to an ordered tuple of outputs.

Supports:
  • dict: ordered by names (or inferred)

  • list/tuple: returns tuple(obj)

  • tensor/ndarray/scalar: returns (obj,)

Parameters:
  • obj (Any) – Targets/predictions container.

  • names (list[str] or None) – Desired order of outputs.

  • model (Any or None) – Model used to infer output names (via _output_keys/output_names).

  • strict (bool) – If True, missing keys in dict raises KeyError.

  • to_numpy ({"never","auto","always"}) – Optional conversion of individual leaves to numpy (only safe in eager).

Returns:

Ordered outputs.

Return type:

tuple

geoprior.utils.target_utils.update_compiled_metrics(model, y_true, y_pred, *, output_names=None, to_numpy='never')[source]#

Keras-3-safe compiled metrics updater.

  • Prefers dict structure (since you compiled with dict loss/metrics).

  • Ensures deterministic output order via output_names/_output_keys.

  • Falls back to list/tuple update_state if needed.

  • Final fallback: manual per-metric update (won’t crash training).

Note: converting to numpy inside train_step is generally NOT safe.