def setUp(self): self.cal = api.Calendar() self.dt = api.deltahours(1) self.nt = 24 * 10 self.t0 = self.cal.time(2016, 1, 1) self.ta = api.TimeAxis(self.t0, self.dt, self.nt) self.ta1 = api.TimeAxisFixedDeltaT(self.t0, self.dt, self.nt) self.geo_points = api.GeoPointVector() self.geo_points.append(api.GeoPoint(100, 100, 1000)) self.geo_points.append(api.GeoPoint(5100, 100, 1150)) self.geo_points.append(api.GeoPoint(100, 5100, 850))
def test_can_run_bayesian_kriging_from_observation_sites_to_1km_grid(self): """ Somewhat more complex test, first do kriging of 1 timeseries out to grid (expect same values flat) then do kriging of 3 time-series out to the grid (expect different values, no real verification here since this is done elsewhere """ # arrange the test with a btk_parameter, a source grid and a destination grid btk_parameter = api.BTKParameter(temperature_gradient=-0.6, temperature_gradient_sd=0.25, sill=25.0, nugget=0.5, range=20000.0, zscale=20.0) fx = lambda z: api.DoubleVector.from_numpy(np.zeros(self.n)) grid_1km_1 = self._create_geo_point_grid(self.mnx, self.mny, self.dx_model) grid_1km_3 = self._create_geo_point_grid(self.mnx, self.mny, self.dx_model) observation_sites = api.TemperatureSourceVector() ta_obs = api.TimeAxisFixedDeltaT(self.t, self.d * 3, int(self.n / 3)) ta_grid = api.TimeAxisFixedDeltaT(self.t, self.d, self.n) point_fx = api.point_interpretation_policy.POINT_AVERAGE_VALUE ts_site_1 = api.TimeSeries(ta_obs, values=api.DoubleVector.from_numpy( (20.0 - 0.6 * 5.0 / 100) + 3.0 * np.sin(np.arange(start=0, stop=ta_obs.size(), step=1) * 2 * np.pi / 8.0 - np.pi / 2.0) ), point_fx=point_fx) ts_site_2 = api.TimeSeries(ta_obs, values=api.DoubleVector.from_numpy( (20.0 - 0.6 * 500.0 / 100) + 3.0 * np.sin(np.arange(start=0, stop=ta_obs.size(), step=1) * 2 * np.pi / 8.0 - np.pi / 2.0)), point_fx=point_fx) ts_site_3 = api.TimeSeries(ta_obs, values=api.DoubleVector.from_numpy( (20.0 - 0.6 * 1050.0 / 100) + 3.0 * np.sin(np.arange(start=0, stop=ta_obs.size(), step=1) * 2 * np.pi / 8.0 - np.pi / 2.0)), point_fx=point_fx) observation_sites.append(api.TemperatureSource(api.GeoPoint(50.0, 50.0, 5.0), ts_site_1)) # act 1: just one time-series put into the system, should give same ts (true-averaged) in all the grid-1km_ts (which can be improved using std.gradient..) grid_1km_1ts = api.bayesian_kriging_temperature(observation_sites, grid_1km_1, ta_grid, btk_parameter) # assert 1: self.assertEqual(len(grid_1km_1ts), self.mnx * self.mny) expected_grid_1ts_values = ts_site_1.average(api.TimeAxis(ta_grid)).values.to_numpy() for gts in grid_1km_1ts: self.assertEqual(gts.ts.size(), ta_grid.size()) self.assertTrue(np.allclose(expected_grid_1ts_values, gts.ts.values.to_numpy())) observation_sites.append(api.TemperatureSource(api.GeoPoint(9000.0, 500.0, 500), ts_site_2)) observation_sites.append(api.TemperatureSource(api.GeoPoint(9000.0, 12000.0, 1050.0), ts_site_3)) grid_1km_3ts = api.bayesian_kriging_temperature(observation_sites, grid_1km_3, ta_grid, btk_parameter) self.assertEqual(len(grid_1km_3ts), self.mnx * self.mny) for gts in grid_1km_3ts: self.assertEqual(gts.ts.size(), ta_grid.size()) self.assertFalse(np.allclose(expected_grid_1ts_values, gts.ts.values.to_numpy()))
def _create_geo_ts_grid(self, nx, ny, dx, fx): """Create a geo_ts_grid of TemperatureSources, We just create a terrain model starting at 0 and increasing to max_elevation at max x and y. parameters ---------- nx : int number of grid-cells in x direction ny : int number of grid-cells in y direction dx : float distance in meters for one of the sides in the grid fx : lambda z : 1.0 a function that takes elevation z as input and generates a np.array len(self.ta) of float64 as time-series returns ------- a TemperatureSourceVector() filled with geo-ts representing the grid. """ arome_grid = api.TemperatureSourceVector() for i in range(nx): for j in range(ny): z = self.max_elevation * (i + j) / (nx + ny) ts = api.Timeseries(ta=self.ta, values=fx(z), point_fx=api.point_interpretation_policy. POINT_AVERAGE_VALUE) geo_ts = api.TemperatureSource(api.GeoPoint(i * dx, j * dx, z), ts) arome_grid.append(geo_ts) return arome_grid
def _get_ts_to_geo_ts_ensemble_result(self, input_source_types, geo_match): """ given the input-sources (temp,precip etc), and a geo-match, return back tsname->geopos, plus a result structure dict ready to add on the read ts""" # 1 get the station-> location map station_ids = [x.gis_id for x in self.ens_config.station_list] geo_loc = self.geo_location_repository.get_locations( location_id_list=station_ids, epsg_id=self.epsg_id) # 2 create map ts-id to tuple (attr_name,GeoPoint()), the xxxxSource.vector_t # fill in a startingpoint for result{'tempeature':xxxxSourve.vector_t} etc ts_to_geo_ts_info = dict() ens_result = [ ] #when done, it's filled with n_ensembles of 'result' dictionaries, one for each ensemble-member # get out the dimension of the ensemble from ens_station_list, .. each station needs the same number of ens.members.., otherwise in trouble.. # because we need correlated temperature/precipitation/radiation (each of them belong to a certain ens.member). for i in range(self.ens_config.n_ensembles): result = {} for attr_name in input_source_types: # we have selected the attr_name and the MetStationConfig with care, so attr_name corresponds to each member in MetStationConfig result[attr_name] = self.source_type_map[attr_name].vector_t( ) # create an empty vector of requested type, we fill in the read-result geo-ts stuff when we are done reading ts_to_geo_ts_info.update({ k: v for k, v in # ts-name , (temperature, geopoint , ens result ( [ getattr(x, attr_name)(i), (attr_name, api.GeoPoint(*geo_loc[x.gis_id]), result) ] #this constructs a key,value list from the result below for x in self.ens_config.station_list if getattr(x, attr_name) is not None and geo_match(geo_loc[x.gis_id]) ) #this get out the matching station.attribute }) ens_result.append(result) # add this ens to the result. return ts_to_geo_ts_info, ens_result
def _geo_ts_to_vec(self, data, pts): res = {} for name, ts in iteritems(data): tpe = self.source_type_map[name] res[name] = tpe.vector_t([tpe(api.GeoPoint(*pts[idx]), ts[idx]) for idx in np.ndindex(pts.shape[:-1])]) return res
def _create_geo_forecast_set(self, n_fc, t0, dt, n_steps, dt_fc, fx): """ Parameters ---------- n_fc : int number of forecasts, e.g. 8 t0 : utctime start of first forecast dt : utctimespan delta t for forecast-ts n_steps : number of steps in one forecast-ts dt_fc : utctimespan delta t between each forecast, like deltahours(6) fx : lambda time_axis: a function returning a DoubleVector with values for the supplied time-axis Returns ------- api.TemperatureSourceVector() """ fc_set = api.TemperatureSourceVector() geo_point = api.GeoPoint( 0.0, 0.0, 0.0) # any point will do, we just reuse the geo-ts for i in range(n_fc): ta = api.Timeaxis2(t0 + i * dt_fc, dt, n_steps) ts = api.Timeseries( ta=ta, values=fx(ta), point_fx=api.point_interpretation_policy.POINT_AVERAGE_VALUE) geo_ts = api.TemperatureSource(geo_point, ts) fc_set.append(geo_ts) return fc_set
def _get_ts_to_geo_ts_result(self, input_source_types, geo_match): """ given the input-sources (temp,precip etc), and a geo-match, return back tsname->geopos, plus a result structure dict ready to add on the read ts""" # 1 get the station-> location map station_ids = [x.gis_id for x in self.met_station_list] geo_loc = self.geo_location_repository.get_locations( location_id_list=station_ids, epsg_id=self.epsg_id) # 2 create map ts-id to tuple (attr_name,GeoPoint()), the xxxxSource.vector_t # fill in a startingpoint for result{'tempeature':xxxxSourve.vector_t} etc ts_to_geo_ts_info = dict() result = {} for attr_name in input_source_types: # we have selected the attr_name and the MetStationConfig with care, so attr_name corresponds to each member in MetStationConfig result[attr_name] = self.source_type_map[attr_name].vector_t( ) # create an empty vector of requested type, we fill in the read-result geo-ts stuff when we are done reading ts_to_geo_ts_info.update({ k: v for k, v in ( [ getattr(x, attr_name), (attr_name, api.GeoPoint(*geo_loc[x.gis_id])) ] #this constructs a key,value list from the result below for x in self.met_station_list if getattr(x, attr_name) is not None and geo_match(geo_loc[x.gis_id]) ) #this get out the matching station.attribute }) return ts_to_geo_ts_info, result
def _create_geo_point_grid(self, nx: int, ny: int , dx: int)->api.GeoPointVector: gpv = api.GeoPointVector() for i in range(nx): for j in range(ny): z = self.max_elevation * (i + j) / (nx + ny) gpv.append(api.GeoPoint(i*dx, j*dx, z)) return gpv
def test_create_region_environment(self): cal = api.Calendar() time_axis = api.Timeaxis(cal.time(api.YMDhms(2015, 1, 1, 0, 0, 0)), api.deltahours(1), 240) re = self.create_dummy_region_environment(time_axis, api.GeoPoint(1000, 1000, 100)) self.assertIsNotNone(re) self.assertEqual(len(re.radiation), 1) self.assertAlmostEqual(re.radiation[0].ts.value(0), 300.0)
def _create_std_geo_cell_data(self): geo_point = api.GeoPoint(1, 2, 3) ltf = api.LandTypeFractions() ltf.set_fractions(0.2, 0.2, 0.1, 0.3) geo_cell_data = api.GeoCellData(geo_point, 1000.0**2, 0, 0.7, ltf) geo_cell_data.radiation_slope_factor = 0.7 return geo_cell_data
def test_can_run_ordinary_kriging_from_observation_sites_to_1km_grid(self): """ Somewhat more complex test, first do kriging of 1 timeseries out to grid (expect same values flat) then do kriging of 3 time-series out to the grid (expect different values, no real verification here since this is done elsewhere """ # arrange the test with a btk_parameter, a source grid and a destination grid ok_parameter = api.OKParameter(c=1.0,a=10.0*1000.0,cov_type=api.OKCovarianceType.EXPONENTIAL,z_scale=1.0) fx = lambda z: api.DoubleVector.from_numpy(np.zeros(self.n)) grid_1km_1 = self._create_geo_point_grid(self.mnx, self.mny, self.dx_model) grid_1km_3 = self._create_geo_point_grid(self.mnx, self.mny, self.dx_model) observation_sites = api.GeoPointSourceVector() ta_obs = api.TimeAxisFixedDeltaT(self.t, self.d * 3, int(self.n / 3)) ta_grid = api.TimeAxisFixedDeltaT(self.t, self.d, self.n) point_fx = api.point_interpretation_policy.POINT_AVERAGE_VALUE ts_site_1 = api.TimeSeries(ta_obs, values=api.DoubleVector.from_numpy( (1.0) + 0.1 * np.sin(np.arange(start=0, stop=ta_obs.size(), step=1) * 2 * np.pi / 8.0 - np.pi / 2.0)), point_fx=point_fx) ts_site_2 = api.TimeSeries(ta_obs, values=api.DoubleVector.from_numpy( (0.8) + 0.2 * np.sin(np.arange(start=0, stop=ta_obs.size(), step=1) * 2 * np.pi / 8.0 - np.pi / 2.0)), point_fx=point_fx) ts_site_3 = api.TimeSeries(ta_obs, values=api.DoubleVector.from_numpy( (1.2) + 0.1 * np.sin(np.arange(start=0, stop=ta_obs.size(), step=1) * 2 * np.pi / 8.0 - np.pi / 2.0)), point_fx=point_fx) observation_sites.append(api.GeoPointSource(api.GeoPoint(50.0, 50.0, 5.0), ts_site_1)) # act 1: just one time-series put into the system, should give same ts (true-averaged) in all the grid-1km_ts (which can be improved using std.gradient..) grid_1km_1ts = api.ordinary_kriging(observation_sites, grid_1km_1, ta_grid, ok_parameter) # assert 1: self.assertEqual(len(grid_1km_1ts), self.mnx * self.mny) expected_grid_1ts_values = ts_site_1.average(api.TimeAxis(ta_grid)).values.to_numpy() for gts in grid_1km_1ts: self.assertEqual(gts.ts.size(), ta_grid.size()) self.assertTrue(np.allclose(expected_grid_1ts_values, gts.ts.values.to_numpy())) observation_sites.append(api.GeoPointSource(api.GeoPoint(9000.0, 500.0, 500), ts_site_2)) observation_sites.append(api.GeoPointSource(api.GeoPoint(9000.0, 12000.0, 1050.0), ts_site_3)) ok_parameter.cov_type= api.OKCovarianceType.GAUSSIAN # just to switch covariance formula grid_1km_3ts = api.ordinary_kriging(observation_sites, grid_1km_3, ta_grid, ok_parameter) self.assertEqual(len(grid_1km_3ts), self.mnx * self.mny) for gts in grid_1km_3ts: self.assertEqual(gts.ts.size(), ta_grid.size()) self.assertFalse(np.allclose(expected_grid_1ts_values, gts.ts.values.to_numpy()))
def test_source_uid(self): cal = api.Calendar() time_axis = api.TimeAxisFixedDeltaT(cal.time(api.YMDhms(2015, 1, 1, 0, 0, 0)), api.deltahours(1), 240) mid_point = api.GeoPoint(1000, 1000, 100) precip_source = self._create_constant_geo_ts(api.PrecipitationSource, mid_point, time_axis.total_period(), 5.0) self.assertIsNotNone(precip_source.uid) precip_source.uid = 'abc' self.assertEqual(precip_source.uid, 'abc')
def _create_geo_ts_grid(self, nx: int, ny: int, dx: int, fx, arome_grid, source_construct): for i in range(nx): for j in range(ny): z = self.max_elevation * (i + j) / (nx + ny) ts = api.TimeSeries(ta=self.ta, values=fx(z), point_fx=api.point_interpretation_policy.POINT_AVERAGE_VALUE) geo_ts = source_construct(api.GeoPoint(i * dx, j * dx, z), ts) arome_grid.append(geo_ts) return arome_grid
def test_geopoint_vector(self): gpv = api.GeoPointVector() for i in range(5): gpv.append(api.GeoPoint(i, i * 2, i * 3)) self.assertEqual(len(gpv), 5) for i in range(5): self.assertEqual(gpv[i].x, i) self.assertEqual(gpv[i].y, i * 2) self.assertEqual(gpv[i].z, i * 3)
def test_create(self): p = api.GeoPoint(100, 200, 300) ltf = api.LandTypeFractions() ltf.set_fractions(glacier=0.1, lake=0.1, reservoir=0.1, forest=0.1) self.assertAlmostEqual(ltf.unspecified(), 0.6) gcd = api.GeoCellData(p, 1000000.0, 1, 0.9, ltf) self.assertAlmostEqual(gcd.area(), 1000000) self.assertAlmostEqual(gcd.catchment_id(), 1)
def _geo_ts_to_vec(self, data, pts): res = {} for name, ts in data.items(): tpe = self.source_type_map[name] tpe_v = tpe.vector_t() for idx in np.ndindex(pts.shape[:-1]): tpe_v.append(tpe(api.GeoPoint(*pts[idx]), ts[idx])) res[name] = tpe_v return res
def test_create_region_environment(self): cal = api.Calendar() time_axis = api.TimeAxisFixedDeltaT(cal.time(api.YMDhms(2015, 1, 1, 0, 0, 0)), api.deltahours(1), 240) re = self.create_dummy_region_environment(time_axis, api.GeoPoint(1000, 1000, 100)) self.assertIsNotNone(re) self.assertEqual(len(re.radiation), 1) self.assertAlmostEqual(re.radiation[0].ts.value(0), 300.0) vv = re.radiation.values_at_time(time_axis.time(0)) # verify .values_at_time(t) self.assertEqual(len(vv), len(re.radiation)) self.assertAlmostEqual(vv[0], 300.0)
def test_region_environment_variable_list(self): """ just to verify ARegionEnvironment.variables container exposed to ease scripting""" cal = api.Calendar() time_axis = api.TimeAxisFixedDeltaT(cal.time(2015, 1, 1, 0, 0, 0), api.deltahours(1), 240) e = self.create_dummy_region_environment(time_axis, api.GeoPoint(0.0, 1.0, 2.0)) self.assertIsNotNone(e) self.assertEqual(len(e.variables), 5) for v in e.variables: self.assertIsNotNone(v[1]) self.assertEqual(getattr(e, v[0])[0].mid_point_, v[1][0].mid_point_) # equivalent, just check first midpoint self.assertEqual(getattr(e, v[0])[0].ts.value(0), v[1][0].ts.value(0)) # and value
def test_geo_cell_data_vector(self): gcdv = api.GeoCellDataVector() for i in range(5): p = api.GeoPoint(100, 200, 300) ltf = api.LandTypeFractions() ltf.set_fractions(glacier=0.1, lake=0.1, reservoir=0.1, forest=0.1) gcd = api.GeoCellData(p, 1000000.0, i, 0.9, ltf) gcdv.append(gcd) self.assertEqual(len(gcdv), 5) for i in range(5): self.assertEqual(gcdv[i].catchment_id(), i)
def _geo_ts_to_vec(self, data, pts): res = {} for name, ts in iteritems(data): tpe = self.source_type_map[name] # YSA: It seems that the boost-based interface does not handle conversion straight from list of non-primitive objects #res[name] = tpe.vector_t([tpe(api.GeoPoint(*pts[idx]), # ts[idx]) for idx in np.ndindex(pts.shape[:-1])]) tpe_v = tpe.vector_t() for idx in np.ndindex(pts.shape[:-1]): tpe_v.append(tpe(api.GeoPoint(*pts[idx]), ts[idx])) res[name] = tpe_v return res
def _create_geo_precipitation_grid(self, nx, ny, dx, fx): arome_grid = api.PrecipitationSourceVector() for i in range(nx): for j in range(ny): z = self.max_elevation * (i + j) / (nx + ny) ts = api.Timeseries(ta=self.ta, values=fx(z), point_fx=api.point_interpretation_policy. POINT_AVERAGE_VALUE) geo_ts = api.PrecipitationSource( api.GeoPoint(i * dx, j * dx, z), ts) arome_grid.append(geo_ts) return arome_grid
def _geo_ts_to_vec(self, data, pts): res = {} for name, ts in data.items(): tpe = self.source_type_map[name] # SiH: Unfortunately, I have not got the boost.python to eat list of non-basic object # into the constructor of vectors like this: # res[name] = tpe.vector_t([tpe(api.GeoPoint(*pts[idx]), ts[idx]) for idx in np.ndindex(pts.shape[:-1])]) # so until then, we have to do the loop tpe_v = tpe.vector_t() for idx in range(len(ts)): tpe_v.append(tpe(api.GeoPoint(*pts[idx]), ts[idx])) res[name] = tpe_v return res
def _geo_ts_to_vec(self, data, pts): res = {} for name, ts in iteritems(data): if name in self.source_type_map.keys(): tpe = self.source_type_map[name] geo_ts_list = tpe.vector_t() for idx in np.ndindex(pts.shape[:-1]): geo_ts = tpe(api.GeoPoint(*pts[idx]), ts[idx]) geo_ts_list.append(geo_ts) res[name] = geo_ts_list else: vct = self.vector_type_map[name] res[name] = vct(ts) return res
def build_model(model_t, parameter_t, model_size, num_catchments=1): cell_area = 1000 * 1000 region_parameter = parameter_t() gcds = api.GeoCellDataVector() # creating models from geo_cell-data is easier and more flexible for i in range(model_size): gp = api.GeoPoint(500+ 1000.0*i,500.0, 500.0*i/model_size) cid = 0 if num_catchments > 1: cid = random.randint(1, num_catchments + 1) geo_cell_data = api.GeoCellData(gp, cell_area, cid, 0.9, api.LandTypeFractions(0.01, 0.05, 0.19, 0.3, 0.45)) geo_cell_data.land_type_fractions_info().set_fractions(glacier=0.01, lake=0.05, reservoir=0.19, forest=0.3) gcds.append(geo_cell_data) return model_t(gcds, region_parameter)
def test_create_source_vector_does_not_leak(self): n = 365 * 24 * 1 # 1st checkpoint memory here, for i in range(10): v = api.TemperatureSourceVector([ api.TemperatureSource( api.GeoPoint(0.0, 1.0, 2.0), api.TimeSeries(api.TimeAxis(api.time(0), api.time(3600), n), fill_value=float(x), point_fx=api.POINT_AVERAGE_VALUE)) for x in range(n) ]) self.assertIsNotNone(v) del v pass # 2nd mem check here, should be approx same as first checkpoint
def test_create(self): p = api.GeoPoint(100, 200, 300) ltf = api.LandTypeFractions() ltf.set_fractions(glacier=0.1, lake=0.1, reservoir=0.1, forest=0.1) self.assertAlmostEqual(ltf.unspecified(), 0.6) routing_info = api.RoutingInfo(2, 12000.0) gcd = api.GeoCellData(p, 1000000.0, 1, 0.9, ltf, routing_info) self.assertAlmostEqual(gcd.area(), 1000000) self.assertAlmostEqual(gcd.catchment_id(), 1) self.assertAlmostEqual(gcd.routing_info.distance, 12000.0) self.assertAlmostEqual(gcd.routing_info.id, 2) gcd.routing_info.distance = 13000.0 gcd.routing_info.id = 3 self.assertAlmostEqual(gcd.routing_info.distance, 13000.0) self.assertAlmostEqual(gcd.routing_info.id, 3)
def build_model(model_t, parameter_t, model_size, num_catchments=1): cells = model_t.cell_t.vector_t() cell_area = 1000 * 1000 region_parameter = parameter_t() for i in range(model_size): loc = (10000 * random.random(2)).tolist() + ( 500 * random.random(1)).tolist() gp = api.GeoPoint(*loc) geo_cell_data = api.GeoCellData(gp, cell_area, random.randint(0, num_catchments)) geo_cell_data.land_type_fractions_info().set_fractions( glacier=0.0, lake=0.0, reservoir=0.1, forest=0.1) cell = model_t.cell_t() cell.geo = geo_cell_data cells.append(cell) return model_t(cells, region_parameter)
def get_timeseries(self, input_source_types, utc_period, geo_location_criteria=None): """Method for fetching the sources in NetCDF files. Parameters ---------- input_source_types: list List of source types to retrieve (precipitation, temperature..) geo_location_criteria: bbox + proj.ref ? utc_period : of type UtcPeriod Returns ------- data: dict Shyft.api container for geo-located time series. Types are found from the input_source_type.vector_t attribute. """ data = dict() # Fill the data with actual values for input_source in input_source_types: api_source_type = self.source_type_map[input_source] ts = self._fetch_station_tseries(input_source, self._params['types'], utc_period) assert type(ts) is list tsf = api.TsFactory() acc_data = api_source_type.vector_t() for station in ts: times = station['time'] assert type(times) is list dt = times[1] - times[0] if len(times) > 1 else api.deltahours( 1) total_period = api.UtcPeriod(times[0], times[-1] + dt) time_points = api.UtcTimeVector(times) time_points.push_back(total_period.end) values = station['values'] value_points = api.DoubleVector.FromNdArray(values) api_ts = tsf.create_time_point_ts(total_period, time_points, value_points) data_source = api_source_type( api.GeoPoint(*station['location']), api_ts) acc_data.append(data_source) data[input_source] = acc_data return data
def build_model(model_t, parameter_t, model_size, num_catchments=1): cells = model_t.cell_t.vector_t() cell_area = 1000 * 1000 region_parameter = parameter_t() for i in range(model_size): loc = (10000 * random.random(2)).tolist() + (500 * random.random(1)).tolist() gp = api.GeoPoint(*loc) cid = 0 if num_catchments>1: cid = random.randint(1,num_catchments) geo_cell_data = api.GeoCellData(gp, cell_area,cid,0.9,api.LandTypeFractions(0.01, 0.05, 0.19, 0.3, 0.45)) # geo_cell_data.land_type_fractions_info().set_fractions(glacier=0.01, lake=0.05, reservoir=0.19, forest=0.3) cell = model_t.cell_t() cell.geo = geo_cell_data cells.append(cell) return model_t(cells, region_parameter)
def test_geo_cell_data_vector(self): gcdv = api.GeoCellDataVector() for i in range(5): p = api.GeoPoint(100, 200, 300) ltf = api.LandTypeFractions() ltf.set_fractions(glacier=0.1, lake=0.1, reservoir=0.1, forest=0.1) gcd = api.GeoCellData(p, 1000000.0, i, 0.9, ltf) gcdv.append(gcd) self.assertEqual(len(gcdv), 5) for i in range(5): self.assertEqual(gcdv[i].catchment_id(), i) g2 = api.GeoCellDataVector(gcdv) # copy construct a new self.assertTrue(g2 == gcdv) g2[0].set_catchment_id(10) self.assertTrue(g2 != gcdv) # serialize gcdv_s= gcdv.serialize() self.assertGreater(len(gcdv_s),2) gcdv_deserialized = api.GeoCellDataVector.deserialize(gcdv_s) self.assertIsNotNone(gcdv_deserialized) self.assertTrue(gcdv_deserialized == gcdv)