def test_grdimage_fails(): """ Should fail for unrecognized input. """ fig = Figure() with pytest.raises(GMTInvalidInput): fig.grdimage(np.arange(20).reshape((4, 5)))
def test_grdimage(grid): """ Plot an image using an xarray grid. """ fig = Figure() fig.grdimage(grid, cmap="earth", projection="W0/6i") return fig
def test_makecpt_reverse_color_only(grid): """ Use static color palette table with its colors reversed. """ fig = Figure() makecpt(cmap="earth", reverse=True) fig.grdimage(grid, projection="W0/10c") return fig
def test_grdimage_slice(grid): """ Plot an image using an xarray grid that has been sliced. """ grid_ = grid.sel(lat=slice(-30, 30)) fig = Figure() fig.grdimage(grid_, cmap="earth", projection="M6i") return fig
def test_makecpt_truncated_zlow_zhigh(grid): """ Use static color palette table that is truncated to z-low and z-high. """ fig = Figure() makecpt(cmap="rainbow", truncate=[0.15, 0.85], series=[-4500, 4500]) fig.grdimage(grid, projection="W0/10c") return fig
def test_makecpt_reverse_zsign_only(grid): """ Use static color palette table with its z-value sign reversed """ fig = Figure() makecpt(cmap="earth", reverse="z") fig.grdimage(grid, projection="W0/6i") return fig
def test_makecpt_truncated_at_zhigh_only(grid): """ Use static color palette table that is truncated at z-high only """ fig = Figure() makecpt(cmap="rainbow", truncate=[None, 0.5], series=[-4500, 4500]) fig.grdimage(grid, projection="W0/6i") return fig
def test_makecpt_plot_grid(grid): """ Use static color palette table to change color of grid. """ fig = Figure() makecpt(cmap="relief") fig.grdimage(grid, projection="W0/10c") return fig
def test_makecpt_plot_grid_scaled_with_series(grid): """ Use static color palette table scaled to a min/max series to change color of grid. """ fig = Figure() makecpt(cmap="oleron", series=[-4500, 4500]) fig.grdimage(grid, projection="W0/10c") return fig
def test_makecpt_continuous(grid): """ Use static color palette table that is continuous from blue to white and scaled from -4500 to 4500m. """ fig = Figure() makecpt(cmap="blue,white", continuous=True, series=[-4500, 4500]) fig.grdimage(grid, projection="W0/10c") return fig
def test_makecpt_reverse_color_and_zsign(grid): """ Use static color palette table with both its colors and z-value sign reversed. """ fig = Figure() makecpt(cmap="earth", reverse="cz") fig.grdimage(grid, projection="W0/10c") return fig
def test_grdimage_central_meridians(grid, proj_type, lon0): """ Test that plotting a grid with different central meridians (lon0) using Hammer (H) and Mollweide (W) projection systems work. """ fig_ref, fig_test = Figure(), Figure() fig_ref.grdimage( "@earth_relief_01d_g", projection=f"{proj_type}{lon0}/15c", cmap="geo" ) fig_test.grdimage(grid, projection=f"{proj_type}{lon0}/15c", cmap="geo") return fig_ref, fig_test
def test_grdimage_default_no_shading(grid, shading): """ Plot an image with no shading. This is a regression test for https://github.com/GenericMappingTools/pygmt/issues/1852 """ grid_ = grid.sel(lat=slice(-30, 30)) fig = Figure() fig.grdimage(grid_, cmap="earth", projection="M6i", shading=shading) return fig
def test_grdimage_file(): "Plot an image using file input" fig = Figure() fig.grdimage( "@earth_relief_01d_g", cmap="ocean", region=[-180, 180, -70, 70], projection="W0/10i", shading=True, ) return fig
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
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", V="i") return fig
def test_grdimage_grid_and_shading_with_xarray(grid, xrgrid): """ Test that shading works well when xarray.DataArray is input to both the ``grid`` and ``shading`` arguments. """ fig_ref, fig_test = Figure(), Figure() fig_ref.grdimage( grid="@earth_relief_01d_g", region="GL", cmap="geo", shading=xrgrid, verbose="i" ) fig_ref.colorbar() fig_test.grdimage(grid=grid, region="GL", cmap="geo", shading=xrgrid, verbose="i") fig_test.colorbar() return fig_ref, fig_test
def test_makecpt_to_plot_grid_scaled_with_series(grid): """ Use static color palette table scaled to a min/max series to change color of grid """ # Use single-character arguments for the reference image fig_ref = Figure() makecpt(C="oleron", T="-4500/4500") fig_ref.grdimage(grid, J="W0/6i") fig_test = Figure() makecpt(cmap="oleron", series="-4500/4500") fig_test.grdimage(grid, projection="W0/6i") return fig_ref, fig_test
def test_grdimage_global_subset(grid_360): """ Ensure subsets of grids are plotted correctly on a global map. Specifically checking that xarray.DataArray grids can wrap around the left and right sides on a Mollweide projection (W) plot correctly. Note that a Cartesian grid is used here instead of a Geographic grid (i.e. GMT_GRID_IS_CARTESIAN). This is a regression test for https://github.com/GenericMappingTools/pygmt/issues/732. """ # Get a slice of South America and Africa only (lat=-90:31, lon=-180:41) sliced_grid = grid_360[0:121, 0:221] assert sliced_grid.gmt.registration == 0 # gridline registration assert sliced_grid.gmt.gtype == 0 # Cartesian coordinate system fig = Figure() fig.grdimage( grid=sliced_grid, cmap="vik", region="g", projection="W0/3.5c", frame=True ) return fig
def test_grdimage_shading_xarray(grid, shading): """ Test that shading works well for xarray. The ``shading`` can be True, a constant intensity, some modifiers, or a grid with modifiers. See https://github.com/GenericMappingTools/pygmt/issues/364 and https://github.com/GenericMappingTools/pygmt/issues/618. """ fig_ref, fig_test = Figure(), Figure() kwargs = dict( region=[-180, 180, -90, 90], frame=True, projection="Cyl_stere/6i", cmap="geo", shading=shading, ) fig_ref.grdimage("@earth_relief_01d_g", **kwargs) fig_test.grdimage(grid, **kwargs) return fig_ref, fig_test