-
Notifications
You must be signed in to change notification settings - Fork 38
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
Wrong error message for duplicate coordinate #373
Comments
but it's impossible to add the same coordinate twice in a cube - even if one is DimCoord and the other is AuxCoord, no? |
Apparently it's possible if the two coordinates are slightly different, e.g. if one has additional |
Pff, smells like an iris bug to me then
Dr Valeriu Predoi.
Computational scientist
NCAS-CMS
University of Reading
Department of Meteorology
Reading RG6 6BB
United Kingdom
…On Wed, 4 Dec 2019, 09:05 Manuel Schlund, ***@***.***> wrote:
Apparently it's possible if the two coordinates are slightly different,
e.g. if one has additional attributes and the other one doesn't, like
it's the case for the example posted above (one height coordinate has a
description, the other one doesn't).
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#373?email_source=notifications&email_token=AG5EFI23QH54OHL74P5E6F3QW5XGZA5CNFSM4JLTRLK2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEF4H3AA#issuecomment-561544576>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AG5EFI6H4CWJNQWJK3IYPGLQW5XGZANCNFSM4JLTRLKQ>
.
|
I don't think so. Why would they add an error message like this then?
|
so the error message takes care of the already created problem; the problem should not happen in the first place ie adding two |
Adding two |
yeah but what happens if the data is 3D and you remove say, time and add longitude in the place of time (so index 0), with the data now having longitude-longitude-latitude coords -> will that work? Coz if it does, it's bonkers 🍺 |
It works if the metadata of the Python 3.7.3 | packaged by conda-forge | (default, Jul 1 2019, 21:52:21)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import iris
>>> d1 = iris.coords.DimCoord([1, 2], standard_name='latitude')
>>> d2 = d1.copy()
>>> d3 = d1.copy([2, 4])
>>> d4 = iris.coords.DimCoord([1, 2], standard_name='latitude', var_name='lat')
>>> cube = iris.cube.Cube([[1, 2], [3, 4]])
>>> print(cube)
unknown / (unknown) (-- : 2; -- : 2)
>>> cube.add_dim_coord(d1, 0)
>>> cube.add_dim_coord(d1, 0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/mnt/lustre02/work/bd0854/b309141/miniconda3/envs/mlr/lib/python3.7/site-packages/iris/cube.py", line 1054, in add_dim_coord
raise ValueError('The coordinate already exists on the cube. '
ValueError: The coordinate already exists on the cube. Duplicate coordinates are not permitted.
>>> cube.add_dim_coord(d1, 1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/mnt/lustre02/work/bd0854/b309141/miniconda3/envs/mlr/lib/python3.7/site-packages/iris/cube.py", line 1054, in add_dim_coord
raise ValueError('The coordinate already exists on the cube. '
ValueError: The coordinate already exists on the cube. Duplicate coordinates are not permitted.
>>> cube.add_dim_coord(d2, 1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/mnt/lustre02/work/bd0854/b309141/miniconda3/envs/mlr/lib/python3.7/site-packages/iris/cube.py", line 1054, in add_dim_coord
raise ValueError('The coordinate already exists on the cube. '
ValueError: The coordinate already exists on the cube. Duplicate coordinates are not permitted.
>>> cube.add_dim_coord(d3, 1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/mnt/lustre02/work/bd0854/b309141/miniconda3/envs/mlr/lib/python3.7/site-packages/iris/cube.py", line 1054, in add_dim_coord
raise ValueError('The coordinate already exists on the cube. '
ValueError: The coordinate already exists on the cube. Duplicate coordinates are not permitted.
>>> cube.add_dim_coord(d4, 1)
>>> cube
<iris 'Cube' of unknown / (unknown) (latitude: 2; latitude: 2)>
>>> |
Bahahah, you got a Frankencube 🤣 I think we should probably tell the iris guys about this - ping @bjlittle |
An interesting question, and quite topical... see SciTools/iris#3583 which is part of an overhaul of This all comes down to the question of "What is the identity of a coordinate?". To be fair we need to communicate this more clearly, but essentially the answer comes down to the metadata of the coordinate, and in this case that is a combination of the coordinate:
The identify of a coordinate has nothing to do with the value of its In your example, only the Hope this helps to clarify. I want to make this a slicker (and configurable) experience for the user and SciTools/iris#3583 is the first step in that direction - plus we need to clearly communicate all of this in the user guide to avoid any on-going confusion. So IMHO this isn't a bug 😃 |
For info, I have previously queried the Frankencubes: SciTools/iris#2917 |
"Frankencubes" -- it's now officially a thing 🤣 I've been thinking about Frankencubes over the weekend, and given that I'm kinda actively working in this area of I stand by my last comment that this isn't a bug, but then again, the double Ideally, what you might want to happen here is for So, if you're happy, leave this issue open, and let's see if I can get the Frankencube to learn some table manners 😄 That said, your temporary workaround here might be something along the lines of: height = iris.coords.DimCoord(2.0, standard_name="height", units="m", attributes=dict(description="...")
coords = cube.coords(height.name())
if not coords:
# This isn't a Frankencube...
cube.add_aux_coord(height)
else:
# A "height-like" coordinate already exists in the cube...
if len(coords)>1:
raise ValueError("oops")
# Add the extra metadata (what ever it is) to the existing "height" coordinate on the cube...
coords[0].attributes.update(height.attributes) |
That sounds great @bjlittle, thanks for your help!! |
I should probably say that, since posting that issue, I've come across cases where two coords with the same name appears to be deliberate. Have emailed you @bjlittle . |
Cheers @bjlittle - can we add Frankencube to the iris documentation? 😁
Dr Valeriu Predoi.
Computational scientist
NCAS-CMS
University of Reading
Department of Meteorology
Reading RG6 6BB
United Kingdom
…On Mon, 9 Dec 2019, 10:30 Ruth Comer, ***@***.***> wrote:
I should probably say that, since posting that issue, I've come across
cases where two coords with the same name appears to be deliberate. Have
emailed you @bjlittle <https://github.com/bjlittle> .
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#373?email_source=notifications&email_token=AG5EFI5E4LYLACD6GZENJMLQXYM5LA5CNFSM4JLTRLK2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEGIUHPQ#issuecomment-563168190>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AG5EFIZIFAD2BSAIKIRHIWDQXYM5LANCNFSM4JLTRLKQ>
.
|
After investigating, this wasn't an issue, given the proposed approach that I wish to adopt here. All good. |
@schlunma have you had the chance to look for Frankencubes with |
Do you mean |
yes yes, I meant 2.3.0, sorry, I meant the 3rd iteration of 2 😁 |
No, but I don't think that it is expected to change, since @bjlittle talked about version |
@valeriupredoi and @schlunma The latest scoop is that we've just released We've also decided to push out The Apologies for the delay. I'm hoping that we can make HTH |
I found another issue regarding Frankencubes: The following file has two
This causes the tool to fail with The problematic part is here ESMValCore/esmvalcore/cmor/check.py Lines 268 to 273 in a0552bd
which runs into the |
@jvegasbsc or @sloosvel Could one of you have a look at this? |
Yes, I will do it |
The error message which appears in #371 is:
However, the coordinate
height
is not missing, but appears twice (because it was additionally added by the fix). This can be very confusing.The reason for this is that
iris
also raises anCoordinateNotFoundError
forcube.coord('coord_name')
if'coord_name'
appears more than once incube
:The text was updated successfully, but these errors were encountered: