2
2
Internal function to load GMT remote datasets.
3
3
"""
4
4
5
+ import contextlib
5
6
from collections .abc import Sequence
6
7
from typing import Any , Literal , NamedTuple
7
8
11
12
from pygmt .helpers import build_arg_list , kwargs_to_strings
12
13
from pygmt .src import which
13
14
15
+ with contextlib .suppress (ImportError ):
16
+ # rioxarray is needed to register the rio accessor
17
+ import rioxarray # noqa: F401
18
+
14
19
15
20
class Resolution (NamedTuple ):
16
21
"""
@@ -48,13 +53,17 @@ class GMTRemoteDataset(NamedTuple):
48
53
Dictionary of available resolution as keys and Resolution objects as values.
49
54
extra_attributes
50
55
A dictionary of extra or unique attributes of the dataset.
56
+ crs
57
+ The coordinate reference system of the raster image. Need to be set for images,
58
+ and should be ``None`` for grids.
51
59
"""
52
60
53
61
description : str
54
62
kind : Literal ["grid" , "image" ]
55
63
units : str | None
56
64
resolutions : dict [str , Resolution ]
57
65
extra_attributes : dict [str , Any ]
66
+ crs : str | None = None
58
67
59
68
60
69
datasets = {
@@ -81,6 +90,7 @@ class GMTRemoteDataset(NamedTuple):
81
90
description = "NASA Day Images" ,
82
91
kind = "image" ,
83
92
units = None ,
93
+ crs = "OGC:CRS84" ,
84
94
extra_attributes = {"long_name" : "blue_marble" , "horizontal_datum" : "WGS84" },
85
95
resolutions = {
86
96
"01d" : Resolution ("01d" , registrations = ["pixel" ]),
@@ -300,6 +310,7 @@ class GMTRemoteDataset(NamedTuple):
300
310
description = "NASA Night Images" ,
301
311
kind = "image" ,
302
312
units = None ,
313
+ crs = "OGC:CRS84" ,
303
314
extra_attributes = {"long_name" : "black_marble" , "horizontal_datum" : "WGS84" },
304
315
resolutions = {
305
316
"01d" : Resolution ("01d" , registrations = ["pixel" ]),
@@ -598,4 +609,9 @@ def _load_remote_dataset(
598
609
grid .attrs .pop ("actual_range" , None )
599
610
for coord in grid .coords :
600
611
grid [coord ].attrs .pop ("actual_range" , None )
612
+
613
+ # For images, if rioxarray is installed, set the coordinate reference system.
614
+ if dataset .crs is not None and hasattr (grid , "rio" ):
615
+ grid = grid .rio .write_crs (input_crs = dataset .crs )
616
+
601
617
return grid
0 commit comments