[yt-users] About ProfilePlot

tyuta y0u1t1a5.t at gmail.com
Wed Oct 18 15:54:04 PDT 2017


Dear Nathan,

Thank you for your quick modification, and the detailed instruction! I will
try reinstallation.

Thanks,
Y.T.

2017-10-18 17:43 GMT-04:00 Nathan Goldbaum <nathan12343 at gmail.com>:

> This is a bug. Thank you for the excellent report that allowed me to
> reproduce exactly what you're seeing and figure out what's going wrong.
>
> The issue was that you were passing a weight field that had zeros in the
> first entry. This triggered a corner case in the low-level C code that
> calculates the ND histogram the profile object uses under the hood,
> introducing NaNs into the calculation. The NaNs caused the holes you saw in
> the final plot. The fix is to catch the case when the weight field is zero
> and ignore those field values.
>
> I've issued a pull request with a fix for your issue:
>
> https://github.com/yt-project/yt/pull/1590
>
> To get the fix, you are going to need to build yt from source and then
> check out my pull request locally. Here are some instructions on how to do
> that:
>
> 1. Uninstall your current yt installation. If you use conda, use "conda
> uninstall yt". If you use pip, use "pip uninstall yt".
> 2. Navigate to a place on your hard disk where you put software and clone
> the yt git repository: "git clone https://github.com/yt-project/yt"
> 3. Go into the yt repo, "cd yt"
> 4. Fetch my pull request and then check it out: "git fetch origin
> pull/1590/head:profile-zero-weight", "git checkout profile-zero-weight".
> 5. Build yt from source, "pip install -e ."
>
> You may need to install cython before building yt if you don't already
> have it installed.
>
> Hope that helps and thanks again for the detailed report!
>
> -Nathan
>
> On Wed, Oct 18, 2017 at 1:59 PM, tyuta <y0u1t1a5.t at gmail.com> wrote:
>
>> Dear yt-users,
>>
>> Hi, I have a question on ProfilePlot. I want to make profile plot of dark
>> matter density, taking gas density as a bin field, weighted by dark matter
>> mass in the cell.I could make the plot, but the plot looks strange (it
>> looks like chopped in small pieces). Also, I tried other plot changing
>> n_bins like 64,32,16,8,... but they still be "chopped", or sometimes there
>> were no line at all. For comparison, I made a plot weighted by cell_mass
>> (which I don't want), and this look OK. To my understanding, if and only if
>> there is at least 1 cell which fall into each bin, there should be some
>> nonzero value no matter what weight I use, so the range of density which
>> has nonzero dark matter density doesn't depend on the choice of weight
>> field. It seems there is a discrepancy between these two plots.
>>
>> Could you tell me what's wrong with me?
>> I tried on yt example dataset, IsolatedGalaxy/galaxy0030/galaxy0030.
>> I'm working with yt-3.4.0.
>>
>> this is my code:
>>
>> import yt
>>
>> from yt.data_objects.particle_filters import add_particle_filter
>>
>>
>> def stars(pfilter, data):
>>
>>     filter = data[(pfilter.filtered_type, "particle_type")] == 2
>>
>>     return filter
>>
>> def DMparticles(pfilter, data):
>>
>>     filter = data[(pfilter.filtered_type, "particle_type")] == 1
>>
>>     return filter
>>
>>
>> add_particle_filter("stars", function=stars, filtered_type='io',
>>
>>                   requires=["particle_type"])
>>
>> add_particle_filter("DMparticles", function=DMparticles, filtered_type=
>> 'io',
>>
>>                    requires=["particle_type"])
>>
>>
>> def only_DM(field, data):
>>
>>     return data['deposit','DMparticles_density']
>>
>> def DM_in_cell_mass(field, data):
>>
>>     return (data['only_DM_Density']*data['cell_volume'])
>>
>>
>> ds_all=yt.load("~/IsolatedGalaxy/galaxy0030/galaxy0030")
>>
>>
>> ds_all.add_particle_filter('stars')
>>
>> ds_all.add_particle_filter('DMparticles')
>>
>>
>> ds_all.add_field(("gas", "only_DM_Density"), units="g/cm**3",
>> function=only_DM)
>>
>> ds_all.add_field(("gas", "DM_cell_mass"), units="g",
>> function=DM_in_cell_mass)
>>
>>
>> sp = ds_all.sphere([0.5, 0.5, 0.5], (10, "kpc"))
>>
>>
>> lineplot_gas_DM_density_128 = yt.ProfilePlot(sp, "density", [
>> "only_DM_Density"], weight_field="DM_cell_mass", n_bins=128)
>>
>> lineplot_gas_DM_density_gasweighted_128 = yt.ProfilePlot(sp, "density", [
>> "only_DM_Density"], weight_field="cell_mass", n_bins=128)
>>
>>
>> lineplot_gas_DM_density_gasweighted_128.save("128_gasweighted")
>>
>> lineplot_gas_DM_density_128.save("128_DMweighted")
>>
>> Sincerely,
>> Y.T.
>>
>> _______________________________________________
>> yt-users mailing list
>> yt-users at lists.spacepope.org
>> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>>
>>
>
> _______________________________________________
> yt-users mailing list
> yt-users at lists.spacepope.org
> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spacepope.org/pipermail/yt-users-spacepope.org/attachments/20171018/47a528fc/attachment.html>


More information about the yt-users mailing list