<div dir="ltr"><div>Dear all, </div><div><br></div><div>I have a question on how to convert a time in hours since <span style="color:rgb(186,33,33);font-family:"Courier New""> 0001-01-01 00:00:00 <font color="#222222" face="Arial">to a normal date time string. In Python a routine is avaiable in the netCDF4 library, so I thought I used that. </font></span></div><div><span style="color:rgb(186,33,33);font-family:"Courier New""><font color="#222222" face="Arial"><br></font></span></div><div><span style="color:rgb(186,33,33);font-family:"Courier New""><font color="#222222" face="Arial">I want to use PythonAnnotate eventually to plot the date time. So know I have to following steps in my pipeline browser</font></span></div><div><span style="color:rgb(186,33,33);font-family:"Courier New""><font color="#222222" face="Arial"><br></font></span></div><div><span style="color:rgb(186,33,33);font-family:"Courier New""><font color="#222222" face="Arial">1: load a netcdf4 file with a Lat/Lon spherical coordinates and a time in as a float giving the number of hourse since 0001</font></span></div><div><span style="color:rgb(186,33,33);font-family:"Courier New""><font color="#222222" face="Arial"><br></font></span></div><div><span style="color:rgb(186,33,33);font-family:"Courier New""><font color="#222222" face="Arial">2 A ProgrammableFilter with the following settings</font></span></div><div><span style="color:rgb(186,33,33);font-family:"Courier New""><font color="#222222" face="Arial"><br></font></span></div><div><span style="color:rgb(186,33,33);font-family:"Courier New""><font color="#222222" face="Arial">Output Data Set Type: vtkTable</font></span></div><div><span style="color:rgb(186,33,33);font-family:"Courier New""><font color="#222222" face="Arial"><br></font></span></div><div>Script:</div><div><br></div><div><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/Anaconda/Anaconda2/envs/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(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_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>
<pre style="margin:0px 0px 12px;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"">append(date_time, </span><span style="color:rgb(186,33,33);font-family:"Courier New"">"datetime"</span><span style="font-family:"Courier New"">)</span></pre><pre style="margin:0px 0px 12px;text-indent:0px"><span style="font-family:"Courier New""><font face="arial,helvetica,sans-serif"></font></span><br></pre></div><span style="color:rgb(186,33,33);font-family:"Courier New""><font color="#222222" face="Arial"><span style="font-family:"Courier New""><div><font face="Arial">This all works. If I create a print statement in the script I see that the time is indeed correctly converted to a date/time string, eg. 17671944.0 is now 2017-01-01-00:00:00</font></div><div><font face="Arial"></font><font face="Arial"><br></font></div><div><font face="Arial">The point is: I want to store this resulting datatime value into a vtkTable so that I can use it to plot it to the screen using the Python annotation (which I do with the RowData.append line)</font></div><div><font face="Arial"><br></font></div><div><font face="Arial">In the python annotation, however, I cannot get the value for datatime rom the RowDATa</font></div><div><font face="Arial"><br></font></div><div><font face="Arial">I now have for the pythonannotation expression the following</font></div><div><font face="Arial"></font><br></div><div><font face="Arial">Array Association: Row Data</font></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><div><font face="Arial"></font><br></div><div><font face="Arial">My question is:</font></div><div><font face="Arial">1) How can I get the rowdata which I stored in the ProgrammableFilter in the vtkTable</font></div><div><font face="Arial">2) Is there a better way to do this: convert a float into a date/time string which you can print</font></div><div><font face="Arial"></font><br></div><div><font face="Arial">Hopefully anybody can give me a hint</font></div><div><br></div></span></font></span></div>