def fill_econ_indicators(ref_year, cntry_info, shp_file, **kwargs): """Get GDP and income group per country in reference year, or it closest one. Source: world bank. Natural earth repository used when missing data. Modifies country info with values [country id, country name, country geometry, ref_year, gdp, income_group]. Parameters: ref_year (int): reference year cntry_info (dict): key = ISO alpha_3 country, value = [country id, country name, country geometry] kwargs (optional): 'gdp' and 'inc_grp' dictionaries with keys the country ISO_alpha3 code. If provided, these are used """ for cntry_iso, cntry_val in cntry_info.items(): cntry_val.append(ref_year) if 'gdp' in kwargs and kwargs['gdp'][cntry_iso] != '': gdp_val = kwargs['gdp'][cntry_iso] else: _, gdp_val = gdp(cntry_iso, ref_year, shp_file) cntry_val.append(gdp_val) if 'inc_grp' in kwargs and kwargs['inc_grp'][cntry_iso] != '': inc_grp = kwargs['inc_grp'][cntry_iso] else: _, inc_grp = income_group(cntry_iso, ref_year, shp_file) cntry_val.append(inc_grp)
def test_switzerland300_pass(self): """Create LitPop entity for Switzerland on 300 arcsec:""" country_name = ['CHE'] resolution = 300 fin_mode = 'income_group' with self.assertLogs('climada.entity.exposures.litpop', level='INFO') as cm: ent = lp.LitPop.from_countries(country_name, res_arcsec=resolution, fin_mode=fin_mode, reference_year=2016) self.assertIn('LitPop: Init Exposure for country: CHE', cm.output[0]) self.assertEqual(ent.gdf.region_id.min(), 756) self.assertEqual(ent.gdf.region_id.max(), 756) # confirm that the total value is equal to GDP * (income_group+1): self.assertAlmostEqual(ent.gdf.value.sum() / gdp('CHE', 2016)[1], (income_group('CHE', 2016)[1] + 1)) self.assertIn("LitPop Exposure for ['CHE'] at 300 as, year: 2016", ent.tag.description) self.assertIn('income_group', ent.tag.description) self.assertIn('1, 1', ent.tag.description) self.assertTrue(u_coord.equal_crs(ent.crs, 'epsg:4326')) self.assertEqual(ent.meta['width'], 54) self.assertEqual(ent.meta['height'], 23) self.assertTrue(u_coord.equal_crs(ent.meta['crs'], 'epsg:4326')) self.assertAlmostEqual(ent.meta['transform'][0], 0.08333333333333333) self.assertAlmostEqual(ent.meta['transform'][1], 0) self.assertAlmostEqual(ent.meta['transform'][2], 5.9166666666666) self.assertAlmostEqual(ent.meta['transform'][3], 0) self.assertAlmostEqual(ent.meta['transform'][4], -0.08333333333333333) self.assertAlmostEqual(ent.meta['transform'][5], 47.75)
def test_income_grp_sxm_1999_pass(self): """ Test income_group function Sint Maarten.""" ref_year = 1999 with self.assertLogs('climada.util.finance', level='INFO') as cm: res_year, res_val = income_group('SXM', ref_year, SHP_FILE) ref_year = 2010 ref_val = 4 self.assertIn('Income group SXM 2010: 4.', cm.output[0]) self.assertEqual(res_year, ref_year) self.assertEqual(res_val, ref_val)
for coeff in coeff_types: all_coeffs.append(coeff + '_' + meth) cc = cc + 1 # indicies of each skill metric: rp_i = np.arange(0, cc, len(coeff_types)) rs_i = np.arange(1, cc, len(coeff_types)) rmse_i = np.arange(2, cc, len(coeff_types)) rmsf_i = np.arange(3, cc, len(coeff_types)) colors3 = ['#1b9e77', '#7570b3', '#d95f02'] c3_10 = [0, 0, 0, 0, 0, 1, 1, 2, 2, 2] income_groups = list() for cntry in countries: income_groups.append(income_group(cntry, 2016)[1]) if compute_validation: """computation of normalized Gross Regional Product nGRP, skill metrics, and make scatter plots""" rho = dict() adm0 = dict() adm1 = dict() # loop over countries, computing nGRP and skill for i in countries_sel: print('*** ' + countries[i] + ' *** ') start_time_c = time.time() rho[countries[i]], adm0[countries[i]], adm1[countries[i]] =\ lp.admin1_validation(countries[i], methods, exponents_list, \ res_arcsec=resolution, check_plot=False)