You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# get cube's coordinate system
cs = cube.coord_system()
# get coord names
# Longitude
xcoord = cube.coord(axis="X", dim_coords=True)
# Latitude
ycoord = cube.coord(axis="Y", dim_coords=True)
# read in the grid lat/lon points from the cube
glat = cube.coord(ycoord).points
glon = cube.coord(xcoord).points
# create a rectangular grid out of an array of
# glon and glat values, shape will be len(glat)xlen(glon)
x, y = np.meshgrid(glon, glat)
# get the cube dimensions which corresponds to glon and glat
x_dim = cube.coord_dims(xcoord)[0]
y_dim = cube.coord_dims(ycoord)[0]
# define two new variables to hold the unrotated coordinates
rlongitude, rlatitude = iris.analysis.cartography.unrotate_pole(
x, y, cs.grid_north_pole_longitude, cs.grid_north_pole_latitude
)
# create two new auxillary coordinates to hold
# the values of the unrotated coordinates
reg_long = iris.coords.AuxCoord(rlongitude, long_name="longitude", units="degrees")
reg_lat = iris.coords.AuxCoord(rlatitude, long_name="latitude", units="degrees")
# add two auxilary coordinates to the cube holding
# regular(unrotated) lat/lon values
cube.add_aux_coord(reg_long, [y_dim, x_dim])
cube.add_aux_coord(reg_lat, [y_dim, x_dim])
print the cube:
air_temperature / (K) (grid_latitude: 550; grid_longitude: 700)
Dimension coordinates:
grid_latitude x -
grid_longitude - x
Auxiliary coordinates:
latitude x x
longitude x x
4. try and get area weights:
weights =iris.analysis.cartography.area_weights(cube)
Traceback (most recent call last):
File "area_bug.py", line 49, in
weights =iris.analysis.cartography.area_weights(cube)
File ".../lib/python3.6/site-packages/iris/analysis/cartography.py", line 399, in area_weights
lon, lat = _get_lon_lat_coords(cube)
File ".../python3.6/site-packages/iris/analysis/cartography.py", line 189, in _get_lon_lat_coords
"Calling _get_lon_lat_coords with multiple lat or lon coords"
ValueError: Calling _get_lon_lat_coords with multiple lat or lon coords is currently disallowed
5. remove the extra coords - works fine:
cube.remove_coord('longitude')
cube.remove_coord('latitude')
weights =iris.analysis.cartography.area_weights(cube)
Expected behaviour
I expect that a cube like this should return the correct area weights
Environment
RHEL 7.9
Iris Version: 2.2.0
Additional context
Click to expand this section...
https://github.com/SciTools/iris/blob/master/lib/iris/analys...
I would suggest that this:
coord for coord in cube.coords() if "latitude" in coord.name()
should actually be:
coord for coord in cube.coords(dim_coords=True) if "latitude" in coord.name()
Don't want to overcomplicate, but this reminds me of : #3169
In an ideal world... instead of returning an array of values, the calculation could add a cell-measure to the cube, and the stats methods could use that automatically. So, I wish we could do that.
Hi @nhsavage, just checking through some older issues and wonder to what degree this is still relevant to you? @alastair-gemmell - we do have work arounds for this and it's generally not an issue. It is a common with roated pole data to add these auxilliary coordinates as it makes it easier to work with for many users. On balance - not that important but a "nice to have"
🐛 Bug Report
Iris is unable to calculate area weights for rotated pole grids if auxiliary coordinates with true latitude and longitude have been added to the cube.
How To Reproduce
Traceback (most recent call last):
File "area_bug.py", line 49, in
weights =iris.analysis.cartography.area_weights(cube)
File ".../lib/python3.6/site-packages/iris/analysis/cartography.py", line 399, in area_weights
lon, lat = _get_lon_lat_coords(cube)
File ".../python3.6/site-packages/iris/analysis/cartography.py", line 189, in _get_lon_lat_coords
"Calling
_get_lon_lat_coords
with multiple lat or lon coords"ValueError: Calling
_get_lon_lat_coords
with multiple lat or lon coords is currently disallowedExpected behaviour
I expect that a cube like this should return the correct area weights
Environment
Additional context
Click to expand this section...
See here for further details.
The text was updated successfully, but these errors were encountered: