-
Notifications
You must be signed in to change notification settings - Fork 295
TypeError when merging masked scalar coord #3584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
In order to maintain a backlog of relevant issues, we automatically label them as stale after 500 days of inactivity. If this issue is still important to you, then please comment on this issue and the stale label will be removed. Otherwise this issue will be automatically closed in 28 days time. |
I just discovered a very similar problem: if the input cubes for merging have a scalar coordinate that uses a masked array, the scalar coordinate of the merged cube is not a masked array anymore. MWE: import numpy as np
import iris
import iris.coords
import iris.cube
# Setup cubes
scalar_coord = iris.coords.AuxCoord(np.ma.masked_array([0]), var_name='x')
merge_coord_1 = iris.coords.AuxCoord([1], var_name='merge_coord')
merge_coord_2 = iris.coords.AuxCoord([2], var_name='merge_coord')
cube_1 = iris.cube.Cube(1, var_name='cube',
aux_coords_and_dims=[(scalar_coord, ()), (merge_coord_1, ())])
cube_2 = iris.cube.Cube(2, var_name='cube',
aux_coords_and_dims=[(scalar_coord, ()), (merge_coord_2, ())])
# Create merged cube
cubes = iris.cube.CubeList([cube_1, cube_2])
merged_cube = cubes.merge_cube()
# Print scalar coordinates
print("Scalar coordinate of input cubes:")
print(cube_1.coord('x'))
print(cube_2.coord('x'))
print("")
print("Scalar coordinate of merged cube:")
print(merged_cube.coord('x')) gives
As you can see, the scalar coordinate of the merged cube is not a |
In order to maintain a backlog of relevant issues, we automatically label them as stale after 500 days of inactivity. If this issue is still important to you, then please comment on this issue and the stale label will be removed. Otherwise this issue will be automatically closed in 28 days time. |
Still relevant |
In order to maintain a backlog of relevant issues, we automatically label them as stale after 500 days of inactivity. If this issue is still important to you, then please comment on this issue and the stale label will be removed. Otherwise this issue will be automatically closed in 28 days time. |
Still relevant |
Hi @schlunma I've looked into this and it's a slightly tricky edge-case. When aux coords are built from their coordinate data, Iris first attempts to construct them as a Lines 1611 to 1631 in 16c6a33
Your The problem is that masked data is NOT ALLOWED in a Lines 2808 to 2809 in 16c6a33
This is what is happening here and why your mask is lost. The fix I am working on for the original problem mentioned in this issue will mitigate this slightly (although not fully) by allowing you to create |
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 inTypeError: 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.
The text was updated successfully, but these errors were encountered: