[ncl-talk] where function

Adam Phillips asphilli at ucar.edu
Fri Jun 22 09:48:34 MDT 2018


Hi Nick,
This might work:
riskvalues_st = tostring(where(riskvalues.gt.1,1,0))
riskwords = where(riskvalues_st.eq."1","High",riskwords) ; assigns a high
risk when precipitation is large
If that doesn't work or if you have any further questions let ncl-talk know.
Adam


On Fri, Jun 22, 2018 at 9:34 AM Bassill, Nicholas <nbassill at albany.edu>
wrote:

> Hi All,
>
>    This isn't an important question, but it's an issue that's cropped up
> for me enough to count on two hands now. Basically, I'd love to use the
> "where" function to return values that are not of the same type as the
> conditional expression. I'm just wondering if anyone has an elegant way
> around this that doesn't involve a do loop and if check.
>
>
> This often gives an error, as the documentation notes ("If neither type
> can be coerced to the other type, an error is returned").
>
>
> Here's a standard example of why I'd like to use it this way. Say I'm
> making a risk table for various weather phenomena contingent on that
> phenomena's value (like say, wind speed or rainfall).
>
>
> It'd be really nice/easy to be able to do something like:
>
> ----------------
>
> ; note: below two arrays have same size
>
> riskvalues = *series of random numbers for a variable, say precipitation
> in inches*
>
> riskwords = *series of words - begin with all equal to "None"*
>
> riskwords = where(riskvalues.gt.1,"High",riskwords) ; assigns a high risk
> when precipitation is large
>
> --------------
>
> This will give an error because you're returning a string, which can't be
> coerced to the number type you're evaluating.
>
>
> So my question is twofold - (1) is there a way/flag to negate this
> behavior? and (2) assuming not, does anyone have a more elegant solution
> than a nested assignment inside an if check inside a do loop? It seems like
> the point of where is to avoid this situation.
>
>
> Thanks for any input!
>
>    - lazy coder
>
>
> Nick Bassill, PhD
>
> Modeler & Meteorologist, Center Of Excellence (Prior: NYS Mesonet)
>
> LC SB-28, 1400 Washington Ave.,
>
> SUNY, University at Albany, NY 12222
> (518) 442-6375
> NYSM Products: http://operations.nysmesonet.org/~nbassill/
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>


-- 
Adam Phillips
Associate Scientist,  Climate and Global Dynamics Laboratory, NCAR
www.cgd.ucar.edu/staff/asphilli/   303-497-1726

<http://www.cgd.ucar.edu/staff/asphilli>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180622/4da93f80/attachment.html>


More information about the ncl-talk mailing list