CompositePotential¶
-
class
gala.potential.
CompositePotential
(*args, **kwargs)[source]¶ Bases:
gala.potential.PotentialBase
,collections.OrderedDict
A potential composed of several distinct components. For example, two point masses or a galactic disk and halo, each with their own potential model.
A
CompositePotential
is created like a Python dictionary, e.g.:>>> p1 = SomePotential(func1) >>> p2 = SomePotential(func2) >>> cp = CompositePotential(component1=p1, component2=p2)
This object actually acts like an
OrderedDict
, so if you want to preserve the order of the potential components, use:>>> cp = CompositePotential() >>> cp['component1'] = p1 >>> cp['component2'] = p2
You can also use any of the built-in
Potential
classes as components:>>> from gala.potential import HernquistPotential >>> cp = CompositePotential() >>> cp['spheroid'] = HernquistPotential(m=1E11, c=10., units=(u.kpc,u.Myr,u.Msun,u.radian))
Attributes Summary
parameters
units
Methods Summary
__call__
(q)acceleration
(q[, t])Compute the acceleration due to the potential at the given position(s). clear
(() -> None. Remove all items from od.)copy
(() -> a shallow copy of od)density
(q[, t])Compute the density value at the given position(s). fromkeys
((S[, ...)If not specified, the value defaults to None. get
((k[,d]) -> D[k] if k in D, ...)gradient
(q[, t])Compute the gradient of the potential at the given position(s). has_key
((k) -> True if D has a key k, else False)hessian
(q[, t])Compute the Hessian of the potential at the given position(s). integrate_orbit
(w0[, Integrator, ...])Integrate an orbit in the current potential using the integrator class provided. items
(() -> list of (key, value) pairs in od)iteritems
()od.iteritems -> an iterator over the (key, value) pairs in od iterkeys
(() -> an iterator over the keys in od)itervalues
()od.itervalues -> an iterator over the values in od keys
(() -> list of keys in od)mass_enclosed
(q[, t])Estimate the mass enclosed within the given position by assuming the potential is spherical. plot_contours
(grid[, ax, labels, subplots_kw])Plot equipotentials contours. plot_densty_contours
(grid[, ax, labels, ...])Plot density contours. pop
((k[,d]) -> v, ...)value. If key is not found, d is returned if given, otherwise KeyError popitem
(() -> (k, v), ...)Pairs are returned in LIFO order if last is true or FIFO order if false. save
(f)Save the potential to a text file. setdefault
((k[,d]) -> od.get(k,d), ...)total_energy
(x, v)Compute the total energy (per unit mass) of a point in phase-space in this potential. update
(([E, ...)If E present and has a .keys() method, does: for k in E: D[k] = E[k] value
(q[, t])Compute the value of the potential at the given position(s). values
(() -> list of values in od)viewitems
(...)viewkeys
(...)viewvalues
(...)Attributes Documentation
-
parameters
¶
-
units
¶
Methods Documentation
-
__call__
(q)¶
-
acceleration
(q, t=0.0)¶ Compute the acceleration due to the potential at the given position(s).
Parameters: q : array_like, numeric
Position to compute the acceleration at.
Returns: acc :
ndarray
The acceleration. Will have the same shape as the input position array,
q
.
-
clear
() → None. Remove all items from od.¶
-
copy
() → a shallow copy of od¶
-
density
(q, t=0.0)¶ Compute the density value at the given position(s).
Parameters: q :
Quantity
, array_likeThe position to compute the value of the potential. If the input position object has no units (i.e. is an
ndarray
), it is assumed to be in the same unit system as the potential.Returns: dens :
Quantity
The potential energy or value of the potential. If the input position has shape
q.shape
, the output energy will have shapeq.shape[1:]
.
-
fromkeys
(S[, v]) → New ordered dictionary with keys from S.¶ If not specified, the value defaults to None.
-
get
(k[, d]) → D[k] if k in D, else d. d defaults to None.¶
-
gradient
(q, t=0.0)¶ Compute the gradient of the potential at the given position(s).
Parameters: q :
Quantity
, array_likeThe position to compute the value of the potential. If the input position object has no units (i.e. is an
ndarray
), it is assumed to be in the same unit system as the potential.Returns: grad :
Quantity
The gradient of the potential. Will have the same shape as the input position array,
q
.
-
has_key
(k) → True if D has a key k, else False¶
-
hessian
(q, t=0.0)¶ Compute the Hessian of the potential at the given position(s).
Parameters: q :
Quantity
, array_likeThe position to compute the value of the potential. If the input position object has no units (i.e. is an
ndarray
), it is assumed to be in the same unit system as the potential.Returns: hess :
Quantity
TODO:
-
integrate_orbit
(w0, Integrator=<class 'gala.integrate.pyintegrators.leapfrog.LeapfrogIntegrator'>, Integrator_kwargs={}, cython_if_possible=True, **time_spec)¶ Integrate an orbit in the current potential using the integrator class provided. Uses same time specification as
Integrator.run()
– see the documentation forgala.integrate
for more information.Parameters: w0 :
PhaseSpacePosition
, array_likeInitial conditions.
Integrator :
Integrator
(optional)Integrator class to use.
Integrator_kwargs : dict (optional)
Any extra keyword argumets to pass to the integrator class when initializing. Only works in non-Cython mode.
cython_if_possible : bool (optional)
If there is a Cython version of the integrator implemented, and the potential object has a C instance, using Cython will be much faster.
**time_spec
Specification of how long to integrate. See documentation for
parse_time_specification
.Returns: orbit :
CartesianOrbit
-
items
() → list of (key, value) pairs in od¶
-
iteritems
()¶ od.iteritems -> an iterator over the (key, value) pairs in od
-
iterkeys
() → an iterator over the keys in od¶
-
itervalues
()¶ od.itervalues -> an iterator over the values in od
-
keys
() → list of keys in od¶
-
mass_enclosed
(q, t=0.0)¶ Estimate the mass enclosed within the given position by assuming the potential is spherical.
Parameters: x : array_like, numeric
Position to estimate the enclossed mass.
Returns: menc :
Quantity
The potential energy or value of the potential. If the input position has shape
q.shape
, the output energy will have shapeq.shape[1:]
.
-
plot_contours
(grid, ax=None, labels=None, subplots_kw={}, **kwargs)¶ Plot equipotentials contours. Computes the potential value on a grid (specified by the array
grid
).Warning
Right now the grid input must be arrays and must already be in the unit system of the potential. Quantity support is coming...
Parameters: grid : tuple
Coordinate grids or slice value for each dimension. Should be a tuple of 1D arrays or numbers.
ax : matplotlib.Axes (optional)
labels : iterable (optional)
List of axis labels.
subplots_kw : dict
kwargs passed to matplotlib’s subplots() function if an axes object is not specified.
kwargs : dict
kwargs passed to either contourf() or plot().
Returns: fig :
Figure
-
plot_densty_contours
(grid, ax=None, labels=None, subplots_kw={}, **kwargs)¶ Plot density contours. Computes the density on a grid (specified by the array
grid
).Warning
Right now the grid input must be arrays and must already be in the unit system of the potential. Quantity support is coming...
Parameters: grid : tuple
Coordinate grids or slice value for each dimension. Should be a tuple of 1D arrays or numbers.
ax : matplotlib.Axes (optional)
labels : iterable (optional)
List of axis labels.
subplots_kw : dict
kwargs passed to matplotlib’s subplots() function if an axes object is not specified.
kwargs : dict
kwargs passed to either contourf() or plot().
Returns: fig :
Figure
-
pop
(k[, d]) → v, remove specified key and return the corresponding¶ value. If key is not found, d is returned if given, otherwise KeyError is raised.
-
popitem
() → (k, v), return and remove a (key, value) pair.¶ Pairs are returned in LIFO order if last is true or FIFO order if false.
-
save
(f)¶ Save the potential to a text file. See
save()
for more information.Parameters: f : str, file_like
A filename or file-like object to write the input potential object to.
-
setdefault
(k[, d]) → od.get(k,d), also set od[k]=d if k not in od¶
-
total_energy
(x, v)¶ Compute the total energy (per unit mass) of a point in phase-space in this potential. Assumes the last axis of the input position / velocity is the dimension axis, e.g., for 100 points in 3-space, the arrays should have shape (100,3).
Parameters: x : array_like, numeric
Position.
v : array_like, numeric
Velocity.
-
update
([E, ]**F) → None. Update D from mapping/iterable E and F.¶ If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
-
value
(q, t=0.0)¶ Compute the value of the potential at the given position(s).
Parameters: q :
Quantity
, array_likeThe position to compute the value of the potential. If the input position object has no units (i.e. is an
ndarray
), it is assumed to be in the same unit system as the potential.Returns: E :
Quantity
The potential energy per unit mass or value of the potential. If the input position has shape
q.shape
, the output energy will have shapeq.shape[1:]
.
-
values
() → list of values in od¶
-
viewitems
() → a set-like object providing a view on od's items¶
-
viewkeys
() → a set-like object providing a view on od's keys¶
-
viewvalues
() → an object providing a view on od's values¶
-