credit.preblock.log#

Classes#

LogTransform

Applies a log transformation with an eps offset to specified variables in a batch dict.

Module Contents#

class credit.preblock.log.LogTransform(variables: list[str], data_types: list[str] = None, base: str = 'e', eps: float = 1e-08)#

Bases: credit.preblock.base.BasePreblock

Applies a log transformation with an eps offset to specified variables in a batch dict.

Applies y = log_base(x + eps) - log_base(eps) so that y = 0 when x = 0, regardless of eps. Use ExpTransform in the postblock to invert this with matching base and eps. Input values should satisfy x >= -eps; values below this produce NaN silently.

Operates on batch[data_type][source][var_key] for each requested data_type (default: ["input", "target"]).

variables supports the same shorthand as the scaler: an empty list transforms every variable; partial paths (e.g. "era5/prognostic") expand to all variables under that hierarchy. Expansion happens lazily on the first forward call.

Config example:

type: "log_transform"
args:
    variables:
        - "era5/prognostic/3d/Q"
    data_types:     # optional, defaults to ["input", "target"]
        - "input"
        - "target"
    base: "e"       # optional, default "e". Options: "e", "2", "10"
    eps: 1.0e-8     # optional, default 1e-8

# or transform all variables:
type: "log_transform"
args:
    variables: []
variables#
variables_expanded = False#
data_types = ['input', 'target']#
forward(batch: dict) → dict#