|
3 | 3 | """
|
4 | 4 |
|
5 | 5 | import ctypes as ctp
|
6 |
| -from typing import ClassVar |
| 6 | +from typing import ClassVar, Any |
7 | 7 |
|
8 | 8 | import numpy as np
|
9 | 9 |
|
@@ -143,26 +143,21 @@ class _GMT_GRID_HEADER(ctp.Structure): # noqa: N801
|
143 | 143 | ("hidden", ctp.c_void_p),
|
144 | 144 | ]
|
145 | 145 |
|
146 |
| - def _parse_dimensions(self) -> dict[str, list]: |
| 146 | + def _parse_dimensions(self): |
147 | 147 | """
|
148 | 148 | Get dimension names and attributes from the grid header.
|
149 | 149 |
|
150 | 150 | For a 2-D grid, the dimension names are set to "y" and "x" by default. The
|
151 | 151 | attributes for each dimension are parsed from the grid header following GMT
|
152 | 152 | source codes. See the GMT functions "gmtnc_put_units", "gmtnc_get_units" and
|
153 | 153 | "gmtnc_grd_info" for reference.
|
154 |
| -
|
155 |
| - Returns |
156 |
| - ------- |
157 |
| - dict |
158 |
| - Dictionary containing the list of dimension names and attributes. |
159 | 154 | """
|
160 | 155 | # Default dimension names.
|
161 |
| - dims: tuple = ("y", "x") |
| 156 | + dims = ("y", "x") |
162 | 157 | nameunits = (self.y_units, self.x_units)
|
163 | 158 |
|
164 | 159 | # Dictionary for dimension attributes with the dimension name as the key.
|
165 |
| - attrs: dict = {dim: {} for dim in dims} |
| 160 | + attrs = {dim: {} for dim in dims} |
166 | 161 | # Dictionary for mapping the default dimension names to the actual names.
|
167 | 162 | newdims = {dim: dim for dim in dims}
|
168 | 163 | # Loop over dimensions and get the dimension name and attributes from header
|
@@ -214,16 +209,17 @@ def get_data_attrs(self) -> dict:
|
214 | 209 | attrs
|
215 | 210 | The attributes for the data variable.
|
216 | 211 | """
|
217 |
| - attrs = {"Conventions": "CF-1.7"} |
| 212 | + attrs : dict[str, Any] = {} |
| 213 | + attrs["Conventions"] = "CF-1.7" |
| 214 | + attrs["title"] = self.title |
| 215 | + attrs["history"] = self.command |
| 216 | + attrs["description"] = self.remark |
218 | 217 | long_name, units = _parse_nameunits(self.z_units.decode())
|
219 | 218 | if long_name:
|
220 | 219 | attrs["long_name"] = long_name
|
221 | 220 | if units:
|
222 | 221 | attrs["units"] = units
|
223 | 222 | attrs["actual_range"] = np.array([self.z_min, self.z_max])
|
224 |
| - attrs["title"] = self.title |
225 |
| - attrs["history"] = self.command |
226 |
| - attrs["description"] = self.remark |
227 | 223 | return attrs
|
228 | 224 |
|
229 | 225 | def get_dims(self):
|
|
0 commit comments