<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Aug 23, 2015 at 10:32 PM, Madison Fitzgerald <span dir="ltr"><<a href="mailto:fitzg152@msu.edu" target="_blank">fitzg152@msu.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word">Hello,<div><br></div><div>I’ve been working on a project where I created derived fields to represent inflowing and outflowing gas in the galaxy. In doing so, I’ve run into a strange issue where yt wants my derived field for inflowing/outflowing mass (cell mass) to be dimensionless, but it will scale graphs as though the units are grams (original script found here: <a href="http://paste.yt-project.org/show/5829/" target="_blank">http://paste.yt-project.org/show/5829/</a>). </div><div><br></div><div>However, this makes it difficult to work with the data, so I’ve tried to give units in the derived field function (g and Msun), but I receive errors similar to this (<a href="http://paste.yt-project.org/show/5830/" target="_blank">http://paste.yt-project.org/show/5830/</a>).</div></div></blockquote><div><br></div><div>Hi Madison,</div><div><br></div><div>This is actually an issue with the numpy.where function, which will return data without units even though you are expecting it to return data with units. This is illustrated with the following example:</div><div><br></div><div><div>In [1]: from yt.units import g</div><div><br></div><div>In [2]: import numpy as np</div><div><br></div><div>In [3]: test_data = np.arange(10)*g</div><div><br></div><div>In [4]: test_data</div><div>Out[4]: YTArray([ 0.,  1.,  2.,  3.,  4.,  5.,  6.,  7.,  8.,  9.]) g</div><div><br></div><div>In [5]: test_where = np.where(test_data < 5, test_data, 0)</div><div><br></div><div>In [6]: test_where</div><div>Out[6]: array([ 0.,  1.,  2.,  3.,  4.,  0.,  0.,  0.,  0.,  0.])</div></div><div><br></div><div><br></div><div>Here's how I would define your inflowing_mass field to work around this issue:</div><div><br></div><div><div>def in_mass(field, data):</div><div>    cell_mass = data['cell_mass']</div><div>    new_field = np.where(data["radial_velocity"]<0, cell_mass, np.zeros_like(cell_mass))</div><div><span style="white-space:pre">    </span>return data.ds.arr(new_field, cell_mass.units)</div></div><div><br></div><div>You'll need to do something similar for the other fields you're defining that use np.where. Hope that helps,</div><div><br></div><div>Nathan</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><div><br></div><div>If I try to change the specified unit within the mass function in the script to g or Msun, I receive this error when I try to plot instead (<a href="http://paste.yt-project.org/show/5831/" target="_blank">http://paste.yt-project.org/show/5831/</a>).</div><div><br></div><div>I’m working with yt through miniconda, so I have yt version 3.2, no changeset, on a Mac with OS X 10.10.4.</div><div><br></div><div>Any suggestions?</div><div><br></div><div>Thank you,</div><div><div>
<div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div>Madison Fitzgerald</div><div><br></div><div>Astrophysics | Lyman Briggs College</div><div>Women’s & Gender Studies | College of Arts & Letters</div><div>LGBTQ and Sexuality Studies Specialization</div><div><div>Women in Science, President</div><div>Undergraduate Teaching Assistant</div><div>Undergraduate Research Assistant</div><div>Department of Physics and Astronomy</div></div><div>Honors College</div><div>Michigan State University</div></div></div></div></div></div></div></div>
</div>
<br></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></div>