Skip to content

Paraview: H5 to Vtk

Maria Okounkova edited this page Jul 18, 2022 · 1 revision

Turning H5 Files into Vtk Files

Both ParaView and VisIt (an alternative visualization software) understand the data-format of the Visualization Toolkit (VTK). In VTK, each timestep at subdomain is represented by one file. Such a file contains both the geometry information (i.e. coordinates), as well as an arbitrary number of datasets. Since these are typically many files, we place them all into a subdirectory, say Data/. The subdirectory name (Data in this example) is referred to as the "Basename". There are also index-files which tell ParaView and VisIt which of the files in Data/ belong to each timestep. The index files are different for VisIt and ParaView, and are called Data.visit (for visit) and Data.pvd (for ParaView). Data.visit and Data.pvd must have a certain structure which makes it impossible to append to these files. Therefore, the conversion routines below require that these files do not exist when they start. H5 files offer an advantage over the former .dump format, as all of the data necessary for the .vtk files is stored within one or two H5 files, in a single directory.

Surface Data

Currently, we are equipped to process surfaces, spins, and trajectories. This task is accomplished by ConvertH5SurfacetoVtk, which is located in /SpEC/Support/H5Manip/. Since the H5 files of interest should always be in a single directory, it is unnecessary to make a distinction between single- and multi-directory data.

Processing Horizon Data

If you only wish to acquire surface data from an H5 file, the process is quite easy. Once you are in the directory of your H5 files, run the following command to determine the location of the black hole surface data:

/<SpEC Home>/Support/H5Manip/H5list <H5 file name>.h5

Typically, the H5 file of interest will have several .tdm files within it, named according to the scalar surface data that they represent. For example, a surface H5 file may contain files called "RicciScalar.tdm", "WeylB_NN.tdm", or "SpinFunction.tdm", among others. Once you are certain of the location of the surface data (since H5 files typically come in pairs), run the following command in the directory to convert the raw data into .vtk files:

/<SpEC Home>/Support/H5Manip/ConvertH5SurfaceToVtk <H5 surface file name>.h5

Please note that several additions must be made to your PATH in ~/.bashrc for this to run properly. Please see the code's documentation for further details about paths, options, and arguments.

Running the above command should produce AhX.pvd files in your current directory, which can be converted to images with ParaviewPythonScript.py. You can check that your .pvd files are in the following format once ConvertH5SurfacetoVtk has finished running:

<?xml version="1.0"?>
<VTKFile type="Collection" version="0.1" byte_order="LittleEndian" compressor="\
vtkZLibDataCompressor">
  <Collection>
    <DataSet timestep="0" file="InBlackHole/data0.vtu" />
    <DataSet timestep="0.5" file="InBlackHole/data1.vtu" />
    <DataSet timestep="1" file="InBlackHole/data2.vtu" />
    .
    .
    .
    <DataSet timestep="756" file="MergerBlackHole/data912.vtu" />
    <DataSet timestep="756.5" file="MergerBlackHole/data913.vtu" />
    <DataSet timestep="757" file="MergerBlackHole/data914.vtu" />
  </Collection>
</VTKFile>

NOTE: If you view these objects in the ParaView GUI, then if you have an AhC, it will be displayed for the entire inspiral. To fix this, you will need to open the Animation View, then change the AhC.pvd visibility to a Step from 0->1 at the common horizon time.

NOTE: SpEC outputs compressed h5 files, which must be uncompressed upon reading them. For a recent ConvertH5SurfaceToVtk call operating on HorizonsDump.h5, the speed-difference was a factor of ~1000: Days vs. minutes. The speed-up could be realized by uncompressing the h5 file first using:

h5repack -f NONE HorizonsDump.h5 HorizonsDump_uncompressed.h5

Spin and Trajectory Data

Trajectory data can be converted to VTK format using commands similar to

ConvertH5TrajectoryToVtk Horizons.h5 /AhA.dir/CoordCenterInertial.dat AhA_Traj

Spin data along the trajectory can be converted to VTK using

ConvertH5VectorToVtk -trajectory /AhA.dir/CoordCenterInertial.dat Horizons.h5 /AhA.dir/chiInertial.dat AhA_Spin

The spin vectors can be drawn using the "Glyph" filter in Paraview.

Slice through Volume Data

H5 files containing volume data can be converted to vtk files representing a slice through the data. This is done through the Interpolate2DSliceToVtk observer and the ApplyObservers script.

To set this up, ensure that all the H5 files are in the same directory along with any necessary input files (particularly Domain.input) and history text files. These will generally be output by your simulation as needed. Next, the ApplyObservers script will require an input file itself, which can specify domain and data information among other things. What is necessary for the input file, however, is a list of observers you wish to use. For this task the aforementioned Interpolate2DSliceToVtk is required. Thus your input file must contain the following:

Observers =
  Interpolate2DSliceToVtk(
    Input = [name of input variable];
    Coords = [coordinates to use];
    Basename = [directory to save output in];
    Origin = [origin representing centre of slice];
    NormalVec = [normal vector of plane to slice];
    NumOfPointsPerM = [density of points];
    Size = [size of plane];
    TopologicalInterpolator = [interpolator to use];
  );

There are two optional parameters which will change the behaviour of the observer. By default, NumOfPointsPerM is the number of points per unit distance and Size is the number of points in each direction. However, providing an optional SizeInCoords = true will tell the observer to interpret Size as the number of coordinates in each direction. Additionally, a spatial coordinate map can optionally be provided with the SpatialCoordMap parameter. This is useful if, for example, you wish to interpolate Inspiral BHNS data to an inertial frame as opposed to the often default co-moving frame.

To use the observer, navigate to the folder containing the data and input file and run the following command (assuming the input file you've created is named Vis.input):

ApplyObservers -t [input variable, e.g. Rho0Phys] -r [type of variable, e.g. Scalar] -d [dimensions, presumably 3] -domaininput Domain.input Vis.input

This should produce vtk files and a corresponding pvd file within a directory named after the Basename you provided. These can then be visualized in Paraview to see the slice through all the data's timesteps. To output a single timestep you can use the -Steps option to specify how many timesteps you want ApplyObservers to process. Alternatively, -f and -l specify the first and last timestep, respectively, and "-s n" will tell ApplyObservers to output every nth timestep.

Clone this wiki locally