Index: wflow-py/wflow/pcrglobwb/landCover.py =================================================================== diff -u -r58f139b2afc2424fc9f8796934878bd6e49c31de -r831722412888fabe904a22d2548ac77be2c1a5f4 --- wflow-py/wflow/pcrglobwb/landCover.py (.../landCover.py) (revision 58f139b2afc2424fc9f8796934878bd6e49c31de) +++ wflow-py/wflow/pcrglobwb/landCover.py (.../landCover.py) (revision 831722412888fabe904a22d2548ac77be2c1a5f4) @@ -32,8 +32,8 @@ logger = logging.getLogger("wflow_pcrglobwb") -from . import virtualOS as vos -from .ncConverter import * +import virtualOS as vos +from ncConverter import * from wflow.wf_DynamicFramework import configsection from wflow.wf_DynamicFramework import configget @@ -104,8 +104,8 @@ # - "Original" is principally the same as defined in van Beek et al., 2014 (default) # - "Modified" is with a modification by Edwin Sutanudjaja: extending interception definition, using totalPotET for the available energy self.interceptionModuleType = "Original" - if "interceptionModuleType" in list(self.iniItemsLC.keys()): - if self.iniItemsLC['interceptionModuleType'] == "Modified": + if "interceptionModuleType" in self.iniItemsLC.keys(): + if self.iniItemsLC["interceptionModuleType"] == "Modified": msg = 'Using the "Modified" version of the interception module (i.e. extending interception definition, using totalPotET for the available energy for the interception process).' logger.info(msg) self.interceptionModuleType = "Modified" @@ -122,7 +122,10 @@ # minimum interception capacity (only used if interceptionModuleType == "Modified", extended interception definition) self.minInterceptCap = 0.0 - if self.interceptionModuleType == "Original" and "minInterceptCap" in list(self.iniItemsLC.keys()): + if ( + self.interceptionModuleType == "Original" + and "minInterceptCap" in self.iniItemsLC.keys() + ): msg = 'As the "Original" interceptionModuleType is used, the "minInterceptCap" value is ignored. The interception scope is only "canopy".' logger.warning(msg) if self.interceptionModuleType == "Modified": @@ -157,18 +160,30 @@ # In the original oldcalc script of Rens (2 layer model), the percolation percUpp (P1) can be negative # - To avoid this, Edwin changed few lines (see the method updateSoilStates) self.allowNegativePercolation = False - if 'allowNegativePercolation' in list(self.iniItemsLC.keys()) and self.iniItemsLC['allowNegativePercolation'] == "True": - msg = 'Allowing negative values of percolation percUpp (P1), as done in the oldcalc script of PCR-GLOBWB 1.0. ' #\n' - msg += 'Note that this option is only relevant for the two layer soil model.' + if ( + "allowNegativePercolation" in self.iniItemsLC.keys() + and self.iniItemsLC["allowNegativePercolation"] == "True" + ): + msg = "Allowing negative values of percolation percUpp (P1), as done in the oldcalc script of PCR-GLOBWB 1.0. " # \n' + msg += ( + "Note that this option is only relevant for the two layer soil model." + ) logger.warning(msg) self.allowNegativePercolation = True # In the original oldcalc script of Rens, there is a possibility that rootFraction/transpiration is only defined in the bottom layer, while no root in upper layer(s) # - To avoid this, Edwin changed few lines (see the methods 'scaleRootFractionsFromTwoLayerSoilParameters' and 'estimateTranspirationAndBareSoilEvap') self.usingOriginalOldCalcRootTranspirationPartitioningMethod = False - if 'usingOriginalOldCalcRootTranspirationPartitioningMethod' in list(self.iniItemsLC.keys()) and self.iniItemsLC['usingOriginalOldCalcRootTranspirationPartitioningMethod'] == "True": - msg = 'Using the original rootFraction/transpiration as defined in the oldcalc script of PCR-GLOBWB 1.0. '#\n' - msg += 'There is a possibility that rootFraction/transpiration is only defined in the bottom layer, while no root in upper layer(s).' + if ( + "usingOriginalOldCalcRootTranspirationPartitioningMethod" + in self.iniItemsLC.keys() + and self.iniItemsLC[ + "usingOriginalOldCalcRootTranspirationPartitioningMethod" + ] + == "True" + ): + msg = "Using the original rootFraction/transpiration as defined in the oldcalc script of PCR-GLOBWB 1.0. " # \n' + msg += "There is a possibility that rootFraction/transpiration is only defined in the bottom layer, while no root in upper layer(s)." logger.warning(msg) self.usingOriginalOldCalcRootTranspirationPartitioningMethod = True @@ -312,11 +327,16 @@ # ~ self.iniItemsLC['coverFractionNC'], self.inputDir) # get the file names of interceptCap and coverFraction files: - if 'interceptCapNC' in list(self.iniItemsLC.keys()) and 'coverFractionNC' in list(self.iniItemsLC.keys()): - self.interceptCapNC = vos.getFullPath(\ - self.iniItemsLC['interceptCapNC'], self.inputDir) - self.coverFractionNC = vos.getFullPath(\ - self.iniItemsLC['coverFractionNC'], self.inputDir) + if ( + "interceptCapNC" in self.iniItemsLC.keys() + and "coverFractionNC" in self.iniItemsLC.keys() + ): + self.interceptCapNC = vos.getFullPath( + self.iniItemsLC["interceptCapNC"], self.inputDir + ) + self.coverFractionNC = vos.getFullPath( + self.iniItemsLC["coverFractionNC"], self.inputDir + ) else: msg = ( "The netcdf files for interceptCapNC (interception capacity) and/or coverFraction (canopy cover fraction) are NOT defined for the landCover type: " @@ -473,8 +493,12 @@ # 2. included in the netcdf file (i.e. self.iniItemsLC['landCoverMapsNC']) # 3. approximated from the minSoilDepthFrac and maxSoilDepthFrac - lc_parameters['arnoBeta'] = None - if 'arnoBeta' not in list(self.iniItemsLC.keys()) and get_only_fracVegCover == False: self.iniItemsLC['arnoBeta'] = "None" + lc_parameters["arnoBeta"] = None + if ( + "arnoBeta" not in self.iniItemsLC.keys() + and get_only_fracVegCover == False + ): + self.iniItemsLC["arnoBeta"] = "None" # - option one (top priority): using a pcraster file if self.iniItemsLC["arnoBeta"] != "None" and get_only_fracVegCover == False: @@ -490,8 +514,12 @@ ) # - option two: included in the netcdf file - if isinstance(lc_parameters['arnoBeta'], type(None)) and landCoverPropertiesNC != None and get_only_fracVegCover == False: - + if ( + isinstance(lc_parameters["arnoBeta"], types.NoneType) + and landCoverPropertiesNC != None + and get_only_fracVegCover == False + ): + if vos.checkVariableInNC(landCoverPropertiesNC, "arnoBeta"): logger.debug( @@ -503,10 +531,15 @@ ) # - option three: approximated from the minSoilDepthFrac and maxSoilDepthFrac - if isinstance(lc_parameters['arnoBeta'], type(None)) and get_only_fracVegCover == False: - - logger.debug("The parameter arnoBeta is approximated from the minSoilDepthFrac and maxSoilDepthFrac values.") - + if ( + isinstance(lc_parameters["arnoBeta"], types.NoneType) + and get_only_fracVegCover == False + ): + + logger.debug( + "The parameter arnoBeta is approximated from the minSoilDepthFrac and maxSoilDepthFrac values." + ) + # make sure that maxSoilDepthFrac >= minSoilDepthFrac: # - Note that maxSoilDepthFrac is needed only for calculating arnoBeta, # while minSoilDepthFrac is needed not only for arnoBeta, but also for rootZoneWaterStorageMin @@ -575,8 +608,9 @@ ) # if not defined, arnoBeta would be approximated from the minSoilDepthFrac and maxSoilDepthFrac - if get_only_fracVegCover == False and\ - isinstance(lc_parameters['arnoBeta'], type(None)): + if get_only_fracVegCover == False and isinstance( + lc_parameters["arnoBeta"], types.NoneType + ): logger.debug( "The parameter arnoBeta is approximated from the minSoilDepthFrac and maxSoilDepthFrac values." @@ -681,12 +715,26 @@ min_percolation_loss = 0.006 max_percolation_loss = 0.008 # - Minimum and maximum percolation loss values given in the ini or configuration file: - if 'minPercolationLoss' in list(iniPaddyOptions.keys()) and iniPaddyOptions['minPercolationLoss'] != "None": - min_percolation_loss = vos.readPCRmapClone(iniPaddyOptions['minPercolationLoss'], self.cloneMap, - self.tmpDir, self.inputDir) - if 'maxPercolationLoss' in list(iniPaddyOptions.keys()) and iniPaddyOptions['maxPercolationLoss'] != "None": - min_percolation_loss = vos.readPCRmapClone(iniPaddyOptions['maxPercolationLoss'], self.cloneMap, - self.tmpDir, self.inputDir) + if ( + "minPercolationLoss" in iniPaddyOptions.keys() + and iniPaddyOptions["minPercolationLoss"] != "None" + ): + min_percolation_loss = vos.readPCRmapClone( + iniPaddyOptions["minPercolationLoss"], + self.cloneMap, + self.tmpDir, + self.inputDir, + ) + if ( + "maxPercolationLoss" in iniPaddyOptions.keys() + and iniPaddyOptions["maxPercolationLoss"] != "None" + ): + min_percolation_loss = vos.readPCRmapClone( + iniPaddyOptions["maxPercolationLoss"], + self.cloneMap, + self.tmpDir, + self.inputDir, + ) # - percolation loss at paddy fields (m/day) design_percolation_loss = pcr.max( min_percolation_loss, pcr.min(max_percolation_loss, design_percolation_loss)