Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing variables from Netcdf into Python

Tags:

python

netcdf

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.

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)

like image 581
Claire Krause Avatar asked Sep 01 '25 10:09

Claire Krause


1 Answers

I figured it out.

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'][:,:]

Thanks!

like image 149
Claire Krause Avatar answered Sep 03 '25 00:09

Claire Krause