[gradsusr] Setting color bar for animation

Jeffrey Duda jdduda at iastate.edu
Wed Mar 23 14:26:20 EDT 2011


Clay,
That is simply how grads behaves.  If you look through the grads
documentation index for the set ccols (e.g.,
http://www.iges.org/grads/gadoc/gradcomdsetccols.html) and set clevs
commands, you'll notice they say things like "this is reset by a display
command".  You will have to issue the commands each time before you display
a variable.  This shouldn't be a problem if you are using a while loop to
create your animation, though.

Jeff

On Wed, Mar 23, 2011 at 1:22 PM, Clay Blankenship <
clay.b.blankenship at nasa.gov> wrote:

> Yes, that is correct.  Ideally, I would specify the range and not have to
> pick the exact colors.  (I'll go back and do that later if necessary.)  Just
> specifying
> clevs initially works fine on my first plot.  If I 'd' the variable, and
> then 'cbar', I get the range of values I want.  However if I advance the
> time one step,
> and do the 'd var' and 'cbar' again,  I get a different value range.  It
> appears that I have to set clevs every time I do a plot.  How is it getting
> reset?
> (And I still haven't figured out how to print out the current clevs and
> ccols.)
>
> Clay
>
>
>
>
>
> On Mar 23, 2011, at 11:23 AM, Jeffrey Duda wrote:
>
> Clay,
> In your original thread post, you asked how to plot a consistent range and set of colors for each time slice of data you want to
> display.  Is that correct?  If so, then all you need to do is use the "set clevs" and "set ccols" commands before you display the
>
> data.  Unless you want to adjust the range of contours and colors so that they fit the maximum and minimum value in the domain
> each time you display data, then it really is that simple.  Simple code to do this would be:
>
> 'set dbuff on'
> t = 1
> 'set gxout shaded'
> while (t <= 5)
>   'set t 't
>   'draw title Temperature'
>   'set clevs A B C D E F G H I ...'
>   'set ccols 17 18 29 20 21 22 23 ...'
>
>   'd t'
>   'cbar'
>   'swap'
>   t = t + 1
> endwhile
>
> This example assumes you have defined color numbers 17, 18, 19, ... and so on using the "set rgb" command prior to this section
>
> of code.  It might be easier just to write a separate script file that defines the colors, then issues the "set clevs" and
> "set ccols" command.  Then you could replace some of the code above with something like
>
> 'set dbuff on'
> t = 1
> 'set gxout shaded'
> while (t <= 5)
>   'set t 't
>   'draw title Temperature'
>   'run mycolorscript.gs'
>
>   'd t'
>   'cbar'
>   'swap'
>   t = t + 1
> endwhile
>
> where you created the script called mycolorscript.gs.  I have sample animated gifs stored at http://www.meteor.iastate.edu/~jdduda/sfc_div.gif
>
> and http://www.meteor.iastate.edu/~jdduda/radar3.gif that show how I used those command lines and a while loop to create the
> frames necessary for an animation, then used gifsicle to make the animated gif.  Gifsicle is another way to make animations,
>
> but you have to use it outside of Grads, and you'd need to make the images first (i.e., the frames of the animation).
>
> I hope this clarifies things.
>
> Jeff Duda
>
>
> On Wed, Mar 23, 2011 at 10:42 AM, Clay Blankenship <
> clay.b.blankenship at nasa.gov> wrote:
>
>> OK, from the command line I can use make_clevs to specify any range of
>> levels and plot and get the color bar.  But both of my scripts dd.gs (a
>> script to plot, specify a range, and make a color bar) and ani.gs(animation) do not plot the full color bar when I specify the range with
>> script arguments.  I can't figure out what's going on...
>>
>> Also, I am still looking for a way to display the current ccols and clevs.
>>  Do you have to use 'q shades'?
>>
>> One more thing, this animation script regulates its speed by redrawing the
>> plot a certain number of times; is there a better way to do that?
>>
>> Thanks,
>> Clay
>>
>> ****dd.gs***********
>> function dd (args)
>> *Plot a variable and its color scale.
>> * dd variable [ -cmin minimum value ]
>> *             [ -cmax maximum value ]
>> *             [ -cint color scale ]
>>
>> variable=subwrd(args,1)
>>
>> ccint=''
>> ccmin=''
>> ccmax=''
>> string=''
>> space=' '
>> n=2
>>
>> while(n<9)
>> idx=subwrd(args,n)
>> opt=subwrd(args,n+1)
>> if(idx='');break;endif
>> if(idx='-cint');ccint=opt;endif
>> if(idx='-cmin');ccmin=opt;endif
>> if(idx='-cmax');ccmax=opt;endif
>> if(idx='-string');string=opt;endif
>> n=n+2
>> endwhile
>>
>> 'c'
>> 'set gxout shaded'
>> if(ccint!=''); 'set cint 'ccint;endif
>> if(ccmin!=''); 'set cmin 'ccmin;endif
>> if(ccmax!=''); 'set cmax 'ccmax;endif
>> if(ccmin!=''); if(ccmax!=''); 'set rbrange 'ccmin ' 'ccmax; endif;endif
>>
>> *CBB 3/22/11 set the levels
>> 'make_clevs ' cmin cmax cint
>> 'd 'variable
>>
>> *Add date and user-input string
>> 'q time'
>> say result
>> cctime=subwrd(result,3)
>> coln=substr(cctime,3,1)
>> if coln = ':'
>> dmy   =substr(cctime,7,9)
>> else
>> dmy   =substr(cctime,1,12)
>> day   =substr(cctime,1,3)
>> my   =substr(cctime,4,9)
>>
>> *dmy   =substr(cctime,4,9)  *cbb changed
>> endif
>>
>> * 'draw title 'dmy space string
>>  'draw title 'day space my space string
>>
>> 'q shades'
>>
>> 'cbar2'
>>
>> ****END***********
>>
>> ***ani.gs************
>>
>> * Display animation
>> *     ga> run ani variable [ -I slowness (default=10) ]
>> *                            [ -cint, -ci  contour interval ]
>> *                            [ -cmin, -mn  minimum contour level ]
>> *                            [ -cmax, -mx  maximum contour level ]
>> *   ex. ga> run ani t-t.2 -ci 0.1 -mn -0.5 -I 5 -cmax 0.3
>> *          >>>> plot (t-t.2) with slowness=5, contour_interval=0.1
>> *               minimum contour level=-0.5, maximum contour level=0.3
>> *
>> *                                                  Nov. 9, 1999 Masami
>> Nonaka
>> *
>> function ani (args)
>>
>> variable=subwrd(args,1)
>>
>> slow=''
>> ccint=''
>> ccmin=''
>> ccmax=''
>> cbar=''
>> n=2
>>
>> while(n<10000)
>> idx=subwrd(args,n)
>> opt=subwrd(args,n+1)
>> if(idx='');break;endif
>> if(idx='-I');slow=opt;endif
>> if(idx='-Int');slow=opt;endif
>> if(idx='-cint');ccint=opt;endif
>> if(idx='-cmin');ccmin=opt;endif
>> if(idx='-cmax');ccmax=opt;endif
>> if(idx='-ci');ccint=opt;endif
>> if(idx='-mn');ccmin=opt;endif
>> if(idx='-mx');ccmax=opt;endif
>> n=n+2
>> endwhile
>>
>> defaultslow=10
>> if(slow=''); slow=defaultslow;endif
>>
>> 'q dims'
>>  say result
>> aline=sublin(result,5)
>> cctime1=subwrd(aline,11)
>> cctime2=subwrd(aline,13)
>> tmin=substr(cctime1,1,9)
>> tmax=substr(cctime2,1,9)
>> it=tmin
>> 'set dbuff on'
>> while (it <=tmax)
>>  'set t 'it
>> i=0
>> while (i <slow)
>> if(ccint!=''); 'set cint 'ccint;endif
>> if(ccmin!=''); 'set cmin 'ccmin;endif
>> if(ccmax!=''); 'set cmax 'ccmax;endif
>> if(ccmin!=''); if(ccmax!=''); 'set rbrange 'ccmin ' 'ccmax; endif;endif
>>
>> *CBB 3/22/11 setting max min clevs
>> 'make_clevs ' cmin cmax cint
>>
>>  'display 'variable
>>
>>  'run date.gs'
>>
>>
>>
>>  'query shades'
>> shdinfo = result
>> if(subwrd(shdinfo,1)!='None');'run fcbar.gs';endif
>>
>> 'swap'
>> i=i+1
>> endwhile
>>  it=it+1
>> endwhile
>>  'set t ' tmin ' ' tmax
>>
>>
>> ****END***********
>>
>>
>>
>>
>>
>>
>> On Mar 22, 2011, at 5:23 PM, Goodson,Ron [Edm] wrote:
>>
>>  I see in my original note I mislead you .. when I said I do my
>> make_clevs.gs before cbar.  As was noted by Jeffrey . the settings of
>> clevs, ccols (all that stuff) must happen before the display of the
>> variable.  So swap those two lines of "display" and "make_clevs".
>>
>>
>>
>> The other thing I usually do right at the start of my programs (and only
>> has to be done once .. unlike settings clevs, ccols which must be done
>> before each display)  is to setup some custom colours through "set rgb" (one
>> entrie per colour) and rbcols (to set the order of the colours).   You don't
>> need to do this if you are using the GrADS standard scheme of 16 colours.
>>
>>
>>  ron
>>
>>  ------------------------------
>> *From:* gradsusr-bounces at gradsusr.org [
>> mailto:gradsusr-bounces at gradsusr.org <gradsusr-bounces at gradsusr.org>] *On
>> Behalf Of *Clay Blankenship
>> *Sent:* March 22, 2011 4:05 PM
>> *To:* GrADS Users Forum
>> *Subject:* Re: [gradsusr] Setting color bar for animation
>>
>> OK, that make_clevs works for me when I do a simple 'd' on my variable,
>> but when I try to use a little fancier script (not even an animation, just
>> trying to pass the range on the command line), I lose the min and max
>> values.
>>
>> If I do:
>>
>> c
>> make_clevs 0 2 0.2
>> d soilwat5
>> cbar
>>
>> I get a colorbar from 0 to 2 in steps of .2, even though the variable
>> range is 0 to 1 (so far, so good).
>>
>> If I do:
>>
>> dd soilwat5 -cmin 0 -cmax 2 -cint 0.2
>>
>> I get a colorbar from 0 to 1 in steps of 0.2.  The colors are the same for
>> the different ranges, it just doesn't show the ones above 1.  Is this
>> because clevs are set and ccols are not?  I was hoping ccols would get set
>> automatically like it does when you don't specify levels.
>>
>> This happens whether or not I use the make_clevs line in the following
>> script.
>>
>> BTW, this seems really basic, but I can't figure out how to see the
>> current values of ccols and clevs.
>> cbar is getting its ccols and clevs from 'q shades', but it doesn't  react
>> to ccols and clevs until a plot has been made.
>>
>> Script follows.
>>
>> Thanks for the help,
>> Clay
>>
>>
>>
>>   --
>> Clay Blankenship                 * USRA Research Scientist
>> clay.b.blankenship at nasa.gov      * 256-961-7638
>> 320 Sparkman Drive               * Huntsville, AL 35805 USA
>> National Space Science and Technology Center at NASA-MSFC/UAH
>>
>>
>>
>>
>>
>>
>>
>> _______________________________________________
>> gradsusr mailing list
>> gradsusr at gradsusr.org
>> http://gradsusr.org/mailman/listinfo/gradsusr
>>
>>
>
>
> --
> Jeff Duda
> Iowa State University
> Meteorology Graduate Student
> 3134 Agronomy Hall
> www.meteor.iastate.edu/~jdduda <http://www.meteor.iastate.edu/%7Ejdduda>
> <ATT00001.txt>
>
>
> --
> Clay Blankenship                 * USRA Research Scientist
> clay.b.blankenship at nasa.gov      * 256-961-7638
> 320 Sparkman Drive               * Huntsville, AL 35805 USA
> National Space Science and Technology Center at NASA-MSFC/UAH
>
>
>
>
>
>
>
> _______________________________________________
> gradsusr mailing list
> gradsusr at gradsusr.org
> http://gradsusr.org/mailman/listinfo/gradsusr
>
>


-- 
Jeff Duda
Iowa State University
Meteorology Graduate Student
3134 Agronomy Hall
www.meteor.iastate.edu/~jdduda
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20110323/5c4ed210/attachment-0003.html 


More information about the gradsusr mailing list