Skip to content

Fix bug when calculating UGRID cell areas when non-spatial coordinates span the discrete axis #721

@davidhassell

Description

@davidhassell

When calculating UGRID cell areas with non-spatial coordinates span that span the discrete axis, an IndexError sometimes occurs:

IndexError: Invalid indices [0, 0, 0] for array with shape (13824, 4)

>>> print (f)
Field: air_pressure_at_mean_sea_level (ncvar%pmsl)
--------------------------------------------------
Data            : air_pressure_at_mean_sea_level(time(2), ncdim%ensemble(3), ncdim%nMesh2d_face(13824)) Pa
Cell methods    : time: mean (interval: 6 h)
Dimension coords: ncvar%ensemble(ncdim%ensemble(3)) = [0.0, 1.0, 2.0]
Auxiliary coords: longitude(ncdim%nMesh2d_face(13824)) = [70.3125, ..., 112.86804962158203] degrees_east
                : latitude(ncdim%nMesh2d_face(13824)) = [0.8827333450317383, ..., -47.359893798828125] degrees_north
                : time(time(2)) = [1978-09-01 12:00:00, 1978-09-02 12:00:00] 360_day
Topologies      : cell:face(ncdim%nMesh2d_face(13824), 4) = [[0, ..., 13755]]
>>> f.cell_area(great_circle=True)
Traceback
    ...
IndexError: Invalid indices [0, 0, 0] for array with shape (13824, 4)

Whether or not this happens depends on the arbitrary of the auxiliary coordinates stored inside the field (specifically within the embedded Constructs instance).

>>> cf.environment(paths=False)
Platform: Linux-5.15.0-94-generic-x86_64-with-glibc2.35
HDF5 library: 1.14.2
netcdf library: 4.9.2
udunits2 library: /home/david/miniconda3/lib/libudunits2.so.0
esmpy/ESMF: 8.4.2
Python: 3.11.4
dask: 2023.12.1
netCDF4: 1.6.4
psutil: 5.9.5
packaging: 23.0
numpy: 1.25.2
scipy: 1.11.3
matplotlib: 3.8.0
cftime: 1.6.2
cfunits: 3.3.6
cfplot: 3.3.0
cfdm: 1.11.0.0
cf: 3.16.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    UGRIDRelating to UGRID mesh topologiesbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions