Differences between revisions 2 and 5 (spanning 3 versions)
Revision 2 as of 2009-11-14 21:31:49
Size: 2330
Editor: anonymous
Comment:
Revision 5 as of 2009-11-14 22:37:52
Size: 2411
Editor: anonymous
Comment:
Deletions are marked like this. Additions are marked like this.
Line 8: Line 8:

= NetCDF =

 * http://www.unidata.ucar.edu/software/netcdf/docs/netcdf.html
Line 93: Line 98:
{{{attachment:Argo_plot.png}}} {{attachment:Argo_plot.png}}

Contents

  1. NetCDF
  2. Excercise

NetCDF

Excercise

Write scripts

  • to download all Argo data in the Atlantic for the last month, and

  • to plot the pressure against the temperature for only those profiles with a surface temperature below -1 deg C.

   1 #download_argo.py
   2 import os,os.path
   3 from ftplib import FTP
   4 
   5 tmp_dir='/home/lars/data/tmp/'
   6 ftp_adr='ftp.ifremer.fr'
   7 ftp_dir='/ifremer/argo/geo/atlantic_ocean/2009/11/'
   8 
   9 ftp = FTP(ftp_adr)   # connect to host, default port
  10 ftp.login()          # user anonymous, passwd anonymous@
  11 ftp.cwd(ftp_dir)
  12 
  13 file_list=ftp.nlst()
  14 
  15 for f in file_list:
  16     urlfile='ftp://'+ftp_adr+ftp_dir+f
  17     localfile=tmp_dir+f
  18    
  19     if not(os.path.exists(localfile)):
  20         print 'Getting file '+f
  21          #We use curl instead of ftp.retrbinary for download
  22         os.system("curl -s -k -o "+localfile+"  "+urlfile)
  23     else:
  24         print 'file '+f+' exists'
  25 
  26 ftp.close()

   1 #Plot Argo profiles with surface temperature below 1 deg C
   2 import scipy.io as io
   3 import glob
   4 from pylab import *
   5 
   6 tmp_dir='/home/lars/data/tmp/'
   7 file_liste=glob.glob(tmp_dir+'*.nc')
   8 
   9 D={}# Empty dictionary to store selected profiles
  10 for f in file_liste:
  11     print f
  12 
  13     # Open netcdf data file
  14     fid=io.netcdf_file(f,'r')
  15 
  16     #print fid.variables.keys()
  17 
  18     # Make a copy of the content 
  19     lat=fid.variables['LATITUDE'][:].copy()
  20     lon=fid.variables['LONGITUDE'][:].copy()
  21     T=fid.variables['TEMP'][:].copy()
  22     P=fid.variables['PRES'][:].copy()
  23     
  24     T[T>=99999]=nan # Set 99999.0 to "Not a Number"
  25     P[P>=99999]=nan
  26     
  27     (nr_profs,Z)=T.shape # Get dimension
  28 
  29     for i in range(nr_profs):
  30         if T[i,0]<1.0: # Select only those profiles with surface temperature below 1 deg C
  31             # Store profile in dictionary with the position as a key
  32             D[(lat[i],lon[i])]=(T[i,:],P[i,:])
  33     # Close data file
  34     fid.close()
  35 
  36 
  37 # Plot data
  38 figure()
  39 for k in D.keys():
  40     print k
  41     plot(D[k][0][:],D[k][1][:])
  42 axis([-2,3,2000,0])
  43 xlabel('T')
  44 ylabel('P')
  45 show()

Argo_plot.png

LehreWiki: OpenSource2010/Lesson5 (last edited 2010-11-21 10:48:36 by anonymous)