Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add enums GridFormat for GMT grid format ID #3449

Merged
merged 17 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion doc/_templates/autosummary/class.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
.. rubric:: Attributes

{% for item in attributes %}
.. autoproperty::
{% if item not in inherited_members %}
.. autoattribute::
{{ objname }}.{{ item }}
{% endif %}
{% endfor %}
{% endif %}

Expand Down
8 changes: 8 additions & 0 deletions doc/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,14 @@ In addition, there is also a special function to load XYZ tile maps via

.. currentmodule:: pygmt

Enumerations
------------

.. autosummary::
:toctree: generated

enums.GridFormat

Exceptions
----------

Expand Down
10 changes: 9 additions & 1 deletion pygmt/datatypes/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Any, ClassVar

import numpy as np
from pygmt.enums import GridFormat

# Constants for lengths of grid header variables.
#
Expand Down Expand Up @@ -203,7 +204,14 @@ def data_attrs(self) -> dict[str, Any]:
Attributes for the data variable from the grid header.
"""
attrs: dict[str, Any] = {}
attrs["Conventions"] = "CF-1.7"
if self.type in {
GridFormat.NB,
GridFormat.NS,
GridFormat.NI,
GridFormat.NF,
GridFormat.ND,
}: # Only set the 'Conventions' attribute for netCDF.
attrs["Conventions"] = "CF-1.7"
attrs["title"] = self.title.decode()
attrs["history"] = self.command.decode()
attrs["description"] = self.remark.decode()
Expand Down
39 changes: 39 additions & 0 deletions pygmt/enums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""
Enumerations for PyGMT.
"""

from enum import IntEnum


class GridFormat(IntEnum):
"""
Enum for the GMT grid format ID.

These enums are defined in 'gmt_grdio.h'.
"""

UNKNOWN = 0 #: Unknown grid format
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BF = 1 #: GMT native, C-binary format (32-bit float)
BS = 2 #: GMT native, C-binary format (16-bit integer)
RB = 3 #: SUN rasterfile format (8-bit standard)
BB = 4 #: GMT native, C-binary format (8-bit integer)
BM = 5 #: GMT native, C-binary format (bit-mask)
SF = 6 #: Golden Software Surfer format 6 (32-bit float)
CB = 7 #: GMT netCDF format (8-bit integer, depreciated)
CS = 8 #: GMT netCDF format (16-bit integer, depreciated)
CI = 9 #: GMT netCDF format (32-bit integer, depreciated)
CF = 10 #: GMT netCDF format (32-bit float, depreciated)
CD = 11 #: GMT netCDF format (64-bit float, depreciated)
seisman marked this conversation as resolved.
Show resolved Hide resolved
RF = 12 #: GEODAS grid format GRD98 (NGDC)
BI = 13 #: GMT native, C-binary format (32-bit integer)
BD = 14 #: GMT native, C-binary format (64-bit float)
NB = 15 #: GMT netCDF format (8-bit integer)
NS = 16 #: GMT netCDF format (16-bit integer)
NI = 17 #: GMT netCDF format (32-bit integer)
NF = 18 #: GMT netCDF format (32-bit float)
ND = 19 #: GMT netCDF format (64-bit float)
SD = 20 #: Golden Software Surfer format 7 (64-bit float, read-only)
AF = 21 #: Atlantic Geoscience Center format AGC (32-bit float)
GD = 22 #: Import through GDAL
EI = 23 #: ESRI Arc/Info ASCII Grid Interchange format (ASCII integer)
EF = 24 #: ESRI Arc/Info ASCII Grid Interchange format (ASCII float)