Hello All, I am doing some work using the yt.create_profile function, and it seems to be returning incorrect results, but that may be based just me misunderstanding something. I am currently working on collecting the dark matter profile within the virial radius of halos in an ART simulation, and have been using this create_profile function for a while. It was pointed out to me that two different profiles I created (one linearly spaced, and one logarithmacilly spaced seemed to disagree on the total mass in a given sphere. Upon looking into this I noticed that there appears to be a drastic falloff in mass for the inner most profiles which does not appear physical. Here is a script that shows the issue: import yt import numpy as np ds.quan(float(19.97536), 'Mpccm/h') center = [ds.quan(19.97536, 'Mpccm/h'), ds.quan(19.58991, 'Mpccm/h'), ds.quan(20.38296, 'Mpccm/h')] rvir = ds.quan(185.12684881603383, 'kpc') ds = yt.load('/Volumes/My Passport for Mac/VELAhalos_4_1_2021/GEN6/VELA07_snap/10MpcBox_csf512_a0.500.d') sp = ds.sphere(center, rvir) #space = np.logspace(-2,0,30) radius_bins = ds.arr(np.logspace(-2, 0, 30)*float(rvir), 'kpc') #print(radius_bins) #create the profile rp_darkmatter = yt.create_profile(sp, ('darkmatter', 'particle_radius'), [('darkmatter', 'particle_mass')], accumulation = True, units = {('darkmatter', 'particle_radius'): 'kpc', ('darkmatter', 'particle_mass'): 'Msun'}, weight_field=None, override_bins={('darkmatter', 'particle_radius'): radius_bins}) #now just find the mass within the smallest sphere to compare sp = ds.sphere(center, (1.85126849, 'kpc')) darkmatter_mass_rvir= sp.quantities.total_quantity([('darkmatter', 'particle_mass')]) Here is the outputs for the profile: print(rp_darkmatter.x_bins) print(rp_darkmatter[('darkmatter', 'particle_mass')]) [ 1.85126849 2.16987605 2.5433167 2.98102735 3.49406901 4.09540631 4.80023514 5.62636664 6.59467727 7.72963638 9.05992455 10.61915839 12.44673994 14.58885248 17.09962751 20.0425127 23.49187518 27.53488087 32.27369713 37.82807456 44.3383731 51.96910898 60.91311203 71.39639856 83.68388279 98.08607129 114.96690951 134.75297878 157.94427603 185.12684882] kpc [1.71640907e+09 4.08670014e+09 7.29731648e+09 1.15396909e+10 1.70891641e+10 2.43093919e+10 3.36631560e+10 4.56267933e+10 6.02872054e+10 7.78791509e+10 9.85060803e+10 1.22442170e+11 1.49759934e+11 1.80141955e+11 2.13532847e+11 2.51746816e+11 2.95421277e+11 3.46319791e+11 4.05501975e+11 4.73278346e+11 5.52642140e+11 6.41302652e+11 7.43654270e+11 8.45108184e+11 9.51028253e+11 1.06624695e+12 1.17616790e+12 1.29792900e+12 1.43690732e+12] Msun And here is the result for the two inner most spheres centered at the same center: 3597806296.1175537 Msun - 1.85126849 kpc 4420085989.534953 Msun - 2.16987605 kpc This is not the same mass as found by any of the inner spheres of the profile, and contains over twice as big as the inner most sphere. I have tried this for several radii, and it appears to always be off by a bit, but the difference gets smaller as the radii gets larger, as shown by a sphere for the total virial radius: 1440505125868.4753 Msun - 185.12684882 kpc Vs the total mass enclosed in the profile of 1.43690732e+12 (only about a 1% difference). I am wondering if there might be something wrong how I am using this, or if there is an issue with the profile maker. I had asked about profile before, and was told to use the rp_darkmatter.x, but rp_darkmatter.x_bins field for the radii. Has something been changed in this function? (Note, I have tried looking at the rp_darkmatter.x radii, but those also do not agree with a ds.sphere of the same radii) (PSS: This is using yt 3.5.1, as I tried to update to 3.6.1 and ran into an error importing yt)
Hi Sean, After looking this over, I *think* what you’re running into here is the fact that the x_bins property of the profile gives you the bin *edges*, whereas the x property of the profile gives you the bin centers. If you count the number of elements in rp_darkmatter.x_bins, it should be one more than the number of elements in rp_darkmatter[('darkmatter', 'particle_mass’)]. So the value of rp_darkmatter[('darkmatter', 'particle_mass’)][0] is the total particle mass enclosed between the radii of rp_darkmatter.x_bins[0] and rp_darkmatter.x_bins[1], and so on for the other values with increasing radii. Of course, this means that any mass interior to rp_darkmatter.x_bins[0] is not counted anywhere in the profile, which in your case is ~1.85 kpc. Whereas when you computed the total DM mass within the sphere of radius 1.85 kpc using sp.quantities.total_quantity([('darkmatter', 'particle_mass’)], it is including everything down to r = 0, within 1.85 kpc, which is an entirely different thing that’s being calculated than in the profile. In any case, this means that within 1.85 kpc, the mass is 4420085989.534953 (from using total_quantity out to 2.17 kpc as you showed below) minus the value of your first bin in the profile, which is 1.71640907e+09. The difference of these two numbers is 2703676919.534953, which is about 25% different from what you calculated using the 1.85 kpc sphere alone, 3597806296.1175537. Now I would have suspected that these two numbers should be identical, and I’m not sure why they aren't, but it probably has to do with subtle differences between sphere spatial selection and profile spatial selection in yt. I hope this points you in the right direction—I think most of this issue has to do with the fact that in your log-spaced profile you are not counting the mass interior to x_bins[0]. Best, John Z
On Apr 22, 2021, at 9:57 PM, Sean Larkin via yt-users
wrote: Hello All,
I am doing some work using the yt.create_profile function, and it seems to be returning incorrect results, but that may be based just me misunderstanding something. I am currently working on collecting the dark matter profile within the virial radius of halos in an ART simulation, and have been using this create_profile function for a while. It was pointed out to me that two different profiles I created (one linearly spaced, and one logarithmacilly spaced seemed to disagree on the total mass in a given sphere. Upon looking into this I noticed that there appears to be a drastic falloff in mass for the inner most profiles which does not appear physical. Here is a script that shows the issue:
import yt
import numpy as np
ds.quan(float(19.97536), 'Mpccm/h') center = [ds.quan(19.97536, 'Mpccm/h'), ds.quan(19.58991, 'Mpccm/h'), ds.quan(20.38296, 'Mpccm/h')]
rvir = ds.quan(185.12684881603383, 'kpc')
ds = yt.load('/Volumes/My Passport for Mac/VELAhalos_4_1_2021/GEN6/VELA07_snap/10MpcBox_csf512_a0.500.d')
sp = ds.sphere(center, rvir)
#space = np.logspace(-2,0,30) radius_bins = ds.arr(np.logspace(-2, 0, 30)*float(rvir), 'kpc') #print(radius_bins)
#create the profile rp_darkmatter = yt.create_profile(sp, ('darkmatter', 'particle_radius'), [('darkmatter', 'particle_mass')], accumulation = True, units = {('darkmatter', 'particle_radius'): 'kpc', ('darkmatter', 'particle_mass'): 'Msun'}, weight_field=None, override_bins={('darkmatter', 'particle_radius'): radius_bins})
#now just find the mass within the smallest sphere to compare sp = ds.sphere(center, (1.85126849, 'kpc')) darkmatter_mass_rvir= sp.quantities.total_quantity([('darkmatter', 'particle_mass')])
Here is the outputs for the profile:
print(rp_darkmatter.x_bins) print(rp_darkmatter[('darkmatter', 'particle_mass')])
[ 1.85126849 2.16987605 2.5433167 2.98102735 3.49406901 4.09540631 4.80023514 5.62636664 6.59467727 7.72963638 9.05992455 10.61915839 12.44673994 14.58885248 17.09962751 20.0425127 23.49187518 27.53488087 32.27369713 37.82807456 44.3383731 51.96910898 60.91311203 71.39639856 83.68388279 98.08607129 114.96690951 134.75297878 157.94427603 185.12684882] kpc [1.71640907e+09 4.08670014e+09 7.29731648e+09 1.15396909e+10 1.70891641e+10 2.43093919e+10 3.36631560e+10 4.56267933e+10 6.02872054e+10 7.78791509e+10 9.85060803e+10 1.22442170e+11 1.49759934e+11 1.80141955e+11 2.13532847e+11 2.51746816e+11 2.95421277e+11 3.46319791e+11 4.05501975e+11 4.73278346e+11 5.52642140e+11 6.41302652e+11 7.43654270e+11 8.45108184e+11 9.51028253e+11 1.06624695e+12 1.17616790e+12 1.29792900e+12 1.43690732e+12] Msun
And here is the result for the two inner most spheres centered at the same center: 3597806296.1175537 Msun - 1.85126849 kpc 4420085989.534953 Msun - 2.16987605 kpc
This is not the same mass as found by any of the inner spheres of the profile, and contains over twice as big as the inner most sphere. I have tried this for several radii, and it appears to always be off by a bit, but the difference gets smaller as the radii gets larger, as shown by a sphere for the total virial radius:
1440505125868.4753 Msun - 185.12684882 kpc
Vs the total mass enclosed in the profile of 1.43690732e+12 (only about a 1% difference).
I am wondering if there might be something wrong how I am using this, or if there is an issue with the profile maker. I had asked about profile before, and was told to use the rp_darkmatter.x, but rp_darkmatter.x_bins field for the radii. Has something been changed in this function? (Note, I have tried looking at the rp_darkmatter.x radii, but those also do not agree with a ds.sphere of the same radii) (PSS: This is using yt 3.5.1, as I tried to update to 3.6.1 and ran into an error importing yt) _______________________________________________ yt-users mailing list -- yt-users@python.org To unsubscribe send an email to yt-users-leave@python.org https://mail.python.org/mailman3/lists/yt-users.python.org/ Member address: jzuhone@gmail.com
participants (2)
-
John Zuhone
-
sflarkin@ucsc.edu