I’m trying to compute the GFM_StellarPhotometrics field — in particular mag_b — for each star particle at any snapshot in the same way as TNG does, using the BC03–based method described in this thread. I generate the table using the def makeStellarPhotometricsHDF5_BC03() function and then interpolate over it.
As a test case I’m using the subhalo with SubfindID = 10 at snapshot 99, but I can’t reproduce the same values stored in the TNG50 simulation.
My code:
import h5py
import numpy as np
from scipy.interpolate import RegularGridInterpolator
from scipy.interpolate import RectBivariateSpline
import illustris_python as il
import CosmoCal as CC
basePath = '../sims.TNG/TNG50-1/output/'
h = 0.6774
# ==========================
# load table BC03
# ==========================
with h5py.File("stellar_photometrics.hdf5", "r") as f:
logZ_grid = f["LogMetallicity_bins"][:]
logAge_grid = f["LogAgeInGyr_bins"][:]
# SSP mags_B normalized to 1 Msun
mag_B_grid = f["Magnitude_B"][:]
# ==========================
# Interpolator 2D (logZ , logAge) -> mag_B
# ==========================
interp_B = RegularGridInterpolator((logZ_grid, logAge_grid), mag_B_grid, bounds_error=False, fill_value=None)
# ==========================
# Stars at Snap 99 for galaxy SubfindID = 10
fieldsPart = ['Masses', 'GFM_StellarFormationTime','GFM_StellarPhotometrics','GFM_Metallicity','GFM_InitialMass']
subfindID=10
Snap=99
partSH=il.snapshot.loadSubhalo(basePath, Snap, subfindID , 'stars', fields=fieldsPart)
agea = partSH['GFM_StellarFormationTime']
metals = partSH['GFM_Metallicity']
InitialMass = partSH['GFM_InitialMass']
magB = partSH['GFM_StellarPhotometrics'][:,1]
CurrentMass = partSH['Masses']
#clean wind particles (age <= 0)
indnowind = agea > 0.
agea = agea[indnowind]
metals = metals[indnowind]
InitialMass = InitialMass[indnowind]*1e10/h
CurrentMass = CurrentMass[indnowind]*1e10/h
magB = magB[indnowind]
print('TNG mags')
print(magB[:1])
print('Initial Mass , Initial Metallicity and scale factor')
print(InitialMass[:1],metals[:1],agea[:1])
# Age Universe at Snap 99, also return scale factor, redshift and lookback time for a given Snap
time = CC.get_time(snap = 99,)
ageU_at_snap = time[3]
# array of scale factor----> return age of Universe at that scale factor
time_stars = CC.AscaletoAgeU(agea)
#Age of stars at given Snap
age_stars = ageU_at_snap - time_stars
#preparing data from star for interpolation
logAge = np.log10(np.clip(age_stars, 1e-3, None))
logZ = np.log10(np.clip(metals, 1e-5, None))
pts = np.column_stack((logZ,logAge))
# Interpolation
mag_B_ssp = interp_B(pts)
print('Mag for ssp 1 Msun')
print(mag_B_ssp[:1])
#mag_b for SSP of Inital Mass
mag_B = mag_B_ssp - 2.5*np.log10(InitialMass)
print('Interpolate mags')
print(mag_B[:1])
Below I show what I obtain for the first star particle.
Here are the relevant values
From TNG:
mags_b from TNG [-5.5265326]
initialMass, Initial Metallity, birth as scale factor :[76993.04] [0.05280386] [0.78129745]
log (Age/Gyr) and log Metallicity: [0.5228039] [-1.2773345]
From Interpolation with BC03 tables:
Mag_b for a ssp of 1 Msun [7.0779547]
Mags_b interpolated [-5.1381746]
So there is a difference of about 0.37 mag. At first I thought I might have made a mistake in the interpolation, but after trying alternative interpolation approaches I obtain very similar values.
To investigate further, I inspected the BC03 files. Since this star particle has GFM_Metallicity = 0.05280, I used the file named bc2003_hr_m72_chab_ssp.1color
The birth time corresponds to a scale factor of 0.78129745, i.e. an age of ≈ 3.33 Gyr → log(age/yr) ≈ 9.522.
In that file I find the following entry (excerpt of the table):
So, using the closest SSP value for 1 M_sun gives mag_b_ssp ≈ 7.0407, which seems to be consistent with my interpolating computed value.
I have also checked other star particles from the same galaxy and I observe similar discrepancies. I show you the first ten star particles for this galaxy:
What am I missing here? Could it be the interpolation, or perhaps the relation between the SSP magnitude and the magnitude scaled to the stellar particle mass?
#mag_b for SSP of Inital Mass
mag_B = mag_B_ssp - 2.5*np.log10(InitialMass)
Sorry for the long post, and thanks in advance for any help.
Best regards, and happy new year!
Dylan Nelson
7 Jan
Why is the last value -4.592 (of the ten you posted) equal, while the rest are not?
Elio Crisci
17 Jun
Sorry for the delay. I have been very busy.
I can recover the TNG B-band magnitudes whenever the stellar metallicity lies within the BC03 grid, i.e. for log Z < -1.30.
As an example, for galaxy ID = 10 at z = 0, below I show the metallicities of its star particles. The particles highlighted in bold are within the interpolation range:
As you can see, the difference is exactly zero for particles with log Z ≤ -1.30, while a systematic offset appears for particles with log Z > -1.30, i.e. outside the metallicity grid.
Therefore, it seems that the discrepancy is entirely due to the treatment of the extrapolation beyond the highest metallicity available in the BC03 tables.
Could you tell me how this extrapolation is handled in TNG? Is the metallicity clipped to the maximum grid value, linearly extrapolated, or is a different prescription used?
Thanks in advance for your help.
Best regards,
Elio
Dylan Nelson
22h
It looks like clipped i.e. constant beyond the edges of the grid. You should be able to confirm?
Elio Crisci
26m
Hi again, Dylan.
Previously, I tried clipping the metallicity at the last grid value, but the offset remained.
Then an IA realized that of another value was using to clip. So I tried clipping to the penultimate metallicity value instead, and it reproduces the TNG magnitudes perfectly. Could this indicate a mistake?
Below I show the first ten star particles of the same galaxy.
Note that the 10th particle is the only one that is not clipped, since its metallicity already lies within the interpolation grid. Therefore, its magnitude is reproduced correctly in both cases.
Hi everyone !
I’m trying to compute the GFM_StellarPhotometrics field — in particular mag_b — for each star particle at any snapshot in the same way as TNG does, using the BC03–based method described in this thread. I generate the table using the def makeStellarPhotometricsHDF5_BC03() function and then interpolate over it.
As a test case I’m using the subhalo with SubfindID = 10 at snapshot 99, but I can’t reproduce the same values stored in the TNG50 simulation.
My code:
Below I show what I obtain for the first star particle.
Here are the relevant values
From TNG:
From Interpolation with BC03 tables:
So there is a difference of about 0.37 mag. At first I thought I might have made a mistake in the interpolation, but after trying alternative interpolation approaches I obtain very similar values.
To investigate further, I inspected the BC03 files. Since this star particle has GFM_Metallicity = 0.05280, I used the file named bc2003_hr_m72_chab_ssp.1color
The birth time corresponds to a scale factor of 0.78129745, i.e. an age of ≈ 3.33 Gyr → log(age/yr) ≈ 9.522.
In that file I find the following entry (excerpt of the table):
log-age-yr Mbol Umag Bmag Vmag Kmag 14-V 17-V 22-V 27-V U-J J-F F-N U-B B-V
5.100002 -2.8772 -0.6833 0.3679 0.6566 1.3966 -4.5563 -3.6206 -3.1758 -2.6092 -1.0391 -0.3117 -0.1551 -1.0512 -0.2887
5.150001 -2.9991 -0.7819 0.2755 0.5665 1.3176 -4.5817 -3.6441 -3.1956 -2.6256 -1.0455 -0.3136 -0.1566 -1.0575 -0.2910
5.199999 -2.9741 -0.7628 0.2934 0.5840 1.3329 -4.5763 -3.6391 -3.1915 -2.6222 -1.0442 -0.3133 -0.1563 -1.0562 -0.2906
9.439333 5.0906 7.3604 6.8300 5.9219 2.6505 4.6283 5.3888 4.8299 2.6821 0.7312 1.0448 0.7941 0.5304 0.9081
9.477121 5.1427 7.4901 6.9349 6.0081 2.6820 4.6099 5.3840 4.8911 2.7446 0.7596 1.0679 0.8173 0.5552 0.9267
9.511884 5.1969 7.6221 7.0407 6.0947 2.7182 4.5646 5.3463 4.9413 2.8092 0.7896 1.0913 0.8395 0.5815 0.9459
9.544068 5.2549 7.7600 7.1505 6.1849 2.7596 4.4979 5.2958 4.9789 2.8768 0.8215 1.1151 0.8616 0.6095 0.9656
9.574031 5.3107 7.8618 7.2402 6.2638 2.8049 4.4526 5.2525 4.9785 2.9070 0.8356 1.1296 0.8785 0.6216 0.9764
So, using the closest SSP value for 1 M_sun gives mag_b_ssp ≈ 7.0407, which seems to be consistent with my interpolating computed value.
I have also checked other star particles from the same galaxy and I observe similar discrepancies. I show you the first ten star particles for this galaxy:
TNG mags_b [-5.5265326, -5.2543945, -5.6814675, -5.740373, -4.3355055, -4.602944, -4.8916907, -4.712752, -5.628621, -4.5920005]
Mags_b interpolated [-5.1381746, -4.8484391, -5.27546944, -5.3343746, -3.83355231, -4.10609969, -4.39670906, -4.21544409, -5.17110325, -4.59200134]
What am I missing here? Could it be the interpolation, or perhaps the relation between the SSP magnitude and the magnitude scaled to the stellar particle mass?
Sorry for the long post, and thanks in advance for any help.
Best regards, and happy new year!
Why is the last value
-4.592(of the ten you posted) equal, while the rest are not?Sorry for the delay. I have been very busy.
I can recover the TNG B-band magnitudes whenever the stellar metallicity lies within the BC03 grid, i.e. for log Z < -1.30.
As an example, for galaxy ID = 10 at z = 0, below I show the metallicities of its star particles. The particles highlighted in bold are within the interpolation range:
Log z: [-1.2773345 -1.1246493 -1.043868 -1.0465484; -1.2706383 -1.1443057
-1.185721 -1.2481058 -1.1964768 -1.6708509 -1.3608484 -1.0046098
-1.27228 -1.0686066 -1.2863213 -1.167124 -1.1232249 -1.0789455
-1.2650504 -1.060161 -1.1886915 -1.241385 -1.1300318 -1.127543
-1.0194157 -1.2235115 -1.1429211 -1.0490373 -1.210124 -1.3247535
-1.1649739 -1.0922784 -1.1602701 -1.1177349 -1.0548248 -1.2953866
-1.2373837 -1.2017826 -1.2150633 -1.0869868 -1.1102042 -1.1628467
-1.120691 -1.096799 -1.1507467 -1.2254072 -1.4299036 -1.2338946
-1.0874329 -1.314193 -1.1277514 -1.3456719 -1.249848 -1.1679686
-1.1215638 -1.0890884 -1.548217 -1.103983 -1.3233489 -1.2043778
-1.0713811 -1.1719047 -1.2786356 -1.1679021 -1.152566 -1.1650618
-1.5178399 -1.1873122 -1.3488623 -1.0059754]
The difference between the TNG B-band magnitudes and those obtained from my interpolation is:
magB_TNG - magB_interporlation:
[-0.4115 -0.5859 -0.6684 -0.6656 -0.5403 -0.6925 -0.6384 -0.5634 -0.5777
0. 0. -0.7084 -0.4713 -0.7982 -0.5226 -0.5383 -0.7309 -0.6326
-0.4373 -0.8053 -0.5391 -0.5693 -0.5805 -0.583 -0.6933 -0.4682 -0.5673
-0.6631 -0.5092 0. -0.5448 -0.7821 -0.6826 -0.593 -0.6572 -0.5078
-0.5234 -0.5073 -0.5256 -0.6244 -0.7513 -0.547 -0.5862 -0.7838 -0.7078
-0.4812 0. -0.4917 -0.7707 0. -0.5828 0. -0.5373 -0.5307
-0.5891 -0.6222 0. -0.7551 0. -0.5122 -0.6403 -0.6821 -0.4288
-0.6854 -0.614 -0.5447 0. -0.5967 0. -0.707 ]
As you can see, the difference is exactly zero for particles with log Z ≤ -1.30, while a systematic offset appears for particles with log Z > -1.30, i.e. outside the metallicity grid.
Therefore, it seems that the discrepancy is entirely due to the treatment of the extrapolation beyond the highest metallicity available in the BC03 tables.
Could you tell me how this extrapolation is handled in TNG? Is the metallicity clipped to the maximum grid value, linearly extrapolated, or is a different prescription used?
Thanks in advance for your help.
Best regards,
Elio
It looks like clipped i.e. constant beyond the edges of the grid. You should be able to confirm?
Hi again, Dylan.
Previously, I tried clipping the metallicity at the last grid value, but the offset remained.
Then an IA realized that of another value was using to clip. So I tried clipping to the penultimate metallicity value instead, and it reproduces the TNG magnitudes perfectly. Could this indicate a mistake?
Below I show the first ten star particles of the same galaxy.
And this is what I obtained:
TNG mags
[-5.5265326 -5.2543945 -5.6814675 -5.740373 -4.3355055 -4.602944
-4.8916907 -4.712752 -5.628621 -4.5920005]
Log z: [-1.2773345 -1.1246493 -1.043868 -1.0465484 -1.2706383 -1.1443057
-1.185721 -1.2481058 -1.1964768 -1.6708509]
Clip to logZ_grid = -1.30103
mags difference: magB_TNG - magB_interpolation
[-0.3884 -0.406 -0.406 -0.406 -0.502 -0.4968 -0.495 -0.4973 -0.4575 0.]
Clip to logZ_grid = -1.69897
mags difference: magB_TNG - magB_interpolation
[ 0. 0. 0. 0. 0. 0. -0. -0. 0. 0.]
Note that the 10th particle is the only one that is not clipped, since its metallicity already lies within the interpolation grid. Therefore, its magnitude is reproduced correctly in both cases.