Skip to content

Commit

Permalink
Numpy-style docstrings for DF functions and methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jobovy committed Oct 2, 2023
1 parent 85e3e3e commit 8be16e0
Show file tree
Hide file tree
Showing 20 changed files with 4,619 additions and 4,983 deletions.
64 changes: 28 additions & 36 deletions galpy/df/constantbetaHernquistdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,22 @@ class constantbetaHernquistdf(_constantbetadf):

def __init__(self, pot=None, beta=0, ro=None, vo=None):
"""
NAME:
__init__
PURPOSE:
Initialize a Hernquist DF with constant anisotropy
INPUT:
pot - Hernquist potential which determines the DF
beta - anisotropy parameter
OUTPUT:
None
HISTORY:
2020-07-22 - Written - Lane (UofT)
Initialize a Hernquist DF with constant anisotropy.
Parameters
----------
pot : HernquistPotential
Hernquist potential which determines the DF.
beta : float
Anisotropy parameter.
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
-----
- 2020-07-22 - Written - Lane (UofT)
"""
assert isinstance(
pot, HernquistPotential
Expand All @@ -56,25 +51,22 @@ def __init__(self, pot=None, beta=0, ro=None, vo=None):

def fE(self, E):
"""
NAME:
fE
PURPOSE
Calculate the energy portion of a Hernquist distribution function
INPUT:
E - The energy (can be Quantity)
Calculate the energy portion of a Hernquist distribution function
OUTPUT:
Parameters
----------
E : float, numpy.ndarray, or Quantity
The energy.
fE - The value of the energy portion of the DF
Returns
-------
float or numpy.ndarray
The value of the energy portion of the DF
HISTORY:
Notes
-----
- 2020-07-22 - Written
2020-07-22 - Written
"""
Etilde = -numpy.atleast_1d(conversion.parse_energy(E, vo=self._vo) / self._psi0)
# Handle potential E outside of bounds
Expand Down
152 changes: 68 additions & 84 deletions galpy/df/constantbetadf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,24 @@ def __init__(
self, pot=None, denspot=None, beta=None, rmax=None, scale=None, ro=None, vo=None
):
"""
NAME:
__init__
PURPOSE:
Initialize a spherical DF with constant anisotropy parameter
INPUT:
pot - Spherical potential which determines the DF
denspot= (None) Potential instance or list thereof that represent the density of the tracers (assumed to be spherical; if None, set equal to pot)
rmax= (None) maximum radius to consider (can be Quantity); DF is cut off at E = Phi(rmax)
scale - Characteristic scale radius to aid sampling calculations.
Not necessary, and will also be overridden by value from pot if
available.
Initialize a spherical DF with constant anisotropy parameter.
Parameters
----------
pot : Potential or list of Potential instances, optional
Spherical potential which determines the DF.
denspot : Potential or list of Potential instances, optional
Potential instance or list thereof that represent the density of the tracers (assumed to be spherical; if None, set equal to pot).
beta : float, optional
Anisotropy parameter. Default is None.
rmax : float or Quantity, optional
Maximum radius to consider; DF is cut off at E = Phi(rmax). Default is None.
scale : float or Quantity, optional
Characteristic scale radius to aid sampling calculations. Not necessary, and will also be overridden by value from pot if available. Default is None.
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).
"""
anisotropicsphericaldf.__init__(
self, pot=pot, denspot=denspot, rmax=rmax, scale=scale, ro=ro, vo=vo
Expand All @@ -51,27 +49,24 @@ def __init__(

def _call_internal(self, *args):
"""
NAME:
Evaluate the DF for a constant anisotropy Hernquist.
_call_internal
Parameters
----------
E : float
The energy.
L : float
The angular momentum.
PURPOSE:
Returns
-------
float
The value of the DF.
Evaluate the DF for a constant anisotropy Hernquist
Notes
-----
- 2020-07-22 - Written - Lane (UofT)
INPUT:
E - The energy
L - The angular momentum
OUTPUT:
fH - The value of the DF
HISTORY:
2020-07-22 - Written - Lane (UofT)
"""
E, L, _ = args
return L ** (-2 * self._beta) * self.fE(E)
Expand Down Expand Up @@ -166,37 +161,30 @@ def __init__(
vo=None,
):
"""
NAME:
__init__
PURPOSE:
Initialize a spherical DF with constant anisotropy parameter
INPUT:
pot= (None) Potential instance or list thereof
denspot= (None) Potential instance or list thereof that represent the density of the tracers (assumed to be spherical; if None, set equal to pot)
beta= (0.) anisotropy parameter
twobeta= (None) twice the anisotropy parameter (useful for \beta = half-integer, which is a special case); has priority over beta
rmax= (None) maximum radius to consider (can be Quantity); DF is cut off at E = Phi(rmax)
scale - Characteristic scale radius to aid sampling calculations. Optionaland will also be overridden by value from pot if available.
ro=, vo= galpy unit parameters
OUTPUT:
None
HISTORY:
2021-02-14 - Written - Bovy (UofT)
Initialize a spherical DF with constant anisotropy parameter
Parameters
----------
pot : Potential instance or list thereof, optional
Potential instance or list thereof
denspot : Potential instance or list thereof, optional
Potential instance or list thereof that represent the density of the tracers (assumed to be spherical; if None, set equal to pot)
beta : float, optional
anisotropy parameter
twobeta : float, optional
twice the anisotropy parameter (useful for \beta = half-integer, which is a special case); has priority over beta
rmax : float or Quantity, optional
maximum radius to consider; DF is cut off at E = Phi(rmax)
scale : float or Quantity, optional
Characteristic scale radius to aid sampling calculations. Optional and will also be overridden by value from pot if available.
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-02-14 - Written - Bovy (UofT)
"""
if not _JAX_LOADED: # pragma: no cover
Expand Down Expand Up @@ -317,25 +305,21 @@ def sample(self, R=None, z=None, phi=None, n=1, return_orbit=True, rmin=0.0):

def fE(self, E):
"""
NAME:
fE
PURPOSE
Calculate the energy portion of a constant-beta distribution function
INPUT:
E - The energy (can be Quantity)
OUTPUT:
Calculate the energy portion of a constant-beta distribution function
fE - The value of the energy portion of the DF
Parameters
----------
E : float, numpy.ndarray, or Quantity
The energy.
HISTORY:
Returns
-------
numpy.ndarray
The value of the energy portion of the DF
2021-02-14 - Written - Bovy (UofT)
Notes
-----
- 2021-02-14 - Written - Bovy (UofT)
"""
Eint = numpy.atleast_1d(conversion.parse_energy(E, vo=self._vo))
out = numpy.zeros_like(Eint)
Expand Down
81 changes: 30 additions & 51 deletions galpy/df/df.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ class df:

def __init__(self, ro=None, vo=None):
"""
NAME:
__init__
PURPOSE:
initialize a DF object
INPUT:
ro= (None) distance scale
vo= (None) velocity scale
OUTPUT:
HISTORY:
2016-02-28 - Written - Bovy (UofT)
Initialize a DF object.
Parameters
----------
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
-----
- 2016-02-28 - Written - Bovy (UofT)
"""
# Parse ro and vo
if ro is None:
Expand All @@ -41,25 +44,11 @@ def _check_consistent_units(self):

def turn_physical_off(self):
"""
NAME:
turn_physical_off
PURPOSE:
turn off automatic returning of outputs in physical units
INPUT:
(none)
OUTPUT:
(none)
HISTORY:
Turn off automatic returning of outputs in physical units.
2017-06-05 - Written - Bovy (UofT)
Notes
-----
- 2017-06-05 - Written - Bovy (UofT)
"""
self._roSet = False
Expand All @@ -68,29 +57,19 @@ def turn_physical_off(self):

def turn_physical_on(self, ro=None, vo=None):
"""
NAME:
turn_physical_on
PURPOSE:
turn on automatic returning of outputs in physical units
INPUT:
ro= reference distance (kpc; can be Quantity)
vo= reference velocity (km/s; can be Quantity)
OUTPUT:
(none)
HISTORY:
2016-06-05 - Written - Bovy (UofT)
2020-04-22 - Don't turn on a parameter when it is False - Bovy (UofT)
Turn on automatic returning of outputs in physical units.
Parameters
----------
ro : float or Quantity, optional
Reference distance (kpc). If False, don't turn it on.
vo : float or Quantity, optional
Reference velocity (km/s). If False, don't turn it on.
Notes
-----
- 2016-06-05 - Written - Bovy (UofT)
- 2020-04-22 - Don't turn on a parameter when it is False - Bovy (UofT)
"""
if not ro is False:
Expand Down
Loading

0 comments on commit 8be16e0

Please sign in to comment.