Differences between revisions 2 and 5 (spanning 3 versions)
Revision 2 as of 2011-01-17 11:12:55
Size: 3380
Editor: anonymous
Comment:
Revision 5 as of 2011-01-17 11:27:48
Size: 2756
Editor: anonymous
Comment:
Deletions are marked like this. Additions are marked like this.
Line 13: Line 13:
== Example: ARGO floats == == Example data from Argo system ==
Line 15: Line 15:
http://en.wikipedia.org/wiki/Argo_%28oceanography%29 [[http://en.wikipedia.org/wiki/Argo_%28oceanography%29|Argo observation system]]
Line 19: Line 19:
First we have to download the data. Here is a script that can be used to download one month of data in a temporary directory called {{{tmp_dir}}}: First we have to download the data. Here is a [[/download script]] that can be used to retrieve one month of Argo data.
Line 21: Line 21:
{{{#!python
#!/usr/bin/env python
import os,os.path
from ftplib import FTP
We extract only the surface temperature to reduce the large amount of data. The next script generates an overview of the data and writes the surface temperature in a file [[attachment:lat_lon_T.tab]] which contains latitude, longitude and surface temperature. We can use this file in the following.
Line 26: Line 23:
tmp_dir='/scratch/clisap/seaice/TMP/u242023/ARGO/'

ftp_adr='ftp.ifremer.fr'
ftp_dir='/ifremer/argo/geo/atlantic_ocean/2011/01/'

ftp = FTP(ftp_adr) # connect to host, default port
ftp.login() # user anonymous, passwd anonymous@
ftp.cwd(ftp_dir)

file_list=ftp.nlst()

for f in file_list:
    urlfile='ftp://'+ftp_adr+ftp_dir+f
    localfile=tmp_dir+f
   
    if not(os.path.exists(localfile)):
        print 'Getting file '+f
         #We use curl instead of ftp.retrbinary for download
        os.system("curl -s -k -o "+localfile+" "+urlfile)
    else:
        print 'file '+f+' exists'

ftp.close()
}}}

The next script generates an overview of the data and writes the surface temperature in a file called {{{lat_lon_T.tab}}} which contains latitude, longitude and surface temperature. [[attachment:lat_lon_T.tab]]

2-dimensional interpolation and gridding

2-dimensional interpolation and gridding is a common problem for the representation of measurements on a map. Usually measurements are taken at irregular sample points and not in a regular grid. There are various approaches for the problem and the best solution depends on the data.

In the following we will look at oceanographic parameters that have been measured with the Argo system.

Example data from Argo system

Argo observation system

Data are provided at, i.e. ftp://ftp.ifremer.fr//ifremer/argo/

First we have to download the data. Here is a /download script that can be used to retrieve one month of Argo data.

We extract only the surface temperature to reduce the large amount of data. The next script generates an overview of the data and writes the surface temperature in a file lat_lon_T.tab which contains latitude, longitude and surface temperature. We can use this file in the following.

argo_position.png Argo_plot.png

   1 import scipy.io as io
   2 import glob
   3 from pylab import *
   4 from mpl_toolkits.basemap import Basemap
   5 
   6 tmp_dir='/scratch/clisap/seaice/TMP/u242023/ARGO/'
   7 
   8 
   9 file_liste=glob.glob(tmp_dir+'*.nc')
  10 D={}# Empty dictionary to store selected profiles
  11 for f in file_liste:# Loop over all data
  12 
  13 
  14     # Open netcdf data file
  15     fid=io.netcdf_file(f,'r')
  16 
  17     # Read content into variables
  18     lat=fid.variables['LATITUDE'][:].copy()
  19     lon=fid.variables['LONGITUDE'][:].copy()
  20     T=fid.variables['TEMP'][:].copy()
  21     P=fid.variables['PRES'][:].copy()
  22     
  23     T[T>=99999]=nan # Set 99999.0 to "Not a Number"
  24     P[P>=99999]=nan
  25 
  26     (nr_profs,Z)=T.shape # Get dimension
  27 
  28     for i in range(nr_profs):
  29         D[(lon[i],lat[i])]=(T[i,:],P[i,:])
  30 
  31     # Close data file
  32     fid.close()
  33 
  34 fid=open('lat_lon_T.tab','w')
  35 for k in D.keys():# write position (lat,lon), surface temperature to file
  36     fid.write(str(k[0])+'\t'+str(k[1])+'\t'+str(D[k][0][0])+'\n')
  37 fid.close()
  38 stop
  39 
  40 
  41 # Draw map of positions
  42 m = Basemap(projection='ortho',lon_0=-45,lat_0=0,resolution='l')
  43 m.bluemarble()
  44 for lon,lat in D.keys():
  45     x,y=m(lon,lat) # Coordinate transfer
  46     m.plot(x,y,'r.')
  47     
  48 savefig('argo_position.png',dpi=150)
  49 
  50 # Plot profiles
  51 figure()
  52 for k in D.keys():
  53 #    print k
  54     plot(D[k][0][:],D[k][1][:])
  55 axis([-2,30,2000,0])
  56 xlabel('T')
  57 ylabel('P')
  58 show()
  59 savefig('Argo_plot.png',dpi=75)

LehreWiki: OpenSource2010/Lesson12 (last edited 2011-01-17 13:34:14 by anonymous)