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