Visualizing pointclouds

If you have interpolated pointclouds into hdf5 files, it is easy to visualize them if you convert them to vtk. Here we show how to do that.

Import general modules

[1]:
# Import required modules
from mpi4py import MPI #equivalent to the use of MPI_init() in C
import matplotlib.pyplot as plt
import numpy as np

# Get mpi info
comm = MPI.COMM_WORLD

convert the hdf5 pointclouds

Read the data and write it back as vtk

[2]:
import h5py
from pyevtk.hl import gridToVTK


mesh_fname = "coordinates_interpolated_fields.hdf5"
with h5py.File(mesh_fname, 'r') as f:
    x = f["x"][:]
    y = f["y"][:]
    z = f["z"][:]

for i in range(0, 49):
    field_fname = "interpolated_fields" + str(i+1).zfill(5) + ".hdf5"

    with h5py.File(field_fname, 'r') as f:

        # Read the data and put it in a dictionary
        field_dict = {}
        for key in f.keys():
            field_dict[key] = f[key][:]

    # write to vtk
    gridToVTK( "interpolated_field"+str(i).zfill(5),  x, y, z, pointData=field_dict)