def test_calc_admin1(self): """test function _calc_admin1 for Switzerland. All required functions are tested in unit tests""" resolution = 300 curr_country = 'CHE' country_info = dict() admin1_info = dict() country_info[curr_country], admin1_info[curr_country] = \ lp._get_country_info(curr_country) curr_shp = lp._get_country_shape(curr_country, 0) for cntry_iso, cntry_val in country_info.items(): _, total_asset_val = lp.gdp(cntry_iso, 2016, curr_shp) cntry_val.append(total_asset_val) lp._get_gdp2asset_factor(country_info, 2016, curr_shp, fin_mode='gdp') cut_bbox = lp._get_country_shape(curr_country, 1)[0] all_coords = lp._litpop_box2coords(cut_bbox, resolution, 1) mask = lp._mask_from_shape(curr_shp, resolution=resolution,\ points2check=all_coords) litpop_data = lp._get_litpop_box(cut_bbox, resolution, 0, 2016, \ [3, 0]) litpop_curr = litpop_data[mask.sp_index.indices] lon, lat = zip(*np.array(all_coords)[mask.sp_index.indices]) litpop_curr = lp._calc_admin1(curr_country, country_info[curr_country],\ admin1_info[curr_country], litpop_curr,\ list(zip(lon, lat)), resolution, 0, conserve_cntrytotal=0, \ check_plot=0, masks_adm1=[], return_data=1) self.assertEqual(len(litpop_curr), 699) self.assertAlmostEqual(max(litpop_curr), 80178713117.21936, places=3)
def test_litpop_box2coords(self): """test function _litpop_box2coords for Taiwan""" curr_country = 'TWN' resolution = 3000 cut_bbox = lp._get_country_shape(curr_country, 1)[0] all_coords = lp._litpop_box2coords(cut_bbox, resolution, 1) self.assertEqual(len(all_coords), 25) self.assertIn(_rnd(117.91666666666666) and _rnd(22.08333333333333),\ _rnd(min(all_coords)))
def test_get_litpop_box(self): """test functions _litpop_box2coords and _get_litpop_box for Taiwan""" curr_country = 'TWN' resolution = 3000 cut_bbox = lp._get_country_shape(curr_country, 1)[0] all_coords = lp._litpop_box2coords(cut_bbox, resolution, 1) self.assertEqual(len(all_coords), 25) self.assertTrue(117.91666666666666 and 22.08333333333333 in min(all_coords)) litpop_data = lp._get_litpop_box(cut_bbox, resolution, 0, 2016, [1, 1]) self.assertEqual(len(litpop_data), 25) self.assertIn(max(litpop_data), [544316890, 594091108.0, 594091108])