yt-project / yt

Main yt repository
http://yt-project.org
Other
468 stars 280 forks source link

Metallicity is broken in the stream frontend for grid data #1344

Closed yt-fido closed 7 years ago

yt-fido commented 7 years ago

Originally reported by: John ZuHone (Bitbucket: jzuhone, GitHub: jzuhone)


If one sets up a stream dataset with metallicity as an input field, the values get transformed. A simple script demonstrates this:

import numpy as np
import yt

Z = np.random.uniform(size=(32,32,32))
d = np.random.uniform(size=(32,32,32))

data = {"density": d, "metallicity": Z}

ds = yt.load_uniform_grid(data, (32,32,32))

dd = ds.all_data()

print(Z.max())
print(dd["metallicity"].max())

gives:

0.99996801409647373
0.012949585782549334 dimensionless

This happens regardless if one sets the units in the dict above. I am pretty sure that somehow the derived field for metallicity is being used instead, because that rescales metal_density by the solar value, and somehow the input field is getting interpreted as metal_density.

This bug got accidentally introduced in yt 3.3.2 with this PR:

https://bitbucket.org/yt_analysis/yt/pull-requests/2331/adding-metallicity-to-alias-fields-in/

I'll see if I can track it down.


yt-fido commented 7 years ago

Original comment by John ZuHone (Bitbucket: jzuhone, GitHub: jzuhone):


Actually, I am thinking too hard--the issue here is that there is a conversion in the unit_lookup_table for metallicity units to solar units. I'm not sure why the alias isn't handling the units correctly, but @chummels originally noted in his PR above that the field was being returned as dimensionless instead of Zsun.