Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,4 @@ def __call__(self, dataset: xr.Dataset, variable: str) -> Union[xr.DataArray, xr
if isinstance(data, xr.Dataset):
data = data[variable]

return pyearthtools.data.transforms.attributes.update(self.attribute_update)(data)
return pyearthtools.data.transforms.attributes.SetAttributes(self.attribute_update)(data)
3 changes: 1 addition & 2 deletions packages/data/src/pyearthtools/data/transforms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def apply(self, dataset):
from pyearthtools.data.transforms.default import get_default_transforms

# from pyearthtools.data.transforms.mask import MaskTransform as mask
from pyearthtools.data.transforms.derive import derive, Derive
from pyearthtools.data.transforms.derive import Derive

from pyearthtools.data.transforms import projection

Expand All @@ -92,7 +92,6 @@ def apply(self, dataset):
"region",
"mask",
"get_default_transform",
"derive",
"Derive",
"projection",
"get_default_transforms",
Expand Down
20 changes: 0 additions & 20 deletions packages/data/src/pyearthtools/data/transforms/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import xarray as xr

from pyearthtools.data.transforms import Transform
from pyearthtools.utils.decorators import BackwardsCompatibility


def _get_attributes_from_ds(reference: xr.DataArray | xr.Dataset) -> dict[str, dict[str, Any]]:
Expand Down Expand Up @@ -108,13 +107,6 @@ def apply(self, data_obj):
return data_obj


@BackwardsCompatibility(SetAttributes)
def set_attributes(*args, **kwargs) -> Transform: ...


update = set_attributes


def _get_encoding_from_ds(reference: xr.DataArray | xr.Dataset, limit: list[str] | None = None):
encoding: dict[str, dict[str, Any]] = {}
relevant_encoding = limit or [
Expand Down Expand Up @@ -204,10 +196,6 @@ def update(x: xr.DataArray):
return dataset


@BackwardsCompatibility(SetEncoding)
def set_encoding(*args, **kwargs) -> Transform: ...


class SetType(Transform):
"""Set type of variables"""

Expand Down Expand Up @@ -252,10 +240,6 @@ def apply(self, dataset: xr.DataArray | xr.Dataset) -> xr.DataArray | xr.Dataset
return dataset


@BackwardsCompatibility(SetType)
def set_type(*args, **kwargs) -> Transform: ...


class Rename(Transform):
"""Rename Components inside Dataset"""

Expand Down Expand Up @@ -285,7 +269,3 @@ def __init__(self, names: dict[str, Any] | None = None, **extra_names: Any):

def apply(self, dataset: xr.Dataset) -> xr.Dataset:
return dataset.rename(**{key: self._names[key] for key in self._names if key in dataset})


@BackwardsCompatibility(Rename)
def rename(*args, **kwargs) -> Transform: ...
10 changes: 0 additions & 10 deletions packages/data/src/pyearthtools/data/transforms/coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
from pyearthtools.data.warnings import pyearthtoolsDataWarning
from pyearthtools.data.exceptions import DataNotFoundError

from pyearthtools.utils.decorators import BackwardsCompatibility

DASK_IMPORTED = False
try:
import dask
Expand Down Expand Up @@ -560,10 +558,6 @@ def apply(self, dataset: xr.Dataset) -> xr.Dataset | xr.DataArray:
return dataset


@BackwardsCompatibility(Expand)
def expand(*args, **kwargs) -> Transform: ...


def SelectFlatten(
coordinates: dict[str, tuple[Any] | Any] | None = None,
tolerance: float = 0.01,
Expand Down Expand Up @@ -682,7 +676,3 @@ def apply(self, dataset: xr.Dataset) -> xr.Dataset:
# @property
# def _info_(self) -> Any | dict:
# return dict(coordinates=self._coordinates, **self._kwargs)


@BackwardsCompatibility(Pad)
def pad(*args, **kwargs) -> Transform: ...
2 changes: 1 addition & 1 deletion packages/data/src/pyearthtools/data/transforms/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ def get_default_transforms(
transforms.append(pyearthtools.data.transforms.coordinates.StandardCoordinateNames(**REPLACEMENT_NAMES)) # type: ignore
# transforms.append(pyearthtools.data.transforms.coordinates.StandardLongitude())
# if intelligence_level > 1:
# transforms.append(pyearthtools.data.transforms.coordinates.set_type("float"))
# transforms.append(pyearthtools.data.transforms.coordinates.SetType("float"))

return transforms
5 changes: 0 additions & 5 deletions packages/data/src/pyearthtools/data/transforms/derive.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@


from pyearthtools.data.transforms import Transform
from pyearthtools.utils.decorators import BackwardsCompatibility

LOG = logging.getLogger("pyearthtools.data")

Expand Down Expand Up @@ -509,10 +508,6 @@ def apply(self, dataset: xr.Dataset) -> xr.Dataset:
return derive_equations(dataset, drop=self._drop, equation=self._equation)


@BackwardsCompatibility(Derive)
def derive(*args, **kwargs) -> Transform: ...


# def equations(equation: str):
# class KnownEquations(Transform):
# @property
Expand Down
9 changes: 0 additions & 9 deletions packages/data/src/pyearthtools/data/transforms/dimensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import xarray as xr

from pyearthtools.data.transforms.transform import Transform
from pyearthtools.utils.decorators import BackwardsCompatibility

XR = TypeVar("XR", xr.Dataset, xr.DataArray)

Expand Down Expand Up @@ -60,10 +59,6 @@ def apply(self, dataset: xr.Dataset):
return dataset


@BackwardsCompatibility(StandardDimensionNames)
def force_standard_dimension_names(*args, **kwargs: str) -> Transform: ...


class Expand(Transform):
"""Expand Dimensions"""

Expand Down Expand Up @@ -138,7 +133,3 @@ def apply(self, dataset: XR) -> XR:

data = dataset.expand_dims(_dim, axis=self._axis, **self._kwargs)
return data


@BackwardsCompatibility(Expand)
def expand(*args, **kwargs) -> Transform: ...
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
from pyearthtools.data.transforms.transform import Transform
from pyearthtools.data.transforms.utils import parse_dataset

from pyearthtools.utils.decorators import BackwardsCompatibility

xESMF_IMPORTED = True
try:
import xesmf as xe # type: ignore
Expand Down Expand Up @@ -263,10 +261,6 @@ def encode(x):
) # type: ignore


@BackwardsCompatibility(InterpolateNan)
def interpolate_na(*args, **kwargs): ...


### Model levels to pressure level transform needed


Expand Down
10 changes: 0 additions & 10 deletions packages/data/src/pyearthtools/data/transforms/mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
from pyearthtools.data.transforms.transform import Transform
from pyearthtools.data.transforms.utils import parse_dataset

from pyearthtools.utils.decorators import BackwardsCompatibility

OPERATIONS = ["==", "!=", ">", "<", ">=", "<="]
OPERATIONS_TYPE = Literal["==", "!=", ">", "<", ">=", "<="]

Expand Down Expand Up @@ -305,10 +303,6 @@ def apply(self, dataset: xr.Dataset) -> xr.Dataset:
)


@BackwardsCompatibility(Dataset)
def dataset(*a, **k): ...


class Replace(UnderlyingMaskTransform):
def __init__(
self,
Expand Down Expand Up @@ -351,8 +345,4 @@ def apply(self, data):
)


@BackwardsCompatibility(Replace)
def replace_value(*a, **k): ...


__all__ = ["Dataset", "Replace"]
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import xarray as xr
from pyearthtools.data.transforms.transform import Transform

from pyearthtools.utils.decorators import BackwardsCompatibility


class Rechunk(Transform):
"""Rechunk data"""
Expand All @@ -48,7 +46,3 @@ def apply(self, dataset: xr.Dataset) -> xr.Dataset:
raise ValueError(f"Could not find 'chunksizes' in encoding of {var}")
dataset[var].data = dataset[var].data.rechunk(chunks)
return dataset


@BackwardsCompatibility(Rechunk)
def rechunk(*args, **kwargs): ...
26 changes: 0 additions & 26 deletions packages/data/src/pyearthtools/data/transforms/region.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
from pyearthtools.data.transforms import Transform
from pyearthtools.data.transforms.utils import parse_dataset

from pyearthtools.utils.decorators import BackwardsCompatibility


RegionLookupFILE = Path(__file__).parent / "RegionLookup.yaml"

Expand Down Expand Up @@ -137,10 +135,6 @@ def apply(self, dataset: xr.Dataset):
return subset_dataset


@BackwardsCompatibility(Select)
def sel(*args, **kwargs): ...


class ISelect(Transform):
"""ISelect"""

Expand All @@ -160,10 +154,6 @@ def apply(self, dataset: xr.Dataset):
return subset_dataset


@BackwardsCompatibility(ISelect)
def isel(*args, **kwargs): ...


def PointBox(point: tuple[float], size: float) -> Transform:
"""
Create a region bounding box of `size` around `point`
Expand All @@ -187,10 +177,6 @@ def PointBox(point: tuple[float], size: float) -> Transform:
return Bounding(edges[0][0], edges[1][0], edges[0][1], edges[1][1])


@BackwardsCompatibility(PointBox)
def point_box(*args, **kwargs): ...


def Lookup(key: str, regionfile: str | Path = RegionLookupFILE) -> Transform:
"""
Use string to retrieve preset lat and lon extent to transform geospatial extent
Expand Down Expand Up @@ -222,10 +208,6 @@ def Lookup(key: str, regionfile: str | Path = RegionLookupFILE) -> Transform:
return Bounding(*bounding_box)


@BackwardsCompatibility(Lookup)
def lookup(*args, **kwargs): ...


class ShapeFile(Transform):
def __init__(self, shapefile, crs: str | None = None):
"""
Expand Down Expand Up @@ -283,10 +265,6 @@ def plot(self, **kwargs):
self._shapefile.plot(**kwargs)


@BackwardsCompatibility(ShapeFile)
def from_shapefile(*args, **kwargs): ...


def Geosearch(
key: str,
column: str | None = None,
Expand Down Expand Up @@ -328,7 +306,3 @@ def Geosearch(
shapefile = geo.geometry

return ShapeFile(shapefile, crs=crs)


@BackwardsCompatibility(Geosearch)
def from_geosearch(*args, **kwargs): ...
5 changes: 0 additions & 5 deletions packages/data/src/pyearthtools/data/transforms/values.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import pyearthtools.data
from pyearthtools.data.transforms.transform import Transform
from pyearthtools.utils.decorators import BackwardsCompatibility


class Fill(Transform):
Expand Down Expand Up @@ -137,10 +136,6 @@ def apply(self, dataset: xr.Dataset) -> xr.Dataset:
return dataset


@BackwardsCompatibility(Fill)
def fill(*args, **kwargs): ...


def ffill(*a, **b):
return Fill(*a, direction=b.pop("direction", "forward"), **b)

Expand Down
16 changes: 1 addition & 15 deletions packages/data/src/pyearthtools/data/transforms/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@
import pyearthtools.data.transforms.attributes as attr
from pyearthtools.data.transforms.transform import Transform

from pyearthtools.utils.decorators import BackwardsCompatibility

# Backwards compatability
rename_variables = attr.rename
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please tidy this up in a new PR?

rename_variables = attr.Rename
replace_name_deviation = rename_variables


Expand Down Expand Up @@ -58,14 +56,6 @@ def apply(self, dataset: xr.Dataset) -> xr.Dataset:
return dataset[var_included]


@BackwardsCompatibility(Trim)
def trim(*args) -> Transform: ...


@BackwardsCompatibility(Trim)
def variable_trim(*args) -> Transform: ...


class Drop(Transform):
"""Drop dataset variables"""

Expand Down Expand Up @@ -142,7 +132,3 @@ def apply(self, dataset: xr.Dataset) -> xr.Dataset:
return dataset

return dataset[list(var_included)]


@BackwardsCompatibility(Drop)
def drop(*args) -> Transform: ...
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

from pyearthtools.data.utils import parse_path

from pyearthtools.utils.decorators import BackwardsCompatibility
from pyearthtools.pipeline.operations.dask.dask import DaskOperation


Expand Down Expand Up @@ -137,10 +136,6 @@ def denormalise(self, sample):
return sample * self.expand(self.division_factor, sample)


@BackwardsCompatibility(Division)
def TemporalDifference(*a, **k): ...


class Evaluated(daskNormalisation):
"""
`eval` based normalisation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

from pyearthtools.data.utils import parse_path

from pyearthtools.utils.decorators import BackwardsCompatibility
from pyearthtools.pipeline.operation import Operation


Expand Down Expand Up @@ -130,10 +129,6 @@ def denormalise(self, sample):
return sample * self.expand(self.division_factor, sample)


@BackwardsCompatibility(Division)
def TemporalDifference(*a, **k): ...


class Evaluated(numpyNormalisation):
"""
`eval` based normalisation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ def __init__(self, coordinates: Union[str, list[str]], *extra_coords: str):

def apply(self, data: xr.Dataset):
dims = list(data.dims)
rebuild_encoding = pyearthtools.data.transforms.attributes.set_encoding(
rebuild_encoding = pyearthtools.data.transforms.attributes.SetEncoding(
reference=data
) + pyearthtools.data.transforms.attributes.set_attributes(reference=data)
) + pyearthtools.data.transforms.attributes.SetAttributes(reference=data)

for coord in self.coordinates:
if coord in data:
Expand Down
Loading