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
8b07db06
Commit
8b07db06
authored
Sep 15, 2021
by
Clément Haëck
Browse files
Move grid generation in script
add plot
parent
d7d316f1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
9 deletions
+51
-9
Compute/generate_box_grid.py
Compute/generate_box_grid.py
+50
-9
Download/integrate_daily_sf.sh
Download/integrate_daily_sf.sh
+1
-0
No files found.
Compute/generate_box_grid.py
View file @
8b07db06
"""Generate grid of indexed boxes."""
import
matplotlib.pyplot
as
plt
import
matplotlib.patches
as
mp
from
os
import
path
import
lib
import
lib.box
import
lib.zones
def
add_args
(
parser
):
...
...
@@ -15,6 +19,34 @@ def add_args(parser):
parser
.
add_argument
(
'-size_lat'
,
type
=
float
,
default
=
5
)
def
generate_grid
(
args
,
zone
,
land
):
bounds
=
lib
.
box
.
Box
(
args
[
'lon_min'
],
args
[
'lon_max'
],
args
[
'lat_min'
],
args
[
'lat_max'
])
boxes
=
[]
lon
=
bounds
.
lon_min
idx_lon
=
0
while
lon
<
bounds
.
lon_max
:
lat
=
bounds
.
lat_max
idx_lat
=
0
while
lat
>
bounds
.
lat_min
:
box
=
lib
.
box
.
IndexBox
(
lon
,
lon
+
args
[
'size_lon'
],
lat
,
lat
+
args
[
'size_lat'
],
idx_lon
=
idx_lon
,
idx_lat
=
idx_lat
)
box_shape
=
box
.
get_shape
()
intersect
=
zone
.
shape
.
intersection
(
box_shape
)
if
intersect
.
area
/
box_shape
.
area
>
0.60
:
# if zone.intersects(box.lon_bounds, box.lat_bounds):
land_b
=
box
.
extract
(
land
)
if
land_b
.
sum
()
/
land_b
.
size
<
0.40
:
boxes
.
append
(
box
)
lat
-=
args
[
'size_lat'
]
idx_lat
+=
1
lon
+=
args
[
'size_lon'
]
idx_lon
+=
1
return
boxes
def
main
():
args
=
lib
.
get_args
([
'region'
],
add_args
=
add_args
)
...
...
@@ -22,20 +54,29 @@ def main():
args
[
'size_lon'
],
args
[
'size_lat'
])
grid_file
=
lib
.
box
.
IndexBox
.
GetGridFile
(
args
)
bounds
=
lib
.
box
.
Box
(
args
[
'lon_min'
],
args
[
'lon_max'
],
args
[
'lat_min'
],
args
[
'lat_max'
])
grid
=
lib
.
box
.
IndexBox
.
GenerateGrid
(
bounds
,
args
[
'size_lon'
],
args
[
'size_lat'
])
zone
=
lib
.
zones
.
zones
[
'total'
]
land
=
lib
.
zones
.
get_land
(
args
,
grid
=
'4km_EPSG4326'
)[
'land'
]
grid
=
generate_grid
(
args
,
zone
,
land
)
idx_lon_max
=
max
(
b
.
idx_lon
for
b
in
grid
)
idx_lat_max
=
max
(
b
.
idx_lat
for
b
in
grid
)
print
(
'Grid of {:d} boxes, {:d}x{:d}'
.
format
(
len
(
grid
),
idx_lon_max
,
idx_lat_max
))
print
(
'Grid of {:d} boxes'
.
format
(
len
(
grid
)))
print
(
"Writing to '{}'"
.
format
(
grid_file
))
lib
.
box
.
IndexBox
.
WriteGridText
(
grid
,
grid_file
)
print
(
"Plotting boxes"
)
fig
,
ax
=
plt
.
subplots
(
1
,
1
)
land
.
plot
.
imshow
(
ax
=
ax
,
add_colorbar
=
False
,
cmap
=
'Greys'
)
for
b
in
grid
:
b
.
add_to_plot
(
ax
,
fill
=
None
,
color
=
'r'
)
ax
.
annotate
(
b
.
idx_str
,
b
.
center
,
ha
=
'center'
,
va
=
'center'
,
color
=
'r'
)
ax
.
add_artist
(
mp
.
Polygon
(
zone
.
points
,
fill
=
False
,
ec
=
'b'
))
ax
.
set_xlim
(
args
[
'lon_min'
],
args
[
'lon_max'
])
ax
.
set_ylim
(
args
[
'lat_min'
],
args
[
'lat_max'
])
if
__name__
==
'__main__'
:
main
()
Download/integrate_daily_sf.sh
View file @
8b07db06
...
...
@@ -30,6 +30,7 @@ if [ "$year" == "none" ]; then
exit
1
fi
# Same as /Download/era5_land_mask.py
lon_min
=
275.
lon_max
=
360.
lat_min
=
0.
...
...
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