{ "cells": [ { "cell_type": "markdown", "id": "31a94bbd-34ef-404b-a9be-4f3a216a8c3c", "metadata": {}, "source": [ "# Visualizing pointclouds\n", "\n", "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." ] }, { "cell_type": "markdown", "id": "f9ad6337-6ba4-47c7-b687-0bf119a5b637", "metadata": {}, "source": [ "#### Import general modules" ] }, { "cell_type": "code", "execution_count": 1, "id": "8b4ca2be-46e8-443b-ab44-6d1a60abfec4", "metadata": {}, "outputs": [], "source": [ "# Import required modules\n", "from mpi4py import MPI #equivalent to the use of MPI_init() in C\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "\n", "# Get mpi info\n", "comm = MPI.COMM_WORLD" ] }, { "cell_type": "markdown", "id": "ae925826", "metadata": {}, "source": [ "## convert the hdf5 pointclouds\n", "\n", "Read the data and write it back as vtk" ] }, { "cell_type": "code", "execution_count": 2, "id": "ac2a48b2", "metadata": {}, "outputs": [], "source": [ "import h5py\n", "from pyevtk.hl import gridToVTK\n", "\n", "\n", "mesh_fname = \"coordinates_interpolated_fields.hdf5\"\n", "with h5py.File(mesh_fname, 'r') as f:\n", " x = f[\"x\"][:]\n", " y = f[\"y\"][:]\n", " z = f[\"z\"][:]\n", "\n", "for i in range(0, 49):\n", " field_fname = \"interpolated_fields\" + str(i+1).zfill(5) + \".hdf5\"\n", "\n", " with h5py.File(field_fname, 'r') as f:\n", "\n", " # Read the data and put it in a dictionary\n", " field_dict = {} \n", " for key in f.keys():\n", " field_dict[key] = f[key][:] \n", "\n", " # write to vtk\n", " gridToVTK( \"interpolated_field\"+str(i).zfill(5), x, y, z, pointData=field_dict)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.14" } }, "nbformat": 4, "nbformat_minor": 5 }