[gradsusr] If Statements and Drawing Variables

Jennifer M Adams jadams21 at gmu.edu
Wed Apr 19 10:48:20 EDT 2017


The latest version of GrADS has an if() function, which could simplify this operation a bit for you. http://cola.gmu.edu/grads/gadoc/gradfuncif.html
If your are unable to upgrade, then you can use const() and maskout() to create separate variables that have desired index values and zeros everywhere else, then you can simply add those variables together to ‘merge’ them into one plot.
—Jennifer

On Apr 18, 2017, at 6:14 PM, Carter Humphreys - Mods for GRX <carter.humphreys at mods-for-grx.com<mailto:carter.humphreys at mods-for-grx.com>> wrote:

Jeff,

Thank you for the help! I got that working. So I've gotta a few different fields that I am working with here. What I want to be able to do is after performing the maskout()and const() on those fields, combine the resulting index value from all fields into one image. So in other words, taking the lowest in each field and outputting that as the final image.

I would image you could use the same process [ maskout) + const() ]but wouldn't that require a variables? (And I can't draw variables)

Thank you!


--

Sincerely,

Carter J. Humphreys

Developer


Mods for GRX

carter.humphreys at mods-for-grx.com<mailto:carter.humphreys at mods-for-grx.com> | Support Email: support at mods-for-grx.com<mailto:support at mods-for-grx.com> | Website: www.mods-for-grx.com<http://www.mods-for-grx.com/>

On Mon, Apr 17, 2017 at 10:50 PM, Jeff Duda <jeffduda319 at gmail.com<mailto:jeffduda319 at gmail.com>> wrote:
Unfortunately you can't define plottable fields like that. You need to use a combination of maskout() and const() to get the desired field. Nesting of const((maskout)) usually gets you what you want. maskout() works like an if statement, filtering out values you don't want to plot based on an inequality. The way it works is maskout(field,mask), where field is the raw field you want to plot, and mask is an expression which may include other fields and/or constants. For example, if you wanted to just plot EHI where it was > 1, you could do 'd maskout(ehi,ehi-1)'. The result of maskout is a field plotted only where the mask expression is > 0 (might be >= 0, I forget, but if you're dealing with a continuous field, the end result is the same). Anywhere the mask field does not satisfy the equation, the raw field is treated like missing data. This is where const() comes in. You can nest maskout() within const() to tell grads what to do with the missing data (like the ELSE part of the if-else block). If you wanted to fill the rest of the EHI-masked field with 0s, for example, you could do 'd const(maskout(ehi,ehi-1),0,-u)', where the -u flag specifies const() to only apply the else value to undefined values (created by the maskout).

While maskout works best for one-sided (i.e., semi-infinite) inequalities (e.g., x > 5 or x <= -10), you can use it for bounded inequalities as well using the absolute value function. You'll have to get a little clever with your masking expression, but some simple algebra will do it for you. You can also sum values and take an average (where the bounded inequality is valid, you'll sum the same field twice, so taking the average will restore the original values to the field. For example, for your first expression:
'd 0.5*(maskout(ehi,ehi-0.25)+maskout(ehi,0.5-ehi))' would plot a band of EHI values at grid points where 0.25 < EHI < 0.5. You could wrap this in a const() function to change those values to 1: 'd const(0.5*(maskout(ehi,ehi-0.25)+maskout(ehi,0.5-ehi)),1)'. You can then do that for all your bands. There will not be any overlap.

Of course, that's a longhand way of doing it. You can also just use repeated multiplied instances of nested const(maskout()) functions to get the same result in one grand command, although it will be quite involved. I'll give you a start and leave you to figure the rest out:

'd const(const(maskout(ehi,0.125 - abs(ehi-0.375)),1),0,-u)...
This first chunk gives your first condition where index would be set to 1. Use multiplication for the other terms.

Good luck!

Jeff Duda


On Mon, Apr 17, 2017 at 4:59 PM, Carter Humphreys - Mods for GRX <carter.humphreys at mods-for-grx.com<mailto:carter.humphreys at mods-for-grx.com>> wrote:
Hello,

I'm fairly new to GrADS and am trying use a script to search through a model product using if statements and assign a value to a certain range of that product. (I.e. if temp is between 45 and 55, x = 2) I then try to have GrADS draw that variable but all I end up with is a blank map.

Any help would be appreciated, it's probably simple but I've been pretty much lost after trying this for a few days now.

My Script:

'clear'
'set mpdset hires'
'sdfopen http://nomads.ncep.noaa.gov/dods/nam/nam20170417/nam_12z'

'define ehi = (capesfc*hlcy1000_0m)/160000'
'define index = 0'

if (ehi>=0.25 & ehi<0.50)
index = 1
endif

if (ehi>=0.50 & ehi<0.75)
index = 2
endif

if (ehi>=0.75 & ehi<1.00)
index = 3
endif

if (ehi>=1.00)
index = 4
endif

'set gxout shaded'

'd index'

'cbar'
'draw title GrADS Script Test'
'printim C:/GrADS/GrADS_script_test.png png white'


--

Sincerely,

Carter J. Humphreys

Developer


Mods for GRX

carter.humphreys at mods-for-grx.com<mailto:carter.humphreys at mods-for-grx.com> | Support Email: support at mods-for-grx.com<mailto:support at mods-for-grx.com> | Website: www.mods-for-grx.com<http://www.mods-for-grx.com/>

_______________________________________________
gradsusr mailing list
gradsusr at gradsusr.org<mailto:gradsusr at gradsusr.org>
http://gradsusr.org/mailman/listinfo/gradsusr




--
Jeff Duda
Post-doctoral research fellow
University of Oklahoma School of Meteorology

_______________________________________________
gradsusr mailing list
gradsusr at gradsusr.org<mailto:gradsusr at gradsusr.org>
http://gradsusr.org/mailman/listinfo/gradsusr


_______________________________________________
gradsusr mailing list
gradsusr at gradsusr.org<mailto:gradsusr at gradsusr.org>
http://gradsusr.org/mailman/listinfo/gradsusr

--
Jennifer Miletta Adams
Center for Ocean-Land-Atmosphere Studies (COLA)
George Mason University



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20170419/e1e0087e/attachment-0001.html 


More information about the gradsusr mailing list