I need to generate a cube that has the horizontal grid of one cube and the vertical grid of another (to make a cube for pressure on rho levels from a temperature cube and a u wind cube). The documentation is lacking context and I can't find anything useful by googling. I image doing something like copying the temperature cube, fidding with the sigma and delta in the cube and then running factory.update on the cube, but I can't quite work out the syntax.
Asked
Active
Viewed 502 times
2 Answers
1
A HybridHeightFactory is attached to a cube, and produces an "altitude" coordinate on request.
It needs to be linked to a suitable surface-altitude coordinate to work
-- which means it's not so simple to move it to a cube with a different horizontal grid.
So I think "factory.update" is not a great route, it is simpler to just make + attach a new one.
The plan will go something like...
orog = hgrid_cube.coord('surface_altitude')
sigma = vgrid_cube.coord('sigma')
delta = vgrid_cube.coord('level_height')
factory = iris.aux_factory.HybridHeightFactory(delta=delta, sigma=sigma, orography=orog)
new_cube = ...
new_cube.add_aux_coord(orog, (2, 3)) # or whatever dimensions
new_cube.add_aux_coord(sigma, (0,)) # or whatever dimensions
new_cube.add_aux_coord(delta, (0,)) # or whatever dimensions
new_cube.add_aux_factory(factory)
Note: in making "new_cube" from the old data, you may need to remove the existing aux factory too.

pp-mo
- 468
- 2
- 8
-
That's really thanks. I did have a few issues like removing the old hybrid height factory. I will post my function below. – Nick Savage Jul 27 '17 at 12:24
0
def make_p_rho_cube(temp, u_wind):
'''
Given a temperature cube (on p level but theta levels)
and a u_wind cube (on rho levels but staggered)
create a cube for pressure on rho levels - on p points
but not non-staggered horizontal grid
'''
# make a pressure cube. Grid is a new one - horizontal grid
# is as temperature, but
# vertical grid is like u_wind. copy temperature cube then change
# name and units and vertical grid. NB need to set stash code as well
p_rho_cube = temp.copy()
p_rho_cube.rename('air_pressure')
p_rho_cube.units = 'Pa'
p_rho_cube.attributes['STASH'] = iris.fileformats.pp.STASH(1, 0, 407)
# now create and use a new hybrid height factory
# surface altitude on theta pts
surface_alt = temp.coord('surface_altitude')
# vertical grid from wind field
sigma = u_wind.coord('sigma')
delta = u_wind.coord('level_height')
# make a hybrid height factory with these variables
factory = iris.aux_factory.HybridHeightFactory(delta=delta, sigma=sigma,
orography=surface_alt)
# delete the old co-ordinates after saving their dimensions
surface_altitude_dim = p_rho_cube.coord_dims('surface_altitude')
p_rho_cube.remove_coord('surface_altitude')
sigma_dim = p_rho_cube.coord_dims('sigma')
p_rho_cube.remove_coord('sigma')
level_height_dim = p_rho_cube.coord_dims('level_height')
p_rho_cube.remove_coord('level_height')
p_rho_cube.remove_aux_factory(p_rho_cube.aux_factories[0])
# add the new ones
p_rho_cube.add_aux_coord(surface_alt, surface_altitude_dim)
p_rho_cube.add_aux_coord(sigma, sigma_dim)
p_rho_cube.add_aux_coord(delta, level_height_dim)
p_rho_cube.add_aux_factory(factory)
return p_rho_cube

Nick Savage
- 44
- 8
-
You can get hold of the dimension that the old coord was on before you remove it with `sigma_dim = p_rho_cube.coord_dims('sigma')` – RuthC Jul 31 '17 at 10:33