diff --git a/docs/src/whatsnew/latest.rst b/docs/src/whatsnew/latest.rst index bbef181057..8b7fbf5864 100644 --- a/docs/src/whatsnew/latest.rst +++ b/docs/src/whatsnew/latest.rst @@ -98,6 +98,10 @@ This document explains the changes made to Iris for this release subclasses of a common generic :class:`~iris.mesh.components.Mesh` class. (:issue:`6057`, :pull:`6061`, :pull:`6077`) +#. `@pp-mo`_ and `@stephenworsley`_ Turned on UGRID loading by default, effectively removing + the need for and deprecating the :func:`~iris.ugrid.experimental.PARSE_UGRID_ON_LOAD` + context manager. (:pull:`6054`, :pull:`6088`) + 🚀 Performance Enhancements =========================== diff --git a/lib/iris/fileformats/cf.py b/lib/iris/fileformats/cf.py index 556642003a..024bcb6f1d 100644 --- a/lib/iris/fileformats/cf.py +++ b/lib/iris/fileformats/cf.py @@ -1331,6 +1331,11 @@ def __init__(self, file_source, warn=False, monotonic=False): self._check_monotonic = monotonic + self._with_ugrid = True + if not self._has_meshes(): + self._trim_ugrid_variable_types() + self._with_ugrid = False + self._translate() self._build_cf_groups() self._reset() @@ -1348,6 +1353,25 @@ def __exit__(self, exc_type, exc_value, traceback): # When used as a context-manager, **always** close the file on exit. self._close() + def _has_meshes(self): + result = False + for variable in self._dataset.variables.values(): + if hasattr(variable, "mesh") or hasattr(variable, "node_coordinates"): + result = True + break + return result + + def _trim_ugrid_variable_types(self): + self._variable_types = ( + CFAncillaryDataVariable, + CFAuxiliaryCoordinateVariable, + CFBoundaryVariable, + CFClimatologyVariable, + CFGridMappingVariable, + CFLabelVariable, + CFMeasureVariable, + ) + @property def filename(self): """The file that the CFReader is reading.""" diff --git a/lib/iris/fileformats/netcdf/ugrid_load.py b/lib/iris/fileformats/netcdf/ugrid_load.py index 210e112629..0a70567f16 100644 --- a/lib/iris/fileformats/netcdf/ugrid_load.py +++ b/lib/iris/fileformats/netcdf/ugrid_load.py @@ -56,11 +56,13 @@ def _meshes_from_cf(cf_reader): # Mesh instances are shared between file phenomena. # TODO: more sophisticated Mesh sharing between files. # TODO: access external Mesh cache? - mesh_vars = cf_reader.cf_group.meshes - meshes = { - name: _build_mesh(cf_reader, var, cf_reader.filename) - for name, var in mesh_vars.items() - } + meshes = {} + if cf_reader._with_ugrid: + mesh_vars = cf_reader.cf_group.meshes + meshes = { + name: _build_mesh(cf_reader, var, cf_reader.filename) + for name, var in mesh_vars.items() + } return meshes