Skip to content

Error reading NetCDF file dimensions with units degrees #4460

@PAGWatson

Description

@PAGWatson

🐛 Bug Report

(Edited to show the error is associated with the coordinates having units 'degrees' rather than no units.)
I can create a NetCDF file of a field with 'longitude' and 'latitude' coordinates with units 'degrees' using the netCDF4 module version 1.5.8. Its metadata appears correct according to ncdump and the data it contains looks correct according to ncview. When I read the file using iris 3.1.0, however, it assigns the name 'grid_latitude' to both coordinates.

How To Reproduce

Steps to reproduce the behaviour:

Creating the file, reading it in with iris and printing the cube:

import numpy as np
import iris
import netCDF4

lat_vals=np.arange(-90,90)
lon_vals=np.arange(360)
data_out=np.random.normal(0,1,(len(lat_vals),len(lon_vals)))

fname='test.nc'
f = netCDF4.Dataset(fname, 'w')
lat_dim=f.createDimension('latitude', len(lat_vals))
lats=f.createVariable('latitude', 'f4', ('latitude',))
lats[:]=lat_vals
lon_dim=f.createDimension('longitude', len(lon_vals))
lons=f.createVariable('longitude', 'f4', ('longitude',))
lons[:]=lon_vals
data=f.createVariable('data', 'f4', ('latitude','longitude'))
data[:]=data_out

#Commenting these next two lines makes iris read the file correctly
lats.units='degrees'
lons.units='degrees'

f.close()

cube=iris.load_cube(fname)
print(cube)

This gives the result

data / (unknown)                    (grid_latitude: 180; grid_latitude: 360)
    Dimension coordinates:
        grid_latitude                             x                   -
        grid_latitude                             -                   x

Expected behaviour

That iris would name the coordinates "latitude" and "longitude".

Environment

  • OS & Version: CentOS Linux 7
  • Iris Version: 3.1.0

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions