Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Figure.grdimage: Remove the unsupported 'img_out'/'A' parameter #2907

Merged
merged 3 commits into from
Dec 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions pygmt/src/grdimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
grdimage - Plot grids or images.
"""
from pygmt.clib import Session
from pygmt.exceptions import GMTInvalidInput
from pygmt.helpers import (
build_arg_string,
deprecate_parameter,
Expand All @@ -16,7 +17,6 @@
@fmt_docstring
@deprecate_parameter("bit_color", "bitcolor", "v0.10.0", remove_version="v0.12.0")
@use_alias(
A="img_out",
B="frame",
C="cmap",
D="img_in",
Expand Down Expand Up @@ -76,21 +76,6 @@ def grdimage(self, grid, **kwargs):
Parameters
----------
{grid}
img_out : str
*out_img*\[=\ *driver*].
Save an image in a raster format instead of PostScript. Append
*out_img* to select the image file name and extension. If the
extension is one of .bmp, .gif, .jpg, .png, or .tif then no driver
information is required. For other output formats you must append
the required GDAL driver. The *driver* is the driver code name used
by GDAL; see your GDAL installation's documentation for available
drivers. Append a **+c**\ *args* string where *args* is a list
of one or more concatenated number of GDAL **-co** arguments. For
example, to write a GeoPDF with the TerraGo format use
``=PDF+cGEO_ENCODING=OGC_BP``. **Notes**: (1) If a tiff file (.tif)
is selected then we will write a GeoTiff image if the GMT
projection syntax translates into a PROJ syntax, otherwise a plain
tiff file is produced. (2) Any vector elements will be lost.
{frame}
{cmap}
img_in : str
Expand Down Expand Up @@ -172,6 +157,13 @@ def grdimage(self, grid, **kwargs):
"""
kwargs = self._preprocess(**kwargs)

# Do not support -A option
if any(kwargs.get(arg) is not None for arg in ["A", "img_out"]):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if any(kwargs.get(arg) is not None for arg in ["A", "img_out"]):
if any(kwargs.get(arg) for arg in ["A", "img_out"]):

Should be ok to remove is not None, e.g.:

kwargs = {"img_out": "temp.nc"}
if any(kwargs.get(arg) for arg in ["A", "img_out"]):
    raise Exception

should raise an Exception.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't raise an exception if an empty string is given:

kwargs = {"img_out": ""}
if any(kwargs.get(arg) for arg in ["A", "img_out"]):
    raise Exception

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, keep it as is then.

raise GMTInvalidInput(
"Parameter 'img_out'/'A' is not implemented. "
"Please consider submitting a feature request to us."
)

with Session() as lib:
with lib.virtualfile_from_data(
check_kind="raster", data=grid
Expand Down
11 changes: 11 additions & 0 deletions pygmt/tests/test_grdimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,14 @@ def test_grdimage_central_meridians_and_standard_parallels(grid, proj_type, lon0
)
fig_test.grdimage(grid, projection=f"{proj_type}{lon0}/{lat0}/15c", cmap="geo")
return fig_ref, fig_test


def test_grdimage_imgout_fails(grid):
"""
Test that an exception is raised if img_out/A is given.
"""
fig = Figure()
with pytest.raises(GMTInvalidInput):
fig.grdimage(grid, img_out="out.png")
with pytest.raises(GMTInvalidInput):
fig.grdimage(grid, A="out.png")