<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p style="margin-top:0;margin-bottom:0">Hi Adam,</p>
<p style="margin-top:0;margin-bottom:0"> Thanks! That works and it's pretty elegant too. </p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<div id="Signature">
<div id="divtagdefaultwrapper" dir="ltr" style="font-size: 12pt; color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif, Helvetica, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;">
<div id="divtagdefaultwrapper" dir="ltr" style="font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); font-family: Calibri, Arial, Helvetica, sans-serif, Helvetica, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;">
<p><span style="color:rgb(0,0,0); font-family:Calibri,Arial,Helvetica,sans-serif; font-size:16px">Nick Bassill, PhD</span></p>
<p style="color:rgb(0,0,0); font-family:Calibri,Arial,Helvetica,sans-serif; font-size:16px">
Modeler & Meteorologist, Center Of Excellence (Prior: NYS Mesonet)</p>
<p style="color:rgb(0,0,0); font-family:Calibri,Arial,Helvetica,sans-serif; font-size:16px">
LC SB-28, 1400 Washington Ave.,</p>
<p style="color:rgb(0,0,0); font-family:Calibri,Arial,Helvetica,sans-serif; font-size:16px">
SUNY, University at Albany, NY 12222</p>
(518) 442-6375</div>
<div id="divtagdefaultwrapper" dir="ltr" style="font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); font-family: Calibri, Arial, Helvetica, sans-serif, Helvetica, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;">
NYSM Products: <a href="http://operations.nysmesonet.org/~nbassill/" class="OWAAutoLink" id="LPNoLP">http://operations.nysmesonet.org/~nbassill/</a></div>
</div>
</div>
<br>
<br>
<div style="color: rgb(0, 0, 0);">
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Adam Phillips <asphilli@ucar.edu><br>
<b>Sent:</b> Friday, June 22, 2018 11:48 AM<br>
<b>To:</b> Bassill, Nicholas<br>
<b>Cc:</b> Ncl-talk<br>
<b>Subject:</b> Re: [ncl-talk] where function</font>
<div> </div>
</div>
<meta content="text/html; charset=utf-8">
<div>
<div dir="ltr"><span style="color:rgb(0,0,0); font-family:Calibri,Helvetica,sans-serif; font-size:16px">Hi Nick,</span>
<div><span style="color:rgb(0,0,0); font-family:Calibri,Helvetica,sans-serif; font-size:16px">This might work:</span></div>
<div><span style="color:rgb(0,0,0); font-family:Calibri,Helvetica,sans-serif; font-size:16px">riskvalues_st = tostring(where(riskvalues.gt.1,1,0))</span>
<div><span style="font-size:16px; color:rgb(0,0,0); font-family:Calibri,Helvetica,sans-serif">riskwords = where(riskvalues_st.eq."1","High",riskwords) ; assigns a high risk when precipitation is large</span></div>
</div>
<div><span style="font-size:16px; color:rgb(0,0,0); font-family:Calibri,Helvetica,sans-serif">If that doesn't work or if you have any further questions let ncl-talk know.</span></div>
<div><span style="font-size:16px; color:rgb(0,0,0); font-family:Calibri,Helvetica,sans-serif">Adam</span></div>
<div><span style="font-size:16px; color:rgb(0,0,0); font-family:Calibri,Helvetica,sans-serif"><br>
</span></div>
</div>
<br>
<div class="x_gmail_quote">
<div dir="ltr">On Fri, Jun 22, 2018 at 9:34 AM Bassill, Nicholas <<a href="mailto:nbassill@albany.edu" id="LPlnk933040" class="OWAAutoLink" previewremoved="true">nbassill@albany.edu</a>> wrote:<br>
</div>
<blockquote class="x_gmail_quote" style="margin:0 0 0 .8ex; border-left:1px #ccc solid; padding-left:1ex">
<div dir="ltr">
<div id="x_m_-7169429113384083017divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:#000000; font-family:Calibri,Helvetica,sans-serif">
<p style="margin-top:0; margin-bottom:0">Hi All,</p>
<p style="margin-top:0; margin-bottom:0"> 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. </p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0">This often gives an error, as the documentation notes ("<span style="color:rgb(51,51,51); font-family:verdana,sans-serif; font-size:13.3333px">If neither type can be coerced to the other type, an error is returned</span>"). </p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0">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).</p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0">It'd be really nice/easy to be able to do something like:</p>
<p style="margin-top:0; margin-bottom:0">----------------</p>
<p style="margin-top:0; margin-bottom:0">; note: below two arrays have same size</p>
<p style="margin-top:0; margin-bottom:0">riskvalues = *series of random numbers for a variable, say precipitation in inches*</p>
<p style="margin-top:0; margin-bottom:0">riskwords = *series of words - begin with all equal to "None"*</p>
<p style="margin-top:0; margin-bottom:0">riskwords = where(riskvalues.gt.1,"High",<span style="font-family:Calibri,Helvetica,sans-serif,Helvetica,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols; font-size:16px">riskwords)
; assigns a high risk when precipitation is large</span></p>
<p style="margin-top:0; margin-bottom:0"><span style="font-family:Calibri,Helvetica,sans-serif,Helvetica,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols; font-size:16px">--------------</span></p>
<p style="margin-top:0; margin-bottom:0"><span style="font-family:Calibri,Helvetica,sans-serif,Helvetica,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols; font-size:16px">This will give an error because
you're returning a string, which can't be coerced to the number type you're evaluating. </span></p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0">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.</p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0">Thanks for any input!</p>
<p style="margin-top:0; margin-bottom:0"> - lazy coder</p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<div id="x_m_-7169429113384083017Signature">
<div id="x_m_-7169429113384083017divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:rgb(0,0,0); font-family:Calibri,Helvetica,sans-serif,Helvetica,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols">
<div id="x_m_-7169429113384083017divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:rgb(0,0,0); background-color:rgb(255,255,255); font-family:Calibri,Arial,Helvetica,sans-serif,Helvetica,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols">
<p><span style="color:rgb(0,0,0); font-family:Calibri,Arial,Helvetica,sans-serif; font-size:16px">Nick Bassill, PhD</span></p>
<p style="color:rgb(0,0,0); font-family:Calibri,Arial,Helvetica,sans-serif; font-size:16px">
Modeler & Meteorologist, Center Of Excellence (Prior: NYS Mesonet)</p>
<p style="color:rgb(0,0,0); font-family:Calibri,Arial,Helvetica,sans-serif; font-size:16px">
LC SB-28, 1400 Washington Ave.,</p>
<p style="color:rgb(0,0,0); font-family:Calibri,Arial,Helvetica,sans-serif; font-size:16px">
SUNY, University at Albany, NY 12222</p>
(518) 442-6375</div>
<div id="x_m_-7169429113384083017divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:rgb(0,0,0); background-color:rgb(255,255,255); font-family:Calibri,Arial,Helvetica,sans-serif,Helvetica,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols">
NYSM Products: <a href="http://operations.nysmesonet.org/~nbassill/" class="x_m_-7169429113384083017OWAAutoLink OWAAutoLink" id="LPlnk484084" target="_blank" previewremoved="true">http://operations.nysmesonet.org/~nbassill/</a></div>
</div>
</div>
</div>
</div>
_______________________________________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu" target="_blank" id="LPlnk871713" class="OWAAutoLink" previewremoved="true">ncl-talk@ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank" id="LPlnk149728" class="OWAAutoLink" previewremoved="true">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
</blockquote>
</div>
<br clear="all">
<div><br>
</div>
-- <br>
<div dir="ltr" class="x_gmail_signature">
<div dir="ltr">
<div>
<div dir="ltr">
<div>
<div dir="ltr">
<div>
<div dir="ltr">
<div>
<div>
<div><span><font color="#888888">Adam Phillips <br>
</font></span></div>
<span><font color="#888888">Associate Scientist, </font></span><span><font color="#888888">Climate and Global Dynamics Laboratory, NCAR<br>
</font></span></div>
</div>
<div><span><font color="#888888"><a href="http://www.cgd.ucar.edu/staff/asphilli/" target="_blank" id="LPlnk705542" class="OWAAutoLink" previewremoved="true">www.cgd.ucar.edu/staff/asphilli/</a>
</font></span><span><font color="#888888">303-497-1726 </font></span></div>
<span><font color="#888888"></font></span>
<div>
<div><span><font color="#888888"><br>
</font></span>
<div><span><font color="#888888"><a href="http://www.cgd.ucar.edu/staff/asphilli" target="_blank" id="LPlnk742136" class="OWAAutoLink" previewremoved="true"></a></font></span></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>