Using the Tracers (finding parents at earlier snapshots)
Josue Lopez
22 Jan '24
Hello,
I am currently working with galaxy data in the TNG-50 simulation and would like to trace the origin of the gas. Specifically, I am interested in determining whether it comes from the intergalactic medium or from another galaxy, and if so, which one. While I have explored the tracers, I am having difficulty loading the necessary data. It appears that the files are empty, but I am not sure if I am doing it correctly. Any help would be greatly appreciated.
Dylan Nelson
23 Jan '24
Are you loading them yourself from the snapshot files? Perhaps you can paste a code snippet.
Josue Lopez
24 Jan '24
Thank you for your response. Firstly, I printed the number of particles for a subhalo in TNG50. The output showed that there was no data for Particle Type 3, which I understand corresponds to the tracers.
This is my code:
I also tried using the dataset mentioned in index a) of the Data Specification. From the information provided, I understand that to trace the gas to a galaxy, we need to use the file 'tr_all_groups_99_subhalo_id'. I went to the path 'TNG/TNG50-1/postprocessing/tracer_tracks' to find the hdf5 file, but I only found two files: 'tr_all_groups_99_meta.hdf5' and 'tr_all_groups_99_parent_indextype.hdf5'. I do not understand how to trace the origin of the gas using these two files. Thanks in advance for your help.
Here is the other part of my code:
basePath = '../sims.TNG/TNG50-1/postprocessing/tracer_tracks'
file = basePath+"/tr_all_groups_99_meta.hdf5"
data = h5py.File(file,"r")
print("####Data")
for f in data.keys():
print(f)
print("\n")
print(np.array(data["Halo/TracerLength/gas"]))
Dylan Nelson
24 Jan '24
Hi Josue,
I would suggest to read the data release papers, which describe the tracers a bit more. They are not so easy to work with. They are not ordered by (sub)halo, so (sub)halos do not "contain" any tracers. To load and use them, you have to load all PartType3 from the snapshot using ill.snapshot.loadSubset(), for example.
The supplementary data catalog "(a) Tracer Tracks" is a good alternative, it makes them easier to use. The documentation gives some pseudo-code advice on how to use this dataset.
Guan-Fu Liu
6 May
Hi!
I am also trying to deal with the '/home/tnguser/sims.TNG/TNG50-1/postprocessing/tracer_tracks/tr_all_groups_99_meta.hdf5' and I find some difficulties. Before describing my questions in detail, I would like to paste some code snippet
basePath = '/home/tnguser/sims.TNG/TNG50-1/postprocessing/tracer_tracks'
file = '%s/tr_all_groups_99_meta.hdf5' % basePath
f = h5py.File(file)
print('Keys of f:', f.keys())
print("Keys of f['Subhalo']:", f['Subhalo'].keys())
print("Keys of f['Subhalo']['TracerOffset']:", f['Subhalo']['TracerOffset'].keys())
print("Keys of f['Subhalo']['TracerLength']:", f['Subhalo']['TracerLength'].keys())
start = f['Subhalo']['TracerOffset']['gas'][6]
length = f['Subhalo']['TracerLength']['gas'][6]
parentIDs = f['ParentIDs'][start:start+length]
tracerIDs = f['TracerIDs'][start:start+length]
print('shape of parentIDs:', parentIDs.shape)
print('shape of tracerIDs:', tracerIDs.shape)
and the printed output is
Keys of f: <KeysViewHDF5 ['Halo', 'ParentIDs', 'Subhalo', 'TracerIDs']>
Keys of f['Subhalo']: <KeysViewHDF5 ['TracerLength', 'TracerOffset']>
Keys of f['Subhalo']['TracerOffset']: <KeysViewHDF5 ['bhs', 'gas', 'stars']>
Keys of f['Subhalo']['TracerLength']: <KeysViewHDF5 ['bhs', 'gas', 'stars']>
shape of parentIDs: (81,)
It seems good and I obtain the parentIDs and tracerIDs of tracer particles whose parent particles are gas in subhalo 6 at snap=99, my questions are
(1) Do I obtain the parentIDs and tracerIDs of tracer particles whose parent particles are gas in subhalo 6 at snap=99 correctly?
(2) If I load the the parentIDs and tracerIDs of tracer particles whose parent particles are gas in subhalo 6 at snap=99 correctly, how can I get their properties like postions, masses, and etc.? I am planning to load all the gas particles of snap=99 via gas=il.snapshot.loadSubset(basePath, 99, 'gas', fields=['particleIDs','Masses'], subset=None) and only select the gas particles whose particleIDs match the tracer particles in subhalo 6 at snap=9. Such a method seems to be slow, is there any faster way?
(3) If method is step (2) are correct and the fastest way, how can I get the properties of tracer particles at snap=98 or earlier? There is only tr_all_groups_99_meta.hdf5, no files like tr_all_groups_98_meta.hdf5 nor tr_all_groups_97_meta.hdf5, etc.
Many thanks!
Dylan Nelson
6 May
(1) That's correct.
(2) That's also correct, in general. To select the gas with matching IDs, an algorithm based on sorting is a good approach, you can use something like np.intersect1d.
However, using the "tracer_tracks", you don't actually need to do this (see below).
(3) The other file, parent_indextype, solves this problem, as well as the problem above. This is because it gives you immediately the index (not the ID) of the parent, at all previous snapshots.
Given a list of snapshot indices, you can either load corresponding fields by calling il.snapshot.loadSubset() and passing subset (see this thread for the idea). Or, you can simply use the simulation.hdf5 file like
with h5py.File(basePath + 'simulation.hdf5','r') as f:
pos = f['/Snapshots/98/PartType0/Coordinates'][indices]
Guan-Fu Liu
6 May
Thanks!
I try the other file, and the following are my codes and outputs:
basePath = '/home/tnguser/sims.TNG/TNG50-1/postprocessing/tracer_tracks'
file1 = '%s/tr_all_groups_99_parent_indextype.hdf5' % basePath
f1 = h5py.File(file1)
print('Keys of f1:', f1.keys())
print("Shape of f1['parent_indextype']:", f1['parent_indextype'].shape)
print("Shape of f1['redshifts']:", f1['redshifts'].shape)
print("Shape of f1['snaps']:", f1['snaps'].shape)
print("f1['parent_indextype'][:10,0]:",f1['parent_indextype'][:10,0])
indices = f1['parent_indextype'][:10,0]
print("f['snap'][0]:", f1['snaps'][0])
Keys of f1: <KeysViewHDF5 ['parent_indextype', 'redshifts', 'snaps']>
Shape of f1['parent_indextype']: (3292847014, 100)
Shape of f1['redshifts']: (100,)
Shape of f1['snaps']: (100,)
f1['parent_indextype'][:10,0]: [0 2 2 3 3 4 4 4 4 5]
f['snap'][0]: 99
It confuses me that why there are some repeating numbers in f1['parent_indextype'][:10,0]? I guess that there are multiple progenitor particles that contribute to the tracer particles at snapNum=99.
Dylan Nelson
6 May
A parent can always have multiple tracers.
In this case, gas cell indices 2 and 3 both have two tracer children.
Guan-Fu Liu
7 May
To check something more, I think f1['parent_indextype'][:10,0]: [0 2 2 3 3 4 4 4 4 5] should be interpreted as follows,
Tracer with a tracerID of 0 at snapNum=99, corresponds to the particle with a particleID of 0;
Tracer with a tracerID of 1 and 2 at snapNum=99, corresponds to the particle with a particleID of 2;
Tracer with a tracerID of 3 and 4 at snapNum=99, corresponds to the particle with a particleID of 3;
Tracer with a tracerID of 5, 6, 7, 8 at snapNum=99, corresponds to the particle with a particleID of 4;
Tracer with a tracerID of 9 at snapNum=99, corresponds to the particle with a particleID of 5.
If so here comes the problem, how can I know the part type of the particles with the particleIDs that was mentioned above.
Dylan Nelson
7 May
(1) Please see the definition of "parent_indextype", this is a number that represents both the type and index.
(2) Don't mix up TracerID and index, your first numbers "0", "1 and 2", "3 and 4" and so on, are the indices of the tracers, not their IDs.
(3) "corresponds to the particle" should be "corresponds to the gas cell". This is because all the parents of these tracers have type 0. This is because the "parent_indextype" values are less than 1e11 (see definition).
(4) "with a particle ID of..." should be "with the index of..." (particles and gas cells have IDs, and indices, and these numbers give the indices).
Hello,
I am currently working with galaxy data in the TNG-50 simulation and would like to trace the origin of the gas. Specifically, I am interested in determining whether it comes from the intergalactic medium or from another galaxy, and if so, which one. While I have explored the tracers, I am having difficulty loading the necessary data. It appears that the files are empty, but I am not sure if I am doing it correctly. Any help would be greatly appreciated.
Are you loading them yourself from the snapshot files? Perhaps you can paste a code snippet.
Thank you for your response. Firstly, I printed the number of particles for a subhalo in TNG50. The output showed that there was no data for Particle Type 3, which I understand corresponds to the tracers.
This is my code:
I also tried using the dataset mentioned in index a) of the Data Specification. From the information provided, I understand that to trace the gas to a galaxy, we need to use the file 'tr_all_groups_99_subhalo_id'. I went to the path 'TNG/TNG50-1/postprocessing/tracer_tracks' to find the hdf5 file, but I only found two files: 'tr_all_groups_99_meta.hdf5' and 'tr_all_groups_99_parent_indextype.hdf5'. I do not understand how to trace the origin of the gas using these two files. Thanks in advance for your help.
Here is the other part of my code:
Hi Josue,
I would suggest to read the data release papers, which describe the tracers a bit more. They are not so easy to work with. They are not ordered by (sub)halo, so (sub)halos do not "contain" any tracers. To load and use them, you have to load all PartType3 from the snapshot using
ill.snapshot.loadSubset()
, for example.The supplementary data catalog "(a) Tracer Tracks" is a good alternative, it makes them easier to use. The documentation gives some pseudo-code advice on how to use this dataset.
Hi!
I am also trying to deal with the
'/home/tnguser/sims.TNG/TNG50-1/postprocessing/tracer_tracks/tr_all_groups_99_meta.hdf5'
and I find some difficulties. Before describing my questions in detail, I would like to paste some code snippetand the printed output is
It seems good and I obtain the parentIDs and tracerIDs of tracer particles whose parent particles are gas in subhalo 6 at snap=99, my questions are
gas=il.snapshot.loadSubset(basePath, 99, 'gas', fields=['particleIDs','Masses'], subset=None)
and only select the gas particles whose particleIDs match the tracer particles in subhalo 6 at snap=9. Such a method seems to be slow, is there any faster way?tr_all_groups_99_meta.hdf5
, no files liketr_all_groups_98_meta.hdf5
nortr_all_groups_97_meta.hdf5
, etc.Many thanks!
(1) That's correct.
(2) That's also correct, in general. To select the gas with matching IDs, an algorithm based on sorting is a good approach, you can use something like np.intersect1d.
However, using the "tracer_tracks", you don't actually need to do this (see below).
(3) The other file,
parent_indextype
, solves this problem, as well as the problem above. This is because it gives you immediately the index (not the ID) of the parent, at all previous snapshots.Given a list of snapshot indices, you can either load corresponding fields by calling
il.snapshot.loadSubset()
and passingsubset
(see this thread for the idea). Or, you can simply use thesimulation.hdf5
file likeThanks!
I try the other file, and the following are my codes and outputs:
It confuses me that why there are some repeating numbers in f1['parent_indextype'][:10,0]? I guess that there are multiple progenitor particles that contribute to the tracer particles at snapNum=99.
A parent can always have multiple tracers.
In this case, gas cell indices 2 and 3 both have two tracer children.
To check something more, I think
f1['parent_indextype'][:10,0]: [0 2 2 3 3 4 4 4 4 5]
should be interpreted as follows,If so here comes the problem, how can I know the part type of the particles with the particleIDs that was mentioned above.
(1) Please see the definition of "parent_indextype", this is a number that represents both the type and index.
(2) Don't mix up TracerID and index, your first numbers "0", "1 and 2", "3 and 4" and so on, are the indices of the tracers, not their IDs.
(3) "corresponds to the particle" should be "corresponds to the gas cell". This is because all the parents of these tracers have type 0. This is because the "parent_indextype" values are less than 1e11 (see definition).
(4) "with a particle ID of..." should be "with the index of..." (particles and gas cells have IDs, and indices, and these numbers give the indices).