I have a question about the best way to load a large number of time series .pvtu files into paraview using a python script.
My files are of the format:
data_0.pvtu
data_1.pvtu…
There are 200 of them in this particular situation.
I used the python trace tool to capture the events as I selected the series in the interface. In the gui it is as simple as just selecting the “data…pvtu” series. I was surprised that in the python trace each individual file was specified:
Thank you, I think that is definitely a great approach to start with.
The python docs state that glob returns value in an arbitrary order. On my system the certainly don’t seem to be ordered how you would expect - the resulting list is neither in alpha order nor sequential order. So it’s not useful directly for forming a time series. But glob does return a list, and that list can then be sorted prior to feeding to XMLPartitionedUnstructuredGridReader()
Just a final followup in case anybody else has a similar need:
Ned Bachelder has a blog which explains a nifty “natural sorting” method that works very well for this particular problem. It seems to work very well in sorting strings of the form (alpha)_(number) in to the order that you would expect them to be. Below is a link to his blog as well as the code:
import re
def tryint(s):
try:
return int(s)
except ValueError:
return s
def alphanum_key(s):
""" Turn a string into a list of string and number chunks.
"z23a" -> ["z", 23, "a"]
"""
return [ tryint(c) for c in re.split('([0-9]+)', s) ]
def sort_nicely(l):
""" Sort the given list in the way that humans expect.
"""
l.sort(key=alphanum_key)
For my code I assigned the glob statement to a variable called file_list: