Skip to content

Commit 79f4c87

Browse files
committed
Change getter methods to properties
1 parent c5897ba commit 79f4c87

File tree

1 file changed

+16
-47
lines changed

1 file changed

+16
-47
lines changed

pygmt/datatypes/header.py

Lines changed: 16 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -190,25 +190,17 @@ def _parse_dimensions(self):
190190
"attrs": [attrs[dim] for dim in dims],
191191
}
192192

193-
def get_name(self) -> str:
193+
@property
194+
def name(self) -> str:
194195
"""
195-
Get the name of the grid from the grid header.
196-
197-
Returns
198-
-------
199-
name
200-
The name of the grid.
196+
Name of the grid.
201197
"""
202198
return "z"
203199

204-
def get_data_attrs(self) -> dict:
200+
@property
201+
def data_attrs(self) -> dict[str, Any]:
205202
"""
206-
Get the attributes for the data variable from the grid header.
207-
208-
Returns
209-
-------
210-
attrs
211-
The attributes for the data variable.
203+
Attributes for the data variable from the grid header.
212204
"""
213205
attrs: dict[str, Any] = {}
214206
attrs["Conventions"] = "CF-1.7"
@@ -223,56 +215,33 @@ def get_data_attrs(self) -> dict:
223215
attrs["actual_range"] = np.array([self.z_min, self.z_max])
224216
return attrs
225217

226-
def get_dims(self):
218+
@property
219+
def dims(self) -> list:
227220
"""
228-
Get the dimension names from the grid header.
229-
230-
Returns
231-
-------
232-
dims : tuple
233-
The dimension names.
221+
List of dimension names.
234222
"""
235223
if not hasattr(self, "_nc"):
236224
self._parse_dimensions()
237225
return self._nc["dims"]
238226

239-
def get_dim_attrs(self) -> list:
227+
@property
228+
def dim_attrs(self) -> list[dict]:
240229
"""
241-
Get the attributes for each dimension from the grid header.
242-
243-
Returns
244-
-------
245-
attrs
246-
List of attributes for each dimension.
230+
List of attributes for each dimension.
247231
"""
248232
if not hasattr(self, "_nc"):
249233
self._parse_dimensions()
250234
return self._nc["attrs"]
251235

252-
def get_gtype(self) -> int:
236+
@property
237+
def gtype(self) -> int:
253238
"""
254-
Get the grid type from the grid header.
239+
Grid type. 0 for Cartesian grid and 1 for geographic grid.
255240
256241
The grid is assumed to be Cartesian by default. If the x/y dimensions are named
257242
"lon"/"lat" or have units "degrees_east"/"degrees_north", then the grid is
258243
assumed to be geographic.
259-
260-
Returns
261-
-------
262-
gtype
263-
The grid type. 0 for Cartesian grid and 1 for geographic grid.
264244
"""
265-
dims = self.get_dims()
245+
dims = self.dims
266246
gtype = 1 if dims[0] == "lat" and dims[1] == "lon" else 0
267247
return gtype
268-
269-
def get_registration(self) -> int:
270-
"""
271-
Get the grid registration from the grid header.
272-
273-
Returns
274-
-------
275-
registration
276-
The grid registration. 0 for gridline and 1 for pixel.
277-
"""
278-
return self.registration

0 commit comments

Comments
 (0)