MetOffice / MetOffice/ANTS

Cube builder cannot create custom vertical coordinate

Open Beginner friendly
#147 0 comments 0 reactions 0 assignees View on GitHub
🐜 bug
Dominant language
Python
Stars
7
Forks
10
Avg merge
1d 19h
Merged PRs (30d)
5

Description

# 🐜 Bug Report

When creating a cube with a vertical coordinate, the cube builder cannot handle anything other than 4 levels. This is hard-coded in [`ants.utils.cube.CubeBuilder.add_model_level_coordinate`](https://github.com/MetOffice/ANTS/blob/ebefe0e5b6ddfaf042c8919348874372ba9b99d0/lib/ants/utils/cube.py#L219).

By extension, [`ants.tests.stock.simple_4d_with_hybrid_height`](https://github.com/MetOffice/ANTS/blob/ebefe0e5b6ddfaf042c8919348874372ba9b99d0/lib/ants/tests/stock.py#L33) fails when a shape is passed that does not specify 4 vertical levels.

## How to reproduce
Step by step guide to reproduce the behaviour:
```python
# use default shape
>>> ants.tests.stock.simple_4d_with_hybrid_height()

# try to specify non-default vertical coord, with 5 levels
>>> ants.tests.stock.simple_4d_with_hybrid_height(shape=(3,5,5,6))
Traceback (most recent call last):
File "", line 1, in
File ".../ants/tests/stock.py", line 57, in simple_4d_with_hybrid_height
builder.add_model_level_coordinate(additional_attributes={"positive": "up"})
File ".../ants/utils/cube.py", line 238, in add_model_level_coordinate
self._cube.add_dim_coord(coord, 1)
File ".../iris/cube.py", line 1409, in add_dim_coord
self._add_unique_dim_coord(dim_coord, data_dim)
File ".../iris/cube.py", line 1437, in _add_unique_dim_coord
raise iris.exceptions.CannotAddError(
iris.exceptions.CannotAddError: Unequal lengths. Cube dimension 1 => 5; coord 'model_level_number' => 4.
```

## Environment
I am using the ANTS 3.1.0 environment.

## Version
This bug exists in ANTS 3.1.0 + head of main

## Additional Context

Contributor guide

Open the contributing guide

Research direction

Start in lib/ants/utils/cube.py at CubeBuilder.add_model_level_coordinate, then inspect lib/ants/tests/stock.py and the simple_4d_with_hybrid_height helper. Reproduce the failure with shape=(3,5,5,6), and run the relevant stock or cube tests. Done means custom vertical-level shapes can be built without an Iris length error while the default four-level case still works.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.