Skip to content

Commit 8a4e5cb

Browse files
committed
Clarify documentation of RotateAndTiltWrapper's used of galaxy/sky PA and inclination and test explicitly that the docs are correct
1 parent ba985f3 commit 8a4e5cb

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

galpy/potential/RotateAndTiltWrapperPotential.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@ class RotateAndTiltWrapperPotential(WrapperPotential):
3232
3333
* A rotation around the original z-axis (`galaxy_pa`), the `inclination`, and a rotation around the new z axis (`sky_pa`).
3434
35-
The second option allows one to specify the inclination and sky position angle (measured from North) in the usual manner in extragalactic observations.
35+
The second option allows one to specify the inclination and sky position angle (measured from North) in the usual manner in extragalactic observations, that is, the relation between the observed coordinates :math:`(x',y',z')` and the intrinsic coordinates :math:`(x,y,z)` is given by
36+
37+
.. math::
38+
39+
\\begin{pmatrix} x \\\\ y \\\\ z \\end{pmatrix} = \\begin{pmatrix} \\phantom{-}\\cos(\\text{PA}_\\text{gal}) & \\sin(\\text{PA}_\\text{gal}) & 0 \\\\ -\\sin(\\text{PA}_\\text{gal}) & \\cos(\\text{PA}_\\text{gal}) & 0 \\\\ 0 & 0 & 1 \\end{pmatrix} \\begin{pmatrix} 1 & 0 & 0 \\\\ 0 & \\phantom{-}\\cos i & \\sin i \\\\ 0 & -\\sin i & \\cos i \\end{pmatrix} \\begin{pmatrix} \\sin(\\text{PA}_\\text{sky}) & -\\cos(\\text{PA}_\\text{sky}) & 0 \\\\ \\cos(\\text{PA}_\\text{sky}) & \\phantom{-}\\sin(\\text{PA}_\\text{sky}) & 0 \\\\ 0 & 0 & 1 \\end{pmatrix} \\begin{pmatrix} x' \\\\ y' \\\\ z' \\end{pmatrix}\\,,
40+
41+
3642
A final `offset` option allows one to apply a static offset in Cartesian coordinate space to be applied to the potential following the rotation and tilt.
3743
"""
3844

tests/test_potential.py

+55
Original file line numberDiff line numberDiff line change
@@ -6236,6 +6236,61 @@ def test_RotateAndTiltWrapper():
62366236
), "Wrapped + Offset and Internally rotated NFW potentials do not match when evaluated at the same point"
62376237

62386238

6239+
def test_RotateAndTiltWrapper_pa_inclination_rotation_matrix():
6240+
# Test that the formula for the rotation matrix given in the documentation agrees with the code
6241+
def rotation_matrix_docs(galaxy_pa, inclination, sky_pa):
6242+
return numpy.dot(
6243+
numpy.array(
6244+
[
6245+
[numpy.cos(galaxy_pa), numpy.sin(galaxy_pa), 0.0],
6246+
[-numpy.sin(galaxy_pa), numpy.cos(galaxy_pa), 0.0],
6247+
[0.0, 0.0, 1.0],
6248+
]
6249+
),
6250+
numpy.dot(
6251+
numpy.array(
6252+
[
6253+
[1.0, 0.0, 0.0],
6254+
[0.0, numpy.cos(inclination), numpy.sin(inclination)],
6255+
[0.0, -numpy.sin(inclination), numpy.cos(inclination)],
6256+
]
6257+
),
6258+
numpy.array(
6259+
[
6260+
[numpy.sin(sky_pa), -numpy.cos(sky_pa), 0.0],
6261+
[numpy.cos(sky_pa), numpy.sin(sky_pa), 0.0],
6262+
[0.0, 0.0, 1],
6263+
]
6264+
),
6265+
),
6266+
)
6267+
6268+
galaxy_pa, inclination, sky_pa = 0.3, -0.2, 0.1
6269+
rtwp = potential.RotateAndTiltWrapperPotential(
6270+
pot=potential.MWPotential2014,
6271+
galaxy_pa=galaxy_pa,
6272+
inclination=inclination,
6273+
sky_pa=sky_pa,
6274+
)
6275+
assert numpy.all(
6276+
numpy.fabs(rtwp._rot - rotation_matrix_docs(galaxy_pa, inclination, sky_pa))
6277+
< 1e-10
6278+
), "Rotation matrix in RotateAndTiltWrapperPotential does not agree with the formula in the documentation"
6279+
6280+
galaxy_pa, inclination, sky_pa = -0.3, 1.2, 2.1
6281+
rtwp = potential.RotateAndTiltWrapperPotential(
6282+
pot=potential.MWPotential2014,
6283+
galaxy_pa=galaxy_pa,
6284+
inclination=inclination,
6285+
sky_pa=sky_pa,
6286+
)
6287+
assert numpy.all(
6288+
numpy.fabs(rtwp._rot - rotation_matrix_docs(galaxy_pa, inclination, sky_pa))
6289+
< 1e-10
6290+
), "Rotation matrix in RotateAndTiltWrapperPotential does not agree with the formula in the documentation"
6291+
return None
6292+
6293+
62396294
def test_integration_RotateAndTiltWrapper():
62406295
## test a quick orbit integration to hit the C code (also test pure python)
62416296
# two potentials, one offset

0 commit comments

Comments
 (0)