[gradsusr] Question on converting script.gs to gradspy

Stephen Woodbridge stephenwoodbridge37 at gmail.com
Sun Jan 6 21:36:51 EST 2019


Ignore, this post, I have it figured out. For those that don't, its 
pretty straight forward, just run the lines through gradspy.cmd() the 
big difference is in handling variables, you keep them on the python 
side for the most part. For example a line like:

'set ylopts 'col1' 5'

in a script where col1 is a variable in the script, you make the a 
variable in python and then run:

gradspy.cmd('set ylots ' + col1 + ' 5')

So variables in the script become variables in python and functions in 
the script become functions in python.

And I found this to be a nice way to handle a long list of commands:

   cmds = [
     'set dfile 1',
     'set t 1 ' + str(nt),
     'set grads off',
     'c ',
     'set lon ' + str(lon),
     'set lat ' + str(lat),
     ]
   for cmd in cmds:
     gradspy.cmd(cmd)

Hope this helps someone.
-Steve

On 1/6/2019 1:10 PM, Stephen Woodbridge wrote:
> Hi all,
>
> I have a grads script, as script.gs, and I'm wondering how to convert 
> it to a python script. The reason for converting it is that I need to 
> get back the curve data that would be used to plot a curve in grads. 
> So for example, I have in the script:
>
> ...
>
> *******************************************************
> * Plot Second Panel (Wind Speed/Direction)
> *******************************************************
> 'set parea .75 10.5 .5 4 '
> 'set grid on 5 '_black
> 'set tlsupp off'
> 'set string '_black
> 'set strsiz .13 '
> 'set ylopts 'col1' 5'
> 'set ylpos -0.45 l'
> 'set annot 'col1
> 'set xlab off'
> 'set ccolor 'col1
> 'set ylab on '
> 'set cterp on '
> 'set vrange 0 16 '
> 'set ylint 2 '
> 'set xlevs 'xlevs
> 'set gxout linefill'
> 'set lfcols 'col1' '_black
>
> *WGRIB2'define b=HTSGWsfc*0'
> 'define b='_sig_height'*0'
>
> *WGRIB2'd smth9(HTSGWsfc*3.25);b '
> 'd smth9(htsgw_surface*3.25);b '
>
> and I want to get the data that was used to plot this curve. Do I just 
> run gradspy.cmd(line) for each of the lines above then for the last run:
>
> gradspy.cmd("'d smth9(htsgw_surface*3.25);b '")  # to display it
>
> res = gradspy.results("'smth9(htsgw_surface*3.25);b '")  # to fetch 
> results
>
> Can I pass a list of commands to gradspy.cmd(list) for all the sets?
>
> Are there docs and examples for gradspy beyond te one page explaining 
> start, cmd, and result methods?
>
> Thanks and sorry if this has been asked and answered before, I'm still 
> stumbling around in the dark here :)
>
> -Steve
>


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus



More information about the gradsusr mailing list