@@ -70,6 +70,52 @@ class _GMT_GRID_HEADER(ctp.Structure): # noqa: N801
70
70
71
71
The class is used in the `GMT_GRID`/`GMT_IMAGE`/`GMT_CUBE` data structure. See the
72
72
GMT source code gmt_resources.h for the original C structure definitions.
73
+
74
+ Examples
75
+ --------
76
+ >>> from pprint import pprint
77
+ >>> from pygmt.clib import Session
78
+
79
+ >>> with Session() as lib:
80
+ ... with lib.virtualfile_out(kind="grid") as voutgrd:
81
+ ... lib.call_module("read", f"@static_earth_relief.nc {voutgrd} -Tg")
82
+ ... # Read the grid from the virtual file
83
+ ... grid = lib.read_virtualfile(voutgrd, kind="grid")
84
+ ... header = grid.contents.header.contents
85
+ ... name = header.get_name()
86
+ ... attrs = header.get_data_attrs()
87
+ ... dims = header.get_dims()
88
+ ... dim_attrs = header.get_dim_attrs()
89
+ ... gtype = header.get_gtype()
90
+ ... registration = header.get_registration()
91
+ >>> name
92
+ 'z'
93
+ >>> pprint(attrs)
94
+ {'Conventions': 'CF-1.7',
95
+ 'actual_range': array([190., 981.]),
96
+ 'description': 'Reduced by Gaussian Cartesian filtering (111.2 km fullwidth) '
97
+ 'from SRTM15_V2.3.nc [Sandwell et al., 2022; '
98
+ 'https://doi.org/10.1029/2021EA002069]',
99
+ 'history': 'grdcut @earth_relief_01d_p -R-55/-47/-24/-10 '
100
+ '-Gstatic_earth_relief.nc',
101
+ 'long_name': 'elevation (m)',
102
+ 'title': 'Produced by grdcut'}
103
+ >>> dims
104
+ ['lat', 'lon']
105
+ >>> pprint(dim_attrs[0])
106
+ {'actual_range': array([-24., -10.]),
107
+ 'axis': 'Y',
108
+ 'long_name': 'latitude',
109
+ 'standard_name': 'latitude',
110
+ 'units': 'degrees_north'}
111
+ >>> pprint(dim_attrs[1])
112
+ {'actual_range': array([-55., -47.]),
113
+ 'axis': 'X',
114
+ 'long_name': 'longitude',
115
+ 'standard_name': 'longitude',
116
+ 'units': 'degrees_east'}
117
+ >>> gtype, registration
118
+ (1, 1)
73
119
"""
74
120
75
121
_fields_ : ClassVar = [
@@ -212,9 +258,9 @@ def get_data_attrs(self) -> dict:
212
258
"""
213
259
attrs : dict [str , Any ] = {}
214
260
attrs ["Conventions" ] = "CF-1.7"
215
- attrs ["title" ] = self .title
216
- attrs ["history" ] = self .command
217
- attrs ["description" ] = self .remark
261
+ attrs ["title" ] = self .title . decode ()
262
+ attrs ["history" ] = self .command . decode ()
263
+ attrs ["description" ] = self .remark . decode ()
218
264
long_name , units = _parse_nameunits (self .z_units .decode ())
219
265
if long_name :
220
266
attrs ["long_name" ] = long_name
0 commit comments