Example #1
0
def CWATMexe2(settings, meteo):
    """
    Base subroutine of the CWATM model for calibration

    * parses the settings file
    * read the information for the netcdf files
    * check if dates are alright
    * check flags for screen output
    * loads meteo data from MEMORY
    * runs the model


    """
    parse_configuration(settings)
    read_metanetcdf(cbinding('metaNetcdfFile'), 'metaNetcdfFile')

    checkifDate('StepStart', 'StepEnd', 'SpinUp',
                cbinding('PrecipitationMaps'))
    # checks if end date is later than start date and puts both in modelSteps

    days = 1 + dateVar["intEnd"] - dateVar["intStart"]
    for i in inputcounter.keys():
        inputcounter[i] = inputcounter[i] - days

    CWATM = CWATModel()
    CWATM.var.meteo = meteo
    stCWATM = ModelFrame(CWATM,
                         firstTimestep=dateVar["intStart"],
                         lastTimeStep=dateVar["intEnd"])

    start_time = datetime.datetime.now().time()
    if Flags['loud']:
        print("%-6s %10s %11s\n" % ("Step", "Date", "Discharge"), end=' ')

    stCWATM.run()

    if Flags['printtime']:
        print("\n\nTime profiling")
        print("%2s %-17s %10s %8s" % ("No", "Name", "time[s]", "%"))

        timeSum = np.array(timeMesSum)
        timePrint = timeSum
        for i in range(len(timePrint)):
            print("%2i %-17s %10.2f %8.1f" %
                  (i, timeMesString[i], timePrint[i],
                   100 * timePrint[i] / timePrint[-1]))

    # return with last value and true for successfull run for pytest
    return (True, CWATM.var.firstout)
Example #2
0
    def initial(self):
        """
        Initial part of the water demand module - industry

        """
        if "industryTimeMonthly" in binding:
            if returnBool('industryTimeMonthly'):
                self.var.industryTime = 'monthly'
            else:
                self.var.industryTime = 'yearly'
        else:
            self.var.industryTime = 'monthly'

        if "industryWithdrawalvarname" in binding:
            self.var.indWithdrawalVar = cbinding("industryWithdrawalvarname")
        else:
            self.var.indWithdrawalVar = "industryGrossDemand"
        if "industryConsuptionvarname" in binding:
            self.var.indConsumptionVar = cbinding("industryConsuptionvarname")
        else:
            self.var.indConsumptionVar = "industryNettoDemand"
Example #3
0
    def initial(self):
        """
        Initial part of the water demand module

        """

        if "domesticTimeMonthly" in binding:
            if returnBool('domesticTimeMonthly'):
                self.var.domesticTime = 'monthly'
            else:
                self.var.domesticTime = 'yearly'
        else:
            self.var.domesticTime = 'monthly'

        if "domesticWithdrawalvarname" in binding:
            self.var.domWithdrawalVar = cbinding("domesticWithdrawalvarname")
        else:
            self.var.domWithdrawalVar = "domesticGrossDemand"
        if "domesticConsuptionvarname" in binding:
            self.var.domConsumptionVar = cbinding("domesticConsuptionvarname")
        else:
            self.var.domConsumptionVar = "domesticNettoDemand"
Example #4
0
    def initial(self):
        """
        Initial part of the water demand module - livestock

        """

        self.var.livestockTime = 'monthly'
        if "livestockTimeMonthly" in binding:
            if returnBool('livestockTimeMonthly'):
                self.var.livestockTime = 'monthly'
            else:
                self.var.livestockTime = 'yearly'
        else:
            self.var.livestockTime = 'monthly'

        if "livestockvarname" in binding:
            self.var.livVar = cbinding("livestockvarname")
        else:
            self.var.livVar = "livestockDemand"

        if "uselivestock" in binding:
            self.var.uselivestock = returnBool('uselivestock')
        else:
            self.var.uselivestock = False
Example #5
0
def CWATMexe(settings):
    """
    Base subroutine of the CWATM model

    * parses the settings file
    * read the information for the netcdf files
    * check if dates are alright
    * check flags for screen output
    * runs the model


    """

    parse_configuration(settings)
    # print option
    # print binding
    # read all the possible option for modelling and for generating output
    # read the settings file with all information about the catchments(s)
    # read the meta data information for netcdf outputfiles
    read_metanetcdf(cbinding('metaNetcdfFile'), 'metaNetcdfFile')

    # os.chdir(outputDir[0])
    # this prevent from using relative path in settings!

    checkifDate('StepStart', 'StepEnd', 'SpinUp',
                cbinding('PrecipitationMaps'))
    # checks if end date is later than start date and puts both in modelSteps
    if Flags['check']:
        dateVar["intEnd"] = dateVar["intStart"]

    CWATM = CWATModel()
    stCWATM = ModelFrame(CWATM,
                         firstTimestep=dateVar["intStart"],
                         lastTimeStep=dateVar["intEnd"])
    """
    ----------------------------------------------
    Deterministic run
    ----------------------------------------------
    """
    print(CWATMRunInfo([outputDir[0], settingsfile[0]]))
    start_time = datetime.datetime.now().time()
    if Flags['loud']:
        print("%-6s %10s %11s\n" % ("Step", "Date", "Discharge"), end=' ')

    stCWATM.run()

    # cProfile.run('stLisflood.run()')
    # python -m cProfile -o  l1.pstats cwatm.py settings1.ini
    # gprof2dot -f pstats l1.pstats | dot -T png -o callgraph.png
    # pyreverse -AS -f ALL -o png cwatm.py -p Main

    if Flags['printtime']:
        print("\n\nTime profiling")
        print("%2s %-17s %10s %8s" % ("No", "Name", "time[s]", "%"))

        timeSum = np.array(timeMesSum)
        timePrint = timeSum
        for i in range(len(timePrint)):
            print("%2i %-17s %10.2f %8.1f" %
                  (i, timeMesString[i], timePrint[i],
                   100 * timePrint[i] / timePrint[-1]))

    if Flags['loud']:
        current_time = datetime.datetime.now().time()
        print("\nStart: " + start_time.isoformat())
        print("End:   " + current_time.isoformat())

    # return with last value and true for successfull run for pytest
    if Flags['calib']:
        return (CWATM.var.meteo, True, CWATM.var.firstout)
    else:
        return (True, CWATM.var.firstout)