Skip to content

Reading UM/PP files fails when LBNPT or LBROW is zero  #621

@davidhassell

Description

@davidhassell

When UM/PP either of the lookup header entries LBNPT or LBROW are zero, a failure occurs when trying to create the coordinates:

>>> import cf
>>> f = cf.read('cm655_cn134_19531029-W_uk-11a.da19531026_00')
<snip>
 File ~/miniconda3/lib/python3.10/site-packages/cf/read_write/um/umread.py:3031, in UMField.xy_coordinate(self, axiscode, axis)
   3028 dc = self.coord_names(dc, axiscode)
   3030 if X and bounds is not None:
-> 3031     autocyclic["cyclic"] = abs(bounds[0, 0] - bounds[-1, -1]) == 360.0
   3032     autocyclic["period"] = Data(360.0, units=units)
   3033     autocyclic["axis"] = axis_key

IndexError: index 0 is out of bounds for axis 0 with size 0

Such fields are runlength encoded, and cf-python can't unpack them because it doesn't know what the mask is.

A solution is to simply skip these fields.

>>> import cf
>>> cf.environment(paths=False)
Platform: Linux-5.15.0-67-generic-x86_64-with-glibc2.35
HDF5 library: 1.12.1
netcdf library: 4.8.1
udunits2 library: /home/david/miniconda3/lib/libudunits2.so.0
ESMF: 8.2.0
Python: 3.10.9
dask: 2023.3.0
netCDF4: 1.6.0
psutil: 5.9.4
packaging: 23.0
numpy: 1.22.3
scipy: 1.8.1
matplotlib: 3.4.3
cftime: 1.6.2
cfunits: 3.3.5
cfplot: 3.1.31
cfdm: 1.10.0.3
cf: 3.14.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingum/ppRelating to UM or PP format files

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions