<div dir="ltr"><div>For those interested</div><div><br></div><div>I turned this script into a macro which you can add. It should work on a generic source containing a time in number of hourse since 0001-01-01</div><div><br></div><div>Regards</div><div><br></div><div><br></div><div>--- start macro python source code---</div><div>"""<br>A macro to turn a "hourse since 0001-01-01 00:00:00" floating number into a human readable data/time <br>string and put it as an annotion to the current view. <br>Requirement: a proper numpy/python/netcdf4 version in the search path. Current the search path is hard <br>added to the macro pointing to the location C://Apps/Anaconda/Anaconda2/envs/paraview/Lib/site-packages<br>At this location the netCDF4 module should be installed. Should be changed depending on current python installation<br>Eelco van Vliet<br>June 2017<br>"""<br>#### import the simple module from the paraview<br>from paraview.simple import *<br>#### disable automatic camera reset on 'Show'<br>paraview.simple._DisableFirstRenderCameraReset()</div><div># find source<br>source = GetActiveSource()</div><div># create a new 'Programmable Filter'<br>programmableFilter1 = ProgrammableFilter(Input=source)<br>programmableFilter1.RequestInformationScript = ''<br>programmableFilter1.RequestUpdateExtentScript = ''<br>programmableFilter1.PythonPath = ""</div><div># Properties modified on programmableFilter1<br>programmableFilter1.OutputDataSetType = 'vtkTable'<br>programmableFilter1.Script = '\<br>import sys\n\<br>sys.path.append("C://Apps/Anaconda/Anaconda2/envs/paraview/Lib/site-packages")\n\<br>import netCDF4 as nc\n\<br>t = inputs[0].GetInformation().Get(vtk.vtkDataObject.DATA_TIME_STEP())\n\<br>date_time = nc.num2date(t, units="hours since 0001-01-01 00:00:00", calendar="gregorian")\n\<br>outputarray = vtk.vtkStringArray()\n\<br>outputarray.SetName("datetime")\n\<br>outputarray.SetNumberOfTuples(1)\n\<br>outputarray.SetValue(0, "{}".format(date_time))\n\<br>print("{} -> {}".format(t, date_time))\n\<br>output.RowData.AddArray(outputarray)'</div><div># find view<br>renderView1 = GetActiveView()</div><div># create a new 'Python Annotation'<br>pythonAnnotation1 = PythonAnnotation(Input=programmableFilter1)</div><div># Properties modified on pythonAnnotation1<br>pythonAnnotation1.ArrayAssociation = 'Row Data'<br>pythonAnnotation1.Expression = '"{}".format(input.RowData["datetime"].GetValue(0))'</div><div># show data in view<br>pythonAnnotation1Display = Show(pythonAnnotation1, renderView1)</div><div># update the view to ensure updated data information<br>renderView1.Update()</div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-06-06 17:41 GMT+02:00 Eelco van Vliet <span dir="ltr"><<a href="mailto:eelcovv@gmail.com" target="_blank">eelcovv@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Dear Utkarsh, </div><div><br></div><div>After some more googling and your answer I found the solution. Indeed I have to store the data as a string in the Programmable Filter and then retrieve with GetValue in the Python Annoatation. </div><div>My ProgrammableFilter with Ouput set to vtkData is now</div><div><br></div><div><span><span style="color:rgb(0,128,0);font-family:"Courier New";font-weight:600">import</span><span style="font-family:"Courier New""> </span><span style="color:rgb(0,0,255);font-family:"Courier New";font-weight:600">sys</span>
<pre style="margin:0px;text-indent:0px"><span style="font-family:"Courier New"">sys</span><span style="color:rgb(102,102,102);font-family:"Courier New"">.</span><span style="font-family:"Courier New"">path</span><span style="color:rgb(102,102,102);font-family:"Courier New"">.</span><span style="font-family:"Courier New"">append(</span><span style="color:rgb(186,33,33);font-family:"Courier New"">"C://Apps/<wbr>Anaconda/Anaconda2/envs/<wbr>paraview/Lib/site-packages/"</span><span style="font-family:"Courier New"">)</span></pre>
<pre style="margin:0px;text-indent:0px"><span style="color:rgb(0,128,0);font-family:"Courier New";font-weight:600">import</span><span style="font-family:"Courier New""> </span><span style="color:rgb(0,0,255);font-family:"Courier New";font-weight:600">netCDF4</span><span style="font-family:"Courier New""> </span><span style="color:rgb(0,128,0);font-family:"Courier New";font-weight:600">as</span><span style="font-family:"Courier New""> </span><span style="color:rgb(0,0,255);font-family:"Courier New";font-weight:600">nc</span><span style="font-family:"Courier New""> </span></pre>
<pre style="margin:0px;text-indent:0px"><span style="font-family:"Courier New"">t </span><span style="color:rgb(102,102,102);font-family:"Courier New"">=</span><span style="font-family:"Courier New""> inputs[</span><span style="color:rgb(102,102,102);font-family:"Courier New"">0</span><span style="font-family:"Courier New"">]</span><span style="color:rgb(102,102,102);font-family:"Courier New"">.</span><span style="font-family:"Courier New"">GetInformation()</span><span style="color:rgb(102,102,102);font-family:"Courier New"">.</span><span style="font-family:"Courier New"">Get<wbr>(vtk</span><span style="color:rgb(102,102,102);font-family:"Courier New"">.</span><span style="font-family:"Courier New"">vtkDataObject</span><span style="color:rgb(102,102,102);font-family:"Courier New"">.</span><span style="font-family:"Courier New"">DATA_TIME_<wbr>STEP())</span></pre>
<pre style="margin:0px;text-indent:0px"><span style="font-family:"Courier New"">date_time </span><span style="color:rgb(102,102,102);font-family:"Courier New"">=</span><span style="font-family:"Courier New""> nc</span><span style="color:rgb(102,102,102);font-family:"Courier New"">.</span><span style="font-family:"Courier New"">num2date(t, units</span><span style="color:rgb(102,102,102);font-family:"Courier New"">=</span><span style="color:rgb(186,33,33);font-family:"Courier New"">"hours since 0001-01-01 00:00:00"</span><span style="font-family:"Courier New"">, calendar</span><span style="color:rgb(102,102,102);font-family:"Courier New"">=</span><span style="color:rgb(186,33,33);font-family:"Courier New"">"gregorian"</span><span style="font-family:"Courier New"">)</span></pre>
</span><pre style="margin:0px;text-indent:0px"><span style="font-family:"Courier New"">outputarray </span><span style="color:rgb(102,102,102);font-family:"Courier New"">=</span><span style="font-family:"Courier New""> vtk</span><span style="color:rgb(102,102,102);font-family:"Courier New"">.</span><span style="font-family:"Courier New"">vtkStringArray()</span></pre>
<pre style="margin:0px;text-indent:0px"><span style="font-family:"Courier New"">outputarray</span><span style="color:rgb(102,102,102);font-family:"Courier New"">.</span><span style="font-family:"Courier New"">SetName(</span><span style="color:rgb(186,33,33);font-family:"Courier New"">"datetime"</span><span style="font-family:"Courier New""><wbr>)</span></pre>
<pre style="margin:0px;text-indent:0px"><span style="font-family:"Courier New"">outputarray</span><span style="color:rgb(102,102,102);font-family:"Courier New"">.</span><span style="font-family:"Courier New"">SetNumberOfTuples(</span><span style="color:rgb(102,102,102);font-family:"Courier New""><wbr>1</span><span style="font-family:"Courier New"">)</span></pre>
<pre style="margin:0px;text-indent:0px"><span style="font-family:"Courier New"">outputarray</span><span style="color:rgb(102,102,102);font-family:"Courier New"">.</span><span style="font-family:"Courier New"">SetValue(</span><span style="color:rgb(102,102,102);font-family:"Courier New"">0</span><span style="font-family:"Courier New"">, </span><span style="color:rgb(186,33,33);font-family:"Courier New"">"{}"</span><span style="color:rgb(102,102,102);font-family:"Courier New"">.</span><span style="font-family:"Courier New"">format(date_time))</span></pre>
<pre style="margin:0px;text-indent:0px"><span style="color:rgb(0,128,0);font-family:"Courier New";font-weight:600">print</span><span style="font-family:"Courier New"">(</span><span style="color:rgb(186,33,33);font-family:"Courier New"">"{} -> {}"</span><span style="color:rgb(102,102,102);font-family:"Courier New"">.</span><span style="font-family:"Courier New"">format(t, date_time))</span></pre>
<pre style="margin:0px;text-indent:0px"><span style="font-family:"Courier New"">output</span><span style="color:rgb(102,102,102);font-family:"Courier New"">.</span><span style="font-family:"Courier New"">RowData</span><span style="color:rgb(102,102,102);font-family:"Courier New"">.</span><span style="font-family:"Courier New"">AddArray(<wbr>outputarray)</span></pre><pre style="margin:0px;text-indent:0px"><span style="font-family:"Courier New""><br></span></pre><pre style="margin:0px;text-indent:0px"><span style="font-family:"Courier New""><font face="arial,helvetica,sans-serif" size="2">and after that I add a PythonAnnotation with Row Data as Array Association and the following expression</font></span></pre><pre style="margin:0px;text-indent:0px"><span style="font-family:"Courier New""><font face="Arial"><br></font></span></pre><pre style="margin:0px;text-indent:0px"><span style="font-family:"Courier New""><font face="Arial">"{}".format(input.RowData["<wbr>datetime"].GetValue(0))</font></span></pre><pre style="margin:0px;text-indent:0px"><span style="font-family:"Courier New""><font face="Arial"><br></font></span></pre><pre style="margin:0px;text-indent:0px"><span style="font-family:"Courier New""><font face="arial,helvetica,sans-serif"><br></font></span></pre><pre style="margin:0px;text-indent:0px"><font face="arial,helvetica,sans-serif" size="4">It is not very trivial I must say, but the result is now that I can plot a date/time string in stead of a float with number of hourse since. Excellent! Thanks for your quick help</font></pre><pre style="margin:0px;text-indent:0px"><font face="Arial" size="4"><br></font></pre><pre style="margin:0px;text-indent:0px"><font face="Arial" size="4">Regards</font></pre><pre style="margin:0px;text-indent:0px"><font face="Arial" size="4">Eelco</font></pre><pre style="margin:0px;text-indent:0px"><font face="Arial" size="4"><br></font></pre><pre style="margin:0px;text-indent:0px"><font face="Arial" size="4">Ps: for those interessed in using netcdf4 with paraview: you have to make sure to get all the versions correct. I did this by using Anaconda and than create a special paraview environment</font></pre><pre style="margin:0px;text-indent:0px"><font face="Arial" size="4">conda create -n paraview python=2.7.3 netcdf4</font></pre><pre style="margin:0px;text-indent:0px"><font face="Arial" size="4">activate paraview</font></pre><pre style="margin:0px;text-indent:0px"><font face="Arial" size="4">conda install numpy=1.8.1</font></pre><pre style="margin:0px;text-indent:0px"><font face="Arial" size="4"><br></font></pre><pre style="margin:0px;text-indent:0px"><font face="Arial" size="4"><br></font></pre></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">2017-06-06 17:05 GMT+02:00 Utkarsh Ayachit <span dir="ltr"><<a href="mailto:utkarsh.ayachit@kitware.com" target="_blank">utkarsh.ayachit@kitware.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><div dir="ltr"><span style="color:rgb(186,33,33);font-family:"Courier New""><font color="#222222" face="Arial"><span style="font-family:"Courier New""><div><span style="font-family:Arial">Array Association: Row Data</span><br></div><div><font face="Arial">Expression: "{}".format(input.RowData) </font></div><div><font face="Arial">But this gives me just a reference to the row data, not the string of the date/time I just stored</font></div></span></font></span></div></blockquote><div><br></div></span><div>Try using `input.RowData["datatime"].Get<wbr>Value(0)` instead. String arrays are a little cumbersome currently. You have to use the vtkAbstractArray API (GetValue) to access elements.</div><span class="m_-946210703091517480HOEnZb"><font color="#888888"><div><br></div><div>Utkarsh</div><div><br></div><div><br></div></font></span></div></div></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>