Exemplo n.º 1
0
def test_contourf():
    a = np.zeros((4, 5))
    a[0, 0] = -1
    a[1, 1] = 1.1
    a[2, 2] = 2.2
    a[2, 4] = 1.9
    a[3, 3] = 9

    # UL Corner
    g = Grid(nxny=(5, 4),
             dxdy=(1, -1),
             x0y0=(-1, 3),
             proj=wgs84,
             pixel_ref='corner')
    c = Map(g, ny=400, countries=False)

    c.set_cmap(mpl.cm.get_cmap('viridis'))
    c.set_plot_params(levels=[0, 1, 2, 3])
    c.set_data(a)
    s = a * 0.
    s[2, 2] = 1
    c.set_contourf(s,
                   interp='linear',
                   hatches=['xxx'],
                   colors='none',
                   levels=[0.5, 1.5])

    s = a * 0.
    s[0:2, 3:] = 1
    s[0, 4] = 2
    c.set_contour(s,
                  interp='linear',
                  colors='k',
                  linewidths=6,
                  levels=[0.5, 1., 1.5])

    c.set_lonlat_contours(interval=0.5)

    # Add a geometry for fun
    gs = g.to_dict()
    gs['nxny'] = (1, 2)
    gs['x0y0'] = (0, 2)
    gs = Grid.from_dict(gs)
    c.set_geometry(gs.extent_as_polygon(), edgecolor='r', linewidth=2)

    fig, ax = plt.subplots(1)
    c.visualize(ax=ax)
    fig.tight_layout()

    # remove it
    c.set_contourf()
    c.set_contour()

    return fig
Exemplo n.º 2
0
def test_contourf():
    a = np.zeros((4, 5))
    a[0, 0] = -1
    a[1, 1] = 1.1
    a[2, 2] = 2.2
    a[2, 4] = 1.9
    a[3, 3] = 9

    # UL Corner
    g = Grid(nxny=(5, 4),
             dxdy=(1, -1),
             ul_corner=(-1, 3),
             proj=wgs84,
             pixel_ref='corner')
    c = Map(g, ny=400, countries=False)

    c.set_cmap(mpl.cm.get_cmap('viridis'))
    c.set_plot_params(levels=[0, 1, 2, 3])
    c.set_data(a)
    s = a * 0.
    s[2, 2] = 1
    c.set_contourf(s,
                   interp='linear',
                   hatches=['xxx'],
                   colors='none',
                   levels=[0.5, 1.5])

    s = a * 0.
    s[0:2, 3:] = 1
    s[0, 4] = 2
    c.set_contour(s,
                  interp='linear',
                  colors='k',
                  linewidths=6,
                  levels=[0.5, 1., 1.5])

    c.set_lonlat_contours(interval=0.5)

    fig, ax = plt.subplots(1)
    c.visualize(ax=ax)
    fig.tight_layout()

    # remove it
    c.set_contourf()
    c.set_contour()

    return fig
Exemplo n.º 3
0
def test_hef_topo_withnan():
    grid = mercator_grid(center_ll=(10.76, 46.798444), extent=(10000, 7000))
    c = Map(grid, countries=False)
    c.set_lonlat_contours(interval=10)
    c.set_shapefile(get_demo_file('Hintereisferner_UTM.shp'))

    dem = GeoTiff(get_demo_file('hef_srtm.tif'))
    mytopo = dem.get_vardata()
    h = c.set_topography(mytopo, crs=dem.grid, interp='spline')

    c.set_lonlat_contours()
    c.set_cmap(get_cmap('topo'))
    c.set_plot_params(nlevels=256)
    # Try with nan data
    h[-100:, -100:] = np.NaN
    c.set_data(h)
    fig, ax = plt.subplots(1, 1)
    c.visualize(ax=ax, title='color with NaN')
    plt.tight_layout()
    return fig
Exemplo n.º 4
0
def test_hef_topo_withnan():
    grid = mercator_grid(center_ll=(10.76, 46.798444),
                         extent=(10000, 7000))
    c = Map(grid, countries=False)
    c.set_lonlat_contours(interval=10)
    c.set_shapefile(get_demo_file('Hintereisferner_UTM.shp'))

    dem = GeoTiff(get_demo_file('hef_srtm.tif'))
    mytopo = dem.get_vardata()
    h = c.set_topography(mytopo, crs=dem.grid, interp='spline')

    c.set_lonlat_contours()
    c.set_cmap(get_cmap('topo'))
    c.set_plot_params(nlevels=256)
    # Try with nan data
    h[-100:, -100:] = np.NaN
    c.set_data(h)
    fig, ax = plt.subplots(1, 1)
    c.visualize(ax=ax, title='color with NaN')
    plt.tight_layout()
    return fig
Exemplo n.º 5
0
def test_contourf():
    a = np.zeros((4, 5))
    a[0, 0] = -1
    a[1, 1] = 1.1
    a[2, 2] = 2.2
    a[2, 4] = 1.9
    a[3, 3] = 9

    # UL Corner
    g = Grid(nxny=(5, 4), dxdy=(1, -1), ul_corner=(-1, 3), proj=wgs84,
             pixel_ref='corner')
    c = Map(g, ny=400, countries=False)

    c.set_cmap(mpl.cm.get_cmap('viridis'))
    c.set_plot_params(levels=[0, 1, 2, 3])
    c.set_data(a)
    s = a * 0.
    s[2, 2] = 1
    c.set_contourf(s, interp='linear', hatches=['xxx'], colors='none',
                   levels=[0.5, 1.5])

    s = a * 0.
    s[0:2, 3:] = 1
    s[0, 4] = 2
    c.set_contour(s, interp='linear', colors='k', linewidths=6,
                  levels=[0.5, 1., 1.5])

    c.set_lonlat_contours(interval=0.5)

    fig, ax = plt.subplots(1)
    c.visualize(ax=ax)
    fig.tight_layout()

    # remove it
    c.set_contourf()
    c.set_contour()

    return fig