示例#1
0
    def generate(self, bounds_polygon, raster_shape, resolution=30, hour: int = 8, **kwargs):
        risk_map, _ = self.make_strike_map(bounds_polygon, hour, raster_shape, resolution)

        bounds = bounds_polygon.bounds
        flipped_bounds = (bounds[1], bounds[0], bounds[3], bounds[2])
        risk_raster = gv.Image(risk_map, vdims=['strike_risk'], bounds=flipped_bounds).options(
            alpha=0.7,
            colorbar=True, colorbar_opts={'title': 'Person Strike Risk [h^-1]'},
            cmap='viridis',
            tools=['hover'],
            clipping_colors={
                'min': (0, 0, 0, 0)})
        import rasterio
        from rasterio import transform
        trans = transform.from_bounds(*flipped_bounds, *raster_shape)
        p = os.path.expanduser(f'~/GroundRiskMaps')
        if not os.path.exists(p):
            os.mkdir(p)
        rds = rasterio.open(p + f'/strike_risk_{hour}h_ac{hash(self.aircraft)}.tif',
                            'w', driver='GTiff', count=1, dtype=rasterio.float64, crs='EPSG:4326', transform=trans,
                            compress='lzw', width=raster_shape[0], height=raster_shape[1])
        rds.write(risk_map, 1)
        rds.close()

        return risk_raster, risk_map, None
示例#2
0
def load_image(time, p):
    print("time %s, p %s" % (time, p))
    data = dataset[p][3]
    if not sea_data:
        data = data[0]
    img = gv.operation.project_image(gv.Image(data))

    return img
示例#3
0
def compare_sp_and_osm_for_tile(rgb_fn, gdf_sp, gdf_osm):
    """
    Creates an interactive gui to explore each tile resulting
    rgb_fn: a uncropped rgb file or cropped tile
    gdf_sp and gdf_osm: ideally covers equal or larger bounds than the bounds of rgb_fn
    """
    ds = rio.open(rgb_fn)
    img = reshape_as_image(ds.read())
    bounds = ds.bounds
    polys_sp = filter_gdf_to_polys_within_bounds(gdf_sp, bounds)
    polys_osm = filter_gdf_to_polys_within_bounds(gdf_osm, bounds)

    overlay = (gv.Image(img, bounds=bounds) *
               gv.Polygons(polys_sp, group='sp', datatype=['list']) *
               gv.Polygons(polys_osm, group='osm'))
    return overlay