Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/amuse/units/trigo.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
arcsin = lambda x: numpy.arcsin(x) | rad
arccos = lambda x: numpy.arccos(x) | rad
arctan = lambda x: numpy.arctan(x) | rad
arctan2 = lambda x, y: numpy.arctan2(x, y) | rad
arctan2 = lambda x, y: numpy.arctan2(
x.value_in(x.unit) if isinstance(x, quantities.Quantity) else x,
y.value_in(x.unit) if isinstance(x, quantities.Quantity) else y,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this explicitly checks the unit of x in both cases, and also whether x is a Quantity. This is because x and y need to be treated in the same way, otherwise they might have different units.

) | rad


def to_rad(angle):
Expand Down
36 changes: 36 additions & 0 deletions src/tests/ticket_tests/test_issue1180.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import pytest
from amuse.support.testing import amusetest

from amuse.units import units
from amuse.units.trigo import arctan2


class TestsForIssue1180(amusetest.TestCase):

def test_arctan2_without_units(self):
"Test when input has no units"
x = 1.0
y = 2.0
result = arctan2(x, y).value_in(units.rad)
assert result == pytest.approx(0.4636476, 1e-7)

def test_arctan2_with_units(self):
"Test when input has units"
x = 1.0 | units.m
y = 2.0 | units.m
result = arctan2(x, y).value_in(units.rad)
assert result == pytest.approx(0.4636476, 1e-7)

def test_arctan2_with_units_and_no_units(self):
"Test when input has units and no units (should fail)"
x = 1.0 | units.m
y = 2.0
with pytest.raises(AttributeError):
result = arctan2(x, y).value_in(units.rad)

def test_arctan2_with_different_units(self):
"Test when input has different units"
x = 1.0 | units.m
y = 2.0e-3 | units.km
result = arctan2(x, y).value_in(units.rad)
assert result == pytest.approx(0.4636476, 1e-7)
Loading