[yt-svn] commit/yt: jzuhone: Merged in ngoldbaum/yt (pull request #2152)
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Wed May 11 11:18:27 PDT 2016
1 new commit in yt:
https://bitbucket.org/yt_analysis/yt/commits/6db4d26078e5/
Changeset: 6db4d26078e5
Branch: yt
User: jzuhone
Date: 2016-05-11 18:18:09+00:00
Summary: Merged in ngoldbaum/yt (pull request #2152)
Make trig functions give correct results when supplied data with dimensions of angle but units that aren't radian. Closes #982
Affected #: 2 files
diff -r 7f7ccbc9329e14578e120835c0365f2e271e72cf -r 6db4d26078e523630af50bde111952bbee7a1018 yt/units/tests/test_ytarray.py
--- a/yt/units/tests/test_ytarray.py
+++ b/yt/units/tests/test_ytarray.py
@@ -42,7 +42,7 @@
assert_allclose_units
from yt.funcs import fix_length
from yt.units.unit_symbols import \
- cm, m, g
+ cm, m, g, degree
from yt.utilities.physical_ratios import \
metallicity_sun
@@ -1157,3 +1157,9 @@
os.chdir(curdir)
shutil.rmtree(tmpdir)
+
+def test_trig_ufunc_degrees():
+ for ufunc in (np.sin, np.cos, np.tan):
+ degree_values = np.random.random(10)*degree
+ radian_values = degree_values.in_units('radian')
+ assert_array_equal(ufunc(degree_values), ufunc(radian_values))
diff -r 7f7ccbc9329e14578e120835c0365f2e271e72cf -r 6db4d26078e523630af50bde111952bbee7a1018 yt/units/yt_array.py
--- a/yt/units/yt_array.py
+++ b/yt/units/yt_array.py
@@ -31,7 +31,11 @@
from yt.units.unit_object import Unit, UnitParseError
from yt.units.unit_registry import UnitRegistry
-from yt.units.dimensions import dimensionless, current_mks, em_dimensions
+from yt.units.dimensions import \
+ angle, \
+ current_mks, \
+ dimensionless, \
+ em_dimensions
from yt.utilities.exceptions import \
YTUnitOperationError, YTUnitConversionError, \
YTUfuncUnitError, YTIterableUnitCoercionError, \
@@ -180,6 +184,10 @@
fmax, fmin, copysign, nextafter, ldexp, fmod,
)
+trigonometric_operators = (
+ sin, cos, tan,
+)
+
class YTArray(np.ndarray):
"""
An ndarray subclass that attaches a symbolic unit object to the array data.
@@ -1166,6 +1174,9 @@
u = getattr(context[1][0], 'units', None)
if u is None:
u = NULL_UNIT
+ if u.dimensions is angle and context[0] in trigonometric_operators:
+ out_arr = context[0](
+ context[1][0].in_units('radian').view(np.ndarray))
unit = self._ufunc_registry[context[0]](u)
ret_class = type(self)
elif context[0] in binary_operators:
Repository URL: https://bitbucket.org/yt_analysis/yt/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spacepope.org/pipermail/yt-svn-spacepope.org/attachments/20160511/ee273a3a/attachment.html>
More information about the yt-svn
mailing list