1
1
# Standard library
2
2
import abc
3
- from collections import OrderedDict
4
3
import copy as pycopy
5
- import warnings
6
4
import uuid
5
+ import warnings
6
+ from collections import OrderedDict
7
+
8
+ import astropy .units as u
7
9
8
10
# Third-party
9
11
import numpy as np
10
12
from astropy .constants import G
11
- import astropy .units as u
12
13
from astropy .utils import isiterable
14
+ from astropy .utils .decorators import deprecated
13
15
14
16
try :
15
17
from scipy .spatial .transform import Rotation
21
23
22
24
# Project
23
25
from gala .util import GalaDeprecationWarning
24
- from ..common import CommonBase
25
- from ...util import ImmutableDict , atleast_2d
26
+
26
27
from ...units import DimensionlessUnitSystem
28
+ from ...util import ImmutableDict , atleast_2d
29
+ from ..common import CommonBase
27
30
28
31
__all__ = ["PotentialBase" , "CompositePotential" ]
29
32
@@ -897,6 +900,11 @@ def value(self, *args, **kwargs):
897
900
###########################################################################
898
901
# Interoperability with other packages
899
902
#
903
+ @deprecated (
904
+ since = "v1.8" ,
905
+ message = "This has been replaced by a more general interoperability framework." ,
906
+ alternative = "interop" ,
907
+ )
900
908
def to_galpy_potential (self , ro = None , vo = None ):
901
909
"""Convert a Gala potential to a Galpy potential instance
902
910
@@ -905,9 +913,36 @@ def to_galpy_potential(self, ro=None, vo=None):
905
913
ro : quantity-like (optional)
906
914
vo : quantity-like (optional)
907
915
"""
908
- from .interop import gala_to_galpy_potential
916
+ return self .as_interop ("galpy" , ro = ro , vo = vo )
917
+
918
+ def as_interop (self , package , ** kwargs ):
919
+ """Interoperability with other Galactic dynamics packages
920
+
921
+ Parameters
922
+ ----------
923
+ package : str
924
+ The package to export the potential to. Currently supported packages are
925
+ ``"galpy"`` and ``"agama"``.
926
+ kwargs
927
+ Any additional keyword arguments are passed to the interop function.
928
+ """
929
+ if package == "galpy" :
930
+ from .interop import gala_to_galpy_potential
931
+
932
+ kwargs .setdefault ("ro" , None )
933
+ kwargs .setdefault ("vo" , None )
934
+ return gala_to_galpy_potential (self , ** kwargs )
935
+ elif package == "agama" :
936
+ import agama
909
937
910
- return gala_to_galpy_potential (self , ro = ro , vo = vo )
938
+ from .interop import gala_to_agama_potential
939
+
940
+ agama_pot = gala_to_agama_potential (self , ** kwargs )
941
+ if not isinstance (agama_pot , agama .Potential ):
942
+ agama_pot = agama .Potential (* agama_pot )
943
+ return agama_pot
944
+ else :
945
+ raise ValueError (f"Unsupported package: { package } " )
911
946
912
947
913
948
class CompositePotential (PotentialBase , OrderedDict ):
0 commit comments