Skip to content
Open
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
14 changes: 8 additions & 6 deletions pygmt/clib/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -1895,13 +1895,15 @@ def virtualfile_in( # noqa: PLR0912
_data = data
match kind:
case "image" if data.dtype != "uint8":
msg = (
f"Input image has dtype: {data.dtype} which is unsupported, and "
"may result in an incorrect output. Please recast image to a uint8 "
"dtype and/or scale to 0-255 range, e.g. using a histogram "
"equalization function like skimage.exposure.equalize_hist."
raise GMTTypeError(
data.dtype,
reason=(
"Only uint8 images are supported. Please recast image to a "
"uint8 dtype and/or scale to 0-255 range, e.g. using a "
"histogram equalization function like "
"skimage.exposure.equalize_hist."
),
)
warnings.warn(message=msg, category=RuntimeWarning, stacklevel=2)
case "empty": # data is None, so data must be given via x/y/z.
_data = [x, y]
if z is not None:
Expand Down
4 changes: 2 additions & 2 deletions pygmt/tests/test_grdimage_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pygmt import Figure
from pygmt.clib.session import DTYPES_NUMERIC
from pygmt.datasets import load_blue_marble
from pygmt.exceptions import GMTTypeError

rioxarray = pytest.importorskip("rioxarray")

Expand Down Expand Up @@ -53,6 +54,5 @@ def test_grdimage_image_dataarray_unsupported_dtype(dtype, xr_image):
"""
fig = Figure()
image = xr_image.copy().astype(dtype=dtype)
with pytest.warns(expected_warning=RuntimeWarning) as record:
with pytest.raises(GMTTypeError, match="Only uint8 images are supported"):
fig.grdimage(grid=image)
assert len(record) == 1
Loading