示例#1
0
 def test_switzerland300_pc2016_pass(self):
     """Create LitPop entity for Switzerland 2016 with admin1 and produced capital:"""
     country_name = ['CHE']
     fin_mode = 'pc'
     resolution = 300
     ref_year = 2016
     adm1 = True
     cons = True
     comparison_total_val = world_bank_wealth_account(country_name[0],
                                                      ref_year,
                                                      no_land=1)[1]
     ent = LitPop()
     with self.assertLogs('climada.entity.exposures.litpop',
                          level='INFO') as cm:
         ent.set_country(country_name,
                         res_arcsec=resolution,
                         reference_year=ref_year,
                         fin_mode=fin_mode,
                         conserve_cntrytotal=cons,
                         calc_admin1=adm1)
     # print(cm)
     self.assertIn('Generating LitPop data at a resolution of 300 arcsec',
                   cm.output[0])
     self.assertEqual(np.around(ent.gdf.value.sum(), 0),
                      np.around(comparison_total_val, 0))
     self.assertAlmostEqual(ent.gdf.value.sum() / 2225854927260, 1.0)
示例#2
0
 def test_switzerland300_pass(self):
     """Create LitPop entity for Switzerland on 300 arcsec:"""
     country_name = ['CHE']
     resolution = 300
     fin_mode = 'income_group'
     ent = LitPop()
     with self.assertLogs('climada.entity.exposures.litpop',
                          level='INFO') as cm:
         ent.set_country(country_name,
                         res_arcsec=resolution,
                         fin_mode=fin_mode)
     # print(cm)
     self.assertIn('Generating LitPop data at a resolution of 300 arcsec',
                   cm.output[0])
     self.assertTrue(ent.region_id.min() == 756)
     self.assertTrue(ent.region_id.max() == 756)
     self.assertTrue(np.int(ent.value.sum().round()) == 3350905328146)
     self.assertIn('LitPop for Switzerland at 300 as, year=2016',
                   ent.tag.description)
     self.assertIn('financial mode=income_group', ent.tag.description)
     self.assertIn('GPW-year=2015', ent.tag.description)
     self.assertIn('BM-year=2016', ent.tag.description)
     self.assertIn('exp=[1, 1]', ent.tag.description)
     self.assertTrue(equal_crs(ent.crs['init'], {'init': 'epsg:4326'}))
     self.assertEqual(ent.meta['width'], 54)
     self.assertEqual(ent.meta['height'], 23)
     self.assertTrue(equal_crs(ent.meta['crs'], {'init': '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.7499999999999)
示例#3
0
def get_entity(country, exponents, description_str, date_str):

    file_name = (country + '_litpop_' + description_str + '_' + date_str +
                 '.hdf5')
    exposure_file = os.path.abspath(os.path.join( \
                CONFIG['local_data']['save_dir'], file_name))
    if os.path.isfile(exposure_file):
        exposure = LitPop()
        exposure.read_hdf5(exposure_file)


#        with open(exposure_file, 'rb') as f:
#            exposure = pickle.load(f)
    else:
        exposure = LitPop()
        # The arguments 'exponent' is used to set the power with which Lit and Pop go into LitPop:
        exposure.set_country(country, exponents=exponents, reference_year=2014)
        exposure.set_geometry_points()
        exposure.check()
        exposure.tag.description = (exposure.tag.description + '_' +
                                    description_str)
        exposure.set_lat_lon()
        exposure.write_hdf5(exposure_file)
        #pickle.dump(exposure,open(exposure_file, 'wb'))
    return exposure
示例#4
0
 def test_exposure_set_admin1_BGD(self):
     """Test function exposure_set_admin1 of litpop for Bangladesh"""
     country_name = ['BGD']
     resolution = 600
     ent = LitPop()
     ent.set_country(country_name, res_arcsec=resolution)
     ent = lp.exposure_set_admin1(ent, 600)
     self.assertIn(5492, ent.admin1_ID.values)
     self.assertIn('Chittagong', ent.admin1.values)
     self.assertEqual(len(np.unique(ent.admin1_ID)), 7)
     self.assertEqual(np.min(np.unique(ent.admin1_ID)), 1806.0)
示例#5
0
 def test_suriname30_nfw_pass(self):
     """Create LitPop entity for Suriname for non-finanical wealth:"""
     country_name = ['SUR']
     fin_mode = 'nfw'
     ent = LitPop()
     with self.assertLogs('climada.entity.exposures.litpop',
                          level='INFO') as cm:
         ent.set_country(country_name,
                         reference_year=2016,
                         fin_mode=fin_mode)
     # print(cm)
     self.assertIn('Generating LitPop data at a resolution of 30.0 arcsec',
                   cm.output[0])
     self.assertTrue(ent.region_id.min() == 740)
     self.assertTrue(ent.region_id.max() == 740)
     self.assertTrue(np.int(ent.value.sum().round()) == 2332806589)
示例#6
0
 def test_switzerland30normPop_pass(self):
     """Create LitPop entity for Switzerland on 30 arcsec:"""
     country_name = ['CHE']
     resolution = 30
     exp = [0, 1]
     fin_mode = 'norm'
     ent = LitPop()
     with self.assertLogs('climada.entity.exposures.litpop',
                          level='INFO') as cm:
         ent.set_country(country_name, res_arcsec=resolution, exponent=exp,\
                         fin_mode=fin_mode, reference_year=2015)
     # print(cm)
     self.assertIn('Generating LitPop data at a resolution of 30 arcsec',
                   cm.output[0])
     self.assertTrue(ent.region_id.min() == 756)
     self.assertTrue(ent.region_id.max() == 756)
     self.assertTrue(np.int((1000 * ent.value.sum()).round()) == 1000)
示例#7
0
 def test_switzerland300_pc2013_pass(self):
     """Create LitPop entity for Switzerland 2013 for produced capital:"""
     country_name = ['CHE']
     fin_mode = 'pc'
     resolution = 300
     ref_year = 2013
     comparison_total_val = world_bank_wealth_account(country_name[0], \
                                                      ref_year, no_land=1)[1]
     ent = LitPop()
     with self.assertLogs('climada.entity.exposures.litpop',
                          level='INFO') as cm:
         ent.set_country(country_name, res_arcsec=resolution, \
                         reference_year=ref_year, fin_mode=fin_mode)
     # print(cm)
     self.assertIn('Generating LitPop data at a resolution of 300 arcsec',
                   cm.output[0])
     self.assertTrue(ent.value.sum() == comparison_total_val)
     self.assertTrue(np.int(ent.value.sum().round()) == 2296358085749)
示例#8
0
def _get_litpop_bbox(country, highValueArea, **kwargs):
    """get litpop exposure for the bbox area of the queried OSM features
    Parameters:
        country (str)
        highValueArea (GeoDataFrame)
        bbox (array)
        kwargs (dict): arguments for LitPop set_country method
    Returns:
        exp_sub (LitPop)
    """
    # Load LitPop Exposure for whole country, and High Value Area
    exp = LitPop()
    exp.set_country(country, **kwargs)
    exp.set_geometry_points()

    # Crop bbox of High Value Area from Country Exposure
    exp.gdf = exp.gdf.cx[min(highValueArea.bounds.minx):max(highValueArea.bounds.maxx),
                         min(highValueArea.bounds.miny):max(highValueArea.bounds.maxy)]

    return exp
示例#9
0
 def test_switzerland300_pass(self):
     """Create LitPop entity for Switzerland on 300 arcsec:"""
     country_name = ['CHE']
     resolution = 300
     fin_mode = 'income_group'
     ent = LitPop()
     with self.assertLogs('climada.entity.exposures.litpop',
                          level='INFO') as cm:
         ent.set_country(country_name,
                         res_arcsec=resolution,
                         fin_mode=fin_mode)
     # print(cm)
     self.assertIn('Generating LitPop data at a resolution of 300 arcsec',
                   cm.output[0])
     self.assertTrue(ent.region_id.min() == 756)
     self.assertTrue(ent.region_id.max() == 756)
     self.assertTrue(np.int(ent.value.sum().round()) == 3350905328146)
     self.assertIn('LitPop for Switzerland at 300 as, year=2016',
                   ent.tag.description)
     self.assertIn('financial mode=income_group', ent.tag.description)
     self.assertIn('GPW-year=2015', ent.tag.description)
     self.assertIn('BM-year=2016', ent.tag.description)
     self.assertIn('exp=[1, 1]', ent.tag.description)