Commit d66fd950 authored by POLCHER Jan's avatar POLCHER Jan 🚴🏾
Browse files

Improvements on the reading of the structure data.

The format of the file was also changed so that the name of the station could be provided.
parent fc9179af
......@@ -15,6 +15,10 @@ MaxDistErr = config.getfloat("OverAll", "MaxDistErr", fallback=25.0)
# Maximum error in the upstream area in %
MaxUpstrErr = config.getfloat("OverAll", "MaxUpstrErr", fallback=10.0)
#
log_master, log_world = getargs.getLogger()
INFO, DEBUG, ERROR = log_master.info, log_master.debug, log_world.error
INFO_ALL, DEBUG_ALL = log_world.info, log_world.debug
#
import routing_interface
import NcHelp as NH
import RPPtools as RPP
......@@ -111,7 +115,9 @@ class HydroGraph :
if np.count_nonzero(~np.isnan(cost)) > 0 :
ij, ib = np.unravel_index(np.nanargmax(cost),cost.shape)
locations.addhtupos(i, ij, ib, np.nanmax(cost))
#
else :
INFO("Could not locate station "+str(lid)+" of nature "+locations.ltype[i] )
#
#
#
def add_variable(self, outnf, procgrid, NCFillValue, part, coord, name, title, units, data, vtyp, orig_type = "float", arrayorder = 'F'):
......
......@@ -3,6 +3,8 @@
import numpy as np
from netCDF4 import Dataset
import sys
import codecs
#
import getargs
config = getargs.SetupConfig()
#
......@@ -17,6 +19,7 @@ class Locations :
self.lat = []
self.upstream = []
self.ltype = []
self.lname = []
self.gnbloc = 0
structure_file = config.get("OverAll","StructuresFile",fallback=None)
if structure_file != None :
......@@ -33,9 +36,18 @@ class Locations :
# Get the locations of infrastructures from an ASCII file
#
def addstructures(self, f, bbox) :
fptr = codecs.open(f, 'r', 'utf-8')
nb = 0
for line in open(f, 'r') :
if line.find("#") != 0 :
while True:
# Try to read next line
try:
line = fptr.readline()
except:
ERROR("Line number "+str(nb+1)+" in file "+f+" cannot be read")
sys.exit()
if len(line) == 0:
break
if line.find("#") != 0 and len(line) > line.count('\n')+line.count(' ') :
nb += 1
col = line.split()
lon = float(col[1]); lat = float(col[2])
......@@ -44,7 +56,12 @@ class Locations :
self.lon.append(lon)
self.lat.append(lat)
self.upstream.append(float(col[3]))
self.ltype.append(" ".join(col[4:]).lower())
self.ltype.append(col[4].lower())
tmpname=" ".join(col[5:])
if len(tmpname) < 1 :
lname.append("NoName")
else :
lname.append(tmpname)
return nb
#
# Get all the locations from the GRDC database
......
......@@ -12,7 +12,7 @@ from matplotlib.backends.backend_pdf import PdfPages
import matplotlib.pyplot as plt
import time
#
# Gert the information from the configuration file.
# Get the information from the configuration file.
#
ConfigFile="run.def"
import getargs
......
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