Esempio n. 1
0
    def __init__(self, iniItems, landmask, Dir, cloneMap, tmpDir):
        object.__init__(self)

        # cloneMap, tmpDir, inputDir based on the configuration/setting given in the ini/configuration file
        self.cloneMap =  cloneMap #iniItems.cloneMap
        self.tmpDir   = tmpDir #iniItems.tmpDir
        self.inputDir = Dir #iniItems.globalOptions['inputDir']
        self.landmask = landmask
        
        # How many soil layers (excluding groundwater):
        self.numberOfLayers = int(configget(iniItems,"landSurfaceOptions","numberOfUpperSoilLayers","2"))
Esempio n. 2
0
    def __init__(self, iniItems, landmask, Dir, cloneMap, tmpDir):
        object.__init__(self)

        # cloneMap, tmpDir, inputDir based on the configuration/setting given in the ini/configuration file
        self.cloneMap = cloneMap  # iniItems.cloneMap
        self.tmpDir = tmpDir  # iniItems.tmpDir
        self.inputDir = Dir  # iniItems.globalOptions['inputDir']
        self.landmask = landmask

        # How many soil layers (excluding groundwater):
        self.numberOfLayers = int(
            configget(iniItems, "landSurfaceOptions", "numberOfUpperSoilLayers", "2")
        )
Esempio n. 3
0
    def readTopo(self, iniItems, optionDict):

        # a dictionary/section of options that will be used
        if optionDict == None: optionDict = iniItems._sections["landSurfaceOptions"]

        # maps of elevation attributes: 
        topoParams = ['tanslope','slopeLength','orographyBeta']
        if optionDict['topographyNC'] == str(None):
            for var in topoParams:
                input = configget(iniItems,"landSurfaceOptions",str(var),"None")
                vars(self)[var] = vos.readPCRmapClone(input,self.cloneMap,
                                                self.tmpDir,self.inputDir)
                if var != "slopeLength": vars(self)[var] = pcr.cover(vars(self)[var], 0.0)
        else:
            topoPropertiesNC = vos.getFullPath(\
                               optionDict['topographyNC'],
                                                self.inputDir)

            for var in topoParams:
                vars(self)[var] = vos.netcdf2PCRobjCloneWithoutTime(\
                                    topoPropertiesNC,var, \
                                    cloneMapFileName = self.cloneMap)
                if var != "slopeLength": vars(self)[var] = pcr.cover(vars(self)[var], 0.0)

        #~ self.tanslope = pcr.max(self.tanslope, 0.00001)              # In principle, tanslope can be zero. Zero tanslope will provide zero TCL (no interflow)

        # covering slopeLength with its maximum value 
        self.slopeLength = pcr.cover(self.slopeLength, pcr.mapmaximum(self.slopeLength))
        
        # maps of relative elevation above flood plains 
        dzRel = ['dzRel0001','dzRel0005',
                 'dzRel0010','dzRel0020','dzRel0030','dzRel0040','dzRel0050',
                 'dzRel0060','dzRel0070','dzRel0080','dzRel0090','dzRel0100']
        if optionDict['topographyNC'] == str(None):
            for i in range(0, len(dzRel)):
                var = dzRel[i]
                input = optionDict[str(var)]
                vars(self)[var] = vos.readPCRmapClone(input,self.cloneMap,
                                                self.tmpDir,self.inputDir)
                vars(self)[var] = pcr.cover(vars(self)[var], 0.0)
                if i > 0: vars(self)[var] = pcr.max(vars(self)[var], vars(self)[dzRel[i-1]])
        else:
            for i in range(0, len(dzRel)):
                var = dzRel[i]
                vars(self)[var] = vos.netcdf2PCRobjCloneWithoutTime(\
                                    topoPropertiesNC,var, \
                                    cloneMapFileName = self.cloneMap)
                vars(self)[var] = pcr.cover(vars(self)[var], 0.0)
                if i > 0: vars(self)[var] = pcr.max(vars(self)[var], vars(self)[dzRel[i-1]])
Esempio n. 4
0
    def readSoil(self, iniItems, optionDict = None):

        # a dictionary/section of options that will be used
        if optionDict == None: optionDict = iniItems._sections["landSurfaceOptions"] #iniItems.landSurfaceOptions

        # default values of soil parameters that are constant/uniform for the entire domain:
        self.clappAddCoeff   = pcr.scalar(3.0)        # dimensionless
        self.matricSuctionFC = pcr.scalar(1.0)        # unit: m
        #~ self.matricSuction50 = pcr.scalar(10./3.)  # unit: m
        self.matricSuction50 = pcr.scalar(3.33)       # unit: m
        self.matricSuctionWP = pcr.scalar(156.0)      # unit: m
        self.maxGWCapRise    = pcr.scalar(5.0)        # unit: m
        #  
        # values defined in the ini/configuration file:
        soilParameterConstants = ['clappAddCoeff',        
                                  'matricSuctionFC',      
                                  'matricSuction50',      
                                  'matricSuctionWP',      
                                  'maxGWCapRise']
        for var in soilParameterConstants:
            if var in configsection(iniItems,"landSurfaceOptions"):
                input = configget(iniItems,"landSurfaceOptions",str(var),"None")
                vars(self)[var] = vos.readPCRmapClone(input,self.cloneMap,\
                                                            self.tmpDir,self.inputDir)
        
        # read soil parameter based on the FAO soil map:
        self.readSoilMapOfFAO(iniItems, optionDict)                                 
       
        # assign Campbell's (1974) beta coefficient, as well as degree 
        # of saturation at field capacity and corresponding unsaturated hydraulic conductivity
        #
        if self.numberOfLayers == 2:

            self.campbellBetaUpp = self.poreSizeBetaUpp*2.0 + \
                                      self.clappAddCoeff                       # Campbell's (1974) coefficient ; Rens's line: BCB = 2*BCH + BCH_ADD
            self.campbellBetaLow = self.poreSizeBetaLow*2.0 + \
                                      self.clappAddCoeff                

            self.effSatAtFieldCapUpp = \
                     (self.matricSuctionFC / self.airEntryValueUpp)**\
                                        (-1.0/ self.poreSizeBetaUpp )          # saturation degree at field capacity       : THEFF_FC = (PSI_FC/PSI_A)**(-1/BCH)
            self.effSatAtFieldCapUpp = pcr.cover(self.effSatAtFieldCapUpp, 1.0)
            
            self.effSatAtFieldCapLow = \
                     (self.matricSuctionFC / self.airEntryValueLow)**\
                                        (-1.0/ self.poreSizeBetaLow )
            self.effSatAtFieldCapLow = pcr.cover(self.effSatAtFieldCapLow, 1.0)

            self.kUnsatAtFieldCapUpp = pcr.max(0., \
             (self.effSatAtFieldCapUpp ** self.campbellBetaUpp) * self.kSatUpp)  # unsaturated conductivity at field capacity: KTHEFF_FC = max(0,THEFF_FC[TYPE]**BCB*KS1)
            self.kUnsatAtFieldCapLow = pcr.max(0., \
             (self.effSatAtFieldCapLow ** self.campbellBetaLow) * self.kSatLow)
        #
        if self.numberOfLayers == 3:

            self.campbellBetaUpp000005 = self.poreSizeBetaUpp000005*2.0 + \
                                            self.clappAddCoeff
            self.campbellBetaUpp005030 = self.poreSizeBetaUpp005030*2.0 + \
                                            self.clappAddCoeff                
            self.campbellBetaLow030150 = self.poreSizeBetaLow030150*2.0 + \
                                            self.clappAddCoeff                

            self.effSatAtFieldCapUpp000005 = \
                     (self.matricSuctionFC / self.airEntryValueUpp000005)**\
                                        (-1.0/ self.poreSizeBetaUpp000005)
            self.effSatAtFieldCapUpp005030 = \
                     (self.matricSuctionFC / self.airEntryValueUpp005030)**\
                                        (-1.0/ self.poreSizeBetaUpp005030)
            self.effSatAtFieldCapLow030150 = \
                     (self.matricSuctionFC / self.airEntryValueLow030150)**\
                                        (-1.0/ self.poreSizeBetaLow030150)

            self.kUnsatAtFieldCapUpp000005 = pcr.max(0., \
             (self.effSatAtFieldCapUpp000005 ** self.campbellBetaUpp000005) * self.kSatUpp000005)
            self.kUnsatAtFieldCapUpp005030 = pcr.max(0., \
             (self.effSatAtFieldCapUpp005030 ** self.campbellBetaUpp005030) * self.kSatUpp005030)
            self.kUnsatAtFieldCapLow030150 = pcr.max(0., \
             (self.effSatAtFieldCapLow030150 ** self.campbellBetaLow030150) * self.kSatLow030150)

        # calculate degree of saturation at which transpiration is halved (50) 
        # and at wilting point
        #
        if self.numberOfLayers == 2:
            self.effSatAt50Upp = (self.matricSuction50/self.airEntryValueUpp)**\
                                                    (-1.0/self.poreSizeBetaUpp)
            self.effSatAt50Upp = pcr.cover(self.effSatAt50Upp, 1.0)                                        
            self.effSatAt50Low = (self.matricSuction50/self.airEntryValueLow)**\
                                                    (-1.0/self.poreSizeBetaLow)
            self.effSatAt50Low = pcr.cover(self.effSatAt50Low, 1.0)                                        
            self.effSatAtWiltPointUpp = pcr.cover(\
                                 (self.matricSuctionWP/self.airEntryValueUpp)**\
                                                    (-1.0/self.poreSizeBetaUpp), 1.0)
            self.effSatAtWiltPointLow = pcr.cover(\
                                 (self.matricSuctionWP/self.airEntryValueLow)**\
                                                    (-1.0/self.poreSizeBetaLow), 1.0)
        if self.numberOfLayers == 3:
            self.effSatAt50Upp000005 = (self.matricSuction50/self.airEntryValueUpp000005)**\
                                                          (-1.0/self.poreSizeBetaUpp000005)
            self.effSatAt50Upp005030 = (self.matricSuction50/self.airEntryValueUpp005030)**\
                                                          (-1.0/self.poreSizeBetaUpp005030)
            self.effSatAt50Low030150 = (self.matricSuction50/self.airEntryValueLow030150)**\
                                                          (-1.0/self.poreSizeBetaLow030150)
            self.effSatAtWiltPointUpp000005 = \
                                       (self.matricSuctionWP/self.airEntryValueUpp000005)**\
                                                          (-1.0/self.poreSizeBetaUpp000005)
            self.effSatAtWiltPointUpp005030 = \
                                       (self.matricSuctionWP/self.airEntryValueUpp005030)**\
                                                          (-1.0/self.poreSizeBetaUpp005030)
            self.effSatAtWiltPointLow030150 = \
                                       (self.matricSuctionWP/self.airEntryValueLow030150)**\
                                                          (-1.0/self.poreSizeBetaLow030150)

        # calculate interflow parameter (TCL): 
        #
        if self.numberOfLayers == 2:
            self.interflowConcTime = (self.kSatLow * self.tanslope*2.0) / \
                     (self.slopeLength * (1.- self.effSatAtFieldCapLow) * \
                    (self.satVolMoistContLow - self.resVolMoistContLow))    # TCL = Duration*(2*KS2*TANSLOPE)/(LSLOPE*(1-THEFF2_FC)*(THETASAT2-THETARES2))
        #
        if self.numberOfLayers == 3:
            self.interflowConcTime = (self.kSatLow030150 * self.tanslope*2.0) / \
                     (self.slopeLength * (1.-self.effSatAtFieldCapLow030150) * \
             (self.satVolMoistContLow030150 - self.resVolMoistContLow030150))
        
        self.interflowConcTime = pcr.max(0.0, pcr.cover(self.interflowConcTime, 0.0))     
Esempio n. 5
0
            case = a
        elif o in ("-I"):
            iniFile = a
        elif o in ("-M"):
            mode = a
        else:
            assert False, "unhandled option"

    # Try and read config file and set default options
    config = ConfigParser.SafeConfigParser()
    config.optionxform = str
    config.read(case + "/" + iniFile)

    # get timestep from wflow ini use comand-line as default
    timestepsecs = int(
        wflow_lib.configget(config, "model", "timestepsecs",
                            str(timestepsecs)))

    logger = setlogger(logfile, "wflow_adapt")

    if mode == "Pre":
        logger.info("Starting preadapter")
        pre_adapter(xmlTimeSeries, logger)
        logger.info("Ending preadapter")
        sys.exit(0)
    elif mode == "Run":
        logger.info("Run adapter not implemented..."
                    )  # Not implmented -> se pcraster adapter
        sys.exit(1)
    elif mode == "Post":

        logger.info("Starting postadapter")
Esempio n. 6
0
        elif o in ("-C"):
            case = a
        elif o in ("-I"):
            iniFile = a
        elif o in ("-M"):
            mode = a
        else:
            assert False, "unhandled option"

    # Try and read config file and set default options
    config = ConfigParser.SafeConfigParser()
    config.optionxform = str
    config.read(case + "/" + iniFile)

    # get timestep from wflow ini use comand-line as default
    timestepsecs = int(wflow_lib.configget(config, "model", "timestepsecs", str(timestepsecs)))

    logger = setlogger(logfile, "wflow_adapt")

    if mode == "Pre":
        logger.info("Starting preadapter")
        pre_adapter(xmlTimeSeries, logger)
        logger.info("Ending preadapter")
        sys.exit(0)
    elif mode == "Run":
        logger.info("Run adapter not implemented...")  # Not implmented -> se pcraster adapter
        sys.exit(1)
    elif mode == "Post":

        logger.info("Starting postadapter")
        pixml_state_updateTime(inputStateFile, stateFile, getEndTimefromRuninfo(runinfofile))
Esempio n. 7
0
            case = a
        elif o in ("-I"):
            iniFile = a
        elif o in ("-M"):
            mode = a
        else:
            assert False, "unhandled option"

    # Try and read config file and set default options
    config = configparser.ConfigParser()
    config.optionxform = str
    config.read(workdir + "/" + case + "/" + iniFile)

    # get timestep from wflow ini
    timestepsecs = int(
        wflow_lib.configget(config, "run", "timestepsecs", str(timestepsecs)))
    netcdf = wflow_lib.configget(config, "framework", "netcdfoutput", "None")
    if netcdf != "None":
        netcdfoutput = True

    logger = setlogger(logfile, "wflow_adapt")

    if mode == "Pre":
        logger.info("Starting preadapter")
        pre_adapter(xmlTimeSeries, logger)
        logger.info("Ending preadapter")
        sys.exit(0)
    elif mode == "Post":
        logger.info("Starting postadapter")

        # Step1: update the state xml files
Esempio n. 8
0
    def readTopo(self, iniItems, optionDict):

        # a dictionary/section of options that will be used
        if optionDict == None:
            optionDict = iniItems._sections["landSurfaceOptions"]

        # maps of elevation attributes:
        topoParams = ["tanslope", "slopeLength", "orographyBeta"]
        if optionDict["topographyNC"] == str(None):
            for var in topoParams:
                input = configget(iniItems, "landSurfaceOptions", str(var), "None")
                vars(self)[var] = vos.readPCRmapClone(
                    input, self.cloneMap, self.tmpDir, self.inputDir
                )
                if var != "slopeLength":
                    vars(self)[var] = pcr.cover(vars(self)[var], 0.0)
        else:
            topoPropertiesNC = vos.getFullPath(
                optionDict["topographyNC"], self.inputDir
            )

            for var in topoParams:
                vars(self)[var] = vos.netcdf2PCRobjCloneWithoutTime(
                    topoPropertiesNC, var, cloneMapFileName=self.cloneMap
                )
                if var != "slopeLength":
                    vars(self)[var] = pcr.cover(vars(self)[var], 0.0)

        # ~ self.tanslope = pcr.max(self.tanslope, 0.00001)              # In principle, tanslope can be zero. Zero tanslope will provide zero TCL (no interflow)

        # covering slopeLength with its maximum value
        self.slopeLength = pcr.cover(self.slopeLength, pcr.mapmaximum(self.slopeLength))

        # maps of relative elevation above flood plains
        dzRel = [
            "dzRel0001",
            "dzRel0005",
            "dzRel0010",
            "dzRel0020",
            "dzRel0030",
            "dzRel0040",
            "dzRel0050",
            "dzRel0060",
            "dzRel0070",
            "dzRel0080",
            "dzRel0090",
            "dzRel0100",
        ]
        if optionDict["topographyNC"] == str(None):
            for i in range(0, len(dzRel)):
                var = dzRel[i]
                input = optionDict[str(var)]
                vars(self)[var] = vos.readPCRmapClone(
                    input, self.cloneMap, self.tmpDir, self.inputDir
                )
                vars(self)[var] = pcr.cover(vars(self)[var], 0.0)
                if i > 0:
                    vars(self)[var] = pcr.max(vars(self)[var], vars(self)[dzRel[i - 1]])
        else:
            for i in range(0, len(dzRel)):
                var = dzRel[i]
                vars(self)[var] = vos.netcdf2PCRobjCloneWithoutTime(
                    topoPropertiesNC, var, cloneMapFileName=self.cloneMap
                )
                vars(self)[var] = pcr.cover(vars(self)[var], 0.0)
                if i > 0:
                    vars(self)[var] = pcr.max(vars(self)[var], vars(self)[dzRel[i - 1]])
Esempio n. 9
0
    def readSoil(self, iniItems, optionDict=None):

        # a dictionary/section of options that will be used
        if optionDict == None:
            optionDict = iniItems._sections[
                "landSurfaceOptions"
            ]  # iniItems.landSurfaceOptions

        # default values of soil parameters that are constant/uniform for the entire domain:
        self.clappAddCoeff = pcr.scalar(3.0)  # dimensionless
        self.matricSuctionFC = pcr.scalar(1.0)  # unit: m
        # ~ self.matricSuction50 = pcr.scalar(10./3.)  # unit: m
        self.matricSuction50 = pcr.scalar(3.33)  # unit: m
        self.matricSuctionWP = pcr.scalar(156.0)  # unit: m
        self.maxGWCapRise = pcr.scalar(5.0)  # unit: m
        #
        # values defined in the ini/configuration file:
        soilParameterConstants = [
            "clappAddCoeff",
            "matricSuctionFC",
            "matricSuction50",
            "matricSuctionWP",
            "maxGWCapRise",
        ]
        for var in soilParameterConstants:
            if var in configsection(iniItems, "landSurfaceOptions"):
                input = configget(iniItems, "landSurfaceOptions", str(var), "None")
                vars(self)[var] = vos.readPCRmapClone(
                    input, self.cloneMap, self.tmpDir, self.inputDir
                )

        # read soil parameter based on the FAO soil map:
        self.readSoilMapOfFAO(iniItems, optionDict)

        # assign Campbell's (1974) beta coefficient, as well as degree
        # of saturation at field capacity and corresponding unsaturated hydraulic conductivity
        #
        if self.numberOfLayers == 2:

            self.campbellBetaUpp = (
                self.poreSizeBetaUpp * 2.0 + self.clappAddCoeff
            )  # Campbell's (1974) coefficient ; Rens's line: BCB = 2*BCH + BCH_ADD
            self.campbellBetaLow = self.poreSizeBetaLow * 2.0 + self.clappAddCoeff

            self.effSatAtFieldCapUpp = (
                self.matricSuctionFC / self.airEntryValueUpp
            ) ** (
                -1.0 / self.poreSizeBetaUpp
            )  # saturation degree at field capacity       : THEFF_FC = (PSI_FC/PSI_A)**(-1/BCH)
            self.effSatAtFieldCapUpp = pcr.cover(self.effSatAtFieldCapUpp, 1.0)

            self.effSatAtFieldCapLow = (
                self.matricSuctionFC / self.airEntryValueLow
            ) ** (-1.0 / self.poreSizeBetaLow)
            self.effSatAtFieldCapLow = pcr.cover(self.effSatAtFieldCapLow, 1.0)

            self.kUnsatAtFieldCapUpp = pcr.max(
                0.0, (self.effSatAtFieldCapUpp ** self.campbellBetaUpp) * self.kSatUpp
            )  # unsaturated conductivity at field capacity: KTHEFF_FC = max(0,THEFF_FC[TYPE]**BCB*KS1)
            self.kUnsatAtFieldCapLow = pcr.max(
                0.0, (self.effSatAtFieldCapLow ** self.campbellBetaLow) * self.kSatLow
            )
        #
        if self.numberOfLayers == 3:

            self.campbellBetaUpp000005 = (
                self.poreSizeBetaUpp000005 * 2.0 + self.clappAddCoeff
            )
            self.campbellBetaUpp005030 = (
                self.poreSizeBetaUpp005030 * 2.0 + self.clappAddCoeff
            )
            self.campbellBetaLow030150 = (
                self.poreSizeBetaLow030150 * 2.0 + self.clappAddCoeff
            )

            self.effSatAtFieldCapUpp000005 = (
                self.matricSuctionFC / self.airEntryValueUpp000005
            ) ** (-1.0 / self.poreSizeBetaUpp000005)
            self.effSatAtFieldCapUpp005030 = (
                self.matricSuctionFC / self.airEntryValueUpp005030
            ) ** (-1.0 / self.poreSizeBetaUpp005030)
            self.effSatAtFieldCapLow030150 = (
                self.matricSuctionFC / self.airEntryValueLow030150
            ) ** (-1.0 / self.poreSizeBetaLow030150)

            self.kUnsatAtFieldCapUpp000005 = pcr.max(
                0.0,
                (self.effSatAtFieldCapUpp000005 ** self.campbellBetaUpp000005)
                * self.kSatUpp000005,
            )
            self.kUnsatAtFieldCapUpp005030 = pcr.max(
                0.0,
                (self.effSatAtFieldCapUpp005030 ** self.campbellBetaUpp005030)
                * self.kSatUpp005030,
            )
            self.kUnsatAtFieldCapLow030150 = pcr.max(
                0.0,
                (self.effSatAtFieldCapLow030150 ** self.campbellBetaLow030150)
                * self.kSatLow030150,
            )

        # calculate degree of saturation at which transpiration is halved (50)
        # and at wilting point
        #
        if self.numberOfLayers == 2:
            self.effSatAt50Upp = (self.matricSuction50 / self.airEntryValueUpp) ** (
                -1.0 / self.poreSizeBetaUpp
            )
            self.effSatAt50Upp = pcr.cover(self.effSatAt50Upp, 1.0)
            self.effSatAt50Low = (self.matricSuction50 / self.airEntryValueLow) ** (
                -1.0 / self.poreSizeBetaLow
            )
            self.effSatAt50Low = pcr.cover(self.effSatAt50Low, 1.0)
            self.effSatAtWiltPointUpp = pcr.cover(
                (self.matricSuctionWP / self.airEntryValueUpp)
                ** (-1.0 / self.poreSizeBetaUpp),
                1.0,
            )
            self.effSatAtWiltPointLow = pcr.cover(
                (self.matricSuctionWP / self.airEntryValueLow)
                ** (-1.0 / self.poreSizeBetaLow),
                1.0,
            )
        if self.numberOfLayers == 3:
            self.effSatAt50Upp000005 = (
                self.matricSuction50 / self.airEntryValueUpp000005
            ) ** (-1.0 / self.poreSizeBetaUpp000005)
            self.effSatAt50Upp005030 = (
                self.matricSuction50 / self.airEntryValueUpp005030
            ) ** (-1.0 / self.poreSizeBetaUpp005030)
            self.effSatAt50Low030150 = (
                self.matricSuction50 / self.airEntryValueLow030150
            ) ** (-1.0 / self.poreSizeBetaLow030150)
            self.effSatAtWiltPointUpp000005 = (
                self.matricSuctionWP / self.airEntryValueUpp000005
            ) ** (-1.0 / self.poreSizeBetaUpp000005)
            self.effSatAtWiltPointUpp005030 = (
                self.matricSuctionWP / self.airEntryValueUpp005030
            ) ** (-1.0 / self.poreSizeBetaUpp005030)
            self.effSatAtWiltPointLow030150 = (
                self.matricSuctionWP / self.airEntryValueLow030150
            ) ** (-1.0 / self.poreSizeBetaLow030150)

        # calculate interflow parameter (TCL):
        #
        if self.numberOfLayers == 2:
            self.interflowConcTime = (self.kSatLow * self.tanslope * 2.0) / (
                self.slopeLength
                * (1.0 - self.effSatAtFieldCapLow)
                * (self.satVolMoistContLow - self.resVolMoistContLow)
            )  # TCL = Duration*(2*KS2*TANSLOPE)/(LSLOPE*(1-THEFF2_FC)*(THETASAT2-THETARES2))
        #
        if self.numberOfLayers == 3:
            self.interflowConcTime = (self.kSatLow030150 * self.tanslope * 2.0) / (
                self.slopeLength
                * (1.0 - self.effSatAtFieldCapLow030150)
                * (self.satVolMoistContLow030150 - self.resVolMoistContLow030150)
            )

        self.interflowConcTime = pcr.max(0.0, pcr.cover(self.interflowConcTime, 0.0))
Esempio n. 10
0
def main():
    """
    Main entry for using the module as a command line program (e.g. from the Delft-FEWS GA)
    """
    global case
    global runId
    timestepsecs = 86400
    xmldiagfname = "wflow_diag.xml"
    adaptxmldiagfname = "wflow_adapt_diag.xml"
    logfname = "wflow.log"
    netcdfoutput = False

    try:
        opts, _ = getopt.getopt(sys.argv[1:], "-M:-t:-s:-o:-r:-w:-C:-I:R:")
    except getopt.GetoptError as err:
        # print help information and exit:
        print(str(err))
        usage()
        sys.exit(2)

    if not opts:
        usage()
        sys.exit(2)

    xmlTimeSeries = ""
    stateFile = ""

    mode = "Pre"
    for o, a in opts:
        if o == "-v":
            verbose = True
        elif o in ("-t"):
            xmlTimeSeries = a
        elif o in ("-R"):
            runId = a
        elif o in ("-o"):
            stateFile = a
        elif o in ("-s"):
            inputStateFile = a
        elif o in ("-r"):
            runinfofile = a
        elif o in ("-w"):
            workdir = a
        elif o in ("-C"):
            case = a
        elif o in ("-I"):
            iniFile = a
        elif o in ("-M"):
            mode = a
        else:
            assert False, "unhandled option"

    # Try and read config file and set default options
    config = configparser.ConfigParser()
    config.optionxform = str
    config.read(workdir + "/" + case + "/" + iniFile)

    # get timestep from wflow ini
    timestepsecs = int(
        wflow_lib.configget(config, "run", "timestepsecs", str(timestepsecs))
    )
    netcdf = wflow_lib.configget(config, "framework", "netcdfoutput", "None")
    if netcdf != "None":
        netcdfoutput = True

    logger = setlogger(logfile, "wflow_adapt")

    if mode == "Pre":
        logger.info("Starting preadapter")
        pre_adapter(xmlTimeSeries, logger)
        logger.info("Ending preadapter")
        sys.exit(0)
    elif mode == "Post":
        logger.info("Starting postadapter")

        # Step1: update the state xml files
        pixml_state_updateTime(
            inputStateFile, stateFile, getEndTimefromRuninfo(runinfofile)
        )

        # Step 2: make XML files to go with the output mapstacks if the output is not in netcdf
        # Get outputmapstacks from wflow ini
        mstacks = config.options("outputmaps")
        # Create XML files for all mapstacks if not netcdf
        if not netcdfoutput:
            for a in mstacks:
                var = config.get("outputmaps", a)
                logger.debug(
                    "Creating mapstack xml: "
                    + workdir
                    + "/"
                    + case
                    + "/"
                    + runId
                    + "/"
                    + var
                    + ".xml"
                )
                mapstackxml(
                    workdir + "/" + case + "/" + runId + "/outmaps/" + var + ".xml",
                    var + "?????.???",
                    var,
                    var,
                    getStartTimefromRuninfo(runinfofile),
                    getEndTimefromRuninfo(runinfofile),
                    timestepsecs,
                )

            # Back hack to work around the 0 based FEWS problem and create a double timestep zo that we have connection between subsequent runs in FEWS
            try:
                shutil.copy(
                    workdir + "/" + case + "/instate/SurfaceRunoff.map",
                    workdir + "/" + case + "/" + runId + "/outmaps/run00000.000",
                )
                shutil.copy(
                    workdir + "/" + case + "/instate/WaterLevel.map",
                    workdir + "/" + case + "/" + runId + "/outmaps/lev00000.000",
                )
                shutil.copy(
                    workdir + "/" + case + "/instate/WSO.map",
                    workdir + "/" + case + "/" + runId + "/outmaps/WSO00000.000",
                )
                shutil.copy(
                    workdir + "/" + case + "/instate/LAI.map",
                    workdir + "/" + case + "/" + runId + "/outmaps/LAI00000.000",
                )
            except:
                logger.warning("Cannot copy Surfacerunoff and/or level")

        # Step 3:
        # now check for tss files in the ini file and convert to XML
        stop = 0
        secnr = 0
        while stop == 0:
            if stop == 1:
                break
            try:
                thissection = "outputtss_" + str(secnr)
                tssfiles = config.options(thissection)
                secnr = secnr + 1
                sDate = getStartTimefromRuninfo(runinfofile)

                for aa in tssfiles:
                    if aa not in "samplemap":
                        tssFile = (
                            workdir
                            + "/"
                            + case
                            + "/"
                            + runId
                            + "/"
                            + config.get(thissection, aa)
                        )
                        logger.debug(
                            "Creating xml from tss: "
                            + tssFile
                            + "==> "
                            + tssFile
                            + ".xml"
                        )
                        tss_topixml(
                            tssFile,
                            tssFile + ".xml",
                            "wflow",
                            config.get(thissection, aa),
                            sDate,
                            timestepsecs,
                        )
            except:
                stop = 1

        # Convert log file of model code
        log2xml(case + "/" + runId + "/" + logfname, xmldiagfname)
        logger.info("Ending postadapter")
        # convert logfile of adapter
        log2xml(logfile, adaptxmldiagfname)
    else:
        sys.exit(2)