def test_makecpt_plot_colorbar(position): """ Use static color palette table to plot a colorbar. """ fig = Figure() makecpt(cmap="relief") fig.colorbar(cmap=True, frame=True, position=position) return fig
def test_makecpt_cyclic(position): """ Use static color palette table that is cyclic. """ fig = Figure() makecpt(cmap="cork", cyclic=True) fig.colorbar(cmap=True, frame=True, position=position) return fig
def test_makecpt_categorical(position): """ Use static color palette table that is categorical. """ fig = Figure() makecpt(cmap="categorical", categorical=True) fig.colorbar(cmap=True, frame=True, position=position) return fig
def test_makecpt_reverse_color_only(position): """ Use static color palette table with its colors reversed. """ fig = Figure() makecpt(cmap="earth", reverse=True, series=[0, 1000]) fig.colorbar(cmap=True, frame=True, position=position) return fig
def test_makecpt_reverse_color_and_zsign(position): """ Use static color palette table with both its colors and z-value sign reversed. """ fig = Figure() makecpt(cmap="earth", reverse="cz", series=[0, 1000]) fig.colorbar(cmap=True, frame=True, position=position) return fig
def test_basemap_power_axis(): """ Create a power axis basemap plot. """ fig = Figure() fig.basemap(R=[0, 100, 0, 5000], J="x1p0.5/-0.001", B=['x1p+l"Crustal age"', "y500+lDepth"]) return fig
def test_figure_savefig(): """ Check if the arguments being passed to psconvert are correct. """ kwargs_saved = [] def mock_psconvert(*args, **kwargs): # pylint: disable=unused-argument """ Just record the arguments. """ kwargs_saved.append(kwargs) fig = Figure() fig.psconvert = mock_psconvert prefix = "test_figure_savefig" fname = ".".join([prefix, "png"]) fig.savefig(fname) assert kwargs_saved[-1] == dict(prefix=prefix, fmt="g", crop=True, Qt=2, Qg=2) fname = ".".join([prefix, "pdf"]) fig.savefig(fname) assert kwargs_saved[-1] == dict(prefix=prefix, fmt="f", crop=True, Qt=2, Qg=2) fname = ".".join([prefix, "png"]) fig.savefig(fname, transparent=True) assert kwargs_saved[-1] == dict(prefix=prefix, fmt="G", crop=True, Qt=2, Qg=2) fname = ".".join([prefix, "eps"]) fig.savefig(fname) assert kwargs_saved[-1] == dict(prefix=prefix, fmt="e", crop=True, Qt=2, Qg=2) fname = ".".join([prefix, "kml"]) fig.savefig(fname) assert kwargs_saved[-1] == dict(prefix=prefix, fmt="g", crop=True, Qt=2, Qg=2, W="+k")
def test_figure_show_notebook_error_without_ipython(): """ Test to check if an error is raised when display method is 'notebook', but IPython is not installed. """ fig = Figure() fig.basemap(region=[0, 1, 2, 3], frame=True) with pytest.raises(GMTError): fig.show(method="notebook")
def test_figure_savefig_ps_extension(): """ Check that an error is raised when .ps extension is specified. """ fig = Figure() fig.basemap(region="10/70/-300/800", projection="X3c/5c", frame="af") fname = "test_figure_savefig_ps_extension.ps" with pytest.raises(GMTInvalidInput, match="Extension '.ps' is not supported."): fig.savefig(fname)
def test_text_xy_with_position_fails(region): """ Run text by providing both x/y pairs and position arguments. """ fig = Figure() with pytest.raises(GMTInvalidInput): fig.text( region=region, projection="x1c", x=1.2, y=2.4, position="MC", text="text" )
def test_config_font_annot(): """ Test that setting `FONT_ANNOT` config changes both `FONT_ANNOT_PRIMARY` and `FONT_ANNOT_SECONDARY`. """ fig_ref = Figure() with config(FONT_ANNOT_PRIMARY="6p,red", FONT_ANNOT_SECONDARY="6p,red"): fig_ref.basemap(R="0/9/0/9", J="C3/3/9c", Tm="jTL+w4c+d4.5") fig_ref.basemap(compass="******") fig_test = Figure() with config(FONT_ANNOT="6p,red"): fig_test.basemap(region=[0, 9, 0, 9], projection="C3/3/9c", compass="******") fig_test.basemap(compass="******") return fig_ref, fig_test
def test_contour_from_file(region): """ Plot using the data file name instead of loaded data. """ fig = Figure() fig.contour( data=POINTS_DATA, projection="X10c", region=region, frame="af", pen="#ffcb87" ) return fig
def test_inset_aliases(): """ Test the aliases for the inset function. """ fig = Figure() fig.basemap(region="MG+r2", frame="afg") with fig.inset(position="jTL+w3.5c+o0.2c", margin=0, box="+pgreen"): fig.basemap(region="g", projection="G47/-20/4c", frame="afg") return fig
def test_makecpt_plot_colorbar_scaled_with_series(position): """ Use static color palette table scaled to a min/max series and plot it on a colorbar. """ fig = Figure() makecpt(cmap="oleron", series=[0, 1000]) fig.colorbar(cmap=True, frame=True, position=position) return fig
def test_makecpt_continuous(position): """ Use static color palette table that is continuous from blue to white and scaled from 0 to 1000 m. """ fig = Figure() makecpt(cmap="blue,white", continuous=True, series=[0, 1000]) fig.colorbar(cmap=True, frame=True, position=position) return fig
def test_grdview_with_perspective_and_zsize(xrgrid): """ Run grdview by passing in a grid and setting a perspective viewpoint with an azimuth from the SouthWest and an elevation angle 30 degrees from the z-plane, plus a z-axis size of 10cm. """ fig = Figure() fig.grdview(grid=xrgrid, perspective=[225, 30], zsize="10c") return fig
def test_grdcontour_slice(grid): """ Plot an contour image using an xarray grid that has been sliced. """ grid_ = grid.sel(lat=slice(-20, -10)) fig = Figure() fig.grdcontour(grid=grid_, interval=100, projection="M10c", frame=True) return fig
def test_subplot_basic_frame(): """ Create a subplot figure with 1 vertical row and 2 horizontal columns, and ensure map frame setting is applied to all subplot figures. """ fig_ref, fig_test = Figure(), Figure() with fig_ref.subplot(nrows=1, ncols=2, Ff="6c/3c", B="WSne"): with fig_ref.set_panel(panel=0): fig_ref.basemap(region=[0, 3, 0, 3], frame="+tplot0") with fig_ref.set_panel(panel=1): fig_ref.basemap(region=[0, 3, 0, 3], frame="+tplot1") with fig_test.subplot(nrows=1, ncols=2, figsize=("6c", "3c"), frame="WSne"): with fig_test.set_panel(panel="0,0"): fig_test.basemap(region=[0, 3, 0, 3], frame="+tplot0") with fig_test.set_panel(panel=[0, 1]): fig_test.basemap(region=[0, 3, 0, 3], frame="+tplot1") return fig_ref, fig_test
def test_figure_icc_gray(): """ Check if icc_gray parameter works correctly if used. """ fig = Figure() fig.basemap(region=[0, 1, 0, 1], projection="X1c/1c", frame=True) with pytest.warns(expected_warning=FutureWarning) as record: fig.psconvert(icc_gray=True, prefix="Test") assert len(record) == 1 # check that only one warning was raised
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_grdview_grid_file_with_region_subset(region): """ Run grdview by passing in a grid filename, and cropping it to a region. """ gridfile = which("@earth_relief_01d_g", download="a") fig = Figure() fig.grdview(grid=gridfile, region=region) 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_figure_savefig_filename_with_spaces(): """ Check if savefig (or psconvert) supports filenames with spaces. """ fig = Figure() fig.basemap(region=[0, 1, 0, 1], projection="X1c/1c", frame=True) with GMTTempFile(prefix="pygmt-filename with spaces", suffix=".png") as imgfile: fig.savefig(imgfile.name) assert os.path.exists(imgfile.name)
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_figure_show_invalid_method(): """ Test to check if an error is raised when an invalid method is passed to show. """ fig = Figure() fig.basemap(region="10/70/-300/800", projection="X3i/5i", frame="af") with pytest.raises(GMTInvalidInput): fig.show(method="test")
def test_inset_context_manager(): """ Test that the inset context manager works and, once closed, plotting elements are added to the larger figure. """ fig_ref, fig_test = Figure(), Figure() fig_ref.basemap(region=[-74, -69.5, 41, 43], projection="M9c", frame=True) fig_ref.basemap(rose="jTR+w3c") # Pass rose argument with basemap before the inset with fig_ref.inset(position="jBL+w3c+o0.2c", margin=0, box="+pblack"): fig_ref.basemap(region=[-80, -65, 35, 50], projection="M3c", frame="afg") fig_test.basemap(region=[-74, -69.5, 41, 43], projection="M9c", frame=True) with fig_test.inset(position="jBL+w3c+o0.2c", margin=0, box="+pblack"): fig_test.basemap(region=[-80, -65, 35, 50], projection="M3c", frame="afg") fig_test.basemap(rose="jTR+w3c") # Pass rose argument with basemap after the inset return fig_ref, fig_test
def test_text_varying_transparency(): "Add texts with varying transparency" x = np.arange(1, 10) y = np.arange(11, 20) text = [f"TEXT-{i}-{j}" for i, j in zip(x, y)] transparency = np.arange(10, 100, 10) fig_ref, fig_test = Figure(), Figure() # Use single-character arguments for the reference image with GMTTempFile() as tmpfile: np.savetxt(tmpfile.name, np.c_[x, y, transparency, text], fmt="%s") fig_ref.basemap(R="0/10/10/20", J="X10c", B="") fig_ref.text(textfiles=tmpfile.name, t="") fig_test.basemap(region=[0, 10, 10, 20], projection="X10c", frame=True) fig_test.text(x=x, y=y, text=text, transparency=transparency) return fig_ref, fig_test
def test_subplot_figsize_and_subsize_error(): """ Check that an error is raised when both figsize and subsize parameters are passed into subplot. """ fig = Figure() with pytest.raises(GMTInvalidInput): with fig.subplot(figsize=("2c", "1c"), subsize=("2c", "1c")): pass
def test_basemap_rose(): """ Create a map with a rose. """ fig = Figure() fig.basemap( region=[127.5, 128.5, 26, 27], projection="H15c", frame=True, rose="jMC+w5c" ) return fig
def test_colorbar_truncated_to_zlow_zhigh(): """ Create colorbar truncated to z-low and z-high. """ fig = Figure() fig.colorbar(cmap="rainbow", truncate=[0.15, 0.85], position="x0c/0c+w2c/0.5c") return fig