<HTML>
<HEAD>
<TITLE>Re: [Paraview] nan</TITLE>
</HEAD>
<BODY>
<FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>I would agree that this is a bug. The “Replace invalid results” was added because the calculator would spout out a bunch of errors when you have an expression that, for example, took the log of a negative number for some of the elements. This was before we considered NANs and just wanted some sane fallback. It makes sense that this option should apply to any result that is a non-finite number (of which NAN qualifies). There are lots of use cases (yours included) where it is convenient to represent “invalid” entries with some placeholder number. That said, when this option is not checked it also makes sense to output the correct non-finite number (NAN, +/-INF) as appropriate rather than report an error.<BR>
<BR>
-Ken<BR>
<BR>
<BR>
On 8/20/10 1:12 PM, "Scott, W Alan" <<a href="wascott@sandia.gov">wascott@sandia.gov</a>> wrote:<BR>
<BR>
</SPAN></FONT><BLOCKQUOTE><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>Question – shouldn’t the calculator be able to handle this? When you have “Replace invalid results” checked, shouldn’t that change NANs to 0’s?<BR>
<BR>
Is this a bug – and should I write up a bug report?<BR>
<BR>
Thanks,<BR>
<BR>
Alan<BR>
<BR>
<BR>
</SPAN><FONT SIZE="2"><SPAN STYLE='font-size:10pt'><B>From:</B> <a href="paraview-bounces@paraview.org">paraview-bounces@paraview.org</a> [<a href="mailto:paraview-bounces@paraview.org">mailto:paraview-bounces@paraview.org</a>] <B>On Behalf Of </B>Scott, W Alan<BR>
<B>Sent:</B> Friday, August 20, 2010 11:13 AM<BR>
<B>To:</B> 'Eric E. Monson'<BR>
<B>Cc:</B> <a href="'paraview@paraview.org">'paraview@paraview.org</a> list'<BR>
<B>Subject:</B> Re: [Paraview] nan<BR>
</SPAN></FONT></FONT><FONT FACE="Times New Roman"><SPAN STYLE='font-size:12pt'> <BR>
</SPAN></FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>Thanks all! I believe we have found numerous solutions.<BR>
<BR>
Alan<BR>
<BR>
<BR>
</SPAN><FONT SIZE="2"><SPAN STYLE='font-size:10pt'><B>From:</B> Eric E. Monson [<a href="mailto:emonson@cs.duke.edu">mailto:emonson@cs.duke.edu</a>] <BR>
<B>Sent:</B> Friday, August 20, 2010 9:26 AM<BR>
<B>To:</B> Scott, W Alan<BR>
<B>Cc:</B> David E DeMarle; Aurélien Marsan; <a href="paraview@paraview.org">paraview@paraview.org</a> list<BR>
<B>Subject:</B> Re: [Paraview] nan<BR>
</SPAN></FONT></FONT><FONT FACE="Times New Roman"><SPAN STYLE='font-size:12pt'> <BR>
If you can use numpy, and you're using a recent-enough version of ParaView, then you can also use the super-spiffy-numpy-hidden-behind-the-scenes programmable filter API to replace all of the attribute arrays with zero'd versions:<BR>
</SPAN></FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
</SPAN></FONT><FONT FACE="Times New Roman"><SPAN STYLE='font-size:12pt'> <BR>
</SPAN></FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
</SPAN></FONT><FONT FACE="Times New Roman"><SPAN STYLE='font-size:12pt'>pdi = self.GetInputDataObject(0,0)<BR>
</SPAN></FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
</SPAN></FONT><FONT FACE="Times New Roman"><SPAN STYLE='font-size:12pt'>pdo = self.GetOutputDataObject(0)<BR>
</SPAN></FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
</SPAN></FONT><FONT FACE="Times New Roman"><SPAN STYLE='font-size:12pt'>pdo.CopyStructure(pdi)<BR>
</SPAN></FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
</SPAN></FONT><FONT FACE="Times New Roman"><SPAN STYLE='font-size:12pt'> <BR>
</SPAN></FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
</SPAN></FONT><FONT FACE="Times New Roman"><SPAN STYLE='font-size:12pt'>for att_name in inputs[0].PointData.keys():<BR>
</SPAN></FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
</SPAN></FONT><FONT FACE="Times New Roman"><SPAN STYLE='font-size:12pt'> naninc = inputs[0].PointData[att_name]<BR>
</SPAN></FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
</SPAN></FONT><FONT FACE="Times New Roman"><SPAN STYLE='font-size:12pt'> zerod = numpy.nan_to_num(naninc)<BR>
</SPAN></FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
</SPAN></FONT><FONT FACE="Times New Roman"><SPAN STYLE='font-size:12pt'> output.PointData.append(zerod, att_name)<BR>
</SPAN></FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
</SPAN></FONT><FONT FACE="Times New Roman"><SPAN STYLE='font-size:12pt'> <BR>
</SPAN></FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
</SPAN></FONT><FONT FACE="Times New Roman"><SPAN STYLE='font-size:12pt'>Talk to you later,<BR>
</SPAN></FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
</SPAN></FONT><FONT FACE="Times New Roman"><SPAN STYLE='font-size:12pt'>-Eric<BR>
</SPAN></FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
</SPAN></FONT><FONT FACE="Times New Roman"><SPAN STYLE='font-size:12pt'> <BR>
</SPAN></FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
</SPAN><FONT SIZE="1"><SPAN STYLE='font-size:9pt'>------------------------------------------------------<BR>
</SPAN></FONT><SPAN STYLE='font-size:11pt'><BR>
</SPAN><FONT SIZE="1"><SPAN STYLE='font-size:9pt'>Eric E Monson<BR>
</SPAN></FONT><SPAN STYLE='font-size:11pt'><BR>
</SPAN><FONT SIZE="1"><SPAN STYLE='font-size:9pt'>Duke Visualization Technology Group<BR>
</SPAN></FONT><SPAN STYLE='font-size:11pt'><BR>
</SPAN><FONT SIZE="1"><SPAN STYLE='font-size:9pt'> <BR>
</SPAN></FONT></FONT><FONT FACE="Times New Roman"><SPAN STYLE='font-size:12pt'> <BR>
</SPAN></FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
</SPAN></FONT><FONT FACE="Times New Roman"><SPAN STYLE='font-size:12pt'>On Aug 20, 2010, at 10:00 AM, Aurélien Marsan wrote:<BR>
<BR>
Hi, <BR>
<BR>
If you're using python, and if you can use the numpy library, you can use the function numpy.nan_to_num too. <BR>
<a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.nan_to_num.html#numpy.nan_to_num">http://docs.scipy.org/doc/numpy/reference/generated/numpy.nan_to_num.html#numpy.nan_to_num</a><BR>
<BR>
Regards, <BR>
<BR>
Aurélien<BR>
</SPAN></FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
</SPAN></FONT><FONT FACE="Times New Roman"><SPAN STYLE='font-size:12pt'>2010/8/20 David E DeMarle <<a href="dave.demarle@kitware.com">dave.demarle@kitware.com</a>><BR>
That said, the same trick may work in the standard calculator filter<BR>
with the expression:<BR>
<BR>
if(val=val, val, 0.0)<BR>
</SPAN></FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
</SPAN></FONT><FONT FACE="Times New Roman"><SPAN STYLE='font-size:12pt'><BR>
David E DeMarle<BR>
Kitware, Inc.<BR>
R&D Engineer<BR>
28 Corporate Drive<BR>
Clifton Park, NY 12065-8662<BR>
Phone: 518-371-3971 x109<BR>
<BR>
On Fri, Aug 20, 2010 at 9:26 AM, David E DeMarle<BR>
<<a href="dave.demarle@kitware.com">dave.demarle@kitware.com</a>> wrote:<BR>
> You might write a python filter that iterates over all floating point arrays and<BR>
> replaces nan's with 0.<BR>
><BR>
> According to <a href="http://stackoverflow.com/questions/944700/how-to-check-for-nan-in-python">http://stackoverflow.com/questions/944700/how-to-check-for-nan-in-python</a><BR>
> The most py version robust way to check for nan is:<BR>
><BR>
> def isNaN(num):<BR>
> return num != num<BR>
><BR>
> David E DeMarle<BR>
> Kitware, Inc.<BR>
> R&D Engineer<BR>
> 28 Corporate Drive<BR>
> Clifton Park, NY 12065-8662<BR>
> Phone: 518-371-3971 x109<BR>
><BR>
><BR>
><BR>
> On Thu, Aug 19, 2010 at 11:24 PM, Moreland, Kenneth <<a href="kmorel@sandia.gov">kmorel@sandia.gov</a>> wrote:<BR>
>> This might not be the best solution, but you can use the threshold filter to<BR>
>> remove NANs. A NAN will always fall outside the threshold range.<BR>
>><BR>
>> -Ken<BR>
>><BR>
>><BR>
>> On 8/19/10 6:28 PM, "Scott, W Alan" <<a href="wascott@sandia.gov">wascott@sandia.gov</a>> wrote:<BR>
>><BR>
>> Is there a way to convert nan’s to zeros in ParaView? I have a user that is<BR>
>> trying to use the integrate data filter, and it is having troubles with<BR>
>> NANs.<BR>
>><BR>
>> Thanks,<BR>
>><BR>
>> Alan<BR>
>><BR>
>><BR>
>><BR>
>><BR>
>><BR>
>> _______________________________________________<BR>
>> Powered by www.kitware.com <<a href="http://www.kitware.com/">http://www.kitware.com/</a>> <BR>
>><BR>
>> Visit other Kitware open-source projects at<BR>
>> <a href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a><BR>
>><BR>
>> Please keep messages on-topic and check the ParaView Wiki at:<BR>
>> <a href="http://paraview.org/Wiki/ParaView">http://paraview.org/Wiki/ParaView</a><BR>
>><BR>
>> Follow this link to subscribe/unsubscribe:<BR>
>> <a href="http://www.paraview.org/mailman/listinfo/paraview">http://www.paraview.org/mailman/listinfo/paraview</a><BR>
>><BR>
>><BR>
><BR>
_______________________________________________<BR>
Powered by www.kitware.com <<a href="http://www.kitware.com/">http://www.kitware.com/</a>> <BR>
<BR>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a><BR>
<BR>
Please keep messages on-topic and check the ParaView Wiki at: <a href="http://paraview.org/Wiki/ParaView">http://paraview.org/Wiki/ParaView</a><BR>
<BR>
Follow this link to subscribe/unsubscribe:<BR>
<a href="http://www.paraview.org/mailman/listinfo/paraview">http://www.paraview.org/mailman/listinfo/paraview</a><BR>
<BR>
_______________________________________________<BR>
Powered by www.kitware.com <<a href="http://www.kitware.com">http://www.kitware.com</a>> <BR>
<BR>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a><BR>
<BR>
Please keep messages on-topic and check the ParaView Wiki at: <a href="http://paraview.org/Wiki/ParaView">http://paraview.org/Wiki/ParaView</a><BR>
<BR>
Follow this link to subscribe/unsubscribe:<BR>
<a href="http://www.paraview.org/mailman/listinfo/paraview">http://www.paraview.org/mailman/listinfo/paraview</a><BR>
<BR>
</SPAN></FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
</SPAN></FONT></BLOCKQUOTE><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
</SPAN></FONT><FONT SIZE="2"><FONT FACE="Consolas, Courier New, Courier"><SPAN STYLE='font-size:10pt'><BR>
**** Kenneth Moreland<BR>
*** Sandia National Laboratories<BR>
*********** <BR>
*** *** *** email: <a href="kmorel@sandia.gov">kmorel@sandia.gov</a><BR>
** *** ** phone: (505) 844-8919<BR>
*** web: <a href="http://www.cs.unm.edu/~kmorel">http://www.cs.unm.edu/~kmorel</a><BR>
</SPAN></FONT></FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
</SPAN></FONT>
</BODY>
</HTML>