Skip to content

Commit

Permalink
Merge pull request #82 from adrn/potential/cdef-subclass
Browse files Browse the repository at this point in the history
Make subclassing easier for CPotentials
  • Loading branch information
adrn committed Apr 17, 2017
2 parents d0ff55d + 951bcd5 commit 2c65d9e
Show file tree
Hide file tree
Showing 74 changed files with 367 additions and 427 deletions.
19 changes: 11 additions & 8 deletions CHANGES.md
Expand Up @@ -2,15 +2,18 @@
----------------

- Added a new potential class for the Satoh density (Satoh 1980).
- Added support for Leapfrog integration when generating mock
stellar streams.
- Added support for Leapfrog integration when generating mock stellar streams.
- Added new colormaps and defaults for the matplotlib style.
- Added support for non-inertial reference frames and implemented a
constant rotating reference frame.
- Added a new class - `Hamiltonian` - for storing potentials with
reference frames and should be used for orbit integration.
- Added a new mock stream argument to output orbits of all of the
mock stream star particles to an HDF5 file.
- Added support for non-inertial reference frames and implemented a constant
rotating reference frame.
- Added a new class - `Hamiltonian` - for storing potentials with reference
frames and should be used for orbit integration.
- Added a new mock stream argument to output orbits of all of the mock stream
star particles to an HDF5 file.
- Cleaned up and simplified the process of subclassing a C-implemented
gravitational potential.
- Gravitational potential class instances can now be composed by just adding the
instances.

0.1.1 (2016-05-20)
------------------
Expand Down
41 changes: 33 additions & 8 deletions docs/potential/compositepotential.rst
Expand Up @@ -6,25 +6,49 @@ Creating a composite (multi-component ) potential

Potential objects can be combined into more complex *composite* potentials
using the :class:`~gala.potential.potential.CompositePotential` or
:class:`~gala.potential.potential.CCompositePotential` classes. These classes operate
like a Python dictionary in that each component potential must be named, and
the potentials can either be passed in to the initializer or added after the
:class:`~gala.potential.potential.CCompositePotential` classes. These classes
operate like a Python dictionary in that each component potential must be named,
and the potentials can either be passed in to the initializer or added after the
composite potential container is already created.

For composing any of the built-in potentials or any external potentials
implemented in C, it is always faster to use
:class:`~gala.potential.potential.CCompositePotential`, where the composition is
done at the C layer rather than in Python.

But with either class, interaction with the class is identical. Each component
potential must be instantiated before adding it to the composite potential::
With either class, interaction with the class is identical. To compose
potentials with unique but arbitrary names, you can simply add pre-defined
potential class instances::

>>> import numpy as np
>>> import gala.potential as gp
>>> from gala.units import galactic
>>> disk = gp.MiyamotoNagaiPotential(m=1E11, a=6.5, b=0.27, units=galactic)
>>> bulge = gp.HernquistPotential(m=3E10, c=0.7, units=galactic)
>>> pot = disk + bulge
>>> print(pot.__class__.__name__)
CCompositePotential
>>> list(pot.keys()) # doctest: +SKIP
['c655f07d-a1fe-4905-bdb2-e8a202d15c81',
'8098cb0b-ebad-4388-b685-2f93a874296e']

The two components are assigned unique names and composed into a
:class:`~gala.potential.potential.CCompositePotential` instance because the two
component potentials are implemented in C (i.e. are
:class:`~gala.potential.potential.CPotential`subclass instances). If any of the
individual potential components are Python-only, the resulting object will be
an instance of :class:`~gala.potential.potential.CompositePotential` instead.

Alternatively, the potentials can be composed directly into the object by
treating it like a dictionary. This allows you to specify the keys or names of
the components in the resulting
:class:`~gala.potential.potential.CCompositePotential` instance::

>>> disk = gp.MiyamotoNagaiPotential(m=1E11, a=6.5, b=0.27, units=galactic)
>>> bulge = gp.HernquistPotential(m=3E10, c=0.7, units=galactic)
>>> pot = gp.CCompositePotential(disk=disk, bulge=bulge)
>>> list(pot.keys()) # doctest: +SKIP
['disk', 'bulge']

is equivalent to::

Expand All @@ -34,9 +58,10 @@ is equivalent to::

In detail, the composite potential classes subclass
:class:`~collections.OrderedDict`, so in this sense there is a slight difference
between the two examples above. By defining components after creating the
instance, the order is preserved. In the above example, the disk potential
would always be called first and the bulge would always be called second.
between the two examples above (if you are using a Python version < 3.6). By
defining components after creating the instance, the order is preserved. In the
above example, the disk potential would always be called first and the bulge
would always be called second.

The resulting potential object has all of the same properties as individual
potential objects::
Expand Down
2 changes: 2 additions & 0 deletions gala/__init__.py
Expand Up @@ -2,6 +2,8 @@
Gala.
"""

__author__ = 'adrn <adrianmpw@gmail.com>'

from ._astropy_init import *

# For egg_info test builds to pass, put package imports here.
Expand Down
1 change: 0 additions & 1 deletion gala/coordinates/gd1.py
Expand Up @@ -4,7 +4,6 @@

from __future__ import division, print_function

__author__ = "adrn <adrn@astro.columbia.edu>"

# Third-party
import numpy as np
Expand Down
1 change: 0 additions & 1 deletion gala/coordinates/orphan.py
Expand Up @@ -4,7 +4,6 @@

from __future__ import division, print_function

__author__ = "adrn <adrn@astro.columbia.edu>"

from astropy.coordinates import frame_transform_graph
import astropy.coordinates as coord
Expand Down
1 change: 0 additions & 1 deletion gala/coordinates/poincarepolar.py
Expand Up @@ -2,7 +2,6 @@

from __future__ import division, print_function

__author__ = "adrn <adrn@astro.columbia.edu>"

# Third-party
import numpy as np
Expand Down
1 change: 0 additions & 1 deletion gala/coordinates/quaternion.py
Expand Up @@ -4,7 +4,6 @@

from __future__ import division, print_function

__author__ = "adrn <adrn@astro.columbia.edu>"

# Third-party
import numpy as np
Expand Down
1 change: 0 additions & 1 deletion gala/coordinates/sgr.py
Expand Up @@ -4,7 +4,6 @@

from __future__ import division, print_function

__author__ = "adrn <adrn@astro.columbia.edu>"

# Third-party
import numpy as np
Expand Down
1 change: 0 additions & 1 deletion gala/coordinates/tests/test_gd1.py
Expand Up @@ -2,7 +2,6 @@

from __future__ import absolute_import, unicode_literals, division, print_function

__author__ = "adrn <adrn@astro.columbia.edu>"

# Third-party
import astropy.coordinates as coord
Expand Down
1 change: 0 additions & 1 deletion gala/coordinates/tests/test_orphan.py
Expand Up @@ -5,7 +5,6 @@

from __future__ import absolute_import, division, print_function

__author__ = "adrn <adrn@astro.columbia.edu>"

# Third-party
import astropy.coordinates as coord
Expand Down
1 change: 0 additions & 1 deletion gala/coordinates/tests/test_propermotion.py
Expand Up @@ -5,7 +5,6 @@

from __future__ import absolute_import, division, print_function

__author__ = "adrn <adrn@astro.columbia.edu>"

# Standard library
import tempfile
Expand Down
1 change: 0 additions & 1 deletion gala/coordinates/tests/test_sgr.py
Expand Up @@ -5,7 +5,6 @@

from __future__ import absolute_import, unicode_literals, division, print_function

__author__ = "adrn <adrn@astro.columbia.edu>"

# Third-party
import astropy.coordinates as coord
Expand Down
1 change: 0 additions & 1 deletion gala/coordinates/tests/test_velocity_frame_transforms.py
Expand Up @@ -5,7 +5,6 @@

from __future__ import absolute_import, division, print_function

__author__ = "adrn <adrn@astro.columbia.edu>"

# Standard library
import os
Expand Down
1 change: 0 additions & 1 deletion gala/coordinates/tests/test_velocity_transforms.py
Expand Up @@ -4,7 +4,6 @@

from __future__ import division, print_function

__author__ = "adrn <adrn@astro.columbia.edu>"

# Standard library
import logging
Expand Down
1 change: 0 additions & 1 deletion gala/coordinates/velocity_coord_transforms.py
Expand Up @@ -4,7 +4,6 @@

from __future__ import division, print_function

__author__ = "adrn <adrn@astro.columbia.edu>"

# Standard library

Expand Down
1 change: 0 additions & 1 deletion gala/coordinates/velocity_frame_transforms.py
Expand Up @@ -4,7 +4,6 @@

from __future__ import division, print_function

__author__ = "adrn <adrn@astro.columbia.edu>"

# Third-party
import numpy as np
Expand Down
1 change: 0 additions & 1 deletion gala/dynamics/actionangle.py
Expand Up @@ -7,7 +7,6 @@
arbitrary potential.
"""

__author__ = "adrn <adrn@astro.columbia.edu>"

# Standard library
import time
Expand Down
1 change: 0 additions & 1 deletion gala/dynamics/analyticactionangle.py
Expand Up @@ -6,7 +6,6 @@
Analytic transformations to action-angle coordinates.
"""

__author__ = "adrn <adrn@astro.columbia.edu>"

# Third-party
import numpy as np
Expand Down
1 change: 0 additions & 1 deletion gala/dynamics/core.py
Expand Up @@ -2,7 +2,6 @@

from __future__ import division, print_function

__author__ = "adrn <adrn@astro.columbia.edu>"

# Standard library
import warnings
Expand Down
1 change: 0 additions & 1 deletion gala/dynamics/lyapunov/dop853_lyapunov.pyx
Expand Up @@ -9,7 +9,6 @@

from __future__ import division, print_function

__author__ = "adrn <adrn@astro.columbia.edu>"

# Third-party
import numpy as np
Expand Down
1 change: 0 additions & 1 deletion gala/dynamics/mockstream/_coord.pyx
Expand Up @@ -10,7 +10,6 @@

from __future__ import division, print_function

__author__ = "adrn <adrn@astro.columbia.edu>"

from libc.math cimport M_PI

Expand Down
1 change: 0 additions & 1 deletion gala/dynamics/mockstream/_mockstream.pyx
Expand Up @@ -10,7 +10,6 @@

from __future__ import division, print_function

__author__ = "adrn <adrn@astro.columbia.edu>"

# Standard library
import warnings
Expand Down
1 change: 0 additions & 1 deletion gala/dynamics/mockstream/core.py
Expand Up @@ -2,7 +2,6 @@

from __future__ import division, print_function

__author__ = "adrn <adrn@astro.columbia.edu>"

# Standard library
import warnings
Expand Down
1 change: 0 additions & 1 deletion gala/dynamics/mockstream/tests/test_coord.py
Expand Up @@ -2,7 +2,6 @@

from __future__ import division, print_function

__author__ = "adrn <adrn@astro.columbia.edu>"

# Project
from .._coord import (_test_sat_rotation_matrix, _test_to_sat_coords_roundtrip,
Expand Down
1 change: 0 additions & 1 deletion gala/dynamics/nonlinear.py
Expand Up @@ -2,7 +2,6 @@

from __future__ import division, print_function

__author__ = "adrn <adrn@astro.columbia.edu>"

# Third-party
import astropy.units as u
Expand Down
1 change: 0 additions & 1 deletion gala/dynamics/orbit.py
Expand Up @@ -2,7 +2,6 @@

from __future__ import division, print_function

__author__ = "adrn <adrn@astro.columbia.edu>"

# Standard library
import warnings
Expand Down
1 change: 0 additions & 1 deletion gala/dynamics/plot.py
Expand Up @@ -4,7 +4,6 @@

from __future__ import division, print_function

__author__ = "adrn <adrn@astro.columbia.edu>"

# Third-party
import numpy as np
Expand Down
1 change: 0 additions & 1 deletion gala/dynamics/tests/helpers.py
Expand Up @@ -4,7 +4,6 @@

from __future__ import division, print_function

__author__ = "adrn <adrn@astro.columbia.edu>"

# Third-party
import astropy.coordinates as coord
Expand Down
1 change: 0 additions & 1 deletion gala/dynamics/tests/test_actionangle.py
Expand Up @@ -4,7 +4,6 @@

from __future__ import division, print_function

__author__ = "adrn <adrn@astro.columbia.edu>"

# Standard library
import logging
Expand Down
1 change: 0 additions & 1 deletion gala/dynamics/tests/test_analyticactionangle.py
Expand Up @@ -4,7 +4,6 @@

from __future__ import division, print_function

__author__ = "adrn <adrn@astro.columbia.edu>"

# Third-party
import matplotlib.pyplot as pl
Expand Down
1 change: 0 additions & 1 deletion gala/dynamics/tests/test_nonlinear.py
Expand Up @@ -2,7 +2,6 @@

from __future__ import division, print_function

__author__ = "adrn <adrn@astro.columbia.edu>"

# Third-party
import numpy as np
Expand Down
1 change: 0 additions & 1 deletion gala/dynamics/tests/test_orbit.py
Expand Up @@ -4,7 +4,6 @@

from __future__ import division, print_function

__author__ = "adrn <adrn@astro.columbia.edu>"

# Third-party
from astropy.coordinates import SphericalRepresentation, Galactic
Expand Down
1 change: 0 additions & 1 deletion gala/dynamics/tests/test_plot.py
Expand Up @@ -4,7 +4,6 @@

from __future__ import division, print_function

__author__ = "adrn <adrn@astro.columbia.edu>"

# Standard library
import os
Expand Down
1 change: 0 additions & 1 deletion gala/dynamics/tests/test_util.py
Expand Up @@ -4,7 +4,6 @@

from __future__ import division, print_function

__author__ = "adrn <adrn@astro.columbia.edu>"

# Third-party
import numpy as np
Expand Down
1 change: 0 additions & 1 deletion gala/dynamics/util.py
Expand Up @@ -4,7 +4,6 @@

from __future__ import division, print_function

__author__ = "adrn <adrn@astro.columbia.edu>"

# Third-party
import astropy.units as u
Expand Down
1 change: 0 additions & 1 deletion gala/integrate/core.py
Expand Up @@ -4,7 +4,6 @@

from __future__ import division, print_function

__author__ = "adrn <adrn@astro.columbia.edu>"

# Third-party
import numpy as np
Expand Down
1 change: 0 additions & 1 deletion gala/integrate/cyintegrators/dop853.pyx
Expand Up @@ -9,7 +9,6 @@

from __future__ import division, print_function

__author__ = "adrn <adrn@astro.columbia.edu>"

# Third-party
import numpy as np
Expand Down
1 change: 0 additions & 1 deletion gala/integrate/cyintegrators/leapfrog.pyx
Expand Up @@ -9,7 +9,6 @@

from __future__ import division, print_function

__author__ = "adrn <adrn@astro.columbia.edu>"

# Third-party
import numpy as np
Expand Down
1 change: 0 additions & 1 deletion gala/integrate/pyintegrators/dopri853.py
Expand Up @@ -4,7 +4,6 @@

from __future__ import division, print_function

__author__ = "adrn <adrn@astro.columbia.edu>"

# Third-party
from scipy.integrate import ode
Expand Down

0 comments on commit 2c65d9e

Please sign in to comment.