File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -75,6 +75,11 @@ def gmtread(
75
75
>>> dataarray = gmtread("@earth_relief_01d", kind="grid")
76
76
>>> type(dataarray)
77
77
<class 'xarray.core.dataarray.DataArray'>
78
+
79
+ Read an image into an :class:`xarray.DataArray` object:
80
+ >>> image = gmtread("@earth_day_01d", kind="image")
81
+ >>> type(image)
82
+ <class 'xarray.core.dataarray.DataArray'>
78
83
"""
79
84
if kind not in {"dataset" , "grid" , "image" }:
80
85
msg = f"Invalid kind '{ kind } ': must be one of 'dataset', 'grid', or 'image'."
Original file line number Diff line number Diff line change 6
6
7
7
import numpy as np
8
8
import pytest
9
+ import rioxarray
9
10
import xarray as xr
10
11
from pygmt import gmtread , which
11
12
12
13
_HAS_NETCDF4 = bool (importlib .util .find_spec ("netCDF4" ))
14
+ _HAS_RIORASTERIO = bool (importlib .util .find_spec ("rioxarray" ))
13
15
14
16
15
17
@pytest .mark .skipif (not _HAS_NETCDF4 , reason = "netCDF4 is not installed." )
@@ -24,6 +26,19 @@ def test_io_gmtread_grid():
24
26
assert np .allclose (grid , expected_grid )
25
27
26
28
29
+ @pytest .mark .skipif (not _HAS_RIORASTERIO , reason = "rioxarray is not installed." )
30
+ def test_io_gmtread_image ():
31
+ """
32
+ Test that reading an image returns an xr.DataArray.
33
+ """
34
+ image = gmtread ("@earth_day_01d" , kind = "image" )
35
+ assert isinstance (image , xr .DataArray )
36
+ with rioxarray .open_rasterio (
37
+ which ("@earth_day_01d" , download = "a" )
38
+ ) as expected_image :
39
+ assert np .allclose (image , expected_image )
40
+
41
+
27
42
def test_io_gmtread_invalid_kind ():
28
43
"""
29
44
Test that an invalid kind raises a ValueError.
You can’t perform that action at this time.
0 commit comments