# `gemath` Examples: Calculating Curl

## Description

This web page provides examples of using `curl_2d` to calculate curl on winds from a CCM3 run. To avoid presenting too many exapmles, only a subset of all the possible options is provided. 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 `help(curl_2d)`.

## Import Statements and Data

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 zonal (`u`) and meridional (`v`) winds 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 `Numeric`. Vectors `x` and `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:

## Examples

### Order 1 Spherical

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')
```

### SPHEREPACK

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 Algorithm With Missing Values

Setting `algorithm` to `'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 `1e+20`.

```>>> u[30:41,20:37] = 1e+20
>>> curl = curl_2d(x, y, u, v, algorithm='default_spherical')
```

## Full Code and Data File For Examples

Return to gemath Index.
Return to Johnny Lin's Python Library.

Updated: April 26, 2004 by Johnny Lin <email address>. License.