grads.gacore (version 1.0.9)
index
/Users/dasilva/src/pygrads/grads/gacore.py

This module implements a Python interface to GrADS by means of
bi-directional pipes. It requires a small patch to GrADS to unbuffer
stdin/stdout and to allow capture of error codes. This modules
provides the basic GrADS class which implements the basic functionality to
start grads, send commands to it and to retrieve the text output
produced by *grads* in response to such command.

 
Modules
       
os
sys

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

 
class GrADSError(exceptions.Exception)
    Defines GrADS general exception errors.
 
 
Method resolution order:
GrADSError
exceptions.Exception
exceptions.BaseException
__builtin__.object

Methods defined here:
__init__(self, value)
__str__(self)

Data descriptors defined here:
__weakref__
list of weak references to the object (if defined)

Data and other attributes inherited from exceptions.Exception:
__new__ = <built-in method __new__ of type object at 0x1e6a40>
T.__new__(S, ...) -> a new object with type S, a subtype of T

Methods inherited from exceptions.BaseException:
__delattr__(...)
x.__delattr__('name') <==> del x.name
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__getitem__(...)
x.__getitem__(y) <==> x[y]
__getslice__(...)
x.__getslice__(i, j) <==> x[i:j]
 
Use of negative indices is not supported.
__reduce__(...)
__repr__(...)
x.__repr__() <==> repr(x)
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value
__setstate__(...)

Data descriptors inherited from exceptions.BaseException:
__dict__
args
message
exception message

 
Functions
       
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.
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.

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