我需要生成一个立方体,该立方体具有一个立方体的水平网格和另一个立方体的垂直网格(用于在温度立方体和u风立方体上对rho级别施加压力的立方体)。文档缺乏上下文,我通过谷歌搜索找不到任何有用的东西。我想像复制温度立方体,在立方体中使用sigma和delta进行拼接,然后在立方体上运行factory.update,但是我无法完全理解语法。
答案 0 :(得分:1)
HybridHeightFactory附加到立方体,并根据请求生成“海拔”坐标 它需要链接到合适的表面高度坐标才能工作 - 这意味着将它移动到具有不同水平网格的立方体并不是那么简单。
所以我认为“factory.update”并不是一条很好的路线,只需要+附加一个新的路线就更简单了。
该计划将类似......
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)
注意:在从旧数据制作“new_cube”时,您可能还需要删除现有的辅助工厂。
答案 1 :(得分: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