<div dir="ltr">Dear yt-users,<div><br></div><div>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.</div><div><br></div><div>Could you tell me what's wrong with me?</div><div>I tried on yt example dataset, <span style="color:rgb(197,156,156);font-family:Menlo;font-size:11px">IsolatedGalaxy/galaxy0030/galaxy0030</span>.</div><div>I'm working with yt-3.4.0.</div><div><br></div><div>this is my code:</div><div><br></div><div><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(208,59,255)"><span style="font-variant-ligatures:no-common-ligatures">import</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> yt</span></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(208,59,255)">from</span><span style="font-variant-ligatures:no-common-ligatures"> yt.data_objects.particle_filters </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(208,59,255)">import</span><span style="font-variant-ligatures:no-common-ligatures"> add_particle_filter</span></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(208,59,255)">def</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(94,52,255)">stars</span><span style="font-variant-ligatures:no-common-ligatures">(pfilter, data):</span></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(239,118,238)">filter</span><span style="font-variant-ligatures:no-common-ligatures"> = data[(pfilter.filtered_type, </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(197,156,156)">"particle_type"</span><span style="font-variant-ligatures:no-common-ligatures">)] == 2</span></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(208,59,255)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">    </span><span style="font-variant-ligatures:no-common-ligatures">return</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(239,118,238)">filter</span></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(208,59,255)">def</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(94,52,255)">DMparticles</span><span style="font-variant-ligatures:no-common-ligatures">(pfilter, data):</span></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(239,118,238)">filter</span><span style="font-variant-ligatures:no-common-ligatures"> = data[(pfilter.filtered_type, </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(197,156,156)">"particle_type"</span><span style="font-variant-ligatures:no-common-ligatures">)] == 1</span></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(208,59,255)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">    </span><span style="font-variant-ligatures:no-common-ligatures">return</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(239,118,238)">filter</span></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">add_particle_filter(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(197,156,156)">"stars"</span><span style="font-variant-ligatures:no-common-ligatures">, function=stars, filtered_type=</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(197,156,156)">'io'</span><span style="font-variant-ligatures:no-common-ligatures">,</span></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">                  requires=[</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(197,156,156)">"particle_type"</span><span style="font-variant-ligatures:no-common-ligatures">])</span></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">add_particle_filter(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(197,156,156)">"DMparticles"</span><span style="font-variant-ligatures:no-common-ligatures">, function=DMparticles, filtered_type=</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(197,156,156)">'io'</span><span style="font-variant-ligatures:no-common-ligatures">,</span></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">                   requires=[</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(197,156,156)">"particle_type"</span><span style="font-variant-ligatures:no-common-ligatures">])</span></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(208,59,255)">def</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(94,52,255)">only_DM</span><span style="font-variant-ligatures:no-common-ligatures">(field, data):</span></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(197,156,156)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(208,59,255)">return</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> data[</span><span style="font-variant-ligatures:no-common-ligatures">'deposit'</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">,</span><span style="font-variant-ligatures:no-common-ligatures">'DMparticles_density'</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">]</span></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(208,59,255)">def</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(94,52,255)">DM_in_cell_mass</span><span style="font-variant-ligatures:no-common-ligatures">(field, data):</span></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(197,156,156)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">    </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(208,59,255)">return</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> (data[</span><span style="font-variant-ligatures:no-common-ligatures">'only_DM_Density'</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">]*data[</span><span style="font-variant-ligatures:no-common-ligatures">'cell_volume'</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">])</span></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(197,156,156)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(199,156,36)">ds_all</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">=yt.load(</span><span style="font-variant-ligatures:no-common-ligatures">"~/IsolatedGalaxy/galaxy0030/galaxy0030"</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">)</span></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">ds_all.add_particle_filter(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(197,156,156)">'stars'</span><span style="font-variant-ligatures:no-common-ligatures">)</span></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">ds_all.add_particle_filter(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(197,156,156)">'DMparticles'</span><span style="font-variant-ligatures:no-common-ligatures">)</span></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">ds_all.add_field((</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(197,156,156)">"gas"</span><span style="font-variant-ligatures:no-common-ligatures">, </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(197,156,156)">"only_DM_Density"</span><span style="font-variant-ligatures:no-common-ligatures">), units=</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(197,156,156)">"g/cm**3"</span><span style="font-variant-ligatures:no-common-ligatures">, function=only_DM)</span></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">ds_all.add_field((</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(197,156,156)">"gas"</span><span style="font-variant-ligatures:no-common-ligatures">, </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(197,156,156)">"DM_cell_mass"</span><span style="font-variant-ligatures:no-common-ligatures">), units=</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(197,156,156)">"g"</span><span style="font-variant-ligatures:no-common-ligatures">, function=DM_in_cell_mass)</span></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(199,156,36)">sp</span><span style="font-variant-ligatures:no-common-ligatures"> = ds_all.sphere([0.5, 0.5, 0.5], (10, </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(197,156,156)">"kpc"</span><span style="font-variant-ligatures:no-common-ligatures">))</span></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(199,156,36)">lineplot_gas_DM_density_128</span><span style="font-variant-ligatures:no-common-ligatures"> = yt.ProfilePlot(sp, </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(197,156,156)">"density"</span><span style="font-variant-ligatures:no-common-ligatures">, [</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(197,156,156)">"only_DM_Density"</span><span style="font-variant-ligatures:no-common-ligatures">], weight_field=</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(197,156,156)">"DM_cell_mass"</span><span style="font-variant-ligatures:no-common-ligatures">, n_bins=128)</span></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(199,156,36)">lineplot_gas_DM_density_gasweighted_128</span><span style="font-variant-ligatures:no-common-ligatures"> = yt.ProfilePlot(sp, </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(197,156,156)">"density"</span><span style="font-variant-ligatures:no-common-ligatures">, [</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(197,156,156)">"only_DM_Density"</span><span style="font-variant-ligatures:no-common-ligatures">], weight_field=</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(197,156,156)">"cell_mass"</span><span style="font-variant-ligatures:no-common-ligatures">, n_bins=128)</span></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">lineplot_gas_DM_density_gasweighted_128.save(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(197,156,156)">"128_gasweighted"</span><span style="font-variant-ligatures:no-common-ligatures">)</span></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">lineplot_gas_DM_density_128.save(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(197,156,156)">"128_DMweighted"</span><span style="font-variant-ligatures:no-common-ligatures">)</span></p></div><div><br></div><div>Sincerely,</div><div>Y.T.</div></div>