Exemplo n.º 1
0
def test_grdcontour_file():
    """
    Plot a contour image using grid file input.
    """
    fig = Figure()
    fig.grdcontour(
        "@earth_relief_01d_g",
        interval="1000",
        limit="0",
        pen="0.5p,black",
        region=[-180, 180, -70, 70],
        projection="M10i",
    )
    return fig
Exemplo n.º 2
0
def test_plot_matrix_color(data):
    """
    Plot the data passing in a matrix and using a colormap.
    """
    fig = Figure()
    fig.plot(
        data=data,
        region=[10, 70, -5, 10],
        projection="X10c",
        style="c0.5c",
        cmap="rainbow",
        frame="a",
    )
    return fig
Exemplo n.º 3
0
def test_contour_vec(region):
    """
    Plot an x-centered gaussian kernel with different y scale.
    """
    fig = Figure()
    x, y = np.meshgrid(
        np.linspace(region[0], region[1]), np.linspace(region[2], region[3])
    )
    x = x.flatten()
    y = y.flatten()
    z = (x - 0.5 * (region[0] + region[1])) ** 2 + 4 * y ** 2
    z = np.exp(-z / 10 ** 2 * np.log(2))
    fig.contour(x=x, y=y, z=z, projection="X10c", region=region, frame="a", pen=True)
    return fig
Exemplo n.º 4
0
def test_grdcontour_slice(grid):
    """
    Plot an contour image using an xarray grid that has been sliced.
    """

    fig_ref, fig_test = Figure(), Figure()

    grid_ = grid.sel(lat=slice(-30, 30))
    kwargs = dict(interval="1000", projection="M6i")
    fig_ref.grdcontour(
        grid="@earth_relief_01d_g", region=[-180, 180, -30, 30], **kwargs
    )
    fig_test.grdcontour(grid=grid_, **kwargs)
    return fig_ref, fig_test
Exemplo n.º 5
0
def test_grdimage_over_dateline(xrgrid):
    """
    Ensure no gaps are plotted over the 180 degree international dateline.

    Specifically checking that `xrgrid.gmt.gtype = 1` sets `GMT_GRID_IS_GEO`,
    and that `xrgrid.gmt.registration = 0` sets `GMT_GRID_NODE_REG`. Note that
    there would be a gap over the dateline if a pixel registered grid is used.
    See also https://github.com/GenericMappingTools/pygmt/issues/375.
    """
    fig = Figure()
    assert xrgrid.gmt.registration == 0  # gridline registration
    xrgrid.gmt.gtype = 1  # geographic coordinate system
    fig.grdimage(grid=xrgrid, region="g", projection="A0/0/1c")
    return fig
Exemplo n.º 6
0
def test_histogram(table):
    """
    Tests plotting a histogram using a list of integers.
    """
    fig = Figure()
    fig.histogram(
        table=table,
        projection="X10c/10c",
        region=[0, 9, 0, 6],
        series=1,
        frame="a",
        fill="green",
    )
    return fig
Exemplo n.º 7
0
def test_grdview_on_a_plane_styled_with_facadepen(xrgrid):
    """
    Run grdview by passing in a grid and plotting it on a z-plane with styled
    lines for the frontal facade.
    """
    fig = Figure()
    fig.grdview(
        grid=xrgrid,
        plane=-4000,
        perspective=[225, 30],
        zscale=0.005,
        facadepen="0.5p,blue,dash",
    )
    return fig
Exemplo n.º 8
0
def test_extract_region_two_figures():
    "Extract region should handle multiple figures existing at the same time"
    # Make two figures before calling extract_region to make sure that it's
    # getting from the current figure, not the last figure.
    fig1 = Figure()
    region1 = np.array([0, 10, -20, -10])
    fig1.coast(region=region1, projection="M6i", frame=True, land="black")

    fig2 = Figure()
    fig2.basemap(region="US.HI+r5", projection="M6i", frame=True)

    # Activate the first figure and extract the region from it
    # Use in a different session to avoid any memory problems.
    with clib.Session() as lib:
        lib.call_module("figure", "{} -".format(fig1._name))
    with clib.Session() as lib:
        wesn1 = lib.extract_region()
        npt.assert_allclose(wesn1, region1)

    # Now try it with the second one
    with clib.Session() as lib:
        lib.call_module("figure", "{} -".format(fig2._name))
    with clib.Session() as lib:
        wesn2 = lib.extract_region()
        npt.assert_allclose(wesn2, np.array([-165.0, -150.0, 15.0, 25.0]))
Exemplo n.º 9
0
def test_makecpt_plot_points(points, region):
    """
    Use static color palette table to change color of points.
    """
    fig = Figure()
    makecpt(cmap="rainbow")
    fig.plot(
        x=points[:, 0],
        y=points[:, 1],
        color=points[:, 2],
        region=region,
        style="c1c",
        cmap=True,
    )
    return fig
Exemplo n.º 10
0
def test_plot_red_circles(data, region):
    """
    Plot the data in red circles passing in vectors.
    """
    fig = Figure()
    fig.plot(
        x=data[:, 0],
        y=data[:, 1],
        region=region,
        projection="X10c",
        style="c0.2c",
        color="red",
        frame="afg",
    )
    return fig
Exemplo n.º 11
0
def test_plot_matrix(data):
    """
    Plot the data passing in a matrix and specifying columns.
    """
    fig = Figure()
    fig.plot(
        data=data,
        region=[10, 70, -5, 10],
        projection="M10i",
        style="cc",
        color="#aaaaaa",
        B="a",
        columns="0,1,2+s0.005",
    )
    return fig
Exemplo n.º 12
0
def test_plot_fail_1d_array_with_data(data):
    """
    Should raise an exception if array color, size, intensity and transparency
    are used with matrix.
    """
    fig = Figure()
    kwargs = dict(data=data, region=region, projection="X10c", frame="afg")
    with pytest.raises(GMTInvalidInput):
        fig.plot(style="c0.2c", color=data[:, 2], **kwargs)
    with pytest.raises(GMTInvalidInput):
        fig.plot(style="cc", size=data[:, 2], color="red", **kwargs)
    with pytest.raises(GMTInvalidInput):
        fig.plot(style="c0.2c", color="red", intensity=data[:, 2], **kwargs)
    with pytest.raises(GMTInvalidInput):
        fig.plot(style="c0.2c", color="red", transparency=data[:, 2] * 100, **kwargs)
Exemplo n.º 13
0
def test_coast_dcw_continent():
    """
    Test passing a continent code to dcw.
    """
    fig_ref, fig_test = Figure(), Figure()
    # Use single-character arguments for the reference image
    fig_ref.coast(R="-10/15/25/44", J="M15c", B="a", G="brown", E="=AF+gbisque+pblue")
    fig_test.coast(
        region=[-10, 15, 25, 44],
        frame="a",
        projection="M15c",
        land="brown",
        dcw="=AF+gbisque+pblue",
    )
    return fig_ref, fig_test
Exemplo n.º 14
0
def test_grdcontour_labels(grid):
    """Plot a contour image using a xarray grid
    with contour labels and alternate colors
    """
    fig_ref, fig_test = Figure(), Figure()
    kwargs = dict(
        interval="1000",
        annotation="5000",
        projection="W0/6i",
        pen=["a1p,red", "c0.5p,black"],
        label_placement="d3i",
    )
    fig_ref.grdcontour("@earth_relief_01d_g", **kwargs)
    fig_test.grdcontour(grid, **kwargs)
    return fig_ref, fig_test
Exemplo n.º 15
0
def test_grdview_with_perspective_and_zaxis_frame(xrgrid, region):
    """
    Run grdview by passing in a grid and plotting an annotated vertical z-axis
    frame on a Transverse Mercator (T) projection.
    """
    fig = Figure()
    projection = f"T{(region[0]+region[1])/2}/{abs((region[2]+region[3])/2)}"
    fig.grdview(
        grid=xrgrid,
        projection=projection,
        perspective=[225, 30],
        zscale=0.005,
        frame=["xaf", "yaf", "zaf"],
    )
    return fig
Exemplo n.º 16
0
def test_plot_from_file(region):
    """
    Plot using the data file name instead of loaded data.
    """
    fig = Figure()
    fig.plot(
        data=POINTS_DATA,
        region=region,
        projection="X10c",
        style="d1c",
        color="yellow",
        frame=True,
        incols=[0, 1],
    )
    return fig
Exemplo n.º 17
0
def test_plot_projection(data):
    """
    Plot the data in green squares with a projection.
    """
    fig = Figure()
    fig.plot(
        x=data[:, 0],
        y=data[:, 1],
        region="g",
        projection="R270/10c",
        style="s0.2c",
        color="green",
        frame="ag",
    )
    return fig
Exemplo n.º 18
0
def test_plot_matrix(data, color):
    """
    Plot the data passing in a matrix and specifying columns.
    """
    fig = Figure()
    fig.plot(
        data=data,
        region=[10, 70, -5, 10],
        projection="M15c",
        style="cc",
        color=color,
        frame="a",
        incols="0,1,2+s0.5",
    )
    return fig
Exemplo n.º 19
0
def test_plot_colors_sizes(data, region):
    "Plot the data using z as sizes and colors"
    fig = Figure()
    fig.plot(
        x=data[:, 0],
        y=data[:, 1],
        color=data[:, 2],
        sizes=0.5 * data[:, 2],
        region=region,
        projection="X3i",
        style="cc",
        cmap="copper",
        frame="af",
    )
    return fig
Exemplo n.º 20
0
def test_text_round_clearance(region, projection):
    """
    Print text with round rectangle box clearance
    """
    fig = Figure()
    fig.text(
        region=region,
        projection=projection,
        x=1.2,
        y=1.2,
        text="clearance around text",
        clearance="90%+tO",
        pen="default,black,dashed",
    )
    return fig
Exemplo n.º 21
0
def test_grdimage_central_meridians_and_standard_parallels(
        grid, proj_type, lon0, lat0):
    """
    Test that plotting a grid with different central meridians (lon0) and
    standard_parallels (lat0) using Cylindrical Equidistant (Q) and General
    Stereographic (S) projection systems work.
    """
    fig_ref, fig_test = Figure(), Figure()
    fig_ref.grdimage("@earth_relief_01d_g",
                     projection=f"{proj_type}{lon0}/{lat0}/15c",
                     cmap="geo")
    fig_test.grdimage(grid,
                      projection=f"{proj_type}{lon0}/{lat0}/15c",
                      cmap="geo")
    return fig_ref, fig_test
Exemplo n.º 22
0
def test_inset_context_manager():
    """
    Test that the inset context manager works and, once closed, plotting
    elements are added to the larger figure.
    """
    fig = Figure()
    fig.basemap(region=[-74, -69.5, 41, 43], projection="M9c", frame=True)
    with fig.inset(position="jBL+w3c+o0.2c", margin=0, box="+pblack"):
        fig.basemap(region=[-80, -65, 35, 50], projection="M3c", frame="afg")
    fig.basemap(
        rose="jTR+w3c")  # Pass rose argument with basemap after the inset
    return fig
Exemplo n.º 23
0
def test_config_format_date_map():
    """
    Test that setting FORMAT_DATE_MAP config changes how the output date string
    is plotted.

    Note the space in 'o dd', this acts as a regression test for
    https://github.com/GenericMappingTools/pygmt/issues/247.
    """
    fig = Figure()
    with config(FORMAT_DATE_MAP="o dd"):
        fig.basemap(
            region=["1969-7-21T", "1969-7-23T", 0, 1],
            projection="X2.5c/0.1c",
            frame=["sxa1D", "S"],
        )
    return fig
Exemplo n.º 24
0
def test_plot_sizes(data, region):
    """
    Plot the data using z as sizes.
    """
    fig = Figure()
    fig.plot(
        x=data[:, 0],
        y=data[:, 1],
        size=0.5 * data[:, 2],
        region=region,
        projection="X10c",
        style="cc",
        color="blue",
        frame="af",
    )
    return fig
Exemplo n.º 25
0
def test_plot_colors(data, region):
    """
    Plot the data using z as colors.
    """
    fig = Figure()
    fig.plot(
        x=data[:, 0],
        y=data[:, 1],
        color=data[:, 2],
        region=region,
        projection="X10c",
        style="c0.5c",
        cmap="cubhelix",
        frame="af",
    )
    return fig
Exemplo n.º 26
0
def test_coast():
    "Simple plot from the GMT docs"
    fig = Figure()
    fig.coast(
        R="-30/30/-40/40",
        J="m0.1i",
        B=5,
        I="1/1p,blue",
        N="1/0.25p,-",
        W="0.25p,white",
        G="green",
        S="blue",
        D="c",
        A=10000,
    )
    return fig
Exemplo n.º 27
0
def test_text_justify_parsed_from_textfile():
    """
    Print text justified based on a column from textfile, using justify=True
    boolean operation. Loosely based on "All great-circle paths lead to Rome"
    gallery example at
    https://gmt.soest.hawaii.edu/doc/latest/gallery/ex23.html
    """
    fig = Figure()
    fig.text(
        region="g",
        projection="H90/9i",
        justify=True,
        textfiles=CITIES_DATA,
        D="j0.45/0+vred",  # draw red-line from xy point to text label (city name)
    )
    return fig
Exemplo n.º 28
0
def test_plot3d_red_circles_zsize(data, region):
    "Plot the 3D data in red circles passing in vectors and setting zsize = 6c"
    fig = Figure()
    fig.plot3d(
        x=data[:, 0],
        y=data[:, 1],
        z=data[:, 2],
        zsize="6c",
        perspective=[225, 30],
        region=region,
        projection="X10c",
        style="c0.2c",
        color="red",
        frame=["afg", "zafg"],
    )
    return fig
Exemplo n.º 29
0
def test_text_nonstr_text():
    """
    Input text is in non-string type (e.g., int, float)
    """
    fig = Figure()

    fig.text(
        region=[0, 10, 0, 10],
        projection="X10c",
        frame=True,
        x=[1, 2, 3, 4],
        y=[1, 2, 3, 4],
        text=[1, 2, 3.0, 4.0],
    )

    return fig
Exemplo n.º 30
0
def test_grdcontour_labels(grid):
    """
    Plot a contour image using a xarray grid with contour labels and alternate
    colors.
    """
    fig = Figure()
    fig.grdcontour(
        grid=grid,
        interval=50,
        annotation=200,
        projection="M10c",
        pen=["a1p,red", "c0.5p,black"],
        label_placement="d6c",
        frame=True,
    )
    return fig