Пример #1
0
    def initialize(self, configfile=None,loglevel=logging.DEBUG):
        """
        Assumptions for now:
        - the configfile wih be a full path
        - we define the case from the basedir of the configfile
        """

        retval = 0
        self.currenttimestep = 1
        wflow_cloneMap = 'wflow_subcatch.map'
        datadir = os.path.dirname(configfile)
        inifile = os.path.basename(configfile)
        runid = "run_default"
        # The current pcraster framework needs a max number of timesteps :-(
        # This cannot be avoided at the moment (needs a rework)
        # set to 10000 for now
        # .. todo::
        #       Get name of module from ini file name

        maxNrSteps = 10000
        if "wflow_sbm.ini" in configfile:
            import wflow_sbm as wf
            self.name = "wflow_sbm"
        elif "wflow_hbv.ini" in configfile:
            import wflow_hbv as wf
            self.name = "wflow_hbv"
        elif "wflow_routing.ini" in configfile:
            import wflow_routing as wf
            self.name = "wflow_routing"
        else:
            modname = os.path.splitext(os.path.basename(configfile))[0]
            exec "import wflow." + modname + " as wf"
            self.name = modname

        self.bmilogger.info("initialize: Initialising wflow bmi with ini: " + configfile)
        myModel = wf.WflowModel(wflow_cloneMap, datadir, runid, inifile)

        self.dynModel = wf.wf_DynamicFramework(myModel, maxNrSteps, firstTimestep = 1)
        self.dynModel.createRunId(NoOverWrite=0,level=loglevel,model=os.path.basename(configfile))


        namesroles = self.dynModel.wf_supplyVariableNamesAndRoles()
        inames = []

        for varrol in namesroles:
            if varrol[1] == 1:
                inames.append(varrol[0])
        self.outputonlyvars = inames

        inames = []
        for varrol in namesroles:
            if varrol[1] == 0 or varrol[1] == 2 or varrol[1] == 3:
                inames.append(varrol[0])

        self.inputoutputvars = inames

        self.dynModel._runInitial()
        self.dynModel._runResume()

        return retval
Пример #2
0
    def initialize_config(self, filename, loglevel=logging.DEBUG):
        """
        *Extended functionality*, see https://github.com/eWaterCycle/bmi/blob/master/src/main/python/bmi.py

        see initialize

        :param filename:
        :param loglevel:
        :return: nothing
        """

        self.currenttimestep = 1
        wflow_cloneMap = 'wflow_subcatch.map'
        self.datadir = os.path.dirname(filename)
        inifile = os.path.basename(filename)
        runid = "run_default"
        # The current pcraster framework needs a max number of timesteps :-(
        # This cannot be avoided at the moment (needs a rework)
        # set to 10000 for now
        #
        maxNrSteps = 10000


        if "wflow_sbm" in inifile:
            import wflow.wflow_sbm as wf
            self.name = "wflow_sbm"
        elif "wflow_hbv" in inifile:
            import wflow.wflow_hbv as wf
            self.name = "wflow_hbv"
        elif "wflow_routing" in inifile:
            import wflow.wflow_routing as wf
            self.name = "wflow_routing"
        elif "wflow_floodmap" in inifile:
            import wflow.wflow_floodmap as wf
            self.name = "wflow_floodmap"
        else:
            modname = os.path.splitext(os.path.basename(filename))[0]
            exec "import wflow." + modname + " as wf"
            self.name = modname

        self.bmilogger.info("initialize_config: Initialising wflow bmi with ini: " + filename + " Component name: " + self.name)
        self.myModel = wf.WflowModel(wflow_cloneMap, self.datadir, runid, inifile)

        self.dynModel = wf.wf_DynamicFramework(self.myModel, maxNrSteps, firstTimestep = 1)
        self.dynModel.createRunId(doSetupFramework=False,NoOverWrite=0,level=loglevel,model=os.path.basename(filename))

        namesroles = self.dynModel.wf_supplyVariableNamesAndRoles()
        inames = []

        for varrol in namesroles:
            if varrol[1] == 1:
                inames.append(varrol[0])
        self.outputonlyvars = inames

        inames = []
        for varrol in namesroles:
            if varrol[1] == 0 or varrol[1] == 2 or varrol[1] == 3:
                inames.append(varrol[0])

        self.inputoutputvars = inames
Пример #3
0
    def initialize_config(self, filename, loglevel=logging.DEBUG):
        """
        *Extended functionality*, see https://github.com/eWaterCycle/bmi/blob/master/src/main/python/bmi.py

        see initialize

        :param filename:
        :param loglevel:
        :return: nothing
        """

        self.currenttimestep = 1
        wflow_cloneMap = 'wflow_subcatch.map'
        self.datadir = os.path.dirname(filename)
        inifile = os.path.basename(filename)
        runid = "run_default"
        # The current pcraster framework needs a max number of timesteps :-(
        # This cannot be avoided at the moment (needs a rework)
        # set to 10000 for now
        #
        maxNrSteps = 10000

        if "wflow_sbm" in filename:
            import wflow.wflow_sbm as wf
            self.name = "wflow_sbm"
        elif "wflow_hbv" in filename:
            import wflow.wflow_hbv as wf
            self.name = "wflow_hbv"
        elif "wflow_routing" in filename:
            import wflow.wflow_routing as wf
            self.name = "wflow_routing"
        else:
            modname = os.path.splitext(os.path.basename(filename))[0]
            exec "import wflow." + modname + " as wf"
            self.name = modname

        self.myModel = wf.WflowModel(wflow_cloneMap, self.datadir, runid,
                                     inifile)

        self.dynModel = wf.wf_DynamicFramework(self.myModel,
                                               maxNrSteps,
                                               firstTimestep=1)
        self.dynModel.createRunId(doSetupFramework=False,
                                  NoOverWrite=0,
                                  level=loglevel,
                                  model=os.path.basename(filename))
Пример #4
0
    def initialize(self, configfile=None, loglevel=logging.DEBUG):
        """
        Assumptions for now:
        - the configfile wih be a full path
        - we define the case from the basedir of the configfile
        """
        retval = 0
        self.currenttimestep = 1
        wflow_cloneMap = 'wflow_subcatch.map'
        datadir = os.path.dirname(configfile)
        inifile = os.path.basename(configfile)
        runid = "run_default"
        # The current pcraster framework needs a max number of timesteps :-(
        # This cannot be avoided at the moment (needs a rework)
        # set to 10000 for now
        # .. todo::
        #       Get name of module from ini file name

        maxNrSteps = 10000
        if "wflow_sbm.ini" in configfile:
            import wflow_sbm as wf
            self.name = "wflow_sbm"
        elif "wflow_hbv.ini" in configfile:
            import wflow_hbv as wf
            self.name = "wflow_hbv"
        elif "wflow_routing.ini" in configfile:
            import wflow_routing as wf
            self.name = "wflow_routing"
        else:
            raise ValueError

        myModel = wf.WflowModel(wflow_cloneMap, datadir, runid, inifile)

        self.dynModel = wf.wf_DynamicFramework(myModel,
                                               maxNrSteps,
                                               firstTimestep=1)
        self.dynModel.createRunId(NoOverWrite=0,
                                  level=loglevel,
                                  model=os.path.basename(configfile))
        self.dynModel._runInitial()
        self.dynModel._runResume()

        return retval
Пример #5
0
    def initialize(self, configfile=None, loglevel=logging.DEBUG):
        """
        Assumptions for now:
        - the configfile wih be a full path
        - we define the case from the basedir of the configfile
        """

        retval = 0
        self.currenttimestep = 1
        wflow_cloneMap = 'wflow_subcatch.map'
        datadir = os.path.dirname(configfile)
        inifile = os.path.basename(configfile)
        runid = "run_default"
        # The current pcraster framework needs a max number of timesteps :-(
        # This cannot be avoided at the moment (needs a rework)
        # set to 10000 for now
        # .. todo::
        #       Get name of module from ini file name
        fullpathname = os.path.abspath(configfile)
        self.config = iniFileSetUp(fullpathname)

        self.name, useddef = configget(
            self.config, 'model', 'modeltype',
            os.path.splitext(os.path.basename(configfile))[0])
        if useddef:
            self.bmilogger.warn(
                "Please specify modeltype in the model section of file: " +
                configfile)
            self.bmilogger.warn("Assuming " + self.name + " as model type.")

        maxNrSteps = 10000
        maxNrSteps = 0
        try:
            exec "import wflow." + self.name + " as wf"
        except:
            if "wflow" in configfile and "sbm" in configfile and ".ini" in configfile:
                import wflow_sbm as wf
                self.name = "wflow_sbm"
            elif "wflow" in configfile and "hbv" in configfile and ".ini" in configfile:
                import wflow_hbv as wf
                self.name = "wflow_hbv"
            elif "wflow" in configfile and "routing" in configfile and ".ini" in configfile:
                import wflow_routing as wf
                self.name = "wflow_routing"

        self.bmilogger.info("initialize: Initialising wflow bmi with ini: " +
                            configfile)
        myModel = wf.WflowModel(wflow_cloneMap, datadir, runid, inifile)

        self.dynModel = wf.wf_DynamicFramework(myModel,
                                               maxNrSteps,
                                               firstTimestep=0)
        self.bmilogger.info("Framework initialized...")
        self.dynModel.createRunId(NoOverWrite=0,
                                  level=loglevel,
                                  model=os.path.basename(configfile))
        self.bmilogger.info("initialize: created runID...")

        namesroles = self.dynModel.wf_supplyVariableNamesAndRoles()
        inames = []

        for varrol in namesroles:
            if varrol[1] == 1:
                inames.append(varrol[0])
        self.outputonlyvars = inames

        inames = []
        for varrol in namesroles:
            if varrol[1] == 0 or varrol[1] == 2 or varrol[1] == 3:
                inames.append(varrol[0])

        self.inputoutputvars = inames

        self.dynModel._runInitial()
        self.bmilogger.info("Model initialised...")
        self.dynModel._runResume()
        self.bmilogger.info("Resumed states...")

        return retval