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

Fix subtle naming differences between DummyCube & iris cubes #117

Open
truth-quark opened this issue Oct 1, 2024 · 0 comments
Open

Fix subtle naming differences between DummyCube & iris cubes #117

truth-quark opened this issue Oct 1, 2024 · 0 comments

Comments

@truth-quark
Copy link
Collaborator

truth-quark commented Oct 1, 2024

There seen to be some subtle differences between iris cubes and our DummyCube which would cause the test_fix_level_coord_... tests to fail if we were using real iris cubes.

The cube.coord() method uses the current name for a DimCoord as its argument, where the "current name" comes from either the DimCoord's standard_name, long_name, or var_name, with the following order of priority: standard_name > long_name > var_name.

This means that if a DimCoord only has a var_name attribute, changing the var_name forces us to also change the argument in cube.coord(...) used to access it:

A made up example after modifying a loaded cube's coordinate names:

>>> cube.coord("pseudo_level").__dict__
{'_metadata_manager': MetadataManager(standard_name=None, long_name=None, var_name='pseudo_level', units=Unit('1'), attributes={}, coord_system=None, climatological=False, circular=False), '_values_dm': DataManager(array([1, 2, 3, 4, 5, 6])), '_bounds_dm': None, '_ignore_axis': False}

>>> cube.coord("pseudo_level").var_name = "new_var_name"

>>> cube.coord("pseudo_level")

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/g/data/vk83/apps/payu/1.1.5/lib/python3.10/site-packages/iris/cube.py", line 2304, in coord
    raise iris.exceptions.CoordinateNotFoundError(emsg)
iris.exceptions.CoordinateNotFoundError: "Expected to find exactly 1 'pseudo_level' coordinate, but found none."

>>> cube.coord("new_var_name")
<DimCoord: new_var_name / (1)  [1, 2, ..., 5, 6]  shape(6,)>

In these tests however, we're changing the coordinate's var_names but not the cube.coord(...) arguments used to access them.

Given that the tests are working and it's a fairly subtly difference, should we defer this to a separate issue?

Originally posted by @blimlim in #113 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant