Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion galpy/actionAngle/actionAngleIsochroneApprox.py
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ def estimateBIsochrone(pot, R, z, phi=None):
0.01,
100.0,
)
except: # pragma: no cover
except Exception: # pragma: no cover
b = numpy.nan
return b

Expand Down
23 changes: 12 additions & 11 deletions galpy/df/df.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from typing import Optional

from ..util import config, conversion
from ..util.conversion import physical_compatible


class df:
"""Top-level class for DF classes"""

def __init__(self, ro=None, vo=None):
def __init__(self, ro: Optional[float] = None, vo: Optional[float] = None) -> None:
"""
Initialize a DF object.

Expand Down Expand Up @@ -34,15 +36,14 @@ def __init__(self, ro=None, vo=None):
else:
self._vo = conversion.parse_velocity_kms(vo)
self._voSet = True
return None

def _check_consistent_units(self):
def _check_consistent_units(self) -> None:
"""Internal function to check that the set of units for this object is consistent with that for the potential"""
assert physical_compatible(self, self._pot), (
"Physical conversion for the DF object is not consistent with that of the Potential given to it"
)

def turn_physical_off(self):
def turn_physical_off(self) -> None:
"""
Turn off automatic returning of outputs in physical units.

Expand All @@ -53,9 +54,10 @@ def turn_physical_off(self):
"""
self._roSet = False
self._voSet = False
return None

def turn_physical_on(self, ro=None, vo=None):
def turn_physical_on(
self, ro: Optional[float] = None, vo: Optional[float] = None
) -> None:
"""
Turn on automatic returning of outputs in physical units.

Expand All @@ -72,14 +74,13 @@ def turn_physical_on(self, ro=None, vo=None):
- 2020-04-22 - Don't turn on a parameter when it is False - Bovy (UofT)

"""
if not ro is False:
if ro is not False:
self._roSet = True
ro = conversion.parse_length_kpc(ro)
if not ro is None:
if ro is not None:
self._ro = ro
if not vo is False:
if vo is not False:
self._voSet = True
vo = conversion.parse_velocity_kms(vo)
if not vo is None:
if vo is not None:
self._vo = vo
return None
8 changes: 4 additions & 4 deletions galpy/orbit/Orbits.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,12 @@ def name_completer(ipython, event):
out.extend(_known_objects_collections_original_keys)
out.extend(_known_objects_synonyms_original_keys)
out.extend(["ro=", "vo=", "zo=", "solarmotion="])
except:
except Exception:
pass
return out

get_ipython().set_hook("complete_command", name_completer, re_key=".*from_name")
except:
except Exception:
pass


Expand Down Expand Up @@ -5714,7 +5714,7 @@ def _call_internal(self, *args, **kwargs):
raise ValueError("Found time value not in the integration time domain")
try:
self._setupOrbitInterp()
except:
except Exception:
out = numpy.zeros((self.phasedim(), nt, self.size))
for jj in range(nt):
try:
Expand Down Expand Up @@ -5874,7 +5874,7 @@ def _setupOrbitInterp(self):
try: # unsort
self.t = self.t[usindx]
self.orbit = self.orbit[:, usindx]
except:
except Exception:
pass
return None

Expand Down
4 changes: 2 additions & 2 deletions galpy/orbit/integratePlanarOrbit.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,10 +725,10 @@ def _prep_tfuncs(pot_tfuncs):
) # time
try: # using numba
if not _NUMBA_LOADED:
raise
raise ImportError("Numba not loaded")
nb_c_sig = types.double(types.double)
func_pyarr = [cfunc(nb_c_sig, nopython=True)(a).ctypes for a in pot_tfuncs]
except: # Any Exception, switch to regular ctypes wrapping
except Exception: # Any Exception, switch to regular ctypes wrapping
func_pyarr = [func_ctype(a) for a in pot_tfuncs]
pot_tfuncs = (func_ctype * len(func_pyarr))(*func_pyarr)
return pot_tfuncs
Expand Down
28 changes: 17 additions & 11 deletions galpy/potential/Force.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
###############################################################################
import copy
from typing import Optional, Union

import numpy

Expand All @@ -23,7 +24,13 @@
class Force:
"""Top-level class for any force, conservative or dissipative"""

def __init__(self, amp=1.0, ro=None, vo=None, amp_units=None):
def __init__(
self,
amp: float = 1.0,
ro: Optional[float] = None,
vo: Optional[float] = None,
amp_units: Optional[str] = None,
) -> None:
"""
Initialize Force.

Expand Down Expand Up @@ -94,9 +101,8 @@ def __init__(self, amp=1.0, ro=None, vo=None, amp_units=None):
# When amplitude is given with units, turn on physical output
self._roSet = True
self._voSet = True
return None

def __repr__(self):
def __repr__(self) -> str:
"""
Return a string representation of the Force instance.

Expand All @@ -112,7 +118,7 @@ def __repr__(self):
"""
return _build_repr(self)

def __mul__(self, b):
def __mul__(self, b: Union[int, float]) -> "Force":
"""
Multiply a Force or Potential's amplitude by a number

Expand Down Expand Up @@ -142,7 +148,7 @@ def __mul__(self, b):
# Similar functions
__rmul__ = __mul__

def __div__(self, b):
def __div__(self, b: Union[int, float]) -> "Force":
return self.__mul__(1.0 / b)

__truediv__ = __div__
Expand Down Expand Up @@ -202,7 +208,7 @@ def __radd__(self, b):
"""other Force objects or combinations thereof"""
)

def turn_physical_off(self):
def turn_physical_off(self) -> None:
"""
Turn off automatic returning of outputs in physical units.

Expand All @@ -217,9 +223,10 @@ def turn_physical_off(self):
"""
self._roSet = False
self._voSet = False
return None

def turn_physical_on(self, ro=None, vo=None):
def turn_physical_on(
self, ro: Optional[float] = None, vo: Optional[float] = None
) -> None:
"""
Turn on automatic returning of outputs in physical units.

Expand Down Expand Up @@ -250,7 +257,6 @@ def turn_physical_on(self, ro=None, vo=None):
vo = conversion.parse_velocity_kms(vo)
if vo is not None:
self._vo = vo
return None

def _Rforce_nodecorator(self, R, z, **kwargs):
# Separate, so it can be used during orbit integration
Expand Down Expand Up @@ -287,7 +293,7 @@ def _phitorque_nodecorator(self, R, z, **kwargs):

@potential_physical_input
@physical_conversion("force", pop=True)
def rforce(self, R, z, **kwargs):
def rforce(self, R: float, z: float, **kwargs) -> float:
"""
Evaluate the spherical radial force F_r (R,z).

Expand Down Expand Up @@ -318,7 +324,7 @@ def rforce(self, R, z, **kwargs):
kwargs["use_physical"] = False
return self.Rforce(R, z, **kwargs) * R / r + self.zforce(R, z, **kwargs) * z / r

def toPlanar(self):
def toPlanar(self) -> "Force":
"""
Convert a 3D potential into a planar potential in the mid-plane.

Expand Down
13 changes: 6 additions & 7 deletions galpy/potential/SCFPotential.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ def __init__(
isinstance(normalize, (int, float)) and not isinstance(normalize, bool)
):
self.normalize(normalize)
return None

@classmethod
def from_density(
Expand Down Expand Up @@ -242,11 +241,11 @@ def from_density(
try:
dens(0)
numOfParam = 1
except:
except Exception:
try:
dens(0, 0)
numOfParam = 2
except:
except Exception:
numOfParam = 3
param = [1] * numOfParam
try:
Expand Down Expand Up @@ -771,7 +770,7 @@ def _scf_compute_determine_dens_kwargs(dens, param):
try:
param[0] = 1.0
dens(*param, use_physical=False)
except:
except Exception:
dens_kw = {}
else:
dens_kw = {"use_physical": False}
Expand Down Expand Up @@ -806,11 +805,11 @@ def scf_compute_coeffs_spherical(dens, N, a=1.0, radial_order=None):
try:
dens(0)
numOfParam = 1
except:
except Exception:
try:
dens(0, 0)
numOfParam = 2
except:
except Exception:
numOfParam = 3
param = [0] * numOfParam
dens_kw = _scf_compute_determine_dens_kwargs(dens, param)
Expand Down Expand Up @@ -938,7 +937,7 @@ def scf_compute_coeffs_axi(dens, N, L, a=1.0, radial_order=None, costheta_order=
try:
dens(0, 0)
numOfParam = 2
except:
except Exception:
numOfParam = 3
param = [0] * numOfParam
dens_kw = _scf_compute_determine_dens_kwargs(dens, param)
Expand Down
3 changes: 1 addition & 2 deletions galpy/potential/interpSphericalPotential.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def __init__(
# Determine whether rforce is a galpy Potential or a combined potential formed using addition (pot1+pot2+…)
try:
_evaluateRforces(rforce, 1.0, 0.0)
except:
except Exception:
_rforce = rforce
Phi0 = 0.0 if Phi0 is None else Phi0
else:
Expand Down Expand Up @@ -98,7 +98,6 @@ def __init__(
self.hasC = True
self.hasC_dxdv = True
self.hasC_dens = True
return None

def _revaluate(self, r, t=0.0):
out = numpy.empty_like(r)
Expand Down
2 changes: 1 addition & 1 deletion galpy/potential/mwpotentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def __getattr__(self, name):
try:
# In Py3 you can just do 'return globals()[name]', but not in Py2
return self.__globals__[name]
except: # pragma: no cover
except KeyError: # pragma: no cover
raise AttributeError(f"'module' object has no attribute '{name}'")


Expand Down
4 changes: 2 additions & 2 deletions galpy/potential/verticalPotential.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def RZToverticalPotential(RZPot, R):
RZPot = _check_potential_list_and_deprecate(RZPot)
try:
conversion.get_physical(RZPot)
except:
except Exception:
raise PotentialError(
"Input to 'RZToverticalPotential' is neither an RZPotential-instance or a combination of such instances"
)
Expand Down Expand Up @@ -239,7 +239,7 @@ def toVerticalPotential(Pot, R, phi=None, t0=0.0):
Pot = _check_potential_list_and_deprecate(Pot)
try:
conversion.get_physical(Pot)
except:
except Exception:
raise PotentialError(
"Input to 'toVerticalPotential' is neither an Potential-instance or a combination of such instances"
)
Expand Down
Empty file added galpy/py.typed
Empty file.
Loading
Loading