Exemplo n.º 1
0
 def add_topo(ax):
     # shade function when the data is retrieved.
     shaded_srtm = PostprocessedRasterSource(SRTM1Source(), shade)
     # Add the shaded SRTM source to our map with a grayscale colormap.
     ax.add_raster(shaded_srtm, cmap='Greys')
     ax.add_feature(cartopy.feature.OCEAN)
     ax.add_feature(cartopy.feature.LAND, edgecolor='black')
     ax.add_feature(cartopy.feature.LAKES, edgecolor='black')
     ax.add_feature(cartopy.feature.RIVERS)
     return ax
def add_srtm_shaded(ax,
                    Source=SRTM1Source,
                    azimuth=135,
                    altitude=35,
                    cmap="Greys",
                    **kwargs):
    shader = partial(shade, azimuth=azimuth, altitude=altitude)

    shaded_srtm = PostprocessedRasterSource(Source(), shader)
    ax.add_raster(shaded_srtm, cmap=cmap, **kwargs)

    return
Exemplo n.º 3
0
    def plot(Source, name):
        plt.figure()
        ax = plt.axes(projection=ccrs.PlateCarree())

        # Define a raster source which uses the SRTM data and applies the
        # shade function when the data is retrieved.
        shaded_srtm = PostprocessedRasterSource(Source(), shade)

        # Add the shaded SRTM source to our map with a grayscale colormap.
        ax.add_raster(shaded_srtm, cmap='Greys')

        # This data is high resolution, so pick a small area which has some
        # interesting orography.
        ax.set_extent([12, 13, 47, 48])

        plt.title(name + " Shaded Relief Map")

        gl = ax.gridlines(draw_labels=True)
        gl.xlabels_top = False
        gl.ylabels_left = False
Exemplo n.º 4
0
def plot_on_map(db,
                scene,
                eastings,
                northings,
                x0,
                y0,
                x1,
                y1,
                mind,
                maxd,
                fname,
                synthetic=False,
                topo=False,
                kite_scene=False,
                comb=False):

    if kite_scene is True:
        scd = scene
        data_dsc = scd.displacement
    else:
        data_dsc = num.rot90(scene.T)

    if comb is True:
        data_dsc[data_dsc < num.max(data_dsc) * 0.1] = num.nan

    else:
        data_dsc[data_dsc == 0] = num.nan

    extent = [
        num.min(eastings),
        num.max(eastings),
        num.min(northings),
        num.max(northings)
    ]
    central_lon = num.mean(extent[:2])
    central_lat = num.mean(extent[2:])
    f, ax = plt.subplots(1, 1, subplot_kw=dict(projection=ccrs.PlateCarree()))
    ax.set_extent(extent)

    if topo is True:
        # shade function when the data is retrieved.
        shaded_srtm = PostprocessedRasterSource(SRTM1Source(), shade)
        # Add the shaded SRTM source to our map with a grayscale colormap.
        ax.add_raster(shaded_srtm, cmap='Greys')
        ax.add_feature(cartopy.feature.OCEAN)
        ax.add_feature(cartopy.feature.LAND, edgecolor='black')
        ax.add_feature(cartopy.feature.LAKES, edgecolor='black')
        ax.add_feature(cartopy.feature.RIVERS)
    scale_bar(ax, (0.1, 0.1), 5_0)

    h = ax.imshow(num.rot90(data_dsc.T),
                  origin='upper',
                  extent=extent,
                  transform=ccrs.PlateCarree(),
                  cmap="seismic",
                  vmin=mind,
                  vmax=maxd,
                  alpha=0.8)

    if kite_scene is True:
        addArrow(ax, scene)

    gl = ax.gridlines(draw_labels=True)
    gl.ylabels_right = False
    gl.xlabels_top = False
    divider = make_axes_locatable(ax)
    cax = divider.new_horizontal(size="5%", pad=0.1, axes_class=plt.Axes)
    f.add_axes(cax)
    plt.colorbar(h, cax=cax)

    fig = plt.gcf()
    fig.set_size_inches((11, 11), forward=False)
    plt.savefig(fname + '.svg', format='svg', dpi=300)
    plt.close()
Exemplo n.º 5
0
def plot_on_kite_box(coords_out,
                     coords_line,
                     scene,
                     eastings,
                     northings,
                     eastcomb,
                     northcomb,
                     x0c,
                     y0c,
                     x1c,
                     y1c,
                     name,
                     ellipses,
                     mind,
                     maxd,
                     fname,
                     synthetic=False,
                     topo=False):
    '''
    Plotting function for plotting a rectangle from coords_out and coords_line
    with coordinates eastings and northings on data from a kite scene withhin
    frame given by x0, y0, x1 and y1 and saves
    the image to a folder under name fname. Optional draw of topography.
    '''
    scd = scene
    data_dsc = scd.displacement
    lengths = []
    widths = []

    data_dsc[data_dsc == 0] = num.nan
    extent = [
        num.min(eastings),
        num.max(eastings),
        num.min(northings),
        num.max(northings)
    ]
    central_lon = num.mean(extent[:2])
    central_lat = num.mean(extent[2:])
    f, ax = plt.subplots(1, 1, subplot_kw=dict(projection=ccrs.PlateCarree()))
    ax.set_extent(extent)

    if topo is True:
        # shade function when the data is retrieved.
        shaded_srtm = PostprocessedRasterSource(SRTM1Source(), shade)
        # Add the shaded SRTM source to our map with a grayscale colormap.
        ax.add_raster(shaded_srtm, cmap='Greys')
        ax.add_feature(cartopy.feature.OCEAN)
        ax.add_feature(cartopy.feature.LAND, edgecolor='black')
        ax.add_feature(cartopy.feature.LAKES, edgecolor='black')
        ax.add_feature(cartopy.feature.RIVERS)

    scale_bar(ax, (0.1, 0.1), 5_0)
    h = ax.imshow(num.rot90(data_dsc.T),
                  origin='upper',
                  extent=extent,
                  transform=ccrs.PlateCarree(),
                  cmap="seismic",
                  vmin=mind,
                  vmax=maxd,
                  alpha=0.8,
                  norm=MidpointNormalize(mind, maxd, 0.))

    ax.gridlines(draw_labels=True)

    coords_all = []
    for coords in coords_line:
        coords_boxes = []
        for k in coords:
            kx = k[1]
            ky = k[0]
            coords_boxes.append(
                [eastcomb[int(kx)][int(ky)], northcomb[int(kx)][int(ky)]])
        coords_all.append(coords_boxes)
    n = 0
    for coords, ell in zip(coords_all, ellipses):

        x1, y1 = coords[0][0], coords[0][1]
        x1a, y1a = coords[1][0], coords[1][1]
        x0, y0 = coords[2][0], coords[2][1]
        x2, y2 = coords[3][0], coords[3][1]
        n = n + 1
        ax.plot((x0, x1), (y0, y1), 'r--', linewidth=2.5)
        ax.plot((x0, x1a), (y0, y1a), 'r--', linewidth=2.5)

        ax.plot((x0, x2), (y0, y2), '-r', linewidth=2.5)
        ax.plot(x0, y0, '.g', markersize=15)
        height = orthodrome.distance_accurate50m(coords[0][0], coords[0][1],
                                                 coords[3][0], coords[3][1])
        width = orthodrome.distance_accurate50m(coords[2][0], coords[2][1],
                                                coords[3][0], coords[3][1])
        lengths.append(height)
        widths.append(width)
        e = mpatches.Ellipse((x0, y0),
                             width=width * 2.,
                             height=height * 2.,
                             angle=num.rad2deg(ell[4]) + 90,
                             lw=2,
                             edgecolor='purple',
                             fill=False)
        ax.add_patch(e)

    coords_boxes = []
    for k in coords_out:
        minr, minc, maxr, maxc = k[0], k[1], k[2], k[3]

        kx = k[2]
        ky = k[1]
        coords_boxes.append(
            [eastcomb[int(kx)][int(ky)], northcomb[int(kx)][int(ky)]])
        kx = k[0]
        ky = k[3]
        coords_boxes.append(
            [eastcomb[int(kx)][int(ky)], northcomb[int(kx)][int(ky)]])

    n = 0

    for coords in coords_out:
        minc, minr = coords_boxes[0 + n][0], coords_boxes[0 + n][1]
        maxc, maxr = coords_boxes[1 + n][0], coords_boxes[1 + n][1]

        n = n + 2
        rect = mpatches.Rectangle((minc, minr),
                                  maxc - minc,
                                  maxr - minr,
                                  fill=False,
                                  edgecolor='r',
                                  linewidth=2)
        ax.add_patch(rect)

    try:
        parallels = num.linspace(y0c, y1c, 22)
        meridians = num.linspace(x0c, x1c, 22)
    except:
        parallels = num.linspace((num.min(northings)), (num.max(northings)),
                                 22)
        meridians = num.linspace((num.min(eastings)), (num.max(eastings)), 22)

    if synthetic is True:
        from pyrocko.gf import RectangularSource

        srcs = load_all(filename='%s.yml' % name)

        for source in srcs:
            n, e = source.outline(cs='latlon').T
            ax.fill(e, n, color=(0, 0, 0), lw=3)

    addArrow(ax, scene)

    gl = ax.gridlines(draw_labels=True)
    gl.ylabels_right = False
    gl.xlabels_top = False
    addArrow(ax, scene)
    divider = make_axes_locatable(ax)
    cax = divider.new_horizontal(size="5%", pad=0.1, axes_class=plt.Axes)
    f.add_axes(cax)
    plt.colorbar(h, cax=cax)

    fig = plt.gcf()
    fig.set_size_inches((11, 11), forward=False)
    plt.savefig(fname + 'box.svg', format='svg', dpi=300)
    plt.close()

    return widths, lengths
Exemplo n.º 6
0
def plot_on_kite_line(coords_out,
                      scene,
                      eastings,
                      northings,
                      eastcomb,
                      northcomb,
                      x0c,
                      y0c,
                      x1c,
                      y1c,
                      mind,
                      maxd,
                      fname,
                      synthetic=False,
                      topo=False):
    '''
    Plotting function for plotting a line from coordinates coords_out,
    with coordinates eastings and northings on data from a kite scene withhin
    frame given by x0c, y0c, x1c and y1c and saves
    the image to a folder under name fname. Optional draw of topography.
    '''
    scd = scene
    data_dsc = scd.displacement

    data_dsc[data_dsc == 0] = num.nan
    extent = [
        num.min(eastings),
        num.max(eastings),
        num.min(northings),
        num.max(northings)
    ]
    central_lon = num.mean(extent[:2])
    central_lat = num.mean(extent[2:])
    f, ax = plt.subplots(1, 1, subplot_kw=dict(projection=ccrs.PlateCarree()))
    ax.set_extent(extent)

    if topo is True:
        # shade function when the data is retrieved.
        shaded_srtm = PostprocessedRasterSource(SRTM1Source(), shade)
        # Add the shaded SRTM source to our map with a grayscale colormap.
        ax.add_raster(shaded_srtm, cmap='Greys')
        ax.add_feature(cartopy.feature.OCEAN)
        ax.add_feature(cartopy.feature.LAND, edgecolor='black')
        ax.add_feature(cartopy.feature.LAKES, edgecolor='black')
        ax.add_feature(cartopy.feature.RIVERS)

    scale_bar(ax, (0.1, 0.1), 5_0)
    h = ax.imshow(num.rot90(data_dsc.T),
                  origin='upper',
                  extent=extent,
                  transform=ccrs.PlateCarree(),
                  cmap="seismic",
                  vmin=mind,
                  vmax=maxd,
                  alpha=0.8)

    ax.gridlines(draw_labels=True)

    coords_all = []
    for coords in coords_out:

        coords_boxes = []
        for k in coords:
            kx = k[1]
            ky = k[0]
            coords_boxes.append(
                [eastcomb[int(kx)][int(ky)], northcomb[int(kx)][int(ky)]])
        coords_all.append(coords_boxes)
    n = 0

    for coords in coords_all:

        x1, y1 = coords[0][0], coords[0][1]
        x1a, y1a = coords[1][0], coords[1][1]
        x0, y0 = coords[2][0], coords[2][1]
        x2, y2 = coords[3][0], coords[3][1]
        n = n + 1
        ax.plot((x0, x1), (y0, y1), '-r', linewidth=2.5)
        ax.plot((x0, x1a), (y0, y1a), '-r', linewidth=2.5)

        ax.plot((x0, x2), (y0, y2), '-r', linewidth=2.5)
        ax.plot(x0, y0, '.g', markersize=15)

    gl = ax.gridlines(draw_labels=True)
    gl.ylabels_right = False
    gl.xlabels_top = False
    addArrow(ax, scene)
    divider = make_axes_locatable(ax)
    cax = divider.new_horizontal(size="5%", pad=0.1, axes_class=plt.Axes)
    f.add_axes(cax)
    plt.colorbar(h, cax=cax)

    addArrow(ax, scene)

    fig = plt.gcf()
    fig.set_size_inches((11, 11), forward=False)
    plt.savefig(fname + 'line.svg', format='svg', dpi=300)
    plt.close()
Exemplo n.º 7
0
def plot_on_kite_scatter(db,
                         scene,
                         eastings,
                         northings,
                         x0,
                         y0,
                         x1,
                         y1,
                         mind,
                         maxd,
                         fname,
                         synthetic=False,
                         topo=False):
    '''
    Plotting function for plotting scatter points from a database (db)
    with coordinates eastings and northings on data from a kite scene withhin
    frame given by x0, y0, x1 and y1 and saves
    the image to a folder under name fname. Optional draw of topography.
    '''
    scd = scene
    data_dsc = scd.displacement

    data_dsc[data_dsc == 0] = num.nan

    extent = [
        num.min(eastings),
        num.max(eastings),
        num.min(northings),
        num.max(northings)
    ]
    central_lon = num.mean(extent[:2])
    central_lat = num.mean(extent[2:])
    f, ax = plt.subplots(1, 1, subplot_kw=dict(projection=ccrs.PlateCarree()))
    ax.set_extent(extent)
    if topo is True:
        # shade function when the data is retrieved.
        shaded_srtm = PostprocessedRasterSource(SRTM1Source(), shade)
        # Add the shaded SRTM source to our map with a grayscale colormap.
        ax.add_raster(shaded_srtm, cmap='Greys')
        ax.add_feature(cartopy.feature.OCEAN)
        ax.add_feature(cartopy.feature.LAND, edgecolor='black')
        ax.add_feature(cartopy.feature.LAKES, edgecolor='black')
        ax.add_feature(cartopy.feature.RIVERS)

    h = ax.imshow(num.rot90(data_dsc.T),
                  origin='upper',
                  extent=extent,
                  transform=ccrs.PlateCarree(),
                  cmap="seismic",
                  alpha=0.8,
                  norm=MidpointNormalize(mind, maxd, 0.))

    gl = ax.gridlines(draw_labels=True)
    gl.ylabels_right = False
    gl.xlabels_top = False
    addArrow(ax, scene)
    divider = make_axes_locatable(ax)
    cax = divider.new_horizontal(size="5%", pad=0.1, axes_class=plt.Axes)
    f.add_axes(cax)
    plt.colorbar(h, cax=cax)

    gj = db
    faults = gj['features']
    coords = [feat['geometry']['coordinates'] for feat in faults]

    i = len(coords)
    colors = iter(cm.rainbow(num.linspace(0, 1, i)))
    for j in coords:
        coords_re_x = []
        coords_re_y = []
        for k in j:
            coords_re_x.append(k[0])
            coords_re_y.append(k[1])
        x, y = coords_re_x, coords_re_y
        plt.scatter(x, y, c=next(colors))

    plt.grid()

    addArrow(ax, scene)
    try:
        x0, y0 = map(x0, y0)
        x1, y1 = map(x1, y1)
        ax.set_xlim([x0, x1])
        ax.set_ylim([y0, y1])
    except:
        pass
    divider = make_axes_locatable(ax)
    try:
        plt.colorbar(cax=cax)
    except TypeError:
        pass
    fig = plt.gcf()
    fig.set_size_inches((11, 11), forward=False)
    plt.savefig(fname + 'scatter.svg', format='svg', dpi=300)
    plt.close()