On Aug 24, 2015, at 10:11 AM, Nathan Goldbaum <nathan12343@gmail.com> wrote:_______________________________________________On Sun, Aug 23, 2015 at 10:32 PM, Madison Fitzgerald <fitzg152@msu.edu> wrote:Hello,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: http://paste.yt-project.org/show/5829/).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 (http://paste.yt-project.org/show/5830/).Hi Madison,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:In [1]: from yt.units import gIn [2]: import numpy as npIn [3]: test_data = np.arange(10)*gIn [4]: test_dataOut[4]: YTArray([ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9.]) gIn [5]: test_where = np.where(test_data < 5, test_data, 0)In [6]: test_whereOut[6]: array([ 0., 1., 2., 3., 4., 0., 0., 0., 0., 0.])Here's how I would define your inflowing_mass field to work around this issue:def in_mass(field, data):cell_mass = data['cell_mass']new_field = np.where(data["radial_velocity"]<0, cell_mass, np.zeros_like(cell_mass))return data.ds.arr(new_field, cell_mass.units)You'll need to do something similar for the other fields you're defining that use np.where. Hope that helps,NathanIf 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 (http://paste.yt-project.org/show/5831/).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.Any suggestions?Thank you,Madison FitzgeraldAstrophysics | Lyman Briggs CollegeWomen’s & Gender Studies | College of Arts & LettersLGBTQ and Sexuality Studies SpecializationWomen in Science, PresidentUndergraduate Teaching AssistantUndergraduate Research AssistantDepartment of Physics and AstronomyHonors CollegeMichigan State University
_______________________________________________
yt-users mailing list
yt-users@lists.spacepope.org
http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
yt-users mailing list
yt-users@lists.spacepope.org
http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org