Skip to content

Commit

Permalink
numpy-style docstrings for potential classes
Browse files Browse the repository at this point in the history
  • Loading branch information
jobovy committed Sep 8, 2023
1 parent 5c56289 commit 02e801d
Show file tree
Hide file tree
Showing 56 changed files with 2,526 additions and 7,325 deletions.
83 changes: 43 additions & 40 deletions galpy/potential/AdiabaticContractionWrapperPotential.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@
class AdiabaticContractionWrapperPotential(interpSphericalPotential):
"""AdiabaticContractionWrapperPotential: Wrapper to adiabatically contract a DM halo in response to the growth of a baryonic component. Use for example as::
dm= AdiabaticContractionWrapperPotential(pot=MWPotential2014[2],baryonpot=MWPotential2014[:2])
dm= AdiabaticContractionWrapperPotential(
pot=MWPotential2014[2],
baryonpot=MWPotential2014[:2]
)
to contract the dark-matter halo in MWPotential2014 according to the baryon distribution within it. The basic physics of the adiabatic contraction is that a fraction `f_bar` of the mass in the original potential `pot` cools adiabatically to form a baryonic component `baryonpot`; this wrapper computes the resulting dark-matter potential using different approximations in the literature.
to contract the dark-matter halo in ``MWPotential2014`` according to the baryon distribution within it. The basic physics of the adiabatic contraction is that a fraction ``f_bar`` of the mass in the original potential ``pot`` cools adiabatically to form a baryonic component ``baryonpot``; this wrapper computes the resulting dark-matter potential using different approximations in the literature.
"""

Expand All @@ -37,44 +40,44 @@ def __init__(
vo=None,
):
"""
NAME:
__init__
PURPOSE:
initialize a AdiabaticContractionWrapper Potential
INPUT:
amp - amplitude to be applied to the potential (default: 1.)
pot - Potential instance or list thereof representing the density that is adiabatically contracted
baryonpot - Potential instance or list thereof representing the density of baryons whose growth causes the contraction
method= ('cautun') Type of adiabatic-contraction formula:
* 'cautun' for that from Cautun et al. 2020 (`2020MNRAS.494.4291C <https://ui.adsabs.harvard.edu/abs/2020MNRAS.494.4291C>`__),
* 'blumenthal' for that from Blumenthal et al. 1986 (`1986ApJ...301...27B 1986ApJ...301...27B <https://ui.adsabs.harvard.edu/abs/1986ApJ...301...27B>`__)
* 'gnedin' for that from Gnedin et al. 2004 (`2004ApJ...616...16G <https://ui.adsabs.harvard.edu/abs/2004ApJ...616...16G>`__)
f_bar= (0.157) universal baryon fraction; if None, calculated from pot and baryonpot assuming that at rmax the halo contains the universal baryon fraction; leave this at the default value unless you know what you are doing
rmin= (None) minimum radius to consider (default: rmax/2500; don't set this to zero)
rmax= (50.) maximum radius to consider (can be Quantity)
ro, vo= standard unit-conversion parameters
OUTPUT:
(none)
HISTORY:
2021-03-21 - Started based on Marius Cautun's code - Bovy (UofT)
Initialize a AdiabaticContractionWrapper Potential.
Parameters
----------
amp : float, optional
Amplitude to be applied to the potential (default: 1.).
pot : Potential instance or list thereof, optional
Representing the density that is adiabatically contracted.
baryonpot : Potential instance or list thereof, optional
Representing the density of baryons whose growth causes the contraction.
method : {'cautun', 'blumenthal', 'gnedin'}, optional
Type of adiabatic-contraction formula:
- 'cautun' for that from Cautun et al. 2020 [1]_;
- 'blumenthal' for that from Blumenthal et al. 1986 [2]_;
- 'gnedin' for that from Gnedin et al. 2004 [3]_.
(default: 'cautun')
f_bar : float, optional
Universal baryon fraction; if None, calculated from pot and baryonpot assuming that at rmax the halo contains the universal baryon fraction; leave this at the default value unless you know what you are doing (default: 0.157).
rmin : float, optional
Minimum radius to consider (default: rmax/2500; don't set this to zero).
rmax : float or Quantity, optional
Maximum radius to consider (default: 50.).
ro : float or Quantity, optional
Distance scale for translation into internal units (default from configuration file).
vo : float or Quantity, optional
Velocity scale for translation into internal units (default from configuration file).
Notes
-----
- 2021-03-21 - Started based on Marius Cautun's code - Bovy (UofT)
References
----------
.. [1] Cautun, M et al. (2020), Mon. Not. Roy. Astron. Soc., 494, 4291. ADS: https://ui.adsabs.harvard.edu/abs/2020MNRAS.494.4291C
.. [2] Blumenthal et al. (1986), Astrophys. J., 301, 27. ADS: https://ui.adsabs.harvard.edu/abs/1986ApJ...301...27B
.. [3] Gnedin et al. (2004), Astrophys. J., 616, 16. ADS: https://ui.adsabs.harvard.edu/abs/2004ApJ...616...16G
"""
# Initialize with Force just to parse (ro,vo)
Force.__init__(self, ro=ro, vo=vo)
Expand Down
152 changes: 20 additions & 132 deletions galpy/potential/AnyAxisymmetricRazorThinDiskPotential.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,35 @@


class AnyAxisymmetricRazorThinDiskPotential(Potential):
r"""Class that implements the potential of an arbitrary axisymmetric, razor-thin disk with surface density :math:`\Sigma(R)`"""
"""Class that implements the potential of an arbitrary axisymmetric, razor-thin disk with surface density :math:`\\Sigma(R)`"""

def __init__(
self,
surfdens=lambda R: 1.5 * numpy.exp(-3.0 * R),
amp=1.0,
surfdens=lambda R: 1.5 * numpy.exp(-3.0 * R),
normalize=False,
ro=None,
vo=None,
):
"""
NAME:
__init__
PURPOSE:
Initialize the potential of an arbitrary axisymmetric disk
INPUT:
surfdens= (1.5 e^[-R/0.3]) function of a single variable that gives the surface density as a function of radius (can return a Quantity)
amp= (1.) amplitude to be applied to the potential
normalize - if True, normalize such that vc(1.,0.)=1., or, if given as a number, such that the force is this fraction of the force necessary to make vc(1.,0.)=1.
ro=, vo= distance and velocity scales for translation into internal units (default from configuration file)
OUTPUT:
AnyAxisymmetricRazorThinDiskPotential object
HISTORY:
2021-01-04 - Written - Bovy (UofT)
Potential of an arbitrary axisymmetric disk.
Parameters
----------
amp : float, optional
Amplitude to be applied to the potential. Default is 1.0.
surfdens : callable, optional
Function of a single variable that gives the surface density as a function of radius (can return a Quantity). Default is ``lambda R: 1.5 * numpy.exp(-3.0 * R)``.
normalize : bool or float, optional
If True, normalize such that vc(1.,0.)=1., or, if given as a number, such that the force is this fraction of the force necessary to make vc(1.,0.)=1. Default is False.
ro : float or Quantity, optional
Distance scale for translation into internal units (default from configuration file).
vo : float or Quantity, optional
Velocity scale for translation into internal units (default from configuration file).
Notes
-----
- 2021-01-04 - Written - Bovy (UofT)
"""
Potential.__init__(self, amp=amp, ro=ro, vo=vo)
Expand Down Expand Up @@ -99,21 +92,6 @@ def __init__(

@check_potential_inputs_not_arrays
def _evaluate(self, R, z, phi=0.0, t=0.0):
"""
NAME:
_evaluate
PURPOSE:
evaluate the potential at (R,z)
INPUT:
R - Cylindrical Galactocentric radius
z - vertical height
phi - azimuth
t - time
OUTPUT:
potential at (R,z)
HISTORY:
2021-01-04 - Written - Bovy (UofT)
"""
if R == 0 and z == 0:
return self._pot_zero
elif numpy.isinf(R**2 + z**2):
Expand All @@ -131,21 +109,6 @@ def _evaluate(self, R, z, phi=0.0, t=0.0):

@check_potential_inputs_not_arrays
def _Rforce(self, R, z, phi=0.0, t=0.0):
"""
NAME:
_Rforce
PURPOSE:
evaluate the radial force at (R,z)
INPUT:
R - Cylindrical Galactocentric radius
z - vertical height
phi - azimuth
t - time
OUTPUT:
F_R at (R,z)
HISTORY:
2021-01-04 - Written - Bovy (UofT)
"""
R2 = R**2
z2 = z**2

Expand All @@ -172,21 +135,6 @@ def rforceint(a):

@check_potential_inputs_not_arrays
def _zforce(self, R, z, phi=0.0, t=0.0):
"""
NAME:
_zforce
PURPOSE:
evaluate the vertical force at (R,z)
INPUT:
R - Cylindrical Galactocentric radius
z - vertical height
phi - azimuth
t - time
OUTPUT:
F_z at (R,z)
HISTORY:
2021-01-04 - Written - Bovy (UofT)
"""
if z == 0:
return 0.0
z2 = z**2
Expand All @@ -213,21 +161,6 @@ def zforceint(a):

@check_potential_inputs_not_arrays
def _R2deriv(self, R, z, phi=0.0, t=0.0):
"""
NAME:
_R2deriv
PURPOSE:
evaluate the 2nd radial derivative at (R,z)
INPUT:
R - Cylindrical Galactocentric radius
z - vertical height
phi - azimuth
t - time
OUTPUT:
d2 Phi / dR2 at (R,z)
HISTORY:
2021-01-04 - Written - Bovy (UofT)
"""
R2 = R**2
z2 = z**2

Expand Down Expand Up @@ -262,21 +195,6 @@ def r2derivint(a):

@check_potential_inputs_not_arrays
def _z2deriv(self, R, z, phi=0.0, t=0.0):
"""
NAME:
_z2deriv
PURPOSE:
evaluate the 2nd vertical derivative at (R,z)
INPUT:
R - Cylindrical Galactocentric radius
z - vertical height
phi - azimuth
t - time
OUTPUT:
d2 Phi / dz2 at (R,z)
HISTORY:
2021-01-04 - Written - Bovy (UofT)
"""
R2 = R**2
z2 = z**2

Expand Down Expand Up @@ -304,21 +222,6 @@ def z2derivint(a):

@check_potential_inputs_not_arrays
def _Rzderiv(self, R, z, phi=0.0, t=0.0):
"""
NAME:
_Rzderiv
PURPOSE:
evaluate the mixed radial, vertical derivative at (R,z)
INPUT:
R - Cylindrical Galactocentric radius
z - vertical height
phi - azimuth
t - time
OUTPUT:
d2 Phi / dRdz at (R,z)
HISTORY:
2021-01-04 - Written - Bovy (UofT)
"""
R2 = R**2
z2 = z**2

Expand Down Expand Up @@ -359,19 +262,4 @@ def rzderivint(a):
)

def _surfdens(self, R, z, phi=0.0, t=0.0):
"""
NAME:
_surfdens
PURPOSE:
evaluate the surface density
INPUT:
R - Cylindrical Galactocentric radius
z - vertical height
phi - azimuth
t - time
OUTPUT:
Sigma (R,z)
HISTORY:
2021-01-04 - Written - Bovy (UofT)
"""
return self._sdens(R)
47 changes: 19 additions & 28 deletions galpy/potential/AnySphericalPotential.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,31 @@ class AnySphericalPotential(SphericalPotential):

def __init__(
self,
dens=lambda r: 0.64 / r / (1 + r) ** 3,
amp=1.0,
dens=lambda r: 0.64 / r / (1 + r) ** 3,
normalize=False,
ro=None,
vo=None,
):
"""
NAME:
__init__
PURPOSE:
Initialize the potential of an arbitrary spherical density distribution
INPUT:
dens= (0.64/r/(1+r)**3) function of a single variable that gives the density as a function of radius (can return a Quantity)
amp= (1.) amplitude to be applied to the potential
normalize - if True, normalize such that vc(1.,0.)=1., or, if
given as a number, such that the force is this fraction
of the force necessary to make vc(1.,0.)=1.
ro=, vo= distance and velocity scales for translation into internal units (default from configuration file)
OUTPUT:
(none)
HISTORY:
2021-01-05 - Written - Bovy (UofT)
Initialize the potential of an arbitrary spherical density distribution.
Parameters
----------
amp : float, optional
Amplitude to be applied to the potential. Default is 1.0.
dens : callable, optional
A function of a single variable that gives the density as a function of radius (can return a Quantity). Default is ``lambda r: 0.64 / r / (1 + r) ** 3``.
normalize : bool or float, optional
If True, normalize such that vc(1.,0.)=1., or, if given as a number, such that the force is this fraction of the force necessary to make vc(1.,0.)=1.
ro : float or Quantity, optional
Distance scale for translation into internal units (default from configuration file).
vo : float or Quantity, optional
Velocity scale for translation into internal units (default from configuration file).
Notes
-----
- 2021-01-05 - Written - Bovy (UofT)
"""
SphericalPotential.__init__(self, amp=amp, ro=ro, vo=vo)
Expand Down
Loading

0 comments on commit 02e801d

Please sign in to comment.