Skip to content

Fix longitude coord in cmorizers utilities.py #3911

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

flicj191
Copy link
Contributor

@flicj191 flicj191 commented Feb 12, 2025

Description


Before you get started

Checklist

It is the responsibility of the author to make sure the pull request is ready to review. The icons indicate whether the item will be subject to the 🛠 Technical or 🧪 Scientific review.

New or updated data reformatting script


To help with the number of pull requests:

@flicj191 flicj191 changed the title Reference to longitude coord in cmor utils Fix longitude coord in cmorizers utilities.py Feb 12, 2025
@flicj191 flicj191 marked this pull request as ready for review February 12, 2025 23:12
@flicj191 flicj191 requested a review from a team as a code owner February 12, 2025 23:12
@flicj191 flicj191 requested review from a team and removed request for a team February 12, 2025 23:14
@@ -221,7 +221,7 @@ def fix_coords(cube,
if cube_coord.ndim == 1:
cube = cube.intersection(longitude=(0.0, 360.0))
if overwrite_lon_bounds or not cube_coord.has_bounds():
fix_bounds(cube, cube_coord)
fix_bounds(cube, cube.coord('longitude'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for tackling this @flicj191 - we have to be careful here what of the two conditionals is stopping the call to fix_bounds: either overwrite_lat_bounds is False or cube.coord('latitude').has_bounds() is True - in which case no fixing is needed, though overwrite_lat_bounds is a bit of a loose constraint, maybe they do need fixing, and that was set to False by mistake?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks V!
hmm, no, overwrite_lat_bounds would be True, I was calling fix_coords() with the defaults. the output didn't have longitude bounds and the initial cube didn't have bounds either. The fix_coords() call when I used it to help CMORize fixed the depth, time and latitude coordinates but not the longitude.
I'll do a few more checks but I think it just got lost when getting parsed through fix_bounds()
ie. latitude is done like line 229:

if overwrite_lat_bounds or not cube.coord('latitude').has_bounds():
   fix_bounds(cube, cube.coord('latitude'))

whereas longitude here :

if overwrite_lon_bounds or not cube_coord.has_bounds():
    fix_bounds(cube, cube_coord)

I'll have another look and see

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just be sure that cube_coord is indeed the "longitude" one - you never know with those raw datasets, maybe it's called "ducks" 🦆 (am not even joking, the amount of weird stuff I've seen in raw outputs, ducks may be even CMOR-like 😁 )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep so i'm proposing to replace cube_coord with cube.coord('longitude')
I haven't had a chance to test it all, will soon

@schlunma
Copy link
Contributor

I am a little bit confused as to why this fix is necessary. Shouldn't cube_coord and cube.coord("longitude") be the same since the coordinate names are updated before running this code? If they are in fact different, are there two different longitude coordinates? To me this would indicate another problem with the data.

I also noticed that the metadata that is set during fix_dim_coordnames is different to the one expected by CMIP6, but this is probably something for another PR...

@flicj191 flicj191 marked this pull request as draft February 24, 2025 04:06
@flicj191
Copy link
Contributor Author

flicj191 commented Feb 24, 2025

Thanks, yes they should be the same, I was just finding that fix_coords did the other coords and not longitude on my dataset, could be strange behaviour so might not need this fix.
I'll check the fix_dim_coordnames if that needs to be fixed

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

Successfully merging this pull request may close these issues.

fix_coords is not fixing the bounds of the longitude coordinate
3 participants