Skip to content

Commit

Permalink
docs: example in as_interop
Browse files Browse the repository at this point in the history
Signed-off-by: nstarman <[email protected]>
  • Loading branch information
nstarman committed Jul 8, 2024
1 parent 8178c04 commit 2c823cf
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions src/galax/potential/_potential/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,38 @@ def evaluate_orbit(
# =========================================================================
# Interoperability

def as_interop(self, library: AbstractInteroperableLibrary) -> object:
"""Convert the potential to an object of a different library."""
def as_interop(self, library: type[AbstractInteroperableLibrary], /) -> object:
"""Convert the potential to an object of a different library.
Parameters
----------
library : :class:`~galax.potential.io.AbstractInteroperableLibrary`
The library type to convert the potential to.
Examples
--------
.. invisible-code-block: python
from galax.utils._optional_deps import HAS_GALA
.. skip: start if(not HAS_GALA, reason="requires gala")
>>> import galax.potential as gp
>>> pot = gp.MilkyWayPotential()
Convert the potential to a :mod:`gala` potential
>>> gala_pot = pot.as_interop(gp.io.GalaLibrary)
>>> gala_pot
<CompositePotential disk,bulge,nucleus,halo>
Now converting back to a :mod:`galax` potential
>>> pot2 = gp.io.convert_potential(gp.io.GalaxLibrary, gala_pot)
>>> pot2 == pot
True
.. skip: end
"""
return convert_potential(library, self)


Expand Down

0 comments on commit 2c823cf

Please sign in to comment.