示例#1
0
def test_contour_incols_transposed_data(region):
    """
    Make sure that transposing the data matrix still produces a correct result
    with incols reordering the columns.

    This is a regression test for
    https://github.com/GenericMappingTools/pygmt/issues/1313

    Modified from the test_contour_vec() test.
    """
    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))

    # generate dataframe
    # switch x and y from here onwards to simulate different column order
    data = np.array([y, x, z]).T

    fig.contour(
        data,
        projection="X10c",
        region=region,
        frame="a",
        pen=True,
        incols=[1, 0, 2],
    )
    return fig
示例#2
0
def test_contour_matrix(data, region):
    """
    Plot data.
    """
    fig = Figure()
    fig.contour(data=data, projection="X3i", region=region, frame="ag", pen="")
    return fig
示例#3
0
def test_contour_deprecate_columns_to_incols(region):
    """
    Make sure that the old parameter "columns" is supported and it reports an
    warning.

    Modified from the test_contour_vec() test.
    """
    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))

    # generate dataframe
    # switch x and y from here onwards to simulate different column order
    data = np.array([y, x, z]).T

    with pytest.warns(expected_warning=FutureWarning) as record:
        fig.contour(
            data,
            projection="X10c",
            region=region,
            frame="a",
            pen=True,
            columns=[1, 0, 2],
        )
        assert len(record) == 1  # check that only one warning was raised
    return fig
示例#4
0
def test_contour_from_file(region):
    "Plot using the data file name instead of loaded data"
    fig = Figure()
    fig.contour(
        data=POINTS_DATA, projection="X4i", region=region, frame="af", pen="#ffcb87"
    )
    return fig
示例#5
0
def test_contour_matrix(array_func, data, region):
    """
    Plot data.
    """
    fig = Figure()
    fig.contour(data=array_func(data),
                projection="X10c",
                region=region,
                frame="ag",
                pen=True)
    return fig
示例#6
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="X4i", region=region, frame="a", pen="")
    return fig
示例#7
0
def test_contour_fail_no_data(data):
    """
    Should raise an exception if no data is given.
    """
    # Contour should raise an exception if no or not sufficient data
    # is given
    fig = Figure()
    # Test all combinations where at least one data variable
    # is not given:
    for variable in product([None, data[:, 0]], repeat=3):
        # Filter one valid configuration:
        if not any(item is None for item in variable):
            continue
        with pytest.raises(GMTInvalidInput):
            fig.contour(
                x=variable[0],
                y=variable[1],
                z=variable[2],
                region=region,
                projection="X4i",
                color="red",
                frame="afg",
                pen="",
            )
    # Should also fail if given too much data
    with pytest.raises(GMTInvalidInput):
        fig.contour(
            x=data[:, 0],
            y=data[:, 1],
            z=data[:, 2],
            data=data,
            region=region,
            projection="X4i",
            style="c0.2c",
            color="red",
            frame="afg",
            pen="",
        )
示例#8
0
    fig.plot(data=trench_fid, pen="thicker,black,solid",
             style="f1c/0.3c+r+t")  # carrots denoting subduction direction

# Plot major SSEs as contours
if sses:
    sse = ("/Users/Chow/Documents/academic/vuw/data/carto/slow_slip_events/"
           "filter_SSE2002_2014.grd")
    fig.grdcontour(sse,
                   pen=sse_pen,
                   limit=[100, 550],
                   annotation=(100, sse_fontsize))
# Deep 2006, 2008 slip
if deep_sses:
    deep = ("/Users/Chow/Documents/academic/vuw/data/carto/slow_slip_events/"
            "sum_06_08_deep.txt")
    fig.contour(data=deep, levels=20, pen=deep_sse_pen, annotation=(20, "+f8"))

if seismicity:
    fig.plot(data=seis_fid, style="a", color="white",
             pen="1.,black")  # style='c'

if moment_tensors and mt_fid:
    mts = open(mt_fid, "r").readlines()
    for mt in mts[1:]:
        _, _, lat, lon, strike, dip, rake, *_ = mt.split(",")
        *_, ml, mw, m0 = mt.split(",")
        fig.meca(dict(strike=float(strike),
                      dip=float(dip),
                      rake=float(rake),
                      magnitude=float(mw) / 2),
                 scale="1c",