Re: [yt-users] defining derived field only for Gas particles

It is a little unclear why you are trying to do what you are doing.
To convert unit systems in yt there are a bunch of unit commands. For example dd[“Gas’,’Mass’].in_units(‘g’) would return the masses in grams.
I think what is going wrong in your derived field is that you set the units to grams and then add your conversion factor to that, but you wanted to use your conversion factor on the code masses. If you just want Physical mass to be in grams and no extra conversion then you could set the units to grams and do nothing to the array.
The first question is whether yt internal unit conversion is working correctly for you or not. Gadget does not output Tipsy files, so it is possible the frontend is doing something wrong since your data sounds very unusual. If you need some extra conversion then you can see what the values of your Masses are in the units of your choice and then add derived field in those units that makes the extra conversion.
Ari
On Oct 3, 2017, at 11:53 PM, yt-users-request@lists.spacepope.org wrote:
Send yt-users mailing list submissions to yt-users@lists.spacepope.org
To subscribe or unsubscribe via the World Wide Web, visit http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org or, via email, send a message with subject or body 'help' to yt-users-request@lists.spacepope.org
You can reach the person managing the list at yt-users-owner@lists.spacepope.org
When replying, please edit your Subject line so it is more specific than "Re: Contents of yt-users digest..."
Today's Topics:
- defining derived field only for Gas particles (tazkera haque)
Message: 1 Date: Tue, 3 Oct 2017 23:29:31 -0400 From: tazkera haque h.tazkera@gmail.com To: Discussion of the yt analysis package yt-users@lists.spacepope.org Subject: [yt-users] defining derived field only for Gas particles Message-ID: CAFj_7zyiZYPOWuFPsPtbGtNVDvXF9G3Z+1srY_TvDKrFM8oRkg@mail.gmail.com Content-Type: text/plain; charset="utf-8"
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 ytfrom 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 Mds = 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.spacepope.org/pipermail/yt-users-spacepope.org/attachments/20171003/d9ee4086/attachment.html
Subject: Digest Footer
yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
End of yt-users Digest, Vol 116, Issue 1

Hi Prateek and Ari,
Thanks very much for your feedback. I took your suggestion and I figured out my problem. It's all about making the new derived field units in 'g'. As a correction, I changed the unit to 'code_mass' to get the right order of magnitude for my new field. The only reason I cannot do dd[“Gas’,’Mass’].in_units(‘g’) because it does not take into account some constant correction for my simulation. so the code with correct magnitude now looks like this:
def _PhysicalMass(field, data): return data['Gas','Mass']*((5995.*(1e10)*(1.98855e33))/(0.7)) ds.add_field(("gas", "PhysicalMass"), function=_PhysicalMass, units="code_mass")
so now dd["gas", "PhysicalMass"] returns the right magnitude. The unit is still in 'code_mass' but It is technically converted into gram.
Thanks very much for your time
Best Tazkera
On Wed, Oct 4, 2017 at 10:50 AM, Ari Maller AMaller@citytech.cuny.edu wrote:
It is a little unclear why you are trying to do what you are doing.
To convert unit systems in yt there are a bunch of unit commands. For example dd[“Gas’,’Mass’].in_units(‘g’) would return the masses in grams.
I think what is going wrong in your derived field is that you set the units to grams and then add your conversion factor to that, but you wanted to use your conversion factor on the code masses. If you just want Physical mass to be in grams and no extra conversion then you could set the units to grams and do nothing to the array.
The first question is whether yt internal unit conversion is working correctly for you or not. Gadget does not output Tipsy files, so it is possible the frontend is doing something wrong since your data sounds very unusual. If you need some extra conversion then you can see what the values of your Masses are in the units of your choice and then add derived field in those units that makes the extra conversion.
Ari
On Oct 3, 2017, at 11:53 PM, yt-users-request@lists.spacepope.org wrote:
Send yt-users mailing list submissions to yt-users@lists.spacepope.org
To subscribe or unsubscribe via the World Wide Web, visit http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org or, via email, send a message with subject or body 'help' to yt-users-request@lists.spacepope.org
You can reach the person managing the list at yt-users-owner@lists.spacepope.org
When replying, please edit your Subject line so it is more specific than "Re: Contents of yt-users digest..."
Today's Topics:
- defining derived field only for Gas particles (tazkera haque)
Message: 1 Date: Tue, 3 Oct 2017 23:29:31 -0400 From: tazkera haque h.tazkera@gmail.com To: Discussion of the yt analysis package yt-users@lists.spacepope.org Subject: [yt-users] defining derived field only for Gas particles Message-ID: <CAFj_7zyiZYPOWuFPsPtbGtNVDvXF9G3Z+1srY_TvDKrFM8oRkg@mail.gmail.
com>
Content-Type: text/plain; charset="utf-8"
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 ytfrom 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 Mds = 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.spacepope.org/pipermail/yt-users-spacepope.
org/attachments/20171003/d9ee4086/attachment.html>
Subject: Digest Footer
yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
End of yt-users Digest, Vol 116, Issue 1
yt-users mailing list yt-users@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
participants (2)
-
Ari Maller
-
tazkera haque