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

Cube loses ancillary variables and cell_measures after (some) intersections #5413

Open
valeriupredoi opened this issue Aug 4, 2023 · 2 comments · May be fixed by #5804
Open

Cube loses ancillary variables and cell_measures after (some) intersections #5413

valeriupredoi opened this issue Aug 4, 2023 · 2 comments · May be fixed by #5804

Comments

@valeriupredoi
Copy link

valeriupredoi commented Aug 4, 2023

Hey folks,

Here's one sneaky one for you:

Main point

An iris cube that has ancillary variables and cell_measures, upon intersecting it with a region via cube.intersect may lose those ancillary variables and cell_measures depending on what the coordinates of the intersected region are.

Minimal fully reproducible code

import iris


cube = iris.load_cube("cube_to_intersect_smol.nc")

def extract_region(cube, start_longitude, end_longitude, start_latitude,
                   end_latitude):
    print("Cube before intersection", cube)
    print("Ancil variables", cube.ancillary_variables())
    print("Cell measures", cube.cell_measures())
    region_subset = cube.intersection(
        longitude=(start_longitude, end_longitude),
        latitude=(start_latitude, end_latitude),
        ignore_bounds=True,
    )
    print("Cube after intersection", region_subset)


# intersection cube loses cell measures and ancillary variables
extract_region(cube,
               start_longitude=-90,
               end_longitude=40,
               start_latitude=20,
               end_latitude=80
    )

# intersection cube doesn't lose cell measures and ancillary variables
extract_region(cube,
               start_longitude=160,
               end_longitude=280,
               start_latitude=-5,
               end_latitude=5
    )

cube_to_intersect_smol.nc attached here (rename to .nc, size=1.2M, smol like I says)
cube_to_intersect_smol.nc.txt

Have I looked at docs?

Yes https://scitools-iris.readthedocs.io/en/latest/generated/api/iris.cube.html#iris.cube.Cube.intersection no mention of any side effects, coordinates are circular

Iris version and installation type

(esmvaltool) valeriu@valeriu-PORTEGE-Z30-C:~$ conda list iris
# packages in environment at /home/valeriu/miniconda3/envs/esmvaltool:
#
# Name                    Version                   Build  Channel
iris                      3.6.1              pyha770c72_0    conda-forge
iris-esmf-regrid          0.7.0              pyhd8ed1ab_0    conda-forge

AOBs

Related to #3483

Great many thanks in advance! Many thanks to @rebeccaherman1 for alerting me to this via ESMValGroup/ESMValCore#2162

Obligatory pint emoji

🍺

@rebeccaherman1
Copy link

@valeriupredoi in your post, the second region (reproduced below) retains the ancillary variables, right? I think you forgot to change a word in the code comment.

# intersection cube loses ancillary variables
extract_region(cube,
               start_longitude=160,
               end_longitude=280,
               start_latitude=-5,
               end_latitude=5
    )

Thanks for looking into it and submitting this issue!

@ESadek-MO ESadek-MO added this to the v3.8 milestone Aug 9, 2023
@valeriupredoi
Copy link
Author

well spotted @rebeccaherman1 - corrected now, cheers 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ⏸️ Paused
Status: paused
Status: No status
Development

Successfully merging a pull request may close this issue.

6 participants