Skip to content

Maths operations on cubes with unstructured grid cause a TypeError in resolve() #4454

@dennissergeev

Description

@dennissergeev

🐛 Bug Report

I am using the dev version of iris to work with unstructured grids (LFRic output). The issue I am having is that all maths operations seem to be broken: a TypeError is raised when the maths operation calls resolver.cube(), which in turn invokes the container() method on an auxiliary coordinate with an unexpected keyword bounds (see the full message below). This happens even if the RHS and LHS cubes are the same cube, but it doesn't happen if operations are unary, such as raising the cube to the power.

How To Reproduce

Steps to reproduce the behaviour:

import os

import iris
from iris.experimental.ugrid import PARSE_UGRID_ON_LOAD

test_data_dir = iris.config.TEST_DATA_DIR
src_fn = os.path.join(
    test_data_dir, "NetCDF", "unstructured_grid", "lfric_ngvat_3D_1t_half_level_face_grid_derived_theta_in_w3.nc"
)
with PARSE_UGRID_ON_LOAD.context():
    theta = iris.load_cube(src_fn, "air_potential_temperature")

foo = theta + theta
This results in "TypeError: __init__() got an unexpected keyword argument 'bounds'"
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/tmp/ipykernel_33999/786035974.py in <module>
----> 1 theta + theta

~/mambaforge/envs/ideal_exo/lib/python3.8/site-packages/iris/common/lenient.py in lenient_client_inner(*args, **kwargs)
    122                 """
    123                 with _LENIENT.context(*services, active=_qualname(func)):
--> 124                     result = func(*args, **kwargs)
    125                 return result
    126 

~/mambaforge/envs/ideal_exo/lib/python3.8/site-packages/iris/analysis/maths.py in add(cube, other, dim, in_place)
    231     else:
    232         op = operator.add
--> 233     return _add_subtract_common(
    234         op, "add", cube, other, new_dtype, dim=dim, in_place=in_place
    235     )

~/mambaforge/envs/ideal_exo/lib/python3.8/site-packages/iris/analysis/maths.py in _add_subtract_common(operation_function, operation_name, cube, other, new_dtype, dim, in_place)
    322         raise iris.exceptions.NotYetImplementedError(emsg)
    323 
--> 324     result = _binary_op_common(
    325         operation_function,
    326         operation_name,

~/mambaforge/envs/ideal_exo/lib/python3.8/site-packages/iris/analysis/maths.py in _binary_op_common(operation_function, operation_name, cube, other, new_unit, new_dtype, dim, in_place)
    824         # Insert the resultant data from the maths operation
    825         # within the resolved cube.
--> 826         result = resolver.cube(result.core_data(), in_place=in_place)
    827         _sanitise_metadata(result, new_unit)
    828 

~/mambaforge/envs/ideal_exo/lib/python3.8/site-packages/iris/common/resolve.py in cube(self, data, in_place)
   2344         )
   2345         for item in prepared_aux_coords:
-> 2346             coord = item.container(item.points, bounds=item.bounds)
   2347             coord.metadata = item.metadata.combined
   2348             try:

TypeError: __init__() got an unexpected keyword argument 'bounds'

Expected behaviour

The expected behaviour is obviously that the maths works :)

Environment

  • OS & Version: Ubuntu 20.04 LTS
  • Iris Version: 3.2.dev0

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions