[Paraview] Annotate time as data/time using pythonannotation and programmablefilter
Eelco van Vliet
eelcovv at gmail.com
Tue Jun 6 11:41:33 EDT 2017
Dear Utkarsh,
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.
My ProgrammableFilter with Ouput set to vtkData is now
import sys
sys.path.append("C://Apps/Anaconda/Anaconda2/envs/paraview/Lib/site-packages/")
import netCDF4 as nc
t = inputs[0].GetInformation().Get(vtk.vtkDataObject.DATA_TIME_STEP())
date_time = nc.num2date(t, units="hours since 0001-01-01 00:00:00",
calendar="gregorian")
outputarray = vtk.vtkStringArray()
outputarray.SetName("datetime")
outputarray.SetNumberOfTuples(1)
outputarray.SetValue(0, "{}".format(date_time))
print("{} -> {}".format(t, date_time))
output.RowData.AddArray(outputarray)
and after that I add a PythonAnnotation with Row Data as Array
Association and the following expression
"{}".format(input.RowData["datetime"].GetValue(0))
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
Regards
Eelco
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
conda create -n paraview python=2.7.3 netcdf4
activate paraview
conda install numpy=1.8.1
2017-06-06 17:05 GMT+02:00 Utkarsh Ayachit <utkarsh.ayachit at kitware.com>:
> Array Association: Row Data
>> Expression: "{}".format(input.RowData)
>> But this gives me just a reference to the row data, not the string of the
>> date/time I just stored
>>
>
> Try using `input.RowData["datatime"].GetValue(0)` instead. String arrays
> are a little cumbersome currently. You have to use the vtkAbstractArray API
> (GetValue) to access elements.
>
> Utkarsh
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/paraview/attachments/20170606/a470ab87/attachment.html>
More information about the ParaView
mailing list