【问题标题】:Plot the time evolution of a variable in a fixed point of a netcdf file using python使用python在netcdf文件的固定点绘制变量的时间演变
【发布时间】:2016-06-15 20:56:29
【问题描述】:

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

一切都使用 python。

【问题讨论】:

  • 你现有的代码在哪里?

标签: python netcdf


【解决方案1】:

加载数据后,使用切片非常容易。例如,以我们模型中的 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])

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-10-06
    • 2016-02-15
    • 2021-05-28
    • 2021-02-25
    • 1970-01-01
    • 1970-01-01
    • 2020-10-27
    相关资源
    最近更新 更多