Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
tkknight committed Nov 10, 2023
1 parent d744432 commit 6095be4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
43 changes: 27 additions & 16 deletions lib/iris/fileformats/netcdf/saver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# See COPYING and COPYING.LESSER in the root of the repository for full
# licensing details.
"""
Module to support the saving of Iris cubes to a NetCDF file.
Module to support the saving of Iris cubes to a NetCDF file, also using the CF
conventions for metadata interpretation.
Expand Down Expand Up @@ -186,13 +188,11 @@ def append(self, name, coord):
@property
def names(self):
"""Return all the CF names."""

return [pair.name for pair in self._map]

@property
def coords(self):
"""Return all the coordinates."""

return [pair.coord for pair in self._map]

def name(self, coord):
Expand Down Expand Up @@ -237,6 +237,8 @@ def coord(self, name):

def _bytes_if_ascii(string):
"""
Convert string to a byte string (str in py2k, bytes in py3k).
Convert the given string to a byte string (str in py2k, bytes in py3k)
if the given string can be encoded to ascii, else maintain the type
of the inputted string.
Expand All @@ -255,6 +257,8 @@ def _bytes_if_ascii(string):

def _setncattr(variable, name, attribute):
"""
Put the given attribute on the given netCDF4 Data type.
Put the given attribute on the given netCDF4 Data type, casting
attributes as we go to bytes rather than unicode.
Expand Down Expand Up @@ -313,6 +317,8 @@ class SaverFillValueWarning(UserWarning):

def _fillvalue_report(fill_info, is_masked, contains_fill_value, warn=False):
"""
Work out whether there was a possible or actual fill-value collision.
From the given information, work out whether there was a possible or actual
fill-value collision, and if so construct a warning.
Expand Down Expand Up @@ -367,7 +373,7 @@ class Saver:

def __init__(self, filename, netcdf_format, compute=True):
"""
A manager for saving netcdf files.
Manage saving netcdf files.
Parameters
----------
Expand Down Expand Up @@ -815,6 +821,8 @@ def _create_cf_dimensions(

def _add_mesh(self, cube_or_mesh):
"""
Add the cube's mesh, and all related variables to the dataset.
Add the cube's mesh, and all related variables to the dataset.
Includes all the mesh-element coordinate and connectivity variables.
Expand Down Expand Up @@ -947,6 +955,8 @@ def _add_inner_related_vars(
self, cube, cf_var_cube, dimension_names, coordlike_elements
):
"""
Create a set of variables for aux-coords, ancillaries or cell-measures.
Create a set of variables for aux-coords, ancillaries or cell-measures,
and attach them to the parent data variable.
Expand Down Expand Up @@ -991,7 +1001,7 @@ def _add_inner_related_vars(

def _add_aux_coords(self, cube, cf_var_cube, dimension_names):
"""
Add aux. coordinate to the dataset and associate with the data variable
Add aux. coordinate to the dataset and associate with the data variable.
Parameters
----------
Expand All @@ -1015,7 +1025,7 @@ def _add_aux_coords(self, cube, cf_var_cube, dimension_names):

def _add_cell_measures(self, cube, cf_var_cube, dimension_names):
"""
Add cell measures to the dataset and associate with the data variable
Add cell measures to the dataset and associate with the data variable.
Parameters
----------
Expand All @@ -1035,8 +1045,7 @@ def _add_cell_measures(self, cube, cf_var_cube, dimension_names):

def _add_ancillary_variables(self, cube, cf_var_cube, dimension_names):
"""
Add ancillary variables measures to the dataset and associate with the
data variable
Add ancillary variables measures to the dataset and associate with the data variable.
Parameters
----------
Expand Down Expand Up @@ -1077,7 +1086,9 @@ def _add_dim_coords(self, cube, dimension_names):

def _add_aux_factories(self, cube, cf_var_cube, dimension_names):
"""
Modifies the variables of the NetCDF dataset to represent
Represent the presence of dimensionless vertical coordinates.
Modify the variables of the NetCDF dataset to represent
the presence of dimensionless vertical coordinates based on
the aux factories of the cube (if any).
Expand Down Expand Up @@ -1198,6 +1209,8 @@ def record_dimension(
names_list, dim_name, length, matching_coords=None
):
"""
Record a file dimension, its length and associated "coordinates".
Record a file dimension, its length and associated "coordinates"
(which may in fact also be connectivities).
Expand Down Expand Up @@ -1542,7 +1555,7 @@ def _create_cf_bounds(self, coord, cf_var, cf_name):

def _get_cube_variable_name(self, cube):
"""
Returns a CF-netCDF variable name for the given cube.
Return a CF-netCDF variable name for the given cube.
Parameters
----------
Expand All @@ -1567,7 +1580,7 @@ def _get_cube_variable_name(self, cube):

def _get_coord_variable_name(self, cube_or_mesh, coord):
"""
Returns a CF-netCDF variable name for a given coordinate-like element.
Return a CF-netCDF variable name for a given coordinate-like element.
Parameters
----------
Expand Down Expand Up @@ -1630,7 +1643,7 @@ def _get_coord_variable_name(self, cube_or_mesh, coord):

def _get_mesh_variable_name(self, mesh):
"""
Returns a CF-netCDF variable name for the mesh.
Return a CF-netCDF variable name for the mesh.
Parameters
----------
Expand Down Expand Up @@ -1741,6 +1754,8 @@ def _create_generic_cf_array_var(
fill_value=None,
):
"""
Create theCF-netCDF variable given dimensional_metadata.
Create the associated CF-netCDF variable in the netCDF dataset for the
given dimensional_metadata.
Expand Down Expand Up @@ -1774,7 +1789,6 @@ def _create_generic_cf_array_var(
-------
str
The name of the CF-netCDF variable created.
"""
# Support cube or mesh save.
from iris.cube import Cube
Expand Down Expand Up @@ -2581,7 +2595,7 @@ def save(
fill_value=None,
compute=True,
):
"""
r"""
Save cube(s) to a netCDF file, given the cube and the filename.
* Iris will write CF 1.7 compliant NetCDF files.
Expand Down Expand Up @@ -2733,9 +2747,6 @@ def save(
The `zlib`, `complevel`, `shuffle`, `fletcher32`, `contiguous`,
`chunksizes` and `endian` keywords are silently ignored for netCDF 3
files that do not use HDF5.
"""
from iris.cube import Cube, CubeList

Expand Down
4 changes: 2 additions & 2 deletions lib/iris/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ def load_http(urls, callback):

def load_data_objects(urls, callback):
"""
Takes a list of data-source objects and a callback function, and returns a
generator of Cubes.
Take a list of data-source objects and a callback function, returns a generator of Cubes.
The 'objects' take the place of 'uris' in the load calls.
The appropriate types of the data-source objects are expected to be
recognised by the handlers : This is done in the usual way by passing the
Expand Down

0 comments on commit 6095be4

Please sign in to comment.