From f7c4c2dbca497a132116c5e8b3d537960f5adeae Mon Sep 17 00:00:00 2001 From: Patrick Peglar Date: Tue, 2 Apr 2024 17:48:54 +0100 Subject: [PATCH 1/3] Support what chunking() returns for NetCDF v3 files. --- lib/iris/fileformats/netcdf/loader.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/iris/fileformats/netcdf/loader.py b/lib/iris/fileformats/netcdf/loader.py index 8a48fddb37..16fe567c9b 100644 --- a/lib/iris/fileformats/netcdf/loader.py +++ b/lib/iris/fileformats/netcdf/loader.py @@ -243,6 +243,9 @@ def _get_cf_var_data(cf_var, filename): result = as_lazy_data(proxy, chunks=None, dask_chunking=True) else: chunks = cf_var.cf_data.chunking() + if chunks is None: + # Occurs for non-version-4 netcdf + chunks = "contiguous" # In the "contiguous" case, pass chunks=None to 'as_lazy_data'. if chunks == "contiguous": if ( From 0daf4a7f23a425f08600710ddf05ab3ff473bf8d Mon Sep 17 00:00:00 2001 From: Patrick Peglar Date: Tue, 2 Apr 2024 18:25:51 +0100 Subject: [PATCH 2/3] Add a test. --- .../fileformats/netcdf/loader/test__chunk_control.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/iris/tests/unit/fileformats/netcdf/loader/test__chunk_control.py b/lib/iris/tests/unit/fileformats/netcdf/loader/test__chunk_control.py index bb6bfd4dcc..d4c813502f 100644 --- a/lib/iris/tests/unit/fileformats/netcdf/loader/test__chunk_control.py +++ b/lib/iris/tests/unit/fileformats/netcdf/loader/test__chunk_control.py @@ -76,6 +76,15 @@ def test_default(tmp_filepath, save_cubelist_with_sigma): assert sigma.lazy_bounds().chunksize == (4, 2) +def test_netcdf_v3(): + # Just check that it does not fail when loading NetCDF v3 data + path = iris.tests.get_data_path( + ["NetCDF", "global", "xyt", "SMALL_total_column_co2.nc.k2"] + ) + with CHUNK_CONTROL.set(time=-1): + iris.load(path) + + def test_control_global(tmp_filepath, save_cubelist_with_sigma): cube_varname, _ = save_cubelist_with_sigma with CHUNK_CONTROL.set(model_level_number=2): From 154fc9124cd99bb09d267d43b447e7918fcb1f4b Mon Sep 17 00:00:00 2001 From: Patrick Peglar Date: Tue, 2 Apr 2024 18:26:07 +0100 Subject: [PATCH 3/3] Add a whatsnew. --- docs/src/whatsnew/latest.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/src/whatsnew/latest.rst b/docs/src/whatsnew/latest.rst index 0cbb1e73c4..dee8ee44f0 100644 --- a/docs/src/whatsnew/latest.rst +++ b/docs/src/whatsnew/latest.rst @@ -44,7 +44,8 @@ This document explains the changes made to Iris for this release 🐛 Bugs Fixed ============= -#. N/A +#. `@pp-mo`_ prevented the CHUNK_CONTROL feature from hitting an error when loading + from a NetCDF v3 file. (:pull:`5897`) 💣 Incompatible Changes