Comparing units from different datasetsΒΆ

Notebook

Units that refer to the internal simulation coordinate system will have different CGS conversion factors in different datasets. Depending on how a unit system is implemented, this could add an element of uncertainty when we compare dimensional array instances produced by different unit systems. Fortunately, this is not a problem for YTArray since all YTArray unit systems are defined in terms of physical CGS units.

As an example, let's load up two enzo datasets from different redshifts in the same cosmology simulation.

In [1]:
# A high redshift output from z ~ 8
import yt

ds1 = yt.load('Enzo_64/DD0002/data0002')
print ("z = %s" % ds1.current_redshift)
print ("Internal length units = %s" % ds1.length_unit)
print ("Internal length units in cgs = %s" % ds1.length_unit.in_cgs())
/usr/lib64/python3.6/site-packages/h5py/__init__.py:34: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
z = 7.8843748886903
Internal length units = 128.0 Mpccm/h
Internal length units in cgs = 6.261455380881711e+25 cm
In [2]:
# A low redshift output from z ~ 0
ds2 = yt.load('Enzo_64/DD0043/data0043')
print ("z = %s" % ds2.current_redshift)
print ("Internal length units = %s" % ds2.length_unit)
print ("Internal length units in cgs = %s" % ds2.length_unit.in_cgs())
z = 0.0013930880640796
Internal length units = 128.0 Mpccm/h
Internal length units in cgs = 5.5551728502644205e+26 cm

Given that these are from the same simulation in comoving units, the CGS length units are different by a factor of $(1+z_1)/(1+z_2)$:

In [3]:
print (ds2.length_unit.in_cgs()/ds1.length_unit.in_cgs() == (1+ds1.current_redshift)/(1+ds2.current_redshift))
True

It's not necessary to convert to CGS units either. yt will automatically account for the fact that a comoving megapaersec in the first output is physically different compared to a comoving megaparsec in the second output.

In [4]:
print (ds2.length_unit/ds1.length_unit)
8.872015389946235 dimensionless

Time series analysis is also straightforward. Since dimensional arrays and quantities carry around the conversion factors to CGS with them, we can safely pickle them, share them with other processors, or combine them without worrying about differences in unit definitions.

The following snippet, which iterates over a time series and saves the length_unit quantity to a storage dictionary. This should work correctly on one core or in a script run in parallel.

In [5]:
import yt
yt.enable_parallelism()

ts = yt.load("Enzo_64/DD????/data????")

storage = {}

for sto, ds in ts.piter(storage=storage):
    sto.result_id = float(ds.current_time.in_units('Gyr'))
    sto.result = ds.length_unit

if yt.is_root():
    for t in sorted(storage.keys()):
        print (t, storage[t].in_units('Mpc'))
0.01676273940629226 1.8028169014084512 Mpc
0.3247048626440744 13.004379088331369 Mpc
0.632651149510049 20.291994923620514 Mpc
0.9405964403842683 26.44507654199263 Mpc
1.2485403178455299 31.960551836194494 Mpc
1.5564877623117352 37.05004845073869 Mpc
1.8644307016392518 41.828976818284 Mpc
2.1723793550089643 46.36965467235576 Mpc
2.4803203208216873 50.72098300904238 Mpc
2.7882672978290066 54.91863310930029 Mpc
3.096215629027159 58.98934575559256 Mpc
3.404156206618686 62.95398325137115 Mpc
3.712100478577947 66.82957833722122 Mpc
4.020051512350332 70.6300703626599 Mpc
4.327994697241795 74.36695572216632 Mpc
4.635937921532979 78.05030128157921 Mpc
4.9438811861356085 81.68874111248732 Mpc
5.251835531680688 85.28997665885913 Mpc
5.559770846794074 88.86037373217331 Mpc
5.867725028896291 92.40638871436397 Mpc
6.175670567007974 95.93314172723768 Mpc
6.483616028998924 99.44568665753908 Mpc
6.791560750573153 102.94856392171005 Mpc
7.099505186480307 106.44598125568383 Mpc
7.407450436082786 109.94185847103901 Mpc
7.715395731056862 113.43984038632928 Mpc
8.023331074786556 116.94324731677312 Mpc
8.33128595763478 120.45565879393497 Mpc
8.639229311121028 123.97979836398135 Mpc
8.947174322316757 127.51874858543704 Mpc
9.255120220282148 131.0753054467177 Mpc
9.563056854329533 134.65204334030335 Mpc
9.871011604296182 138.25187486919478 Mpc
10.178954010038005 141.87695100123045 Mpc
10.486898080899497 145.52986468697884 Mpc
10.794841599306537 149.21295107449208 Mpc
11.10278856050129 152.9285596811627 Mpc
11.410733190906743 156.6788693809309 Mpc
11.718679123874194 160.46612604443848 Mpc
12.026621735130746 164.29243333243653 Mpc
12.334566916502455 168.15998952325535 Mpc
12.642509688504886 172.0708262802806 Mpc
12.950467233429489 176.02723200663078 Mpc
13.258411498439456 180.03089125507208 Mpc

(4)_Comparing_units_from_different_datasets.ipynb; 4)_Comparing_units_from_different_datasets_evaluated.ipynb; 4)_Comparing_units_from_different_datasets.py)