Esempio n. 1
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
    )  # 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)))

ax_exp = exposure_data.plot_hexbin(pop_name=False,
                                   cmap='plasma',
                                   norm=LogNorm(vmin=10,
                                                vmax=0.1 *
                                                exposure_data.value.max()))
if save_figures:
    plt.savefig(os.path.join(RES_DIR, 'LitPop_pc_%iarcsec_%i_world_map.pdf' % (RES_ARCSEC, REF_YEAR)), \
                  dpi=DPI, facecolor='w', edgecolor='w', \
                  orientation='portrait', papertype=None, format='pdf', \
                  transparent=False, bbox_inches=None, pad_inches=0.1, \
                  frameon=None, metadata=None)
    plt.savefig(os.path.join(RES_DIR, 'LitPop_pc_%iarcsec_%i_world_map.png' % (RES_ARCSEC, REF_YEAR)), \
                  dpi=DPI, facecolor='w', edgecolor='w', \