Author LudwigBoess
2 Stars
Updated Last
2 Years Ago
Started In
July 2020
Documentation Build Status Licence
Build Status codecov.io The MIT License


This package maps SPH quantities to a cartesian grid.

You can map SPH data to a grid using the function sphMapping:

function sphMapping(Pos, HSML, M, ρ, Bin_Quant,
                    kernel::SPHKernel [,



Define parameters for mapping

To map the data you need to define the mapping parameters via the mappingParameters object. One way to set this up is by defining the limits of the map as

par = mappingParameters(xlim=[xmin, xmax],
                        ylim=[ymin, ymax],
                        zlim=[zmin, zmax],

or give a center position and the size in each direction

par = mappingParameters(center=[x0, y0, z0], 

Instead of Npixels you can also give the keyword argument pixelSideLength if you prefer to define your image that way.

If you are mapping a periodic box you also can give the keyword boxsize to enable periodic mapping.

par = mappingParameters(center=[x0, y0, z0], 

Select Kernel

You also need to choose the kernel you used in the simulation. For this you need to install the package SPHKernels.jl. You can currently use these kernels:

k = Cubic()
k = Quintic()
k = WendlandC4()
k = WendlandC6()

Please see the SPHKernels docs for more details.


With the setup done you can now map (e.g.) density of your data using the function above as:

image = sphMapping(x, hsml, m, rho, rho, param=par, kernel=k)

Replacing the second rho with any other quantity would map that quantity of course. Please note: This function doesn't do any unit conversion for you, so you need to convert to the desired units beforehand. You can do this e.g. with GadgetUnits.jl.

Image now contains a 2D array with the binned data and can easily be plotted with imshow() from any plotting package of your choosing.

The keyword parallel = true causes the run to use multiple processors. For this you need to start julia with julia -p <N> where <N> is the number of processors in your machine, or define

using Distributed

# now you can load SPHtoGrid
using SPHtoGrid

Conserved quantities

With the latest release you can map the particles to a grid while also conserving the particle volume, following the algorithm described in Dolag et. al. 2006.

Weight functions

With the mapping you may decide to use a specivic weighting function. For this you can pass the optional variable Weights in sphMapping.

You can either use your own weight functions or use one of the built-in ones:

part_weight_one just returns an Array of ones.

part_weight_physical converts from pixel- to physical units.

part_weight_emission weights the contribution due to density and temperature of the particle.

part_weight_spectroscopic gives spectroscopic weighting, see Mazotta+ 04.

part_weight_XrayBand weights the particle due to its Xray emission in the defined energy band.

Used By Packages

No packages found.