Skip to content

Latest commit

 

History

History
94 lines (68 loc) · 3.24 KB

pictures.rst

File metadata and controls

94 lines (68 loc) · 3.24 KB

Pictures in Pynbody

Density Slice

The essential kind of image -- a density slice:

tutorials/example_code/density_slice.py

Integrated Density

Line-of-sight averaged density map:

tutorials/example_code/density_integrated.py

Temperature Slice

Simple example for displaying a slice of some other quantity (Temperature in this case)

tutorials/example_code/temperature_slice.py

Velocity Vectors

It is also straightforward to obtain an image with velocity vectors or flow lines overlaid:

tutorials/example_code/velocity_vectors.py

Multi-band Images of Stars

You can create visualizations of the stellar distribution using synthetic colors in a variety of bands:

tutorials/example_code/star_render.py

Creating images using ~pynbody.plot.sph.image

The ~pynbody.plot.sph.image function is a general purpose function for creating an x-y map of a value from your ~pynbody.snapshot.SimSnap object. Under the hood, the function calls one two SPH kernels (written in c) to calculate the intensity values of whatever value you're plotting - a 2d kernel for integrated maps, and a 3d kernel for slices. Both kernels require the use of a kd-tree to perform an SPH smooth, so you will notice that the first time ~pynbody.plot.sph.image is called, it creates a kd-tree. Subsequent calls on the same data set should use the already created tree, and thus should be faster.

~pynbody.plot.sph.image returns an x,y array representing pixel intensity. The function also displays the image with automatically created axes and a colorbar. However, one can use the x-y array and plt.imshow() to create your own plot.

Common issues

~pynbody.plot.sph.image is prone to a number of common errors when being used by new users. Probably the most common is

ValueError: zero-size array to minimum.reduce without identity

This can come about in a number of circumstances, but essentially it means that there were not enough particles in the region that was being plotted. It could be due to no/bad centering, passing in a very small/empty ~pynbody.snapshot.SubSnap object, or bad units (units being an issue should no longer be an issue. In older versions of pynbody, the width parameter assumed kpc, so if the simulation distances were in e.g. "au", this could cause a problem).

Another common error is the following:

TypeError: 'int' object does not support item assignment

which occurs when the returned image from the kernel is a singular value rather than an array. In this case, the issue was because the kernel did not complete because of attempting to plot a value for the whole ~pynbody.snapshot.Snapshot object rather than a specific family (such as gas). In this case, the "smooth" array needed to be deleted before another image could be produced because SPH needed to resmooth with the new dark and star particles.