#======================================================================= # Examples for Testing Function curl_2d in Module curl_2d. # (Using CCM3 output.) # # I assume that this script is run on a system that has the module # sphere installed. # # Copyright (c) 2004 by Johnny Lin. For licensing, distribution # conditions, contact information, and additional documentation see # the URL http://www.johnny-lin.com/py_pkgs/gemath/doc/. #======================================================================= #- Import modules: try: execfile('/home/jlin/.pythonrc.py') except: print "test_curl_2d.py: Ignore Johnny Lin's path settings." import cdms, os, MV import Numeric as N import gemath from gemath.curl_2d import curl_2d import IaGraph from IaGraph import * #- Data: From CCM3 output. u and v are in m/s and x and y are in # deg (except for the final example, when we take x and y as being # in m): f = cdms.open('uv_501hPa_ccm3.nc') u = f('U') v = f('V') x = MV.filled( u.getAxis(-1)[:] ) y = MV.filled( u.getAxis(-2)[:] ) u = MV.filled( u[:,:] ) v = MV.filled( v[:,:] ) #- Set system variables for lon/lat axes tick labels: sysvar = IaGraph.Sysvar() sysvar.__class__.x_tickvalues = \ {0:'0', 90:'90E', 180:'180E', 270:'270E', 360:'360E'} sysvar.__class__.y_tickvalues = \ {-90:'90S', -45:'45S', 0:'EQ', 45:'45N', 90:'90N'} #- Plot u and v data: base_fn = 'test_curl_2d_ccm3_udata' contour(u, x, y, title=base_fn) active2gif(base_fn+'.gif') os.system('convert -verbose -trim -border 8x8 -bordercolor white ' \ +'-mattecolor black -frame 2x2 ' \ +base_fn+'.gif gem_'+base_fn+'.jpg') base_fn = 'test_curl_2d_ccm3_vdata' contour(v, x, y, title=base_fn) active2gif(base_fn+'.gif') os.system('convert -verbose -trim -border 8x8 -bordercolor white ' \ +'-mattecolor black -frame 2x2 ' \ +base_fn+'.gif gem_'+base_fn+'.jpg') #- Use order 1 spherical algorithm: x and y are in deg and u and v # are in m/s. The curl is in 1/s. Note that these results should # be nearly identical to those from SPHEREPACK: curl = curl_2d(x, y, u, v, algorithm='order1_spherical') base_fn = 'test_curl_2d_ccm3_o1sph' contour(curl, x, y, continents=1, title=base_fn) active2gif(base_fn+'.gif') os.system('convert -verbose -trim -border 8x8 -bordercolor white ' \ +'-mattecolor black -frame 2x2 ' \ +base_fn+'.gif gem_'+base_fn+'.jpg') #- Use spectral method from SPHEREPACK. Here we take x and y in deg, # while u and v are in m/s. If so the curl is in 1/s: curl = curl_2d(x, y, u, v, algorithm='spherepack') base_fn = 'test_curl_2d_ccm3_sphpk' contour(curl, x, y, continents=1, title=base_fn) active2gif(base_fn+'.gif') os.system('convert -verbose -trim -border 8x8 -bordercolor white ' \ +'-mattecolor black -frame 2x2 ' \ +base_fn+'.gif gem_'+base_fn+'.jpg') #- Add some missing values in the middle of the plot, use the # "default_spherical" algorithm. The order 1 spherical algorithm # will be chosen: u[30:41,20:37] = 1e+20 curl = curl_2d(x, y, u, v, algorithm='default_spherical') base_fn = 'test_curl_2d_ccm3_defsph' contour(MA.masked_values(curl, 1e+20), x, y, continents=1, title=base_fn) active2gif(base_fn+'.gif') os.system('convert -verbose -trim -border 8x8 -bordercolor white ' \ +'-mattecolor black -frame 2x2 ' \ +base_fn+'.gif gem_'+base_fn+'.jpg') #- Close data file: f.close() # ===== end file =====