Differences between revisions 6 and 7
Revision 6 as of 2012-08-15 20:12:37
Size: 216
Editor: MikhailItkin
Comment:
Revision 7 as of 2012-08-15 20:20:12
Size: 669
Editor: MikhailItkin
Comment:
Deletions are marked like this. Additions are marked like this.
Line 2: Line 2:
Line 3: Line 4:
Download a [[http://www.unidata.ucar.edu/software/netcdf/examples/files.html| sample file (CCM precipitation flux, air temperature, etc)]]
 * Download a [[ http://www.unidata.ucar.edu/software/netcdf/examples/sresa1b_ncar_ccsm3_0_run1_200001.nc | sample file (CCM precipitation flux, air temperature, etc)]]
 * load python module and start ipython

{{{
module load python/2.7-ve0
ipython
}}}

Ipython listing

{{{#!python
# load Nio module
import Nio

# open netcdf file
f = Nio.open_file('sresa1b_ncar_ccsm3_0_run1_200001.nc', 'r') # 'r' stands for "read rights"

# check contents
print f

# read single variable:
pr = f.variables['pr']
print pr

# read variables contents
pr_data = pr[:]
print pr_data

# close file
f.close()
Line 6: Line 37:
{{{#!python

print Hello!

PyNIO

Read NetCDF files

module load python/2.7-ve0
ipython

Ipython listing

   1 # load Nio module
   2 import Nio
   3 
   4 # open netcdf file
   5 f = Nio.open_file('sresa1b_ncar_ccsm3_0_run1_200001.nc', 'r') # 'r' stands for "read rights"
   6 
   7 # check contents
   8 print f
   9 
  10 # read single variable:
  11 pr = f.variables['pr']
  12 print pr
  13 
  14 # read variables contents
  15 pr_data = pr[:]
  16 print pr_data
  17 
  18 # close file
  19 f.close()

LehreWiki: IoBasemapNgl (last edited 2012-08-16 08:22:08 by MikhailItkin)