Magnetic field in TNG50-2 has NaNs for some subhalos

Mohammad Rad
  • 1
  • 11 Jul '23

Hi all,

I recognized that in the TNG50-2 sanpshot 99, the magnetic field in the subfind subhalos's catalog has NaN values for some galaxies. Specially the most massive one with id=0, has NaNs for the SubhaloBfldDisk and SubhaloBfldHalo fields. There are also galaxies with the total stellar mass > 10^8 M0 and more or less the same value for the gas mass that strangely have NaN for SubhaloBfldDisk but not for SubhaloBfldHalo.

I appreciate it if anyone could help. The code to re-produce it could be:

import numpy as np
import pandas as pd
import illustris_python.groupcat as gc

basePath = './sims.TNG/TNG50-2/output/'

a = 1
h = 0.6774
SnapNum = 99

subhalo_fields = ['SubhaloFlag','SubhaloBfldDisk','SubhaloBfldHalo']
subhalos = gc.loadSubhalos(basePath,SnapNum, fields=subhalo_fields)

s_B_re  = subhalos['SubhaloBfldDisk']*h/(a**2)*2.6          # micro Gauss
s_B_tot = subhalos['SubhaloBfldHalo']*h/(a**2)*2.6          # micro Gauss

print(s_B_re[0], s_B_tot[0])
print(s_B_re[26], s_B_tot[26])
Dylan Nelson
  • 19 Jul '23

HI Mohammad,

Yes this is unfortunate, the reason is that the SubhaloBfldDisk and SubhaloBfldHalo fields were (originally, when TNG was run) corrupt. They were re-computed after the fact, and the catalogs were fixed, but apparently this failed in some cases.

For the most immediate solution, I would suggest (if you need these values) to calculate them from the snapshot.

Mohammad Rad
  • 20 Jul '23

Hi Dylan,

Thank you. Yes, I need them to compare with TNG50-1. So, I should calculate them.

Dylan Nelson
  • 27 Jul '23

Hi Mohammad,

Thanks for the report and follow-up email. The SubhaloBfldDisk and SubhaloBfldHalo fields for TNG50-4, TNG50-3, and TNG50-2 have been recomputed.

Can you please re-download the catalogs, and make your checks again? Let me know if everything looks now fixed.

Mohammad Rad
  • 29 Jul '23

Hi Dylan,

Could you please tell me did you also replace the catalogs on the TNG Jupyter server? Because I can still see NaNs and some others also seem very smaller than what they should be. Thanks.

Dylan Nelson
  • 29 Jul '23

Can you provide a specific example? (Sim, snap, subhalo ID)

Dylan Nelson
  • 29 Jul '23

NaNs are indeed present, they should represent subhalos for which the calculation is not possible (e.g. contain no gas cells).

Mohammad Rad
  • 29 Jul '23

NaNs are indeed present, they should represent subhalos for which the calculation is not possible (e.g. contain no gas cells).

I understand that NaNs are possible.

Can you provide a specific example? (Sim, snap, subhalo ID).

Yes. For example: TNG50-2, snapshot 99, subhalo 1. This subhalo has 80 cells. Could you please see the following code:

import numpy as np
import illustris_python.groupcat as gc
from illustris_python.snapshot import loadSubhalo

##########################################
# function to ccalculate volume weighted B
def B_volume_weighted(Bxyz, vol):
    B   = np.sqrt(np.sum(Bxyz**2, axis=1, dtype=np.float64))
    B2  = np.sum(Bxyz**2, axis=1, dtype=np.float64)
    B2V = 0
    V   = 0
    bvw = np.nan
    if vol.sum() > 0:
        for i in range(B2.size):
            B2V = B2V + B2[i] * vol[i]
            V   = V + vol[i]
        bvw = np.sqrt(B2V/V)
    return bvw
###########################################
# test catalog value

basePath = '../sims.TNG/TNG50-2/output/'

a = 1
h = 0.6774
M_fac = (10**10)/h

SnapNum = 99
gi = 1 # subhalo ID

subhalo_fields = ['SubhaloFlag','SubhaloBfldDisk','SubhaloBfldHalo']
subhalos = gc.loadSubhalos(basePath, SnapNum, fields=subhalo_fields)

s_B_re  = subhalos['SubhaloBfldDisk']*h/(a*a)*2.6          # micro Gauss
s_B_tot = subhalos['SubhaloBfldHalo']*h/(a*a)*2.6          # micro Gauss

print("In catalog:", s_B_tot[gi])
###########################################
# now test snapshot value
ptclType = 0  # gas cell

m = loadSubhalo(basePath, SnapNum, gi, ptclType, fields=['Masses']) * M_fac # in Mgas in M0
rho = loadSubhalo(basePath, SnapNum, gi, ptclType, fields=['Density']) * M_fac / (1./(h**3)) # in M0/(kpc^3)
vol = m/rho # in kpc^3, not important for taking the volume weighted avarage
Bxyz= loadSubhalo(basePath, SnapNum, gi, ptclType, fields=['MagneticField'])*h/(a*a)*2.6 # in micro G

print("From snapshot:", B_volume_weighted(Bxyz, vol))
B = np.sqrt(np.sum(Bxyz**2, axis=1, dtype=np.float64)) # B magnitude of each cell
print("B in micro G:", B)
print("Simple average:", B.mean())

For me this gives:

In catalog: 5.95136e-07
From snapshot: 0.367075672233
B in micro G: [ 0.14101963  0.32300692  0.42221129  0.49209787  0.25282099  0.31059606
  0.42328453  0.41460323  0.24916654  0.30802816  0.41683747  0.21218518
  0.30993395  0.13970353  0.41832142  0.40488468  0.43663593  0.34016824
  0.34529578  0.18712755  0.43876813  0.16013994  0.5003266   0.22004774
  0.65428959  0.52452167  0.43220014  0.36628218  0.3197154   0.42967253
  0.32835496  0.11473559  0.14220999  0.34771544  0.29025606  0.22200479
  0.48058551  0.15294337  0.22778014  0.3685951   0.38741896  0.31124933
  0.66300425  0.24547508  0.19554428  0.30864625  0.16989434  0.36602047
  0.47606137  0.63334576  0.50441914  0.21656936  0.09282972  0.42237114
  0.23672425  0.26817241  0.3126682   0.55242227  0.39230921  0.12931915
  0.52580785  0.28199041  0.37991705  0.58384092  0.2014507   0.55871252
  0.16351889  0.59451273  0.53666731  0.28545628  0.08401386  0.10690492
  0.17335541  0.39922186  0.46071288  0.12745335  0.43122055  0.39076704
  0.5452468   0.30241811]
Simple average: 0.341084102259
Dylan Nelson
  • 2
  • 29 Jul '23

Hi Mohammad,

It looks like these new values were (mistakenly) already in Gauss. I am recomputing them now, let's wait a day.

Mohammad Rad
  • 29 Jul '23

Hi Dylan,

According to the data specifications, if I understand correctly, as the (UnitPressure)^0.5 = 2.6 * 10^-6 G, I've removed the 10^-6 factor to get the values in micro G. If I re-add the 1e-6 factor, I will get 5.9e-13 G. So, I think may be you missed this factor when you were calculating the magnetic field. You might compare subhalo ID=0 in TNG50-1 and TNG50-2 to see the 10^6 difference.

Dylan Nelson
  • 29 Jul '23

Can you please check these values again?

(Should be all resolved now)

Mohammad Rad
  • 30 Jul '23

Yes. I also think the issue has been resolved. Thank you so much.

  • Page 1 of 1