Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
Add cropping
Browse files Browse the repository at this point in the history
  • Loading branch information
b8raoult committed Mar 15, 2024
1 parent 4930df1 commit 3961f4d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions ecml_tools/data/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ def _subset(self, **kwargs):
method = kwargs.pop("method", "every-nth")
return Thinning(self, thinning, method)._subset(**kwargs)

if "bounding_box" in kwargs:
if "area" in kwargs:
from .masked import Cropping

bbox = kwargs.pop("bounding_box")
bbox = kwargs.pop("area")
return Cropping(self, bbox)._subset(**kwargs)

raise NotImplementedError("Unsupported arguments: " + ", ".join(kwargs))
Expand Down
20 changes: 10 additions & 10 deletions ecml_tools/data/masked.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,19 @@ def tree(self):


class Cropping(Masked):
def __init__(self, forward, bounding_box):
self.bounding_box = bounding_box
def __init__(self, forward, area):
self.area = area

if isinstance(bounding_box, Dataset):
north = np.amax(bounding_box.latitudes)
south = np.amin(bounding_box.latitudes)
east = np.amax(bounding_box.longitudes)
west = np.amin(bounding_box.longitudes)
bounding_box = (north, west, south, east)
if isinstance(area, Dataset):
north = np.amax(area.latitudes)
south = np.amin(area.latitudes)
east = np.amax(area.longitudes)
west = np.amin(area.longitudes)
area = (north, west, south, east)

mask = cropping_mask(forward.latitudes, forward.longitudes, *bounding_box)
mask = cropping_mask(forward.latitudes, forward.longitudes, *area)

super().__init__(forward, mask)

def tree(self):
return Node(self, [self.forward.tree()], bounding_box=self.bounding_box)
return Node(self, [self.forward.tree()], area=self.area)

0 comments on commit 3961f4d

Please sign in to comment.