credit.preblock.nan#

Classes#

FillNan

Replace NaN values with a constant fill value for selected variables.

Module Contents#

class credit.preblock.nan.FillNan(variables: list[str] = None, data_types: list[str] = None, fill_value: float = 0.0)#

Bases: credit.preblock.base.BasePreblock

Replace NaN values with a constant fill value for selected variables.

Walks a nested batch dict of the form batch[data_type][source][var_key] and replaces any NaN entries with fill_value for the selected variables. Only NaNs are touched; +/-inf and finite values are left unchanged.

variables may contain full or partial names (e.g. "era5/prognostic/3d" expands to every variable beneath it) and is expanded against the first batch via credit.preblock._utils._parse_variable_selection(). An empty or omitted variables list means “every variable”. Specifying a subset lets several FillNan preblocks coexist, each filling different variables with a different value.

Config example:

type: "fill_nan"
args:
    variables:                  # optional, defaults to all variables
        - "era5/prognostic/3d/Q"
    data_types:                 # optional, defaults to ['input', 'target']
        - "input"
        - "target"
    fill_value: 0.0             # optional, default 0.0
variables = []#
variables_expanded = False#
data_types = ['input', 'target']#
fill_value = 0.0#
forward(batch: dict) dict#