Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise error when plotting a potential with both xy=True and effective=True #587

Merged
merged 1 commit into from
Jun 21, 2023
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
4 changes: 4 additions & 0 deletions galpy/potential/Potential.py
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,8 @@ def plot(
2014-04-08 - Added effective= - Bovy (IAS)

"""
if effective and xy:
raise RuntimeError("xy and effective cannot be True at the same time")
rmin = conversion.parse_length(rmin, ro=self._ro)
rmax = conversion.parse_length(rmax, ro=self._ro)
zmin = conversion.parse_length(zmin, ro=self._ro)
Expand Down Expand Up @@ -3062,6 +3064,8 @@ def plotPotentials(
2010-07-09 - Written - Bovy (NYU)

"""
if effective and xy:
raise RuntimeError("xy and effective cannot be True at the same time")
Pot = flatten(Pot)
rmin = conversion.parse_length(rmin, **get_physical(Pot))
rmax = conversion.parse_length(rmax, **get_physical(Pot))
Expand Down
14 changes: 14 additions & 0 deletions tests/test_potential.py
Original file line number Diff line number Diff line change
Expand Up @@ -7582,6 +7582,20 @@ def test_InterpSnapshotRZPotential_pickling():
return None


# Test that trying to plot a potential with xy=True and effective=True raises a RuntimeError
def test_plotting_xy_effective_error():
# First a single potential
kp = potential.KeplerPotential(normalize=1.0)
with pytest.raises(RuntimeError) as excinfo:
kp.plot(xy=True, effective=True)
assert "xy and effective cannot be True at the same time" in excinfo.value.args[0]
# Then a list of potentials
with pytest.raises(RuntimeError) as excinfo:
potential.plotPotentials(potential.MWPotential2014, xy=True, effective=True)
assert "xy and effective cannot be True at the same time" in excinfo.value.args[0]
return None


def test_plotting():
import tempfile

Expand Down