<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">That worked perfectly! Thank you—I thought it might have to do with numpy, but I couldn’t figure out how.<div class=""><br class=""></div><div class="">Thank you!<br class=""><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><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; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="">Madison Fitzgerald</div><div class=""><br class=""></div><div class="">Astrophysics | Lyman Briggs College</div><div class="">Women’s & Gender Studies | College of Arts & Letters</div><div class="">LGBTQ and Sexuality Studies Specialization</div><div class=""><div class="">Women in Science, President</div><div class="">Undergraduate Teaching Assistant</div><div class="">Undergraduate Research Assistant</div><div class="">Department of Physics and Astronomy</div></div><div class="">Honors College</div><div class="">Michigan State University</div></div></div></div></div></div></div></div>
</div>
<br class=""><div><blockquote type="cite" class=""><div class="">On Aug 24, 2015, at 10:11 AM, Nathan Goldbaum <<a href="mailto:nathan12343@gmail.com" class="">nathan12343@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="gmail_extra"><br class="Apple-interchange-newline"><br class=""><div class="gmail_quote">On Sun, Aug 23, 2015 at 10:32 PM, Madison Fitzgerald<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:fitzg152@msu.edu" target="_blank" class="">fitzg152@msu.edu</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""><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;" class="">Hello,<div class=""><br class=""></div><div class="">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:<span class="Apple-converted-space"> </span><a href="http://paste.yt-project.org/show/5829/" target="_blank" class="">http://paste.yt-project.org/show/5829/</a>). </div><div class=""><br class=""></div><div class="">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" class="">http://paste.yt-project.org/show/5830/</a>).</div></div></blockquote><div class=""><br class=""></div><div class="">Hi Madison,</div><div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class=""><div class="">In [1]: from yt.units import g</div><div class=""><br class=""></div><div class="">In [2]: import numpy as np</div><div class=""><br class=""></div><div class="">In [3]: test_data = np.arange(10)*g</div><div class=""><br class=""></div><div class="">In [4]: test_data</div><div class="">Out[4]: YTArray([ 0.,  1.,  2.,  3.,  4.,  5.,  6.,  7.,  8.,  9.]) g</div><div class=""><br class=""></div><div class="">In [5]: test_where = np.where(test_data < 5, test_data, 0)</div><div class=""><br class=""></div><div class="">In [6]: test_where</div><div class="">Out[6]: array([ 0.,  1.,  2.,  3.,  4.,  0.,  0.,  0.,  0.,  0.])</div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Here's how I would define your inflowing_mass field to work around this issue:</div><div class=""><br class=""></div><div class=""><div class="">def in_mass(field, data):</div><div class="">    cell_mass = data['cell_mass']</div><div class="">    new_field = np.where(data["radial_velocity"]<0, cell_mass, np.zeros_like(cell_mass))</div><div class=""><span style="white-space: pre;" class="">    </span>return data.ds.arr(new_field, cell_mass.units)</div></div><div class=""><br class=""></div><div class="">You'll need to do something similar for the other fields you're defining that use np.where. Hope that helps,</div><div class=""><br class=""></div><div class="">Nathan</div><div class=""><br class=""></div><div class=""> </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;" class=""><div class=""><br class=""></div><div class="">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" class="">http://paste.yt-project.org/show/5831/</a>).</div><div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">Any suggestions?</div><div class=""><br class=""></div><div class="">Thank you,</div><div class=""><div class=""><div style="letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; word-wrap: break-word;" class=""><div style="letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; word-wrap: break-word;" class=""><div style="letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; word-wrap: break-word;" class=""><div style="letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; word-wrap: break-word;" class=""><div style="letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; word-wrap: break-word;" class=""><div style="letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; word-wrap: break-word;" class=""><div style="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;" class=""><div class="">Madison Fitzgerald</div><div class=""><br class=""></div><div class="">Astrophysics | Lyman Briggs College</div><div class="">Women’s & Gender Studies | College of Arts & Letters</div><div class="">LGBTQ and Sexuality Studies Specialization</div><div class=""><div class="">Women in Science, President</div><div class="">Undergraduate Teaching Assistant</div><div class="">Undergraduate Research Assistant</div><div class="">Department of Physics and Astronomy</div></div><div class="">Honors College</div><div class="">Michigan State University</div></div></div></div></div></div></div></div></div><br class=""></div></div><br class="">_______________________________________________<br class="">yt-users mailing list<br class=""><a href="mailto:yt-users@lists.spacepope.org" class="">yt-users@lists.spacepope.org</a><br class=""><a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" rel="noreferrer" target="_blank" class="">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br class=""><br class=""></blockquote></div><br class=""></div></div><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">yt-users mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:yt-users@lists.spacepope.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">yt-users@lists.spacepope.org</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a></div></blockquote></div><br class=""></div></body></html>