Dear Tazkera,

You got this error that dd['Gas', 'PhysicalMass'] doesn't exist because while defining new field you didn't add it to yt available field. To do so you have to add one more line after return M in derived field PhysicalMass...

ds.add_field(("gas", "PhysicalMass"), function = _PhysicalMass, units="g")

Now why you are getting the wrong output: Actually now Yt itself do the conversion between the units. For doing so you can do one thing:
1) if you want to use ["Gas","Mass"] as a field while plotting or deriving new field you can you this:
       data["Gas", "Mass"].in_units('g')
2) if you want to see it in output on terminal then do this:
       PhysicalMass = dd["Gas","Mass"];        then           PhysicalMass.in_units('g') will give you the correct output.

Actually, the problem is with your code for getting mass wrong (in the gram of order 74) is that while giving output Yt itself first converting ["Gas","Mass"] in units of "g" and then it multiplied with your conversion formula.

Please ask if you didn't understand any point in this reply. Hope this will help you.

-Prateek

On Wed, Oct 4, 2017 at 8:59 AM, tazkera haque <h.tazkera@gmail.com> wrote:
Dear yt community,

I am analyzing some Tipsy data output from Gadget 3. I have three different particles, Gas, Star and Dark Matter. I want to derive a new field 'PhysicalMass', that will make a unit conversion of code_mass to some physical mass units. My code so far looks like this:

import yt
from yt import derived_field

@derived_field(name="PhysicalMass", units="g")
def _PhysicalMass(field, data):
    M = data['Gas','Mass']*((5995.*(1e10)*(1.98855e33))/(0.7))
    return M
ds = yt.load('snap_p6n36fof_031.bin', n_ref=64)
dd= ds.all_data


My default ('Gas', 'Mass') array looks like this:
dd['Gas','Mass']
YTArray([  9.64448986e-07,   9.64448986e-07,   9.64448986e-07, ...,
         9.64448986e-07,   9.64448986e-07,   9.64448986e-07]) code_mass

But when I call the new derived field, it takes some values which does not correspond to the conversion constants I have multiplied with:

dd['PhysicalMass']
YTArray([ 3.26598467e+74, 3.26598467e+74, 3.26598467e+74, ..., 3.26598467e+74, 3.26598467e+74, 3.26598467e+74]) g

I can directly multiply the ('Gas', 'Mass') array with some conversion factors to get accurate values, but I need to define a new field for later calls:
dd['Gas','Mass']*((5995.*(1e10)*(1.98855e33))/(0.7))


So my question is how do I get a new field which will only contain PhysicalMass from Gas particles. it seems dd['Gas', 'PhysicalMass'] does not exist.


Thanks very much for your time.

Best
Tazkera


_______________________________________________
yt-users mailing list
yt-users@lists.spacepope.org
http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org