繁体   English   中英

在python中针对2D数组插值3D WRF数据

[英]Interpolating 3D WRF Data against a 2D array in python

我一直在研究用于WRF模型研究的python脚本,但在插值例程方面遇到了一些困难。 在我的情况下,我试图绘制一个特定的场,但是,在整个山脉中,使用横扫压力水平,尤其是对于较低的水平(1000、850)通常会导致极高的最大值或纳值。它们在地面以下。

因此,我的想法是编写一个脚本来检测地面的压力水平(轻松完成以下操作):

pb = ncFile.variables['PB'][0][0]
p = ncFile.variables['P'][0][0]
sfcPres = pb + p

这将导致包含地面压力的2D阵列表面,然后在其上方分别建立两个分别包含压力50hPa和100hPa的场:

medLevel = sfcPres - 50
topLevel = sfcPres - 100

从这里开始,我想给sfcPres,medLevel和topLevel这三个数组一个插值函数作为height参数,以将每个纬度对的数据集插值到三个数组的纬度对。

我的问题是,到目前为止,我使用的所有插值例程仅允许将压力值插值到奇异值,正如我在上文所述,这会导致出现极限边缘的问题。

我希望能够按此函数的顺序执行某些操作,使期望的水平参数可以采用该2D数组并在该2D内每个点的3D数据集([Z,lat,lon]数组)上执行插值阵列。

有谁知道这样做的简单方法,因为数据集非常大,所以不涉及使用循环,我需要使用8个组合集(约60个文件)来计算函数的平均值。

谢谢!

没有简单的方法可以做到这一点,它确实涉及使用循环。 我有自己的WRF例程,可以将4D变量字段线性插值到我指定的恒定高度的表面。 我相信您应该能够为压力表面修改此功能。 虽然WRF数据困扰我,但我一直在工作。

def linear_height(var,surface): #defaults to .5km to 20.5km with .5 km intervals
    '''
    Requirements:
    import numpy as np

    This function will take in a variable and the corrosponding height surface of the model to
    then interpolate to constant height surfaces from 500m to 20km at 500m intervals.
    The interpolation to the new height surfaces is linear and occurs from the lowest level x,y point
    to the top level x,y point.

    The output variable will have the same units as the input variable but will have a different shape
    Assuming that height is the second column of the array, this will be the only length to change
    example: linear_height(Temperature, Height_surfaces)

    '''
    ######################################
    #Edit to change the levels of the interpolated height coordinates
    new_height = np.arange(500,20500,500) # 1km to 20 km
    ######################################
    new_surf = np.empty((var.shape[0],new_height.shape[0],var.shape[2],var.shape[3]))

    for TIM in np.arange(var.shape[0]):
        for IDX, VAL in np.ndenumerate(var[0][0]):
            new_val = np.interp(new_height,surface[TIM,:,IDX[0],IDX[1]],var[TIM,:,IDX[0],IDX[1]],left=np.nan, right=np.nan)
            new_surf[TIM,:,IDX[0],IDX[1]]=new_val[:]
    return new_surf

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM