2017-07-26 67 views
0

我需要生成一個立方體,其中一個立方體的水平網格和另一個立方體的垂直網格一個溫度立方體和一個au風力立方體)。文檔缺乏上下文,我無法找到任何有用的谷歌搜索。我想像做複製溫度立方體,用立方體中的西格瑪和三角洲進行處理,然後在立方體上運行factory.update,但我無法完全理解語法。如何使一個立方體的水平網格和另一個垂直網格的立方體成爲一個立方體

回答

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」,您可能需要太刪除現有的輔助工廠。

+0

真的非常感謝。我確實有一些問題,例如拆除舊的混合高度工廠。我將在下面發佈我的功能。 –

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 
+0

您可以在使用'sigma_dim = p_rho_cube.coord_dims('sigma')' – RuthC

+0

將其刪除之前獲得舊座標的尺寸。謝謝!這很好。我將在上面編輯我的代碼 –