diff --git a/docs/iris/src/whatsnew/2.0.rst b/docs/iris/src/whatsnew/2.0.rst index ebdf09a123..28c78e11fc 100644 --- a/docs/iris/src/whatsnew/2.0.rst +++ b/docs/iris/src/whatsnew/2.0.rst @@ -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 ==================== diff --git a/lib/iris/fileformats/cf.py b/lib/iris/fileformats/cf.py index da43230afd..c641a67fb6 100644 --- a/lib/iris/fileformats/cf.py +++ b/lib/iris/fileformats/cf.py @@ -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 + if not (nc_var.ndim == 1 and nc_var_name in nc_var.dimensions): continue # Restrict to monotonic? if monotonic: diff --git a/lib/iris/tests/integration/test_netcdf.py b/lib/iris/tests/integration/test_netcdf.py index fcab14d973..5351e615d8 100644 --- a/lib/iris/tests/integration/test_netcdf.py +++ b/lib/iris/tests/integration/test_netcdf.py @@ -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()