src.FRAME_FM.transforms.transforms

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.

Module Contents

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

Bases: BaseTransform

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

Bases: FillMissingValueTransform

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

Bases: BaseTransform

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

Bases: NormalizeTransform

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

Bases: BaseTransform

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

Bases: BaseTransform

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

Bases: BaseTransform

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

Bases: BaseTransform

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

Bases: BaseTransform

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

Bases: BaseTransform

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

Bases: BaseTransform

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

Bases: BaseTransform

__call__(sample)[source]
class src.FRAME_FM.transforms.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'[source]
tile_sizes[source]
__call__(sample: DA) DA[source]
class src.FRAME_FM.transforms.transforms.ToDataArray(var_id: str)[source]

Bases: BaseTransform

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

Bases: BaseTransform

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

Bases: BaseTransform

__call__(sample)[source]
class src.FRAME_FM.transforms.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',...[source]
variables[source]
new_dim[source]
only_vars_with_time = True[source]
__call__(sample)[source]
src.FRAME_FM.transforms.transforms.transform_mapping[source]
src.FRAME_FM.transforms.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.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.transforms.apply_preprocessors[source]