コード例 #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
コード例 #2
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
コード例 #3
0
        grid_stats.loc[idx, 'mean'] = exposure_tmp.value.mean()
        grid_stats.loc[idx, 'median'] = exposure_tmp.value.median()

    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,