Exemplo n.º 1
0
def test_grdgradient_fails(grid):
    """
    Check that grdgradient fails correctly when neither of azimuth, direction
    or radiance is given.
    """
    with pytest.raises(GMTInvalidInput):
        grdgradient(grid=grid)
Exemplo n.º 2
0
def test_grdgradient_fails(grid):
    """
    Check that grdgradient fails correctly.

    Check that grdgradient fails correctly when `tiles` is specified but
    normalize is not.
    """
    with pytest.raises(GMTInvalidInput):
        grdgradient(grid=grid)  # fails without required arguments
    with pytest.raises(GMTInvalidInput):
        # fails when tiles is specified but not normalize
        grdgradient(grid=grid, azimuth=10, direction="c", tiles="c")
Exemplo n.º 3
0
def test_grdgradient_no_outgrid(grid, expected_grid):
    """
    Test the azimuth and direction parameters for grdgradient with no set
    outgrid.
    """
    result = grdgradient(grid=grid, azimuth=10, region=[-53, -49, -20, -17])
    # check information of the output grid
    assert isinstance(result, xr.DataArray)
    assert result.gmt.gtype == 1  # Geographic grid
    assert result.gmt.registration == 1  # Pixel registration
    # check information of the output grid
    xr.testing.assert_allclose(a=result, b=expected_grid)
Exemplo n.º 4
0
def test_grdgradient_no_outgrid(grid):
    """
    Test the azimuth and direction parameters for grdgradient with no set
    outgrid.
    """
    temp_grid = grdgradient(grid=grid, azimuth=10, direction="c")
    assert temp_grid.dims == ("lat", "lon")
    assert temp_grid.gmt.gtype == 1  # Geographic grid
    assert temp_grid.gmt.registration == 1  # Pixel registration
    npt.assert_allclose(temp_grid.min(), -0.0045060496)
    npt.assert_allclose(temp_grid.max(), 0.0575332976)
    npt.assert_allclose(temp_grid.median(), 0.0004889865522272885)
    npt.assert_allclose(temp_grid.mean(), 0.0028633063193410635)
Exemplo n.º 5
0
def test_grdgradient_outgrid(grid, expected_grid):
    """
    Test the azimuth and direction parameters for grdgradient with a set
    outgrid.
    """
    with GMTTempFile(suffix=".nc") as tmpfile:
        result = grdgradient(grid=grid,
                             outgrid=tmpfile.name,
                             azimuth=10,
                             region=[-53, -49, -20, -17])
        assert result is None  # return value is None
        assert os.path.exists(path=tmpfile.name)  # check that outgrid exists
        temp_grid = load_dataarray(tmpfile.name)
        xr.testing.assert_allclose(a=temp_grid, b=expected_grid)
Exemplo n.º 6
0
def test_grdgradient_no_outgrid(grid, expected_grid):
    """
    Test the azimuth and direction parameters for grdgradient with no set
    outgrid.

    This is a regression test for
    https://github.com/GenericMappingTools/pygmt/issues/1807.
    """
    result = grdgradient(grid=grid,
                         azimuth=10,
                         region=[-53, -49, -20, -17],
                         outgrid=None)
    # check information of the output grid
    assert isinstance(result, xr.DataArray)
    assert result.gmt.gtype == 1  # Geographic grid
    assert result.gmt.registration == 1  # Pixel registration
    # check information of the output grid
    xr.testing.assert_allclose(a=result, b=expected_grid)
Exemplo n.º 7
0
def test_grdgradient_outgrid(grid):
    """
    Test the azimuth and direction parameters for grdgradient with a set
    outgrid.
    """
    with GMTTempFile(suffix=".nc") as tmpfile:
        result = grdgradient(grid=grid,
                             outgrid=tmpfile.name,
                             azimuth=10,
                             direction="c")
        assert result is None  # return value is None
        assert os.path.exists(path=tmpfile.name)  # check that outgrid exists
        result = (grdinfo(grid=tmpfile.name, force_scan="a",
                          per_column="n").strip().split())
    npt.assert_allclose(float(result[4]), -0.0045060496)  # min
    npt.assert_allclose(float(result[5]), 0.0575332976)  # max
    # Check spherically weighted statistics below
    npt.assert_allclose(float(result[10]), 0.000384754501283)  # median
    npt.assert_allclose(float(result[12]), 0.00285958005568)  # mean
Exemplo n.º 8
0
the respective gradient and returns it as an :class:`xarray.DataArray` object.
We will use the ``radiance`` parameter in order to set the illumination source
direction and altitude.
"""

import pygmt

# Define region of interest around Yosemite valley
region = [-119.825, -119.4, 37.6, 37.825]

# Load sample grid (3 arc second global relief) in target area
grid = pygmt.datasets.load_earth_relief(resolution="03s", region=region)

# calculate the reflection of a light source projecting from west to east
# (azimuth of 270 degrees) and at a latitude of 30 degrees from the horizon
dgrid = pygmt.grdgradient(grid=grid, radiance=[270, 30])

fig = pygmt.Figure()
# define figure configuration
pygmt.config(FORMAT_GEO_MAP="ddd.x", MAP_FRAME_TYPE="plain")

# --------------- plotting the original Data Elevation Model -----------

pygmt.makecpt(cmap="gray", series=[200, 4000, 10])
fig.grdimage(
    grid=grid,
    projection="M12c",
    frame=['WSrt+t"Original Data Elevation Model"', "xa0.1", "ya0.1"],
    cmap=True,
)