Skip to content

Commit a93272b

Browse files
committed
Add enums for GMT grid format ID and only add the Conventions for netCDF files
1 parent 7544245 commit a93272b

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

doc/api/index.rst

+8
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,14 @@ In addition, there is also a special function to load XYZ tile maps via
242242

243243
.. currentmodule:: pygmt
244244

245+
Enumerations
246+
------------
247+
248+
.. autosummary::
249+
:toctree: generated
250+
251+
enums
252+
245253
Exceptions
246254
----------
247255

pygmt/datatypes/header.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from typing import Any, ClassVar
77

88
import numpy as np
9+
from pygmt.enums import GridID
910

1011
# Constants for lengths of grid header variables.
1112
#
@@ -203,7 +204,14 @@ def data_attrs(self) -> dict[str, Any]:
203204
Attributes for the data variable from the grid header.
204205
"""
205206
attrs: dict[str, Any] = {}
206-
attrs["Conventions"] = "CF-1.7"
207+
if self.type in { # netCDF format
208+
GridID.GMT_GRID_IS_NB,
209+
GridID.GMT_GRID_IS_NS,
210+
GridID.GMT_GRID_IS_NI,
211+
GridID.GMT_GRID_IS_NF,
212+
GridID.GMT_GRID_IS_ND,
213+
}:
214+
attrs["Conventions"] = "CF-1.7"
207215
attrs["title"] = self.title.decode()
208216
attrs["history"] = self.command.decode()
209217
attrs["description"] = self.remark.decode()

pygmt/enums.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""
2+
Enumerations for PyGMT.
3+
"""
4+
5+
from enum import IntEnum
6+
7+
8+
class GridID(IntEnum):
9+
"""
10+
Enum for the GMT grid format ID.
11+
12+
These enums are defined in 'gmt_grdio.h'.
13+
"""
14+
15+
GMT_GRD_UNKNOWN_FMT = 0 # If grid format cannot be auto-detected
16+
GMT_GRID_IS_BF = 1 # GMT native, C-binary format (32-bit float)
17+
GMT_GRID_IS_BS = 2 # GMT native, C-binary format (16-bit integer)
18+
GMT_GRID_IS_RB = 3 # SUN rasterfile format (8-bit standard)
19+
GMT_GRID_IS_BB = 4 # GMT native, C-binary format (8-bit integer)
20+
GMT_GRID_IS_BM = 5 # GMT native, C-binary format (bit-mask)
21+
GMT_GRID_IS_SF = 6 # Golden Software Surfer format 6 (32-bit float)
22+
GMT_GRID_IS_CB = 7 # GMT netCDF format (8-bit integer, depreciated)
23+
GMT_GRID_IS_CS = 8 # GMT netCDF format (16-bit integer, depreciated)
24+
GMT_GRID_IS_CI = 9 # GMT netCDF format (32-bit integer, depreciated)
25+
GMT_GRID_IS_CF = 10 # GMT netCDF format (32-bit float, depreciated)
26+
GMT_GRID_IS_CD = 11 # GMT netCDF format (64-bit float, depreciated)
27+
GMT_GRID_IS_RF = 12 # GEODAS grid format GRD98 (NGDC)
28+
GMT_GRID_IS_BI = 13 # GMT native, C-binary format (32-bit integer)
29+
GMT_GRID_IS_BD = 14 # GMT native, C-binary format (64-bit float)
30+
GMT_GRID_IS_NB = 15 # GMT netCDF format (8-bit integer)
31+
GMT_GRID_IS_NS = 16 # GMT netCDF format (16-bit integer)
32+
GMT_GRID_IS_NI = 17 # GMT netCDF format (32-bit integer)
33+
GMT_GRID_IS_NF = 18 # GMT netCDF format (32-bit float)
34+
GMT_GRID_IS_ND = 19 # GMT netCDF format (64-bit float)
35+
GMT_GRID_IS_SD = 20 # Golden Software Surfer format 7 (64-bit float, read-only)
36+
GMT_GRID_IS_AF = 21 # Atlantic Geoscience Center format AGC (32-bit float)
37+
GMT_GRID_IS_GD = 22 # Import through GDAL
38+
GMT_GRID_IS_EI = 23 # ESRI Arc/Info ASCII Grid Interchange format (ASCII integer)
39+
GMT_GRID_IS_EF = 24 # ESRI Arc/Info ASCII Grid Interchange format (ASCII float)

0 commit comments

Comments
 (0)