Skip to content

Commit b7c3bf0

Browse files
committed
Allow (R,z) input to set u0 in OblateStaeckelWrapperPotential
1 parent 57f66a8 commit b7c3bf0

2 files changed

Lines changed: 19 additions & 10 deletions

File tree

galpy/potential/OblateStaeckelWrapperPotential.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
###############################################################################
1010
import numpy
1111

12-
from galpy.util import coords
12+
from galpy.util import conversion, coords
1313

1414
from .Potential import (
1515
_APY_LOADED,
@@ -57,10 +57,10 @@ def __init__(self, amp=1.0, pot=None, delta=0.5, u0=0.0, ro=None, vo=None):
5757
Amplitude to be applied to the potential. Default is 1.0.
5858
pot : Potential or list
5959
Potential instance or list thereof; this potential is made into an oblate Staeckel potential.
60-
delta : float or astropy.units.Quantity, optional
60+
delta : float or Quantity, optional
6161
The focal length. Default is 0.5.
62-
u0 : float, optional
63-
Reference u value. Default is 0.0.
62+
u0 : float or tuple or tuple of Quantity
63+
Reference u value; if a tuple is given, this is assumed to be a (R,z) value to be converted to u.
6464
ro : float or Quantity, optional
6565
Distance scale for translation into internal units (default from configuration file).
6666
vo : float or Quantity, optional
@@ -70,14 +70,19 @@ def __init__(self, amp=1.0, pot=None, delta=0.5, u0=0.0, ro=None, vo=None):
7070
-----
7171
- 2017-12-15 - Started - Bovy (UofT)
7272
"""
73-
if _APY_LOADED and isinstance(delta, units.Quantity):
74-
delta = delta.to(units.kpc).value / self._ro
75-
self._delta = delta
73+
self._delta = conversion.parse_length(delta, ro=ro)
7674
if u0 is None: # pragma: no cover
7775
raise ValueError(
7876
"u0= needs to be given to setup OblateStaeckelWrapperPotential"
7977
)
80-
self._u0 = u0
78+
if isinstance(u0, (tuple, list, numpy.ndarray)):
79+
self._u0 = coords.Rz_to_uv(
80+
conversion.parse_length(u0[0], ro=ro),
81+
conversion.parse_length(u0[1], ro=ro),
82+
delta=self._delta,
83+
)[0]
84+
else:
85+
self._u0 = u0
8186
self._v0 = numpy.pi / 2.0 # so we know when we're using this
8287
R0, z0 = coords.uv_to_Rz(self._u0, self._v0, delta=self._delta)
8388
self._refpot = (

tests/test_quantity.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9710,10 +9710,14 @@ def test_potential_paramunits():
97109710
amp=20.0 * units.Msun, Delta=10.0 * units.kpc, ro=ro, vo=vo
97119711
)
97129712
pot = potential.OblateStaeckelWrapperPotential(
9713-
pot=kksp, delta=10.0 * units.kpc, u0=1.0
9713+
pot=kksp,
9714+
delta=10.0 * units.kpc,
9715+
u0=(8.0 * units.kpc, 0.0 * units.kpc),
9716+
ro=ro,
9717+
vo=vo,
97149718
)
97159719
pot_nounits = potential.OblateStaeckelWrapperPotential(
9716-
pot=kksp, delta=10.0 / ro, ro=ro, vo=vo
9720+
pot=kksp, delta=10.0 / ro, u0=(8.0 / ro, 0.0 / ro), ro=ro, vo=vo
97179721
)
97189722
# Check potential
97199723
assert (

0 commit comments

Comments
 (0)