Skip to content

Commit

Permalink
Use rioxarray.open_rasterio to open earth_day images
Browse files Browse the repository at this point in the history
  • Loading branch information
weiji14 committed Feb 17, 2024
1 parent e839ef7 commit aa8a474
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pygmt/datasets/load_remote_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,8 @@ def _load_remote_dataset(
f"'region' is required for {dataset.title} resolution '{resolution}'."
)
fname = which(f"@{dataset_prefix}{resolution}{reg}", download="a")
grid = load_dataarray(fname, engine="netcdf4")
engine = "rasterio" if dataset_prefix == "earth_day_" else "netcdf4"
grid = load_dataarray(fname, engine=engine)
else:
grid = grdcut(f"@{dataset_prefix}{resolution}{reg}", region=region)

Expand Down
10 changes: 9 additions & 1 deletion pygmt/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,15 @@ def load_dataarray(filename_or_obj, **kwargs):
if "cache" in kwargs:
raise TypeError("cache has no effect in this context")

with xr.open_dataarray(filename_or_obj, **kwargs) as dataarray:
if kwargs.get("engine") == "rasterio":
import rioxarray

open_dataarray_func = rioxarray.open_rasterio
kwargs.pop("engine")
else:
open_dataarray_func = xr.open_dataarray

with open_dataarray_func(filename_or_obj, **kwargs) as dataarray:
result = dataarray.load()
_ = result.gmt # load GMTDataArray accessor information

Expand Down

0 comments on commit aa8a474

Please sign in to comment.