| | |
- __builtin__.object
-
- GaCore
- GaCore
- exceptions.Exception(exceptions.BaseException)
-
- GrADSError
class GaCore(__builtin__.object) |
| |
This is the core GrADS client class. It provides the basic functionality
to start the GrADS application, send commands to it and parse its
output.
_Methods provided:
cmd - sends a generic command to GrADS
open - opens a file, returning metadata in a dictionary
query - queries the GrADS state, returning properties in
a dictionary
rline - returns a given line from the GrADS stdout
rword - returns a given word from the GrADS stdout
setdim - set dimension from dictionary returned by query()
flush - fluxes the communication pipes
Methods for exchanging data arrays with GrADS as well as an interface
to Python based graphics are provided in derived classes such as
*GanNum* and *GaLab*. |
| |
Methods defined here:
- __call__ = cmd(self, gacmd, Quiet=False, Block=True)
- __del__(self)
- Sends GrADS the 'quit' command and close the pipes.
- __init__(self, Bin='gradshdf', Echo=True, Opts='', Port=False, Strict=False, Verb=0, Window=None)
- Starts the GrADS process using popen2() function. Optional input
parameters are:
Bin the name of the GrADS binary; you can enter a full path
here, say, "/opt/mygrads/bin/gradshdf", or simply the
name of other executables, e.g., "gradsdods" if this is
on your PATH.
Echo if True output from GrADS will not be echoed on the screen
Port If set to True GrADS will start in portrait mode; default is
to start GrADS in landscape mode.
Opts Use that to send additional options to GrADS, such as -c
Strict By default, it behaves a bit like perl: not raising
exceptions for index errors, etc. If Strict=1, then
exceptions will be raised.
Verb provides information about each GrADS command executed. If
set to zero, it will be real quiet. When Verb=1 the rc code
of failed GrADS commands will be printed. If verb=2 then
the rc for all GrADS commands will be printed.
Window If True GrADS will start with a graphics window; the
default is to start GrADS in batch mode.
- 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 defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
|
GrADS = class GaCore(__builtin__.object) |
| |
This is the core GrADS client class. It provides the basic functionality
to start the GrADS application, send commands to it and parse its
output.
_Methods provided:
cmd - sends a generic command to GrADS
open - opens a file, returning metadata in a dictionary
query - queries the GrADS state, returning properties in
a dictionary
rline - returns a given line from the GrADS stdout
rword - returns a given word from the GrADS stdout
setdim - set dimension from dictionary returned by query()
flush - fluxes the communication pipes
Methods for exchanging data arrays with GrADS as well as an interface
to Python based graphics are provided in derived classes such as
*GanNum* and *GaLab*. |
| |
Methods defined here:
- __call__ = cmd(self, gacmd, Quiet=False, Block=True)
- __del__(self)
- Sends GrADS the 'quit' command and close the pipes.
- __init__(self, Bin='gradshdf', Echo=True, Opts='', Port=False, Strict=False, Verb=0, Window=None)
- Starts the GrADS process using popen2() function. Optional input
parameters are:
Bin the name of the GrADS binary; you can enter a full path
here, say, "/opt/mygrads/bin/gradshdf", or simply the
name of other executables, e.g., "gradsdods" if this is
on your PATH.
Echo if True output from GrADS will not be echoed on the screen
Port If set to True GrADS will start in portrait mode; default is
to start GrADS in landscape mode.
Opts Use that to send additional options to GrADS, such as -c
Strict By default, it behaves a bit like perl: not raising
exceptions for index errors, etc. If Strict=1, then
exceptions will be raised.
Verb provides information about each GrADS command executed. If
set to zero, it will be real quiet. When Verb=1 the rc code
of failed GrADS commands will be printed. If verb=2 then
the rc for all GrADS commands will be printed.
Window If True GrADS will start with a graphics window; the
default is to start GrADS in batch mode.
- 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 defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
|
|