grads.galab (version 1.1.0)
index
/Users/dasilva/src/pygrads/grads/galab.py

This module implements the GaLab class, an extention of the GrADS
client class which adds Matplotlib/Basemap specific methods for
contours, images and other graphical functionality. This class
provides high level methods operating directly on GrADS expressions
(or *fields*) while retaining all the configurability that Matplotlib
has to offer.

 
Modules
       
PIL.Image
matplotlib.cm
numpy.ma
os
sys

 
Classes
       
grads.ganum.GaNum(grads.gacore.GaCore)
GaLab

 
class GaLab(grads.ganum.GaNum)
    This class extends the GrADS client class GaNum by providing an interface
to PyLab and Matplotlib. The main design philosophy is to use the
GrADS dimension environment to derive sensible defaults for the
high level graphical commands, while retaining most of Matplotlib
configurability.
 
 
Method resolution order:
GaLab
grads.ganum.GaNum
grads.gacore.GaCore
__builtin__.object

Methods defined here:
__init__(self, **kwopts)
Contructor. All keyword options (**kwopts) are passed to the
costructor of the core GrADS client class.
basemap(self, proj='latlon', dh=None, opts=None, resolution='c', area_tresh=10000.0, **kwopts)
Defines basemap based on GrADS dimension environment.
blue_marble(self, mode=None, Filename=None, dh=None, Show=False, Nx=None, Ny=None, Cache=True)
Loads Blue Marble image at the current map projection and
use it as the default background image. For turning the
Blue Marble background on for subsequent plotting methods
you enter
 
   ga.blue_marble('on')
 
For retriving an image on the current map projection:
 
   bm = blue_marble()
contour(self, expr, **kwopts)
Wrapper around Basemap.contour() with axis, colorbar and map
transformations based on the current dimension environment/
map projection.
contourf(self, expr, **kwopts)
Wrapper around Basemap.contourf() with axis, colorbar and map
transformations based on the current dimension environment/
map projection.
implain(self, expr, dh=None, cmap=None, interpolation='bicubic', vmin=None, vmax=None, **kwopts)
Evaluates GrADS expression and display it as an image
on the current basemap.
imshow(self, expr, **kwopts)
Wrapper around Basemap.imshow() with axis, colorbar and map
transformations based on the current dimension environment/
map projection.
interp(self, expr, lons, lats, dh=None, **kwopts)
Evaluates GrADS expression (or GaField) and interpolates it to
the the (longitude,latitude) points given the input arrays
(lons,lats) on input. Both x/y dimensions must be
varying. When the z-dimenson is varying as well a curtain
slice is returned. For now, the time dimension must be fixed.
Example:
 
  tau, levs = ga.interp('duexttau',lons,lats)
 
where *levs* is an 1D array with the versical levels. The optional
**kwopts arguments are passwd to the basemap.interp() function.
 
Note: the basemap interpolation routine requires longitudes in
the range [-180,180]. When *expr* is a string the longitudes are
set to the correct range. However, when *expr* is a GaField
the user must make sure this is the case or undefs may result.
pcolor(self, expr, **kwopts)
Wrapper around Basemap.pcolor() with axis, colorbar and map
transformations based on the current dimension environment/
map projection.

Methods inherited from grads.ganum.GaNum:
eof(self, expr, transf='anomaly', metric='area', keep=None)
Given a GrADS generalized expression *expr*, calculates Empirical 
Orthogonal Functions (EOFS) using Singular Value Decomposition (SVD). 
 
    V, d, c = eof(expr)
 
where
 
    V  ---  A specialized GrADS Field holding eigenvectors
            with *add* offset and *scale* factors to aid
            subsequent decomposition in terms of V
    d  ---  NumPy array with eigenvalues
    c  ---  NumPy array with principal components
 
The other optional parameters are:
 
transf     
    Type of pre-processing transform to be applied:
    None     ---  time series as is
    anomaly  ---  remove time mean
    z-score  ---  remove time mean and divide 
                  by standard deviation
metric    
    Determines whether to scale the timeseries prior
    to calculation of the EOFs; this is equivalent to 
    choosing a particular norm. Acceptable values are:
    None   ---  do not scale
    'area' ---  multiply by cos(lat), the default
 
keep
    How many eigenvectors to keep:
    None  ---  in this case keep as many vectors as 
               there are timesteps (nt) 
    n     ---  keep "n" eigenvectors
 
Notice that *expr* on input is a *generalized expression* in the
sense that it can contain a string with a GrADS expression to be
evaluated or a valid GrADS field. See method *exp* for additional
information.
exp(self, expr)
Exports GrADS expression *expr*, returning a GrADS Field.
 
    F = exp(expr)
 
where
 
    F  ---  GrADS field
    
Generalized Expressions
=======================
 
For convenience, *expr* can also be a GrADS Field.  In such
cases, the input Field is just returned back. This
*overloading* is useful for writing high level functions that
work equaly on a GrADS expression to be exported or on GrADS
fields already known to python.
expr(self, expr)
Evaluates a GrADS expression returning a GrADS Field. This is similar
to the exp() method except that the resulting GaField cannot be
imported back into GrADS. It relies on *gacore* methods eval()
and coords() to retrieve the data and coordinate information.
imp(self, name, Field)
Sends a GrADS Field containing a NumPy array and associated 
grid information to GrADS, defining it in GrADS as *name*.
Notice that *Field* can be an instance of the GaField
class or a tuple with the (Array,Grid) components.
lsq(self, y_expr, x_exprs, Bias=False, Mask=None)
 Given a target GrADS expression *y_expr* and a tuple of predictor
 GrADS expressions *x_exprs*, returns a NumPy array with linear 
 regression coefficients 
 
     c, info = lsq(y_expr, x_exprs)
 
 where *info* contains information about the minimization:
 
     info.residuals  ---  sum square of residuals
     info.rank       ---  rank of the predictor matrix
     info.s          ---  singular values of predictor matrix
 
 When Bias=False (default) the residual
 
     y - c[0] * x[:,0] + c[1] * x[:,1] + ... + c[n] * x[:,N-1]
 
 is minimized in the last square sense, where *x* and *y* are
 NumPy arrays associated with the following GrADS Fields:
 
     Y = exp(y_expr)
     X[:,n] = exp(x_exprs[n]),  n = 0, ..., N-1
 
When Bias=True, the additional predictor array 
 
     x[N] = ones(y)
 
is included in the calculation, resulting in an output array of
size N+1. This is equivalent to allowing for an *intercept* in
the regression equation.
 
The optional Mask is a 1D logical array with the location of the
data to be included (see compress() method).
 
On input, all expressions are *generalized expressions* in the
sense that they can contain a string with a GrADS expression to be
evaluated or a valid GrADS field. See method *expr* for additional
information.

Methods inherited from grads.gacore.GaCore:
__call__ = cmd(self, gacmd, Quiet=False, Block=True)
Sends a command to GrADS. When Block=True, the output is captured 
and can be retrieved by methods rline() and rword().
__del__(self)
Sends GrADS the 'quit' command and close the pipes.
cmd(self, gacmd, Quiet=False, Block=True)
Sends a command to GrADS. When Block=True, the output is captured 
and can be retrieved by methods rline() and rword().
coords(self)
Returns a GaHandle object with attributes defining the
following coordinate variables associated with the current
dimension environmnet:
 
name  ---  set to "coords"
undef ---  based on default file
dims  ---  list with names of varying dimensions
denv  ---  dimension environment: result of query("dims")
time  ---  list with time, e.g., ['00Z01JAN1987', '12Z01JAN1987' ]
lev   ---  float array with vertical levels
lat   ---  float array with latitudes
lon   ---  float array with longitudes
 
Notice that this method defines many of the attributes of
a GaGrid object.
eval(self, expr)
Exports GrADS expression *expr*, returning a flat Python array.
 
    a = eval(expr)
 
where
 
    a  ---  flat Python array (or flat jarray under Jython)
    
Generalized Expressions
=======================
 
For convenience, *expr* can also be an array.  In such
cases, the input Field is just returned back. This
*overloading* is useful for writing high level functions that
work equaly on a GrADS expression to be exported or on arrays.
flush(self)
Flushes the GrADS pipes. This is primarily an internal 
method that sometimes can be useful to the end-user. If for
some reason the echo you see on the screen seems out of sync
with the command you just issued, a call to *flush()* may be your
ticket. (This situation is usually a symptom of an internal
error.)
jcoords(self)
Returns a GaHandle object with attributes defining the
coordinate variables associated with the current dimension
environment. This is a Java wrapper; see coords() for 
additional information.
jopen(self, fname, ftype='default', Quiet=False)
Similar to open() but returns a Java HashMap instead.
This method only makes sense under Jython.
jquery(self, what, Quiet=False)
Queries GrADS internal state and returns a Java Hashtable with 
the results. This method only makes sense under Jython.
open(self, fname, ftype='default', Quiet=False)
Opens a GrADS file, returning the relevant metadata. On input,
ftype can be used to specify which GrADS open command to open
the file:
ctl      the classic GrADS control file; uses the "open" command
sdf      NetCDF, HDF or a DODS URL; uses the "sdfopen" command
xdf      NetCDF, HDF or a DODS URL; uses the "xdfopen" command
default  Open command is Guessed from the file name; the heuristic
         algorithm works pretty well but is not perfect, therefore
         the options above for when it fails.
query(self, what, Quiet=False)
Queries GrADS internal state and returns a GaHandle object
with the results of the query:
 
   qh = query(what)
 
where *what* is the name of the properpty being queried.
When Quiet=True echo of GrADS commands is temporarily 
suppressed. The following properties are implemented:
 
qh = self.query ( "file #" )
 
   Returns information about the file number "#". If the file number
   is ommitted the default file is used. The following *qh* attributes
   are defined:
 
      fid        - the file Id number
      title      - the title of the dataset
      desc       - the description of the dataset
      bin        - the binary file name
      type       - file type
      nx         - number of longitudinal points
      ny         - number of latitudinal points
      nz         - number of vertical levels
      nt         - number of times on file
      nvars      - number of variables on file
      vars       - list of variable names in the file
      var_levs   - list of number of levels for each variable
      var_titles - list of long names for each variable
      var_info   - list of tuplet triplets (var,levs,title) for each 
                   variable to allow easy iterating:
                     qh = ga.query('file')
                     for varname, nlevels, vartitle in qh.var_info:
                         # ...
 
qh = self.query ( "dims" )
                                                                        
   Returns information about the dimension environment. The following
   *qh* attributes are define:
                                                                        
      dfile   - default file number
      x_state - x-coordinate state: "fixed" or "varying"
      lon     - longitudinal range
      x       - x-index range
      y_state - y-coordinate state: "fixed" or "varying"
      lat     - latitudinal range
      y       - y-index range
      z_state - z-coordinate state: "fixed" or "varying"
      lev     - level range
      z       - z-index range
      t_state - time-coordinate state: "fixed" or "varying"
      time    - time range
      t       - t-index range
rline(self, i=None)
Returns the ith line of the most recent GrADS output.
If *i* is not specified, returns the number of lines available
rword(self, i, j)
Returns the jth word of the ith line of the most recent
GrADS output
setdim(self, dh)
Sets the dimension environment. On input, 8dh* is usually obtained
as the output of:
 
    dh = ga.query('dims')

Data descriptors inherited from grads.gacore.GaCore:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
Functions
       
arange(...)
arange([start,] stop[, step,], dtype=None)
 
For integer arguments, just like range() except it returns an array
whose type can be specified by the keyword argument dtype.  If dtype
is not specified, the type of the result is deduced from the type of
the arguments.
 
For floating point arguments, the length of the result is ceil((stop -
start)/step).  This rule may result in the last element of the result
being greater than stop.
array(...)
array(object, dtype=None, copy=1,order=None, subok=0,ndmin=0)
 
Return an array from object with the specified data-type.
 
Parameters
----------
object : array-like
    an array, any object exposing the array interface, any
    object whose __array__ method returns an array, or any
    (nested) sequence.
dtype : data-type
    The desired data-type for the array.  If not given, then
    the type will be determined as the minimum type required
    to hold the objects in the sequence.  This argument can only
    be used to 'upcast' the array.  For downcasting, use the
    .astype(t) method.
copy : bool
    If true, then force a copy.  Otherwise a copy will only occur
    if __array__ returns a copy, obj is a nested sequence, or
    a copy is needed to satisfy any of the other requirements
order : {'C', 'F', 'A' (None)}
    Specify the order of the array.  If order is 'C', then the
    array will be in C-contiguous order (last-index varies the
    fastest).  If order is 'FORTRAN', then the returned array
    will be in Fortran-contiguous order (first-index varies the
    fastest).  If order is None, then the returned array may
    be in either C-, or Fortran-contiguous order or even
    discontiguous.
subok : bool
    If True, then sub-classes will be passed-through, otherwise
    the returned array will be forced to be a base-class array
ndmin : int
    Specifies the minimum number of dimensions that the resulting
    array should have.  1's will be pre-pended to the shape as
    needed to meet this requirement.
ceil(...)
ceil(x)
 
Return the ceiling of x as a float.
This is the smallest integral value >= x.
floor(...)
floor(x)
 
Return the floor of x as a float.
This is the largest integral value <= x.
fromfile(...)
fromfile(file=, dtype=float, count=-1, sep='')
 
Return an array of the given data type from a text or binary file.
 
Data written using the tofile() method can be conveniently recovered using
this function.
 
Parameters
----------
file : file or string
    Open file object or string containing a file name.
dtype : data-type
    Data type of the returned array.
    For binary files, it is also used to determine the size and order of
    the items in the file.
count : int
    Number of items to read. -1 means all data in the whole file.
sep : string
    Separator between items if file is a text file.
    Empty ("") separator means the file should be treated as binary.
 
See also
--------
loadtxt : load data from text files
 
Notes
-----
WARNING: This function should be used sparingly as the binary files are not
platform independent. In particular, they contain no endianess or datatype
information. Nevertheless it can be useful for reading in simply formatted
or binary data quickly.
inner(...)
innerproduct(a,b)
Returns the inner product of a and b for arrays of floating point types.
Like the generic NumPy equivalent the product sum is over
the last dimension of a and b.
NB: The first argument is not conjugated.
maketrans(...)
maketrans(frm, to) -> string
 
Return a translation table (a string of 256 bytes long)
suitable for use in string.translate.  The strings frm and to
must be of the same length.
sleep(...)
sleep(seconds)
 
Delay execution for a given number of seconds.  The argument may be
a floating point number for subsecond precision.
time(...)
time() -> floating point number
 
Return the current time in seconds since the Epoch.
Fractions of a second may be present if the system clock provides them.
zeros(...)
zeros(shape, dtype=float, order='C')
 
Return a new array of given shape and type, filled zeros.
 
Parameters
----------
shape : tuple of integers
    Shape of the new array
dtype : data-type
    The desired data-type for the array.
order : {'C', 'F'}
    Whether to store multidimensional data in C or Fortran order.

 
Data
        HAS_PIL = True
StringTypes = (<type 'str'>, <type 'unicode'>)
__version__ = '1.1.0'
abs = <ufunc 'absolute'>
ascii_letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
cos = <ufunc 'cos'>
digits = '0123456789'
hexdigits = '0123456789abcdefABCDEF'
letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
lowercase = 'abcdefghijklmnopqrstuvwxyz'
newaxis = None
octdigits = '01234567'
pi = 3.1415926535897931
printable = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c'
punctuation = '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
sqrt = <ufunc 'sqrt'>
uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
whitespace = '\t\n\x0b\x0c\r '