Skip to content
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
91b6f18
Basic LOAD_PROBLEMS object.
trexfeathers Feb 21, 2025
bfc6abc
Minimum docstring for LOAD_PROBLEMS.
trexfeathers Feb 24, 2025
65c56a9
Working handling of names and dimension coords.
trexfeathers Feb 26, 2025
0397942
Warn user of load problems.
trexfeathers Feb 26, 2025
eb2f489
Docstring and UX improvements.
trexfeathers Feb 26, 2025
106dbf6
Merge remote-tracking branch 'upstream/main' into tolerance_1
trexfeathers Feb 26, 2025
abe3e4a
What's New entry.
trexfeathers Feb 26, 2025
9a3673f
Fix doctests.
trexfeathers Feb 27, 2025
d972e5a
Fix tests.
trexfeathers Feb 28, 2025
9c9fc31
Fix doctests for 3.13.
trexfeathers Feb 28, 2025
1e2e605
New tests for actions.
trexfeathers Feb 28, 2025
31190b9
Updated load problems tests for names.
trexfeathers Mar 3, 2025
3acdd8e
Licence header.
trexfeathers Mar 3, 2025
c7ea621
Tidy up code modifications.
trexfeathers Mar 3, 2025
6a15ca1
Convenience - get_latest_load_problem.
trexfeathers Mar 3, 2025
224ff03
Tests for _add_or_capture.
trexfeathers Mar 6, 2025
8308a50
Test for build_raw_cube.
trexfeathers Mar 6, 2025
bbb5b08
Make more methods private.
trexfeathers Mar 6, 2025
db99cfb
Fix doctest.
trexfeathers Mar 6, 2025
02fc923
Factor out add_method.
trexfeathers Mar 7, 2025
dae7220
Remove stack_trace TODO.
trexfeathers Mar 7, 2025
4cc2197
Correct docstring of _add_or_capture.
trexfeathers Mar 7, 2025
fc2da93
Extra comments.
trexfeathers Mar 7, 2025
bc98b2f
Refactor to create the LoadProblems class.
trexfeathers Mar 10, 2025
5a7f68c
Merge remote-tracking branch 'upstream/main' into tolerance_1
trexfeathers Mar 10, 2025
995b872
Fix doctest.
trexfeathers Mar 10, 2025
09bd216
What's New improvements.
trexfeathers Mar 10, 2025
ba3420c
Merge remote-tracking branch 'upstream/main' into tolerance_1
trexfeathers Mar 10, 2025
7e6c958
Encase coordinate name in quotes.
trexfeathers Mar 10, 2025
93045b3
More robust LoadProblems testing.
trexfeathers Mar 10, 2025
50a7a7d
Remove TODO tags following review discussion.
trexfeathers Mar 10, 2025
241a782
Propose mail-archive for addition to linkcheck_ignore.
trexfeathers Mar 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion docs/src/whatsnew/latest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ This document explains the changes made to Iris for this release
render text in the bottom right of the plot figure.
(:issue:`6247`, :pull:`6332`)

#. `@trexfeathers`_ added the :class:`iris.loading.LOAD_PROBLEMS` dictionary to
capture objects that could not be loaded correctly, increasing transparency
and helping users to fix loading problems via the Iris API. As a first pass,
this is currently limited to ``standard_name`` and dimension coordinates from
NetCDF files. (:issue:`6317`, :pull:`6338`)


🐛 Bugs Fixed
=============
Expand Down Expand Up @@ -166,7 +172,7 @@ This document explains the changes made to Iris for this release
necessary. (:issue:`6285`, :pull:`6288`)

#. `@trexfeathers`_ improved the handling of benchmark environments, especially
when working across Python versions. (:pull:`6329`)
when working across Python versions. (:pull:`6329`)

#. `@trexfeathers`_ temporarily pinned Sphinx to `<8.2`.
(:pull:`6344`, :issue:`6345`)
Expand Down
10 changes: 9 additions & 1 deletion lib/iris/common/mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ class LimitedAttributeDict(dict):

"""

#: Attributes with special CF meaning, forbidden in Iris attribute dictionaries.
CF_ATTRS_FORBIDDEN = (
"standard_name",
"long_name",
Expand All @@ -94,6 +93,15 @@ class LimitedAttributeDict(dict):
"scale_factor",
"_FillValue",
)
"""Attributes with special CF meaning, forbidden in Iris attribute dictionaries."""

IRIS_RAW = "IRIS_RAW"
"""Key used by Iris to store ALL attributes when problems are encountered during loading.

See Also
--------
iris.loading.LOAD_PROBLEMS: The destination for captured loading problems.
"""

def __init__(self, *args, **kwargs):
dict.__init__(self, *args, **kwargs)
Expand Down
27 changes: 26 additions & 1 deletion lib/iris/fileformats/_nc_load_rules/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from iris.config import get_logger
import iris.fileformats.cf
import iris.fileformats.pp as pp
from iris.loading import LOAD_PROBLEMS
import iris.warnings

from . import helpers as hh
Expand Down Expand Up @@ -104,6 +105,10 @@ def inner(engine, *args, **kwargs):
@action_function
def action_default(engine):
"""Perform standard operations for every cube."""
# Future pattern (iris#6319).
hh.build_and_add_names(engine)

# Legacy pattern.
hh.build_cube_metadata(engine)


Expand Down Expand Up @@ -286,6 +291,7 @@ def action_build_dimension_coordinate(engine, providescoord_fact):
cf_var = engine.cf_var.cf_group[var_name]
rule_name = f"fc_build_coordinate_({coord_type})"
coord_grid_class, coord_name = _COORDTYPE_GRIDTYPES_AND_COORDNAMES[coord_type]
succeed = None
if coord_grid_class is None:
# Coordinates not identified with a specific grid-type class (latlon,
# rotated or projected) are always built, but can have no coord-system.
Expand Down Expand Up @@ -367,9 +373,28 @@ def action_build_dimension_coordinate(engine, providescoord_fact):
assert coord_grid_class in grid_classes

if succeed:
hh.build_dimension_coordinate(
hh.build_and_add_dimension_coordinate(
engine, cf_var, coord_name=coord_name, coord_system=coord_system
)

else:
message = f"Dimension coordinate {var_name} not created. Debug info:\n"
if succeed is None:
message += "An unexpected error occurred"
error = NotImplementedError(message)
else:
message += rule_name
error = ValueError(message)

try:
raise error
except error.__class__ as error:
_ = LOAD_PROBLEMS.record(
filename=engine.filename,
loaded=hh.build_raw_cube(cf_var, engine.filename),
exception=error,
)

return rule_name


Expand Down
9 changes: 9 additions & 0 deletions lib/iris/fileformats/_nc_load_rules/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

"""

from iris.coords import _DimensionalMetadata
from iris.cube import Cube
from iris.fileformats.cf import CFDataVariable

from .actions import run_actions


Expand Down Expand Up @@ -74,6 +78,11 @@ class Engine:

"""

cf_var: CFDataVariable | None
cube: Cube | None
cube_parts: dict[str, list[tuple[_DimensionalMetadata, str]]] | None
filename: str | None

def __init__(self):
"""Init new engine."""
self.reset()
Expand Down
Loading
Loading