【发布时间】:2016-06-15 20:56:29
【问题描述】:
我有一个 netcdf 文件,其中包含水箱中速度场的时间相关分布。我大致知道如何在特定时间步长内绘制速度场的大图,但我想绘制空间固定点中速度变量(u,v,w)的时间变化。
一切都使用 python。
【问题讨论】:
-
你现有的代码在哪里?
我有一个 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])
【讨论】: