将变量从Netcdf导入Python [英] Importing variables from Netcdf into Python

查看:97
本文介绍了将变量从Netcdf导入Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Python还是很陌生,我设法将一些变量从NetCDF读入Python并绘制它们,但是变量的大小不正确.

I am very new to Python, and I have managed to read in some variables from NetCDF in to Python and plot them, but the size of the variables isn't correct.

我的数据集是144 x 90(lon x lat),但是当我调用变量时,它似乎错过了很大一部分数据.

My dataset is 144 x 90 (lon x lat) but when I call in the variables, it seems to miss a large section of data.

我是否需要指定正在读取的数据集的大小?那是我在这里做错了吗?

Do I need to specify the size of the dataset I'm reading in? Is that what I'm doing wrong here?

这是我正在使用的代码:

Here is the code I am using:

    import netCDF4
    from netCDF4 import Dataset
    from pylab import *

    ncfile = Dataset('DEC3499.aijE03Ccek11p5A.nc','r')

    temp = ncfile.variables['tsurf']
    prec = ncfile.variables['prec']

    subplot(2,1,1)
    pcolor(temp)

    subplot(2,1,2)
    pcolor(prec)

    savefig('DEC3499.png',optimize=True,quality=85)

    quit()

请澄清一下,这是显示输出的图像.框的最右边应该有数据.

Just to clarify, here is an image showing the output. There should be data right to the far right hand side of the box.

( http://img163.imageshack.us/img163/6900/screenshot20130520at112.png )

推荐答案

我知道了.

对于那些感兴趣的人,我只需要修改以下几行即可正确提取变量:

For those interested, I just needed to amend the following lines to pull in the variables properly:

temp = ncfile.variables['tsurf'][:,:]
prec = ncfile.variables['prec'][:,:]

谢谢!

这篇关于将变量从Netcdf导入Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆