Hi Sean,

Sorry there's been such a delay to get back to you. I believe the issue you're seeing has to do with how custom units, like little h, are handled in yt's unit system. When you create a YTQuantity, it is attached to a UnitRegistry object under the hood, which keeps track of all the possible unit conversions. When datasets are loaded or cosmology calculators created, a new unit registry is created that keeps track of the value of h. When you make something via YTQuantity, you can attach an existing UnitRegistry with the registry keyword, but if you don't, the default that is created has little h set to 1.0. For example, you can see this by doing:

import yt
r1 = yt.YTQuantity(100, 'kpc/h')

from yt.utilities.cosmology import Cosmology
co = Cosmology(hubble_constant=0.7)
r2 = co.quan(100, 'kpc/h')

print (r1.to('kpc'), r2.to('kpc'))

What you'll see is that only r2 reflects h=0.7. The co.quan command is a helper to create unit quantities using the cosmology calculators unit registry. If you use that in place of YTQuantity, that should help.

One last thing I'll note. The cosmology calculator does not properly convert between the comoving and proper frame. For example, if you do:
x = co.quan(1, 'kpc')
x_com = x.to('kpccm')
This will give you values of x and x_com that are equal, which is only correct at z = 0. Proper and comoving can only be converted correctly when creating quantities from a loaded dataset at a specific redshift. For example,
ds = yt.load(...)
x = ds.quan(1, 'kpc')
print (x.to('kpccm'))

Anyway, sorry to be so long-winded. I hope that helps.

Britton

On Wed, Jul 31, 2019 at 10:41 PM Sean Larkin via yt-users <yt-users@python.org> wrote:
Hello All,

I am currently attempting to compare a catalog with Mvir and Rvir units of Mpc/h and Kpc/h comoving to a catalog with Mpc and Kpc proper. I am currently using yt version 3.5.1, which I just checked for updates.

When doing this conversion of units within yt, there appears to be a problem where an amount of h*h is not handeled properly. I have included a screenshot of a jupyter session that outlines the problem as well as a .py and jupyter script so it can be tested.

The problem arises when I try to calculate delta_vir, which is the density of a galaxy/ critical density. The correct value for both catalogs I am comparing is around 170. When I use yt to calculate the critical density at z = 2, it get the correct value, which I convert to Mpc*h*h//kpc/kpc/kpc to match with my /h catalog. Then, when I divide the densities, even thought their units are identical, their division is different than if just the float values are divided, by an exact factor of h*h. I wonder if there is something wrong with how I am initializing my values with the ytquantity, or if there is something wrong going on in the code.
Screen Shot 2019-07-31 at 2.36.01 PM.png
_______________________________________________
yt-users mailing list -- yt-users@python.org
To unsubscribe send an email to yt-users-leave@python.org