Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Clément Haëck
submeso-color
Commits
39b19c22
Commit
39b19c22
authored
Sep 23, 2021
by
Clément Haëck
Browse files
Add method to get box slices
parent
824107cc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
3 deletions
+14
-3
lib/box.py
lib/box.py
+14
-3
No files found.
lib/box.py
View file @
39b19c22
...
...
@@ -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.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment