This problem is this:
- I have a volumetric time series in netCDF format that has a time index with actual time values
- I have vtk files generated for each of these netCDF files that I need to sync in time with their associated netCDF files.
- As is well known, vtk files don’t have a time index. And, yes, I do want to keep these in vtk format and not change to another one (for a variety of reasons).
So I wrote a programmable plugin to take care of the indexing within Paraview. It is tantalizingly close, but I can’t seem to get it to work yet.
Here is a description of where I am so far. And just FYI, I’m not actually using the pvsm file. I was just using it was a guide to understand what Paraview is doing, to get the names of the relevant structures, etc. and to show the printout below. But everything is being done in the python programmable filter.
All our generated netCDF results have a set of time variables that are the same (eg, [2102, 2122, 2142, …. ] so no matter how many netCDF files I load, they are always perfectly synced in time.
Separate VTK files are generated at each time points. Each VTK file has a name that includes the correct time so there is never confusion (ie, vtk_result-2102.vtk, vtk_results-2122.vtk, ….]
The problem is that vtk files don’t have a time variable that can be written into the file. However, they ARE assigned a timestepvalue in Paraview that by default is set to the index value, ie
For the netcdf state files, this looks like
<Property name="TimestepValues" id="10329.TimestepValues" number_of_elements="195"> <Element index="0" value=“2102"/> <Element index="1" value=“2120”/>
So, I figured that if I just change the TimeStepValues in the VTK files to those of the netCDF files using a Programmable Filter, that should do what I want.
In fact, this does work - sort of. But it seems to break in two distinct ways.
Here is the programmable filter:
executive = self.GetExecutive()
inInfo = executive.GetInputInformation(0).GetInformationObject(0)
inTimeSteps = inInfo.Get(executive.TIME_STEPS())
print(’\n *** old time steps:’)
# Define time steps here if getTimesFromFiles: newTimeSteps = get_times() print('\n *** new time steps:') print(newTimeSteps) print('ntimes = %i'%len(newTimeSteps)) else: newTimeSteps = [x * 2 for x in inTimeSteps] outInfo = executive.GetOutputInformation().GetInformationObject(0) outInfo.Remove(executive.TIME_STEPS()) timeCount = 0 for timestep in newTimeSteps: outInfo.Append(executive.TIME_STEPS(), newTimeSteps[timeCount]) timeCount += 1 outInfo.Remove(executive.TIME_RANGE()) outInfo.Append(executive.TIME_RANGE(), newTimeSteps) outInfo.Append(executive.TIME_RANGE(), newTimeSteps[-1]) outTimeSteps = outInfo.Get(executive.TIME_STEPS()) print('\n outTimeSteps = ') print(outTimeSteps) outInfo.Set(executive.UPDATE_TIME_STEP())
if name == “main”:
I broke this down into two different stages -
getTimesFromFiles = 0: I defined new times (newTimeSteps) by just making up values to test if I could change the TimeSteps. This seems to work. The VTK files now step through times 0,2,4,6, with indices 1,2,3,4,… However, this change doesn’t seem to stick. When I make a change to the filter then reload it, the time values go back to being identical with the indices (0,1,2,3). But at least in all cases that data does advance with each time step, so in this sense I can at least get it to work some of the time.
getTimesFromFiles = 1: Here I generated the correct list of time steps directly from the file names, which is ultimately what I want. (This took a long time to figure out!):
import paraview.servermanager as sm
times =  for aProxy in sm.ProxyManager().GetProxiesInGroup("sources").values(): print(aProxy) print('filenames = ') filenames = aProxy.GetProperty("FileNames") if (filenames != None): #print(filenames) file_count = 0 newTimeSteps =  for filename in filenames: print('file %i = %s'%(file_count,filename)) file_count += 1 time_idx = filename.find('.vtk') - 5 this_time = filename[time_idx:time_idx+5] #print('time=%s'%this_time) times.append(int(this_time)) return times
This returns a list of time steps (newTimeSteps) in exactly the same place in the code as the method in 1, and in fact does change the TimeStep values correctly, but for some reason the data no longer advances when I change the time index in Paraview.
I have no idea why this should be different, but it is for some reason.
So it seems like I’m close. I can change the TimeStep values for the vtk files (sometimes, and with an artificially generated list), and I can create the actual list of times I want and assign them to the time increments which Paraview can see, but the data doesn’t advance.
Any thoughts/advice would be most helpful.
Thanks again for your help.