QuickView is the simplest way to produce images with Py-SPHViewer. In this example, we’ll demonstrate its use.
We will create an image of a dark matter halo extracted from a cosmological simulation. Before starting the tutorial, please download this file.
You can read the file content using the h5py library:
import h5py
with h5py.File('dm_halo.h5py', 'r') as f:
pos = f['Coordinates'][:]
The coordinates of the dark matter particles are in Mpc/h, tracing the density field of a collapsed dark matter halo from a cosmological simulation. Our goal is to visualize the projected density field.
Below is the xy projection of the particle distribution:
We can calculate (and visualize) the projected density field using QuickView:
from sphviewer.tools import QuickView
qv = QuickView(pos, r='infinity', plot=False)
qv.imshow()
The argument r='infinity'
tells the camera to render the scene using a parallel (or orthographic) projection, as if viewed from infinity.
QuickView retrieves the active axis and places the image on it, while plot=False
suppresses automatic plotting. The imshow
method can be used to display the image. Valid **kwargs
are the same as those accepted by matplotlib.pyplot.imshow
. For instance, we can modify the colormap and vmax
as shown:
qv.imshow(cmap="gist_stern", vmax=2)
You can also retrieve the image generated by QuickView:
img = qv.get_image()
extent = qv.get_extent()
fig = plt.figure(1, figsize=(7,7))
plt.imshow(img, extent=extent, cmap='gist_stern')