使用Python在NetCDF文件的固定点中绘制变量的时间演变



我有一个netcdf文件,其速度场在水罐中的时间相关分布。我粗略地知道如何在特定的时间步中绘制速度场的大图,但是我想在固定空间的固定点中绘制速度变量(u,v,w)时间的变化。

使用Python的一切。

加载数据后,使用切片非常容易。例如,以我们模型的NetCDF数据文件为例:

ncdump -h的输出:

netcdf w.xz {  
dimensions:  
    x = 1024 ;  
    y = 1 ;  
    zh = 512 ;  
    time = UNLIMITED ; // (81 currently)  
variables:  
    float time(time) ;  
        string time:units = "Seconds since start of experiment" ;  
    float x(x) ;  
    float y(y) ;  
    float zh(zh) ;  
    float w(time, zh, x, y) ;  
}  

如果您加载了时间和速度变量,则为:

import netCDF4 as nc4
f    = nc4.Dataset('w.xz.nc')
time = f.variables['time'][:]
w    = f.variables['w'][:,:,:,:]   # dimensions: time,z,x,y

您可以在例如位置z,x,y = index{10,5,1}

k = 10; i = 5; j = 1
data = w[:,k,i,j]

或将其绘制为:

pl.plot(time, w[:,k,i,j])

最新更新