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
00bc9b0b
Commit
00bc9b0b
authored
Jan 19, 2021
by
Lucia Rinchiuso
Browse files
WMOreg and subreg, exclusion list
parent
65bdba7a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
7 deletions
+46
-7
StationDiag.py
StationDiag.py
+24
-3
Stations/AllStations.py
Stations/AllStations.py
+22
-4
No files found.
StationDiag.py
View file @
00bc9b0b
...
...
@@ -19,6 +19,7 @@ stationsconfig = configparser.ConfigParser()
stationsconfig
.
read
(
"stations.def"
)
GRDCFile
=
stationsconfig
.
get
(
"OverAll"
,
"GRDCFile"
,
fallback
=
None
)
StationList
=
stationsconfig
.
get
(
"OverAll"
,
"StationList"
,
fallback
=
[]).
split
(
','
)
ExcludedList
=
stationsconfig
.
get
(
"OverAll"
,
"ExcludedList"
,
fallback
=
[]).
split
(
','
)
GraphFile
=
stationsconfig
.
get
(
"OverAll"
,
"GraphFile"
,
fallback
=
None
)
DiagFile
=
stationsconfig
.
get
(
"OverAll"
,
"DiagFile"
,
fallback
=
"StationDiag.nc"
)
StructureFile
=
stationsconfig
.
get
(
"OverAll"
,
"StructuresFile"
,
fallback
=
None
)
...
...
@@ -34,7 +35,12 @@ if not isinstance(GraphFile, str) or not isinstance(StructureFile, str) :
if
len
(
StationList
)
<
1
:
print
(
"ERROR : no stations provided"
)
sys
.
exit
()
print
(
'Station list:'
)
print
(
StationList
)
if
len
(
StationList
)
<
1
:
print
(
"No excluded stations"
)
print
(
'Exclusion list:'
)
print
(
ExcludedList
)
#
# Some extra modules so we can start to work
#
...
...
@@ -50,18 +56,32 @@ L = LO.PlacedLocations(GraphFile)
A
=
AS
.
AllStations
()
A
.
fetchnetcdf
(
GRDCFile
,
metaonly
=
True
,
region
=
[
L
.
lonrange
,
L
.
latrange
])
#
# Find the IDs of all the stations listed in stations.def
# Find the IDs of all the stations
and exclusions
listed in stations.def
#
# Excluded stations/regions
EX
=
[]
for
teststn
in
ExcludedList
:
EX
.
extend
(
A
.
FindID
(
teststn
))
print
(
'Excluded '
+
str
(
A
.
FindID
(
teststn
)))
if
EX
[
-
1
]
<
0
:
print
(
"Excluded station selection "
,
teststn
,
" was already not present in the GRDC file over your regions."
)
#Selected stations/regions
IDs
=
[]
initial_calls
=
[]
for
teststn
in
StationList
:
IDs
.
extend
(
A
.
FindID
(
teststn
))
for
i
in
A
.
FindID
(
teststn
):
initial_calls
.
append
(
teststn
)
print
(
A
.
FindID
(
teststn
))
print
(
'Selected '
+
str
(
A
.
FindID
(
teststn
))
)
if
IDs
[
-
1
]
<
0
:
print
(
"Station "
,
teststn
,
" could not be found in the GRDC file over your regions."
)
print
(
"Station
selection
"
,
teststn
,
" could not be found in the GRDC file over your regions."
)
if
len
(
IDs
)
!=
len
(
initial_calls
):
print
(
'WARNING'
)
#Subtraction of ALL recurrences of the excluded stations
for
i
in
set
(
EX
):
for
index
,
elem
in
enumerate
(
IDs
):
if
elem
==
i
:
del
initial_calls
[
index
]
del
IDs
[
index
]
# Get additional information from the GRDC file.
Rivers
=
[]
Upstream
=
[]
...
...
@@ -113,6 +133,7 @@ for i,loc in enumerate(Lind) :
vname
=
"ST"
+
str
(
IDs
[
i
])
print
(
"Creating Variable : "
,
vname
,
initial_calls
[
i
])
ncvar
.
append
(
nc
.
createVariable
(
vname
,
float
,
(
'y'
,
'x'
)))
ncvar
[
-
1
].
InitialCall
=
initial_calls
[
i
]
ncvar
[
-
1
].
Name
=
Names
[
i
]
ncvar
[
-
1
].
River
=
Rivers
[
i
]
ncvar
[
-
1
].
ObsUpstream
=
Upstream
[
i
]
...
...
Stations/AllStations.py
View file @
00bc9b0b
...
...
@@ -60,14 +60,21 @@ class AllStations :
if
stnname
.
lower
().
find
(
name
.
lower
())
>=
0
:
ID
=
stn
.
Number
return
ID
def
FindIDfromCountry
(
self
,
country
)
:
def
FindIDfromCountry
(
self
,
river
,
country
)
:
ID
=
[]
for
i
in
self
.
stations
:
if
isinstance
(
i
.
Country
,
str
):
stncountry
=
i
.
Country
else
:
stncountry
=
i
.
Country
.
tolist
()
if
stncountry
==
country
:
if
river
!=
'all'
:
if
isinstance
(
i
.
River
,
str
):
stnriver
=
i
.
River
else
:
stnriver
=
i
.
River
.
tolist
()
else
:
stnriver
=
'all'
if
stncountry
==
country
and
stnriver
==
river
:
ID
.
append
(
i
.
Number
)
return
ID
def
FindIDfromRiver
(
self
,
river
)
:
...
...
@@ -80,6 +87,17 @@ class AllStations :
if
stnriver
.
lower
()
==
river
.
lower
():
ID
.
append
(
i
.
Number
)
return
ID
def
FindIDfromWMOregion
(
self
,
reg
)
:
reg
=
int
(
reg
)
ID
=
[]
for
i
in
self
.
stations
:
if
reg
<
7
:
stnreg
=
i
.
WMOregion
else
:
stnreg
=
i
.
WMOregion
*
100
+
i
.
WMOsubregion
if
stnreg
==
reg
:
ID
.
append
(
i
.
Number
)
return
ID
def
FindID
(
self
,
teststn
)
:
IDs
=
[]
if
self
.
is_integer
(
teststn
):
...
...
@@ -89,10 +107,10 @@ class AllStations :
selection
=
teststn
.
split
(
'@'
)[
0
]
place
=
teststn
.
split
(
'@'
)[
1
]
if
self
.
is_integer
(
place
):
print
(
'it is a region, still to be implemented'
)
IDs
.
extend
(
self
.
FindIDfromWMOregion
(
place
.
strip
())
)
else
:
if
len
(
place
)
==
2
and
place
.
isupper
():
IDs
.
extend
(
self
.
FindIDfromCountry
(
place
.
strip
()))
IDs
.
extend
(
self
.
FindIDfromCountry
(
selection
.
strip
(),
place
.
strip
()))
else
:
IDs
.
extend
(
self
.
FindIDfromRiver
(
place
.
strip
()))
else
:
...
...
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