### How to Use 'Density' Field

Tian Zeng
• 1
• 26 Apr

Dear TNG Team,
I am looking to plot a density distribution, so I found the field named 'SubfindDensity', but this has led to some confusion: how do I link the density with the corresponding coordinates? This question has puzzled me for a while.
Today, I found a script in the API Getting Started Guide that might be what I need, but I am still confused about its content: I noticed that the 'masses' field is a one-dimensional list, so, If I set the 'weights' directly to 'masses', how do they correspond to the coordinates? The script in API Getting Started Guide I mentioned is:

``````>>> with h5py.File(cutout,'r') as f:
>>>     x = f['PartType0']['Coordinates'][:,0] - sub_prog['pos_x']
>>>     y = f['PartType0']['Coordinates'][:,1] - sub_prog['pos_y']
>>>     dens = np.log10(f['PartType0']['Masses'][:])
>>>
>>> plt.hist2d(x,y,weights=dens,bins=[150,100])
>>> plt.xlabel('\$\Delta x\$ [ckpc/h]')
>>> plt.ylabel('\$\Delta y\$ [ckpc/h]');
``````

Many thanks for your help! By the way, all of the discriptions of 'SubfindDensity' for different PartTypes is the same, i.e.: "The local total comoving mass density, estimated using the standard cubic-spline SPH kernel over all particles/cells within a radius of SubfindHsml." What does 'all' means? All cells in one PartType or all cells of all PartTypes?Thank you!

Dylan Nelson
• 28 Apr

You should generally not use `SubfindDensity`, this is a kernel density estimate of the total matter density (not just DM, or gas, or stars, but everything together, as the docs describe).

For gas you can use `PartType0/Density`. There is one entry per cell, just as with Masses. The positions of the same cells are in `PartType0/Coordinates`'.

Tian Zeng
• 28 Apr

thank you！

• Page 1 of 1