-
Notifications
You must be signed in to change notification settings - Fork 301
Closed
Description
The handling of scalar coordinates in _merge.py includes the build_indexes step. This cannot handle the scalar point being a masked value since it attempts to look the value up in the dictionary name_index_by_scalar, resulting in TypeError: unhashable type: 'MaskedConstant'.
This was discovered when attempting to load a NetCDF file that had previously been converted from NIMROD to NetCDF format. NetCDF had recognized a fill value for a scalar coordinate and therefore saved it as masked. load_cube includes a merge step, resulting in the error. This is demonstrated in the code below.
The presence of a masked point for a scalar coordinate is a possible scenario and should therefore be handled rather than producing an error.
import numpy as np
import iris
from iris import coords
my_cube = iris.cube.Cube(data=[1, 2])
# Generate a single-point array with a value NetCDF will recognise as a fill
# value and convert to a mask.
# Use the array as a scalar coordinate on my_cube.
my_array = np.array([-32767], dtype=np.int16)
my_scalar_coord = coords.DimCoord(points=my_array, standard_name="realization")
my_cube.add_aux_coord(my_scalar_coord)
# Save my_cube in NetCDF format.
iris.save(my_cube, "masked_scalar.nc")
# Attempt to load back the saved file. Results in the TypeError.
iris.load_cube("masked_scalar.nc")Reactions are currently unavailable