Dark Matter densities in IllustrisTNG

Charles Walker
  • 2
  • 4 May '20

Hi Dylan and the TNG team,

I'd like to extract dark matter densities from TNG-100, but I'm a bit confused about terminology.

I'd essentially like to reproduce some work of Haider16+ (see Fig. 6): defining different structures by plotting dark matter density against baryon density and then cross-refeerencing coordinates.

I'm aware from the fields list that baryonic density is extracted using the 'density' field, but how do I extract dark matter density? I'm not sure whether to use 'subfindDMdensity', or whether this refers to an estimate of 'total' (DM + baryons etc) density calculated using dark matter particles.

Additionally, reading Haider+16's introduction section makes me wonder whether I have to calculate this explicitly for TNG. They write:

In the subsequent analysis, we compute the density fields of ... dark matter on a uniform grid with 1024^3 cells. To this end, the dark matter and gas particles are mapped conservatively to the grid using a smoothed particle hydrodynamics (SPH) kernel technique. For the dark matter, we set the smoothing length to be the radius of a sphere containing the 64 nearest dark matter particles, as is done also insubfind. The gas cells are mapped using three times rc= (3V_cell/4π)1/3, where V_cell is the volume of a Voronoi cell.

Please could you advise me on how I can go about extracting the dark matter densities in a similar form to the baryonic densities provided by the 'density' field?

All the best,


Dylan Nelson
  • 6 May '20

Hi Charles,

Yes there are two options, do you want (i) density estimates at the location of every DM particle, or (ii) density estimates on a uniform grid?

If (i), then you can use the SubfindDMDensity field at the particle level.

If (ii), you'd have to compute the grid (by distributing the dark matter particle mass in a/any conservative way, including e.g. at zeroth order a 3D histogram). This would be the typical thing to do for e.g. cosmic web classification, machine learning experiments, etc.

Charles Walker
  • 1
  • 6 May '20

Hi Dylan,

Thanks for the speedy reply.

The goal for my work is to come up with a definition as to whether a set of coordinates (which I’d use, say, for generating light rays) lies in a halo, filament or void.

Haider+16 do this by looking at dark matter density compared to the critical density. If using the definitions resulting from their work, I just need to know the dark matter density estimate for every point in the simulation. Would option (i) using subfindDMDensity allow me to do this? Am I correct in understanding that the dark matter particle coordinates do not necessarily map exactly to the baryonic particle coordinates? How then would I go about essentially saying “I pick coordinates a,b,c to be the start point of my light ray, which lies in a sheet/filament/void according to Haider+16 definitions.”?

Also, I’d ideally like to reproduce some of Haider’s plots and results for IllustrisTNG as well, as a check to make sure their definitions for voids, filaments and halos still hold for IllustrisTNG. As they compute a grid (i.e. option II), I’d have to do this as well.

Please could you explain more to me about computing this kind of grid? I’m currently in the process of doing the following (pieced together using your advice to other people on the forum):

  • Getting the total volume of each IllustrisTNG Voronoi cell using Volume = ‘Masses’ field / ‘Density’ field
  • Getting the radius of each cell by assuming they are spherical
  • Getting the center position of each cell using the ‘CenterOfMass’ field
  • Looping over each cell and counting the number of dark matter particles within by comparing the cell radius with the radial distance from the cell center to the dark matter particle locations (extracted from the PartType1 ‘Coordinates’ field)
  • Multiplying the number of particles by the particle mass
  • Calculating the density using this mass and the cell volume.

It's currently taking quite some time. But from here I hoped to average over cells, making some sort of grid. Is this the correct approach/is this the kind of approach you refer to by option (ii)? And how does the ‘smoothing length’ referred to by Haider+16 relate to all of this?

Thanks loads for all your advice.


Dylan Nelson
  • 7 May '20


A procedure such as you describe would be ok, but it will give you a density estimate at the location of every gas cell, which doesn't seem necessary.

As Haider use a 1024^3 grid, I would simply start with histogram_dd (in python) on the Coordinates of all dark matter particles. Multiply by the DM particle mass, divide by the volume of the grid cells, and you have the density grid estimate.

In general, you want such a coarse grid (i.e. very smoothed) when identifying cosmic web structures, so for your light rays, I would suggest to use the same grid, find which cell the point is in, and use that value.

Charles Walker
  • 12 May '20

Hi Dylan,

Thanks very much for the advice. I'll get to work on it.



  • Page 1 of 1