From aa8a47477a13f22889491e00093da9488f091557 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Sat, 17 Feb 2024 16:34:44 +1300 Subject: [PATCH] Use rioxarray.open_rasterio to open earth_day images --- pygmt/datasets/load_remote_dataset.py | 3 ++- pygmt/io.py | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pygmt/datasets/load_remote_dataset.py b/pygmt/datasets/load_remote_dataset.py index ef0737e7f98..190e8f38c6d 100644 --- a/pygmt/datasets/load_remote_dataset.py +++ b/pygmt/datasets/load_remote_dataset.py @@ -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) diff --git a/pygmt/io.py b/pygmt/io.py index 9c27e7b08b5..e612da5a692 100644 --- a/pygmt/io.py +++ b/pygmt/io.py @@ -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