def _combine_data(
         *,
         location_data: gpd.GeoDataFrame,
         population_data: pd.DataFrame=None,
         location_index='NUMBER',
         **kwargs
 ) -> gpd.GeoDataFrame:
     location_data = utils.split_plots(location_data, location_index)
     if isinstance(population_data, pd.DataFrame):
         location_data = location_data.set_index(location_index)
         location_data = location_data.join(population_data, **kwargs)
     return location_data
Beispiel #2
0
def join_viewpoints_to_split_islands(
        islands_df: GeoDataFrame,
        viewpoints: GeoDataFrame,
        split_islands: GeoDataFrame,
        output_path: str,
        overwrite: bool = False
) -> GeoDataFrame:
    if output_path and exists(output_path) and not overwrite:
        return gpd.read_file(output_path)
    else:
        jvp = viewpoints.join(split_islands[['FID_island']], on='FID', how='inner')
        jvp = jvp[['FID_island', 'Z', 'geometry']]
        ivp = jvp.join(islands_df, on='FID_island', rsuffix='_island')[
            ['FID_island', 'Z', 'geometry']]
        ivp.to_file(output_path)
        return ivp
Beispiel #3
0
        "winddirection_80m",
        "winddirection_100m",
        "winddirection_200m",
    ]

    gdf = GeoDataFrame().from_file("vector/h5_grid.shp")

    for dataset in datasets:
        logger.debug("Iterating over our target WTK datasets and flush the" +
                     "attributed results to disc as we go")
        if os.path.exists("vector/" + dataset + ".shp"):
            print("Existing file found (skipping): " + "vector/" + dataset +
                  ".shp")
        else:

            result = attribute_gdf_w_dataset(
                gdf,
                hour_interval=_HOURS_PER_MONTH,
                n_bootstrap_replicates=30,
                dataset=dataset,
            )

            result.columns = [
                dataset + "_" + str(n) for n in list(result.columns)
            ]
            result = gdf.join(result)

            result.to_file("vector/" + dataset + ".geojson", driver="GeoJSON")

            del result
Beispiel #4
0
def visualize_building_counts(dg: gpd.GeoDataFrame, osm: gpd.GeoDataFrame):
    # get n range 
    max_n = max(dg.num_buildings.max(), osm.num_buildings.max())
    min_n = 0
    
    # visualize num_buildings distribution
    fig, ax = plt.subplots(1, 2, sharey='row', sharex='col')
    bins = range(0, max_n + 1, 5000)
    dg.num_buildings.hist( ax = ax[0], bins = bins)
    osm.num_buildings.hist(ax = ax[1], bins = bins)
    ax[0].set_title("DigitalGlobe")
    ax[1].set_title("OpenStreetMap")
    fig.suptitle("Histogram of Per-Block Building Counts for Freetown, SL")
    plt.semilogy()
    # plt.savefig("n_histogram_sl.png", dpi=300, bbox_inches="tight")
    plt.show()

    # num_buildings choropleth 
    fig, ax = plt.subplots(1, 2, sharey='row', sharex='col')
    plot_opts = { 
        "column"   : "num_buildings",
        "cmap"     : "PiYG",
        # "scheme"   : "natural_breaks",
        "scheme"   : "User_Defined",
        "edgecolor": "grey",
        "linewidth": 0.1,
        "legend"   : True,
        "categorical" : False,
        "markersize" : 0,
        "classification_kwds" : {"bins" : [4270, 16922, 47521, 122413, 160779, max_n]} # numbers taken from natural_breaks
    }

    # dummy polygons to make choropleth color scheme consistent 
    dgd = gpd.GeoDataFrame(pd.concat([pd.DataFrame([ 
        ["d0", shapely.geometry.MultiPoint(osm.centroid).centroid, 0, [], 35], 
    ], columns = dg.columns), dg.copy()]).reset_index(), geometry = "block_geom")

    dgd.plot(ax=ax[0],  **plot_opts)
    ax[0].get_xaxis().set_visible(False)
    ax[0].axes.get_yaxis().set_visible(False)

    # osmd.plot(ax=ax[1], **plot_opts)
    osm.plot(ax=ax[1], **plot_opts)
    ax[1].get_xaxis().set_visible(False)
    ax[1].axes.get_yaxis().set_visible(False)
    plt.subplots_adjust(left = 0.02, bottom = 0.02, right = 0.98, top = 0.98, wspace = 0.10)
    ax[0].set_title("DigitalGlobe")
    ax[1].set_title("OpenStreetMap")
    fig.suptitle("Building Count Choropleth for Freetown, SL")
    # plt.savefig("n_choropleth_sl.png", dpi=300, bbox_inches="tight")
    plt.show()

    # get block-by-block diff of k values
    diff = dg.join(osm, rsuffix="_osm")
    diff["delta_n"] = diff["num_buildings"] - diff["num_buildings_osm"]
    diff.plot("delta_n", legend=True)#, cmap="PRGn", scheme = "natural_breaks", missing_kwds={"color": "lightgrey"})
    plt.gca().get_xaxis().set_visible(False)
    plt.gca().axes.get_yaxis().set_visible(False)
    plt.title(r'Block-by-block Difference in Building Count ($n_{DG} - n_{OSM}$)')
    plt.subplots_adjust(left = 0.02, bottom = 0.02, right = 0.98, top = 0.88, wspace = 0.10)
    # plt.savefig("delta_n_choropleth_sl.png", dpi=300, bbox_inches="tight")
    plt.show()
Beispiel #5
0
def visualize_complexity(dg: gpd.GeoDataFrame, osm: gpd.GeoDataFrame):
    # get k range 
    max_k = max(dg.complexity.max(), osm.complexity.max())
    min_k = 0
    
    # visualize complexity distribution
    fig, ax = plt.subplots(1, 2, sharey='row', sharex='col')
    bins = range(0, max_k + 1, 1)
    dg.complexity.hist( ax = ax[0], bins = bins)
    osm.complexity.hist(ax = ax[1], bins = bins)
    ax[0].set_title("DigitalGlobe")
    ax[1].set_title("OpenStreetMap")
    fig.suptitle("Histogram of $k$-values for Freetown, SL")
    plt.semilogy()
    # plt.savefig("k_histogram_sl.png", dpi=300, bbox_inches="tight")
    plt.show()

    # complexity choropleth 
    fig, ax = plt.subplots(1, 2, sharey='row', sharex='col')
    plot_opts = { 
        "column"   : "complexity",
        "cmap"     : mnp_palette,
        # "scheme"   : "natural_breaks",
        "scheme"   : "User_Defined",
        "edgecolor": "grey",
        "linewidth": 0.1,
        "legend"   : True,
        "categorical" : False,
        "markersize" : 0,
        "classification_kwds" : {"bins" : [6, 15, 31, 76, max_k]} # numbers taken from natural_breaks
    }
    dg.plot( ax=ax[0],  **plot_opts)
    ax[0].get_xaxis().set_visible(False)
    ax[0].axes.get_yaxis().set_visible(False)

    # dummy polygons to make choropleth color scheme consistent 
    osmd = gpd.GeoDataFrame(pd.concat([pd.DataFrame([ 
        ["d0", shapely.geometry.MultiPoint(osm.centroid).centroid, 0,     [], 0], 
        ["d1", shapely.geometry.MultiPoint(osm.centroid).centroid, 2,     [], 0], 
        ["d2", shapely.geometry.MultiPoint(osm.centroid).centroid, 5,     [], 0], 
        ["d3", shapely.geometry.MultiPoint(osm.centroid).centroid, 19,    [], 0], 
        ["d4", shapely.geometry.MultiPoint(osm.centroid).centroid, max_k, [], 0] 
    ], columns = osm.columns), osm.copy()]).reset_index(), geometry = "block_geom")

    osmd.plot(ax=ax[1], **plot_opts)
    ax[1].get_xaxis().set_visible(False)
    ax[1].axes.get_yaxis().set_visible(False)
    plt.subplots_adjust(left = 0.02, bottom = 0.02, right = 0.98, top = 0.98, wspace = 0.10)
    ax[0].set_title("DigitalGlobe")
    ax[1].set_title("OpenStreetMap")
    fig.suptitle("Complexity Choropleth for Freetown, SL")
    # plt.savefig("k_choropleth_sl.png", dpi=300, bbox_inches="tight")
    plt.show()

    # get block-by-block diff of k values
    diff = dg.join(osm, rsuffix="_osm")
    diff["delta_k"] = diff["complexity"] - diff["complexity_osm"]
    diff.plot("delta_k", legend=True, cmap="PRGn", scheme = "natural_breaks", missing_kwds={"color": "lightgrey"})
    plt.gca().get_xaxis().set_visible(False)
    plt.gca().axes.get_yaxis().set_visible(False)
    plt.title(r'Block-by-block Difference in Complexity Measure ($k_{DG} - k_{OSM}$)')
    plt.subplots_adjust(left = 0.02, bottom = 0.02, right = 0.98, top = 0.88, wspace = 0.10)
    # plt.savefig("delta_k_choropleth_sl.png", dpi=300, bbox_inches="tight")
    plt.show()