<div dir="ltr">Hi Britton,<div><br></div><div>Thanks very much for your test! The error happens when I make light rays from one single dataset. I tried to reproduce the error with the dataset under src/yt-hg/tests. The code I used is here:</div><div>







<p class=""><span class=""><a href="http://paste.yt-project.org/show/6751/">http://paste.yt-project.org/show/6751/</a></span></p></div><div>After running the code, I did </div><div>







<p class=""><span class="">h5ls -d lightray.h5/grid/redshift</span></p></div><div>and found the last redshift was 9.98999107782409. However, the correct value should be ~ 9.979.</div>







<div><br></div><div>When I call LightRay this way, it will call the _deltaz_forward function in cosmology_splice.py, which will call the comoving_radial_distance in cosmology.py:</div><div>







<p class=""><span class="">        distance2 = </span><span class="">self</span><span class="">.cosmology.comoving_radial_distance(z2, z)</span></p></div>







<div>, where distance2 is not in comoving units. Then it will calculate z2:</div><div><div><br></div><div>            z2 = ((target_distance - distance2) / m.in_units("Mpccm / h")) + z2</div></div><div><br></div><div>. I think the subtraction here is the problem, since it tries to convert distance2 to comoving units, even though the numerical value of distance2 is already comoving. So a wrong factor of (1+z) is multiplied.</div><div><br></div><div>Any comment is appreciated.</div><div><br></div><div>Thanks again for your help!</div><div>Pengfei</div>







</div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 8, 2016 at 7:10 AM, Britton Smith <span dir="ltr"><<a href="mailto:brittonsmith@gmail.com" target="_blank">brittonsmith@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">Hi Pengfei,<div><br></div><div>I'm not able to reproduce what you're seeing, but before I go into that, I can explain a few things about how the cosmology calculator works.  In yt, we are only able to define a comoving unit system in relation to a proper unit system at a specific redshift.  We are unable to define a comoving unit system that is the base unit system.  This is a problem for the cosmology calculator, which only calculates comoving quantities.  Therefore, in this case, we are forced to set the comoving and proper unit systems to be the same.  You can see this for yourself by running the following script:</div><div><br></div><div><div>from yt.utilities.cosmology import Cosmology</div><div>co = Cosmology()</div><div>print (co.comoving_radial_distance(<wbr>1.92, 2).to("Mpc/h"))</div><div>print (co.comoving_radial_distance(<wbr>1.92, 2).to("Mpccm/h"))</div></div><div><br></div><div>Both will be the same answer.</div><div><br></div><div>Now, back to the issue you're seeing.  I ran the following script:</div><div><a href="http://paste.yt-project.org/show/6741/" target="_blank">http://paste.yt-project.org/<wbr>show/6741/</a><br></div><div>to calculate the redshifts dumps needed for a 80 Mpc/h box to go from z = 2 to z = 1.92 and got the following result:</div><div><div>CosmologyOutputRedshift[0] = 2.000</div><div>CosmologyOutputRedshift[1] = 1.926</div></div><div><br></div><div>This is pretty close to what you expected.  Additionally, if I run the following script, </div><div><a href="http://paste.yt-project.org/show/6743/" target="_blank">http://paste.yt-project.org/<wbr>show/6743/</a><br></div><div>with the above redshifts added to the parameter file, I get that dz_max (the change in redshift when moving 80 Mpccm/h at z = 0) of 0.0746521607364, which also seems to agree with what you are finding.</div><div><br></div><div>Can you share with me the simulation parameter file and script that you're using to make your light rays?  I can take a look at that and see if I still get what I expect.</div><div><br></div><div>Britton</div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Mon, Aug 8, 2016 at 6:13 AM, Pengfei Chen <span dir="ltr"><<a href="mailto:madcpf@gmail.com" target="_blank">madcpf@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr">Hi all,<div><br></div><div>I was trying to generate light rays using yt 3.4-dev, but found that the light rays have wrong redshift intervals. For example, my simulation box is 80Mpccm/h per side, and I expect a light ray generated in a data dump at z=2 with length =1 simulation unit (i.e. 80Mpccm/h) would have a redshift interval from z=2 to z=1.92. However, the light ray generated by yt gives spans from z=2 to z=1.97.</div><div><br></div><div>As I look into this, I found that the function comoving_radial_distance in cosmology.py might return the wrong unit. I think the return value should be in comoving units, instead of physical units. To see this directly, I made the following change in cosmology_splice.py:</div><div><br></div><div><div>(root) ~/yt-conda/src/yt-hg/yt/analys<wbr>is_modules/cosmological_observ<wbr>ation $diff cosmology_splice.py cosmology_splice.py0</div><div>373d372<br></div><div><             print target_distance, distance2, z2</div></div><div><br></div><div>And it shows:</div><div><br></div><div><div>80.0 Mpccm/h 4.65320708035e+26 cm 1.97387969592 dimensionless</div><div>80.0 Mpccm/h 1.19455177073e+26 cm 1.97343368065 dimensionless</div><div>80.0 Mpccm/h 1.21507519065e+26 cm 1.97342592996 dimensionless</div></div><div><br></div><div><div>Then I made the following change in cosmology.py:</div><div><br></div><div><div>(root) ~/yt-conda/src/yt-hg/yt/utilit<wbr>ies $diff cosmology.py cosmology.py0</div><div>111,112c111,112</div><div><         return self.quan((self.hubble_distanc<wbr>e() *</div><div><                 trapzint(self.inverse_expansio<wbr>n_factor, z_i, z_f)).value, 'cmcm')</div><div>---</div><div>>         return (self.hubble_distance() *</div><div>>                 trapzint(self.inverse_expansio<wbr>n_factor, z_i, z_f)).in_base(self.unit_system<wbr>)</div></div></div><div><br></div><div><br></div><div>Then I get:</div><div><div>80.0 Mpccm/h 4.65320708035e+26 cmcm 1.92163908776 dimensionless</div><div>80.0 Mpccm/h 3.62771515661e+26 cmcm 1.92124702027 dimensionless</div></div><div><br></div><div>With the change of unit from cm to cmcm, the light rays have the right span.</div><div><br></div><div>Even though this solves my problem, I am not sure if similar problem still exists. For example, instead of making change in comoving_radial_distance, we might need to change hubble_distance into comoving units. Hopefully someone familiar with yt unit system could check this.</div><div><br></div><div>Thanks,<br>Pengfei</div>































</div>
<br></div></div>______________________________<wbr>_________________<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/lis<wbr>tinfo.cgi/yt-users-spacepope.<wbr>org</a><br>
<br></blockquote></div><br></div>
<br>______________________________<wbr>_________________<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/<wbr>listinfo.cgi/yt-users-<wbr>spacepope.org</a><br>
<br></blockquote></div><br></div>