Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions docs/iris/src/whatsnew/2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ Bugs Fixed
* The order in which files are passed to iris.load functions is now the order in
which they are processed. (#2325)

* Loading from netCDF files with :func:`iris.load` will load a cube for each scalar variable,
a variable that does not reference a netCDF dimension, unless that scalar variable is identified as
a CF scalar coordinate, referenced from another data variable via the 'coordinates' attribute.
Previously such data variables were ignored during load.


Incompatible Changes
====================
Expand Down
4 changes: 2 additions & 2 deletions lib/iris/fileformats/cf.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,8 @@ def identify(cls, variables, ignore=None, target=None, warn=True, monotonic=Fals
# String variables can't be coordinates
if _is_str_dtype(nc_var):
continue
# Restrict to one-dimensional with name as dimension OR zero-dimensional scalar
if not ((nc_var.ndim == 1 and nc_var_name in nc_var.dimensions) or (nc_var.ndim == 0)):
# Restrict to one-dimensional with name as dimension
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A zero dimensional scalar variable can never be a netcdf coordinate variable. The definitions within the CF Conventions and the netCDF user guide are explicit on this.
A 'coordinate variable' is one dimensional, with the same name as the dimension it is defining.
A scalar variable is not defined with respect to a dimension, it is a scalar.

if not (nc_var.ndim == 1 and nc_var_name in nc_var.dimensions):
continue
# Restrict to monotonic?
if monotonic:
Expand Down
9 changes: 9 additions & 0 deletions lib/iris/tests/integration/test_netcdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,5 +420,14 @@ def test_multi_packed_multi_dtype(self):
self._multi_test('multi_packed_multi_dtype.cdl', multi_dtype=True)


class TestScalarCube(tests.IrisTest):
def test_scalar_cube_save_load(self):
cube = iris.cube.Cube(1, long_name='scalar_cube')
with self.temp_filename(suffix='.nc') as fout:
iris.save(cube, fout)
scalar_cube = iris.load_cube(fout)
self.assertEqual(scalar_cube.name(), 'scalar_cube')


if __name__ == "__main__":
tests.main()