<div dir="ltr">Hello Nathan,<div><br></div><div>I checked the code, and it is not correct, as what you said. It should be: <span style="color:rgb(80,0,80);font-size:14px">ed = density_image</span><span style="color:rgb(80,0,80);font-size:14px">.convert_to_cgs() </span><span style="font-size:14px"><font color="#000000">instead of  </font></span><span style="color:rgb(80,0,80);font-size:14px">ed = density_image['Electron_</span><span style="color:rgb(80,0,80);font-size:14px">Density'].convert_to_cgs(). </span></div><div><span style="color:rgb(80,0,80);font-size:14px"><br></span></div><div><span style="font-size:14px"><font color="#000000">I used the </font></span><span style="color:rgb(80,0,80);font-size:14px">dd.quantities.weighted_</span><span style="color:rgb(80,0,80);font-size:14px">average_quantity('Electron_Density', weight='cell_volume'), </span><span style="font-size:14px"><font color="#000000">and I got a sum close to the sum I got from the projection. </font></span></div><div><span style="font-size:14px"><font color="#000000"><br></font></span></div><div><span style="font-size:14px"><font color="#000000">Thank you for your help!</font></span></div><div><span style="font-size:14px"><font color="#000000"><br></font></span></div><div><span style="font-size:14px"><font color="#000000">Best,</font></span></div><div><span style="font-size:14px"><font color="#000000">Hansheng</font></span></div><div><span style="color:rgb(80,0,80);font-size:14px"><br></span></div><div><span style="color:rgb(80,0,80);font-size:14px"><br></span></div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-06-27 13:18 GMT-04:00 Nathan Goldbaum <span dir="ltr"><<a href="mailto:nathan12343@gmail.com" target="_blank">nathan12343@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span class="">On Mon, Jun 27, 2016 at 12:14 PM, Nathan Goldbaum <span dir="ltr"><<a href="mailto:nathan12343@gmail.com" target="_blank">nathan12343@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span>On Mon, Jun 27, 2016 at 11:59 AM, Hansheng Chen <span dir="ltr"><<a href="mailto:jasonhs1221@gmail.com" target="_blank">jasonhs1221@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hello yt users, <div><br></div><div>I have a question about projection. I used ds.proj() and to_frb() to get an image array of the projected 'Electron_Density' of an entire dataset. I multiplied the mean of projected 'Electron_Density' by the entire area of x-y plane and got a sum of total mass of electrons. Then, I used ds.all_data() and mean() to get the mean of 'Electron_Density' in 3-dimensional. I multiplied the mean by the volume of the entire box of the dataset and got another sum of total mass of electrons. However, this sum did not match the sum I got from the projected 'Electron_Density' previously. Here are the codes I used:</div><div><br></div><div><div>import yt</div><div>import numpy as np</div><div>ds = yt.load("redshift0100/redshift0100")</div><div>print("Redshift =", ds.current_redshift)</div></div><div><br></div><div>p = yt.ProjectionPlot(ds, 2, 'Electron_Density')<br></div><div><div>density_image = p.frb['Electron_Density']</div><div>ed = density_image['Electron_Density'].convert_to_cgs()</div></div></div></blockquote><div><br></div></span><div>Are you sure this code would run? I'm pretty sure this line would produce an IndexError, since you can't use a string to index into an array.</div><span><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>ed_ndarr = ed.to_ndarray()<br></div><div>sum1 = ed_ndarr.mean() * ((105.82 * 3.085677581e+24)**2)<br></div><div>print(sum1)</div><div><br></div><div>dd = ds.all_data()<br></div><div>ed_3d = dd['Electron_Density'].convert_to_cgs()<br></div><div>sum2 = ed_3d.mean() * ((105.82 * 3.085677581e+24)**3)</div><div>print(sum2)</div></div></blockquote><div><br></div></span><div>You're not comparing apples and oranges here. </div></div></div></div></blockquote><div><br></div></span><div>Oops, meant to say "you're comparing apples and oranges here"</div><span class=""><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>In particular, in this section, you've found the mean density of cells in your simulation. If you have an AMR simulation, each cell is not necessarily the same size, so they do not contribute equally if you want to find the true, volume or mass-weighted mean density in your simulation.</div><div><br></div><div>It would be a closer comparison to use a covering grid, or you could ask for a volume-weighted mean:</div><div><br></div><div><div>In [18]: dd.quantities.weighted_average_quantity('El_density', weight='cell_volume</div><div>    ...: ')</div><div>Out[18]: 5.54459040433e-34 g/cm**3</div></div><div><br></div><div>This script makes use of a public test dataset from <a href="http://yt-project.org/data" target="_blank">yt-project.org/data</a> and illustrates the point I'm making:</div><div><br></div><div><a href="https://bpaste.net/show/2eab176d8128" target="_blank">https://bpaste.net/show/2eab176d8128</a><br></div><div><br></div><div>On my machine, both operations print out the same result to machine precision.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><span><div dir="ltr"><div><br></div><div>(105.82 * 3.085677581e+24) is the width of entire box in cm. I think sum1 and sum2 should be close to each other, but the result was that the two values did not match with each other. Is there any problem in the codes I used to get the values of sum1 and sum2? Could some one give me some help?</div><div><br></div><div>Thank you very much!</div><div><br></div><div>Sincerely,</div><div>Hansheng</div><div><br></div></div>
<br></span>_______________________________________________<br>
yt-users mailing list<br>
<a href="mailto:yt-users@lists.spacepope.org" target="_blank">yt-users@lists.spacepope.org</a><br>
<a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br>
<br></blockquote></div><br></div></div>
</blockquote></span></div><br></div></div>
<br>_______________________________________________<br>
yt-users mailing list<br>
<a href="mailto:yt-users@lists.spacepope.org">yt-users@lists.spacepope.org</a><br>
<a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br>
<br></blockquote></div><br></div>