0

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.

4

2 回答 2

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”时,您可能还需要删除现有的辅助工厂。

于 2017-07-27T10:02:12.690 回答
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
于 2017-07-27T12:30:04.717 回答