Commit 87a7c8ce authored by Lucia Rinchiuso's avatar Lucia Rinchiuso
Browse files

Refinments, fixed a few issues

parent 8c7f8105
......@@ -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(StationList) < 1 :
if len(ExcludedList) < 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):
if elem==i:
del initial_calls[index]
del IDs[index]
for i in EX:
if i in IDs:
index=IDs.index(i)
del initial_calls[index]
del IDs[index]
# Get additional information from the GRDC file.
Rivers=[]
Upstream=[]
......
......@@ -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 stnname.lower().find(name.lower()) >= 0 :
if self.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 stncountry==country and stnriver==river:
if self.findWholeWord(country.strip(),stncountry) and self.findWholeWord(river.strip(),stnriver):
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 stnriver.lower()==river.lower():
if self.findWholeWord(river.strip(),stnriver):
ID.append(i.Number)
return ID
def FindIDfromWMOregion(self, reg) :
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment