From 0d953cb84cb58bd460ad3d2c4e774262de69bb40 Mon Sep 17 00:00:00 2001 From: POLCHER Jan <jan.polcher@lmd.jussieu.fr> Date: Wed, 22 Apr 2020 16:39:59 +0200 Subject: [PATCH] Some clean-up of the code and supression of the call to the plot routines in the main. That is replced by Anthony's code. --- HydroGrid.py | 4 +--- Interface.py | 8 ++++---- ModelGrid.py | 8 ++++---- RPPtools.py | 6 +++--- RoutingPreProc.py | 24 +++++------------------- 5 files changed, 17 insertions(+), 33 deletions(-) diff --git a/HydroGrid.py b/HydroGrid.py index 809846d..f2745dd 100644 --- a/HydroGrid.py +++ b/HydroGrid.py @@ -10,7 +10,7 @@ import RPPtools as RPP import configparser config=configparser.ConfigParser() config.read("run.def") -EarthRadius=config.getfloat("OverAll", "EarthRadius") +EarthRadius=config.getfloat("OverAll", "EarthRadius", fallback=6370000.0) # import getargs log_master, log_world = getargs.getLogger(__name__) @@ -58,8 +58,6 @@ def corners(lon, lat) : def gather(x, index) : y=[] for ia in index : - # print("XXXX shape of ia :", ia.shape, ia.dtype) - # print("XXXX ia :", ia) y.append(list(x[ia[0,i],ia[1,i]] for i in range(ia.shape[1]) )) return y # diff --git a/Interface.py b/Interface.py index b96c57e..adf4d74 100644 --- a/Interface.py +++ b/Interface.py @@ -26,11 +26,11 @@ MPI.COMM_WORLD.Barrier() import routing_interface # import configparser -config = configparser.ConfigParser({'Documentation':'false', 'nbxmax':'63', 'ROUTING_RIVERS':'50'}) +config = configparser.ConfigParser() config.read("run.def") -gendoc = config.get("OverAll", "Documentation") -nbxmax = config.getint("OverAll", "nbxmax") -largest_pos = config.getint("OverAll", "ROUTING_RIVERS") +gendoc = config.get("OverAll", "Documentation", fallback='false') +nbxmax = config.getint("OverAll", "nbxmax", fallback=63) +largest_pos = config.getint("OverAll", "ROUTING_RIVERS", fallback=50) # undef_int = 999999999.9 # Order of magnitude for the area precision in m^2. diff --git a/ModelGrid.py b/ModelGrid.py index 7f3fcfa..4490827 100644 --- a/ModelGrid.py +++ b/ModelGrid.py @@ -10,7 +10,7 @@ import RPPtools as RPP import sys # import configparser -config=configparser.ConfigParser({"WEST_EAST":"-180., 180", "SOUTH_NORTH":"-90., 90."}) +config=configparser.ConfigParser() config.read("run.def") # import getargs @@ -19,7 +19,7 @@ INFO, DEBUG, ERROR = log_master.info, log_master.debug, log_world.error INFO_ALL, DEBUG_ALL = log_world.info, log_world.debug # # -EarthRadius=config.getfloat("OverAll", "EarthRadius") +EarthRadius=config.getfloat("OverAll", "EarthRadius", fallback=6370000.0) rose=[[-1,-1],[-1,0],[-1,+1],[0,+1],[+1,+1],[+1,0],[+1,-1],[0,-1]] epsilon=0.00001 # @@ -410,8 +410,8 @@ class ModelGrid : class GlobalGrid : def __init__(self) : - lonrange=np.array(config.get("OverAll", "WEST_EAST").split(","),dtype=float) - latrange=np.array(config.get("OverAll", "SOUTH_NORTH").split(","),dtype=float) + lonrange=np.array(config.get("OverAll", "WEST_EAST", fallback="-180., 180.").split(","),dtype=float) + latrange=np.array(config.get("OverAll", "SOUTH_NORTH", fallback="-90., 90.").split(","),dtype=float) self.source=config.get("OverAll", "ModelGridFile") INFO("Opening : "+self.source) diff --git a/RPPtools.py b/RPPtools.py index b03515f..04c7e3c 100644 --- a/RPPtools.py +++ b/RPPtools.py @@ -15,10 +15,10 @@ from spherical_geometry import vector # Configuration # import configparser -config=configparser.ConfigParser({'SaveWeights':'true'}) +config=configparser.ConfigParser() config.read("run.def") -saveweights=config.get("OverAll", "SaveWeights") -EarthRadius=config.getfloat("OverAll", "EarthRadius") +saveweights=config.get("OverAll", "SaveWeights", fallback="true") +EarthRadius=config.getfloat("OverAll", "EarthRadius", fallback=6370000.0) # # Logging in MPI : https://groups.google.com/forum/#!topic/mpi4py/SaNzc8bdj6U # diff --git a/RoutingPreProc.py b/RoutingPreProc.py index 23078e1..c97d295 100644 --- a/RoutingPreProc.py +++ b/RoutingPreProc.py @@ -15,14 +15,12 @@ import time # Gert the information from the configuration file. # import configparser -config=configparser.ConfigParser({"DiagLon":"0.0, 0.0", "DiagLat":"0.0, 0.0"}) +config=configparser.ConfigParser() config.read("run.def") nbasmax=config.getint("OverAll", "nbasmax") numop=config.getint("OverAll", "numop", fallback=100) OutGraphFile=config.get("OverAll","GraphFile") DumpHydroSuper=config.getboolean("OverAll","DumpHydroSuper",fallback=False) -lonint=np.array(config.get("OverAll", "DiagLon").split(","),dtype=float) -latint=np.array(config.get("OverAll", "DiagLat").split(","),dtype=float) wfile=config.get("OverAll","WeightFile",fallback="Weights.nc") # import ModelGrid as MG @@ -89,23 +87,11 @@ comm.Barrier() del w gc.collect() -if rank ==0 : - if lonint[0] != lonint[1] and latint[0] != latint[1] : - DP.MAPPLOT("MapHydroGrid", lonint, latint, hoverlap, hoverlap.hierarchy_bx, modelgrid.polyll, title="Distance to ocean") - hsuper = IF.HydroSuper(nbvmax, hydrodata, hoverlap, nbasmax) # -# Plot the hydrological supermesh -# -if rank == 0 : - if lonint[0] != lonint[1] and latint[0] != latint[1] : - DP.SUPERMESHPLOT("MapSuperGrid_Beforelinkup", lonint, latint, hoverlap, hsuper, modelgrid.polyll) - -print("=================== LINKUP ====================") +INFO("=================== LINKUP ====================") hsuper.linkup(hydrodata) -if rank ==0 : - if lonint[0] != lonint[1] and latint[0] != latint[1] : - DP.SUPERMESHPLOT("MapSuperGrid_Afterlinkup", lonint, latint, hoverlap, hsuper, modelgrid.polyll) + # # Do some memory management and synchronize procs. # @@ -114,7 +100,7 @@ comm.Barrier() del hoverlap gc.collect() -print("=================== Compute fetch ====================") +INFO("=================== Compute fetch ====================") t = time.time() hsuper.fetch(part) comm.Barrier() @@ -123,7 +109,7 @@ print("Time for fetch: {:0.2f} s.".format(t1-t)) comm.Barrier() if DumpHydroSuper : - print("Dumping HydroSuper") + INFO("Dumping HydroSuper") hsuper.dumpnetcdf(OutGraphFile.replace(".nc","_HydroSuper.nc"), gg, modelgrid, part) print("Rank : {0} - Basin_count Before Truncate : ".format(part.rank), hsuper.basin_count) -- GitLab