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
IPSL
LMD
InTro
RoutingPP
Commits
4921d2ad
Commit
4921d2ad
authored
Jan 09, 2021
by
POLCHER Jan
🚴🏾
Browse files
Merge branch 'master' of gitlab.in2p3.fr:ipsl/lmd/intro/routingpp
parents
e46a9a20
b1956a0e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
0 deletions
+54
-0
Stations/AllStations.py
Stations/AllStations.py
+4
-0
Stations/WMOref.py
Stations/WMOref.py
+50
-0
No files found.
Stations/AllStations.py
View file @
4921d2ad
...
...
@@ -406,6 +406,10 @@ def PairAtoB (A, B, AclosetoB, BclosetoA, mindist, maxerr, interactive=False) :
def
concatenate
(
A
,
B
,
pairs
,
Sources
=
""
)
:
C
=
AllStations
(
Source
=
Sources
)
#
# Case no stations to merge -> pairs = []
if
np
.
array
(
pairs
).
shape
[
0
]
==
0
:
pairs
=
np
.
full
((
1
,
2
),
-
1
)
#
for
Ai
,
Astn
in
enumerate
(
A
.
stations
)
:
if
not
any
(
np
.
array
(
pairs
)[:,
0
]
==
Ai
)
:
C
.
add
(
Astn
)
...
...
Stations/WMOref.py
0 → 100644
View file @
4921d2ad
import
cartopy.io.shapereader
as
shpreader
from
shapely.geometry
import
Polygon
,
Point
,
MultiPolygon
import
numpy
as
np
class
WMOREG
:
"""
Quick use :
WMO = WMOREG(dfile)
WMOreg, WMOsubreg = WMO.stations(lon,lat)
"""
def
__init__
(
self
,
dfile
):
"""
dfile : direction of the file : wmobb_basins.shp
Download at ftp://ftp.bafg.de/pub/REFERATE/GRDC/wmo_basins_shp.zip
"""
self
.
polygonWMO
=
[]
self
.
attributesPolygonWMO
=
[]
self
.
dfile
=
dfile
geo_reg
=
shpreader
.
Reader
(
dfile
)
for
r
,
geom
in
zip
(
geo_reg
.
records
(),
geo_reg
.
geometries
()):
try
:
poly
=
Polygon
(
geom
)
except
:
poly
=
MultiPolygon
(
geom
)
# Polygon
self
.
polygonWMO
.
append
(
poly
)
self
.
attributesPolygonWMO
.
append
([
r
.
attributes
[
"REGNUM"
],
r
.
attributes
[
"WMO306_MoC"
]])
def
stations
(
self
,
lon
,
lat
,
output
=
"num"
):
"""
Get the WMOreg and WMOsubreg indexes
lon, lat: longitude and latitude of the point.
output: format of the output -> "num" (default) or "list"
eg. WMOreg = 3 and WMOsubreg = 19
-> num: 319; list: [3,19]
"""
# Point is (x,y)-(lon,lat)
p1
=
Point
(
lon
,
lat
)
out
=
np
.
array
([
p1
.
within
(
poly
)
for
poly
in
self
.
polygonWMO
])
try
:
index
=
np
.
where
(
out
)[
0
][
0
]
stReg
,
stSubreg
=
self
.
attributesPolygonWMO
[
index
]
if
output
==
"num"
:
return
stReg
*
100
+
stSubreg
elif
output
==
"list"
:
return
[
stReg
,
stSubreg
]
except
:
print
(
"lon: {0}; lat: {1}"
.
format
(
lon
,
lat
))
print
(
"No valid WMO region has been found, verify the lon lat"
)
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