__init__ (version 0.1.1, 13 March 2004) | index __init__.py |
Define/calculate atmospheric constants and quantities.
Package of the following classes and methods/functions:
(1) The AtmQty class of all "atmospheric quantities" (defined
below). All such quantities in a given instantiation of the
class share the same latitude, longitude, level locations.
(2) The stand-alone AtmConst class of atmosphere-related con-
stants.
(3) Stand-alone functions to calculate atmospheric quantities
that are directly derivative from standard state variables.
Most (though not all) of these functions are referenced by
methods in AtmQty, but are called "stand-alone" because they
can also be used on objects that are not AtmQty attributes.
Used in a stand-alone fashion, these functions can operate
on arrays of any size and dimension and are not confined to
a spherical or vertical grid.
(4) Stand-alone functions to manipulate objects of the AtmQty
class (e.g. a regridding function that moves all variables
from one set of latitude, longitude, level locations to
another).
"Atmospheric quantities" are defined as quantities that are stan-
dard state variables or are directly derivative (i.e. not requi-
ring time integration or modeling) from standard state variables.
The AtmQty class is defined in __init__.py. The AtmConst class
and each of the stand-alone functions are defined individually in
separate modules in this package; AtmConst is defined in module
atmconst. For the stand-alone functions, the function name is
the same as the module name (e.g. function "theta" is defined in
module "theta").
The stand-alone functions may not be "truly" stand-alone since they
may require methods in other modules in this package; this package
is designed to be used as a unit. Some modules, like the atmconst
module, however, are truly stand-alone as they requires no other
modules besides themselves; see the notes in the beginning of the
module source code for details.
The package is written such that a single command "import atmqty"
to import the package will also import all the submodules in the
package (unless the package initialization module is being run
explicity at the command line as a unit test, in which case this
submodule import is not done). Thus, one does not need to type
in individual "import atmqty.M" commands for each M submodule.
Some useful online help commands for the package:
* help(atmqty): Help for the package (including the AtmQty class).
A list of all modules in this package is found in the "Package
Contents" section of the help output.
* help(atmqty.M): Details of each module "M", where "M" is the
module's name.
Example 1: Atmospheric constants:
>>> from atmconst import AtmConst
>>> const = AtmConst()
>>> '%.6f' % const.R_d
'287.050000'
Example 2: Stand-alone function:
>>> from theta import theta
>>> p = N.array([1000., 850., 500.])
>>> T = N.array([273.1, 257.3, 233.1])
>>> var = theta(p,T)
>>> ['%.6f' % var[i] for i in range(3)]
['273.100000', '269.537605', '284.189919']
Example 3: Single-level x-y domain AtmQty object:
(a) Initialize the AtmQty object:
>>> import atmqty
>>> import Numeric as N
>>> lat = N.arange(13) * 15.0 - 90.0
>>> lon = N.arange(25) * 15.0 - 180.0
>>> lev = N.array(850.)
>>> x = atmqty.AtmQty(lat, lon, lev, missing=1e29)
(b) The pattern "base" is two "distorted bulls-eyes" of opposite
polarity, centered over the poles (and add extra shallow
dimension to represent the single level):
>>> base = N.outerproduct(N.sin(lat*N.pi/360.), N.cos(lon*N.pi/360.))
>>> base = N.reshape(base, (base.shape[0], base.shape[1], 1))
(c) Create temperature and moisture "data" using the "base"
pattern and add to AtmQty object (a second, redundant call
to add_qty is provided to show the method accepts both types
of argument syntax shown):
>>> T = (base * 10.) + 257.3
>>> q = N.absolute(base) * 5e-3
>>> x.add_qty( {'q':q, 'T':T} )
>>> x.add_qty( {'q':q}, {'T':T} )
(d) Calculate potential temperature and output temperature and
potential temperature:
>>> x.theta()
>>> ['%.6f' % x.qty['T'][i,2,0] for i in range(3)]
['255.469873', '255.724409', '256.005905']
>>> ['%.6f' % x.qty['theta'][i,2,0] for i in range(3)]
['267.620434', '267.887077', '268.181961']
(e) Illustrate that the get_qty method is the same as accessing
the quantities dictionary directly:
>>> tmp = x.get_qty('theta')
>>> ['%.6f' % tmp[i,2,0] for i in range(3)]
['267.620434', '267.887077', '268.181961']
(f) Set T[1,2,0] to missing and calculate eice (note that the
other quantities, such as theta, that are dependent on T do
not recalculate to take into account the new missing value):
>>> x.qty['T'][1,2,0] = 1e29
>>> x.eice()
>>> ['%.7g' % x.qty['eice'][i,2,0] for i in range(3)]
['1.285009', '1e+29', '1.351447']
>>> ['%.6f' % x.qty['theta'][i,2,0] for i in range(3)]
['267.620434', '267.887077', '268.181961']
Modules | ||||||
|
Classes | ||||||||||
|
Data | ||
__all__ = ['atmconst', 'eice', 'esat', 'is_numeric_float', 'press2alt', 'theta', 'vapor_press', 'virt_temp'] __author__ = 'Johnny Lin <http://www.johnny-lin.com/>' __credits__ = 'Package contributions: Mike Fiorino.' __date__ = '13 March 2004' __test__ = {'Additional Example 1: Constants': '\n >>> from atmconst import AtmConst\n >>> c... >>> const.epsilon\n 0.62195306913960091\n ', 'Additional Example 2: Homogenous x-y domain AtmQty object': "\n >>> import atmqty\n >>> import Numeric as...3)]\n ['8.813646', '4.637070', '1.846433']\n ", 'Additional Example 3: More Example 3 methods, with missing values': "\n >>> import atmqty\n >>> import Numeric as...907822', '1e+29', '1.0002703', '0.67660701']\n "} __version__ = '0.1.1' |
Author | ||
Johnny Lin <http://www.johnny-lin.com/> |
Credits | ||
Package contributions: Mike Fiorino. |