コード例 #1
0
ファイル: test_BMI.py プロジェクト: openstreams/wflow
    def testbmirunnetcdf(self):
        bmiobj = bmi.wflowbmi_csdms()
        bmiobj.initialize_config("wflow_sbm/wflow_sbm_nc.ini", loglevel=logging.ERROR)
        bmiobj.set_start_time(1399597200)
        bmiobj.set_end_time(1399597200 + (4 * 3600))

        st = bmiobj.get_start_time()
        ett = bmiobj.get_end_time()
        ts = bmiobj.get_time_step()

        bmiobj.initialize_model()
        tt = bmiobj.get_value("timestepsecs")
        curtime = st
        cnt = 0
        lastcurtime = bmiobj.get_current_time()
        while curtime < ett:
            avar = bmiobj.get_value("PET")
            bmiobj.set_value("PET", avar + 10.0)
            cnt = cnt + 1
            bmiobj.update_until(curtime + ts)
            print((curtime + ts) / ts)
            curtime = bmiobj.get_current_time()
            print(bmiobj.get_current_time() - lastcurtime)
            lastcurtime = bmiobj.get_current_time()

        bmiobj.finalize()
        self.assertEqual(ett, bmiobj.get_current_time())
コード例 #2
0
ファイル: TestBMI.py プロジェクト: charlibrown33/wflow
    def testbmirun(self):
        bmiobj = bmi.wflowbmi_csdms()
        bmiobj.initialize('wflow_sceleton/wflow_sceleton.ini',loglevel=logging.ERROR)

        et = bmiobj.get_end_time()
        bmiobj.update_until(et)
        bmiobj.finalize()
コード例 #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

        Read the ini file for the comnined bmi model and initializes all the bmi models
        listed in the config file.

        :param filename:
        :return: nothing
        """

        self.currenttimestep = 1

        fullpathname = os.path.abspath(filename)
        self.config = iniFileSetUp(fullpathname)
        self.datadir = os.path.dirname(fullpathname)
        inifile = os.path.basename(filename)

        self.models = configsection(self.config, "models")
        self.exchanges = configsection(self.config, "exchanges")

        for mod in self.models:
            self.bmimodels[mod] = wfbmi.wflowbmi_csdms()

        # Initialize all bmi model objects
        for key, value in self.bmimodels.iteritems():
            modconf = os.path.join(self.datadir, self.config.get("models", key))
            self.bmimodels[key].initialize_config(modconf, loglevel=loglevel)
コード例 #4
0
ファイル: wflow_bmi_combined.py プロジェクト: gurbuzf/wflow
    def initialize_config(self, filename, loglevel=logging.DEBUG):
        """
        *Extended functionality*, see https://github.com/eWaterCycle/bmi/blob/master/src/main/python/bmi.py

        Read the ini file for the comnined bmi model and initializes all the bmi models
        listed in the config file.

        :param filename:
        :return: nothing
        """

        self.currenttimestep = 1

        fullpathname = os.path.abspath(filename)
        self.config = iniFileSetUp(fullpathname)
        self.datadir = os.path.dirname(fullpathname)
        inifile = os.path.basename(filename)

        # mappingdir = self.datadir + '\\bmi_mapping\\'
        mappingdir = (os.path.join(
            self.datadir,
            wfbmi.configget(self.config, "IdMapping", "folder",
                            "bmi_mapping")[0],
        ) + "\\")

        self.models = configsection(self.config, "models")
        self.exchanges = configsection(self.config, "exchanges")

        for item in self.exchanges:
            exchange_from = item.split(self.comp_sep)

            if len(exchange_from) == 3 and exchange_from[2].endswith("map"):
                map_temp = pcr.readmap(mappingdir + exchange_from[2])
                map_flip = np.flipud(pcr.pcr2numpy(map_temp, 0))
                ind_temp = np.where(map_flip == 1)
                ind = [list(ind_temp[0]), list(ind_temp[1])]
                self.indices_from.append(ind)
            else:
                self.indices_from.append([])

            exchange_to = self.config.get("exchanges",
                                          item).split(self.comp_sep)

            if len(exchange_to) == 3 and exchange_from[2].endswith("map"):
                map_temp = pcr.readmap(mappingdir + exchange_to[2])
                map_flip = np.flipud(pcr.pcr2numpy(map_temp, 0))
                ind_temp = np.where(map_flip == 1)
                ind = [list(ind_temp[0]), list(ind_temp[1])]
                self.indices_to.append(ind)
            else:
                self.indices_to.append([])

        for mod in self.models:
            self.bmimodels[mod] = wfbmi.wflowbmi_csdms()

        # Initialize all bmi model objects
        for key, value in self.bmimodels.items():
            modconf = os.path.join(self.datadir,
                                   self.config.get("models", key))
            self.bmimodels[key].initialize_config(modconf, loglevel=loglevel)
コード例 #5
0
ファイル: TestBMI.py プロジェクト: marioponce/wflow
    def testbmirunnetcdf(self):
        bmiobj = bmi.wflowbmi_csdms()
        bmiobj.initialize_config('wflow_sbm/wflow_sbm_nc.ini',
                                 loglevel=logging.ERROR)
        bmiobj.set_start_time(1399597200)
        bmiobj.set_end_time(1399597200 + (4 * 3600))

        st = bmiobj.get_start_time()
        ett = bmiobj.get_end_time()
        ts = bmiobj.get_time_step()

        bmiobj.initialize_model()
        tt = bmiobj.get_value('timestepsecs')
        curtime = st
        cnt = 0
        lastcurtime = bmiobj.get_current_time()
        while curtime < ett:
            avar = bmiobj.get_value('PET')
            bmiobj.set_value('PET', avar + 10.0)
            cnt = cnt + 1
            bmiobj.update_until(curtime + ts)
            print(curtime + ts) / ts
            curtime = bmiobj.get_current_time()
            print bmiobj.get_current_time() - lastcurtime
            lastcurtime = bmiobj.get_current_time()

        bmiobj.finalize()
        self.assertEquals(ett, bmiobj.get_current_time())
コード例 #6
0
    def testbmirun(self):
        bmiobj = bmi.wflowbmi_csdms()
        bmiobj.initialize('wflow_sceleton/wflow_sceleton.ini',loglevel=logging.ERROR)

        et = bmiobj.get_end_time()
        bmiobj.update_until(et)
        bmiobj.finalize()
コード例 #7
0
    def initialize_config(self, filename, loglevel=logging.DEBUG):
        """
        *Extended functionality*, see https://github.com/eWaterCycle/bmi/blob/master/src/main/python/bmi.py

        Read the ini file for the comnined bmi model and initializes all the bmi models
        listed in the config file.

        :param filename:
        :return: nothing
        """

        self.currenttimestep = 1

        fullpathname = os.path.abspath(filename)
        self.config = iniFileSetUp(fullpathname)
        self.datadir = os.path.dirname(fullpathname)
        inifile = os.path.basename(filename)

        self.models = configsection(self.config,'models')
        self.exchanges= configsection(self.config,'exchanges')

        for mod in self.models:
            self.bmimodels[mod] = wfbmi.wflowbmi_csdms()

        # Initialize all bmi model objects
        for key, value in self.bmimodels.iteritems():
            modconf = os.path.join(self.datadir,self.config.get('models',key))
            self.bmimodels[key].initialize_config(modconf,loglevel=loglevel)
コード例 #8
0
    def testbmirunnetcdf(self):
        bmiobj = bmi.wflowbmi_csdms()
        bmiobj.initialize_config('wflow_sbm/wflow_sbm_nc.ini',
                                 loglevel=logging.ERROR)
        #bmiobj.set_attribute_value('run:starttime','2014-05-01 01:00:00')
        #bmiobj.set_attribute_value('run:endtime','2014-05-17 00:00:00')
        #bmiobj.set_attribute_value('run:runlengthdetermination','steps')

        bmiobj.set_start_time(1399597200)
        bmiobj.set_end_time(1399597200 + (4 * 3600))

        st = bmiobj.get_start_time()
        ett = bmiobj.get_end_time()
        ts = bmiobj.get_time_step()

        bmiobj.initialize_model()
        tt = bmiobj.get_value('timestepsecs')
        curtime = st
        cnt = 0
        lastcurtime = bmiobj.get_current_time()
        while curtime < ett:
            avar = bmiobj.get_value('PET')
            bmiobj.set_value('PET', avar + 10.0)
            cnt = cnt + 1
            bmiobj.update_until(curtime + ts)
            print(curtime + ts) / ts
            curtime = bmiobj.get_current_time()
            print bmiobj.get_current_time() - lastcurtime
            lastcurtime = bmiobj.get_current_time()

        bmiobj.finalize()
コード例 #9
0
ファイル: TestBMI.py プロジェクト: Imme1992/wflow
    def testbmirunnetcdf(self):
        bmiobj = bmi.wflowbmi_csdms()
        bmiobj.initialize_config('wflow_sbm/wflow_sbm_nc.ini',loglevel=logging.DEBUG)
        #bmiobj.set_attribute_value('run:starttime','2014-05-01 01:00:00')
        #bmiobj.set_attribute_value('run:endtime','2014-05-17 00:00:00')
        #bmiobj.set_attribute_value('run:runlengthdetermination','steps')


        bmiobj.set_start_time(1399597200)
        bmiobj.set_end_time(1399597200 + (4 * 3600))

        st = bmiobj.get_start_time()
        ett = bmiobj.get_end_time()
        ts = bmiobj.get_time_step()

        bmiobj.initialize_model()
        tt = bmiobj.get_value('timestepsecs')
        curtime = st
        cnt = 0
        lastcurtime = bmiobj.get_current_time()
        while curtime < ett:
            avar = bmiobj.get_value('PET')
            bmiobj.set_value('PET',avar + 10.0)
            cnt = cnt + 1
            bmiobj.update_until(curtime + ts)
            print (curtime + ts)/ts
            curtime = bmiobj.get_current_time()
            print bmiobj.get_current_time() - lastcurtime
            lastcurtime = bmiobj.get_current_time()


        bmiobj.finalize()
コード例 #10
0
ファイル: Test_w3ra_BMI.py プロジェクト: edwinkost/wflow
    def testbmirunnetcdfw3ra(self):
        bmiobj = bmi.wflowbmi_csdms()
        bmiobj.initialize_config('../../examples/openstreams_w3ra_usa/wflow_w3ra.ini',loglevel=logging.ERROR)
        bmiobj.set_attribute_value('run:runlengthdetermination','intervals')

        stime= calendar.timegm(parser.parse("2014-05-13 00:00:00").utctimetuple())
        etime = calendar.timegm(parser.parse("2014-05-21 00:00:00").utctimetuple())
        bmiobj.set_start_time(stime)
        bmiobj.set_end_time(etime)
        st = bmiobj.get_start_time()
        #print st
        ett = bmiobj.get_end_time()
        ts = bmiobj.get_time_step()

        bmiobj.initialize_model()
        curtime = st
        cnt = 0
        lastcurtime = bmiobj.get_current_time()
        while curtime < ett:
            avar = bmiobj.get_value('LAI1')
            bmiobj.set_value('PRECIP',avar)
            cnt = cnt + 1
            bmiobj.update_until(curtime + ts)
            #print (curtime + ts)/ts
            curtime = bmiobj.get_current_time()
            #print bmiobj.get_current_time() - lastcurtime
            lastcurtime = bmiobj.get_current_time()


        bmiobj.finalize()
コード例 #11
0
ファイル: Test_w3ra_BMI.py プロジェクト: muguangyuze/wflow
    def testbmirunnetcdfw3ra(self):
        bmiobj = bmi.wflowbmi_csdms()
        bmiobj.initialize_config(
            '../../examples/openstreams_w3ra_usa/wflow_w3ra.ini',
            loglevel=logging.DEBUG)
        bmiobj.set_attribute_value('run:runlengthdetermination', 'intervals')

        stime = calendar.timegm(
            parser.parse("2014-05-13 00:00:00").utctimetuple())
        etime = calendar.timegm(
            parser.parse("2014-05-21 00:00:00").utctimetuple())
        bmiobj.set_start_time(stime)
        bmiobj.set_end_time(etime)
        st = bmiobj.get_start_time()
        print st
        ett = bmiobj.get_end_time()
        ts = bmiobj.get_time_step()

        bmiobj.initialize_model()
        curtime = st
        cnt = 0
        lastcurtime = bmiobj.get_current_time()
        while curtime < ett:
            avar = bmiobj.get_value('LAI1')
            bmiobj.set_value('PRECIP', avar)
            cnt = cnt + 1
            bmiobj.update_until(curtime + ts)
            print(curtime + ts) / ts
            curtime = bmiobj.get_current_time()
            print bmiobj.get_current_time() - lastcurtime
            lastcurtime = bmiobj.get_current_time()

        bmiobj.finalize()
コード例 #12
0
 def __init__(self, loglevel=logging.INFO, logger=None):
     # import original PCR bmi
     import wflow.wflow_bmi as _bmi
     self._bmi = _bmi.wflowbmi_csdms()
     if logger:
         self.logger = logger.getChild(self._name)
     else:
         self.logger = setlogger(None, self._name, thelevel=loglevel)
     self._loglevel = loglevel
     self.initialized = False
     self.grid = None
コード例 #13
0
ファイル: TestBMI.py プロジェクト: Imme1992/wflow
 def testbmirun(self):
     bmiobj = bmi.wflowbmi_csdms()
     bmiobj.initialize('wflow_sceleton/wflow_sceleton.ini',loglevel=logging.DEBUG)
     print(bmiobj.get_var_type("IF"))
     et = bmiobj.get_end_time()
     st = bmiobj.get_start_time()
     ts = 86400
     # Do one timestep and check
     bmiobj.get_current_time()
     bmiobj.update_until(et)
     bmiobj.finalize()
     self.assertEquals(et,bmiobj.get_current_time())
コード例 #14
0
 def testbmirun(self):
     bmiobj = bmi.wflowbmi_csdms()
     bmiobj.initialize('wflow_sceleton/wflow_sceleton.ini',
                       loglevel=logging.ERROR)
     print(bmiobj.get_var_type("IF"))
     et = bmiobj.get_end_time()
     st = bmiobj.get_start_time()
     ts = 86400
     # Do one timestep and check
     bmiobj.get_current_time()
     bmiobj.update_until(et)
     bmiobj.finalize()
     self.assertEquals(et, bmiobj.get_current_time())
コード例 #15
0
ファイル: test_BMI_Init.py プロジェクト: openstreams/wflow
    def testbmiinitfuncs(self):
        bmiobj = bmi.wflowbmi_csdms()

        bmiobj.initialize_config(
            "wflow_sceleton/wflow_sceleton_notime.ini", loglevel=logging.INFO
        )
        print("-------------- Time units: ")
        print((bmiobj.get_time_units()))
        print("-------------- Default current time: ")
        print((datetime.datetime.utcfromtimestamp(bmiobj.get_current_time())))
        print("-------------- Default start time: ")
        print((datetime.datetime.utcfromtimestamp(bmiobj.get_start_time())))
        print("-------------- Default end time: ")
        print((datetime.datetime.utcfromtimestamp(bmiobj.get_end_time())))
        print("-------------- Set start time to 5: ")
        bmiobj.set_start_time(5 * 86400)
        print("-------------- Set start time to 10: ")
        bmiobj.set_end_time(10 * 86400)

        print("-------------- Updated start time: ")
        stime = datetime.datetime.utcfromtimestamp(bmiobj.get_start_time())
        print("-------------- Updated end time: ")
        etime = datetime.datetime.utcfromtimestamp(bmiobj.get_end_time())

        print("Init model...")
        bmiobj.initialize_model()
        print((bmiobj.dynModel._userModel().config.get("run", "starttime")))

        nstime = datetime.datetime.utcfromtimestamp(bmiobj.get_start_time())

        netime = datetime.datetime.utcfromtimestamp(bmiobj.get_end_time())

        self.assertEqual(stime, nstime)
        self.assertEqual(etime, netime)
        print("-------------- Set start time to 5: ")
        bmiobj.set_start_time(5 * 86400)
        print("-------------- Get current time: ")
        print((datetime.datetime.utcfromtimestamp(bmiobj.get_current_time())))

        print("-------------- Get timestep: ")
        print((bmiobj.get_time_step()))
        print("-------------- get endtime: ")
        print((datetime.datetime.utcfromtimestamp(bmiobj.get_end_time())))
        print("-------------- set endtime: ")
        bmiobj.set_end_time(10.0 * 86400)
        print("-------------- get endtime: ")
        print((datetime.datetime.utcfromtimestamp(bmiobj.get_end_time())))

        print("-------------- get_var_units: ")
        print((bmiobj.get_var_units("SS")))
        bmiobj.finalize()
コード例 #16
0
    def testbmiinitfuncs(self):
        bmiobj = bmi.wflowbmi_csdms()

        bmiobj.initialize_config(
            "wflow_sceleton/wflow_sceleton_notime.ini", loglevel=logging.INFO
        )
        print("-------------- Time units: ")
        print(bmiobj.get_time_units())
        print("-------------- Default current time: ")
        print(datetime.datetime.utcfromtimestamp(bmiobj.get_current_time()))
        print("-------------- Default start time: ")
        print(datetime.datetime.utcfromtimestamp(bmiobj.get_start_time()))
        print("-------------- Default end time: ")
        print(datetime.datetime.utcfromtimestamp(bmiobj.get_end_time()))
        print("-------------- Set start time to 5: ")
        bmiobj.set_start_time(5 * 86400)
        print("-------------- Set start time to 10: ")
        bmiobj.set_end_time(10 * 86400)

        print("-------------- Updated start time: ")
        stime = datetime.datetime.utcfromtimestamp(bmiobj.get_start_time())
        print("-------------- Updated end time: ")
        etime = datetime.datetime.utcfromtimestamp(bmiobj.get_end_time())

        print("Init model...")
        bmiobj.initialize_model()
        print(bmiobj.dynModel._userModel().config.get("run", "starttime"))

        nstime = datetime.datetime.utcfromtimestamp(bmiobj.get_start_time())

        netime = datetime.datetime.utcfromtimestamp(bmiobj.get_end_time())

        self.assertEquals(stime, nstime)
        self.assertEquals(etime, netime)
        print("-------------- Set start time to 5: ")
        bmiobj.set_start_time(5 * 86400)
        print("-------------- Get current time: ")
        print(datetime.datetime.utcfromtimestamp(bmiobj.get_current_time()))

        print("-------------- Get timestep: ")
        print(bmiobj.get_time_step())
        print("-------------- get endtime: ")
        print(datetime.datetime.utcfromtimestamp(bmiobj.get_end_time()))
        print("-------------- set endtime: ")
        bmiobj.set_end_time(10.0 * 86400)
        print("-------------- get endtime: ")
        print(datetime.datetime.utcfromtimestamp(bmiobj.get_end_time()))

        print("-------------- get_var_units: ")
        print(bmiobj.get_var_units("SS"))
        bmiobj.finalize()
コード例 #17
0
ファイル: test_BMI.py プロジェクト: openstreams/wflow
    def testbmirun(self):
        bmiobj = bmi.wflowbmi_csdms()
        bmiobj.initialize("wflow_sceleton/wflow_sceleton.ini", loglevel=logging.DEBUG)
        bmiobj.set_attribute_value("run:runlengthdetermination", "intervals")
        print((bmiobj.get_var_type("IF")))
        et = bmiobj.get_end_time()
        st = bmiobj.get_start_time()
        ts = 86400
        # Do timesteps and chak

        bmiobj.update_until(et)
        bmiobj.get_current_time()
        bmiobj.finalize()
        print(et - bmiobj.get_current_time())
        self.assertEqual(et, bmiobj.get_current_time())
コード例 #18
0
ファイル: TestBMI.py プロジェクト: upnigs-egl/wflow
    def testbmirun(self):
        bmiobj = bmi.wflowbmi_csdms()
        bmiobj.initialize('wflow_sceleton/wflow_sceleton.ini',loglevel=logging.DEBUG)
        bmiobj.set_attribute_value('run:runlengthdetermination', 'intervals')
        print(bmiobj.get_var_type("IF"))
        et = bmiobj.get_end_time()
        st = bmiobj.get_start_time()
        ts = 86400
        # Do timesteps and chak

        bmiobj.update_until(et)
        bmiobj.get_current_time()
        bmiobj.finalize()
        print et - bmiobj.get_current_time()
        self.assertEquals(et,bmiobj.get_current_time())
コード例 #19
0
ファイル: TestBMI.py プロジェクト: upnigs-egl/wflow
    def testbmirun_hr(self):
        bmiobj = bmi.wflowbmi_csdms()
        bmiobj.initialize('wflow_sceleton/wflow_sceleton_hr.ini',loglevel=logging.DEBUG)

        print(bmiobj.get_var_type("IF"))
        et = bmiobj.get_end_time()
        st = bmiobj.get_start_time()
        ts = 3600
        # Do timesteps and chak

        bmiobj.update_until(et)
        bmiobj.get_current_time()
        bmiobj.finalize()
        print et - bmiobj.get_current_time()
        self.assertEquals(et,bmiobj.get_current_time())
コード例 #20
0
    def testbmiinitfuncs(self):
        bmiobj = bmi.wflowbmi_csdms()

        bmiobj.initialize_config('wflow_sceleton/wflow_sceleton.ini',
                                 loglevel=logging.ERROR)
        print("-------------- Time units: ")
        print(bmiobj.get_time_units())
        print("-------------- Default current time: ")
        print(datetime.datetime.utcfromtimestamp(bmiobj.get_current_time()))
        print("-------------- Default start time: ")
        print(datetime.datetime.utcfromtimestamp(bmiobj.get_start_time()))
        print("-------------- Default end time: ")
        print(datetime.datetime.utcfromtimestamp(bmiobj.get_end_time()))
        print("-------------- Set start time to 5: ")
        bmiobj.set_start_time(5 * 86400)
        print("-------------- Set start time to 10: ")
        bmiobj.set_end_time(10 * 86400)

        print("-------------- Updated start time: ")
        print(datetime.datetime.utcfromtimestamp(bmiobj.get_start_time()))
        print("-------------- Updated end time: ")
        print(datetime.datetime.utcfromtimestamp(bmiobj.get_end_time()))

        print("Init model...")
        bmiobj.initialize_model()
        print(bmiobj.dynModel._userModel().config.get("run", 'starttime'))
        print("-------------- Default start time: ")
        print(datetime.datetime.utcfromtimestamp(bmiobj.get_start_time()))
        print("-------------- Default end time: ")
        print(datetime.datetime.utcfromtimestamp(bmiobj.get_end_time()))

        print("-------------- Set start time to 5: ")
        bmiobj.set_start_time(5 * 86400)
        print("-------------- Get current time: ")
        print(datetime.datetime.utcfromtimestamp(bmiobj.get_current_time()))

        print("-------------- Get timestep: ")
        print(bmiobj.get_time_step())
        print("-------------- get endtime: ")
        print(datetime.datetime.utcfromtimestamp(bmiobj.get_end_time()))
        print("-------------- set endtime: ")
        bmiobj.set_end_time(10.0 * 86400)
        print("-------------- get endtime: ")
        print(datetime.datetime.utcfromtimestamp(bmiobj.get_end_time()))

        print("-------------- get_var_units: ")
        print(bmiobj.get_var_units("SS"))
        bmiobj.finalize()
コード例 #21
0
ファイル: TestBMI_Init.py プロジェクト: Imme1992/wflow
    def testbmiinitfuncs(self):
        bmiobj = bmi.wflowbmi_csdms()

        bmiobj.initialize_config('wflow_sceleton/wflow_sceleton.ini',loglevel=logging.ERROR)
        print("-------------- Time units: ")
        print(bmiobj.get_time_units())
        print("-------------- Default current time: ")
        print(datetime.datetime.utcfromtimestamp(bmiobj.get_current_time()))
        print("-------------- Default start time: ")
        print(datetime.datetime.utcfromtimestamp(bmiobj.get_start_time()))
        print("-------------- Default end time: ")
        print(datetime.datetime.utcfromtimestamp(bmiobj.get_end_time()))
        print("-------------- Set start time to 5: ")
        bmiobj.set_start_time(5 * 86400)
        print("-------------- Set start time to 10: ")
        bmiobj.set_end_time(10 * 86400)

        print("-------------- Updated start time: ")
        print(datetime.datetime.utcfromtimestamp(bmiobj.get_start_time()))
        print("-------------- Updated end time: ")
        print(datetime.datetime.utcfromtimestamp(bmiobj.get_end_time()))


        print("Init model...")
        bmiobj.initialize_model()
        print(bmiobj.dynModel._userModel().config.get("run",'starttime'))
        print("-------------- Default start time: ")
        print(datetime.datetime.utcfromtimestamp(bmiobj.get_start_time()))
        print("-------------- Default end time: ")
        print(datetime.datetime.utcfromtimestamp(bmiobj.get_end_time()))

        print("-------------- Set start time to 5: ")
        bmiobj.set_start_time(5 * 86400)
        print("-------------- Get current time: ")
        print(datetime.datetime.utcfromtimestamp(bmiobj.get_current_time()))

        print("-------------- Get timestep: ")
        print(bmiobj.get_time_step())
        print("-------------- get endtime: ")
        print(datetime.datetime.utcfromtimestamp(bmiobj.get_end_time()))
        print("-------------- set endtime: ")
        bmiobj.set_end_time(10.0 * 86400)
        print("-------------- get endtime: ")
        print(datetime.datetime.utcfromtimestamp(bmiobj.get_end_time()))

        print("-------------- get_var_units: ")
        print(bmiobj.get_var_units("SS"))
        bmiobj.finalize()
コード例 #22
0
    def testbmirunnetcdfw3ra(self):
        bmiobj = bmi.wflowbmi_csdms()
        bmiobj.initialize_config(
            "../../examples/openstreams_w3ra_usa/wflow_w3ra.ini",
            loglevel=logging.DEBUG)
        bmiobj.set_attribute_value("run:runlengthdetermination", "intervals")

        stime = calendar.timegm(
            parser.parse("2014-05-13 00:00:00").utctimetuple())
        etime = calendar.timegm(
            parser.parse("2014-05-21 00:00:00").utctimetuple())
        bmiobj.set_start_time(stime)
        bmiobj.set_end_time(etime)
        st = bmiobj.get_start_time()
        # print st
        ett = bmiobj.get_end_time()
        ts = bmiobj.get_time_step()

        bmiobj.initialize_model()
        curtime = bmiobj.get_current_time()
        cnt = 0
        lastcurtime = bmiobj.get_current_time()
        while curtime < ett:
            avar = bmiobj.get_value("LAI1")
            bmiobj.set_value("PRECIP", avar)
            cnt = cnt + 1
            bmiobj.update_until(curtime + ts)
            # print (curtime + ts)/ts
            curtime = bmiobj.get_current_time()
            # print bmiobj.get_current_time() - lastcurtime
            lastcurtime = bmiobj.get_current_time()

        bmiobj.finalize()
        # Check the values in a state file as a refrence. This is what the baselien model gives
        x, y, data, FillVal = wf.readMap(
            "../../examples/openstreams_w3ra_usa/run_default/outstate/Sd2.map",
            "PCRaster",
        )
        tmean = np.ma.masked_invalid(data.astype(np.float64)).mean()
        tmax = np.ma.masked_invalid(data.astype(np.float64)).max()
        tmin = np.ma.masked_invalid(data.astype(np.float64)).min()
        self.assertAlmostEquals(266.18075561523438, tmax)
        self.assertAlmostEquals(-7.8522729383405979e+37, tmean)
        self.assertAlmostEquals(-3.4028234663852886e+38, tmin)
コード例 #23
0
ファイル: test_w3ra_BMI.py プロジェクト: openstreams/wflow
    def testbmirunnetcdfw3ra(self):
        bmiobj = bmi.wflowbmi_csdms()
        bmiobj.initialize_config(
            "../examples/openstreams_w3ra_usa/wflow_w3ra.ini", loglevel=logging.DEBUG
        )
        bmiobj.set_attribute_value("run:runlengthdetermination", "intervals")

        stime = calendar.timegm(parser.parse("2014-05-13 00:00:00").utctimetuple())
        etime = calendar.timegm(parser.parse("2014-05-21 00:00:00").utctimetuple())
        bmiobj.set_start_time(stime)
        bmiobj.set_end_time(etime)
        st = bmiobj.get_start_time()
        # print st
        ett = bmiobj.get_end_time()
        ts = bmiobj.get_time_step()

        bmiobj.initialize_model()
        curtime = bmiobj.get_current_time()
        cnt = 0
        lastcurtime = bmiobj.get_current_time()
        while curtime < ett:
            avar = bmiobj.get_value("LAI1")
            bmiobj.set_value("PRECIP", avar)
            cnt = cnt + 1
            bmiobj.update_until(curtime + ts)
            # print (curtime + ts)/ts
            curtime = bmiobj.get_current_time()
            # print bmiobj.get_current_time() - lastcurtime
            lastcurtime = bmiobj.get_current_time()

        bmiobj.finalize()
        # Check the values in a state file as a refrence. This is what the baselien model gives
        x, y, data, FillVal = wf.readMap(
            "../examples/openstreams_w3ra_usa/run_default/outstate/Sd2.map",
            "PCRaster",
        )
        tmean = np.ma.masked_invalid(data.astype(np.float64)).mean()
        tmax = np.ma.masked_invalid(data.astype(np.float64)).max()
        tmin = np.ma.masked_invalid(data.astype(np.float64)).min()
        self.assertAlmostEqual(266.18075561523438, tmax)
        self.assertAlmostEqual(-7.8522729383405979e37, tmean)
        self.assertAlmostEqual(-3.4028234663852886e38, tmin)
コード例 #24
0
ファイル: TestBMI.py プロジェクト: andreybugaets/wflow
    def testbmifuncs(self):

        bmiobj = bmi.wflowbmi_csdms()
        bmiobj.initialize('wflow_sceleton/wflow_sceleton.ini',
                          loglevel=logging.ERROR)

        print("-------------- Grid origin: ")
        gorigin = bmiobj.get_grid_origin('Altitude')
        print(gorigin)
        self.assertAlmostEquals(sum([52.054268, 5.2271633]),
                                sum(gorigin),
                                places=4)

        print("-------------- Grid shape: ")
        print(bmiobj.get_grid_shape('Altitude'))
        self.assertAlmostEquals(sum([169L, 187L]),
                                sum(bmiobj.get_grid_shape('Altitude')),
                                places=4)

        print("-------------- Grid spacing: ")
        print(bmiobj.get_grid_spacing('Altitude'))

        print("-------------- Grid X: ")
        print(bmiobj.get_grid_x('Altitude'))

        print("-------------- Grid Y: ")
        print(bmiobj.get_grid_y('Altitude'))

        print("-------------- Grid Z: ")
        print(bmiobj.get_grid_z('Altitude'))

        print("-------------- Name: ")
        print(bmiobj.get_component_name())

        print("-------------- Input var names: ")
        print(bmiobj.get_input_var_names())

        print("-------------- UNit of var TEMP: ")
        print(bmiobj.get_var_units('TEMP'))

        print("-------------- UNit of var P: ")
        print(bmiobj.get_var_units('P'))

        print("-------------- Output var names: ")
        print(bmiobj.get_output_var_names())

        print("-------------- Time units: ")
        print(bmiobj.get_time_units())

        print("-------------- Time step: ")
        print(bmiobj.get_time_step())

        print("-------------- Start time: ")
        print(bmiobj.get_start_time())

        print("-------------- Current time: ")
        print(bmiobj.get_current_time())
        a = bmiobj.get_current_time()
        # print(time.localtime(bmiobj.get_current_time()))

        os.environ['TZ'] = 'Europe/London'

        print("-------------- Current time (set to london): ")
        print(bmiobj.get_current_time())
        b = bmiobj.get_current_time()

        self.assertAlmostEquals(a, b)

        print("-------------- update: ")
        bmiobj.update()

        print("-------------- Current time after update: ")
        print(bmiobj.get_current_time())
        print(time.localtime(bmiobj.get_current_time()))

        print("-------------- Start time: ")
        print(bmiobj.get_start_time())
        print(time.localtime(bmiobj.get_start_time()))

        print("-------------- End time: ")
        print(bmiobj.get_end_time())
        print(time.localtime(bmiobj.get_end_time()))

        print("-------------- Grid type: ")
        print(bmiobj.get_grid_type('Altitude'))

        print("-------------- Var type: ")
        print(bmiobj.get_var_type('Altitude'))

        print("-------------- Var rank: ")
        print(bmiobj.get_var_rank('Altitude'))

        print("-------------- Var size: ")
        print(bmiobj.get_var_size('Altitude'))

        print("-------------- Var nbytes: ")
        print(bmiobj.get_var_nbytes('Altitude'))

        print("-------------- Getvalue: ")
        print(bmiobj.get_value('Altitude'))

        print("-------------- Getvalue: ")
        print(bmiobj.get_value('timestepsecs'))

        print("-------------- get_attribute_names: ")
        names = bmiobj.get_attribute_names()
        print names
        self.assertEquals([
            'API:IF', 'API:InwaterMM', 'framework:outputformat',
            'framework:debug', 'framework:netcdfinput',
            'framework:netcdfstatesinput', 'framework:netcdfoutput',
            'framework:netcdfstaticoutput', 'framework:netcdfstatesoutput',
            'framework:netcdfstaticinput', 'framework:EPSG',
            'framework:netcdf_format', 'framework:netcdf_zlib',
            'framework:netcdf_least_significant_digit', 'run:starttime',
            'run:endtime', 'run:timestepsecs', 'run:reinit',
            'modelparameters:AltTemperature', 'layout:sizeinmetres',
            'outputmaps:self.TSoil', 'outputmaps:self.AltTemperature',
            'outputcsv_0:samplemap', 'outputcsv_0:self.TSoil',
            'outputcsv_0:self.AltTemperature', 'outputcsv_1:samplemap',
            'outputtss_0:samplemap', 'model:timestepsecs'
        ], names)

        print("-------------- get_attribute_value: ")
        print names[0]
        print(bmiobj.get_attribute_value(names[0]))

        print("-------------- set_attribute_value: ")
        print names[0]
        bmiobj.set_attribute_value(names[0], "SET By TEST")
        print(bmiobj.get_attribute_value(names[0]))
        self.assertEquals("SET By TEST", bmiobj.get_attribute_value(names[0]))

        print("-------------- set_start_time: ")
        bmiobj.set_start_time(0)
        print(bmiobj.get_attribute_value("run:starttime"))

        print("-------------- save the state:")
        bmiobj.save_state(".")
        self.assertTrue(os.path.exists("TSoil.map"))
        os.remove("TSoil.map")

        bmiobj.finalize()
コード例 #25
0
    def testbmifuncs(self):

        bmiobj = bmi.wflowbmi_csdms()
        bmiobj.initialize('wflow_sceleton/wflow_sceleton.ini',loglevel=logging.ERROR)

        print("-------------- Grid origin: ")
        gorigin = bmiobj.get_grid_origin('Altitude')
        print(gorigin)

        print("-------------- Grid X: ")
        print(bmiobj.get_grid_x('Altitude'))

        print("-------------- Grid Y: ")
        print(bmiobj.get_grid_y('Altitude'))

        print("-------------- Grid Z: ")
        print(bmiobj.get_grid_z('Altitude'))

        print("-------------- Name: ")
        print(bmiobj.get_component_name())

        print("-------------- Input var names: ")
        print(bmiobj.get_input_var_names())

        print("-------------- UNit of var TEMP: ")
        print(bmiobj.get_var_units('TEMP'))

        print("-------------- UNit of var P: ")
        print(bmiobj.get_var_units('P'))

        print("-------------- Output var names: ")
        print(bmiobj.get_output_var_names())

        print("-------------- Time units: ")
        print(bmiobj.get_time_units())

        print("-------------- Time step: ")
        print(bmiobj.get_time_step())

        print("-------------- Start time: ")
        print(bmiobj.get_start_time())

        print("-------------- Current time: ")
        print(bmiobj.get_current_time())
        a= bmiobj.get_current_time()
        #print(time.localtime(bmiobj.get_current_time()))

        os.environ['TZ'] = 'Europe/London'

        print("-------------- Current time (set to london): ")
        print(bmiobj.get_current_time())
        b = bmiobj.get_current_time()

        self.assertAlmostEquals(a,b)


        #print(time.localtime(bmiobj.get_current_time()))

        print("-------------- update: ")
        bmiobj.update()

        print("-------------- Current time after update: ")
        print(bmiobj.get_current_time())
        print(time.localtime(bmiobj.get_current_time()))

        print("-------------- Start time: ")
        print(bmiobj.get_start_time())
        print(time.localtime(bmiobj.get_start_time()))

        print("-------------- End time: ")
        print(bmiobj.get_end_time())
        print(time.localtime(bmiobj.get_end_time()))

        print("-------------- Grid shape: ")
        print(bmiobj.get_grid_shape('Altitude'))


        print("-------------- Grid spacing: ")
        print(bmiobj.get_grid_spacing('Altitude'))

        print("-------------- Grid type: ")
        print(bmiobj.get_grid_type('Altitude'))

        print("-------------- Var type: ")
        print(bmiobj.get_var_type('Altitude'))



        print("-------------- Var rank: ")
        print(bmiobj.get_var_rank('Altitude'))

        print("-------------- Var size: ")
        print(bmiobj.get_var_size('Altitude'))

        print("-------------- Var nbytes: ")
        print(bmiobj.get_var_nbytes('Altitude'))

        print("-------------- Getvalue: ")
        print(bmiobj.get_value('Altitude'))

        bmiobj.finalize()
コード例 #26
0
ファイル: wflow_bmi_combined.py プロジェクト: Macowe/wflow
    def initialize_config(self, filename, loglevel=logging.DEBUG):
        """
        *Extended functionality*, see https://github.com/eWaterCycle/bmi/blob/master/src/main/python/bmi.py

        Read the ini file for the comnined bmi model and initializes all the bmi models
        listed in the config file.

        :param filename:
        :return: nothing
        """

        self.currenttimestep = 1

        fullpathname = os.path.abspath(filename)
        self.config = iniFileSetUp(fullpathname)
        self.datadir = os.path.dirname(fullpathname)
        inifile = os.path.basename(filename)

        self.models = configsection(self.config, 'models')
        self.exchanges = configsection(self.config, 'exchanges')

        for item in self.exchanges:
            exchange_from = item.split(self.comp_sep)

            if len(exchange_from) == 3:
                if exchange_from[2].startswith('['):
                    ind = json.loads(exchange_from[2])
                else:
                    ind_temp = np.loadtxt(exchange_from[2],
                                          delimiter=',',
                                          dtype=int)
                    if ind_temp.size == 2:
                        ind = [[ind_temp[0]], [ind_temp[1]]]
                    else:
                        ind = [list(ind_temp[0]), list(ind_temp[1])]
                self.indices_from.append(ind)
            else:
                self.indices_from.append([])

            exchange_to = self.config.get('exchanges',
                                          item).split(self.comp_sep)

            if len(exchange_to) == 3:
                if exchange_to[2].startswith('['):
                    ind = json.loads(exchange_to[2])
                else:
                    ind_temp = np.loadtxt(exchange_to[2],
                                          delimiter=',',
                                          dtype=int)
                    if ind_temp.size == 2:
                        ind = [[ind_temp[0]], [ind_temp[1]]]
                    else:
                        ind = [list(ind_temp[0]), list(ind_temp[1])]
                self.indices_from.append(ind)
            else:
                self.indices_to.append([])

        # Initialize rtc bmi model object
        for mod in self.models:
            if mod.startswith('RTC'):
                bin_rtc = os.path.join(
                    self.datadir,
                    self.config.get('RTC wrapper engine', 'bin_rtc'))
                print bin_rtc
                os.chdir(bin_rtc)
                import rtc_wflow_bmi as rtcwfbmi
                print bin_rtc
                self.bmimodels[mod] = rtcwfbmi.rtcbmi_csdms(
                    os.path.join(bin_rtc, "RTCTools_BMI"))

            else:
                self.bmimodels[mod] = wfbmi.wflowbmi_csdms()

        # Initialize all wflow bmi model objects
        for key, value in self.bmimodels.iteritems():
            if key.startswith('wflow'):
                modconf = os.path.join(self.datadir,
                                       self.config.get('models', key))
                self.bmimodels[key].initialize_config(modconf,
                                                      loglevel=loglevel)
コード例 #27
0
ファイル: wflow_sbm_rtc.py プロジェクト: openstreams/wflow
########################################################################

# In[]: Initialize the RTC-Tools model
os.chdir(Bin_RTC)

from wflow.wrappers.rtc.wrapperExtended import BMIWrapperExtended

# RTC_model = BMIWrapperExtended(engine=os.path.join(Bin_RTC,"RTCTools_BMI"))
RTC_model = BMIWrapperExtended(engine=os.path.join(Bin_RTC, "RTCTools_BMI"))
print("RTCmodel", Bin_RTC, RTC_model)
RTC_model.initialize("..")


# In[]: Initialize the WFlow model
os.chdir(dir_wflow)
LA_model = bmi.wflowbmi_csdms()
LA_model.initialize((IniFile), loglevel=logging.DEBUG)

# now get the forcings that wflow expects
# The bmi is such that you can get the input variables and the output variables. However, the
# input variable list also contains the in/out variables. So to
# get the input only we subtract the two lists.
invars = LA_model.get_input_var_names()
outvars = LA_model.get_output_var_names()
inputmstacks = list(set(invars) - set(outvars))


# In[]: Investigate start time, end time and time step of both models

print("WFlow:")
LA_dt = LA_model.get_time_step()
コード例 #28
0
    def initialize_config(self, filename, loglevel=logging.DEBUG):
        """
        *Extended functionality*, see https://github.com/eWaterCycle/bmi/blob/master/src/main/python/bmi.py

        Read the ini file for the comnined bmi model and initializes all the bmi models
        listed in the config file.

        :param filename:
        :return: nothing
        """

        self.currenttimestep = 1

        fullpathname = os.path.abspath(filename)
        self.config = iniFileSetUp(fullpathname)
        self.datadir = os.path.dirname(fullpathname)
        inifile = os.path.basename(filename)

        # mappingdir = self.datadir + '\\bmi_mapping\\'
        mappingdir = (os.path.join(
            self.datadir,
            wfbmi.configget(self.config, "IdMapping", "folder",
                            "bmi_mapping")[0],
        ) + "\\")

        self.models = configsection(self.config, "models")
        self.exchanges = configsection(self.config, "exchanges")

        for item in self.exchanges:
            exchange_from = item.split(self.comp_sep)

            if len(exchange_from) == 3:
                if exchange_from[2].startswith("["):
                    ind = json.loads(mappingdir + exchange_from[2])
                elif exchange_from[2].endswith("id"):
                    ind_temp = np.loadtxt(mappingdir + exchange_from[2],
                                          delimiter=",",
                                          dtype=int)
                    if ind_temp.size == 2:
                        ind = [[ind_temp[0]], [ind_temp[1]]]
                    else:
                        ind = [list(ind_temp[0]), list(ind_temp[1])]
                elif exchange_from[2].endswith("map"):
                    map_temp = pcr.readmap(mappingdir + exchange_from[2])
                    map_flip = np.flipud(pcr.pcr2numpy(map_temp, 0))
                    ind_temp = np.where(map_flip == 1)
                    ind = [list(ind_temp[0]), list(ind_temp[1])]
                self.indices_from.append(ind)
            else:
                self.indices_from.append([])

            exchange_to = self.config.get("exchanges",
                                          item).split(self.comp_sep)

            if len(exchange_to) == 3:
                if exchange_to[2].startswith("["):
                    ind = json.loads(mappingdir + exchange_to[2])
                elif exchange_to[2].endswith("id"):
                    ind_temp = np.loadtxt(mappingdir + exchange_to[2],
                                          delimiter=",",
                                          dtype=int)
                    if ind_temp.size == 2:
                        ind = [[ind_temp[0]], [ind_temp[1]]]
                    else:
                        ind = [list(ind_temp[0]), list(ind_temp[1])]
                elif exchange_to[2].endswith("map"):
                    map_temp = pcr.readmap(mappingdir + exchange_to[2])
                    map_flip = np.flipud(pcr.pcr2numpy(map_temp, 0))
                    ind_temp = np.where(map_flip == 1)
                    ind = [list(ind_temp[0]), list(ind_temp[1])]
                self.indices_to.append(ind)
            else:
                self.indices_to.append([])

        # Initialize rtc bmi model object
        for mod in self.models:
            if mod.startswith("RTC"):
                bin_rtc = os.path.join(
                    self.datadir,
                    self.config.get("RTC wrapper engine", "bin_rtc"))
                print(bin_rtc)
                os.chdir(bin_rtc)
                import wflow.rtc_wflow_bmi as rtcwfbmi

                print(bin_rtc)
                self.bmimodels[mod] = rtcwfbmi.rtcbmi_csdms(
                    os.path.join(bin_rtc, "RTCTools_BMI"))

            else:
                self.bmimodels[mod] = wfbmi.wflowbmi_csdms()

        # Initialize all wflow bmi model objects
        for key, value in self.bmimodels.items():
            if key.startswith("wflow"):
                modconf = os.path.join(self.datadir,
                                       self.config.get("models", key))
                self.bmimodels[key].initialize_config(modconf,
                                                      loglevel=loglevel)
コード例 #29
0
    def testbmifuncs(self):

        bmiobj = bmi.wflowbmi_csdms()
        bmiobj.initialize('wflow_sceleton/wflow_sceleton.ini',
                          loglevel=logging.ERROR)

        print("-------------- Grid origin: ")
        gorigin = bmiobj.get_grid_origin('Altitude')
        #print(gorigin)
        self.assertAlmostEquals(sum([45.875934703275561, 5.2088299822062254]),
                                sum(gorigin),
                                places=4)

        print("-------------- Grid shape: ")
        print(bmiobj.get_grid_shape('Altitude'))
        self.assertAlmostEquals(sum([169L, 187L]),
                                sum(bmiobj.get_grid_shape('Altitude')),
                                places=4)

        print("-------------- Grid spacing: ")
        print(bmiobj.get_grid_spacing('Altitude'))

        print("-------------- Grid X: ")
        print(bmiobj.get_grid_x('Altitude'))

        print("-------------- Grid Y: ")
        print(bmiobj.get_grid_y('Altitude'))

        print("-------------- Grid Z: ")
        print(bmiobj.get_grid_z('Altitude'))

        print("-------------- Name: ")
        print(bmiobj.get_component_name())

        print("-------------- Input var names: ")
        print(bmiobj.get_input_var_names())

        print("-------------- UNit of var TEMP: ")
        print(bmiobj.get_var_units('TEMP'))

        print("-------------- UNit of var P: ")
        print(bmiobj.get_var_units('P'))

        print("-------------- Output var names: ")
        print(bmiobj.get_output_var_names())

        print("-------------- Time units: ")
        print(bmiobj.get_time_units())

        print("-------------- Time step: ")
        print(bmiobj.get_time_step())

        print("-------------- Start time: ")
        print(bmiobj.get_start_time())

        print("-------------- Current time: ")
        print(bmiobj.get_current_time())
        a = bmiobj.get_current_time()
        # print(time.localtime(bmiobj.get_current_time()))

        os.environ['TZ'] = 'Europe/London'

        print("-------------- Current time (set to london): ")
        print(bmiobj.get_current_time())
        b = bmiobj.get_current_time()

        self.assertAlmostEquals(a, b)

        print("-------------- update: ")
        bmiobj.update()

        print("-------------- Current time after update: ")
        print(bmiobj.get_current_time())
        print(time.localtime(bmiobj.get_current_time()))

        print("-------------- Start time: ")
        print(bmiobj.get_start_time())
        print(time.localtime(bmiobj.get_start_time()))

        print("-------------- End time: ")
        print(bmiobj.get_end_time())
        print(time.localtime(bmiobj.get_end_time()))

        print("-------------- Grid type: ")
        print(bmiobj.get_grid_type('Altitude'))

        print("-------------- Var type: ")
        print(bmiobj.get_var_type('Altitude'))

        print("-------------- Var rank: ")
        print(bmiobj.get_var_rank('Altitude'))

        print("-------------- Var size: ")
        print(bmiobj.get_var_size('Altitude'))

        print("-------------- Var nbytes: ")
        print(bmiobj.get_var_nbytes('Altitude'))

        print("-------------- Getvalue: ")
        print(bmiobj.get_value('Altitude'))

        print("-------------- Getvalue: ")
        print(bmiobj.get_value('timestepsecs'))

        print("-------------- get_attribute_names: ")
        names = bmiobj.get_attribute_names()
        print names

        print("-------------- get_attribute_value: ")
        print names[0]
        print(bmiobj.get_attribute_value(names[0]))

        print("-------------- set_attribute_value: ")
        print names[0]
        bmiobj.set_attribute_value(names[0], "SET By TEST")
        print(bmiobj.get_attribute_value(names[0]))
        self.assertEquals("SET By TEST", bmiobj.get_attribute_value(names[0]))

        print("-------------- set_start_time: ")
        bmiobj.set_start_time(0)
        print(bmiobj.get_attribute_value("run:starttime"))

        print("-------------- save the state:")
        bmiobj.save_state(".")
        self.assertTrue(os.path.exists("TSoil.map"))
        os.remove("TSoil.map")

        bmiobj.finalize()
コード例 #30
0
ファイル: test_BMI.py プロジェクト: openstreams/wflow
    def testbmifuncs(self):

        bmiobj = bmi.wflowbmi_csdms()
        bmiobj.initialize("wflow_sceleton/wflow_sceleton.ini", loglevel=logging.ERROR)

        print("-------------- Grid origin: ")
        gorigin = bmiobj.get_grid_origin("Altitude")
        # print(gorigin)
        self.assertAlmostEqual(
            sum([45.875934703275561, 5.2088299822062254]), sum(gorigin), places=4
        )

        print("-------------- Grid shape: ")
        print((bmiobj.get_grid_shape("Altitude")))
        self.assertAlmostEqual(
            sum([169, 187]), sum(bmiobj.get_grid_shape("Altitude")), places=4
        )

        print("-------------- Grid spacing: ")
        print((bmiobj.get_grid_spacing("Altitude")))
        self.assertAlmostEqual(
            sum([0.036666665, 0.036666665]),
            sum(bmiobj.get_grid_spacing("Altitude")),
            places=4,
        )

        print("-------------- Grid X: ")
        print((bmiobj.get_grid_x("Altitude")))
        self.assertAlmostEqual(
            5.22716331, bmiobj.get_grid_x("Altitude")[0, 0], places=4
        )

        print("-------------- Grid Y: ")
        print((bmiobj.get_grid_y("Altitude")))
        self.assertAlmostEqual(
            45.89426804, bmiobj.get_grid_y("Altitude")[0, 0], places=4
        )

        print("-------------- Grid Z: ")
        print((bmiobj.get_grid_z("Altitude")))
        self.assertAlmostEqual(
            218.44944763, bmiobj.get_grid_z("Altitude")[0, 0], places=4
        )

        print("-------------- Name: ")
        print((bmiobj.get_component_name()))
        self.assertEqual("wflow_sceleton", bmiobj.get_component_name())

        print("-------------- Input var names: ")
        print((bmiobj.get_input_var_names()))

        print("-------------- UNit of var TEMP: ")
        print((bmiobj.get_var_units("TEMP")))

        print("-------------- UNit of var P: ")
        print((bmiobj.get_var_units("P")))

        print("-------------- Output var names: ")
        print((bmiobj.get_output_var_names()))

        print("-------------- Time units: ")
        print((bmiobj.get_time_units()))

        print("-------------- Time step: ")
        print((bmiobj.get_time_step()))

        print("-------------- Start time: ")
        print((bmiobj.get_start_time()))

        print("-------------- Current time: ")
        print((bmiobj.get_current_time()))
        a = bmiobj.get_current_time()
        # print(time.localtime(bmiobj.get_current_time()))

        os.environ["TZ"] = "Europe/London"

        print("-------------- Current time (set to london): ")
        print((bmiobj.get_current_time()))
        b = bmiobj.get_current_time()

        self.assertAlmostEqual(a, b)

        print ("-------------- update: ")
        bmiobj.update()

        print("-------------- Current time after update: ")
        print((bmiobj.get_current_time()))
        print((time.localtime(bmiobj.get_current_time())))

        print("-------------- Start time: ")
        print((bmiobj.get_start_time()))
        print((time.localtime(bmiobj.get_start_time())))

        print("-------------- End time: ")
        print((bmiobj.get_end_time()))
        print((time.localtime(bmiobj.get_end_time())))

        print("-------------- Grid type: ")
        print((bmiobj.get_grid_type("Altitude")))

        print("-------------- Var type: ")
        print((bmiobj.get_var_type("Altitude")))

        print("-------------- Var rank: ")
        print((bmiobj.get_var_rank("Altitude")))

        print("-------------- Var size: ")
        print((bmiobj.get_var_size("Altitude")))

        print("-------------- Var nbytes: ")
        print((bmiobj.get_var_nbytes("Altitude")))

        print("-------------- Getvalue: ")
        print((bmiobj.get_value("Altitude")))

        print("-------------- Getvalue: ")
        print((bmiobj.get_value("timestepsecs")))

        print ("-------------- get_attribute_names: ")
        names = bmiobj.get_attribute_names()
        print(names)

        print("-------------- get_attribute_value: ")
        print(names[0])
        print((bmiobj.get_attribute_value(names[0])))

        print("-------------- set_attribute_value: ")
        print(names[0])
        bmiobj.set_attribute_value(names[0], "SET By TEST")
        print((bmiobj.get_attribute_value(names[0])))
        self.assertEqual("SET By TEST", bmiobj.get_attribute_value(names[0]))

        print ("-------------- set_start_time: ")
        bmiobj.set_start_time(0)
        print((bmiobj.get_attribute_value("run:starttime")))

        print ("-------------- save the state:")
        bmiobj.save_state(".")
        self.assertTrue(os.path.exists("TSoil.map"))
        os.remove("TSoil.map")

        bmiobj.finalize()
コード例 #31
0
ファイル: TestBMI.py プロジェクト: charlibrown33/wflow
    def testbmifuncs(self):

        bmiobj = bmi.wflowbmi_csdms()
        bmiobj.initialize('wflow_sceleton/wflow_sceleton.ini',loglevel=logging.ERROR)

        print("-------------- Grid origin: ")
        gorigin = bmiobj.get_grid_origin('Altitude')
        print(gorigin)

        print("-------------- Grid X: ")
        print(bmiobj.get_grid_x('Altitude'))

        print("-------------- Grid Y: ")
        print(bmiobj.get_grid_y('Altitude'))

        print("-------------- Grid Z: ")
        print(bmiobj.get_grid_z('Altitude'))

        print("-------------- Name: ")
        print(bmiobj.get_component_name())

        print("-------------- Input var names: ")
        print(bmiobj.get_input_var_names())

        print("-------------- UNit of var TEMP: ")
        print(bmiobj.get_var_units('TEMP'))

        print("-------------- UNit of var P: ")
        print(bmiobj.get_var_units('P'))

        print("-------------- Output var names: ")
        print(bmiobj.get_output_var_names())

        print("-------------- Time units: ")
        print(bmiobj.get_time_units())

        print("-------------- Time step: ")
        print(bmiobj.get_time_step())

        print("-------------- Start time: ")
        print(bmiobj.get_start_time())

        print("-------------- Current time: ")
        print(bmiobj.get_current_time())
        a= bmiobj.get_current_time()
        #print(time.localtime(bmiobj.get_current_time()))

        os.environ['TZ'] = 'Europe/London'

        print("-------------- Current time (set to london): ")
        print(bmiobj.get_current_time())
        b = bmiobj.get_current_time()

        self.assertAlmostEquals(a,b)

        print("-------------- update: ")
        bmiobj.update()

        print("-------------- Current time after update: ")
        print(bmiobj.get_current_time())
        print(time.localtime(bmiobj.get_current_time()))

        print("-------------- Start time: ")
        print(bmiobj.get_start_time())
        print(time.localtime(bmiobj.get_start_time()))

        print("-------------- End time: ")
        print(bmiobj.get_end_time())
        print(time.localtime(bmiobj.get_end_time()))

        print("-------------- Grid shape: ")
        print(bmiobj.get_grid_shape('Altitude'))

        print("-------------- Grid spacing: ")
        print(bmiobj.get_grid_spacing('Altitude'))

        print("-------------- Grid type: ")
        print(bmiobj.get_grid_type('Altitude'))

        print("-------------- Var type: ")
        print(bmiobj.get_var_type('Altitude'))

        print("-------------- Var rank: ")
        print(bmiobj.get_var_rank('Altitude'))

        print("-------------- Var size: ")
        print(bmiobj.get_var_size('Altitude'))

        print("-------------- Var nbytes: ")
        print(bmiobj.get_var_nbytes('Altitude'))

        print("-------------- Getvalue: ")
        print(bmiobj.get_value('Altitude'))

        print("-------------- get_attribute_names: ")
        names = bmiobj.get_attribute_names()
        print names

        print("-------------- get_attribute_value: ")
        print names[0]
        print(bmiobj.get_attribute_value(names[0]))

        print("-------------- set_attribute_value: ")
        print names[0]
        bmiobj.set_attribute_value(names[0],"SET By TEST")
        print(bmiobj.get_attribute_value(names[0]))

        print("-------------- set_start_time: ")
        bmiobj.set_start_time(0)
        print(bmiobj.get_attribute_value("run:starttime"))

        print("-------------- save the state:")
        bmiobj.save_state(".")
        self.assertTrue(os.path.exists("TSoil.map"))
        os.remove("TSoil.map")

        bmiobj.finalize()
コード例 #32
0
ファイル: wflow_bmi_combined.py プロジェクト: edwinkost/wflow
    def initialize_config(self, filename, loglevel=logging.DEBUG):
        """
        *Extended functionality*, see https://github.com/eWaterCycle/bmi/blob/master/src/main/python/bmi.py

        Read the ini file for the comnined bmi model and initializes all the bmi models
        listed in the config file.

        :param filename:
        :return: nothing
        """

        self.currenttimestep = 1

        fullpathname = os.path.abspath(filename)
        self.config = iniFileSetUp(fullpathname)
        self.datadir = os.path.dirname(fullpathname)
        inifile = os.path.basename(filename)

        self.models = configsection(self.config,'models')
        self.exchanges= configsection(self.config,'exchanges')
        
        for item in self.exchanges:
            exchange_from = item.split(self.comp_sep)

            if len(exchange_from)==3:
                if exchange_from[2].startswith('['):
                    ind = json.loads(exchange_from[2])
                else:
                    ind_temp = np.loadtxt(exchange_from[2],delimiter=',',dtype=int)
                    if ind_temp.size == 2:
                        ind = [[ind_temp[0]],[ind_temp[1]]]
                    else:
                        ind = [list(ind_temp[0]),list(ind_temp[1])]
                self.indices_from.append(ind)
            else:
                self.indices_from.append([])
            
            exchange_to = self.config.get('exchanges',item).split(self.comp_sep)
            
            if len(exchange_to)==3:
                if exchange_to[2].startswith('['):
                    ind = json.loads(exchange_to[2])
                else:
                    ind_temp = np.loadtxt(exchange_to[2],delimiter=',',dtype=int)
                    if ind_temp.size == 2:
                        ind = [[ind_temp[0]],[ind_temp[1]]]
                    else:
                        ind = [list(ind_temp[0]),list(ind_temp[1])]
                self.indices_from.append(ind)
            else:
                self.indices_to.append([])
                
            
            
        # Initialize rtc bmi model object
        for mod in self.models:
            if mod.startswith('RTC'):
                bin_rtc = os.path.join(self.datadir,self.config.get('RTC wrapper engine','bin_rtc'))
                print bin_rtc
                os.chdir(bin_rtc)
                import rtc_wflow_bmi as rtcwfbmi
                print bin_rtc
                self.bmimodels[mod] = rtcwfbmi.rtcbmi_csdms(os.path.join(bin_rtc,"RTCTools_BMI"))
            
            else:
                self.bmimodels[mod] = wfbmi.wflowbmi_csdms()
        
            

        # Initialize all wflow bmi model objects
        for key, value in self.bmimodels.iteritems():
            if key.startswith('wflow'):
                modconf = os.path.join(self.datadir,self.config.get('models',key))
                self.bmimodels[key].initialize_config(modconf,loglevel=loglevel)
コード例 #33
0
    def initialize_config(self, filename, loglevel=logging.DEBUG):
        """
        *Extended functionality*, see https://github.com/eWaterCycle/bmi/blob/master/src/main/python/bmi.py

        Read the ini file for the comnined bmi model and initializes all the bmi models
        listed in the config file.

        :param filename:
        :return: nothing
        """

        self.currenttimestep = 1

        fullpathname = os.path.abspath(filename)
        self.config = iniFileSetUp(fullpathname)
        self.datadir = os.path.dirname(fullpathname)
        inifile = os.path.basename(filename)

        # mappingdir = self.datadir + '\\bmi_mapping\\'
        mappingdir = (
            os.path.join(
                self.datadir,
                wfbmi.configget(self.config, "IdMapping", "folder", "bmi_mapping")[0],
            )
            + "\\"
        )

        self.models = configsection(self.config, "models")
        self.exchanges = configsection(self.config, "exchanges")

        for item in self.exchanges:
            exchange_from = item.split(self.comp_sep)

            if len(exchange_from) == 3:
                if exchange_from[2].startswith("["):
                    ind = json.loads(mappingdir + exchange_from[2])
                elif exchange_from[2].endswith("id"):
                    ind_temp = np.loadtxt(
                        mappingdir + exchange_from[2], delimiter=",", dtype=int
                    )
                    if ind_temp.size == 2:
                        ind = [[ind_temp[0]], [ind_temp[1]]]
                    else:
                        ind = [list(ind_temp[0]), list(ind_temp[1])]
                elif exchange_from[2].endswith("map"):
                    map_temp = pcr.readmap(mappingdir + exchange_from[2])
                    map_flip = np.flipud(pcr.pcr2numpy(map_temp, 0))
                    ind_temp = np.where(map_flip == 1)
                    ind = [list(ind_temp[0]), list(ind_temp[1])]
                self.indices_from.append(ind)
            else:
                self.indices_from.append([])

            exchange_to = self.config.get("exchanges", item).split(self.comp_sep)

            if len(exchange_to) == 3:
                if exchange_to[2].startswith("["):
                    ind = json.loads(mappingdir + exchange_to[2])
                elif exchange_to[2].endswith("id"):
                    ind_temp = np.loadtxt(
                        mappingdir + exchange_to[2], delimiter=",", dtype=int
                    )
                    if ind_temp.size == 2:
                        ind = [[ind_temp[0]], [ind_temp[1]]]
                    else:
                        ind = [list(ind_temp[0]), list(ind_temp[1])]
                elif exchange_to[2].endswith("map"):
                    map_temp = pcr.readmap(mappingdir + exchange_to[2])
                    map_flip = np.flipud(pcr.pcr2numpy(map_temp, 0))
                    ind_temp = np.where(map_flip == 1)
                    ind = [list(ind_temp[0]), list(ind_temp[1])]
                self.indices_to.append(ind)
            else:
                self.indices_to.append([])

        # Initialize rtc bmi model object
        for mod in self.models:
            if mod.startswith("RTC"):
                bin_rtc = os.path.join(
                    self.datadir, self.config.get("RTC wrapper engine", "bin_rtc")
                )
                print(bin_rtc)
                os.chdir(bin_rtc)
                import wflow.rtc_wflow_bmi as rtcwfbmi

                print(bin_rtc)
                self.bmimodels[mod] = rtcwfbmi.rtcbmi_csdms(
                    os.path.join(bin_rtc, "RTCTools_BMI")
                )

            else:
                self.bmimodels[mod] = wfbmi.wflowbmi_csdms()

        # Initialize all wflow bmi model objects
        for key, value in self.bmimodels.items():
            if key.startswith("wflow"):
                modconf = os.path.join(self.datadir, self.config.get("models", key))
                self.bmimodels[key].initialize_config(modconf, loglevel=loglevel)
コード例 #34
0
ファイル: test_BMI.py プロジェクト: teije01/wflow
    def testbmifuncs(self):
        grid_id = 1

        bmiobj = bmi.wflowbmi_csdms()
        bmiobj.initialize("wflow_sceleton/wflow_sceleton.ini",
                          loglevel=logging.ERROR)

        print("-------------- Grid origin: ")
        gorigin = bmiobj.get_grid_origin(grid_id)
        # print(gorigin)
        self.assertAlmostEqual(sum([45.875934703275561, 5.2088299822062254]),
                               sum(gorigin),
                               places=4)

        print("-------------- Grid shape: ")
        print((bmiobj.get_grid_shape(grid_id)))
        self.assertAlmostEqual(sum([169, 187]),
                               sum(bmiobj.get_grid_shape(grid_id)),
                               places=4)

        print("-------------- Grid spacing: ")
        print((bmiobj.get_grid_spacing(grid_id)))
        self.assertAlmostEqual(
            sum([0.036666665, 0.036666665]),
            sum(bmiobj.get_grid_spacing(grid_id)),
            places=4,
        )

        print("-------------- Grid X: ")
        print((bmiobj.get_grid_x(grid_id)))
        self.assertAlmostEqual(5.22716331,
                               bmiobj.get_grid_x(grid_id)[0],
                               places=4)

        print("-------------- Grid Y: ")
        print((bmiobj.get_grid_y(grid_id)))
        self.assertAlmostEqual(45.89426804,
                               bmiobj.get_grid_y(grid_id)[0],
                               places=4)

        print("-------------- Grid Z: ")
        print((bmiobj.get_grid_z(grid_id)))
        self.assertAlmostEqual(218.44944763,
                               bmiobj.get_grid_z(grid_id)[0, 0],
                               places=4)

        print("-------------- Name: ")
        print((bmiobj.get_component_name()))
        self.assertEqual("wflow_sceleton", bmiobj.get_component_name())

        print("-------------- Input var names: ")
        print((bmiobj.get_input_var_names()))

        print("-------------- UNit of var TEMP: ")
        print((bmiobj.get_var_units("TEMP")))

        print("-------------- UNit of var P: ")
        print((bmiobj.get_var_units("P")))

        print("-------------- Output var names: ")
        print((bmiobj.get_output_var_names()))

        print("-------------- Time units: ")
        print((bmiobj.get_time_units()))

        print("-------------- Time step: ")
        print((bmiobj.get_time_step()))

        print("-------------- Start time: ")
        print((bmiobj.get_start_time()))

        print("-------------- Current time: ")
        print((bmiobj.get_current_time()))
        a = bmiobj.get_current_time()
        # print(time.localtime(bmiobj.get_current_time()))

        os.environ["TZ"] = "Europe/London"

        print("-------------- Current time (set to london): ")
        print((bmiobj.get_current_time()))
        b = bmiobj.get_current_time()

        self.assertAlmostEqual(a, b)

        print("-------------- update: ")
        bmiobj.update()

        print("-------------- Current time after update: ")
        print((bmiobj.get_current_time()))
        print((time.localtime(bmiobj.get_current_time())))

        print("-------------- Start time: ")
        print((bmiobj.get_start_time()))
        print((time.localtime(bmiobj.get_start_time())))

        print("-------------- End time: ")
        print((bmiobj.get_end_time()))
        print((time.localtime(bmiobj.get_end_time())))

        print("-------------- Grid type: ")
        print((bmiobj.get_grid_type(grid_id)))

        print("-------------- Var type: ")
        print((bmiobj.get_var_type("Altitude")))

        print("-------------- Var rank: ")
        print((bmiobj.get_var_rank("Altitude")))

        print("-------------- Var size: ")
        print((bmiobj.get_var_size("Altitude")))

        print("-------------- Var nbytes: ")
        print((bmiobj.get_var_nbytes("Altitude")))

        print("-------------- Getvalue: ")
        print((bmiobj.get_value("Altitude")))

        print("-------------- Getvalue: ")
        print((bmiobj.get_value("timestepsecs")))

        print("-------------- get_attribute_names: ")
        names = bmiobj.get_attribute_names()
        print(names)

        print("-------------- get_attribute_value: ")
        print(names[0])
        print((bmiobj.get_attribute_value(names[0])))

        print("-------------- set_attribute_value: ")
        print(names[0])
        bmiobj.set_attribute_value(names[0], "SET By TEST")
        print((bmiobj.get_attribute_value(names[0])))
        self.assertEqual("SET By TEST", bmiobj.get_attribute_value(names[0]))

        print("-------------- set_start_time: ")
        bmiobj.set_start_time(0)
        print((bmiobj.get_attribute_value("run:starttime")))

        print("-------------- save the state:")
        bmiobj.save_state(".")
        self.assertTrue(os.path.exists("TSoil.map"))
        os.remove("TSoil.map")

        bmiobj.finalize()
コード例 #35
0
########################################################################

# In[]: Initialize the RTC-Tools model
os.chdir(Bin_RTC)

from wflow.wrappers.rtc.wrapperExtended import BMIWrapperExtended

# RTC_model = BMIWrapperExtended(engine=os.path.join(Bin_RTC,"RTCTools_BMI"))
RTC_model = BMIWrapperExtended(engine=os.path.join(Bin_RTC, "RTCTools_BMI"))
print "RTCmodel", Bin_RTC, RTC_model
RTC_model.initialize("..")


# In[]: Initialize the WFlow model
os.chdir(dir_wflow)
LA_model = bmi.wflowbmi_csdms()
LA_model.initialize((IniFile), loglevel=logging.DEBUG)

# now get the forcings that wflow expects
# The bmi is such that you can get the input variables and the output variables. However, the
# input variable list also contains the in/out variables. So to
# get the input only we subtract the two lists.
invars = LA_model.get_input_var_names()
outvars = LA_model.get_output_var_names()
inputmstacks = list(set(invars) - set(outvars))


# In[]: Investigate start time, end time and time step of both models

print "WFlow:"
LA_dt = LA_model.get_time_step()
コード例 #36
0
ファイル: TestBMI.py プロジェクト: andreybugaets/wflow
    def testbmifuncs(self):

        bmiobj = bmi.wflowbmi_csdms()
        bmiobj.initialize('wflow_sceleton/wflow_sceleton.ini',loglevel=logging.ERROR)

        print("-------------- Grid origin: ")
        gorigin = bmiobj.get_grid_origin('Altitude')
        print(gorigin)
        self.assertAlmostEquals(sum([52.054268, 5.2271633]), sum(gorigin),places=4)

        print("-------------- Grid shape: ")
        print(bmiobj.get_grid_shape('Altitude'))
        self.assertAlmostEquals(sum([169L, 187L]), sum(bmiobj.get_grid_shape('Altitude')),places=4)

        print("-------------- Grid spacing: ")
        print(bmiobj.get_grid_spacing('Altitude'))

        print("-------------- Grid X: ")
        print(bmiobj.get_grid_x('Altitude'))

        print("-------------- Grid Y: ")
        print(bmiobj.get_grid_y('Altitude'))

        print("-------------- Grid Z: ")
        print(bmiobj.get_grid_z('Altitude'))

        print("-------------- Name: ")
        print(bmiobj.get_component_name())

        print("-------------- Input var names: ")
        print(bmiobj.get_input_var_names())

        print("-------------- UNit of var TEMP: ")
        print(bmiobj.get_var_units('TEMP'))

        print("-------------- UNit of var P: ")
        print(bmiobj.get_var_units('P'))

        print("-------------- Output var names: ")
        print(bmiobj.get_output_var_names())

        print("-------------- Time units: ")
        print(bmiobj.get_time_units())

        print("-------------- Time step: ")
        print(bmiobj.get_time_step())

        print("-------------- Start time: ")
        print(bmiobj.get_start_time())

        print("-------------- Current time: ")
        print(bmiobj.get_current_time())
        a = bmiobj.get_current_time()
        # print(time.localtime(bmiobj.get_current_time()))

        os.environ['TZ'] = 'Europe/London'

        print("-------------- Current time (set to london): ")
        print(bmiobj.get_current_time())
        b = bmiobj.get_current_time()

        self.assertAlmostEquals(a,b)

        print("-------------- update: ")
        bmiobj.update()

        print("-------------- Current time after update: ")
        print(bmiobj.get_current_time())
        print(time.localtime(bmiobj.get_current_time()))

        print("-------------- Start time: ")
        print(bmiobj.get_start_time())
        print(time.localtime(bmiobj.get_start_time()))

        print("-------------- End time: ")
        print(bmiobj.get_end_time())
        print(time.localtime(bmiobj.get_end_time()))

        print("-------------- Grid type: ")
        print(bmiobj.get_grid_type('Altitude'))

        print("-------------- Var type: ")
        print(bmiobj.get_var_type('Altitude'))

        print("-------------- Var rank: ")
        print(bmiobj.get_var_rank('Altitude'))

        print("-------------- Var size: ")
        print(bmiobj.get_var_size('Altitude'))

        print("-------------- Var nbytes: ")
        print(bmiobj.get_var_nbytes('Altitude'))

        print("-------------- Getvalue: ")
        print(bmiobj.get_value('Altitude'))

        print("-------------- Getvalue: ")
        print(bmiobj.get_value('timestepsecs'))

        print("-------------- get_attribute_names: ")
        names = bmiobj.get_attribute_names()
        print names
        self.assertEquals(['API:IF', 'API:InwaterMM', 'framework:outputformat', 'framework:debug',
                           'framework:netcdfinput', 'framework:netcdfstatesinput', 'framework:netcdfoutput',
                           'framework:netcdfstaticoutput', 'framework:netcdfstatesoutput',
                           'framework:netcdfstaticinput', 'framework:EPSG', 'framework:netcdf_format',
                           'framework:netcdf_zlib', 'framework:netcdf_least_significant_digit', 'run:starttime',
                           'run:endtime', 'run:timestepsecs', 'run:reinit', 'modelparameters:AltTemperature',
                           'layout:sizeinmetres', 'outputmaps:self.TSoil', 'outputmaps:self.AltTemperature',
                           'outputcsv_0:samplemap', 'outputcsv_0:self.TSoil', 'outputcsv_0:self.AltTemperature',
                           'outputcsv_1:samplemap', 'outputtss_0:samplemap', 'model:timestepsecs'], names)

        print("-------------- get_attribute_value: ")
        print names[0]
        print(bmiobj.get_attribute_value(names[0]))

        print("-------------- set_attribute_value: ")
        print names[0]
        bmiobj.set_attribute_value(names[0],"SET By TEST")
        print(bmiobj.get_attribute_value(names[0]))
        self.assertEquals("SET By TEST",bmiobj.get_attribute_value(names[0]))

        print("-------------- set_start_time: ")
        bmiobj.set_start_time(0)
        print(bmiobj.get_attribute_value("run:starttime"))

        print("-------------- save the state:")
        bmiobj.save_state(".")
        self.assertTrue(os.path.exists("TSoil.map"))
        os.remove("TSoil.map")

        bmiobj.finalize()
コード例 #37
0
ファイル: Testwflow_sbm2bmi.py プロジェクト: marioponce/wflow
 def TestBMIrun(self):
     import wflow.wflow_bmi as bmi
     bmimodel = bmi.wflowbmi_csdms()
     bmimodel.initialize('../../examples/wflow_rhine_sbm2/wflow_sbm2.ini')
     bmimodel.update()