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

In cf.write, allow dimension coordinate constructs' netCDF names to be added to the coordinates netCDF attribute, if the user desires. Currently they are always omitted. Either way is CF-compliant. #126

Merged
merged 2 commits into from
Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
cf.write 'coordinates' parameter
  • Loading branch information
davidhassell committed Sep 30, 2020
commit 17892111e85f85cd526913acea7b2202777273a1
11 changes: 9 additions & 2 deletions cf/read_write/netcdf/netcdfwrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ def _write_data(self, data, cfvar, ncvar, ncdimensions,

partition.close()

def _write_dimension_coordinate(self, f, key, coord, ncdim=None):
def _write_dimension_coordinate(self, f, key, coord, ncdim=None,
coordinates=None):
'''Write a coordinate variable and its bound variable to the file.

This also writes a new netCDF dimension to the file and, if
Expand All @@ -160,6 +161,11 @@ def _write_dimension_coordinate(self, f, key, coord, ncdim=None):

.. versionadded:: 3.6.0

coordinates: `list`
This list may get updated in-place.

.. versionadded:: 3.7.0

:Returns:

`str`
Expand All @@ -169,7 +175,8 @@ def _write_dimension_coordinate(self, f, key, coord, ncdim=None):
coord = self._change_reference_datetime(coord)

return super()._write_dimension_coordinate(f, key, coord,
ncdim=ncdim)
ncdim=ncdim,
coordinates=coordinates)

def _write_scalar_coordinate(self, f, key, coord_1d, axis,
coordinates, extra=None):
Expand Down
13 changes: 11 additions & 2 deletions cf/read_write/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def write(fields, filename, fmt='NETCDF4', overwrite=True,
fletcher32=False, shuffle=True, reference_datetime=None,
verbose=None, cfa_options=None, mode='w', single=None,
double=None, variable_attributes=None, string=True,
warn_valid=True, group=True, HDF_chunksizes=None,
no_shuffle=None, unlimited=None):
warn_valid=True, group=True, coordinates=False,
HDF_chunksizes=None, no_shuffle=None, unlimited=None):
'''Write field constructs to a netCDF file.


Expand Down Expand Up @@ -517,6 +517,14 @@ def write(fields, filename, fmt='NETCDF4', overwrite=True,

.. versionadded:: 3.6.0

coordinates: `bool`, optional
If True then include CF-netCDF coordinate variable names
in the 'coordinates' attribute of output data
variables. By default only auxiliary and scalar coordinate
variables are included.

.. versionadded:: (cfdm) 3.7.0

HDF_chunksizes: deprecated at version 3.0.0
HDF chunk sizes may be set for individual constructs prior
to writing, instead. See `cf.Data.nc_set_hdf5_chunksizes`.
Expand Down Expand Up @@ -655,6 +663,7 @@ def write(fields, filename, fmt='NETCDF4', overwrite=True,
shuffle=shuffle, fletcher32=fletcher32,
verbose=verbose, string=string,
warn_valid=warn_valid, group=group,
coordinates=coordinates,
extra_write_vars=extra_write_vars)
# --- End: if

Expand Down