<div dir="ltr">Great, thanks! I tried that, and it gave me the error: "YTQuantity instances must be scalars." I'm not sure what to do about that, since all of these quantities depend on either temperature or density, both of which are arrays. I tried looking at the doc page for YTQuantity, but I didn't see anything that looked like it could solve this problem, though it's possible I missed it.  <div>-Jared</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 24, 2015 at 8:13 PM, Nathan Goldbaum <span dir="ltr"><<a href="mailto:nathan12343@gmail.com" target="_blank">nathan12343@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br><br>On Monday, August 24, 2015, Cameron Hummels <<a href="mailto:chummels@gmail.com" target="_blank">chummels@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Jared,<div><br></div><div>The problem is one of units.  In order to make common arithmetic work like addition, yt requires both arguments going into the addition operator to have the same units.</div><div><br></div><div><span style="color:rgb(0,0,0);font-family:'Bitstream Vera Sans Mono',monospace;font-size:13px">In your line, </span></div><div><span style="color:rgb(0,0,0);font-family:'Bitstream Vera Sans Mono',monospace;font-size:13px"><br></span></div><div><span style="color:rgb(0,0,0);font-family:'Bitstream Vera Sans Mono',monospace;font-size:13px">fHI = (recomb * ne) / (gamma_HI + (gamma_c *ne))</span></div><div><br></div><div>you're adding two things (gamma_HI) and (gamma_c*ne) that have different units--in this case, something with <span style="color:rgb(0,0,0);font-family:'Bitstream Vera Sans Mono',monospace;font-size:13px">(code_mass/code_length**3) units and something with no units defined as (1).</span></div><div></div></div></blockquote><div><br></div></span><div>Just a quick clarification: they need not have the same units, just the same dimensions.  You can add two quantities with units of grams and solar masses (for example) but not grams and liters.<span></span></div><div class="HOEnZb"><div class="h5"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div></div><div><br></div><div>In order to fix this, you can re-assign the appropriate units to different arrays or quantities with the YTArray and YTQuantity classes.  In this case, make sure that the two arguments going into the addition have the same units.  If you want to recast "ne" to have number density units, you can do this:  from yt.units.yt_array import YTQuantity; ne = YTQuantity(ne, 'cm**-3').  For more info on units, check out <a href="http://yt-project.org/docs/dev/analyzing/units/index.html" target="_blank">http://yt-project.org/docs/dev/analyzing/units/index.html</a></div><div><br></div><div>I hope this helps!</div><div><br></div><div>Cameron</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 24, 2015 at 4:12 PM, Jared Coughlin <span dir="ltr"><<a>Jared.W.Coughlin.29@nd.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hello! I have a gadget snapshot for which the standard internal energy block has been replaced by one containing the temperature.  I'm trying to calculate a derived field for the neutral hydrogen number density,  but I'm getting an error when I try to do ds.add_field():<div><br></div><div><a href="http://paste.yt-project.org/show/5833/" target="_blank">http://paste.yt-project.org/show/5833/</a></div><div><br></div><div>However, I get an error about being unable to add quantities with differing units:</div><div><br></div><div><a href="http://paste.yt-project.org/show/5834/" target="_blank">http://paste.yt-project.org/show/5834/</a></div><div><br></div><div>The docs say not to do any unit conversion because that is apparently taken care of behind the scenes, so I didn't.  I was just wondering if there was a way around this? Thanks! </div><span><font color="#888888"><div>-Jared<br><div><br></div></div></font></span></div>
<br>_______________________________________________<br>
yt-users mailing list<br>
<a>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/listinfo.cgi/yt-users-spacepope.org</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div><div dir="ltr"><div>Cameron Hummels<div><span style="font-size:12.8000001907349px">NSF Postdoctoral Fellow</span></div><div><span style="font-size:12.8000001907349px">Department of Astronomy</span></div><div><span style="font-size:12.8000001907349px">California Institute of Technology</span><br></div><div><a href="http://chummels.org" style="font-size:12.8000001907349px" target="_blank">http://chummels.org</a><br></div></div></div></div>
</div>
</blockquote>
</div></div><br>_______________________________________________<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/listinfo.cgi/yt-users-spacepope.org</a><br>
<br></blockquote></div><br></div>