Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load performance improvement (ignoring UGRID) #6088

Merged
merged 11 commits into from
Jul 29, 2024
24 changes: 24 additions & 0 deletions lib/iris/fileformats/cf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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.items():
stephenworsley marked this conversation as resolved.
Show resolved Hide resolved
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."""
Expand Down
2 changes: 2 additions & 0 deletions lib/iris/fileformats/netcdf/ugrid_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ 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?
if not cf_reader._with_ugrid:
return {}
bjlittle marked this conversation as resolved.
Show resolved Hide resolved
mesh_vars = cf_reader.cf_group.meshes
meshes = {
name: _build_mesh(cf_reader, var, cf_reader.filename)
Expand Down
Loading