gemathExamples: Calculating Curl
This web page provides examples of using
to calculate curl on winds from a CCM3 run. To avoid presenting
too many exapmles, only a subset of all the possible options is
Output from examples illustrating
the use of additional options is also provided; comparison to all the
examples operates as a "unit test" of the function.
A link to the full source code and the data file used in these
examples is at the bottom of this page. For more information on the
curl_2d command, type
All examples below use the following import statements and data:
>>> import cdms, MV >>> import gemath >>> from gemath.curl_2d import curl_2d
The data is from a netCDF data file of
u) and meridional (
at a pressure level of 501.275 hPa for a moment of time in a CCM3 run
(the moment in time is at 2970.0 days since 0000-09-01 00:00:00).
Winds are in m/s.
We read in the winds using netCDF utilities from
cdms and convert the arrays to
y are longitude and latitude,
respectively, in degrees:
>>> 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[:,:] )
The zonal (
u) wind looks like:
and the meridional (
v) wind looks like:
The algorithm used is order 1 differencing in spherical coordinates. Curl is in 1/s, if the winds are in m/s and the domain are in degrees longitude and latitude.
>>> curl = curl_2d(x, y, u, v, algorithm='order1_spherical')
NCAR SPHEREPACK, which solves the curl in spectral space, is used as the algorithm. Since the CCM3 grid is gaussian, SPHEREPACK can be used.
>>> curl = curl_2d(x, y, u, v, algorithm='spherepack')
'default_spherical' uses an order 1 (spherical)
algorithm or SPHEREPACK.
If there are missing values, order 1 (spherical)
is chosen since spectral methods cannot work in those cases.
We set a block of
u to the default missing value
>>> u[30:41,20:37] = 1e+20 >>> curl = curl_2d(x, y, u, v, algorithm='default_spherical')