When a ParaView state file is saved, it saves the absolute paths to the data files that ParaView has loaded. This has made sharing state files annoying since the person loading the state file has to tell ParaView where to look for each data file. Since sharing state files is something many people want to do, one of the most requested features for ParaView is to be able to load data from a path relative to the state file rather than an absolute path. We have added some new features to loading state files that will make sharing state files much easier.
When you load a state file, ParaView will now give broader options of where to look for the files as shown in this screenshot:
Use File Names From State just uses the file locations specified in the state file and errors if they are not found. This is useful if you are using a state file written out on the same computer.
Search files under specified directory looks for the data files in a specified directory. ParaView will parse out the filename of each file and look in the given directory to see if that filename exists. If the file exists it will be used, otherwise it will try the path in the state file. Since a common use case is sharing state files along with their data, the default directory used by this option is the location of the state file. Here is what the dialog looks like when using this option:
The Choose File Names option is the old default: manually specifying where each data file is located. This is still useful for running a pipeline on a different dataset than the one it was built with although we expect the other two to be more commonly used. This option has been improved with the ability to specify environment variables as a part of the filename as shown here:
Unlike the old load state file mechanism these options can also be specified from the Python API. Use the python trace to find the options needed for a given state file. Here is an example of loading state in a python script that loads a state and uses the Search files under specified directory option. This was created by using Python Trace while loading the state file used to create the above screenshots, so you can compare the options passed to LoadState to the options in the screenshots above.
# load state LoadState('/home/shawn/data/pvsm/exampleStateFile.pvsm', LoadStateDataFileOptions='Search files under specified directory', DataDirectory='/home/shawn/data/pvsm', SMALL_PtCu_NanoParticletifFileNames=['/home/shawn/data/tem/SMALL_PtCu_NanoParticle.tif'], ringeFileName=['/home/shawn/data/pvsm/ring.e'], sFilePattern='%s', ringeFilePrefix='/home/shawn/data/pvsm/ring.e', InvalidresultXMLFileName='Invalid result')
These changes are merged into ParaView master and are available in the ParaView 5.4-RC1 binaries which can be obtained here.
Additional details about these options are available in the ParaView Guide in the chapter named Saving Results.
6 comments to New Options when Loading ParaView State Files
thank you for your effort on the topic. I have been struggeling a lot with adjusting the paths in state files when reusing them for different simulations. My current workflow is:
1. Create a state in Paraview on Windows
2. When the simulation is done:
2.1 Use a search/replace script on Linux cluster to replace Windows paths with Linux paths
2.2 Run pvpython on Linux to load the state and save Animations
3. Run another simulation
3.1 copy state to new location
3.2 Use script (from 2.1) to update all the paths for the local case
3.3 Run pvpython on Linux to load the state and save Animations
My script kind of behaves like “Search files under specified directory”. However “If the file exists it will be used, otherwise it will try the path in the state file.” sometimes led to making videos with the wrong data source and I only noticed some time later. Now I adjust all the paths and prefer getting errors if the file does not exist, instead of accidentially using the file from the previous case. (Sometimes the new case does not have all the sources the original case had for which I made the state template.)
For me the perfect behaviour would be:
– tick a “use relative paths” checkbox when saving the state file, making all paths relative to the current directory the state file is located when being loaded.
– relative paths are accepted when the state is loaded in pvpython and also accepting both “/” and “\” paths separators, regardless of which operating system was used when creating the state file.
Maybe you can add such a behaviour to the upcoming version?
I added a new option for you that behaves like your script. Search files under specified directory now has a checkbox called ‘Only Use Files In Data Directory’ that makes it fail if the file is not found in the directory you specified rather than defaulting to the path in the state file. This change was just merged and will be in 5.4 RC2. Relative paths in state files is a bigger piece of work and will have to wait for a future release. But we are hoping that these changes will remove most of the need for it.
Thank you for the feedback,
I am looking forward to test it once the next version is released.
Thank you for adding this feature.
I have a state file that loads two .pvtp files in split-screen to compare results.
In 5.4, using the “Choose File Names” option, changing the name of one input file automatically updates the second file name to match the first, whereas I need two new paths for comparison. The feature works as I expected in 5.2. Is this a bug in the new release, or can I expect the current functionality to remain?
That sounds like a bug to me. Can you make a bug report over on the bug tracker? (https://gitlab.kitware.com/paraview/paraview/issues) Please include an example state file that demonstrates the problem.
In 4.5.1 when changing the file names in the Load State Options my changes are not applied. I have one State which I want to use for two CSV data series. I have created the state for one of the data series but when changing the file names to the other data series in the Load State Options the default data series is loaded.