Skip to content

Commit

Permalink
Merge 3dc26e2 into 9253643
Browse files Browse the repository at this point in the history
  • Loading branch information
jobovy committed Sep 3, 2020
2 parents 9253643 + 3dc26e2 commit 9e01f54
Show file tree
Hide file tree
Showing 63 changed files with 469 additions and 931 deletions.
23 changes: 5 additions & 18 deletions galpy/actionAngle/actionAngle.py
Expand Up @@ -2,14 +2,9 @@
import types
import copy
import numpy
from ..util import config
from ..util import config, conversion
from ..util.conversion import physical_conversion_actionAngle, \
actionAngle_physical_input, physical_compatible
_APY_LOADED= True
try:
from astropy import units
except ImportError:
_APY_LOADED= False
# Metaclass for copying docstrings from subclass methods, first func
# to copy func
def copyfunc(func):
Expand Down Expand Up @@ -54,17 +49,13 @@ def __init__(self,ro=None,vo=None):
self._ro= config.__config__.getfloat('normalization','ro')
self._roSet= False
else:
if _APY_LOADED and isinstance(ro,units.Quantity):
ro= ro.to(units.kpc).value
self._ro= ro
self._ro= conversion.parse_length_kpc(ro)
self._roSet= True
if vo is None:
self._vo= config.__config__.getfloat('normalization','vo')
self._voSet= False
else:
if _APY_LOADED and isinstance(vo,units.Quantity):
vo= vo.to(units.km/units.s).value
self._vo= vo
self._vo= conversion.parse_velocity_kms(vo)
self._voSet= True
return None

Expand Down Expand Up @@ -133,13 +124,9 @@ def turn_physical_on(self,ro=None,vo=None):
if not ro is False: self._roSet= True
if not vo is False: self._voSet= True
if not ro is None and ro:
if _APY_LOADED and isinstance(ro,units.Quantity):
ro= ro.to(units.kpc).value
self._ro= ro
self._ro= conversion.parse_length_kpc(ro)
if not vo is None and vo:
if _APY_LOADED and isinstance(vo,units.Quantity):
vo= vo.to(units.km/units.s).value
self._vo= vo
self._vo= conversion.parse_velocity_kms(vo)
return None

def _parse_eval_args(self,*args,**kwargs):
Expand Down
14 changes: 3 additions & 11 deletions galpy/actionAngle/actionAngleHarmonic.py
Expand Up @@ -13,12 +13,7 @@
###############################################################################
import numpy
from .actionAngle import actionAngle
from galpy.util import conversion
_APY_LOADED= True
try:
from astropy import units
except ImportError:
_APY_LOADED= False
from ..util import conversion
class actionAngleHarmonic(actionAngle):
"""Action-angle formalism for the one-dimensional harmonic oscillator"""
def __init__(self,*args,**kwargs):
Expand Down Expand Up @@ -52,11 +47,8 @@ def __init__(self,*args,**kwargs):
ro=kwargs.get('ro',None),vo=kwargs.get('vo',None))
if not 'omega' in kwargs: #pragma: no cover
raise IOError("Must specify omega= for actionAngleHarmonic")
omega= kwargs.get('omega')
if _APY_LOADED and isinstance(omega,units.Quantity):
omega= omega.to(units.km/units.s/units.kpc).value \
/conversion.freq_in_kmskpc(self._vo,self._ro)
self._omega= omega
self._omega= conversion.parse_frequency(kwargs.get('omega'),
ro=self._ro,vo=self._vo)
return None

def _evaluate(self,*args,**kwargs):
Expand Down
13 changes: 3 additions & 10 deletions galpy/actionAngle/actionAngleHarmonicInverse.py
Expand Up @@ -9,12 +9,7 @@
###############################################################################
import numpy
from .actionAngleInverse import actionAngleInverse
from galpy.util import conversion
_APY_LOADED= True
try:
from astropy import units
except ImportError:
_APY_LOADED= False
from ..util import conversion
class actionAngleHarmonicInverse(actionAngleInverse):
"""Inverse action-angle formalism for the one-dimensional harmonic oscillator"""
def __init__(self,*args,**kwargs):
Expand Down Expand Up @@ -47,10 +42,8 @@ def __init__(self,*args,**kwargs):
actionAngleInverse.__init__(self,*args,**kwargs)
if not 'omega' in kwargs: #pragma: no cover
raise IOError("Must specify omega= for actionAngleHarmonic")
omega= kwargs.get('omega')
if _APY_LOADED and isinstance(omega,units.Quantity):
omega= omega.to(units.km/units.s/units.kpc).value \
/conversion.freq_in_kmskpc(self._vo,self._ro)
omega= conversion.parse_frequency(kwargs.get('omega'),
ro=self._ro,vo=self._vo)
self._omega= omega
return None

Expand Down
11 changes: 2 additions & 9 deletions galpy/actionAngle/actionAngleIsochrone.py
Expand Up @@ -16,12 +16,7 @@
import numpy
from .actionAngle import actionAngle
from ..potential import IsochronePotential
from ..util import galpyWarning
_APY_LOADED= True
try:
from astropy import units
except ImportError:
_APY_LOADED= False
from ..util import galpyWarning, conversion
class actionAngleIsochrone(actionAngle):
"""Action-angle formalism for the isochrone potential, on the Jphi, Jtheta system of Binney & Tremaine (2008)"""
def __init__(self,*args,**kwargs):
Expand Down Expand Up @@ -62,9 +57,7 @@ def __init__(self,*args,**kwargs):
self.b= ip.b
self.amp= ip._amp
else:
self.b= kwargs['b']
if _APY_LOADED and isinstance(self.b,units.Quantity):
self.b= self.b.to(units.kpc).value/self._ro
self.b= conversion.parse_length(kwargs['b'],ro=self._ro)
rb= numpy.sqrt(self.b**2.+1.)
self.amp= (self.b+rb)**2.*rb
self._c= False
Expand Down
20 changes: 4 additions & 16 deletions galpy/actionAngle/actionAngleIsochroneApprox.py
Expand Up @@ -23,16 +23,11 @@
from .actionAngleIsochrone import actionAngleIsochrone
from .actionAngle import actionAngle
from ..potential import IsochronePotential, MWPotential
from ..util import plot, galpyWarning
from ..util import plot, galpyWarning, conversion
from ..util.conversion import physical_conversion, \
potential_physical_input, time_in_Gyr
_TWOPI= 2.*numpy.pi
_ANGLETOL= 0.02 #tolerance for deciding whether full angle range is covered
_APY_LOADED= True
try:
from astropy import units
except ImportError:
_APY_LOADED= False
class actionAngleIsochroneApprox(actionAngle):
"""Action-angle formalism using an isochrone potential as an approximate potential and using a Fox & Binney (2014?) like algorithm to calculate the actions using orbit integrations and a torus-machinery-like angle-fit to get the angles and frequencies (Bovy 2014)"""
def __init__(self,*args,**kwargs):
Expand Down Expand Up @@ -95,16 +90,11 @@ def __init__(self,*args,**kwargs):
raise IOError("'Provided ip= does not appear to be an instance of an IsochronePotential")
self._aAI= actionAngleIsochrone(ip=ip)
else:
if _APY_LOADED and isinstance(kwargs['b'],units.Quantity):
b= kwargs['b'].to(units.kpc).value/self._ro
else:
b= kwargs['b']
b= conversion.parse_length(kwargs['b'],ro=self._ro)
self._aAI= actionAngleIsochrone(ip=IsochronePotential(b=b,
normalize=1.))
self._tintJ= kwargs.get('tintJ',100.)
if _APY_LOADED and isinstance(self._tintJ,units.Quantity):
self._tintJ= self._tintJ.to(units.Gyr).value\
/time_in_Gyr(self._vo,self._ro)
self._tintJ= conversion.parse_time(self._tintJ,ro=self._ro,vo=self._vo)
self._ntintJ= kwargs.get('ntintJ',10000)
self._integrate_dt= kwargs.get('dt',None)
self._tsJ= numpy.linspace(0.,self._tintJ,self._ntintJ)
Expand Down Expand Up @@ -237,9 +227,7 @@ def _actionsFreqsAngles(self,*args,**kwargs):
R,vR,vT,z,vz,phi= self._parse_args(True,_firstFlip,*args)
if 'ts' in kwargs and not kwargs['ts'] is None:
ts= kwargs['ts']
if _APY_LOADED and isinstance(ts,units.Quantity):
ts= ts.to(units.Gyr).value\
/time_in_Gyr(self._vo,self._ro)
ts= conversion.parse_time(ts,ro=self._ro,vo=self._vo)
else:
ts= numpy.empty(R.shape[1])
ts[self._ntintJ-1:]= self._tsJ
Expand Down
12 changes: 3 additions & 9 deletions galpy/actionAngle/actionAngleIsochroneInverse.py
Expand Up @@ -9,13 +9,9 @@
###############################################################################
import numpy
from scipy import optimize
from galpy.potential import IsochronePotential
from ..util import conversion
from ..potential import IsochronePotential
from .actionAngleInverse import actionAngleInverse
_APY_LOADED= True
try:
from astropy import units
except ImportError:
_APY_LOADED= False
class actionAngleIsochroneInverse(actionAngleInverse):
"""Inverse action-angle formalism for the isochrone potential, on the Jphi, Jtheta system of Binney & Tremaine (2008); following McGill & Binney (1990) for transformations"""
def __init__(self,*args,**kwargs):
Expand Down Expand Up @@ -62,9 +58,7 @@ def __init__(self,*args,**kwargs):
self.b= ip.b
self.amp= ip._amp
else:
self.b= kwargs['b']
if _APY_LOADED and isinstance(self.b,units.Quantity):
self.b= self.b.to(units.kpc).value/self._ro
self.b= conversion.parse_length(kwargs['b'],ro=self._ro)
rb= numpy.sqrt(self.b**2.+1.)
self.amp= (self.b+rb)**2.*rb
# In case we ever decide to implement this in C...
Expand Down
10 changes: 2 additions & 8 deletions galpy/actionAngle/actionAngleStaeckel.py
Expand Up @@ -20,18 +20,13 @@
_evaluateRforces, _evaluatezforces
from ..potential.Potential import flatten as flatten_potential
from ..util import coords #for prolate confocal transforms
from ..util import galpyWarning
from ..util import galpyWarning, conversion
from ..util.conversion import physical_conversion, \
potential_physical_input
from .actionAngle import actionAngle, UnboundError
from . import actionAngleStaeckel_c
from .actionAngleStaeckel_c import _ext_loaded as ext_loaded
from ..potential.Potential import _check_c
_APY_LOADED= True
try:
from astropy import units
except ImportError:
_APY_LOADED= False
class actionAngleStaeckel(actionAngle):
"""Action-angle formalism for axisymmetric potentials using Binney (2012)'s Staeckel approximation"""
def __init__(self,*args,**kwargs):
Expand Down Expand Up @@ -84,8 +79,7 @@ def __init__(self,*args,**kwargs):
self._useu0= kwargs.get('useu0',False)
self._delta= kwargs['delta']
self._order= kwargs.get('order',10)
if _APY_LOADED and isinstance(self._delta,units.Quantity):
self._delta= self._delta.to(units.kpc).value/self._ro
self._delta= conversion.parse_length(self._delta,ro=self._ro)
# Check the units
self._check_consistent_units()
return None
Expand Down
11 changes: 2 additions & 9 deletions galpy/actionAngle/actionAngleStaeckelGrid.py
Expand Up @@ -19,13 +19,8 @@
from .. import potential
from ..potential.Potential import _evaluatePotentials
from ..potential.Potential import flatten as flatten_potential
from ..util import multi, coords
from ..util import multi, coords, conversion
_PRINTOUTSIDEGRID= False
_APY_LOADED= True
try:
from astropy import units
except ImportError:
_APY_LOADED= False
class actionAngleStaeckelGrid(actionAngle):
"""Action-angle formalism for axisymmetric potentials using Binney (2012)'s Staeckel approximation, grid-based interpolation"""
def __init__(self,pot=None,delta=None,Rmax=5.,
Expand Down Expand Up @@ -76,9 +71,7 @@ def __init__(self,pot=None,delta=None,Rmax=5.,
self._c= True
else:
self._c= False
self._delta= delta
if _APY_LOADED and isinstance(self._delta,units.Quantity):
self._delta= self._delta.to(units.kpc).value/self._ro
self._delta= conversion.parse_length(delta,ro=self._ro)
self._Rmax= Rmax
self._Rmin= 0.01
#Set up the actionAngleStaeckel object that we will use to interpolate
Expand Down
23 changes: 5 additions & 18 deletions galpy/df/df.py
@@ -1,10 +1,5 @@
from ..util.conversion import physical_compatible
_APY_LOADED= True
try:
from astropy import units
except ImportError:
_APY_LOADED= False
from ..util import config
from ..util import config, conversion
class df(object):
"""Top-level class for DF classes"""
def __init__(self,ro=None,vo=None):
Expand All @@ -25,17 +20,13 @@ def __init__(self,ro=None,vo=None):
self._ro= config.__config__.getfloat('normalization','ro')
self._roSet= False
else:
if _APY_LOADED and isinstance(ro,units.Quantity):
ro= ro.to(units.kpc).value
self._ro= ro
self._ro= conversion.parse_length_kpc(ro)
self._roSet= True
if vo is None:
self._vo= config.__config__.getfloat('normalization','vo')
self._voSet= False
else:
if _APY_LOADED and isinstance(vo,units.Quantity):
vo= vo.to(units.km/units.s).value
self._vo= vo
self._vo= conversion.parse_velocity_kms(vo)
self._voSet= True
return None

Expand Down Expand Up @@ -100,11 +91,7 @@ def turn_physical_on(self,ro=None,vo=None):
if not ro is False: self._roSet= True
if not vo is False: self._voSet= True
if not ro is None and ro:
if _APY_LOADED and isinstance(ro,units.Quantity):
ro= ro.to(units.kpc).value
self._ro= ro
self._ro= conversion.parse_length_kpc(ro)
if not vo is None and vo:
if _APY_LOADED and isinstance(vo,units.Quantity):
vo= vo.to(units.km/units.s).value
self._vo= vo
self._vo= conversion.parse_velocity_kms(vo)
return None

0 comments on commit 9e01f54

Please sign in to comment.