2017-08-10 45 views
1

我一直在研究一個我用於WRF模型研究的python腳本,並且我在插入例程時遇到了一些困難。在我的情況下,我試圖繪製一個特定的領域,但是,使用全面的掃描壓力水平,特別是對於較低水平(1000,850),通常在處理山區時導致極大的極大值或極值他們低於地面水平。在Python中插入3D WRF數據與2D數組

所以,我的想法是寫檢測地面的壓力水平(以下情況很容易做到)的腳本:

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

導致含地面壓力的二維陣列表面,然後建立含有壓力50hPa和100hPa從分別與上述這兩個其它字段:

medLevel = sfcPres - 50 
topLevel = sfcPres - 100 

在這裏,我想給三個陣列:sfcPres,medLevel和頂層內插函數作爲高度參數來內插所述數據設定爲每個o f lat,lon對與三個陣列的相應的經緯度對。

我的問題是,我所使用的所有插值程序迄今爲止只允許針對壓力水平的奇異值進行插值,正如我上面所述,這導致邊緣極值問題。

我希望能夠按照this function的順序進行操作,其中desiredlevel參數可以採用該二維數組,並在3D數據集([Z,lat,lon]的數組)上對每個點執行插值在那個二維數組中。

有沒有人知道一個簡單的方法來做到這一點,不涉及使用循環,因爲數據集相當大,我需要使用8個組合集約60個文件計算函數的平均值。

謝謝!

回答

0

有沒有簡單的方法來做到這一點,它涉及到使用循環。我有自己的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 
+0

我明白了,這是令人失望的。我在CONUS的絕大多數人身上有一個4km 24成員集合模擬,我需要生成一個不穩定參數的集合方法,該參數使用了需要使用這種方法進行插值的五個變量。我的單個WRFOUT文件上的測試腳本在24小時後仍然運行,所以很遺憾,看起來我對這個特定的情節運氣不好。 謝謝反正! – Phantom139