python interface
Arlindo da Silva
dasilva at ALUM.MIT.EDU
Mon Sep 10 02:01:52 EDT 2007
On 9/7/07, Hai-Ru Chang <hrc at eas.gatech.edu> wrote:
> Hello,
> Does anyone have a package allowing call grads functions from
> language python? Thanks!
>
The answer is yes and no. I have a partially implemented grads class
that allows you to drive GrADS from python; see man page below and
actual code attached. Two problems with it:
1) It needs the command line option "-u" which will be present in the
final v1.9 release coming up sometime this Fall. It really amounts to
a small patch of grads.c, I can post this patch if there is interest.
Don't try this on v1.9b4 because it will certainly hang. (I am
attaching to code so that you can see if it has the functionality you
need).
2) I am yet to implement the methods that allow to exchange variable
data to/from python; I am not sure if you need this feature. Take a
look at the attached code.
Arlindo
Help on module grads:
NAME
grads
FILE
grads.py
DESCRIPTION
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 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. The
destructor closes grads and the pipes used for communication
CLASSES
GrADS
class GrADS
| Methods defined here:
|
| __del__(self)
| Sends GrADS the 'quit' command and close the pipes.
|
| __init__(self, Bin='gradshdf', Echo=0, Opts='', Port=0,
Strict=0, Verb=0, Window=0)
| 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 set to 1 output from GrADS will be echoed on the screen
| Port If set to 1 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 set to 1 GrADS will start with a graphics window; the
| default is to start GrADS in batch mode.
|
| cmd(self, gacmd)
| Sends a command to GrADS; output is captured and can be
| retrieved by methods rline() and rword(). On output, the
| return code received from GrADS.
|
| open(self, fname, ftype='default')
| 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)
| Queries GrADS internal state and returns a hash with the
| results. PARTIALLY IMPLEMENTED - THIS IS JUST AN EXAMPLE!
|
| recv(self, expr)
| Receives the result of the GrADS expression 'expr', returning
| a float point field. *** NOT IMPLEMENTED YET ***
|
| rline(self, i)
| Returns the ith line of the most recent GrADS output
|
| rword(self, i, j)
| Returns the jth word of the ith line of the most recent
| GrADS output
|
| send(self, field, vname)
| Sends a local float 'field' to GrADS, defining it as 'vname'.
| *** NOT IMPLEMENTED YET ***
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| VERSION = '1.00'
>
>
>
>
>
>
> Dr. Hai-Ru Chang
>
> School of Earth and Atmospheric Sciences
>
> Georgia Institute of Technology
>
> Atlanta, GA 30332-0340
>
> tel: 404-385-4404
>
--
Arlindo da Silva
dasilva at alum.mit.edu
-------------- next part --------------
A non-text attachment was scrubbed...
Name: grads.py
Type: text/x-python-script
Size: 12715 bytes
Desc: not available
Url : http://gradsusr.org/pipermail/gradsusr/attachments/20070910/eb52f411/attachment.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: utGrADS.py
Type: text/x-python-script
Size: 3684 bytes
Desc: not available
Url : http://gradsusr.org/pipermail/gradsusr/attachments/20070910/eb52f411/attachment-0001.bin
More information about the gradsusr
mailing list