Hi Sean,

I suspect the issue is that rp1.x is the array of bin centers, but the bin edges are stored in rp1.x_bins, which will be of length N+1. You might try the comparison again using spheres of radius rp1.x_bins[index+1].

Britton

On Wed, Apr 29, 2020 at 9:08 PM Sean Larkin <seanfrancislarkin@gmail.com> wrote:
Hey Britton,

Thanks for the suggestion. I did not see that field when looking through the field list, and it seems to fix the issue well. Now I am possibly having an issue with this profile when comparing to what I think is what should be the same data. I noticed this while trying to fix a misunderstanding what the weight_field parameter did, so I may just be continuing to misunderstand something, but want to make sure.

Here is the script that illustrates the issue I am having:

import yt
from yt import YTQuantity

largest_halo = consistent.halo_data_sorted[30][0]

ds = yt.load('/Users/user1/documents/GEN6/VELA07_snap/10MpcBox_csf512_a0.400.d')

x = ds.quan(float(largest_halo[17]), 'Mpccm/h')
y = ds.quan(float(largest_halo[18]), 'Mpccm/h')
z = ds.quan(float(largest_halo[19]), 'Mpccm/h')
rvir = ds.quan(float(largest_halo[11]), 'kpccm/h')
center = [x, y, z]

sp = ds.sphere(center, (float(rvir.in_units('kpc')), 'kpc'))

#rp = yt.create_profile(sp, 'radius', [('gas', 'density')], n_bins=4, accumulation = True,
#                           units = {'radius': 'kpc', 'density': 'Msun/kpc**3'})

rp1 = yt.create_profile(sp, 'particle_radius', [('all', 'particle_mass')], accumulation = True,
                           units = {'particle_radius': 'kpc', 'particle_mass': 'Msun'}, weight_field=None)

massbysphere = []

for radii in rp1.x:
    sp3 = ds.sphere(center, (float(radii), 'kpc'))
    massbysphere.append(sp3.quantities.total_quantity([('all', 'particle_mass')]).in_units('Msun'))

for index in range(len(massbysphere)):
    print(rp1['all', 'particle_mass'][index], massbysphere[index], rp1['all', 'particle_mass'][index]-massbysphere[index])



What I am doing here is making a profile of the particle_mass based on the particle_radius, as in the issue solved above. This is the rp1 object. Since the weight_field is false, this profile should just be returning the sums of all particle_mass within the bins, and since the accumulation is True, each value should be the sum of all of the bins up to the current one. In short, from what I understand, this profile should just be the total particle_mass within each radius of the profile. This profile seems is now created correctly due to the particle_radius field, but I am having some issues with the data it is generating.

To show this problem, I have set up the for radii in rp1.x loop. This just takes the radii used by the profile object, and calculates the total particle_mass within a sphere of radius that the profile uses. From my understanding, these two methods should produce the same value. However, here is a comparison of both:

Profile Values                                ds.sphere values                          Difference
83159.35410774668 Msun 83159.35410774668 Msun 0.0 Msun
166318.70821549336 Msun 166318.70821549336 Msun 0.0 Msun
249478.06232324004 Msun 249478.06232324004 Msun 0.0 Msun
249478.06232324004 Msun 249478.06232324004 Msun 0.0 Msun
249478.06232324004 Msun 249478.06232324004 Msun 0.0 Msun
415796.7705387334 Msun 249478.06232324004 Msun 166318.70821549336 Msun
796095.2737129169 Msun 469597.4315641475 Msun 326497.84214876936 Msun
1176911.7216399934 Msun 997807.4956533725 Msun 179104.22598662088 Msun
1530223.9518534143 Msun 1262193.7543518362 Msun 268030.19750157814 Msun
2303637.194162465 Msun 1946020.722392148 Msun 357616.47177031706 Msun
3368132.0818114113 Msun 3077824.8652968905 Msun 290307.2165145208 Msun
5367070.705443867 Msun 4420298.461235261 Msun 946772.244208606 Msun
8412516.958967673 Msun 6530768.038707411 Msun 1881748.9202602617 Msun
12065222.471638702 Msun 10137022.99302278 Msun 1928199.478615921 Msun
16291241.455885464 Msun 14542532.792480856 Msun 1748708.6634046081 Msun
23070515.00150906 Msun 19828776.422735278 Msun 3241738.5787737817 Msun
33259855.130330868 Msun 28492797.917437937 Msun 4767057.212892931 Msun
45919301.65254922 Msun 39099666.67069177 Msun 6819634.981857449 Msun
66156157.60428917 Msun 54237258.43434696 Msun 11918899.169942208 Msun
92970164.63046609 Msun 79599241.96234518 Msun 13370922.668120906 Msun
132155089.8228528 Msun 110591601.38418552 Msun 21563488.438667282 Msun
190192094.94335926 Msun 160315871.50117832 Msun 29876223.44218093 Msun
277920953.8468867 Msun 231971900.24583715 Msun 45949053.60104954 Msun
394021726.67128986 Msun 331545441.9839491 Msun 62476284.68734074 Msun
569482674.797049 Msun 474685738.73410463 Msun 94796936.06294441 Msun
816201292.0237103 Msun 683019856.6283534 Msun 133181435.3953569 Msun
1171332770.8400025 Msun 979970023.2377394 Msun 191362747.6022631 Msun
1718144643.4919553 Msun 1425802404.530043 Msun 292342238.9619124 Msun
2533794476.7099442 Msun 2090154937.1532123 Msun 443639539.55673194 Msun
3736961046.5822906 Msun 3082631771.9124036 Msun 654329274.6698871 Msun
5643551722.483292 Msun 4611813828.94564 Msun 1031737893.537652 Msun
8654391307.323744 Msun 6987943056.5117035 Msun 1666448250.8120403 Msun
13632977170.470148 Msun 10902464502.390213 Msun 2730512668.079935 Msun
21940275719.6288 Msun 17424483946.03078 Msun 4515791773.598019 Msun
34675310473.09914 Msun 28383619631.259476 Msun 6291690841.839661 Msun
48305210816.824326 Msun 41525817177.719765 Msun 6779393639.104561 Msun
63131177375.8879 Msun 55770882010.02951 Msun 7360295365.858391 Msun
79314962566.46469 Msun 71271379420.24701 Msun 8043583146.217682 Msun
97095635794.43866 Msun 88251223928.01863 Msun 8844411866.420029 Msun
116063420309.91327 Msun 106665694057.06548 Msun 9397726252.847794 Msun
135533180094.37088 Msun 126022922965.82726 Msun 9510257128.543625 Msun
155646999147.89078 Msun 145790971208.65002 Msun 9856027939.240753 Msun
176753500847.7627 Msun 166397621613.24057 Msun 10355879234.522125 Msun
198964374971.99426 Msun 188008444733.5007 Msun 10955930238.49356 Msun
222156818553.0722 Msun 210778289952.58505 Msun 11378528600.487152 Msun
246561049625.35162 Msun 234558219539.49835 Msun 12002830085.853271 Msun
272213489294.873 Msun 259608234565.29123 Msun 12605254729.581757 Msun
299068169157.3915 Msun 285829870854.13196 Msun 13238298303.259521 Msun
328038951227.93896 Msun 313639011433.0674 Msun 14399939794.871582 Msun
359856879077.02704 Msun 344100356408.82886 Msun 15756522668.198181 Msun
394969404661.22974 Msun 377517339073.7443 Msun 17452065587.485413 Msun
433611156575.81775 Msun 414361334070.6628 Msun 19249822505.15497 Msun
476247488785.28235 Msun 455028260349.85095 Msun 21219228435.431396 Msun
522677378866.6877 Msun 499757952809.8332 Msun 22919426056.854492 Msun
572382093035.1168 Msun 547779502497.86523 Msun 24602590537.251587 Msun
629601117587.4315 Msun 600442822340.7622 Msun 29158295246.66931 Msun
696359824440.2887 Msun 662604372802.9868 Msun 33755451637.30188 Msun
777093681313.162 Msun 735427520469.8046 Msun 41666160843.35742 Msun
882456504694.5624 Msun 828138492661.0006 Msun 54318012033.56177 Msun
989778561664.4609 Msun 937384677465.783 Msun 52393884198.67798 Msun
1097723366391.0186 Msun 1045915036493.5972 Msun 51808329897.42139 Msun
1202581289394.909 Msun 1152229991790.4731 Msun 50351297604.43579 Msun
1319196539060.7722 Msun 1260339742590.6423 Msun 58856796470.12988 Msun
1425698510781.3452 Msun 1378017366466.7822 Msun 47681144314.56299 Msun


As can be seen by the third column, the values vary signifigantly between the two methods, with the profile values always skewing larger than the ds.sphere values. I am not sure if this is a bug, or just me using the profile incorrectly, or me misunderstanding what the profile is calculating.

On Mon, Apr 27, 2020 at 3:21 AM Britton Smith <brittonsmith@gmail.com> wrote:
Hi Sean,

Sorry to take so long to get back to you on this. You should be able to accomplish this with the `particle_radius` field. Let me know if that doesn't work. We'll try to be a bit more responsive.

Britton

On Fri, Apr 17, 2020 at 7:58 PM Sean Larkin via yt-users <yt-users@python.org> wrote:
Hello All,

I am trying to calculate the Mvir/Rvir based on the Bryan Norman definition using yt. I currently have a catalog of halos generated by running rockstar on the darkmatter particles of an ART simulation, and am trying to use the same centers to recalculate these values including the stellar and gas contents of each object. From looking into some of the yt processes, I thought that the profile function would be a perfect tool, but it seems like there is a bit of a problem with particle grids vs mesh grids that I am not sure if there is a way around.

My goal was to use the yt.create_profile function to create a radial profile of the different masses using the following script:

import yt
from yt import YTQuantity

largest_halo = consistent.halo_data_sorted[30][0]

ds = yt.load('/Users/user1/documents/GEN6/VELA07_snap/10MpcBox_csf512_a0.400.d')

x = ds.quan(float(largest_halo[17]), 'Mpccm/h')
y = ds.quan(float(largest_halo[18]), 'Mpccm/h')
z = ds.quan(float(largest_halo[19]), 'Mpccm/h')
rvir = ds.quan(float(largest_halo[11]), 'kpccm/h')
center = [x, y, z]

sp = ds.sphere(center, (float(rvir.in_units('kpc'))*2, 'kpc'))

rp = yt.create_profile(sp, 'radius', [('gas', 'density')], n_bins=4, accumulation = True,
                           units = {'radius': 'kpc', 'density': 'Msun/kpc**3'})

rp1 = yt.create_profile(sp, 'radius', [('all', 'particle_mass')], n_bins=4, accumulation = True,
                           units = {'radius': 'kpc'}, weight_field='particle_mass')


This works perfectly for the gas, but I get the following error for the profile calculating the particle masses:

YTIllDefinedProfile:
Cannot create a profile object that mixes particle and mesh fields.

Received the following bin_fields:

   ('index', 'radius'), particle_type = False

Profile fields:

   ('all', 'particle_mass'), particle_type = True

And weight field:

   ('all', 'particle_mass'), particle_type = True

I am wondering if there is another radial-like field/it is possible to create such a field to make this profile properly match the particle_type? If not, are there any other yt functions that would simplify such an Mvir/Rvir calculation. I know it is possible to do this with a ds.sphere script call that varies the size of the region until the proper ratio is found, but I imagine that would not be a super efficient method, and it also might be interesting to see the density profile of each halo object outside of calculating its Mvir/Rvir.

Thank you for your time!
_______________________________________________
yt-users mailing list -- yt-users@python.org
To unsubscribe send an email to yt-users-leave@python.org
_______________________________________________
yt-users mailing list -- yt-users@python.org
To unsubscribe send an email to yt-users-leave@python.org
_______________________________________________
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/