src.FRAME_FM.transforms

Submodules

Attributes

DA

DS

TT

transform_mapping

apply_preprocessors

Classes

BaseTransform

FillMissingValueTransform

FillNaNTransform

NormalizeTransform

ScaleTransform

RenameTransform

ResampleTransform

ReshapeTransform

RollTransform

ReverseAxisTransform

SortAxisTransform

SubsetTransform

SqueezeTransform

TilerTransform

A transform that takes a Dataset or DataArray and breaks it into smaller tiles along specified dimensions.

ToDataArray

ToTensorTransform

TransposeTransform

VarsToDimensionTransform

A transform that takes a list of variables from a Dataset and stacks them into a

Functions

resolve_transform(→ BaseTransform)

If a transform is a dictionary with a "type" key, resolve it to the corresponding transform class instance.

apply_transforms(→ xarray.Dataset | xarray.DataArray)

Apply a list of preprocessing transforms to a data sample.

Package Contents

src.FRAME_FM.transforms.DA[source]
src.FRAME_FM.transforms.DS[source]
src.FRAME_FM.transforms.TT[source]
class src.FRAME_FM.transforms.BaseTransform(*args, **kwargs)[source]
abstractmethod __call__(sample)[source]
class src.FRAME_FM.transforms.FillMissingValueTransform(strategy: str = 'constant', fill_value: None | float = None, method: None | str = 'linear')[source]

Bases: BaseTransform

strategy = 'constant'
fill_value = None
method = 'linear'
__call__(sample: DS | DA) DS | DA[source]
class src.FRAME_FM.transforms.FillNaNTransform(strategy: str = 'constant', fill_value: None | float = None, method: None | str = 'linear')[source]

Bases: FillMissingValueTransform

class src.FRAME_FM.transforms.NormalizeTransform(mean: float, std: float)[source]

Bases: BaseTransform

mean
std
__call__(sample: DA) DA[source]
class src.FRAME_FM.transforms.ScaleTransform(mean: float, std: float)[source]

Bases: NormalizeTransform

class src.FRAME_FM.transforms.RenameTransform(var_id: str, new_name: str)[source]

Bases: BaseTransform

var_id
new_name
__call__(sample: DS) DS[source]
class src.FRAME_FM.transforms.ResampleTransform(dim: str, freq: str | int, method: str = 'mean')[source]

Bases: BaseTransform

dim
freq
method = 'mean'
__call__(sample)[source]
class src.FRAME_FM.transforms.ReshapeTransform(shape: tuple)[source]

Bases: BaseTransform

shape
__call__(sample)[source]
class src.FRAME_FM.transforms.RollTransform(dim: str, shift: None | int)[source]

Bases: BaseTransform

dim
shift
__call__(sample)[source]
class src.FRAME_FM.transforms.ReverseAxisTransform(dim: str)[source]

Bases: BaseTransform

dim
__call__(sample)[source]
class src.FRAME_FM.transforms.SortAxisTransform(dim: str, ascending: bool = True)[source]

Bases: BaseTransform

dim
ascending = True
__call__(sample)[source]
class src.FRAME_FM.transforms.SubsetTransform(**subset_selectors)[source]

Bases: BaseTransform

subset_selectors
__call__(sample)[source]
class src.FRAME_FM.transforms.SqueezeTransform(*args, **kwargs)[source]

Bases: BaseTransform

__call__(sample)[source]
class src.FRAME_FM.transforms.TilerTransform(boundary: str = 'pad', **dim_tile_sizes)[source]

Bases: BaseTransform

A transform that takes a Dataset or DataArray and breaks it into smaller tiles along specified dimensions. This uses the xarray coarsen + construct pattern to create non-overlapping tiles of the data, which can be useful for training models on large spatial datasets by reducing memory usage and allowing for batch processing of smaller chunks of data.

boundary = 'pad'
tile_sizes
__call__(sample: DA) DA[source]
class src.FRAME_FM.transforms.ToDataArray(var_id: str)[source]

Bases: BaseTransform

var_id
__call__(sample: DS | DA) DA[source]
class src.FRAME_FM.transforms.ToTensorTransform(*args, **kwargs)[source]

Bases: BaseTransform

__call__(sample: DA | numpy.ndarray) torch.Tensor[source]
class src.FRAME_FM.transforms.TransposeTransform(*args, **kwargs)[source]

Bases: BaseTransform

__call__(sample)[source]
class src.FRAME_FM.transforms.VarsToDimensionTransform(variables: list, new_dim: str, only_vars_with_time: bool = True)[source]

Bases: BaseTransform

A transform that takes a list of variables from a Dataset and stacks them into a new dimension, effectively converting the variable dimension into a coordinate dimension. This is useful for models that expect a single multi-channel input rather than separate variables.

Since the purpose is to prepare the data for conversion to a Tensor, we assume that ancillary variables that are not genuine coordinates can be dropped.

exclusion_vars = ['time_bounds', 'lat_bounds', 'lon_bounds', 'time_bnds', 'lat_bnds', 'lon_bnds', 'crs',...
variables
new_dim
only_vars_with_time = True
__call__(sample)[source]
src.FRAME_FM.transforms.transform_mapping[source]
src.FRAME_FM.transforms.resolve_transform(transform_config: dict) BaseTransform[source]

If a transform is a dictionary with a “type” key, resolve it to the corresponding transform class instance. If it is already an instance of a transform class, return it as is. Args: - transform_config (dict or BaseTransform): The transform configuration to resolve. Returns: - BaseTransform: An instance of a transform class.

src.FRAME_FM.transforms.apply_transforms(data: xarray.Dataset | xarray.DataArray, preprocessors: list) xarray.Dataset | xarray.DataArray[source]

Apply a list of preprocessing transforms to a data sample. :param sample: The input data sample to be transformed. :type sample: xr.Dataset | xr.DataArray :param preprocessors: A list of transform configurations to apply to the sample. :type preprocessors: list

Returns:

The transformed data sample after applying all preprocessors.

Return type:

xr.Dataset | xr.DataArray

src.FRAME_FM.transforms.apply_preprocessors[source]