Skip to content

Commit

Permalink
Set CF-1.7-specific attributes for netCDF formats only
Browse files Browse the repository at this point in the history
  • Loading branch information
seisman committed Sep 29, 2024
1 parent 9972ba1 commit 62f0ce0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pygmt/datatypes/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ def to_dataarray(self) -> xr.DataArray:
title: Produced by grdcut
history: grdcut @earth_relief_01d_p -R-55/-47/-24/-10 -Gstatic_ea...
description: Reduced by Gaussian Cartesian filtering (111.2 km fullwi...
long_name: elevation (m)
actual_range: [190. 981.]
long_name: elevation (m)
>>> da.coords["lon"] # doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS
<xarray.DataArray 'lon' (lon: 8)>...
array([-54.5, -53.5, -52.5, -51.5, -50.5, -49.5, -48.5, -47.5])
Expand Down
10 changes: 5 additions & 5 deletions pygmt/datatypes/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,17 @@ def data_attrs(self) -> dict[str, Any]:
GridFormat.NI,
GridFormat.NF,
GridFormat.ND,
}: # Only set the 'Conventions' attribute for netCDF.
}: # Set attributes specific to CF-1.7 conventions
attrs["Conventions"] = "CF-1.7"
attrs["title"] = self.title.decode()
attrs["history"] = self.command.decode()
attrs["description"] = self.remark.decode()
attrs["title"] = self.title.decode()
attrs["history"] = self.command.decode()
attrs["description"] = self.remark.decode()
attrs["actual_range"] = np.array([self.z_min, self.z_max])
long_name, units = _parse_nameunits(self.z_units.decode())
if long_name:
attrs["long_name"] = long_name
if units:
attrs["units"] = units
attrs["actual_range"] = np.array([self.z_min, self.z_max])
return attrs

@property
Expand Down
4 changes: 0 additions & 4 deletions pygmt/datatypes/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,7 @@ def to_dataarray(self) -> xr.DataArray:
* x (x) float64... -179.5 -178.5 -177.5 -176.5 ... 177.5 178.5 179.5
* band (band) uint8... 1 2 3
Attributes:
title:
history:
description:
long_name: z
actual_range: [ 1.79769313e+308 -1.79769313e+308]
>>> da.coords["x"] # doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS
<xarray.DataArray 'x' (x: 360)>...
Expand Down

0 comments on commit 62f0ce0

Please sign in to comment.