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
87a7c8ce
Commit
87a7c8ce
authored
Jan 19, 2021
by
Lucia Rinchiuso
Browse files
Refinments, fixed a few issues
parent
8c7f8105
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
19 deletions
+37
-19
StationDiag.py
StationDiag.py
+28
-16
Stations/AllStations.py
Stations/AllStations.py
+9
-3
No files found.
StationDiag.py
View file @
87a7c8ce
...
...
@@ -19,7 +19,10 @@ 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
(
','
)
if
stationsconfig
.
has_option
(
"OverAll"
,
"ExcludedList"
):
ExcludedList
=
stationsconfig
.
get
(
"OverAll"
,
"ExcludedList"
,
fallback
=
[]).
split
(
','
)
else
:
ExcludedList
=
[]
GraphFile
=
stationsconfig
.
get
(
"OverAll"
,
"GraphFile"
,
fallback
=
None
)
DiagFile
=
stationsconfig
.
get
(
"OverAll"
,
"DiagFile"
,
fallback
=
"StationDiag.nc"
)
StructureFile
=
stationsconfig
.
get
(
"OverAll"
,
"StructuresFile"
,
fallback
=
None
)
...
...
@@ -37,10 +40,11 @@ if len(StationList) < 1 :
sys
.
exit
()
print
(
'Station list:'
)
print
(
StationList
)
if
len
(
Station
List
)
<
1
:
if
len
(
Excluded
List
)
<
1
:
print
(
"No excluded stations"
)
print
(
'Exclusion list:'
)
print
(
ExcludedList
)
else
:
print
(
'Exclusion list:'
)
print
(
ExcludedList
)
#
# Some extra modules so we can start to work
#
...
...
@@ -61,27 +65,35 @@ A.fetchnetcdf(GRDCFile, metaonly=True, region=[L.lonrange,L.latrange])
# Excluded stations/regions
EX
=
[]
for
teststn
in
ExcludedList
:
EX
.
extend
(
A
.
FindID
(
teststn
))
print
(
'Excluded '
+
str
(
A
.
FindID
(
teststn
)))
if
EX
[
-
1
]
<
0
:
sublist
=
A
.
FindID
(
teststn
)
print
(
"With "
,
teststn
,
" exclude stations: "
,
str
(
sublist
))
EX
.
extend
(
sublist
)
if
not
sublist
:
print
(
"Excluded station selection "
,
teststn
,
" was already not present in the GRDC file over your regions."
)
EX
=
list
(
set
(
EX
))
#avoid duplicates
#Selected stations/regions
IDs
=
[]
initial_calls
=
[]
for
teststn
in
StationList
:
IDs
.
extend
(
A
.
FindID
(
teststn
))
for
i
in
A
.
FindID
(
teststn
):
sublist
=
A
.
FindID
(
teststn
)
print
(
"With "
,
teststn
,
" select stations: "
,
str
(
sublist
))
for
i
in
sublist
:
#avoid duplicates and save the initial call(s)
if
i
in
IDs
:
sublist
.
remove
(
i
)
index
=
IDs
.
index
(
i
)
initial_calls
[
index
]
=
initial_calls
[
index
]
+
', '
+
teststn
continue
initial_calls
.
append
(
teststn
)
print
(
'Selected '
+
str
(
A
.
FindID
(
teststn
))
)
if
IDs
[
-
1
]
<
0
:
IDs
.
extend
(
sublist
)
if
not
sublist
:
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
)
:
i
f
elem
==
i
:
del
initial_calls
[
index
]
del
IDs
[
index
]
for
i
in
EX
:
if
i
in
IDs
:
i
ndex
=
IDs
.
index
(
i
)
del
initial_calls
[
index
]
del
IDs
[
index
]
# Get additional information from the GRDC file.
Rivers
=
[]
Upstream
=
[]
...
...
Stations/AllStations.py
View file @
87a7c8ce
...
...
@@ -2,6 +2,7 @@
import
numpy
as
np
import
datetime
import
sys
import
re
from
netCDF4
import
Dataset
from
netCDF4
import
stringtochar
,
chartostring
,
stringtoarr
#
...
...
@@ -49,6 +50,11 @@ class AllStations :
return
False
else
:
return
float
(
n
).
is_integer
()
def
findWholeWord
(
self
,
w
,
s
):
if
re
.
compile
(
r
'\b({0})\b'
.
format
(
w
),
flags
=
re
.
IGNORECASE
).
search
(
s
):
return
True
else
:
return
False
def
FindIDfromName
(
self
,
name
)
:
ID
=
-
1
for
i
,
stn
in
enumerate
(
self
.
stations
)
:
...
...
@@ -57,7 +63,7 @@ class AllStations :
else
:
stnname
=
stn
.
Name
.
tolist
()
#
if
s
tnname
.
lower
().
find
(
name
.
lower
())
>=
0
:
if
s
elf
.
findWholeWord
(
name
.
strip
(),
stnname
)
:
ID
=
stn
.
Number
return
ID
def
FindIDfromCountry
(
self
,
river
,
country
)
:
...
...
@@ -74,7 +80,7 @@ class AllStations :
stnriver
=
i
.
River
.
tolist
()
else
:
stnriver
=
'all'
if
s
tncountry
==
country
and
s
tnriver
==
river
:
if
s
elf
.
findWholeWord
(
country
.
strip
(),
stn
country
)
and
s
elf
.
findWholeWord
(
river
.
strip
(),
stn
river
)
:
ID
.
append
(
i
.
Number
)
return
ID
def
FindIDfromRiver
(
self
,
river
)
:
...
...
@@ -84,7 +90,7 @@ class AllStations :
stnriver
=
i
.
River
else
:
stnriver
=
i
.
River
.
tolist
()
if
s
tnriver
.
lower
()
==
river
.
lower
(
):
if
s
elf
.
findWholeWord
(
river
.
strip
(),
stnriver
):
ID
.
append
(
i
.
Number
)
return
ID
def
FindIDfromWMOregion
(
self
,
reg
)
:
...
...
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