Loading a cube changes the coordinates var_name

Open
#6,956 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
data

Research direction

Start with the reproduction using iris.save and iris.load_cube, then trace how the DimCoord var_name is serialized and restored. Add a regression test covering a coordinate with only a standard_name, and verify that the loaded coordinate retains an unset var_name and matches the original cube.

Written by the indexing model from the issue text.

Description

Release: Major Type: Bug

🐛 Bug Report

Not sure if this is a bug or intentional, or if this has been raised before (I couldn't find a related issue in my search). So my issue is that if you create a cube with a iris.coord.DimCoord (setting only the standard_name of the coordinate) and save it. If you then load the cube, the var_name of the coordinate is then set, meaning that the saved cube no longer matches the loaded one.

How To Reproduce

Here is a small script to reproduce the issue.

from iris.cube import Cube
from iris.coords import DimCoord
import iris

# First create a cube
cube = Cube([0])
cube.add_dim_coord(DimCoord([0],"latitude"), 0)

# Save it to disk
iris.save(cube, "test.nc")

# Load the cube
loaded_cube = iris.load_cube("test.nc")

# Check if the cubes 
print("cube==loaded_cube:",cube==loaded_cube)

# Check the coordinate metadata match
print("cube.coord('latitude')==loaded_cube.coord('latitude'):",cube.coord("latitude")==loaded_cube.coord("latitude"))

# Check the coordinate var_name
print("cube.coord('latitude').var_name==loaded_cube.coord('latitude').var_name:",cube.coord("latitude").var_name==loaded_cube.coord("latitude").var_name)

This outputs:

cube==loaded_cube: False
cube.coord('latitude')==loaded_cube.coord('latitude'): False
cube.coord('latitude').var_name==loaded_cube.coord('latitude').var_name: False

Expected behaviour

The cube coordinate var_name is not set for the loaded cube

Environment

  • OS & Version: RHEL 9.7
  • Iris Version: 3.14.1
Dominant language
Python
Stars
724
Forks
317
Avg merge
3d 20h
Merged PRs (30d)
9

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from SciTools/iris

All issues in SciTools/iris

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.