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
del exposure_tmp grid_stats.to_csv( os.path.join( RES_DIR, 'LitPop_pc_%iarcsec_%i_grid_stats.csv' % (RES_ARCSEC, REF_YEAR))) grid_stats.to_csv( os.path.join( ENTITY_DIR, 'LitPop_pc_%iarcsec_%i_grid_stats.csv' % (RES_ARCSEC, REF_YEAR))) exposure_data = Exposures(exposure_data) print('\n' + '\x1b[1;03;30;30m' + 'exposure_data is now an Exposures:', str(type(exposure_data)) + '\x1b[0m') exposure_data.set_geometry_points( ) # set geometry attribute (shapely Points) from GeoDataFrame from latitude and longitude print('\n' + '\x1b[1;03;30;30m' + 'check method logs:' + '\x1b[0m') exposure_data.check() # puts metadata that has not been assigned print('\n' + '\x1b[1;03;30;30m' + 'exposure_data looks like:' + '\x1b[0m') print(exposure_data.head()) print('\n' + '\x1b[1;03;30;30m' + 'plotting global map...' + '\x1b[0m') print('Global max. grid cell value: USD %1.0f' % (exposure_data.value.max())) print('Global mean grid cell value: USD %1.0f' % (exposure_data.value.mean())) print('Global median grid cell value: USD %1.0f' % (exposure_data.value.median())) if write_to_hdf5: exposure_data.write_hdf5( os.path.join(ENTITY_DIR, 'LitPop_pc_%iarcsec_000_all.hdf5' % (RES_ARCSEC)))