<div dir="ltr">Hi Prateek and Ari, <div><br></div><div>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 <span style="font-size:12.8px">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:</span></div><div><span style="font-size:12.8px"><br></span></div><div><div><span style="font-size:12.8px">def _PhysicalMass(field, data):</span></div><div><span style="font-size:12.8px">    return data['Gas','Mass']*((5995.*(1e10)*(1.98855e33))/(0.7))</span></div></div><div><span style="font-size:12.8px">ds.add_field(("gas", "PhysicalMass"), function=_PhysicalMass, units="code_mass")</span><br></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">so now dd["gas", "PhysicalMass"] returns the right magnitude. The unit is still in 'code_mass' but It is technically converted into gram.</span><br></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Thanks very much for your time</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Best</span></div><div><span style="font-size:12.8px">Tazkera</span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Oct 4, 2017 at 10:50 AM, Ari Maller <span dir="ltr"><<a href="mailto:AMaller@citytech.cuny.edu" target="_blank">AMaller@citytech.cuny.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">It is a little unclear why you are trying to do what you are doing.<br>
<br>
To convert unit systems in yt there are a bunch of unit commands. For example<br>
dd[“Gas’,’Mass’].in_units(‘g’)<br>
would return the masses in grams.<br>
<br>
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.<br>
<br>
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.<br>
<br>
Ari<br>
<br>
<br>
> On Oct 3, 2017, at 11:53 PM, <a href="mailto:yt-users-request@lists.spacepope.org">yt-users-request@lists.<wbr>spacepope.org</a> wrote:<br>
><br>
> Send yt-users mailing list submissions to<br>
>       <a href="mailto:yt-users@lists.spacepope.org">yt-users@lists.spacepope.org</a><br>
><br>
> To subscribe or unsubscribe via the World Wide Web, visit<br>
>       <a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/<wbr>listinfo.cgi/yt-users-<wbr>spacepope.org</a><br>
> or, via email, send a message with subject or body 'help' to<br>
>       <a href="mailto:yt-users-request@lists.spacepope.org">yt-users-request@lists.<wbr>spacepope.org</a><br>
><br>
> You can reach the person managing the list at<br>
>       <a href="mailto:yt-users-owner@lists.spacepope.org">yt-users-owner@lists.<wbr>spacepope.org</a><br>
><br>
> When replying, please edit your Subject line so it is more specific<br>
> than "Re: Contents of yt-users digest..."<br>
><br>
><br>
> Today's Topics:<br>
><br>
>   1. defining derived field only for Gas particles (tazkera haque)<br>
><br>
><br>
> ------------------------------<wbr>------------------------------<wbr>----------<br>
><br>
> Message: 1<br>
> Date: Tue, 3 Oct 2017 23:29:31 -0400<br>
> From: tazkera haque <<a href="mailto:h.tazkera@gmail.com">h.tazkera@gmail.com</a>><br>
> To: Discussion of the yt analysis package<br>
>       <<a href="mailto:yt-users@lists.spacepope.org">yt-users@lists.spacepope.org</a>><br>
> Subject: [yt-users] defining derived field only for Gas particles<br>
> Message-ID:<br>
>       <<a href="mailto:CAFj_7zyiZYPOWuFPsPtbGtNVDvXF9G3Z%2B1srY_TvDKrFM8oRkg@mail.gmail.com">CAFj_<wbr>7zyiZYPOWuFPsPtbGtNVDvXF9G3Z+<wbr>1srY_TvDKrFM8oRkg@mail.gmail.<wbr>com</a>><br>
> Content-Type: text/plain; charset="utf-8"<br>
<span class="">><br>
> Dear yt community,<br>
><br>
> I am analyzing some Tipsy data output from Gadget 3. I have three different<br>
> particles, Gas, Star and Dark Matter. I want to derive a new field<br>
> 'PhysicalMass', that will make a unit conversion of code_mass to some<br>
> physical mass units. My code so far looks like this:<br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
</span>> *import ytfrom yt import derived_field@derived_field(<wbr>name="PhysicalMass",<br>
> units="g")def _PhysicalMass(field, data):    M =<br>
<span class="">> data['Gas','Mass']*((5995.*(<wbr>1e10)*(1.98855e33))/(0.7))    return Mds =<br>
</span>> yt.load('snap_p6n36fof_031.<wbr>bin', n_ref=64)dd= ds.all_data*<br>
<span class="">><br>
><br>
> My default ('Gas', 'Mass') array looks like this:<br>
</span>> *dd['Gas','Mass']*<br>
<span class="">><br>
> YTArray([  9.64448986e-07,   9.64448986e-07,   9.64448986e-07, ...,<br>
>         9.64448986e-07,   9.64448986e-07,   9.64448986e-07]) code_mass<br>
><br>
> But when I call the new derived field, it takes some values which does<br>
> not correspond to the conversion constants I have multiplied with:<br>
><br>
> dd['PhysicalMass']<br>
> YTArray([  3.26598467e+74,   3.26598467e+74,   3.26598467e+74, ...,<br>
>         3.26598467e+74,   3.26598467e+74,   3.26598467e+74]) g<br>
><br>
> I can directly multiply the ('Gas', 'Mass') array with some conversion<br>
> factors to get accurate values, but I need to define a new field for<br>
> later calls:<br>
> dd['Gas','Mass']*((5995.*(<wbr>1e10)*(1.98855e33))/(0.7))<br>
><br>
><br>
><br>
> So my question is how do I get a new field which will only contain<br>
> PhysicalMass from Gas particles. it seems dd['Gas', 'PhysicalMass'] does<br>
> not exist.<br>
><br>
><br>
> Thanks very much for your time.<br>
><br>
> Best<br>
> Tazkera<br>
</span>> -------------- next part --------------<br>
> An HTML attachment was scrubbed...<br>
> URL: <<a href="http://lists.spacepope.org/pipermail/yt-users-spacepope.org/attachments/20171003/d9ee4086/attachment.html" rel="noreferrer" target="_blank">http://lists.spacepope.org/<wbr>pipermail/yt-users-spacepope.<wbr>org/attachments/20171003/<wbr>d9ee4086/attachment.html</a>><br>
><br>
> ------------------------------<br>
><br>
> Subject: Digest Footer<br>
<span class="">><br>
> ______________________________<wbr>_________________<br>
> yt-users mailing list<br>
> <a href="mailto:yt-users@lists.spacepope.org">yt-users@lists.spacepope.org</a><br>
> <a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/<wbr>listinfo.cgi/yt-users-<wbr>spacepope.org</a><br>
><br>
><br>
</span>> ------------------------------<br>
><br>
> End of yt-users Digest, Vol 116, Issue 1<br>
> ******************************<wbr>**********<br>
<div class="HOEnZb"><div class="h5"><br>
______________________________<wbr>_________________<br>
yt-users mailing list<br>
<a href="mailto:yt-users@lists.spacepope.org">yt-users@lists.spacepope.org</a><br>
<a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/<wbr>listinfo.cgi/yt-users-<wbr>spacepope.org</a><br>
</div></div></blockquote></div><br></div>