Commit 39b19c22 authored by Clément Haëck's avatar Clément Haëck
Browse files

Add method to get box slices

parent 824107cc
......@@ -89,8 +89,8 @@ class Box:
sh = box(*self.corner_ll, *self.corner_ur)
return sh
def extract(self, ds, enlarge=False):
"""Return dataset (or array) inside box.
def get_isel(self, ds, enlarge=False):
"""Return slices indices to select box in Xarray object.
Parameters:
-----------
......@@ -126,7 +126,18 @@ class Box:
enlarge_slice(slice_lon, slice_lat, enlarge)
return ds.isel(lon=slice(*slice_lon), lat=slice(*slice_lat))
return dict(lon=slice(*slice_lon), lat=slice(*slice_lat))
def extract(self, ds, enlarge=False):
"""Return dataset (or array) inside box.
Parameters:
-----------
enlarge:
Expends the area by a number of pixel on each side.
If is True, enlarge by 2 pixels by default.
"""
return ds.isel(**self.get_isel(ds, enlarge))
def add_to_plot(self, ax, **kwargs):
"""Plot area on axis.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment