Skip to content

Commit c36f901

Browse files
corinnebosleydjkirkham
authored andcommitted
Futures netcdf no unlimited (#2838)
* switched boolean operator and altered docstring * raised error on future flag and tweaked functionality * small change to deprecation warning message * Code changes * remake cdl results * More CDL updates (cherry picked from commit 47272b3) * Review actions
1 parent 2ed03db commit c36f901

File tree

71 files changed

+447
-468
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+447
-468
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
* Deprecated FUTURE flag :attr:`iris.Future.netcdf_no_unlimited`.
2+
3+
* Removed deprecated behaviour that automatically set the length of the outer netCDF variable to 'UNLIMITED' on save.
4+
This change means that no cube dimension coordinates will be automatically saved as netCDF variables with 'UNLIMITED' length.
5+
You can manually specify cube dimension coordinates to save with 'UNLIMITED' length.
6+
7+
For example::
8+
>>> iris.save(my_cube, 'my_result_file.nc', unlimited_dimensions=['latitude'])

lib/iris/__init__.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class Future(threading.local):
138138
"""Run-time configuration controller."""
139139

140140
def __init__(self, cell_datetime_objects=True, netcdf_promote=True,
141-
netcdf_no_unlimited=False, clip_latitudes=True):
141+
netcdf_no_unlimited=True, clip_latitudes=True):
142142
"""
143143
A container for run-time options controls.
144144
@@ -184,10 +184,15 @@ def __init__(self, cell_datetime_objects=True, netcdf_promote=True,
184184
exposed variables that defined reference surfaces for
185185
dimensionless vertical coordinates as independent Cubes.
186186
187-
The option `netcdf_no_unlimited`, when True, changes the
188-
behaviour of the netCDF saver, such that no dimensions are set to
189-
unlimited. The current default is that the leading dimension is
190-
unlimited unless otherwise specified.
187+
.. deprecated:: 2.0.0
188+
189+
The option `netcdf_no_unlimited` is deprecated and will be removed
190+
in a future release. The deprecated code paths this option used to
191+
toggle have been removed.
192+
193+
The option `netcdf_no_unlimited` changed the behaviour of the
194+
netCDF saver regarding unlimited dimensions. The netCDF saver now
195+
sets no dimensions to unlimited.
191196
192197
.. deprecated:: 2.0.0
193198
@@ -212,6 +217,7 @@ def __repr__(self):
212217
self.netcdf_no_unlimited, self.clip_latitudes)
213218

214219
deprecated_options = {'cell_datetime_objects': 'warning',
220+
'netcdf_no_unlimited': 'error',
215221
'netcdf_promote': 'error',
216222
'clip_latitudes': 'warning'}
217223

lib/iris/fileformats/netcdf.py

Lines changed: 20 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -851,13 +851,11 @@ def write(self, cube, local_keys=None, unlimited_dimensions=None,
851851
852852
* unlimited_dimensions (iterable of strings and/or
853853
:class:`iris.coords.Coord` objects):
854-
Explicit list of coordinate names (or coordinate objects)
854+
List of coordinate names (or coordinate objects)
855855
corresponding to coordinate dimensions of `cube` to save with the
856-
NetCDF dimension variable length 'UNLIMITED'. By default, the
857-
outermost (first) dimension for each cube is used. Only the
858-
'NETCDF4' format supports multiple 'UNLIMITED' dimensions. To save
859-
no unlimited dimensions, use `unlimited_dimensions=[]` (an empty
860-
list).
856+
NetCDF dimension variable length 'UNLIMITED'. By default, no
857+
unlimited dimensions are saved. Only the 'NETCDF4' format
858+
supports multiple 'UNLIMITED' dimensions.
861859
862860
* zlib (bool):
863861
If `True`, the data will be compressed in the netCDF file using
@@ -942,19 +940,9 @@ def write(self, cube, local_keys=None, unlimited_dimensions=None,
942940
`chunksizes` and `endian` keywords are silently ignored for netCDF
943941
3 files that do not use HDF5.
944942
945-
.. deprecated:: 1.8.0
946-
947-
NetCDF default saving behaviour currently assigns the outermost
948-
dimension as unlimited. This behaviour is to be deprecated, in
949-
favour of no automatic assignment. To switch to the new behaviour,
950-
set `iris.FUTURE.netcdf_no_unlimited` to True.
951-
952-
"""
943+
"""
953944
if unlimited_dimensions is None:
954-
if iris.FUTURE.netcdf_no_unlimited:
955945
unlimited_dimensions = []
956-
else:
957-
_no_unlim_dep_warning()
958946

959947
cf_profile_available = (iris.site_configuration.get('cf_profile') not
960948
in [None, False])
@@ -1088,29 +1076,23 @@ def _create_cf_dimensions(self, cube, dimension_names,
10881076
10891077
* unlimited_dimensions (iterable of strings and/or
10901078
:class:`iris.coords.Coord` objects):
1091-
List of coordinates to make unlimited. By default, the
1092-
outermost dimension is made unlimited.
1079+
List of coordinates to make unlimited (None by default).
10931080
10941081
Returns:
10951082
None.
10961083
10971084
"""
10981085
unlimited_dim_names = []
1099-
if (unlimited_dimensions is None and
1100-
not iris.FUTURE.netcdf_no_unlimited):
1101-
if dimension_names:
1102-
unlimited_dim_names.append(dimension_names[0])
1103-
else:
1104-
for coord in unlimited_dimensions:
1105-
try:
1106-
coord = cube.coord(name_or_coord=coord, dim_coords=True)
1107-
except iris.exceptions.CoordinateNotFoundError:
1108-
# coordinate isn't used for this cube, but it might be
1109-
# used for a different one
1110-
pass
1111-
else:
1112-
dim_name = self._get_coord_variable_name(cube, coord)
1113-
unlimited_dim_names.append(dim_name)
1086+
for coord in unlimited_dimensions:
1087+
try:
1088+
coord = cube.coord(name_or_coord=coord, dim_coords=True)
1089+
except iris.exceptions.CoordinateNotFoundError:
1090+
# coordinate isn't used for this cube, but it might be
1091+
# used for a different one
1092+
pass
1093+
else:
1094+
dim_name = self._get_coord_variable_name(cube, coord)
1095+
unlimited_dim_names.append(dim_name)
11141096

11151097
for dim_name in dimension_names:
11161098
if dim_name not in self._dataset.dimensions:
@@ -2127,12 +2109,11 @@ def save(cube, filename, netcdf_format='NETCDF4', local_keys=None,
21272109
21282110
* unlimited_dimensions (iterable of strings and/or
21292111
:class:`iris.coords.Coord` objects):
2130-
Explicit list of coordinate names (or coordinate objects) corresponding
2112+
List of coordinate names (or coordinate objects) corresponding
21312113
to coordinate dimensions of `cube` to save with the NetCDF dimension
2132-
variable length 'UNLIMITED'. By default, the outermost (first)
2133-
dimension for each cube is used. Only the 'NETCDF4' format supports
2134-
multiple 'UNLIMITED' dimensions. To save no unlimited dimensions, use
2135-
`unlimited_dimensions=[]` (an empty list).
2114+
variable length 'UNLIMITED'. By default, no unlimited dimensions are
2115+
saved. Only the 'NETCDF4' format supports multiple 'UNLIMITED'
2116+
dimensions.
21362117
21372118
* zlib (bool):
21382119
If `True`, the data will be compressed in the netCDF file using gzip
@@ -2225,19 +2206,9 @@ def save(cube, filename, netcdf_format='NETCDF4', local_keys=None,
22252206
22262207
NetCDF Context manager (:class:`~Saver`).
22272208
2228-
.. deprecated:: 1.8.0
2229-
2230-
NetCDF default saving behaviour currently assigns the outermost
2231-
dimensions to unlimited. This behaviour is to be deprecated, in
2232-
favour of no automatic assignment. To switch to the new behaviour,
2233-
set `iris.FUTURE.netcdf_no_unlimited` to True.
2234-
22352209
"""
22362210
if unlimited_dimensions is None:
2237-
if iris.FUTURE.netcdf_no_unlimited:
22382211
unlimited_dimensions = []
2239-
else:
2240-
_no_unlim_dep_warning()
22412212

22422213
if isinstance(cube, iris.cube.Cube):
22432214
cubes = iris.cube.CubeList()
@@ -2347,12 +2318,3 @@ def is_valid_packspec(p):
23472318

23482319
# Add conventions attribute.
23492320
sman.update_global_attributes(Conventions=conventions)
2350-
2351-
2352-
def _no_unlim_dep_warning():
2353-
msg = ('NetCDF default saving behaviour currently assigns the '
2354-
'outermost dimensions to unlimited. This behaviour is to be '
2355-
'deprecated, in favour of no automatic assignment. To switch '
2356-
'to the new behaviour, set iris.FUTURE.netcdf_no_unlimited to '
2357-
'True.')
2358-
warn_deprecated(msg)

0 commit comments

Comments
 (0)