示例#1
0
 def test_make_shyft_ts_from_xts(self):
     shyft_ts = self._create_shyft_ts()
     ts_name = u'/make_xts'
     xts = SmGTsRepository._make_xts_from_shyft_ts(ts_name, shyft_ts)
     test_ts = SmGTsRepository._make_shyft_ts_from_xts(xts)
     [self.assertAlmostEqual(test_ts.value(i), xts.Value(i).V) for i in range(test_ts.size())]
     [self.assertAlmostEqual(test_ts.time(i), xts.Time(i).ToUnixTime()) for i in range(test_ts.size())]
示例#2
0
 def test_namelist_to_ListOf_TsIdentities(self):
     ds = SmGTsRepository(PREPROD)
     nl = [u'/ICC-test-v9.2', u'/test/b2', u'/test/c2']
     r = ds._namelist_to_ListOf_TsIdentities(nl)
     self.assertEqual(len(nl), r.Count)
     [(self.assertEqual(nl[i], r[i].Name)
       and self.assertEqual(0, r[i].Id)) for i in range(len(nl))]
示例#3
0
 def test_read_forecast(self):
     utc = api.Calendar()
     ds = SmGTsRepository(PREPROD, FC_PREPROD)
     nl = [u'/LTMS-Abisko........-T0000A5P_EC00_ENS']
     t0 = utc.time(2016, 8, 1, 00, 00, 00)
     t1 = utc.time(2016, 8, 10, 00, 00, 00)
     p = api.UtcPeriod(t0, t1)
     fclist = ds.read_forecast(nl, p)
     self.assertIsNotNone(fclist)
     fc1 = fclist[u'/LTMS-Abisko........-T0000A5P_EC00_ENS']
     fc1_v = [fc1.value(i) for i in range(fc1.size())]
     # Test times here, left for manual inspection fc1_t = [utc.to_string(fc1.time(i)) for i in range(fc1.size())]
     self.assertIsNotNone(fc1_v)
     # Values read from SMG PREPROD:
     fc1_repeat = [
         1.449, 1.001, 0.423, 0.249, 0.252, 0.126, 0.068, 0.067, 0.189,
         0.309, 0.300, 0.086, 0.055, 0.121, 0.149, 0.020, 0.014, 0.055,
         0.222, 0.070, 0.094, 0.196, 0.132, 0.085, 0.087, 0.159, 0.158,
         0.150, 0.214, 0.254, 0.239, 0.099, 0.089, 0.140, 0.154
     ]
     fc1_v_read = [0.0] + [x for x in fc1_repeat
                           for i in range(6)] + [0.079] * 5
     [
         self.assertLess(
             fabs(fc1_v_read[i] - fc1_v[i]), 0.01,
             "{}: {} != {}".format(i, fc1_v_read[i], fc1_v[i]))
         for i in range(len(fc1_v_read))
     ]
示例#4
0
 def test_store(self):
     ds = SmGTsRepository(PREPROD)
     nl = [u'/shyft/test/a', u'/shyft/test/b',
           u'/shyft/test/c']  #[u'/ICC-test-v9.2']
     t0 = 946684800  # time_t/unixtime 2000.01.01 00:00:00
     dt = 3600  #one hour in seconds
     values = np.array([1.0, 2.0, 3.0])
     shyft_ts_factory = api.TsFactory()
     shyft_result_ts = shyft_ts_factory.create_point_ts(
         len(values), t0, dt, api.DoubleVector(values))
     shyft_catchment_result = dict()
     shyft_catchment_result[nl[0]] = shyft_result_ts
     shyft_catchment_result[nl[1]] = shyft_result_ts
     shyft_catchment_result[nl[2]] = shyft_result_ts
     r = ds.store(shyft_catchment_result)
     self.assertEqual(r, True)
     # now read back the ts.. and verify it's there..
     read_period = api.UtcPeriod(t0, t0 + 3 * dt)
     rts_list = ds.read(nl, read_period)
     self.assertIsNotNone(rts_list)
     c2 = rts_list[nl[-1]]
     [
         self.assertAlmostEqual(c2.value(i), values[i])
         for i in range(len(values))
     ]
示例#5
0
 def test_make_shyft_ts_from_xts(self):
     shyft_ts = self._create_shyft_ts()
     ts_name = u'/make_xts'
     xts = SmGTsRepository._make_xts_from_shyft_ts(ts_name, shyft_ts)
     test_ts = SmGTsRepository._make_shyft_ts_from_xts(xts)
     [
         self.assertAlmostEqual(test_ts.value(i),
                                xts.Value(i).V)
         for i in range(test_ts.size())
     ]
     [
         self.assertAlmostEqual(test_ts.time(i),
                                xts.Time(i).ToUnixTime())
         for i in range(test_ts.size())
     ]
示例#6
0
 def test_make_shyft_ts_from_ssa_ts(self):
     shyft_ts1 = self._create_shyft_ts()
     ssa_ts = SmGTsRepository._make_ssa_ts_from_shyft_ts(
         u'/just_a_test', shyft_ts1)
     shyft_ts = SmGTsRepository._make_shyft_ts_from_ssa_ts(ssa_ts)
     [
         self.assertAlmostEqual(shyft_ts.value(i),
                                ssa_ts.Value(i).V)
         for i in range(shyft_ts.size())
     ]
     [
         self.assertAlmostEqual(shyft_ts.time(i),
                                ssa_ts.Time(i).ToUnixTime())
         for i in range(shyft_ts.size())
     ]
示例#7
0
        def fc_geo_ts_repository(self):
            """
            Returns
            -------
             - geo_ts_repository that have met-station-config relevant for tistel
            """

            met_stations = [
                # this is the list of MetStations, the gis_id tells the position, the remaining tells us what properties we observe/forecast/calculate at the metstation (smg-ts)
                MetStationConfig(gis_id=218,  # 0 midtpunkt
                                 temperature=u'/Vikf-Tistel........-T0017A3P_MAN',
                                 precipitation=u'/Vikf-Tistel........-T0000A5P_MAN',
                                 radiation=u'/ENKI/STS/Radiation/Sim.-Hestvollan....-T0006V0B-0119-0.8',
                                 wind_speed=u'/Dnmi-Fjærland.Bremu-T0016V3K-A55820-332',
                                 relative_humidity=u'/SHFT-rel-hum-dummy.-T0002A3R-0103')
            ]

            gis_location_repository = GisLocationService()  # yaml... geo_location service..this provides the gis locations for my stations
            smg_ts_repository = SmGTsRepository(PROD, FC_PROD)  # this provide the read function for my time-series

            return GeoTsRepository(  # together, the location provider, ts-provider, and the station, we have
                epsg_id=self.epsg_id,
                geo_location_repository=gis_location_repository,  # a complete geo_ts-repository
                ts_repository=smg_ts_repository,
                met_station_list=met_stations,
                ens_config=None)  # pass service info and met_stations
示例#8
0
 def test_read_forecast(self):
     utc=api.Calendar()
     ds=SmGTsRepository(PROD,FC_PROD)
     nl=[u'/LTMS-Abisko........-T0000A5P_EC00_ENS',u'/LTMS-Abisko........-T0000A5P_EC00_E04',u'/Vikf-Tistel........-T0017A3P_MAN',u'/Vikf-Tistel........-T0000A5P_MAN' ] #[u'/ICC-test-v9.2']
     t0=utc.time(api.YMDhms(2015,10, 1,00,00,00))
     t1=utc.time(api.YMDhms(2015,10,10,00,00,00))
     p=api.UtcPeriod(t0,t1)
     fclist=ds.read_forecast(nl,p)
     self.assertIsNotNone(fclist)
     fc1=fclist[u'/LTMS-Abisko........-T0000A5P_EC00_E04']
     fc1_v=[fc1.value(i) for i in range(fc1.size())]
     # test times here, left for manual inspection here fc1_t=[utc.to_string(fc1.time(i)) for i in range(fc1.size())]
     self.assertIsNotNone(fc1_v)
     #values as read from preprod smg:
     fc1_v_expected=[0.00,0.33,0.33,0.33,0.33,0.33,0.33,0.08,0.08,0.08,0.08,0.08,0.08,0.16,0.16,0.16,0.16,0.16,0.16,0.11,0.11,0.11,0.11,0.11,0.11,0.47,0.47,0.47,0.47,0.47,0.47,0.15,0.15,0.15,0.15,0.15,0.15,0.12,0.12,0.12,0.12,0.12,0.12,0.20,0.20,0.20,0.20,0.20,0.20,0.14,0.14,0.14,0.14,0.14,0.14,0.02,0.02,0.02,0.02,0.02,0.02,0.01,0.01,0.01,0.01,0.01,0.01,0.00,0.00,0.00,0.00,0.00,0.00,0.09,0.09,0.09,0.09,0.09,0.09,0.10,0.10,0.10,0.10,0.10,0.10,0.08,0.08,0.08,0.08,0.08,0.08,0.11,0.11,0.11,0.11,0.11,0.11,0.23,0.23,0.23,0.23,0.23,0.23,0.03,0.03,0.03,0.03,0.03,0.03,0.01,0.01,0.01,0.01,0.01,0.01,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.03,0.03,0.03,0.03,0.03,0.03,0.06,0.06,0.06,0.06,0.06,0.06,0.14,0.14,0.14,0.14,0.14,0.14,0.13,0.13,0.13,0.13,0.13,0.13,0.10,0.10,0.10,0.10]
     [ self.assertLess(fabs(fc1_v_expected[i]-fc1_v[i]),0.01 ,"{}:{} !={}".format(i,fc1_v_expected[i],fc1_v[i]) ) for i in range(len(fc1_v_expected)) ]
示例#9
0
def geo_ts_repo_constructor(cls, params):  # ,region_config):
    if cls_path(
            cls
    ) == 'shyft.repository.service.ssa_geo_ts_repository.GeoTsRepository':
        # from shyft.repository.service.ssa_geo_ts_repository import GeoTsRepository
        from shyft.repository.service.ssa_geo_ts_repository import MetStationConfig
        from shyft.repository.service.gis_location_service import GisLocationService
        from shyft.repository.service.ssa_smg_db import SmGTsRepository, PROD, FC_PROD

        #epsg = region_config.domain()["EPSG"]
        epsg = params['epsg']
        met_stations = [MetStationConfig(**s) for s in params['stations_met']]
        gis_location_repository = GisLocationService(
            server_name=params.get('server_name', None),
            server_name_preprod=params.get(
                'server_name_preprod',
                None))  # this provides the gis locations for my stations
        smg_ts_repository = SmGTsRepository(
            PROD, FC_PROD)  # this provide the read function for my time-series
        # return GeoTsRepository(epsg_id=epsg, geo_location_repository=gis_location_repository,
        #                        ts_repository=smg_ts_repository, met_station_list=met_stations,
        #                        ens_config=None)
        return cls(epsg_id=epsg,
                   geo_location_repository=gis_location_repository,
                   ts_repository=smg_ts_repository,
                   met_station_list=met_stations,
                   ens_config=None)
    else:
        #params.update({'epsg': region_config.domain()["EPSG"]})
        return cls(**params)
示例#10
0
 def test_read_forecast(self):
     utc=api.Calendar()
     ds=SmGTsRepository(PROD,FC_PROD)
     nl=[u'/LTMS-Abisko........-T0000A5P_EC00_ENS',u'/LTMS-Abisko........-T0000A5P_EC00_E04',u'/Vikf-Tistel........-T0017A3P_MAN',u'/Vikf-Tistel........-T0000A5P_MAN' ] #[u'/ICC-test-v9.2']
     t0=utc.time(api.YMDhms(2015,10, 1,00,00,00))
     t1=utc.time(api.YMDhms(2015,10,10,00,00,00))
     p=api.UtcPeriod(t0,t1)
     fclist=ds.read_forecast(nl,p)
     self.assertIsNotNone(fclist)
     fc1=fclist[u'/LTMS-Abisko........-T0000A5P_EC00_E04']
     fc1_v=[fc1.value(i) for i in range(fc1.size())]
     # test times here, left for manual inspection here fc1_t=[utc.to_string(fc1.time(i)) for i in range(fc1.size())]
     self.assertIsNotNone(fc1_v)
     #values as read from preprod smg:
     # [5.88181900e-01,4.41494600e-01,4.41494600e-01,4.41494600e-01,4.41494600e-01,4.41494600e-01,4.41494600e-01,1.34702200e-01,1.34702200e-01,1.34702200e-01,1.34702200e-01,1.34702200e-01,1.34702200e-01,1.16103300e-01,1.16103300e-01,1.16103300e-01,1.16103300e-01,1.16103300e-01,1.16103300e-01,3.03330000e-02,3.03330000e-02,3.03330000e-02,3.03330000e-02,3.03330000e-02,3.03330000e-02,2.43238400e-01,2.43238400e-01,2.43238400e-01,2.43238400e-01,2.43238400e-01,2.43238400e-01,3.47356600e-01,3.47356600e-01,3.47356600e-01,3.47356600e-01,3.47356600e-01,3.47356600e-01,1.92175200e-01,1.92175200e-01,1.92175200e-01,1.92175200e-01,1.92175200e-01,1.92175200e-01,8.15074000e-02,8.15074000e-02,8.15074000e-02,8.15074000e-02,8.15074000e-02,8.15074000e-02,4.19893000e-02,4.19893000e-02,4.19893000e-02,4.19893000e-02,4.19893000e-02,4.19893000e-02,5.14924000e-02,5.14924000e-02,5.14924000e-02,5.14924000e-02,5.14924000e-02,5.14924000e-02,6.47497000e-02,6.47497000e-02,6.47497000e-02,6.47497000e-02,6.47497000e-02,6.47497000e-02,8.22890000e-03,8.22890000e-03,8.22890000e-03,8.22890000e-03,8.22890000e-03,8.22890000e-03,2.67790000e-03,2.67790000e-03,2.67790000e-03,2.67790000e-03,2.67790000e-03,2.67790000e-03,4.33804000e-02,4.33804000e-02,4.33804000e-02,4.33804000e-02,4.33804000e-02,4.33804000e-02,2.17829100e-01,2.17829100e-01,2.17829100e-01,2.17829100e-01,2.17829100e-01,2.17829100e-01,1.61850600e-01,1.61850600e-01,1.61850600e-01,1.61850600e-01,1.61850600e-01,1.61850600e-01,1.31069800e-01,1.31069800e-01,1.31069800e-01,1.31069800e-01,1.31069800e-01,1.31069800e-01,6.11500000e-03,6.11500000e-03,6.11500000e-03,6.11500000e-03,6.11500000e-03,6.11500000e-03,0.00000000e+00,0.00000000e+00,0.00000000e+00,0.00000000e+00,0.00000000e+00,0.00000000e+00,3.62100000e-04,3.62100000e-04,3.62100000e-04,3.62100000e-04,3.62100000e-04,3.62100000e-04,5.20010000e-03,5.20010000e-03,5.20010000e-03,5.20010000e-03,5.20010000e-03,5.20010000e-03,3.24410000e-03,3.24410000e-03,3.24410000e-03,3.24410000e-03,3.24410000e-03,3.24410000e-03,1.70412000e-02,1.70412000e-02,1.70412000e-02,1.70412000e-02,1.70412000e-02,1.70412000e-02,4.21979000e-02,4.21979000e-02,4.21979000e-02,4.21979000e-02,4.21979000e-02,4.21979000e-02,3.39565000e-02,3.39565000e-02,3.39565000e-02,3.39565000e-02,3.39565000e-02,3.39565000e-02,7.62323000e-02,7.62323000e-02,7.62323000e-02,7.62323000e-02,7.62323000e-02,7.62323000e-02,7.38052000e-02,7.38052000e-02,7.38052000e-02,7.38052000e-02,7.38052000e-02,7.38052000e-02,4.41573000e-02,4.41573000e-02,4.41573000e-02,4.41573000e-02,4.41573000e-02,4.41573000e-02,5.31360000e-03,5.31360000e-03,5.31360000e-03,5.31360000e-03,5.31360000e-03,5.31360000e-03,1.36700000e-04,1.36700000e-04,1.36700000e-04,1.36700000e-04,1.36700000e-04,1.36700000e-04,1.68420000e-03,1.68420000e-03,1.68420000e-03,1.68420000e-03,1.68420000e-03,1.68420000e-03,2.09430000e-03,2.09430000e-03,2.09430000e-03,2.09430000e-03,2.09430000e-03,2.09430000e-03,9.97500000e-04,9.97500000e-04,9.97500000e-04,9.97500000e-04,9.97500000e-04,9.97500000e-04,0.00000000e+00,0.00000000e+00,0.00000000e+00,0.00000000e+00,0.00000000e+00,0.00000000e+00,0.00000000e+00,0.00000000e+00,0.00000000e+00,0.00000000e+00,0.00000000e+00,0.00000000e+00,2.37430000e-03,2.37430000e-03,2.37430000e-03,2.37430000e-03,2.37430000e-03]
     fc1_v_expected = [0.00,0.33,0.33,0.33,0.33,0.33,0.33,0.08,0.08,0.08,0.08,0.08,0.08,0.16,0.16,0.16,0.16,0.16,0.16,0.11,0.11,0.11,0.11,0.11,0.11,0.47,0.47,0.47,0.47,0.47,0.47,0.15,0.15,0.15,0.15,0.15,0.15,0.12,0.12,0.12,0.12,0.12,0.12,0.20,0.20,0.20,0.20,0.20,0.20,0.14,0.14,0.14,0.14,0.14,0.14,0.02,0.02,0.02,0.02,0.02,0.02,0.01,0.01,0.01,0.01,0.01,0.01,0.00,0.00,0.00,0.00,0.00,0.00,0.09,0.09,0.09,0.09,0.09,0.09,0.10,0.10,0.10,0.10,0.10,0.10,0.08,0.08,0.08,0.08,0.08,0.08,0.11,0.11,0.11,0.11,0.11,0.11,0.23,0.23,0.23,0.23,0.23,0.23,0.03,0.03,0.03,0.03,0.03,0.03,0.01,0.01,0.01,0.01,0.01,0.01,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.03,0.03,0.03,0.03,0.03,0.03,0.06,0.06,0.06,0.06,0.06,0.06,0.14,0.14,0.14,0.14,0.14,0.14,0.13,0.13,0.13,0.13,0.13,0.13,0.10,0.10,0.10,0.10]
     [ self.assertLess(fabs(fc1_v_expected[i]-fc1_v[i]),0.01 ,"{}:{} !={}".format(i,fc1_v_expected[i],fc1_v[i]) ) for i in range(len(fc1_v_expected)) ]
示例#11
0
 def test_read_forecast(self):
     utc=api.Calendar()
     ds=SmGTsRepository(PREPROD, FC_PREPROD)
     nl=[u'/LTMS-Abisko........-T0000A5P_EC00_ENS']
     t0=utc.time(api.YMDhms(2016,8, 1,00,00,00))
     t1=utc.time(api.YMDhms(2016,8,10,00,00,00))
     p=api.UtcPeriod(t0,t1)
     fclist=ds.read_forecast(nl,p)
     self.assertIsNotNone(fclist)
     fc1=fclist[u'/LTMS-Abisko........-T0000A5P_EC00_ENS']
     fc1_v=[fc1.value(i) for i in range(fc1.size())]
     # test times here, left for manual inspection fc1_t=[utc.to_string(fc1.time(i)) for i in range(fc1.size())]
     self.assertIsNotNone(fc1_v)
     # values read from SMG PREPROD:
     fc1_repeat = [1.449, 1.001, 0.423, 0.249, 0.252, 0.126, 0.068, 0.067, 0.189, 0.309, 0.300, 0.086, 0.055, 0.121, 0.149, 0.020, 0.014, 0.055, 0.222, 0.070, 0.094, 0.196, 0.132, 0.085, 0.087, 0.159, 0.158, 0.150, 0.214, 0.254, 0.239, 0.099, 0.089, 0.140, 0.154]
     fc1_v_read = [0.0] + [x for x in fc1_repeat for i in range(6)] + [0.079]*5
     [ self.assertLess( fabs(fc1_v_read[i]-fc1_v[i]), 0.01, "{}: {} != {}".format(i,fc1_v_read[i],fc1_v[i]) ) for i in range(len(fc1_v_read)) ]
示例#12
0
 def test_read_forecast(self):
     utc = api.Calendar()
     ds = SmGTsRepository(PROD, FC_PROD)
     nl = [
         u'/LTMS-Abisko........-T0000A5P_EC00_ENS',
         u'/LTMS-Abisko........-T0000A5P_EC00_E04',
         u'/Vikf-Tistel........-T0017A3P_MAN',
         u'/Vikf-Tistel........-T0000A5P_MAN'
     ]  #[u'/ICC-test-v9.2']
     t0 = utc.time(api.YMDhms(2015, 10, 1, 00, 00, 00))
     t1 = utc.time(api.YMDhms(2015, 10, 10, 00, 00, 00))
     p = api.UtcPeriod(t0, t1)
     fclist = ds.read_forecast(nl, p)
     self.assertIsNotNone(fclist)
     fc1 = fclist[u'/LTMS-Abisko........-T0000A5P_EC00_E04']
     fc1_v = [fc1.value(i) for i in range(fc1.size())]
     # test times here, left for manual inspection here fc1_t=[utc.to_string(fc1.time(i)) for i in range(fc1.size())]
     self.assertIsNotNone(fc1_v)
     #values as read from preprod smg:
     # [5.88181900e-01,4.41494600e-01,4.41494600e-01,4.41494600e-01,4.41494600e-01,4.41494600e-01,4.41494600e-01,1.34702200e-01,1.34702200e-01,1.34702200e-01,1.34702200e-01,1.34702200e-01,1.34702200e-01,1.16103300e-01,1.16103300e-01,1.16103300e-01,1.16103300e-01,1.16103300e-01,1.16103300e-01,3.03330000e-02,3.03330000e-02,3.03330000e-02,3.03330000e-02,3.03330000e-02,3.03330000e-02,2.43238400e-01,2.43238400e-01,2.43238400e-01,2.43238400e-01,2.43238400e-01,2.43238400e-01,3.47356600e-01,3.47356600e-01,3.47356600e-01,3.47356600e-01,3.47356600e-01,3.47356600e-01,1.92175200e-01,1.92175200e-01,1.92175200e-01,1.92175200e-01,1.92175200e-01,1.92175200e-01,8.15074000e-02,8.15074000e-02,8.15074000e-02,8.15074000e-02,8.15074000e-02,8.15074000e-02,4.19893000e-02,4.19893000e-02,4.19893000e-02,4.19893000e-02,4.19893000e-02,4.19893000e-02,5.14924000e-02,5.14924000e-02,5.14924000e-02,5.14924000e-02,5.14924000e-02,5.14924000e-02,6.47497000e-02,6.47497000e-02,6.47497000e-02,6.47497000e-02,6.47497000e-02,6.47497000e-02,8.22890000e-03,8.22890000e-03,8.22890000e-03,8.22890000e-03,8.22890000e-03,8.22890000e-03,2.67790000e-03,2.67790000e-03,2.67790000e-03,2.67790000e-03,2.67790000e-03,2.67790000e-03,4.33804000e-02,4.33804000e-02,4.33804000e-02,4.33804000e-02,4.33804000e-02,4.33804000e-02,2.17829100e-01,2.17829100e-01,2.17829100e-01,2.17829100e-01,2.17829100e-01,2.17829100e-01,1.61850600e-01,1.61850600e-01,1.61850600e-01,1.61850600e-01,1.61850600e-01,1.61850600e-01,1.31069800e-01,1.31069800e-01,1.31069800e-01,1.31069800e-01,1.31069800e-01,1.31069800e-01,6.11500000e-03,6.11500000e-03,6.11500000e-03,6.11500000e-03,6.11500000e-03,6.11500000e-03,0.00000000e+00,0.00000000e+00,0.00000000e+00,0.00000000e+00,0.00000000e+00,0.00000000e+00,3.62100000e-04,3.62100000e-04,3.62100000e-04,3.62100000e-04,3.62100000e-04,3.62100000e-04,5.20010000e-03,5.20010000e-03,5.20010000e-03,5.20010000e-03,5.20010000e-03,5.20010000e-03,3.24410000e-03,3.24410000e-03,3.24410000e-03,3.24410000e-03,3.24410000e-03,3.24410000e-03,1.70412000e-02,1.70412000e-02,1.70412000e-02,1.70412000e-02,1.70412000e-02,1.70412000e-02,4.21979000e-02,4.21979000e-02,4.21979000e-02,4.21979000e-02,4.21979000e-02,4.21979000e-02,3.39565000e-02,3.39565000e-02,3.39565000e-02,3.39565000e-02,3.39565000e-02,3.39565000e-02,7.62323000e-02,7.62323000e-02,7.62323000e-02,7.62323000e-02,7.62323000e-02,7.62323000e-02,7.38052000e-02,7.38052000e-02,7.38052000e-02,7.38052000e-02,7.38052000e-02,7.38052000e-02,4.41573000e-02,4.41573000e-02,4.41573000e-02,4.41573000e-02,4.41573000e-02,4.41573000e-02,5.31360000e-03,5.31360000e-03,5.31360000e-03,5.31360000e-03,5.31360000e-03,5.31360000e-03,1.36700000e-04,1.36700000e-04,1.36700000e-04,1.36700000e-04,1.36700000e-04,1.36700000e-04,1.68420000e-03,1.68420000e-03,1.68420000e-03,1.68420000e-03,1.68420000e-03,1.68420000e-03,2.09430000e-03,2.09430000e-03,2.09430000e-03,2.09430000e-03,2.09430000e-03,2.09430000e-03,9.97500000e-04,9.97500000e-04,9.97500000e-04,9.97500000e-04,9.97500000e-04,9.97500000e-04,0.00000000e+00,0.00000000e+00,0.00000000e+00,0.00000000e+00,0.00000000e+00,0.00000000e+00,0.00000000e+00,0.00000000e+00,0.00000000e+00,0.00000000e+00,0.00000000e+00,0.00000000e+00,2.37430000e-03,2.37430000e-03,2.37430000e-03,2.37430000e-03,2.37430000e-03]
     fc1_v_expected = [
         0.00, 0.33, 0.33, 0.33, 0.33, 0.33, 0.33, 0.08, 0.08, 0.08,
         0.08, 0.08, 0.08, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.11,
         0.11, 0.11, 0.11, 0.11, 0.11, 0.47, 0.47, 0.47, 0.47, 0.47,
         0.47, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.12, 0.12, 0.12,
         0.12, 0.12, 0.12, 0.20, 0.20, 0.20, 0.20, 0.20, 0.20, 0.14,
         0.14, 0.14, 0.14, 0.14, 0.14, 0.02, 0.02, 0.02, 0.02, 0.02,
         0.02, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.00, 0.00, 0.00,
         0.00, 0.00, 0.00, 0.09, 0.09, 0.09, 0.09, 0.09, 0.09, 0.10,
         0.10, 0.10, 0.10, 0.10, 0.10, 0.08, 0.08, 0.08, 0.08, 0.08,
         0.08, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.23, 0.23, 0.23,
         0.23, 0.23, 0.23, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.01,
         0.01, 0.01, 0.01, 0.01, 0.01, 0.00, 0.00, 0.00, 0.00, 0.00,
         0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
         0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.03,
         0.03, 0.03, 0.03, 0.03, 0.03, 0.06, 0.06, 0.06, 0.06, 0.06,
         0.06, 0.14, 0.14, 0.14, 0.14, 0.14, 0.14, 0.13, 0.13, 0.13,
         0.13, 0.13, 0.13, 0.10, 0.10, 0.10, 0.10
     ]
     [
         self.assertLess(
             fabs(fc1_v_expected[i] - fc1_v[i]), 0.01,
             "{}:{} !={}".format(i, fc1_v_expected[i], fc1_v[i]))
         for i in range(len(fc1_v_expected))
     ]
示例#13
0
 def test_make_xts_from_shyft_ts(self):
     shyft_ts = self._create_shyft_ts()
     ts_name = u'/make_xts'
     xts = SmGTsRepository._make_xts_from_shyft_ts(ts_name, shyft_ts)
     self.assertEqual(xts.Count, shyft_ts.size())
     self.assertEqual(xts.Name, ts_name)
     [self.assertAlmostEqual(xts.Value(i).V, shyft_ts.value(i)) for i in range(shyft_ts.size())]
     [self.assertAlmostEqual(xts.Value(i).Q, 0) for i in range(shyft_ts.size())]
     [self.assertAlmostEqual(xts.Time(i).ToUnixTime(), shyft_ts.time(i)) for i in range(shyft_ts.size())]
示例#14
0
 def test_read_forecast(self):
     utc = api.Calendar()
     ds = SmGTsRepository(PROD, FC_PROD)
     nl = [
         u'/LTMS-Abisko........-T0000A5P_EC00_ENS',
         u'/LTMS-Abisko........-T0000A5P_EC00_E04',
         u'/Vikf-Tistel........-T0017A3P_MAN',
         u'/Vikf-Tistel........-T0000A5P_MAN'
     ]  #[u'/ICC-test-v9.2']
     t0 = utc.time(api.YMDhms(2015, 10, 1, 00, 00, 00))
     t1 = utc.time(api.YMDhms(2015, 10, 10, 00, 00, 00))
     p = api.UtcPeriod(t0, t1)
     fclist = ds.read_forecast(nl, p)
     self.assertIsNotNone(fclist)
     fc1 = fclist[u'/LTMS-Abisko........-T0000A5P_EC00_E04']
     fc1_v = [fc1.value(i) for i in range(fc1.size())]
     # test times here, left for manual inspection here fc1_t=[utc.to_string(fc1.time(i)) for i in range(fc1.size())]
     self.assertIsNotNone(fc1_v)
     #values as read from preprod smg:
     fc1_v_expected = [
         0.00, 0.33, 0.33, 0.33, 0.33, 0.33, 0.33, 0.08, 0.08, 0.08,
         0.08, 0.08, 0.08, 0.16, 0.16, 0.16, 0.16, 0.16, 0.16, 0.11,
         0.11, 0.11, 0.11, 0.11, 0.11, 0.47, 0.47, 0.47, 0.47, 0.47,
         0.47, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.12, 0.12, 0.12,
         0.12, 0.12, 0.12, 0.20, 0.20, 0.20, 0.20, 0.20, 0.20, 0.14,
         0.14, 0.14, 0.14, 0.14, 0.14, 0.02, 0.02, 0.02, 0.02, 0.02,
         0.02, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.00, 0.00, 0.00,
         0.00, 0.00, 0.00, 0.09, 0.09, 0.09, 0.09, 0.09, 0.09, 0.10,
         0.10, 0.10, 0.10, 0.10, 0.10, 0.08, 0.08, 0.08, 0.08, 0.08,
         0.08, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.23, 0.23, 0.23,
         0.23, 0.23, 0.23, 0.03, 0.03, 0.03, 0.03, 0.03, 0.03, 0.01,
         0.01, 0.01, 0.01, 0.01, 0.01, 0.00, 0.00, 0.00, 0.00, 0.00,
         0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
         0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.03,
         0.03, 0.03, 0.03, 0.03, 0.03, 0.06, 0.06, 0.06, 0.06, 0.06,
         0.06, 0.14, 0.14, 0.14, 0.14, 0.14, 0.14, 0.13, 0.13, 0.13,
         0.13, 0.13, 0.13, 0.10, 0.10, 0.10, 0.10
     ]
     [
         self.assertLess(
             fabs(fc1_v_expected[i] - fc1_v[i]), 0.01,
             "{}:{} !={}".format(i, fc1_v_expected[i], fc1_v[i]))
         for i in range(len(fc1_v_expected))
     ]
示例#15
0
 def test_make_ssa_ts_from_shyft_ts(self):
     ts_name=u'/abc'
     
     shyft_ts=self._create_shyft_ts()
     r=SmGTsRepository._make_ssa_ts_from_shyft_ts(ts_name,shyft_ts)
     self.assertEqual(r.Count,shyft_ts.size())
     self.assertEqual(r.Name,ts_name)
     [self.assertAlmostEqual(shyft_ts.value(i),r.Value(i).V) for i in range(shyft_ts.size())]
     [self.assertAlmostEqual(0,r.Value(i).Q) for i in range(shyft_ts.size())]
     [self.assertAlmostEqual(shyft_ts.time(i),r.Time(i).ToUnixTime()) for i in range(shyft_ts.size())]
示例#16
0
 def test_store(self):
     ds=SmGTsRepository(PREPROD)
     nl=[u'/shyft/test/a',u'/shyft/test/b',u'/shyft/test/c']
     t0=946684800 # time_t/unixtime 2000.01.01 00:00:00
     dt=3600 #one hour in seconds
     values=np.array([1.0,2.0,3.0])
     shyft_ts_factory=api.TsFactory()
     shyft_result_ts=shyft_ts_factory.create_point_ts(len(values),t0,dt,api.DoubleVector(values))
     shyft_catchment_result=dict()
     shyft_catchment_result[nl[0]]=shyft_result_ts
     shyft_catchment_result[nl[1]]=shyft_result_ts
     shyft_catchment_result[nl[2]]=shyft_result_ts
     r=ds.store(shyft_catchment_result) 
     self.assertEqual(r,True)
     # now read back the ts.. and verify it's there..
     read_period=api.UtcPeriod(t0,t0+3*dt)
     rts_list=ds.read(nl,read_period)
     self.assertIsNotNone(rts_list)
     c2=rts_list[nl[-1]]
     [self.assertAlmostEqual(c2.value(i),values[i]) for i in range(len(values))]
示例#17
0
    def geo_ts_repository(self):
        bbox=self.grid_specification.geometry # gives us [x0,y0,x1,y1], the corners of the bounding box
        fake_station_1_pos = [bbox[0],bbox[1], self._met_station_heights[0]]
        fake_station_2_pos = [bbox[2],bbox[3], self._met_station_heights[1]]
        gis_location_repository = HbvGeoLocationRepository(
            geo_location_dict={self._met_stations[0].gis_id:fake_station_1_pos,self._met_stations[1].gis_id:fake_station_2_pos},
            epsg_id=self.grid_specification._epsg_id)  # this provides the gis locations for my stations
        smg_ts_repository = SmGTsRepository(PROD, FC_PROD)  # this provide the read function for my time-series

        return GeoTsRepository(epsg_id=self.grid_specification._epsg_id, geo_location_repository=gis_location_repository,
                               ts_repository=smg_ts_repository, met_station_list=self._met_stations,
                               ens_config=None)
示例#18
0
 def test_period(self):
     utc = api.Calendar()
     t0 = utc.time(2014, 1, 1, 00, 00, 00)
     t1 = utc.time(2014, 3, 1, 00, 00, 00)
     p = api.UtcPeriod(t0, t1)
     self.assertEqual(p.start, t0)
     self.assertEqual(p.end, t1)
     self.assertTrue(isinstance(p, api.UtcPeriod))
     ssa_period = SmGTsRepository._make_ssa_Period_from_shyft_period(p)
     t0ssa = ssa_period.Start.ToUnixTime()
     t1ssa = ssa_period.End.ToUnixTime()
     self.assertEqual(t0ssa, t0)
     self.assertEqual(t1ssa, t1)
示例#19
0
 def test_period(self):
     utc = api.Calendar()
     t0 = utc.time(api.YMDhms(2014, 1, 1, 00, 00, 00))
     t1 = utc.time(api.YMDhms(2014, 3, 1, 00, 00, 00))
     p = api.UtcPeriod(t0, t1)
     self.assertEqual(p.start, t0)
     self.assertEqual(p.end, t1)
     self.assertTrue(isinstance(p, api.UtcPeriod))
     ssa_period = SmGTsRepository._make_ssa_Period_from_shyft_period(p)
     t0ssa = ssa_period.Start.ToUnixTime()
     t1ssa = ssa_period.End.ToUnixTime()
     self.assertEqual(t0ssa, t0)
     self.assertEqual(t1ssa, t1)
示例#20
0
def smg_geo_ts_repo_constructor(params, region_config):
    from shyft.repository.service.ssa_geo_ts_repository import GeoTsRepository
    from shyft.repository.service.ssa_geo_ts_repository import MetStationConfig
    from shyft.repository.service.gis_location_service import GisLocationService
    from shyft.repository.service.ssa_smg_db import SmGTsRepository, PROD, FC_PROD

    epsg = region_config.domain()["EPSG"]
    met_stations = [MetStationConfig(**s) for s in params['stations_met']]
    gis_location_repository = GisLocationService(
    )  # this provides the gis locations for my stations
    smg_ts_repository = SmGTsRepository(
        PROD, FC_PROD)  # this provide the read function for my time-series
    return GeoTsRepository(epsg_id=epsg,
                           geo_location_repository=gis_location_repository,
                           ts_repository=smg_ts_repository,
                           met_station_list=met_stations,
                           ens_config=None)
示例#21
0
        def test_get_timeseries_using_known_service_and_db_content(self):
            utc = Calendar()  # always use Calendar() stuff
            met_stations = [  # this is the list of MetStations, the gis_id tells the position, the remaining tells us what properties we observe/forecast/calculate at the metstation (smg-ts)
                MetStationConfig(
                    gis_id=598,
                    temperature=u'/NeNi-Sylsjøen......-T0017V3KI0114',
                    precipitation=u'/NeNi-Sylsjøen-2....-T0000D9BI0124'),
                MetStationConfig(
                    gis_id=574,
                    temperature=u'/NeNi-Stuggusjøen...-T0017V3KI0114',
                    precipitation=u'/NeNi-Stuggusjøen...-T0000D9BI0124',
                    radiation=
                    u'/ENKI/STS/Radiation/Sim.-Stuggusjøen...-T0006A0B-0119')
            ]
            #note: the MetStationConfig can be constructed from yaml-config
            gis_location_repository = GisLocationService(
            )  # this provides the gis locations for my stations
            smg_ts_repository = SmGTsRepository(
                PROD,
                FC_PROD)  # this provide the read function for my time-series

            geo_ts_repository = GeoTsRepository(
                epsg_id=32633,
                geo_location_repository=gis_location_repository,
                ts_repository=smg_ts_repository,
                met_station_list=met_stations,
                ens_config=None)  #pass service info and met_stations

            self.assertIsNotNone(geo_ts_repository)
            utc_period = UtcPeriod(utc.time(YMDhms(2010, 1, 1, 0, 0, 0)),
                                   utc.time(YMDhms(2010, 1, 2, 0, 0, 0)))
            ts_types = ['temperature', 'precipitation', 'radiation']
            geo_ts_dict = geo_ts_repository.get_timeseries(
                ts_types, utc_period=utc_period, geo_location_criteria=None)
            self.assertIsNotNone(geo_ts_dict)
            for ts_type in ts_types:
                self.assertTrue(
                    ts_type in geo_ts_dict.keys(),
                    "we ecpect to find an entry for each requested type (it could be empty list though"
                )
                self.assertTrue(
                    len(geo_ts_dict[ts_type]) > 0,
                    "we expect to find the series that we pass in, given they have not changed the name in SmG PROD"
                )
示例#22
0
 def test_make_xts_from_shyft_ts(self):
     shyft_ts = self._create_shyft_ts()
     ts_name = u'/make_xts'
     xts = SmGTsRepository._make_xts_from_shyft_ts(ts_name, shyft_ts)
     self.assertEqual(xts.Count, shyft_ts.size())
     self.assertEqual(xts.Name, ts_name)
     [
         self.assertAlmostEqual(xts.Value(i).V, shyft_ts.value(i))
         for i in range(shyft_ts.size())
     ]
     [
         self.assertAlmostEqual(xts.Value(i).Q, 0)
         for i in range(shyft_ts.size())
     ]
     [
         self.assertAlmostEqual(
             xts.Time(i).ToUnixTime(), shyft_ts.time(i))
         for i in range(shyft_ts.size())
     ]
     def test_get_ensemble_forecast_using_known_service_and_db_content(self):
         utc = Calendar()
         met_stations = [MetStationConfig(gis_id=402, temperature=u'/LTM5-Nea...........-T0017A3P_EC00_ENS', precipitation=u'/LTM5-Nea...........-T0000A5P_EC00_ENS')]
         gis_location_repository = GisLocationService()
         smg_ts_repository = SmGTsRepository(PREPROD, FC_PREPROD)
         n_ensembles = 51
         ens_station_list = [
             EnsembleStation(402, n_ensembles,
                 temperature_ens = lambda i:u'/LTM5-Nea...........-T0017A3P_EC00_E{0:02}'.format(i),
                 precipitation_ens = lambda i:u'/LTM5-Nea...........-T0000A5P_EC00_E{0:02}'.format(i),
                 wind_speed_ens = None,
                 radiation_ens = None,
                 relative_humidity_ens = None
             ),
             EnsembleStation(460, n_ensembles,
                 temperature_ens = lambda i:u'/LTM5-Tya...........-T0017A3P_EC00_E{0:02}'.format(i),
                 precipitation_ens = lambda i:u'/LTM5-Tya...........-T0000A5P_EC00_E{0:02}'.format(i),
                 wind_speed_ens = None,
                 radiation_ens = None,
                 relative_humidity_ens = None
             )
         ]
         ens_config = EnsembleConfig(n_ensembles, ens_station_list)
         geo_ts_repository = GeoTsRepository(
             epsg_id = 32633,
             geo_location_repository = gis_location_repository,
             ts_repository = smg_ts_repository,
             met_station_list = met_stations,
             ens_config = ens_config)
 
         self.assertIsNotNone(geo_ts_repository)
         utc_period = UtcPeriod(utc.time(YMDhms(2015, 10, 1, 0, 0, 0)),utc.time(YMDhms(2015, 10, 10, 0, 0, 0)))
         ts_types= ['temperature', 'precipitation']
         ens_geo_ts_dict = geo_ts_repository.get_forecast_ensemble(ts_types, utc_period=utc_period, t_c=None, geo_location_criteria=None)
         self.assertIsNotNone(ens_geo_ts_dict)
         self.assertEqual(ens_config.n_ensembles, len(ens_geo_ts_dict))
         for i in range(ens_config.n_ensembles):
             for ts_type in ts_types:
                 self.assertTrue(ts_type in ens_geo_ts_dict[i].keys(), "we expect to find an entry for each requested type (it could be empty list though)")
                 self.assertTrue(len(ens_geo_ts_dict[i][ts_type])>0, "we expect to find the series that we pass in by name in SmG PREPROD")
     def test_get_forecast_using_known_service_and_db_content(self):
         utc = Calendar()
         met_stations=[ # this is the list of MetStations, the gis_id tells the position, the remaining tells us what properties we observe/forecast/calculate at the metstation (smg-ts)
             MetStationConfig(gis_id=402, temperature=u'/LTM5-Nea...........-T0017A3P_EC00_ENS', precipitation=u'/LTM5-Nea...........-T0000A5P_EC00_ENS')
         ]
         gis_location_repository = GisLocationService()
         smg_ts_repository = SmGTsRepository(PREPROD, FC_PREPROD)
         geo_ts_repository = GeoTsRepository(
             epsg_id = 32633,
             geo_location_repository = gis_location_repository,
             ts_repository = smg_ts_repository,
             met_station_list = met_stations,
             ens_config = None)
 
         self.assertIsNotNone(geo_ts_repository)
         utc_period = UtcPeriod(utc.time(YMDhms(2015, 10, 1, 0, 0, 0)), utc.time(YMDhms(2015, 10, 10, 0, 0, 0)))
         ts_types= ['temperature', 'precipitation']
         geo_ts_dict = geo_ts_repository.get_forecast(ts_types, utc_period=utc_period, t_c=None, geo_location_criteria=None)
         self.assertIsNotNone(geo_ts_dict)
         for ts_type in ts_types:
             self.assertTrue(ts_type in geo_ts_dict.keys(), "we expect to find an entry for each requested type (it could be empty list though)")
             self.assertTrue(len(geo_ts_dict[ts_type])>0, "we expect to find the series that we pass in by name in SmG PREPROD")
示例#25
0
        def test_make_ssa_ts_from_shyft_ts(self):
            #ds=SmGTsRepository(PREPROD)
            ts_name = u'/abc'

            shyft_ts = self._create_shyft_ts()
            r = SmGTsRepository._make_ssa_ts_from_shyft_ts(ts_name, shyft_ts)
            self.assertEqual(r.Count, shyft_ts.size())
            self.assertEqual(r.Name, ts_name)
            [
                self.assertAlmostEqual(shyft_ts.value(i),
                                       r.Value(i).V)
                for i in range(shyft_ts.size())
            ]
            [
                self.assertAlmostEqual(0,
                                       r.Value(i).Q)
                for i in range(shyft_ts.size())
            ]
            [
                self.assertAlmostEqual(shyft_ts.time(i),
                                       r.Time(i).ToUnixTime())
                for i in range(shyft_ts.size())
            ]
示例#26
0
def observed_tistel_discharge(period):
    smg_ts_repository = SmGTsRepository(PROD, FC_PROD)
    result = smg_ts_repository.read([u"/Vikf-Tistel........-T1054A3KI0108"],
                                    period)
    return next(iter(result.values()))
示例#27
0
def observed_kjela_discharge(period):
    smg_ts_repository = SmGTsRepository(PROD, FC_PROD)
    discharge_ts_name=u'/Tokk-Kjela.........-D9100A3B5132R016.206'
    result = smg_ts_repository.read([discharge_ts_name], period)
    return result[discharge_ts_name]
示例#28
0
def smg_target_repo_constructor(params):
    from shyft.repository.service.ssa_smg_db import SmGTsRepository

    return SmGTsRepository(**params)
示例#29
0
 def test_make_shyft_ts_from_ssa_ts(self):
     shyft_ts1=self._create_shyft_ts()
     ssa_ts=SmGTsRepository._make_ssa_ts_from_shyft_ts(u'/just_a_test',shyft_ts1)
     shyft_ts=SmGTsRepository._make_shyft_ts_from_ssa_ts(ssa_ts)
     [self.assertAlmostEqual(shyft_ts.value(i),ssa_ts.Value(i).V) for i in range(shyft_ts.size())]
     [self.assertAlmostEqual(shyft_ts.time(i),ssa_ts.Time(i).ToUnixTime()) for i in range(shyft_ts.size())]
示例#30
0
def observed_tistel_discharge(period):
    smg_ts_repository = SmGTsRepository(PROD, FC_PROD)
    result = smg_ts_repository.read([u"/Vikf-Tistel........-T1054A3KI0108"], period)
    return next(iter(result.values()))
示例#31
0
 def test_namelist_to_ListOf_TsIdentities(self):
     ds=SmGTsRepository(PREPROD)
     nl=[u'/ICC-test-v9.2',u'/test/b2',u'/test/c2']
     r=ds._namelist_to_ListOf_TsIdentities(nl)
     self.assertEqual(len(nl),r.Count)
     [ (self.assertEqual(nl[i],r[i].Name) and self.assertEqual(0,r[i].Id)) for i in range(len(nl))]
示例#32
0
        def test_run_observed_then_arome_and_store(self):
            """
              Start Tistel 2015.09.01, dummy state with some kirchner water
               use observations around Tistel (geo_ts_repository)
               and simulate forwared to 2015.10.01 (store discharge and catchment level precip/temp)
               then use arome forecast for 65 hours (needs arome for this period in arome-directory)
               finally store the arome results.

            """
            utc = Calendar()  # No offset gives Utc
            time_axis = TimeAxisFixedDeltaT(utc.time(YMDhms(2015, 9, 1, 0)), deltahours(1), 30 * 24)
            fc_time_axis = TimeAxisFixedDeltaT(utc.time(YMDhms(2015, 10, 1, 0)), deltahours(1), 65)

            interpolation_id = 0
            ptgsk = DefaultSimulator("Tistel-ptgsk",
                                     interpolation_id,
                                     self.region_model_repository,
                                     self.geo_ts_repository,
                                     self.interpolation_repository, None)
            n_cells = ptgsk.region_model.size()
            ptgsk_state = DefaultStateRepository(ptgsk.region_model.__class__, n_cells)

            ptgsk.region_model.set_state_collection(-1, True)  # collect state so we can inspect it
            s0 = ptgsk_state.get_state(0)
            for i in range(s0.size()):  # add some juice to get started
                s0[i].kirchner.q = 0.5

            ptgsk.run(time_axis, s0)

            print("Done simulation, testing that we can extract data from model")

            cids = api.IntVector()  # we pull out for all the catchments-id if it's empty
            model = ptgsk.region_model  # fetch out  the model
            sum_discharge = model.statistics.discharge(cids)
            self.assertIsNotNone(sum_discharge)
            avg_temperature = model.statistics.temperature(cids)
            avg_precipitation = model.statistics.precipitation(cids)
            self.assertIsNotNone(avg_precipitation)
            self.assertIsNotNone(avg_temperature)
            for time_step in range(time_axis.size()):
                precip_raster = model.statistics.precipitation(cids, time_step)  # example raster output
                self.assertEqual(precip_raster.size(), n_cells)
            avg_gs_lwc = model.gamma_snow_state.lwc(cids)  # sca skaugen|gamma
            self.assertIsNotNone(avg_gs_lwc)
            # lwc surface_heat alpha melt_mean melt iso_pot_energy temp_sw
            avg_gs_output = model.gamma_snow_response.outflow(cids)
            self.assertIsNotNone(avg_gs_output)
            print("done. now save to db")
            # SmGTsRepository(PROD,FC_PROD)
            save_list = [
                TsStoreItem(u'/test/x/shyft/tistel/discharge_m3s', lambda m: m.statistics.discharge(cids)),
                TsStoreItem(u'/test/x/shyft/tistel/temperature', lambda m: m.statistics.temperature(cids)),
                TsStoreItem(u'/test/x/shyft/tistel/precipitation', lambda m: m.statistics.precipitation(cids)),
            ]

            tss = TimeseriesStore(SmGTsRepository(PREPROD, FC_PREPROD), save_list)

            self.assertTrue(tss.store_ts(ptgsk.region_model))

            print("Run forecast arome")
            endstate = ptgsk.region_model.state_t.vector_t()
            ptgsk.region_model.get_states(endstate)  # get the state at end of obs
            ptgsk.geo_ts_repository = self.arome_repository  # switch to arome here
            ptgsk.run_forecast(fc_time_axis, fc_time_axis.start, endstate)  # now forecast
            print("Done forecast")
            fc_save_list = [
                TsStoreItem(u'/test/x/shyft/tistel/fc_discharge_m3s', lambda m: m.statistics.discharge(cids)),
                TsStoreItem(u'/test/x/shyft/tistel/fc_temperature', lambda m: m.statistics.temperature(cids)),
                TsStoreItem(u'/test/x/shyft/tistel/fc_precipitation', lambda m: m.statistics.precipitation(cids)),
                TsStoreItem(u'/test/x/shyft/tistel/fc_radiation', lambda m: m.statistics.radiation(cids)),
                TsStoreItem(u'/test/x/shyft/tistel/fc_rel_hum', lambda m: m.statistics.rel_hum(cids)),
                TsStoreItem(u'/test/x/shyft/tistel/fc_wind_speed', lambda m: m.statistics.wind_speed(cids)),

            ]
            TimeseriesStore(SmGTsRepository(PREPROD, FC_PREPROD), fc_save_list).store_ts(ptgsk.region_model)
            print("Done save to db")
示例#33
0
        def geo_ts_repository(self):
            """
            Returns
            -------
             - geo_ts_repository with observed values, that have met-station-config relevant for tistel
            """

            met_stations = [
                # this is the list of MetStations, the gis_id tells the position, the remaining tells us what properties we observe/forecast/calculate at the metstation (smg-ts)
                MetStationConfig(gis_id=129,  # 0 Fjærland Bremu
                                 temperature=None,
                                 precipitation=None,
                                 radiation=None,
                                 wind_speed=u'/Dnmi-Fjærland.Bremu-T0016V3K-A55820-332'),

                MetStationConfig(gis_id=619,  # 1 Tistel
                                 temperature=u'/Vikf-Tistel........-T0017A3KI0114',
                                 precipitation=None,
                                 radiation=None,
                                 wind_speed=None,
                                 relative_humidity=u'/SHFT-rel-hum-dummy.-T0002A3R-0103'),

                MetStationConfig(gis_id=684,  # 2 Vossevangen
                                 temperature=None,  # u'/Dnmi-Vossevangen...-T0017V3K-A51530-1337'
                                 precipitation=u'/Dnmi-Vossevangen...-T0000D9B-A51530-1337',
                                 radiation=None,
                                 wind_speed=u'/Dnmi-Vossevangen...-T0016V3K-A51530-337'),

                MetStationConfig(gis_id=654,  # 2 Vossevangen
                                 temperature=None,
                                 precipitation=u'/Dnmi-Vangsnes......-T0000D9B-A53101-338',
                                 radiation=None,
                                 wind_speed=u'/Dnmi-Vangsnes......-T0016V3K-A53101-338'),

                MetStationConfig(gis_id=218,  # 4 Hestvollan
                                 temperature=u'/Vikf-Hestvollan....-T0017A3KI0114',
                                 precipitation=u'/Vikf-Hestvollan....-T0000D9BI0124',
                                 radiation=u'/ENKI/STS/Radiation/Sim.-Hestvollan....-T0006V0B-0119-0.8',  # clear sky,reduced to 0.8
                                 wind_speed=u'/Vikf-Hestvollan....-T0015V3KI0120'),

                MetStationConfig(gis_id=542,  # 5 Sopandefjell
                                 temperature=None,  # u'/Vikf-Sopandefjell..-T0017V3KI0114'
                                 precipitation=None,
                                 radiation=None,
                                 wind_speed=None),

                MetStationConfig(gis_id=650,  # 6 Ulldalsvatnet
                                 temperature=None,
                                 precipitation=None,
                                 radiation=None,
                                 wind_speed=u'/Hoey-Ulldalsvatnet.-T0015V3KI0120'),

            ]

            gis_location_repository = GisLocationService()  # this provides the gis locations for my stations
            smg_ts_repository = SmGTsRepository(PROD, FC_PROD)  # this provide the read function for my time-series

            return GeoTsRepository(  # together, the location provider, ts-provider, and the station, we have
                epsg_id=self.epsg_id,
                geo_location_repository=gis_location_repository,  # a complete geo_ts-repository
                ts_repository=smg_ts_repository,
                met_station_list=met_stations,
                ens_config=None)  # pass service info and met_stations
示例#34
0
        def test_get_ensemble_forecast_using_known_service_and_db_content(
                self):
            utc = Calendar()  # always use Calendar() stuff
            met_stations = [  # this is the list of MetStations, the gis_id tells the position, the remaining tells us what properties we observe/forecast/calculate at the metstation (smg-ts)
                MetStationConfig(
                    gis_id=598,
                    temperature=u'/LTM5-Nea...........-T0017A3P_EC00_ENS',
                    precipitation=u'/LTM5-Nea...........-T0000A5P_EC00_ENS')
            ]

            #note: the MetStationConfig can be constructed from yaml-config
            gis_location_repository = GisLocationService(
            )  # this provides the gis locations for my stations
            smg_ts_repository = SmGTsRepository(
                PROD,
                FC_PROD)  # this provide the read function for my time-series
            n_ensembles = 51
            ens_station_list = [
                EnsembleStation(
                    598,
                    n_ensembles,
                    temperature_ens=lambda i:
                    u'/LTM5-Nea...........-T0017A3P_EC00_E{0:02}'.format(i),
                    precipitation_ens=lambda i:
                    u'/LTM5-Nea...........-T0000A5P_EC00_E{0:02}'.format(i),
                    wind_speed_ens=None,
                    radiation_ens=None,
                    relative_humidity_ens=None),
                EnsembleStation(
                    574,
                    n_ensembles,
                    temperature_ens=lambda i:
                    u'/LTM5-Tya...........-T0017A3P_EC00_E{0:02}'.format(i),
                    precipitation_ens=lambda i:
                    u'/LTM5-Tya...........-T0000A5P_EC00_E{0:02}'.format(i),
                    wind_speed_ens=None,
                    radiation_ens=None,
                    relative_humidity_ens=None)
            ]
            ens_config = EnsembleConfig(n_ensembles, ens_station_list)
            geo_ts_repository = GeoTsRepository(
                epsg_id=32633,
                geo_location_repository=gis_location_repository,
                ts_repository=smg_ts_repository,
                met_station_list=met_stations,
                ens_config=ens_config)  #pass service info and met_stations

            self.assertIsNotNone(geo_ts_repository)
            utc_period = UtcPeriod(utc.time(YMDhms(2015, 10, 1, 0, 0, 0)),
                                   utc.time(YMDhms(2015, 10, 10, 0, 0, 0)))
            ts_types = ['temperature', 'precipitation']
            ens_geo_ts_dict = geo_ts_repository.get_forecast_ensemble(
                ts_types,
                utc_period=utc_period,
                t_c=None,
                geo_location_criteria=None)
            self.assertIsNotNone(ens_geo_ts_dict)
            self.assertEqual(ens_config.n_ensembles, len(ens_geo_ts_dict))
            for i in range(ens_config.n_ensembles):
                for ts_type in ts_types:
                    self.assertTrue(
                        ts_type in ens_geo_ts_dict[i].keys(),
                        "we ecpect to find an entry for each requested type (it could be empty list though"
                    )
                    self.assertTrue(
                        len(ens_geo_ts_dict[i][ts_type]) > 0,
                        "we expect to find the series that we pass in, given they have not changed the name in SmG PROD"
                    )