Skip to content

Commit 06943f2

Browse files
committed
Doc updates for new CompositePotential use
1 parent 4944fcb commit 06943f2

4 files changed

Lines changed: 67 additions & 64 deletions

File tree

doc/source/actionAngle.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ dynamical in the vertical direction perpendicular to the main plane of a disk.
820820

821821
The action-angle coordinates for one-dimensional potentials are computed using the
822822
``actionAngleVertical`` class. This class can be initialized with a
823-
``linearPotential`` instance or with a list of such instances
823+
``linearPotential`` instance or with a combination of such instances
824824
(``verticalPotential`` instances which represent the vertical direction of
825825
3D potentials are examples of a ``linearPotential``). As an example, we'll
826826
consider orbits in the one-dimensional version of the ``MWPotential2014`` model

doc/source/getting_started.rst

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,13 @@ rotation curve
3838
>>> mp= MiyamotoNagaiPotential(a=0.5,b=0.0375,normalize=.6)
3939
>>> np= NFWPotential(a=4.5,normalize=.35)
4040
>>> hp= HernquistPotential(a=0.6/8,normalize=0.05)
41-
>>> from galpy.potential import plotRotcurve
42-
>>> plotRotcurve(hp+mp+np,Rrange=[0.01,10.],grid=1001,yrange=[0.,1.2])
41+
>>> (hp+mp+np).plotRotcurve(Rrange=[0.01,10.],grid=1001,yrange=[0.,1.2])
4342

4443
Note that the ``normalize`` values add up to 1. such that the circular
4544
velocity will be 1 at R=1. Potentials can be combined into a composite
46-
potential either by combining them in a list as ``[hp,mp,np]`` or by
47-
adding them up ``hp+mp+np`` (the latter simply returns the list
48-
``[hp,mp,np]``). The resulting rotation curve is approximately
49-
flat. To show the rotation curves of the three components do
45+
potential by adding them up ``hp+mp+np``.
46+
The resulting rotation curve is approximately flat.
47+
To show the rotation curves of the three components do
5048

5149
>>> mp.plotRotcurve(Rrange=[0.01,10.],grid=1001,overplot=True)
5250
>>> hp.plotRotcurve(Rrange=[0.01,10.],grid=1001,overplot=True)
@@ -56,7 +54,7 @@ You'll see the following
5654

5755
.. image:: images/rotcurve.png
5856

59-
As a shortcut the ``[hp,mp,np]`` Milky-Way-like potential is defined as
57+
As a shortcut the ``hp+mp+np`` Milky-Way-like potential is defined as
6058

6159
>>> from galpy.potential import MWPotential
6260

@@ -104,14 +102,14 @@ or about 223 Myr. We can also express forces in various physical
104102
units. For example, for the Milky-Way-like potential defined in galpy,
105103
we have that the vertical force at 1.1 kpc is
106104

107-
>>> from galpy.potential import MWPotential2014, evaluatezforces
108-
>>> -evaluatezforces(MWPotential2014, 1.,1.1/8.)*conversion.force_in_pcMyr2(220.,8.)
105+
>>> from galpy.potential import MWPotential2014
106+
>>> -MWPotential2014.zforce(1.,1.1/8.)*conversion.force_in_pcMyr2(220.,8.)
109107
# 2.0259181908629933
110108

111109
which we can also express as an equivalent surface-density by dividing
112110
by :math:`2\pi G`
113111

114-
>>> -evaluatezforces(MWPotential2014, 1.,1.1/8.)*conversion.force_in_2piGmsolpc2(220.,8.)
112+
>>> -MWPotential2014.zforce(1.,1.1/8.)*conversion.force_in_2piGmsolpc2(220.,8.)
115113
# 71.658016957792356
116114

117115
Because the vertical force at the solar circle in the Milky Way at 1.1
@@ -223,7 +221,7 @@ input to any galpy function that does not take a Quantity as an input
223221
<https://github.com/jobovy/galpy/issues>`__.
224222

225223
.. WARNING::
226-
If you combine potentials by adding them (``comb_pot= pot1+pot2``), galpy uses the ``ro`` and ``vo`` scales from the first potential in the list for physical <-> internal unit conversion. If you add potentials using the '+' operator, galpy will check that the units are compatible. galpy does **not** always check whether the unit systems of various objects are consistent when they are combined (but does check this for many common cases, e.g., integrating an Orbit in a Potential, setting up an actionAngle object for a given potential, setting up a DF object for a given potential, etc.).
224+
If you combine potentials by adding them (``comb_pot= pot1+pot2``), galpy uses the ``ro`` and ``vo`` scales from the first potential in the combination for physical <-> internal unit conversion. If you add potentials using the '+' operator, galpy will check that the units are compatible. galpy does **not** always check whether the unit systems of various objects are consistent when they are combined (but does check this for many common cases, e.g., integrating an Orbit in a Potential, setting up an actionAngle object for a given potential, setting up a DF object for a given potential, etc.).
227225

228226
galpy can also return values with units as an astropy
229227
Quantity. Whether or not this is done is specified by the
@@ -269,7 +267,7 @@ Quantity when ``astropy-units = False``. If you setup a Potential, Orbit,
269267
actionAngle, or DF object with parameters specified as a Quantity, the
270268
default is to return any output in physical units. This is why
271269
``mp.vcirc`` returns the velocity in km/s above. Potential and Orbit
272-
instances (or lists of Potentials) also support the functions
270+
instances (or combinations of Potentials) also support the functions
273271
``turn_physical_off`` and ``turn_physical_on`` to turn physical output
274272
off or on. For example, if we do
275273

@@ -395,27 +393,25 @@ above
395393

396394
or of the combination of potentials defined above
397395

398-
>>> from galpy.potential import plotEscapecurve
399-
>>> plotEscapecurve(mp+hp+np,Rrange=[0.01,10.],grid=1001)
396+
>>> (mp+hp+np).plotEscapecurve(Rrange=[0.01,10.],grid=1001)
400397

401398
.. image:: images/esc-comb.png
402399

403400
For the Milky-Way-like potential ``MWPotential2014``, the
404401
escape-velocity curve is
405402

406-
>>> plotEscapecurve(MWPotential2014,Rrange=[0.01,10.],grid=1001)
403+
>>> MWPotential2014.plotEscapecurve(Rrange=[0.01,10.],grid=1001)
407404

408405
.. image:: images/esc-mw14.png
409406

410407
At the solar radius, the escape velocity is
411408

412-
>>> from galpy.potential import vesc
413-
>>> vesc(MWPotential2014,1.)
409+
>>> MWPotential2014.vesc(1.)
414410
2.3316389848832784
415411

416412
Or, for a local circular velocity of 220 km/s
417413

418-
>>> vesc(MWPotential2014,1.)*220.
414+
>>> MWPotential2014.vesc(1.)*220.
419415
# 512.96057667432126
420416

421417
similar to direct measurements of this (e.g., `2007MNRAS.379..755S

doc/source/potential.rst

Lines changed: 51 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,34 @@ such instances. Similarly, we can evaluate a Potential instance
3434
>>> mp(1.,0.)
3535
# -1.2889062500000001
3636

37-
Most member functions of Potential instances have corresponding
38-
functions in the galpy.potential module that allow them to be
39-
evaluated for lists of multiple Potential instances (and in versions
40-
>=1.4 even for nested lists of Potential
41-
instances). ``galpy.potential.MWPotential2014`` is such a list of
37+
You can create more potentials by adding up multiple Potential instances using the
38+
``+`` operator. For example, ``galpy.potential.MWPotential2014`` is such a combination of
4239
three Potential instances
4340

4441
>>> from galpy.potential import MWPotential2014
4542
>>> print(MWPotential2014)
46-
# [<galpy.potential.PowerSphericalPotentialwCutoff.PowerSphericalPotentialwCutoff instance at 0x1089b23b0>, <galpy.potential.MiyamotoNagaiPotential.MiyamotoNagaiPotential instance at 0x1089b2320>, <galpy.potential.TwoPowerSphericalPotential.NFWPotential instance at 0x1089b2248>]
43+
# CompositePotential of 3 potentials:
44+
# PowerSphericalPotentialwCutoff with internal parameters: amp=0.029994597188218296, alpha=1.8, rc=0.2375
45+
# MiyamotoNagaiPotential with internal parameters: amp=0.7574802019371595, a=0.375, b=0.035
46+
# NFWPotential with internal parameters: amp=4.852230533527998, a=2.0
47+
#and physical outputs off
4748

48-
and we can evaluate the potential by using the ``evaluatePotentials``
49+
Combinations of potentials can be evaluated in the same way as single
50+
Potential instances, e.g.,
51+
52+
>>> from galpy.potential import MWPotential2014
53+
>>> MWPotential2014(1.,0.)
54+
# -1.3733506513947897
55+
56+
For historical reasons, there is also a functional interface in the
57+
``galpy.potential`` module that mirrors most member functions of Potential instances.
58+
For example, we can evaluate the potential also by using the ``evaluatePotentials``
4959
function
5060

5161
>>> from galpy.potential import evaluatePotentials
5262
>>> evaluatePotentials(MWPotential2014,1.,0.)
5363
# -1.3733506513947895
5464

55-
.. TIP::
56-
Lists of Potential instances can be nested, allowing you to easily add components to existing gravitational-potential models. For example, to add a ``DehnenBarPotential`` to ``MWPotential2014``, you can do: ``pot= [MWPotential2014,DehnenBarPotential()]`` and then use this ``pot`` everywhere where you can use a list of Potential instances. You can also add potential simply as ``pot= MWPotential2014+DehnenBarPotential()``.
57-
5865
.. WARNING::
5966
``galpy`` potentials do *not* necessarily approach zero at infinity. To compute, for example, the escape velocity or whether or not an orbit is unbound, you need to take into account the value of the potential at infinity. E.g., :math:`v_{\mathrm{esc}}(r) = \sqrt{2[\Phi(\infty)-\Phi(r)]}`. If you want to create a potential that does go to zero at infinity, you can add a :ref:`NullPotential <null_potential>` with value equal to minus the original potential evaluated at infinity.
6067

@@ -71,15 +78,16 @@ which produces the following plot
7178

7279
.. image:: images/mp-potential.png
7380

74-
Similarly, we can plot combinations of Potentials using
75-
``plotPotentials``, e.g.,
81+
Similarly, we can plot combinations of Potentials using the ``.plot`` member function, or using the
82+
``plotPotentials`` function, e.g.,
7683

7784
>>> from galpy.potential import plotPotentials
7885
>>> plotPotentials(MWPotential2014,rmin=0.01)
7986

8087
.. image:: images/MWPotential-potential.png
8188

82-
These functions have arguments that can provide custom ``R`` and ``z``
89+
this produces the same plot as ``MWPotential2014.plot(rmin=0.01)``. These functions
90+
have arguments that can provide custom ``R`` and ``z``
8391
ranges for the plot, the number of grid points, the number of
8492
contours, and many other parameters determining the appearance of
8593
these figures.
@@ -114,24 +122,23 @@ assuming a physical circular velocity of 220 km/s at R=8 kpc
114122
>>> mp.zforce(1.,0.125)*conversion.force_in_2piGmsolpc2(220.,8.)
115123
# -119.72021771473301 #2 \pi G Msol / pc^2
116124

117-
Again, there are functions in ``galpy.potential`` that allow for the
118-
evaluation of the forces for lists of Potential instances, such that
125+
Again, the forces for combinations of Potential instances, like ``MWPotential2014``,
126+
can be calculated using the same member functions, or using the functional interface. For example,
119127

120128
>>> from galpy.potential import evaluateRforces
121-
>>> evaluateRforces(MWPotential2014,1.,0.)
129+
>>> evaluateRforces(MWPotential2014,1.,0.), MWPotential2014.Rforce(1.,0.)
122130
# -1.0
123131
>>> from galpy.potential import evaluatezforces
124132
>>> evaluatezforces(MWPotential2014,1.,0.125)*conversion.force_in_2piGmsolpc2(220.,8.)
125133
>>> -69.680720137571114 #2 \pi G Msol / pc^2
126134

127135
We can evaluate the flattening of the potential as
128136
:math:`\sqrt{|z\,F_R/R\,F_Z|}` for a Potential instance as well as for
129-
a list of such instances
137+
a combination of such instances
130138

131139
>>> mp.flattening(1.,0.125)
132140
# 0.4549542914935209
133-
>>> from galpy.potential import flattening
134-
>>> flattening(MWPotential2014,1.,0.125)
141+
>>> MWPotential2014.flattening(1.,0.125)
135142
# 0.61231675305658628
136143

137144
.. WARNING::
@@ -163,19 +170,24 @@ which are the same to machine precision
163170
Similarly, all of the potentials in ``galpy.potential.MWPotential2014``
164171
have explicitly-implemented densities, so we can do
165172

173+
>>> MWPotential2014.dens(1.,0.)
174+
# 0.57508603122264867
175+
176+
or using the functional interface
177+
166178
>>> from galpy.potential import evaluateDensities
167179
>>> evaluateDensities(MWPotential2014,1.,0.)
168180
# 0.57508603122264867
169181

170182
In physical coordinates, this becomes
171183

172-
>>> evaluateDensities(MWPotential2014,1.,0.)*conversion.dens_in_msolpc3(220.,8.)
184+
>>> MWPotential2014.dens(1.,0.)*conversion.dens_in_msolpc3(220.,8.)
173185
# 0.1010945632524705 #Msol / pc^3
174186

175187
We can also plot densities
176188

177-
>>> from galpy.potential import plotDensities
178-
>>> plotDensities(MWPotential2014,rmin=0.1,zmax=0.25,zmin=-0.25,nrs=101,nzs=101)
189+
>>> MWPotential2014.plotDensity(rmin=0.1,zmax=0.25,zmin=-0.25,nrs=101,nzs=101)
190+
# or from galpy.potential import plotDensities; plotDensities(MWPotential2014,rmin=0.1,zmax=0.25,zmin=-0.25,nrs=101,nzs=101)
179191

180192
which gives
181193

@@ -220,7 +232,7 @@ kinds of wrappers are listed on the :ref:`Potential wrapper API page
220232
<potwrapperapi>`. These wrappers can be applied to instances of *any*
221233
potential implemented in galpy (including other wrappers). An example
222234
is to grow a bar using the polynomial smoothing of `Dehnen (2000)
223-
<http://adsabs.harvard.edu/abs/2000AJ....119..800D>`__. We first setup
235+
<http://adsabs.harvard.edu/abs/2000AJ....119..800D>`__. We first set up
224236
an instance of a ``DehnenBarPotential`` that is essentially fully
225237
grown already
226238

@@ -303,53 +315,49 @@ of all, we can calculate the circular velocity and its derivative
303315
>>> mp.dvcircdR(1.)
304316
# -0.163777427566978
305317

306-
or, for lists of Potential instances
318+
or, for combinations of Potential instances
307319

308-
>>> from galpy.potential import vcirc
309-
>>> vcirc(MWPotential2014,1.)
320+
>>> MWPotential2014.vcirc(1.)
310321
# 1.0
311-
>>> from galpy.potential import dvcircdR
312-
>>> dvcircdR(MWPotential2014,1.)
322+
>>> MWPotential2014.dvcircdR(1.)
313323
# -0.10091361254334696
314324

315325
We can also calculate the various frequencies for close-to-circular
316326
orbits. For example, the rotational frequency
317327

318328
>>> mp.omegac(0.8)
319329
# 1.2784598203204887
320-
>>> from galpy.potential import omegac
321-
>>> omegac(MWPotential2014,0.8)
330+
>>> MWPotential2014.omegac(0.8)
322331
# 1.2733514576122869
323332

324333
and the epicycle frequency
325334

326335
>>> mp.epifreq(0.8)
327336
# 1.7774973530267848
328-
>>> from galpy.potential import epifreq
329-
>>> epifreq(MWPotential2014,0.8)
337+
>>> MWPotential2014.epifreq(0.8)
330338
# 1.7452189766287691
331339

332340
as well as the vertical frequency
333341

334342
>>> mp.verticalfreq(1.0)
335343
# 3.7859388972001828
336-
>>> from galpy.potential import verticalfreq
337-
>>> verticalfreq(MWPotential2014,1.)
344+
>>> MWPotential2014.verticalfreq(1.)
338345
# 2.7255405754769875
339346

340347
We can also for example easily make the diagram of :math:`\Omega-n
341348
\kappa /m` that is important for understanding kinematic spiral
342349
density waves. For example, for ``MWPotential2014``
343350

344-
>>> from galpy.potential import MWPotential2014, omegac, epifreq
351+
>>> from galpy.potential import MWPotential2014
345352
>>> def OmegaMinusKappa(pot,Rs,n,m,ro=8.,vo=220.):
346353
# ro,vo for physical units, Rs in units of ro
347-
return omegac(pot,Rs/ro,ro=ro,vo=vo)-n/m*epifreq(pot,Rs/ro,ro=ro,vo=vo)
354+
return pot.omegac(Rs/ro,ro=ro,vo=vo)-n/m*pot.epifreq(Rs/ro,ro=ro,vo=vo)
348355
>>> Rs= numpy.linspace(0.,16.,101) # kpc
349356
>>> plot(Rs,OmegaMinusKappa(MWPotential2014,Rs,0,1))
350357
>>> plot(Rs,OmegaMinusKappa(MWPotential2014,Rs,1,2))
351358
>>> plot(Rs,OmegaMinusKappa(MWPotential2014,Rs,1,1))
352359
>>> plot(Rs,OmegaMinusKappa(MWPotential2014,Rs,1,-2))
360+
>>> xlim(0.,16.)
353361
>>> ylim(-20.,100.)
354362
>>> xlabel(r'$R\,(\mathrm{kpc})$')
355363
>>> ylabel(r'$(\mathrm{km\,s}^{-1}\,\mathrm{kpc}^{-1})$')
@@ -811,13 +819,12 @@ assuming that we scale velocities by ``vo=220`` km/s and positions by
811819
``ro=8`` kpc in galpy. These two strings can then be given to the
812820
``gyrfalcON`` ``accname=`` and ``accpars=`` keywords.
813821

814-
We can do the same for lists of potentials. For example, for
822+
We can do the same for combinations of potentials. For example, for
815823
``MWPotential2014`` we do
816824

817-
>>> from galpy.potential import nemo_accname, nemo_accpars
818-
>>> nemo_accname(MWPotential2014)
825+
>>> MWPotential2014.nemo_accname()
819826
# 'PowSphwCut+MiyamotoNagai+NFW'
820-
>>> nemo_accpars(MWPotential2014,220.,8.)
827+
>>> MWPotential2014.nemo_accpars(220.,8.)
821828
# '0,1001.79126907,1.8,1.9#0,306770.418682,3.0,0.28#0,16.0,162.958241887'
822829

823830
Therefore, these are the ``accname=`` and ``accpars=`` that one needs
@@ -1011,7 +1018,7 @@ take the velocity ``v=[vR,vT,vZ]`` in cylindrical coordinates as an
10111018
argument to the force in addition to the standard
10121019
``(R,z,phi=0,t=0)``. The set of functions ``evaluateXforces`` (with
10131020
``X=R,z,r,phi,etc.``) will evaluate the force due to ``Potential``
1014-
instances, ``DissipativeForce`` instances, or lists of combinations of
1021+
instances, ``DissipativeForce`` instances, or combinations of
10151022
these two.
10161023

10171024
Currently, the dissipative forces implemented in ``galpy`` include
@@ -1033,9 +1040,9 @@ Adding potentials to the galpy framework
10331040
Potentials in galpy can be used in many places such as orbit
10341041
integration, distribution functions, or the calculation of
10351042
action-angle variables, and in most cases any instance of a potential
1036-
class that inherits from the general ``Potential`` class (or a list of
1043+
class that inherits from the general ``Potential`` class (or a combination of
10371044
such instances) can be given. For example, all orbit integration
1038-
routines work with any list of instances of the general ``Potential``
1045+
routines work with any combination of instances of the general ``Potential``
10391046
class. Adding new potentials to galpy therefore allows them to be used
10401047
everywhere in galpy where general ``Potential`` instances can be
10411048
used. Adding a new class of potentials to galpy consists of the
@@ -1202,7 +1209,7 @@ economically in Python than new ``Potential`` instances as described
12021209

12031210
To add a Python implementation of a new wrapper, classes need to
12041211
inherit from ``parentWrapperPotential``, take the potentials to be
1205-
wrapped as a ``pot=`` (a ``Potential``, ``planarPotential``, or a list
1212+
wrapped as a ``pot=`` (a ``Potential``, ``planarPotential``, or a combination
12061213
thereof; automatically assigned to ``self._pot``) input to
12071214
``__init__``, and implement the
12081215
``_wrap(self,attribute,*args,**kwargs)`` function. This function

doc/source/reference/potential.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ defined as
316316
>>> np= NFWPotential(a=16/8.,normalize=.35)
317317
>>> MWPotential2014= bp+mp+np
318318

319-
and can thus be used like any list of ``Potentials``. The mass of the
319+
and can thus be used like any combination of ``Potentials``. The mass of the
320320
dark-matter halo in ``MWPotential2014`` is on the low side of
321321
estimates of the Milky Way's halo mass; if you want to adjust it, for
322322
example making it 50% larger, you can simply multiply the halo part of

0 commit comments

Comments
 (0)