diff --git a/galpy/actionAngle/actionAngleSpherical.py b/galpy/actionAngle/actionAngleSpherical.py index d78b75929..08aeb0c63 100644 --- a/galpy/actionAngle/actionAngleSpherical.py +++ b/galpy/actionAngle/actionAngleSpherical.py @@ -807,9 +807,7 @@ def _calc_anglez( def _JrSphericalIntegrand(r, E, L, pot): """The J_r integrand""" - return numpy.sqrt( - 2.0 * (E - _evaluateplanarPotentials(pot, r)) - L**2.0 / r**2.0 - ) + return numpy.sqrt(2.0 * (E - _evaluateplanarPotentials(pot, r)) - L**2.0 / r**2.0) def _TrSphericalIntegrandSmall(t, E, L, pot, rperi): diff --git a/galpy/actionAngle/actionAngleStaeckel.py b/galpy/actionAngle/actionAngleStaeckel.py index 4fcf160ef..a91d1689f 100644 --- a/galpy/actionAngle/actionAngleStaeckel.py +++ b/galpy/actionAngle/actionAngleStaeckel.py @@ -1237,10 +1237,7 @@ def calcELStaeckel(R, vR, vT, z, vz, pot, vc=1.0, ro=1.0): """ return ( - _evaluatePotentials(pot, R, z) - + vR**2.0 / 2.0 - + vT**2.0 / 2.0 - + vz**2.0 / 2.0, + _evaluatePotentials(pot, R, z) + vR**2.0 / 2.0 + vT**2.0 / 2.0 + vz**2.0 / 2.0, R * vT, ) @@ -1552,9 +1549,7 @@ def estimateDeltaStaeckel(pot, R, z, no_median=False, delta0=1e-6): for ii in range(len(R)) ] ) - indx = (delta2 < delta0**2.0) * ( - (delta2 > -(10.0**-10.0)) + pot_includes_scf - ) + indx = (delta2 < delta0**2.0) * ((delta2 > -(10.0**-10.0)) + pot_includes_scf) delta2[indx] = delta0**2.0 if not no_median: delta2 = numpy.median(delta2[True ^ numpy.isnan(delta2)]) diff --git a/galpy/actionAngle/actionAngleTorus.py b/galpy/actionAngle/actionAngleTorus.py index f2a0dd9cf..bdddfb973 100644 --- a/galpy/actionAngle/actionAngleTorus.py +++ b/galpy/actionAngle/actionAngleTorus.py @@ -18,9 +18,9 @@ from .actionAngleTorus_c import _ext_loaded as ext_loaded _autofit_errvals = {} -_autofit_errvals[ - -1 -] = "something wrong with input, usually bad starting values for the parameters" +_autofit_errvals[-1] = ( + "something wrong with input, usually bad starting values for the parameters" +) _autofit_errvals[-2] = "Fit failed the goal by a factor <= 2" _autofit_errvals[-3] = "Fit failed the goal by more than 2" _autofit_errvals[-4] = "Fit aborted: serious problems occurred" diff --git a/galpy/df/constantbetadf.py b/galpy/df/constantbetadf.py index a9b0a2c07..5d724ebbd 100644 --- a/galpy/df/constantbetadf.py +++ b/galpy/df/constantbetadf.py @@ -384,9 +384,9 @@ def _fEintegrand_raw(r, pot, E, dmp1nudrmp1, alpha): out = numpy.zeros_like(r) # Avoid JAX item assignment issues # print("r",r,dmp1nudrmp1(r),(_evaluatePotentials(pot,r,0)-E)) out[:] = dmp1nudrmp1(r) / (_evaluatePotentials(pot, r, 0) - E) ** alpha - out[ - True ^ numpy.isfinite(out) - ] = 0.0 # assume these are where denom is slightly neg. + out[True ^ numpy.isfinite(out)] = ( + 0.0 # assume these are where denom is slightly neg. + ) return out diff --git a/galpy/df/diskdf.py b/galpy/df/diskdf.py index 31b03204d..e4ecd151e 100644 --- a/galpy/df/diskdf.py +++ b/galpy/df/diskdf.py @@ -1782,9 +1782,7 @@ def _estimateSigmaT2(self, R, phi=0.0, log=False): self._gamma ) else: - return ( - self.targetSigma2(R, log=log, use_physical=False) / self._gamma**2.0 - ) + return self.targetSigma2(R, log=log, use_physical=False) / self._gamma**2.0 class dehnendf(diskdf): diff --git a/galpy/df/evolveddiskdf.py b/galpy/df/evolveddiskdf.py index ede7eff85..49214c0ef 100644 --- a/galpy/df/evolveddiskdf.py +++ b/galpy/df/evolveddiskdf.py @@ -2910,9 +2910,9 @@ def _buildvgrid( deriv=deriv, use_physical=False, ) - out.df[ - ii, jj, numpy.isnan(out.df[ii, jj, :]) - ] = 0.0 # BOVY: for now + out.df[ii, jj, numpy.isnan(out.df[ii, jj, :])] = ( + 0.0 # BOVY: for now + ) if print_progress: sys.stdout.write("\n") # pragma: no cover else: @@ -3278,9 +3278,9 @@ def __init__( self.df[ii, jj, :] = edf( thiso, numpy.array(t).flatten(), deriv=deriv ) - self.df[ - ii, jj, numpy.isnan(self.df[ii, jj, :]) - ] = 0.0 # BOVY: for now + self.df[ii, jj, numpy.isnan(self.df[ii, jj, :])] = ( + 0.0 # BOVY: for now + ) # Multiply in area, somewhat tricky for edge objects if upperdxdy is None or ( ii != 0 @@ -3401,9 +3401,7 @@ def __call__(self, n, m): return numpy.array(out) + self.subgrid(n, m) else: # We already multiplied in the area - thislevel = numpy.dot( - self.vRgrid**n, numpy.dot(self.df, self.vTgrid**m) - ) + thislevel = numpy.dot(self.vRgrid**n, numpy.dot(self.df, self.vTgrid**m)) if self.subgrid is None: return thislevel else: diff --git a/galpy/df/isotropicPlummerdf.py b/galpy/df/isotropicPlummerdf.py index 1eea5cb95..ffbf9b402 100644 --- a/galpy/df/isotropicPlummerdf.py +++ b/galpy/df/isotropicPlummerdf.py @@ -40,12 +40,7 @@ def __init__(self, pot=None, ro=None, vo=None): self._Etildemax = pot._amp / pot._b # /amp^4 instead of /amp^5 to make the DF that of mass density self._fEnorm = ( - 24.0 - * numpy.sqrt(2.0) - / 7.0 - / numpy.pi**3.0 - * pot._b**2.0 - / pot._amp**4.0 + 24.0 * numpy.sqrt(2.0) / 7.0 / numpy.pi**3.0 * pot._b**2.0 / pot._amp**4.0 ) def fE(self, E): diff --git a/galpy/df/osipkovmerrittNFWdf.py b/galpy/df/osipkovmerrittNFWdf.py index a149fd428..46725dc6d 100644 --- a/galpy/df/osipkovmerrittNFWdf.py +++ b/galpy/df/osipkovmerrittNFWdf.py @@ -59,9 +59,7 @@ def __init__(self, pot=None, ra=1.4, rmax=1e4, ro=None, vo=None): self._Qtildemax = pot._amp / pot.a self._Qtildemin = -pot(self._rmax, 0, use_physical=False) / self._Qtildemax self._a2overra2 = self._pot.a**2.0 / self._ra2 - self._fQnorm = ( - self._a2overra2 / (4.0 * numpy.pi) / pot.a**1.5 / pot._amp**0.5 - ) + self._fQnorm = self._a2overra2 / (4.0 * numpy.pi) / pot.a**1.5 / pot._amp**0.5 # Initialize isotropic version to use as part of fQ self._idf = isotropicNFWdf(pot=pot, rmax=rmax, ro=ro, vo=vo) diff --git a/galpy/df/osipkovmerrittdf.py b/galpy/df/osipkovmerrittdf.py index b8e4905bc..e12d96b17 100644 --- a/galpy/df/osipkovmerrittdf.py +++ b/galpy/df/osipkovmerrittdf.py @@ -160,8 +160,7 @@ def _p_v_at_r(self, v, r): ) else: return ( - self.fQ(-_evaluatePotentials(self._pot, r, 0) - 0.5 * v**2.0) - * v**2.0 + self.fQ(-_evaluatePotentials(self._pot, r, 0) - 0.5 * v**2.0) * v**2.0 ) def _sample_v(self, r, eta, n=1): diff --git a/galpy/df/sphericaldf.py b/galpy/df/sphericaldf.py index ff4de0a35..e0d0661fd 100644 --- a/galpy/df/sphericaldf.py +++ b/galpy/df/sphericaldf.py @@ -732,10 +732,7 @@ def _p_v_at_r(self, v, r): * v**2.0 ) else: - return ( - self.fE(_evaluatePotentials(self._pot, r, 0) + 0.5 * v**2.0) - * v**2.0 - ) + return self.fE(_evaluatePotentials(self._pot, r, 0) + 0.5 * v**2.0) * v**2.0 class anisotropicsphericaldf(sphericaldf): diff --git a/galpy/df/streamdf.py b/galpy/df/streamdf.py index 45c872207..704f741ff 100644 --- a/galpy/df/streamdf.py +++ b/galpy/df/streamdf.py @@ -2650,9 +2650,7 @@ def sigangledAngle(self, dangle, assumeZeroMean=True, smallest=False, simple=Fal eigIndx = 1 if simple: dt = self.meantdAngle(dangle, use_physical=False) - return numpy.sqrt( - self._sigangle2 + self._sortedSigOEig[eigIndx] * dt**2.0 - ) + return numpy.sqrt(self._sigangle2 + self._sortedSigOEig[eigIndx] * dt**2.0) aplow = numpy.amax( [ numpy.sqrt(self._sortedSigOEig[eigIndx]) * self._tdisrupt * 5.0, diff --git a/galpy/df/streamgapdf.py b/galpy/df/streamgapdf.py index dbf6af1c5..9b7162f30 100644 --- a/galpy/df/streamgapdf.py +++ b/galpy/df/streamgapdf.py @@ -382,9 +382,7 @@ def _densMoments_approx_higherorder_gaussxpolyInts(self, ll, ul, maxj): in the higher-order terms, recursively""" gaussxpolyInt = numpy.zeros((maxj, len(ul))) gaussxpolyInt[-1] = ( - 1.0 - / numpy.sqrt(numpy.pi) - * (numpy.exp(-(ll**2.0)) - numpy.exp(-(ul**2.0))) + 1.0 / numpy.sqrt(numpy.pi) * (numpy.exp(-(ll**2.0)) - numpy.exp(-(ul**2.0))) ) gaussxpolyInt[-2] = 1.0 / numpy.sqrt(numpy.pi) * ( numpy.exp(-(ll**2.0)) * ll - numpy.exp(-(ul**2.0)) * ul diff --git a/galpy/orbit/Orbits.py b/galpy/orbit/Orbits.py index 271ac03c5..8eb1f91bc 100644 --- a/galpy/orbit/Orbits.py +++ b/galpy/orbit/Orbits.py @@ -219,9 +219,9 @@ def _update_keys_named_objects(): # Format the keys of the known objects dictionary, first collections old_keys = list(_known_objects["_collections"].keys()) for old_key in old_keys: - _known_objects["_collections"][ - _named_objects_key_formatting(old_key) - ] = _known_objects["_collections"].pop(old_key) + _known_objects["_collections"][_named_objects_key_formatting(old_key)] = ( + _known_objects["_collections"].pop(old_key) + ) # Then the objects themselves old_keys = list(_known_objects.keys()) old_keys.remove("_collections") @@ -488,9 +488,7 @@ def _setup_parse_coordtransform(self, vxvv, ro, vo, zo, solarmotion, radec, lb): elif ( not vxvv.galcen_distance is None and numpy.fabs( - ro**2.0 - + zo**2.0 - - vxvv.galcen_distance.to(units.kpc).value ** 2.0 + ro**2.0 + zo**2.0 - vxvv.galcen_distance.to(units.kpc).value ** 2.0 ) > 1e-10 ): @@ -643,8 +641,7 @@ def _setup_parse_vxvv(self, vxvv, radec, lb, uvw): / units.s ) gc_frame = coordinates.Galactocentric( - galcen_distance=numpy.sqrt(self._ro**2.0 + self._zo**2.0) - * units.kpc, + galcen_distance=numpy.sqrt(self._ro**2.0 + self._zo**2.0) * units.kpc, z_sun=self._zo * units.kpc, galcen_v_sun=galcen_v_sun, ) @@ -2148,9 +2145,7 @@ def E(self, *args, **kwargs): for jj in range(self.size) ] ) - + ( - thiso[1] ** 2.0 / 2.0 + thiso[2] ** 2.0 / 2.0 + vz**2.0 / 2.0 - ).T + + (thiso[1] ** 2.0 / 2.0 + thiso[2] ** 2.0 / 2.0 + vz**2.0 / 2.0).T ) elif self.phasedim() == 6: z = kwargs.get("_z", 1.0) * thiso[3] # For ER and Ez @@ -2187,9 +2182,7 @@ def E(self, *args, **kwargs): for jj in range(self.size) ] ) - + ( - thiso[1] ** 2.0 / 2.0 + thiso[2] ** 2.0 / 2.0 + vz**2.0 / 2.0 - ).T + + (thiso[1] ** 2.0 / 2.0 + thiso[2] ** 2.0 / 2.0 + vz**2.0 / 2.0).T ) if onet: return out[:, 0] @@ -8056,9 +8049,11 @@ def _parse_radec_kwargs(orb, kwargs, vel=False, dontpop=False, thiso=None): if isinstance(obs, list) and not thiso is None and thiso.shape[1] > orb.size: nt = thiso.shape[1] // orb.size obs = [ - numpy.tile(obs[ii], nt) - if isinstance(obs[ii], numpy.ndarray) and obs[ii].ndim > 0 - else obs[ii] + ( + numpy.tile(obs[ii], nt) + if isinstance(obs[ii], numpy.ndarray) and obs[ii].ndim > 0 + else obs[ii] + ) for ii in range(len(obs)) ] ro = numpy.tile(ro, nt) if isinstance(ro, numpy.ndarray) and ro.ndim > 0 else ro diff --git a/galpy/potential/BurkertPotential.py b/galpy/potential/BurkertPotential.py index 4c60499f4..87ad5627f 100644 --- a/galpy/potential/BurkertPotential.py +++ b/galpy/potential/BurkertPotential.py @@ -65,8 +65,7 @@ def _revaluate(self, r, t=0.0): * ( -numpy.pi / x + 2.0 * (1.0 / x + 1) * numpy.arctan(1 / x) - + (1.0 / x + 1) - * numpy.log((1.0 + 1.0 / x) ** 2.0 / (1.0 + 1 / x**2.0)) + + (1.0 / x + 1) * numpy.log((1.0 + 1.0 / x) ** 2.0 / (1.0 + 1 / x**2.0)) + special.xlogy(2.0 / x, 1.0 + x**2.0) ) ) diff --git a/galpy/potential/DehnenBarPotential.py b/galpy/potential/DehnenBarPotential.py index a523478b2..71f6f68d8 100644 --- a/galpy/potential/DehnenBarPotential.py +++ b/galpy/potential/DehnenBarPotential.py @@ -163,10 +163,7 @@ def _smooth(self, t): deltat = t - self._tform xi = 2.0 * deltat / (self._tsteady - self._tform) - 1.0 smooth = ( - 3.0 / 16.0 * xi**5.0 - - 5.0 / 8 * xi**3.0 - + 15.0 / 16.0 * xi - + 0.5 + 3.0 / 16.0 * xi**5.0 - 5.0 / 8 * xi**3.0 + 15.0 / 16.0 * xi + 0.5 ) else: # bar is fully on smooth = 1.0 diff --git a/galpy/potential/DehnenSmoothWrapperPotential.py b/galpy/potential/DehnenSmoothWrapperPotential.py index 8c08f5ce0..9b195aa5d 100644 --- a/galpy/potential/DehnenSmoothWrapperPotential.py +++ b/galpy/potential/DehnenSmoothWrapperPotential.py @@ -72,9 +72,7 @@ def _smooth(self, t): elif t < self._tsteady: deltat = t - self._tform xi = 2.0 * deltat / (self._tsteady - self._tform) - 1.0 - smooth = ( - 3.0 / 16.0 * xi**5.0 - 5.0 / 8 * xi**3.0 + 15.0 / 16.0 * xi + 0.5 - ) + smooth = 3.0 / 16.0 * xi**5.0 - 5.0 / 8 * xi**3.0 + 15.0 / 16.0 * xi + 0.5 else: # bar is fully on smooth = 1.0 return smooth if self._grow else 1.0 - smooth diff --git a/galpy/potential/DiskSCFPotential.py b/galpy/potential/DiskSCFPotential.py index be0003a15..a85bd90f6 100644 --- a/galpy/potential/DiskSCFPotential.py +++ b/galpy/potential/DiskSCFPotential.py @@ -392,10 +392,7 @@ def _Rzderiv(self, R, z, phi=0.0, t=0.0): 4.0 * numpy.pi * a - * ( - H(z) * R * z / r**2.0 * (d2s(r) - ds(r) / r) - + ds(r) * dH(z) * R / r - ) + * (H(z) * R * z / r**2.0 * (d2s(r) - ds(r) / r) + ds(r) * dH(z) * R / r) ) return out diff --git a/galpy/potential/EllipsoidalPotential.py b/galpy/potential/EllipsoidalPotential.py index 5934103c9..fd9eb0f51 100644 --- a/galpy/potential/EllipsoidalPotential.py +++ b/galpy/potential/EllipsoidalPotential.py @@ -430,11 +430,7 @@ def _forceInt(x, y, z, dens, b2, c2, i, glx=None, glw=None): def integrand(s): t = 1 / s**2.0 - 1.0 return ( - dens( - numpy.sqrt( - x**2.0 / (1.0 + t) + y**2.0 / (b2 + t) + z**2.0 / (c2 + t) - ) - ) + dens(numpy.sqrt(x**2.0 / (1.0 + t) + y**2.0 / (b2 + t) + z**2.0 / (c2 + t))) * ( x / (1.0 + t) * (i == 0) + y / (b2 + t) * (i == 1) diff --git a/galpy/potential/EllipticalDiskPotential.py b/galpy/potential/EllipticalDiskPotential.py index fc6216e8b..e97f7fcca 100644 --- a/galpy/potential/EllipticalDiskPotential.py +++ b/galpy/potential/EllipticalDiskPotential.py @@ -109,10 +109,7 @@ def _evaluate(self, R, phi=0.0, t=0.0): deltat = t - self._tform xi = 2.0 * deltat / (self._tsteady - self._tform) - 1.0 smooth = ( - 3.0 / 16.0 * xi**5.0 - - 5.0 / 8 * xi**3.0 - + 15.0 / 16.0 * xi - + 0.5 + 3.0 / 16.0 * xi**5.0 - 5.0 / 8 * xi**3.0 + 15.0 / 16.0 * xi + 0.5 ) else: # fully on smooth = 1.0 @@ -135,10 +132,7 @@ def _Rforce(self, R, phi=0.0, t=0.0): deltat = t - self._tform xi = 2.0 * deltat / (self._tsteady - self._tform) - 1.0 smooth = ( - 3.0 / 16.0 * xi**5.0 - - 5.0 / 8 * xi**3.0 - + 15.0 / 16.0 * xi - + 0.5 + 3.0 / 16.0 * xi**5.0 - 5.0 / 8 * xi**3.0 + 15.0 / 16.0 * xi + 0.5 ) else: # fully on smooth = 1.0 @@ -162,18 +156,13 @@ def _phitorque(self, R, phi=0.0, t=0.0): deltat = t - self._tform xi = 2.0 * deltat / (self._tsteady - self._tform) - 1.0 smooth = ( - 3.0 / 16.0 * xi**5.0 - - 5.0 / 8 * xi**3.0 - + 15.0 / 16.0 * xi - + 0.5 + 3.0 / 16.0 * xi**5.0 - 5.0 / 8 * xi**3.0 + 15.0 / 16.0 * xi + 0.5 ) else: # fully on smooth = 1.0 else: smooth = 1.0 - return ( - smooth * self._twophio * R**self._p * numpy.sin(2.0 * (phi - self._phib)) - ) + return smooth * self._twophio * R**self._p * numpy.sin(2.0 * (phi - self._phib)) def _R2deriv(self, R, phi=0.0, t=0.0): # Calculate relevant time @@ -184,10 +173,7 @@ def _R2deriv(self, R, phi=0.0, t=0.0): deltat = t - self._tform xi = 2.0 * deltat / (self._tsteady - self._tform) - 1.0 smooth = ( - 3.0 / 16.0 * xi**5.0 - - 5.0 / 8 * xi**3.0 - + 15.0 / 16.0 * xi - + 0.5 + 3.0 / 16.0 * xi**5.0 - 5.0 / 8 * xi**3.0 + 15.0 / 16.0 * xi + 0.5 ) else: # fully on smooth = 1.0 @@ -212,10 +198,7 @@ def _phi2deriv(self, R, phi=0.0, t=0.0): deltat = t - self._tform xi = 2.0 * deltat / (self._tsteady - self._tform) - 1.0 smooth = ( - 3.0 / 16.0 * xi**5.0 - - 5.0 / 8 * xi**3.0 - + 15.0 / 16.0 * xi - + 0.5 + 3.0 / 16.0 * xi**5.0 - 5.0 / 8 * xi**3.0 + 15.0 / 16.0 * xi + 0.5 ) else: # perturbation is fully on smooth = 1.0 @@ -238,10 +221,7 @@ def _Rphideriv(self, R, phi=0.0, t=0.0): deltat = t - self._tform xi = 2.0 * deltat / (self._tsteady - self._tform) - 1.0 smooth = ( - 3.0 / 16.0 * xi**5.0 - - 5.0 / 8 * xi**3.0 - + 15.0 / 16.0 * xi - + 0.5 + 3.0 / 16.0 * xi**5.0 - 5.0 / 8 * xi**3.0 + 15.0 / 16.0 * xi + 0.5 ) else: # perturbation is fully on smooth = 1.0 diff --git a/galpy/potential/FerrersPotential.py b/galpy/potential/FerrersPotential.py index ae9056f6e..c323c1cbc 100644 --- a/galpy/potential/FerrersPotential.py +++ b/galpy/potential/FerrersPotential.py @@ -439,9 +439,7 @@ def _FracInt(x, y, z, a, b, c, tau, n): sqrt(tau+a)(tau+b)(tau+c)) tau+a tau+b tau+c """ denom = numpy.sqrt((a + tau) * (b + tau) * (c + tau)) - return ( - 1.0 - x**2 / (a + tau) - y**2 / (b + tau) - z**2 / (c + tau) - ) ** n / denom + return (1.0 - x**2 / (a + tau) - y**2 / (b + tau) - z**2 / (c + tau)) ** n / denom def lowerlim(x, y, z, a, b, c): diff --git a/galpy/potential/KGPotential.py b/galpy/potential/KGPotential.py index d8bdb3422..e3da1e302 100644 --- a/galpy/potential/KGPotential.py +++ b/galpy/potential/KGPotential.py @@ -56,11 +56,7 @@ def __init__(self, amp=1.0, K=1.15, F=0.03, D=1.8, ro=None, vo=None): pass if _APY_LOADED and isinstance(F, units.Quantity): try: - F = ( - F.to(units.km**2 / units.s**2 / units.kpc**2).value - * ro**2 - / vo**2 - ) + F = F.to(units.km**2 / units.s**2 / units.kpc**2).value * ro**2 / vo**2 except units.UnitConversionError: raise units.UnitConversionError( "Units for F not understood; should be density" @@ -72,9 +68,7 @@ def __init__(self, amp=1.0, K=1.15, F=0.03, D=1.8, ro=None, vo=None): self.hasC = True def _evaluate(self, x, t=0.0): - return ( - self._K * (numpy.sqrt(x**2.0 + self._D2) - self._D) + self._F * x**2.0 - ) + return self._K * (numpy.sqrt(x**2.0 + self._D2) - self._D) + self._F * x**2.0 def _force(self, x, t=0.0): return -x * (self._K / numpy.sqrt(x**2 + self._D2) + 2.0 * self._F) diff --git a/galpy/potential/LogarithmicHaloPotential.py b/galpy/potential/LogarithmicHaloPotential.py index 93928cfd0..ba9e2f691 100644 --- a/galpy/potential/LogarithmicHaloPotential.py +++ b/galpy/potential/LogarithmicHaloPotential.py @@ -168,14 +168,10 @@ def _z2deriv(self, R, z, phi=0.0, t=0.0): if self.isNonAxi: Rt2 = R**2.0 * (1.0 - self._1m1overb2 * numpy.sin(phi) ** 2.0) denom = 1.0 / (Rt2 + (z / self._q) ** 2.0 + self._core2) - return ( - denom / self._q**2.0 - 2.0 * z**2.0 * denom**2.0 / self._q**4.0 - ) + return denom / self._q**2.0 - 2.0 * z**2.0 * denom**2.0 / self._q**4.0 else: denom = 1.0 / (R**2.0 + (z / self._q) ** 2.0 + self._core2) - return ( - denom / self._q**2.0 - 2.0 * z**2.0 * denom**2.0 / self._q**4.0 - ) + return denom / self._q**2.0 - 2.0 * z**2.0 * denom**2.0 / self._q**4.0 def _Rzderiv(self, R, z, phi=0.0, t=0.0): if self.isNonAxi: @@ -217,10 +213,7 @@ def _Rphideriv(self, R, z, phi=0.0, t=0.0): Rt2 = R**2.0 * (1.0 - self._1m1overb2 * numpy.sin(phi) ** 2.0) denom = 1.0 / (Rt2 + (z / self._q) ** 2.0 + self._core2) return ( - -(denom - Rt2 * denom**2.0) - * R - * numpy.sin(2.0 * phi) - * self._1m1overb2 + -(denom - Rt2 * denom**2.0) * R * numpy.sin(2.0 * phi) * self._1m1overb2 ) else: return 0.0 diff --git a/galpy/potential/McMillan17.py b/galpy/potential/McMillan17.py index 1517e24e0..fd2d9d091 100644 --- a/galpy/potential/McMillan17.py +++ b/galpy/potential/McMillan17.py @@ -91,9 +91,7 @@ def bulge_dens(R, z): ro=ro, vo=vo, ) -McMillan_halo = NFWPotential( - amp=rho0_halo * (4 * numpy.pi * rh**3), a=rh, ro=ro, vo=vo -) +McMillan_halo = NFWPotential(amp=rho0_halo * (4 * numpy.pi * rh**3), a=rh, ro=ro, vo=vo) # Go back to old floating-point warnings settings numpy.seterr(**old_error_settings) McMillan17 = McMillan_disk + McMillan_halo + McMillan_bulge diff --git a/galpy/potential/MiyamotoNagaiPotential.py b/galpy/potential/MiyamotoNagaiPotential.py index b05a6b648..871358299 100644 --- a/galpy/potential/MiyamotoNagaiPotential.py +++ b/galpy/potential/MiyamotoNagaiPotential.py @@ -128,11 +128,7 @@ def _z2deriv(self, R, z, phi=0.0, t=0.0): * numpy.sqrt(self._b2 + z**2.0) + (self._b2 + R**2.0 - 2.0 * z**2.0) * (self._b2 + z**2.0) ** 1.5 + self._a - * ( - 3.0 * self._b2**2.0 - - 4.0 * z**4.0 - + self._b2 * (R**2.0 - z**2.0) - ) + * (3.0 * self._b2**2.0 - 4.0 * z**4.0 + self._b2 * (R**2.0 - z**2.0)) ) / ((self._b2 + z**2.0) ** 1.5 * (R**2.0 + asqrtbz**2.0) ** 2.5) def _Rzderiv(self, R, z, phi=0.0, t=0.0): @@ -141,9 +137,7 @@ def _Rzderiv(self, R, z, phi=0.0, t=0.0): if isinstance(R, float) and sqrtbz == asqrtbz: return -(3.0 * R * z / (R**2.0 + asqrtbz**2.0) ** 2.5) else: - return -( - 3.0 * R * z * asqrtbz / sqrtbz / (R**2.0 + asqrtbz**2.0) ** 2.5 - ) + return -(3.0 * R * z * asqrtbz / sqrtbz / (R**2.0 + asqrtbz**2.0) ** 2.5) @kms_to_kpcGyrDecorator def _nemo_accpars(self, vo, ro): diff --git a/galpy/potential/PlummerPotential.py b/galpy/potential/PlummerPotential.py index 8225f9c48..7b8b9ab35 100644 --- a/galpy/potential/PlummerPotential.py +++ b/galpy/potential/PlummerPotential.py @@ -70,9 +70,7 @@ def _rforce_jax(self, r): return -self._amp * r * (r**2.0 + self._b2) ** -1.5 def _dens(self, R, z, phi=0.0, t=0.0): - return ( - 3.0 / 4.0 / numpy.pi * self._b2 * (R**2.0 + z**2.0 + self._b2) ** -2.5 - ) + return 3.0 / 4.0 / numpy.pi * self._b2 * (R**2.0 + z**2.0 + self._b2) ** -2.5 def _surfdens(self, R, z, phi=0.0, t=0.0): Rb = R**2.0 + self._b2 @@ -87,14 +85,10 @@ def _surfdens(self, R, z, phi=0.0, t=0.0): ) def _R2deriv(self, R, z, phi=0.0, t=0.0): - return (self._b2 - 2.0 * R**2.0 + z**2.0) * ( - R**2.0 + z**2.0 + self._b2 - ) ** -2.5 + return (self._b2 - 2.0 * R**2.0 + z**2.0) * (R**2.0 + z**2.0 + self._b2) ** -2.5 def _z2deriv(self, R, z, phi=0.0, t=0.0): - return (self._b2 + R**2.0 - 2.0 * z**2.0) * ( - R**2.0 + z**2.0 + self._b2 - ) ** -2.5 + return (self._b2 + R**2.0 - 2.0 * z**2.0) * (R**2.0 + z**2.0 + self._b2) ** -2.5 def _Rzderiv(self, R, z, phi=0.0, t=0.0): return -3.0 * R * z * (R**2.0 + z**2.0 + self._b2) ** -2.5 @@ -117,10 +111,7 @@ def _d2densdr2(self, r, t=0.0): / 4.0 / numpy.pi * self._b2 - * ( - (r**2.0 + self._b2) ** -3.5 - - 7.0 * r**2.0 * (r**2 + self._b2) ** -4.5 - ) + * ((r**2.0 + self._b2) ** -3.5 - 7.0 * r**2.0 * (r**2 + self._b2) ** -4.5) ) def _ddenstwobetadr(self, r, beta=0): diff --git a/galpy/potential/Potential.py b/galpy/potential/Potential.py index 9f4244bef..cec2560b4 100644 --- a/galpy/potential/Potential.py +++ b/galpy/potential/Potential.py @@ -4171,10 +4171,7 @@ def zvc_range(Pot, E, Lz, phi=0.0, t=0.0): # Check whether a solution exists RLz = rl(Pot, Lz, t=t, use_physical=False) Rstart = RLz - if ( - _evaluatePotentials(Pot, Rstart, 0.0, phi=phi, t=t) + Lz2over2 / Rstart**2.0 - > E - ): + if _evaluatePotentials(Pot, Rstart, 0.0, phi=phi, t=t) + Lz2over2 / Rstart**2.0 > E: return numpy.array([numpy.nan, numpy.nan]) # Find starting value for Rmin Rstartmin = 1e-8 @@ -4184,9 +4181,7 @@ def zvc_range(Pot, E, Lz, phi=0.0, t=0.0): ): Rstart /= 2.0 Rmin = optimize.brentq( - lambda R: _evaluatePotentials(Pot, R, 0, phi=phi, t=t) - + Lz2over2 / R**2.0 - - E, + lambda R: _evaluatePotentials(Pot, R, 0, phi=phi, t=t) + Lz2over2 / R**2.0 - E, Rstart, RLz, ) @@ -4199,9 +4194,7 @@ def zvc_range(Pot, E, Lz, phi=0.0, t=0.0): ): Rstart *= 2.0 Rmax = optimize.brentq( - lambda R: _evaluatePotentials(Pot, R, 0, phi=phi, t=t) - + Lz2over2 / R**2.0 - - E, + lambda R: _evaluatePotentials(Pot, R, 0, phi=phi, t=t) + Lz2over2 / R**2.0 - E, RLz, Rstart, ) diff --git a/galpy/potential/PseudoIsothermalPotential.py b/galpy/potential/PseudoIsothermalPotential.py index fe8e07313..c6180cda3 100644 --- a/galpy/potential/PseudoIsothermalPotential.py +++ b/galpy/potential/PseudoIsothermalPotential.py @@ -78,9 +78,7 @@ def _zforce(self, R, z, phi=0.0, t=0.0): return -(1.0 / r - self._a / r2 * numpy.arctan(r / self._a)) / self._a * z / r def _dens(self, R, z, phi=0.0, t=0.0): - return ( - 1.0 / (1.0 + (R**2.0 + z**2.0) / self._a2) / 4.0 / numpy.pi / self._a3 - ) + return 1.0 / (1.0 + (R**2.0 + z**2.0) / self._a2) / 4.0 / numpy.pi / self._a3 def _R2deriv(self, R, z, phi=0.0, t=0.0): r2 = R**2.0 + z**2.0 diff --git a/galpy/potential/RingPotential.py b/galpy/potential/RingPotential.py index fae7fce99..b16d1bafd 100644 --- a/galpy/potential/RingPotential.py +++ b/galpy/potential/RingPotential.py @@ -58,9 +58,7 @@ def __init__(self, amp=1.0, a=0.75, normalize=False, ro=None, vo=None): def _evaluate(self, R, z, phi=0.0, t=0.0): # Stable as r -> infty m = 4.0 * self.a / ((numpy.sqrt(R) + self.a / numpy.sqrt(R)) ** 2 + z**2 / R) - return ( - -4.0 * self.a / numpy.sqrt((R + self.a) ** 2 + z**2) * special.ellipk(m) - ) + return -4.0 * self.a / numpy.sqrt((R + self.a) ** 2 + z**2) * special.ellipk(m) def _Rforce(self, R, z, phi=0.0, t=0.0): m = 4.0 * R * self.a / ((R + self.a) ** 2 + z**2) diff --git a/galpy/potential/SCFPotential.py b/galpy/potential/SCFPotential.py index 697568891..d7726fb3f 100644 --- a/galpy/potential/SCFPotential.py +++ b/galpy/potential/SCFPotential.py @@ -481,9 +481,7 @@ def _mass(self, R, z=None, t=0.0): raise AttributeError # Hack to fall back to general # when integrating over spherical volume, all non-zero l,m vanish N = len(self._Acos) - return R**2.0 * numpy.sum( - self._Acos[:, 0, 0] * self._dphiTilde(R, N, 1)[:, 0] - ) + return R**2.0 * numpy.sum(self._Acos[:, 0, 0] * self._dphiTilde(R, N, 1)[:, 0]) def _evaluate(self, R, z, phi=0.0, t=0.0): if not self.isNonAxi and phi is None: @@ -1130,9 +1128,9 @@ def integrand(xi, costheta, phi): Nln = 0.5 * gammaln(l - m + 1) - 0.5 * gammaln(l + m + 1) - (2 * l) * numpy.log(2) NN = numpy.e ** (Nln) - NN[ - numpy.where(NN == numpy.inf) - ] = 0 ## To account for the fact that m can't be bigger than l + NN[numpy.where(NN == numpy.inf)] = ( + 0 ## To account for the fact that m can't be bigger than l + ) constants = NN * (2 * l + 1.0) ** 0.5 diff --git a/galpy/potential/SpiralArmsPotential.py b/galpy/potential/SpiralArmsPotential.py index 236f1c4d4..85efb8c4e 100644 --- a/galpy/potential/SpiralArmsPotential.py +++ b/galpy/potential/SpiralArmsPotential.py @@ -465,8 +465,7 @@ def _R2deriv(self, R, z, phi=0, t=0): + ( self._ns * ( - sin_ng - * (d2g_dR2 / Ks - dg_dR / Ks**2 * dKs_dR) + sin_ng * (d2g_dR2 / Ks - dg_dR / Ks**2 * dKs_dR) + dg_dR**2 / Ks * cos_ng * self._ns ) + z @@ -498,10 +497,7 @@ def _R2deriv(self, R, z, phi=0, t=0): / Ks * ztanhzKB * (dKs_dR / Bs - dBs_dR / Bs**2 * Ks) - - ( - d2Bs_dR2 / Ks - - dBs_dR * dKs_dR / Ks**2 - ) + - (d2Bs_dR2 / Ks - dBs_dR * dKs_dR / Ks**2) * log_sechzKB ) + dBs_dR @@ -514,15 +510,8 @@ def _R2deriv(self, R, z, phi=0, t=0): + ( ( cos_ng - * ( - d2Ks_dR2 / Ks**2 - - 2 * dKs_dR**2 / Ks**3 - ) - - dKs_dR - / Ks**2 - * sin_ng - * self._ns - * dg_dR + * (d2Ks_dR2 / Ks**2 - 2 * dKs_dR**2 / Ks**3) + - dKs_dR / Ks**2 * sin_ng * self._ns * dg_dR ) + ( cos_ng diff --git a/galpy/potential/SteadyLogSpiralPotential.py b/galpy/potential/SteadyLogSpiralPotential.py index 6f98c7459..2174e4fdf 100644 --- a/galpy/potential/SteadyLogSpiralPotential.py +++ b/galpy/potential/SteadyLogSpiralPotential.py @@ -102,10 +102,7 @@ def _evaluate(self, R, phi=0.0, t=0.0): deltat = t - self._tform xi = 2.0 * deltat / (self._tsteady - self._tform) - 1.0 smooth = ( - 3.0 / 16.0 * xi**5.0 - - 5.0 / 8 * xi**3.0 - + 15.0 / 16.0 * xi - + 0.5 + 3.0 / 16.0 * xi**5.0 - 5.0 / 8 * xi**3.0 + 15.0 / 16.0 * xi + 0.5 ) else: # spiral is fully on smooth = 1.0 @@ -129,10 +126,7 @@ def _Rforce(self, R, phi=0.0, t=0.0): deltat = t - self._tform xi = 2.0 * deltat / (self._tsteady - self._tform) - 1.0 smooth = ( - 3.0 / 16.0 * xi**5.0 - - 5.0 / 8 * xi**3.0 - + 15.0 / 16.0 * xi - + 0.5 + 3.0 / 16.0 * xi**5.0 - 5.0 / 8 * xi**3.0 + 15.0 / 16.0 * xi + 0.5 ) else: # spiral is fully on smooth = 1.0 @@ -156,10 +150,7 @@ def _phitorque(self, R, phi=0.0, t=0.0): deltat = t - self._tform xi = 2.0 * deltat / (self._tsteady - self._tform) - 1.0 smooth = ( - 3.0 / 16.0 * xi**5.0 - - 5.0 / 8 * xi**3.0 - + 15.0 / 16.0 * xi - + 0.5 + 3.0 / 16.0 * xi**5.0 - 5.0 / 8 * xi**3.0 + 15.0 / 16.0 * xi + 0.5 ) else: # spiral is fully on smooth = 1.0 diff --git a/galpy/potential/TwoPowerSphericalPotential.py b/galpy/potential/TwoPowerSphericalPotential.py index b0032b494..8d69f3d09 100644 --- a/galpy/potential/TwoPowerSphericalPotential.py +++ b/galpy/potential/TwoPowerSphericalPotential.py @@ -905,9 +905,7 @@ def _rforce_jax(self, r): raise ImportError( "Making use of _rforce_jax function requires the google/jax library" ) - return self._amp * ( - 1.0 / r / (self.a + r) - jnp.log(1.0 + r / self.a) / r**2.0 - ) + return self._amp * (1.0 / r / (self.a + r) - jnp.log(1.0 + r / self.a) / r**2.0) def _R2deriv(self, R, z, phi=0.0, t=0.0): Rz = R**2.0 + z**2.0 diff --git a/galpy/util/conversion.py b/galpy/util/conversion.py index c322d0a1f..ae51fa844 100644 --- a/galpy/util/conversion.py +++ b/galpy/util/conversion.py @@ -629,9 +629,7 @@ def parse_time(x, ro=None, vo=None): def parse_mass(x, ro=None, vo=None): try: return ( - x.to(units.pc * units.km**2 / units.s**2).value - / mass_in_msol(vo, ro) - / _G + x.to(units.pc * units.km**2 / units.s**2).value / mass_in_msol(vo, ro) / _G if _APY_LOADED and isinstance(x, units.Quantity) else x ) diff --git a/galpy/util/coords.py b/galpy/util/coords.py index 9854d5ae6..6c0690c1a 100644 --- a/galpy/util/coords.py +++ b/galpy/util/coords.py @@ -1023,9 +1023,11 @@ def XYZ_to_galcenrect(X, Y, Z, Xsun=1.0, Zsun=0.0, _extra_rot=True): zero = numpy.zeros_like(costheta) one = numpy.ones_like(costheta) return numpy.einsum( - "ijk,jk->ik" - if isinstance(costheta, numpy.ndarray) and costheta.ndim > 0 - else "ij,jk->ik", + ( + "ijk,jk->ik" + if isinstance(costheta, numpy.ndarray) and costheta.ndim > 0 + else "ij,jk->ik" + ), numpy.array( [[costheta, zero, -sintheta], [zero, one, zero], [sintheta, zero, costheta]] ), @@ -1072,9 +1074,11 @@ def galcenrect_to_XYZ(X, Y, Z, Xsun=1.0, Zsun=0.0, _extra_rot=True): one = numpy.ones_like(costheta) out = ( numpy.einsum( - "ijk,jk->ik" - if isinstance(costheta, numpy.ndarray) and costheta.ndim > 0 - else "ij,jk->ik", + ( + "ijk,jk->ik" + if isinstance(costheta, numpy.ndarray) and costheta.ndim > 0 + else "ij,jk->ik" + ), numpy.array( [ [-costheta, zero, -sintheta], @@ -1311,9 +1315,11 @@ def vxvyvz_to_galcenrect( one = numpy.ones_like(costheta) return ( numpy.einsum( - "ijk,jk->ik" - if isinstance(costheta, numpy.ndarray) and costheta.ndim > 0 - else "ij,jk->ik", + ( + "ijk,jk->ik" + if isinstance(costheta, numpy.ndarray) and costheta.ndim > 0 + else "ij,jk->ik" + ), numpy.array( [ [costheta, zero, -sintheta], @@ -1428,9 +1434,11 @@ def galcenrect_to_vxvyvz( zero = numpy.zeros_like(costheta) one = numpy.ones_like(costheta) out = numpy.einsum( - "ijk,jk->ik" - if isinstance(costheta, numpy.ndarray) and costheta.ndim > 0 - else "ij,jk->ik", + ( + "ijk,jk->ik" + if isinstance(costheta, numpy.ndarray) and costheta.ndim > 0 + else "ij,jk->ik" + ), numpy.array( [ [-costheta, zero, -sintheta], diff --git a/tests/conftest.py b/tests/conftest.py index 19c3f12b5..adcb5d9fc 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -103,18 +103,18 @@ def pytest_generate_tests(metafunc): jactol["mockFlatDehnenBarPotential"] = -8.0 # these are more difficult jactol["mockFlatDehnenSmoothBarPotential"] = -8.0 # these are more difficult jactol["mockMovingObjectLongIntPotential"] = -8.0 # these are more difficult - jactol[ - "mockSlowFlatEllipticalDiskPotential" - ] = -6.0 # these are more difficult (and also not quite conserved) - jactol[ - "mockSlowFlatSteadyLogSpiralPotential" - ] = -8.0 # these are more difficult (and also not quite conserved) - jactol[ - "mockSlowFlatDehnenSmoothBarPotential" - ] = -8.0 # these are more difficult (and also not quite conserved) - jactol[ - "mockSlowFlatDecayingDehnenSmoothBarPotential" - ] = -8.0 # these are more difficult (and also not quite conserved) + jactol["mockSlowFlatEllipticalDiskPotential"] = ( + -6.0 + ) # these are more difficult (and also not quite conserved) + jactol["mockSlowFlatSteadyLogSpiralPotential"] = ( + -8.0 + ) # these are more difficult (and also not quite conserved) + jactol["mockSlowFlatDehnenSmoothBarPotential"] = ( + -8.0 + ) # these are more difficult (and also not quite conserved) + jactol["mockSlowFlatDecayingDehnenSmoothBarPotential"] = ( + -8.0 + ) # these are more difficult (and also not quite conserved) # Now generate all inputs and run tests tols = [tol[p] if p in tol else tol["default"] for p in pots] jactols = [jactol[p] if p in jactol else tol["default"] for p in pots] diff --git a/tests/test_actionAngle.py b/tests/test_actionAngle.py index f10c9512a..057d6dbc9 100644 --- a/tests/test_actionAngle.py +++ b/tests/test_actionAngle.py @@ -189,9 +189,7 @@ def test_actionAngleVertical_conserved_freqs(): (os - numpy.tile(numpy.mean(os), (len(times), 1)).T) / numpy.mean(os) ) ) - assert maxdo < 10.0**-4.0, "Frequency conservation fails at %g%%" % ( - 100.0 * maxdo - ) + assert maxdo < 10.0**-4.0, "Frequency conservation fails at %g%%" % (100.0 * maxdo) return None @@ -519,8 +517,7 @@ def test_actionAngleIsochrone_basic_freqs(): 100.0 * numpy.fabs((jos[4] - ip.omegac(1.0)) / ip.omegac(1.0)) ) assert ( - numpy.fabs((jos[5] - ip.verticalfreq(1.0)) / ip.verticalfreq(1.0)) - < 10.0**-12.0 + numpy.fabs((jos[5] - ip.verticalfreq(1.0)) / ip.verticalfreq(1.0)) < 10.0**-12.0 ), "Circular orbit in the isochrone potential does not have Oz=nu at %g%%" % ( 100.0 * numpy.fabs((jos[5] - ip.verticalfreq(1.0)) / ip.verticalfreq(1.0)) ) @@ -536,8 +533,7 @@ def test_actionAngleIsochrone_basic_freqs(): % (100.0 * numpy.fabs((jos[4] - ip.omegac(1.0)) / ip.omegac(1.0))) ) assert ( - numpy.fabs((jos[5] - ip.verticalfreq(1.0)) / ip.verticalfreq(1.0)) - < 10.0**-2.0 + numpy.fabs((jos[5] - ip.verticalfreq(1.0)) / ip.verticalfreq(1.0)) < 10.0**-2.0 ), ( "Close-to-circular orbit in the isochrone potential does not have Oz=nu at %g%%" % (100.0 * numpy.fabs((jos[5] - ip.verticalfreq(1.0)) / ip.verticalfreq(1.0))) @@ -852,8 +848,7 @@ def test_actionAngleSpherical_basic_freqs(): % (100.0 * numpy.fabs((jos[4] - lp.omegac(1.0)) / lp.omegac(1.0))) ) assert ( - numpy.fabs((jos[5] - lp.verticalfreq(1.0)) / lp.verticalfreq(1.0)) - < 10.0**-12.0 + numpy.fabs((jos[5] - lp.verticalfreq(1.0)) / lp.verticalfreq(1.0)) < 10.0**-12.0 ), ( "Circular orbit in the spherical LogarithmicHaloPotential does not have Oz=nu at %g%%" % (100.0 * numpy.fabs((jos[5] - lp.verticalfreq(1.0)) / lp.verticalfreq(1.0))) @@ -870,8 +865,7 @@ def test_actionAngleSpherical_basic_freqs(): % (100.0 * numpy.fabs((jos[4] - lp.omegac(1.0)) / lp.omegac(1.0))) ) assert ( - numpy.fabs((jos[5] - lp.verticalfreq(1.0)) / lp.verticalfreq(1.0)) - < 10.0**-1.9 + numpy.fabs((jos[5] - lp.verticalfreq(1.0)) / lp.verticalfreq(1.0)) < 10.0**-1.9 ), ( "Close-to-circular orbit in the spherical LogarithmicHaloPotential does not have Oz=nu at %g%%" % (100.0 * numpy.fabs((jos[5] - lp.verticalfreq(1.0)) / lp.verticalfreq(1.0))) @@ -898,8 +892,7 @@ def test_actionAngleSpherical_basic_freqsAngles(): % (100.0 * numpy.fabs((jos[4] - lp.omegac(1.0)) / lp.omegac(1.0))) ) assert ( - numpy.fabs((jos[5] - lp.verticalfreq(1.0)) / lp.verticalfreq(1.0)) - < 10.0**-1.9 + numpy.fabs((jos[5] - lp.verticalfreq(1.0)) / lp.verticalfreq(1.0)) < 10.0**-1.9 ), ( "Close-to-circular orbit in the spherical LogarithmicHaloPotential does not have Oz=nu at %g%%" % (100.0 * numpy.fabs((jos[5] - lp.verticalfreq(1.0)) / lp.verticalfreq(1.0))) @@ -1335,14 +1328,12 @@ def test_actionAngleSpherical_smallr(): o = Orbit([0.000000001, 0.0, ip.vcirc(0.000000001), 0.0, 0.0, 0.0]) # Code should have rperi = 0 assert ( - numpy.fabs(o.rperi(analytic=True, pot=ip, type="spherical") - 0.0) - < 10.0**-10.0 + numpy.fabs(o.rperi(analytic=True, pot=ip, type="spherical") - 0.0) < 10.0**-10.0 ), "rperi is not 0 for very small r" # Orbit just outside rperi, very small r o = Orbit([0.000000001, 0.0001, ip.vcirc(0.000000001), 0.0, 0.0, 0.0]) assert ( - numpy.fabs(o.rperi(analytic=True, pot=ip, type="spherical") - 0.0) - < 10.0**-10.0 + numpy.fabs(o.rperi(analytic=True, pot=ip, type="spherical") - 0.0) < 10.0**-10.0 ), "rperi is not 0 for very small r" return None @@ -6400,15 +6391,9 @@ def check_actionAngle_conserved_actions( maxdj = numpy.amax( numpy.fabs(js - numpy.tile(numpy.mean(js, axis=1), (len(times), 1)).T), axis=1 ) / numpy.mean(js, axis=1) - assert maxdj[0] < 10.0**toljr, "Jr conservation fails at %g%%" % ( - 100.0 * maxdj[0] - ) - assert maxdj[1] < 10.0**toljp, "Lz conservation fails at %g%%" % ( - 100.0 * maxdj[1] - ) - assert maxdj[2] < 10.0**toljz, "Jz conservation fails at %g%%" % ( - 100.0 * maxdj[2] - ) + assert maxdj[0] < 10.0**toljr, "Jr conservation fails at %g%%" % (100.0 * maxdj[0]) + assert maxdj[1] < 10.0**toljp, "Lz conservation fails at %g%%" % (100.0 * maxdj[1]) + assert maxdj[2] < 10.0**toljz, "Jz conservation fails at %g%%" % (100.0 * maxdj[2]) return None diff --git a/tests/test_amuse.py b/tests/test_amuse.py index 208edd141..f3010af42 100644 --- a/tests/test_amuse.py +++ b/tests/test_amuse.py @@ -62,9 +62,7 @@ def test_amuse_potential_with_physical(): pot1 = potential.TwoPowerSphericalPotential(amp=amp, a=a, ro=ro, vo=vo) grho1 = pot1.dens(5 / ro, 2 / ro) grho1 = ( - grho1.to_value(apy_u.solMass / apy_u.pc**3) - if hasattr(grho1, "unit") - else grho1 + grho1.to_value(apy_u.solMass / apy_u.pc**3) if hasattr(grho1, "unit") else grho1 ) amuse_pot1 = to_amuse(pot1) arho1 = amuse_pot1.mass_density(x, y, z) @@ -74,9 +72,7 @@ def test_amuse_potential_with_physical(): pot2 = potential.TwoPowerSphericalPotential(amp=amp_u, a=a_u, ro=ro_u, vo=vo_u) grho2 = pot2.dens(5 * apy_u.kpc, 2 * apy_u.kpc) grho2 = ( - grho2.to_value(apy_u.solMass / apy_u.pc**3) - if hasattr(grho2, "unit") - else grho2 + grho2.to_value(apy_u.solMass / apy_u.pc**3) if hasattr(grho2, "unit") else grho2 ) amuse_pot2 = to_amuse(pot2) arho2 = amuse_pot2.mass_density(x, y, z) diff --git a/tests/test_coords.py b/tests/test_coords.py index b2693e249..e22d67a79 100644 --- a/tests/test_coords.py +++ b/tests/test_coords.py @@ -1859,8 +1859,7 @@ def test_pmrapmdec_to_pmllpmbb(): ) assert ( numpy.fabs( - numpy.sqrt(pmll**2.0 + pmbb**2.0) - - numpy.sqrt(pmra**2.0 + pmdec**2.0) + numpy.sqrt(pmll**2.0 + pmbb**2.0) - numpy.sqrt(pmra**2.0 + pmdec**2.0) ) < 10.0**-10.0 ), "pmrapmdec_to_pmllpmbb conversion did not work as expected" @@ -1876,8 +1875,7 @@ def test_pmrapmdec_to_pmllpmbb(): pmbb = pmllpmbb[:, 1] assert numpy.all( numpy.fabs( - numpy.sqrt(pmll**2.0 + pmbb**2.0) - - numpy.sqrt(pmra**2.0 + pmdec**2.0) + numpy.sqrt(pmll**2.0 + pmbb**2.0) - numpy.sqrt(pmra**2.0 + pmdec**2.0) ) < 10.0**-10.0 ), "pmrapmdec_to_pmllpmbb conversion did not work as expected close to the NGP" @@ -1893,8 +1891,7 @@ def test_pmrapmdec_to_pmllpmbb(): pmbb = pmllpmbb[:, 1] assert numpy.all( numpy.fabs( - numpy.sqrt(pmll**2.0 + pmbb**2.0) - - numpy.sqrt(pmra**2.0 + pmdec**2.0) + numpy.sqrt(pmll**2.0 + pmbb**2.0) - numpy.sqrt(pmra**2.0 + pmdec**2.0) ) < 10.0**-10.0 ), "pmrapmdec_to_pmllpmbb conversion did not work as expected for the NGP" @@ -1906,8 +1903,7 @@ def test_pmrapmdec_to_pmllpmbb(): ) assert ( numpy.fabs( - numpy.sqrt(pmll**2.0 + pmbb**2.0) - - numpy.sqrt(pmra**2.0 + pmdec**2.0) + numpy.sqrt(pmll**2.0 + pmbb**2.0) - numpy.sqrt(pmra**2.0 + pmdec**2.0) ) < 10.0**-10.0 ), "pmrapmdec_to_pmllpmbb conversion did not work as expected for the NCP" @@ -1923,8 +1919,7 @@ def test_pmllpmbb_to_pmrapmdec(): ) assert ( numpy.fabs( - numpy.sqrt(pmll**2.0 + pmbb**2.0) - - numpy.sqrt(pmra**2.0 + pmdec**2.0) + numpy.sqrt(pmll**2.0 + pmbb**2.0) - numpy.sqrt(pmra**2.0 + pmdec**2.0) ) < 10.0**-10.0 ), "pmllpmbb_to_pmrapmdec conversion did not work as expected for a random l,b" @@ -1939,8 +1934,7 @@ def test_pmllpmbb_to_pmrapmdec(): pmdec = pmrapmdec[:, 1] assert numpy.all( numpy.fabs( - numpy.sqrt(pmll**2.0 + pmbb**2.0) - - numpy.sqrt(pmra**2.0 + pmdec**2.0) + numpy.sqrt(pmll**2.0 + pmbb**2.0) - numpy.sqrt(pmra**2.0 + pmdec**2.0) ) < 10.0**-10.0 ), "pmllpmbb_to_pmrapmdec conversion did not work as expected close to the NGP" @@ -1955,8 +1949,7 @@ def test_pmllpmbb_to_pmrapmdec(): pmdec = pmrapmdec[:, 1] assert numpy.all( numpy.fabs( - numpy.sqrt(pmll**2.0 + pmbb**2.0) - - numpy.sqrt(pmra**2.0 + pmdec**2.0) + numpy.sqrt(pmll**2.0 + pmbb**2.0) - numpy.sqrt(pmra**2.0 + pmdec**2.0) ) < 10.0**-10.0 ), "pmllpmbb_to_pmrapmdec conversion did not work as expected at the NGP" @@ -1969,8 +1962,7 @@ def test_pmllpmbb_to_pmrapmdec(): ) assert ( numpy.fabs( - numpy.sqrt(pmll**2.0 + pmbb**2.0) - - numpy.sqrt(pmra**2.0 + pmdec**2.0) + numpy.sqrt(pmll**2.0 + pmbb**2.0) - numpy.sqrt(pmra**2.0 + pmdec**2.0) ) < 10.0**-10.0 ), "pmllpmbb_to_pmrapmdec conversion did not work as expected at the NCP" @@ -2012,8 +2004,7 @@ def test_cov_pmradec_to_pmllbb(): < 10.0**-10.0 ), "cov_pmradec_to_pmllbb conversion did not work as expected" assert ( - numpy.fabs(numpy.trace(cov_pmllpmbb) - numpy.trace(cov_pmrapmdec)) - < 10.0**-10.0 + numpy.fabs(numpy.trace(cov_pmllpmbb) - numpy.trace(cov_pmrapmdec)) < 10.0**-10.0 ), "cov_pmradec_to_pmllbb conversion did not work as expected" # This is a random position, check that the conversion makes sense, arrays (using einsum) ra, dec = 132.25, -23.4 @@ -2773,29 +2764,19 @@ def test_cyl_to_spher_vec(): assert ( numpy.fabs(vtheta - 0) < 10.0**-8 ), "cyl_to_spher_vec does not work as expected" - assert ( - numpy.fabs(vT - 1.3) < 10.0**-8 - ), "cyl_to_spher_vec does not work as expected" + assert numpy.fabs(vT - 1.3) < 10.0**-8, "cyl_to_spher_vec does not work as expected" vr, vT, vtheta = coords.cyl_to_spher_vec(-1.2, -0.7, -0.8, 1.0, 0.0) - assert ( - numpy.fabs(vr + 1.2) < 10.0**-8 - ), "cyl_to_spher_vec does not work as expected" + assert numpy.fabs(vr + 1.2) < 10.0**-8, "cyl_to_spher_vec does not work as expected" assert ( numpy.fabs(vtheta - 0.8) < 10.0**-8 ), "cyl_to_spher_vec does not work as expected" - assert ( - numpy.fabs(vT + 0.7) < 10.0**-8 - ), "cyl_to_spher_vec does not work as expected" + assert numpy.fabs(vT + 0.7) < 10.0**-8, "cyl_to_spher_vec does not work as expected" vr, vT, vtheta = coords.cyl_to_spher_vec(-1.2, -0.7, -0.8, 0.0, 1.0) - assert ( - numpy.fabs(vr + 0.8) < 10.0**-8 - ), "cyl_to_spher_vec does not work as expected" + assert numpy.fabs(vr + 0.8) < 10.0**-8, "cyl_to_spher_vec does not work as expected" assert ( numpy.fabs(vtheta + 1.2) < 10.0**-8 ), "cyl_to_spher_vec does not work as expected" - assert ( - numpy.fabs(vT + 0.7) < 10.0**-8 - ), "cyl_to_spher_vec does not work as expected" + assert numpy.fabs(vT + 0.7) < 10.0**-8, "cyl_to_spher_vec does not work as expected" return None @@ -2805,32 +2786,16 @@ def test_spher_to_cyl_vec(): assert ( numpy.fabs(vR - 0.7 * 2**0.5) < 10.0**-8 ), "spher_to_cyl_vec does not work as expected" - assert ( - numpy.fabs(vT - 1.4) < 10.0**-8 - ), "spher_to_cyl_vec does not work as expected" - assert ( - numpy.fabs(vz - 0.0) < 10.0**-8 - ), "spher_to_cyl_vec does not work as expected" + assert numpy.fabs(vT - 1.4) < 10.0**-8, "spher_to_cyl_vec does not work as expected" + assert numpy.fabs(vz - 0.0) < 10.0**-8, "spher_to_cyl_vec does not work as expected" vR, vT, vz = coords.spher_to_cyl_vec(0.5, -1.3, 0.7, 0.0) - assert ( - numpy.fabs(vR - 0.7) < 10.0**-8 - ), "spher_to_cyl_vec does not work as expected" - assert ( - numpy.fabs(vT + 1.3) < 10.0**-8 - ), "spher_to_cyl_vec does not work as expected" - assert ( - numpy.fabs(vz - 0.5) < 10.0**-8 - ), "spher_to_cyl_vec does not work as expected" + assert numpy.fabs(vR - 0.7) < 10.0**-8, "spher_to_cyl_vec does not work as expected" + assert numpy.fabs(vT + 1.3) < 10.0**-8, "spher_to_cyl_vec does not work as expected" + assert numpy.fabs(vz - 0.5) < 10.0**-8, "spher_to_cyl_vec does not work as expected" vR, vT, vz = coords.spher_to_cyl_vec(0.5, -1.3, 0.7, numpy.pi / 2.0) - assert ( - numpy.fabs(vR - 0.5) < 10.0**-8 - ), "spher_to_cyl_vec does not work as expected" - assert ( - numpy.fabs(vT + 1.3) < 10.0**-8 - ), "spher_to_cyl_vec does not work as expected" - assert ( - numpy.fabs(vz + 0.7) < 10.0**-8 - ), "spher_to_cyl_vec does not work as expected" + assert numpy.fabs(vR - 0.5) < 10.0**-8, "spher_to_cyl_vec does not work as expected" + assert numpy.fabs(vT + 1.3) < 10.0**-8, "spher_to_cyl_vec does not work as expected" + assert numpy.fabs(vz + 0.7) < 10.0**-8, "spher_to_cyl_vec does not work as expected" return None diff --git a/tests/test_diskdf.py b/tests/test_diskdf.py index c50a1b9aa..aaa8d77f8 100644 --- a/tests/test_diskdf.py +++ b/tests/test_diskdf.py @@ -38,8 +38,7 @@ def test_expSurfaceSigmaProfile_surfacemassDerivative(): < 10.0**-8.0 ), "expSurfaceSigmaProfile's surfacemassDerivative does not work as expected" assert ( - numpy.fabs(essp.surfacemassDerivative(1.5, log=True) + 1.0 / 0.25) - < 10.0**-8.0 + numpy.fabs(essp.surfacemassDerivative(1.5, log=True) + 1.0 / 0.25) < 10.0**-8.0 ), "expSurfaceSigmaProfile's surfacemassDerivative does not work as expected" return None @@ -744,16 +743,13 @@ def test_dehnendf_cold_powerrise_srst(): profileParams=(0.3333333333333333, 1.0, 0.01), beta=beta, correct=False ) assert ( - numpy.fabs(df.sigmaR2(1.0) / df.sigmaT2(1.0) - 2.0 / (1.0 + beta)) - < 10.0**-2.0 + numpy.fabs(df.sigmaR2(1.0) / df.sigmaT2(1.0) - 2.0 / (1.0 + beta)) < 10.0**-2.0 ), "sigma_R^2 / sigma_T^2 of cool dehnendf in a flat rotation curve is not close to expected at R=1" assert ( - numpy.fabs(df.sigmaR2(0.5) / df.sigmaT2(0.5) - 2.0 / (1.0 + beta)) - < 10.0**-2.0 + numpy.fabs(df.sigmaR2(0.5) / df.sigmaT2(0.5) - 2.0 / (1.0 + beta)) < 10.0**-2.0 ), "sigma_R^2 / sigma_T^2 of cool dehnendf in a flat rotation curve is not close to expected at R=1" assert ( - numpy.fabs(df.sigmaR2(2.0) / df.sigmaT2(2.0) - 2.0 / (1.0 + beta)) - < 10.0**-2.0 + numpy.fabs(df.sigmaR2(2.0) / df.sigmaT2(2.0) - 2.0 / (1.0 + beta)) < 10.0**-2.0 ), "sigma_R^2 / sigma_T^2 of cool dehnendf in a flat rotation curve is not close to expected at R=1" return None @@ -765,16 +761,13 @@ def test_dehnendf_cold_powerfall_srst(): profileParams=(0.3333333333333333, 1.0, 0.01), beta=beta, correct=False ) assert ( - numpy.fabs(df.sigmaR2(1.0) / df.sigmaT2(1.0) - 2.0 / (1.0 + beta)) - < 10.0**-2.0 + numpy.fabs(df.sigmaR2(1.0) / df.sigmaT2(1.0) - 2.0 / (1.0 + beta)) < 10.0**-2.0 ), "sigma_R^2 / sigma_T^2 of cool dehnendf in a flat rotation curve is not close to expected at R=1" assert ( - numpy.fabs(df.sigmaR2(0.5) / df.sigmaT2(0.5) - 2.0 / (1.0 + beta)) - < 10.0**-2.0 + numpy.fabs(df.sigmaR2(0.5) / df.sigmaT2(0.5) - 2.0 / (1.0 + beta)) < 10.0**-2.0 ), "sigma_R^2 / sigma_T^2 of cool dehnendf in a flat rotation curve is not close to expected at R=1" assert ( - numpy.fabs(df.sigmaR2(2.0) / df.sigmaT2(2.0) - 2.0 / (1.0 + beta)) - < 10.0**-2.0 + numpy.fabs(df.sigmaR2(2.0) / df.sigmaT2(2.0) - 2.0 / (1.0 + beta)) < 10.0**-2.0 ), "sigma_R^2 / sigma_T^2 of cool dehnendf in a flat rotation curve is not close to expected at R=1" return None @@ -1541,9 +1534,7 @@ def test_dehnendf_dlnfdRe_powerfall(): numpy.log(dfc(numpy.array([R, vR + dvR, vT]))) - numpy.log(dfc(numpy.array([R, vR, vT]))) ) / dvR - dE = ( - (vR + dvR) ** 2.0 / 2.0 + vT**2.0 / 2.0 + 1.0 / 2.0 / beta * R ** (2.0 * beta) - ) + dE = (vR + dvR) ** 2.0 / 2.0 + vT**2.0 / 2.0 + 1.0 / 2.0 / beta * R ** (2.0 * beta) dRE = (2.0 * dE / (1.0 + 1.0 / beta)) ** (1.0 / 2.0 / beta) dRedvR = (dRE - RE) / dvR # dvT @@ -1554,9 +1545,7 @@ def test_dehnendf_dlnfdRe_powerfall(): numpy.log(dfc(numpy.array([R, vR, vT + dvT]))) - numpy.log(dfc(numpy.array([R, vR, vT]))) ) / dvT - dE = ( - vR**2.0 / 2.0 + (vT + dvT) ** 2.0 / 2.0 + 1.0 / 2.0 / beta * R ** (2.0 * beta) - ) + dE = vR**2.0 / 2.0 + (vT + dvT) ** 2.0 / 2.0 + 1.0 / 2.0 / beta * R ** (2.0 * beta) dRE = (2.0 * dE / (1.0 + 1.0 / beta)) ** (1.0 / 2.0 / beta) dRedvT = (dRE - RE) / dvT # Calculate dR/dRe etc. from matrix inversion @@ -1597,9 +1586,7 @@ def test_dehnendf_dlnfdRe_powerrise(): numpy.log(dfc(numpy.array([R, vR + dvR, vT]))) - numpy.log(dfc(numpy.array([R, vR, vT]))) ) / dvR - dE = ( - (vR + dvR) ** 2.0 / 2.0 + vT**2.0 / 2.0 + 1.0 / 2.0 / beta * R ** (2.0 * beta) - ) + dE = (vR + dvR) ** 2.0 / 2.0 + vT**2.0 / 2.0 + 1.0 / 2.0 / beta * R ** (2.0 * beta) dRE = (2.0 * dE / (1.0 + 1.0 / beta)) ** (1.0 / 2.0 / beta) dRedvR = (dRE - RE) / dvR # dvT @@ -1610,9 +1597,7 @@ def test_dehnendf_dlnfdRe_powerrise(): numpy.log(dfc(numpy.array([R, vR, vT + dvT]))) - numpy.log(dfc(numpy.array([R, vR, vT]))) ) / dvT - dE = ( - vR**2.0 / 2.0 + (vT + dvT) ** 2.0 / 2.0 + 1.0 / 2.0 / beta * R ** (2.0 * beta) - ) + dE = vR**2.0 / 2.0 + (vT + dvT) ** 2.0 / 2.0 + 1.0 / 2.0 / beta * R ** (2.0 * beta) dRE = (2.0 * dE / (1.0 + 1.0 / beta)) ** (1.0 / 2.0 / beta) dRedvT = (dRE - RE) / dvT # Calculate dR/dRe etc. from matrix inversion @@ -1702,9 +1687,7 @@ def test_dehnendf_dlnfdl_powerfall(): numpy.log(dfc(numpy.array([R, vR + dvR, vT]))) - numpy.log(dfc(numpy.array([R, vR, vT]))) ) / dvR - dE = ( - (vR + dvR) ** 2.0 / 2.0 + vT**2.0 / 2.0 + 1.0 / 2.0 / beta * R ** (2.0 * beta) - ) + dE = (vR + dvR) ** 2.0 / 2.0 + vT**2.0 / 2.0 + 1.0 / 2.0 / beta * R ** (2.0 * beta) dRE = (2.0 * dE / (1.0 + 1.0 / beta)) ** (1.0 / 2.0 / beta) dRedvR = (dRE - RE) / dvR # dvT @@ -1715,9 +1698,7 @@ def test_dehnendf_dlnfdl_powerfall(): numpy.log(dfc(numpy.array([R, vR, vT + dvT]))) - numpy.log(dfc(numpy.array([R, vR, vT]))) ) / dvT - dE = ( - vR**2.0 / 2.0 + (vT + dvT) ** 2.0 / 2.0 + 1.0 / 2.0 / beta * R ** (2.0 * beta) - ) + dE = vR**2.0 / 2.0 + (vT + dvT) ** 2.0 / 2.0 + 1.0 / 2.0 / beta * R ** (2.0 * beta) dRE = (2.0 * dE / (1.0 + 1.0 / beta)) ** (1.0 / 2.0 / beta) dRedvT = (dRE - RE) / dvT # Calculate dR/dl etc. from matrix inversion @@ -1756,9 +1737,7 @@ def test_dehnendf_dlnfdl_powerrise(): numpy.log(dfc(numpy.array([R, vR + dvR, vT]))) - numpy.log(dfc(numpy.array([R, vR, vT]))) ) / dvR - dE = ( - (vR + dvR) ** 2.0 / 2.0 + vT**2.0 / 2.0 + 1.0 / 2.0 / beta * R ** (2.0 * beta) - ) + dE = (vR + dvR) ** 2.0 / 2.0 + vT**2.0 / 2.0 + 1.0 / 2.0 / beta * R ** (2.0 * beta) dRE = (2.0 * dE / (1.0 + 1.0 / beta)) ** (1.0 / 2.0 / beta) dRedvR = (dRE - RE) / dvR # dvT @@ -1769,9 +1748,7 @@ def test_dehnendf_dlnfdl_powerrise(): numpy.log(dfc(numpy.array([R, vR, vT + dvT]))) - numpy.log(dfc(numpy.array([R, vR, vT]))) ) / dvT - dE = ( - vR**2.0 / 2.0 + (vT + dvT) ** 2.0 / 2.0 + 1.0 / 2.0 / beta * R ** (2.0 * beta) - ) + dE = vR**2.0 / 2.0 + (vT + dvT) ** 2.0 / 2.0 + 1.0 / 2.0 / beta * R ** (2.0 * beta) dRE = (2.0 * dE / (1.0 + 1.0 / beta)) ** (1.0 / 2.0 / beta) dRedvT = (dRE - RE) / dvT # Calculate dR/dl etc. from matrix inversion @@ -2999,9 +2976,7 @@ def test_axipotential(): < 10.0**-8 ), "axipotential w/ beta=0.2 does not work as expected" assert ( - numpy.fabs( - axipotential(numpy.array([0.5]), beta=-0.2) + 1.0 / 0.4 * 0.5**-0.4 - ) + numpy.fabs(axipotential(numpy.array([0.5]), beta=-0.2) + 1.0 / 0.4 * 0.5**-0.4) < 10.0**-8 ), "axipotential w/ beta=0.2 does not work as expected" # special case of R=0 should go to _RMIN diff --git a/tests/test_galpypaper.py b/tests/test_galpypaper.py index 62fb57f15..43d0f4aa1 100644 --- a/tests/test_galpypaper.py +++ b/tests/test_galpypaper.py @@ -2,6 +2,7 @@ isort:skip_file """ + import os import numpy import pytest @@ -53,8 +54,7 @@ def test_units(): print(conversion.force_in_pcMyr2(220.0, 8.0)) # pc/Myr^2 assert ( - numpy.fabs(conversion.force_in_pcMyr2(220.0, 8.0) - 6.32793804994) - < 10.0**-4.0 + numpy.fabs(conversion.force_in_pcMyr2(220.0, 8.0) - 6.32793804994) < 10.0**-4.0 ), "unit conversion has changed" print(conversion.dens_in_msolpc3(220.0, 8.0)) # Msolar/pc^3 # Loosen tolerances including mass bc of 0.025% change in Msun in astropyv2 @@ -156,8 +156,7 @@ def test_potmethods(): ), "potmethods has changed" dp.lindbladR(1.75, m="corotation") # co-rotation resonance assert ( - numpy.fabs(dp.lindbladR(1.75, m="corotation") - 0.540985051273488) - < 10.0**-4.0 + numpy.fabs(dp.lindbladR(1.75, m="corotation") - 0.540985051273488) < 10.0**-4.0 ), "potmethods has changed" return None @@ -591,12 +590,10 @@ def test_diskdf(): # Calculate the velocity dispersions numpy.sqrt(dfc.sigmaR2(0.9)), numpy.sqrt(dfc.sigmaT2(0.9)) assert ( - numpy.fabs(numpy.sqrt(dfc.sigmaR2(0.9)) - 0.22103383792719539) - < 10.0**-4.0 + numpy.fabs(numpy.sqrt(dfc.sigmaR2(0.9)) - 0.22103383792719539) < 10.0**-4.0 ), "diskdf does not behave as expected" assert ( - numpy.fabs(numpy.sqrt(dfc.sigmaT2(0.9)) - 0.17613725303902811) - < 10.0**-4.0 + numpy.fabs(numpy.sqrt(dfc.sigmaT2(0.9)) - 0.17613725303902811) < 10.0**-4.0 ), "diskdf does not behave as expected" # Calculate the skew of the velocity distribution df.skewvR(0.9), df.skewvT(0.9) diff --git a/tests/test_jeans.py b/tests/test_jeans.py index c2bcf1957..ac4219a4c 100644 --- a/tests/test_jeans.py +++ b/tests/test_jeans.py @@ -126,9 +126,7 @@ def test_sigmar_wlog_linbeta(): numpy.fabs( numpy.array( [ - jeans.sigmar( - lp, r, beta=lambda x: -b * x, dens=lambda x: x**-gamma - ) + jeans.sigmar(lp, r, beta=lambda x: -b * x, dens=lambda x: x**-gamma) - numpy.sqrt( special.gamma(-gamma) * special.gammaincc(-gamma, 2 * b * r) @@ -145,9 +143,7 @@ def test_sigmar_wlog_linbeta(): numpy.fabs( numpy.array( [ - jeans.sigmar( - lp, r, beta=lambda x: -b * x, dens=lambda x: x**-gamma - ) + jeans.sigmar(lp, r, beta=lambda x: -b * x, dens=lambda x: x**-gamma) - numpy.sqrt( special.gamma(-gamma) * special.gammaincc(-gamma, 2 * b * r) diff --git a/tests/test_kuzminkutuzov.py b/tests/test_kuzminkutuzov.py index d81d00bac..dcde232c0 100644 --- a/tests/test_kuzminkutuzov.py +++ b/tests/test_kuzminkutuzov.py @@ -719,17 +719,13 @@ def test_lambdanu_to_Rz(): z_true = numpy.sqrt((l + g) * (n + g) / (g - a)) # test: rel_diff = numpy.fabs((R - R_true) / R_true) < 10.0**-8.0 - abs_diff = (numpy.fabs(R - R_true) < 10.0**-6.0) * ( - numpy.fabs(R_true) < 10.0**-6.0 - ) + abs_diff = (numpy.fabs(R - R_true) < 10.0**-6.0) * (numpy.fabs(R_true) < 10.0**-6.0) assert numpy.all( rel_diff + abs_diff ), "lambdanu_to_Rz conversion did not work as expected (R array)" rel_diff = numpy.fabs((z - z_true) / z_true) < 10.0**-8.0 - abs_diff = (numpy.fabs(z - z_true) < 10.0**-6.0) * ( - numpy.fabs(z_true) < 10.0**-6.0 - ) + abs_diff = (numpy.fabs(z - z_true) < 10.0**-6.0) * (numpy.fabs(z_true) < 10.0**-6.0) assert numpy.all( rel_diff + abs_diff ), "lambdanu_to_Rz conversion did not work as expected (z array)" diff --git a/tests/test_noninertial.py b/tests/test_noninertial.py index 1b8a6a17c..eeb579598 100644 --- a/tests/test_noninertial.py +++ b/tests/test_noninertial.py @@ -1204,11 +1204,7 @@ def test_linacc_constantacc_z(): from scipy import special intaz = ( - lambda t: 0.02 - * t**2.0 - / 2.0 - * (special.erf(t) + 2.0) - / (special.erf(t) + 2.0) + lambda t: 0.02 * t**2.0 / 2.0 * (special.erf(t) + 2.0) / (special.erf(t) + 2.0) ) framepot = potential.NonInertialFrameForce(a0=[0.0, 0.0, az]) diskframepot = ( diff --git a/tests/test_orbit.py b/tests/test_orbit.py index 32490fa1e..b3a3afff9 100644 --- a/tests/test_orbit.py +++ b/tests/test_orbit.py @@ -2017,9 +2017,7 @@ def test_analytic_ecc_rperi_rap(): "Analytically computed pericenter radius does not agree with numerical estimate for potential %s and integrator %s" % (p, integrator) ) - assert ( - o.rperi(ro=8.0) / 8.0 - trperi_analytic - ) ** 2.0 < 10.0**ttol, ( + assert (o.rperi(ro=8.0) / 8.0 - trperi_analytic) ** 2.0 < 10.0**ttol, ( "Pericenter in physical coordinates does not agree with physical-scale times pericenter in normalized coordinates for potential %s and integrator %s" % (p, integrator) ) @@ -2095,9 +2093,7 @@ def test_analytic_ecc_rperi_rap(): "Analytically computed pericenter radius does not agree with numerical estimate for potential %s and integrator %s" % (p, integrator) ) - assert ( - o.rperi(ro=8.0) / 8.0 - trperi_analytic - ) ** 2.0 < 10.0**ttol, ( + assert (o.rperi(ro=8.0) / 8.0 - trperi_analytic) ** 2.0 < 10.0**ttol, ( "Pericenter in physical coordinates does not agree with physical-scale times pericenter in normalized coordinates for potential %s and integrator %s" % (p, integrator) ) @@ -2173,9 +2169,7 @@ def test_analytic_ecc_rperi_rap(): "Analytically computed pericenter radius does not agree with numerical estimate for potential %s and integrator %s" % (p, integrator) ) - assert ( - o.rperi(ro=8.0) / 8.0 - trperi_analytic - ) ** 2.0 < 10.0**ttol, ( + assert (o.rperi(ro=8.0) / 8.0 - trperi_analytic) ** 2.0 < 10.0**ttol, ( "Pericenter in physical coordinates does not agree with physical-scale times pericenter in normalized coordinates for potential %s and integrator %s" % (p, integrator) ) @@ -3406,12 +3400,7 @@ def test_orbit_setup(): numpy.fabs(o.dist() - 0.0) < 10.0**-2.0 ), "Orbit dist setup does not agree with o.dist()" # because of tweak in the code to deal with at the Sun assert ( - o.U() ** 2.0 - + o.V() ** 2.0 - + o.W() ** 2.0 - - 10.0**2.0 - - 20.0**2.0 - - 30.0**2.0 + o.U() ** 2.0 + o.V() ** 2.0 + o.W() ** 2.0 - 10.0**2.0 - 20.0**2.0 - 30.0**2.0 ) < 10.0**-10.0, ( "Velocity wrt the Sun when looking at Orbit at the Sun does not agree" ) @@ -5145,8 +5134,7 @@ def test_physical_output_on(): ), "o.vz() output for Orbit setup with vo= does not work as expected when turned back on" # Test energies assert ( - numpy.fabs(o.E(pot=lp) - o_orig.E(pot=lp, use_physical=True)) - < 10.0**-10.0 + numpy.fabs(o.E(pot=lp) - o_orig.E(pot=lp, use_physical=True)) < 10.0**-10.0 ), "o.E() output for Orbit setup with vo= does not work as expected when turned back on" assert ( numpy.fabs(o.Jacobi(pot=lp) - o_orig.Jacobi(pot=lp, use_physical=True)) @@ -5930,8 +5918,7 @@ def test_orbit_obs_Orbit_issue322(): # The basic case, for a planar orbit o = Orbit([0.9, 0.1, 1.2, 0.0]) assert ( - numpy.fabs(o.helioX(obs=Orbit([1.0, 0.0, 0.0, 0.0]), ro=1.0) - 0.1) - < 10.0**-7.0 + numpy.fabs(o.helioX(obs=Orbit([1.0, 0.0, 0.0, 0.0]), ro=1.0) - 0.1) < 10.0**-7.0 ), "Relative position wrt the Sun from using obs= keyword does not work as expected" assert ( numpy.fabs(o.helioY(obs=Orbit([1.0, 0.0, 0.0, 0.0]), ro=1.0)) < 10.0**-7.0 @@ -7082,8 +7069,7 @@ def test_orbit_method_inputvo_quantity(): numpy.fabs(o.theta(vo=vo * units.km / units.s) - o.theta(vo=vo)) < 10.0**-8.0 ), "Orbit method theta does not return the correct value when input vo is Quantity" assert ( - numpy.fabs(o.vtheta(vo=vo * units.km / units.s) - o.vtheta(vo=vo)) - < 10.0**-8.0 + numpy.fabs(o.vtheta(vo=vo * units.km / units.s) - o.vtheta(vo=vo)) < 10.0**-8.0 ), "Orbit method vtheta does not return the correct value when input vo is Quantity" assert ( numpy.fabs(o.vr(vo=vo * units.km / units.s) - o.vr(vo=vo)) < 10.0**-8.0 @@ -7131,16 +7117,13 @@ def test_orbit_method_inputvo_quantity(): numpy.fabs(o.vbb(vo=vo * units.km / units.s) - o.vbb(vo=vo)) < 10.0**-8.0 ), "Orbit method vbb does not return the correct value when input vo is Quantity" assert ( - numpy.fabs(o.helioX(vo=vo * units.km / units.s) - o.helioX(vo=vo)) - < 10.0**-8.0 + numpy.fabs(o.helioX(vo=vo * units.km / units.s) - o.helioX(vo=vo)) < 10.0**-8.0 ), "Orbit method helioX does not return the correct value when input vo is Quantity" assert ( - numpy.fabs(o.helioY(vo=vo * units.km / units.s) - o.helioY(vo=vo)) - < 10.0**-8.0 + numpy.fabs(o.helioY(vo=vo * units.km / units.s) - o.helioY(vo=vo)) < 10.0**-8.0 ), "Orbit method helioY does not return the correct value when input vo is Quantity" assert ( - numpy.fabs(o.helioZ(vo=vo * units.km / units.s) - o.helioZ(vo=vo)) - < 10.0**-8.0 + numpy.fabs(o.helioZ(vo=vo * units.km / units.s) - o.helioZ(vo=vo)) < 10.0**-8.0 ), "Orbit method helioZ does not return the correct value when input vo is Quantity" assert ( numpy.fabs(o.U(vo=vo * units.km / units.s) - o.U(vo=vo)) < 10.0**-8.0 @@ -7941,9 +7924,7 @@ def test_orbinterp_reset_integrate(): assert ( numpy.fabs(o.rperi() - op.rperi()) < 10.0**-10.0 ), "Orbit rperi not reset correctly" - assert ( - numpy.fabs(o.rap() - op.rap()) < 10.0**-10.0 - ), "Orbit rap not reset correctly" + assert numpy.fabs(o.rap() - op.rap()) < 10.0**-10.0, "Orbit rap not reset correctly" assert numpy.fabs(o.e() - op.e()) < 10.0**-10.0, "Orbit e not reset correctly" return None @@ -7985,9 +7966,7 @@ def test_orbinterp_reset_integrateSOS(): assert ( numpy.fabs(o.rperi() - op.rperi()) < 10.0**-10.0 ), "Orbit rperi not reset correctly" - assert ( - numpy.fabs(o.rap() - op.rap()) < 10.0**-10.0 - ), "Orbit rap not reset correctly" + assert numpy.fabs(o.rap() - op.rap()) < 10.0**-10.0, "Orbit rap not reset correctly" assert numpy.fabs(o.e() - op.e()) < 10.0**-10.0, "Orbit e not reset correctly" return None @@ -8029,9 +8008,7 @@ def test_orbinterp_reset_bruteSOS(): assert ( numpy.fabs(o.rperi() - op.rperi()) < 10.0**-10.0 ), "Orbit rperi not reset correctly" - assert ( - numpy.fabs(o.rap() - op.rap()) < 10.0**-10.0 - ), "Orbit rap not reset correctly" + assert numpy.fabs(o.rap() - op.rap()) < 10.0**-10.0, "Orbit rap not reset correctly" assert numpy.fabs(o.e() - op.e()) < 10.0**-10.0, "Orbit e not reset correctly" return None @@ -8065,9 +8042,7 @@ def test_orbinterp_reset_integratedxdv(): assert ( numpy.fabs(o.rperi() - op.rperi()) < 10.0**-10.0 ), "Orbit rperi not reset correctly" - assert ( - numpy.fabs(o.rap() - op.rap()) < 10.0**-10.0 - ), "Orbit rap not reset correctly" + assert numpy.fabs(o.rap() - op.rap()) < 10.0**-10.0, "Orbit rap not reset correctly" assert numpy.fabs(o.e() - op.e()) < 10.0**-10.0, "Orbit e not reset correctly" return None diff --git a/tests/test_orbits.py b/tests/test_orbits.py index 89c08e6a4..1c009502d 100644 --- a/tests/test_orbits.py +++ b/tests/test_orbits.py @@ -5905,8 +5905,7 @@ def _check_energy_jacobi_angmom(os, list_os): ), "Evaluating Orbits L does not agree with Orbit" if os.dim() != 1: assert numpy.all( - numpy.fabs(os.Lz(times)[ii] / list_os[ii].Lz(times) - 1.0) - < 10.0**-10.0 + numpy.fabs(os.Lz(times)[ii] / list_os[ii].Lz(times) - 1.0) < 10.0**-10.0 ), "Evaluating Orbits Lz does not agree with Orbit" if os.phasedim() % 2 == 0 and os.dim() != 1: assert numpy.all( @@ -8330,8 +8329,7 @@ def test_physical_output_on(): ), "o.vz() output for Orbit setup with vo= does not work as expected when turned back on" # Test energies assert ( - numpy.fabs(o.E(pot=lp) - o_orig.E(pot=lp, use_physical=True)) - < 10.0**-10.0 + numpy.fabs(o.E(pot=lp) - o_orig.E(pot=lp, use_physical=True)) < 10.0**-10.0 ), "o.E() output for Orbit setup with vo= does not work as expected when turned back on" assert ( numpy.fabs(o.Jacobi(pot=lp) - o_orig.Jacobi(pot=lp, use_physical=True)) diff --git a/tests/test_potential.py b/tests/test_potential.py index d5fd932f9..ac09e8292 100644 --- a/tests/test_potential.py +++ b/tests/test_potential.py @@ -993,9 +993,9 @@ def test_poisson_surfdens_potential(): tol = {} tol["default"] = -8.0 tol["DoubleExponentialDiskPotential"] = -3.0 # these are more difficult - tol[ - "SphericalShellPotential" - ] = -0 # Direct integration fails to deal with delta function! + tol["SphericalShellPotential"] = ( + -0 + ) # Direct integration fails to deal with delta function! # tol['SpiralArmsPotential']= -3 #these are more difficult # tol['rotatingSpiralArmsPotential']= -3 # tol['specialSpiralArmsPotential']= -4 @@ -1228,9 +1228,7 @@ def test_evaluateAndDerivs_potential(): % p ) else: - assert ( - tevaldr2 - tr2deriv - ) ** 2.0 / tevaldr2**2.0 < 10.0**ttol, ( + assert (tevaldr2 - tr2deriv) ** 2.0 / tevaldr2**2.0 < 10.0**ttol, ( "Calculation of 2nd radial derivative through _evaluate and R2deriv inconsistent for the %s potential" % p ) @@ -1248,9 +1246,7 @@ def test_evaluateAndDerivs_potential(): % p ) else: - assert ( - tevaldphi + tphitorque - ) ** 2.0 / tevaldphi**2.0 < 10.0**ttol, ( + assert (tevaldphi + tphitorque) ** 2.0 / tevaldphi**2.0 < 10.0**ttol, ( "Calculation of azimuthal derivative through _evaluate and phitorque inconsistent for the %s potential" % p ) @@ -1627,8 +1623,7 @@ def test_potential_array_input(): ] ) assert numpy.all( - numpy.fabs(tp.phi2deriv(rs, zs, phi=phis, t=ts) - tpevals) - < 10.0**-10.0 + numpy.fabs(tp.phi2deriv(rs, zs, phi=phis, t=ts) - tpevals) < 10.0**-10.0 ), f"{p} phi2deriv evaluation does not work as expected for array inputs" # Rzderiv if hasattr(tp, "_Rzderiv"): @@ -1650,8 +1645,7 @@ def test_potential_array_input(): ] ) assert numpy.all( - numpy.fabs(tp.Rphideriv(rs, zs, phi=phis, t=ts) - tpevals) - < 10.0**-10.0 + numpy.fabs(tp.Rphideriv(rs, zs, phi=phis, t=ts) - tpevals) < 10.0**-10.0 ), f"{p} Rphideriv evaluation does not work as expected for array inputs" # phizderiv if hasattr(tp, "_phizderiv"): @@ -1662,8 +1656,7 @@ def test_potential_array_input(): ] ) assert numpy.all( - numpy.fabs(tp.phizderiv(rs, zs, phi=phis, t=ts) - tpevals) - < 10.0**-10.0 + numpy.fabs(tp.phizderiv(rs, zs, phi=phis, t=ts) - tpevals) < 10.0**-10.0 ), f"{p} phizderiv evaluation does not work as expected for array inputs" # dens tpevals = numpy.array( @@ -4059,9 +4052,7 @@ def test_McMillan17(): ), "Mass within 50 kpc in McMillan17 does not agree with what it is supposed to be" # Mass of the bulge is slightly off assert ( - numpy.fabs( - (McMillan17[2].mass(50.0 / 8.21, quantity=False)) / 10.0**9.0 - 9.23 - ) + numpy.fabs((McMillan17[2].mass(50.0 / 8.21, quantity=False)) / 10.0**9.0 - 9.23) < 4e-1 ), "Bulge mass in McMillan17 does not agree with what it is supposed to be" # Mass in stars, compute bulge+disk and subtract what's supposed to be gas @@ -4405,8 +4396,7 @@ def test_NFW_virialsetup_wrtmeanmatter(): ), "NFWPotential virial setup's concentration does not work" assert ( numpy.fabs( - mvir - - np.mvir(H=H, Om=Om, overdens=overdens, wrtcrit=wrtcrit) / 10.0**12.0 + mvir - np.mvir(H=H, Om=Om, overdens=overdens, wrtcrit=wrtcrit) / 10.0**12.0 ) < 10.0**-6.0 ), "NFWPotential virial setup's virial mass does not work" @@ -4433,8 +4423,7 @@ def test_NFW_virialsetup_wrtcrit(): ), "NFWPotential virial setup's concentration does not work" assert ( numpy.fabs( - mvir - - np.mvir(H=H, Om=Om, overdens=overdens, wrtcrit=wrtcrit) / 10.0**12.0 + mvir - np.mvir(H=H, Om=Om, overdens=overdens, wrtcrit=wrtcrit) / 10.0**12.0 ) < 10.0**-6.0 ), "NFWPotential virial setup's virial mass does not work" @@ -4815,12 +4804,8 @@ def test_nemoaccpars(): vo /= 1.0227121655399913 ap = np.nemo_accpars(vo, ro).split(",") assert numpy.fabs(float(ap[0]) - 0) < 10.0**-8.0, "NFW's NEMO accpars incorrect" - assert ( - numpy.fabs(float(ap[1]) - 0.25) < 10.0**-8.0 - ), "NFW's NEMO accpars incorrect" - assert ( - numpy.fabs(float(ap[2]) - 12.0) < 10.0**-8.0 - ), "NFW's NEMO accpars incorrect" + assert numpy.fabs(float(ap[1]) - 0.25) < 10.0**-8.0, "NFW's NEMO accpars incorrect" + assert numpy.fabs(float(ap[2]) - 12.0) < 10.0**-8.0, "NFW's NEMO accpars incorrect" # MN3ExponentialDiskPotential mn = potential.MN3ExponentialDiskPotential(normalize=1.0, hr=2.0, hz=0.5) vo, ro = 3.0, 4.0 @@ -4862,9 +4847,7 @@ def test_nemoaccpars(): vo, ro = 7.0, 9.0 vo /= 1.0227121655399913 ap = pp.nemo_accpars(vo, ro).split(",") - assert ( - numpy.fabs(float(ap[0]) - 0) < 10.0**-8.0 - ), "Plummer's NEMO accpars incorrect" + assert numpy.fabs(float(ap[0]) - 0) < 10.0**-8.0, "Plummer's NEMO accpars incorrect" assert ( numpy.fabs(float(ap[1]) - 1323.0) < 10.0**-5.0 ), "Plummer's NEMO accpars incorrect" @@ -6350,8 +6333,7 @@ def test_rtide(): ), "Calculation of rtide in point-mass potential fails" # Also test function interface assert ( - abs(1.0 - potential.rtide([lp], 1.0, 0.0, M=1.0) / 0.793700525984) - < 10.0**-12.0 + abs(1.0 - potential.rtide([lp], 1.0, 0.0, M=1.0) / 0.793700525984) < 10.0**-12.0 ), "Calculation of rtide in logarithmic potential fails" pmass = potential.PlummerPotential(b=0.0) assert ( @@ -6518,17 +6500,13 @@ def test_zvc_range(): Rmin, Rmax = pot.zvc_range(E, Lz) assert ( numpy.fabs( - potential.evaluatePotentials(pot, Rmin, 0.0) - + Lz**2.0 / 2.0 / Rmin**2.0 - - E + potential.evaluatePotentials(pot, Rmin, 0.0) + Lz**2.0 / 2.0 / Rmin**2.0 - E ) < 1e-8 ), "zvc_range does not return radius at which Phi_eff(R,0) = E" assert ( numpy.fabs( - potential.evaluatePotentials(pot, Rmax, 0.0) - + Lz**2.0 / 2.0 / Rmax**2.0 - - E + potential.evaluatePotentials(pot, Rmax, 0.0) + Lz**2.0 / 2.0 / Rmax**2.0 - E ) < 1e-8 ), "zvc_range does not return radius at which Phi_eff(R,0) = E" diff --git a/tests/test_qdf.py b/tests/test_qdf.py index 63733e2fd..2f8e76a34 100644 --- a/tests/test_qdf.py +++ b/tests/test_qdf.py @@ -1583,9 +1583,7 @@ def test_jmomentdensity_physical(): assert ( numpy.fabs( qdf.jmomentdensity(1.1, 0.1, 0, 0, 0, nmc=100000, ro=ro, vo=vo) - - qdf.jmomentdensity(1.1, 0.1, 0, 0, 0, nmc=100000) - / ro**3 - * (ro * vo) ** 0 + - qdf.jmomentdensity(1.1, 0.1, 0, 0, 0, nmc=100000) / ro**3 * (ro * vo) ** 0 ) < 10.0**-4.0 ), "quasiisothermaldf method jmomentdensity does not return correct Quantity" @@ -1594,9 +1592,7 @@ def test_jmomentdensity_physical(): qdf.jmomentdensity( 1.1, 0.1, 1, 0, 0, nmc=100000, ro=ro, vo=vo, use_physical=True ) - - qdf.jmomentdensity(1.1, 0.1, 1, 0, 0, nmc=100000) - / ro**3 - * (ro * vo) ** 1 + - qdf.jmomentdensity(1.1, 0.1, 1, 0, 0, nmc=100000) / ro**3 * (ro * vo) ** 1 ) < 10.0**-2.0 ), "quasiisothermaldf method jmomentdensity does not return correct Quantity" diff --git a/tests/test_quantity.py b/tests/test_quantity.py index de6a9fb1e..a179a502e 100644 --- a/tests/test_quantity.py +++ b/tests/test_quantity.py @@ -420,9 +420,7 @@ def test_orbit_setup_lb_oddunits(): < 10.0**-8.0 ), "Orbit initialization with pmll as Quantity does not work as expected" assert ( - numpy.fabs( - (o.pmbb(quantity=False) - 2.0 / 10.0**3.0) / o.pmbb(quantity=False) - ) + numpy.fabs((o.pmbb(quantity=False) - 2.0 / 10.0**3.0) / o.pmbb(quantity=False)) < 10.0**-4.0 ), "Orbit initialization with pmbb as Quantity does not work as expected" assert ( @@ -1154,25 +1152,19 @@ def test_orbit_method_returnunit(): "Orbit method zmax does not return Quantity with the right units" ) try: - o.jr(pot=MWPotential2014, type="staeckel", delta=0.5).to( - units.km**2 / units.s - ) + o.jr(pot=MWPotential2014, type="staeckel", delta=0.5).to(units.km**2 / units.s) except units.UnitConversionError: raise AssertionError( "Orbit method jr does not return Quantity with the right units" ) try: - o.jp(pot=MWPotential2014, type="staeckel", delta=0.5).to( - units.km**2 / units.s - ) + o.jp(pot=MWPotential2014, type="staeckel", delta=0.5).to(units.km**2 / units.s) except units.UnitConversionError: raise AssertionError( "Orbit method jp does not return Quantity with the right units" ) try: - o.jz(pot=MWPotential2014, type="staeckel", delta=0.5).to( - units.km**2 / units.s - ) + o.jz(pot=MWPotential2014, type="staeckel", delta=0.5).to(units.km**2 / units.s) except units.UnitConversionError: raise AssertionError( "Orbit method jz does not return Quantity with the right units" @@ -1695,8 +1687,7 @@ def test_orbit_method_value(): numpy.fabs(o.bb().to(units.deg).value - oc.bb(quantity=False)) < 10.0**-8.0 ), "Orbit method bb does not return the correct value as Quantity" assert ( - numpy.fabs(o.dist().to(units.kpc).value - oc.dist(quantity=False)) - < 10.0**-8.0 + numpy.fabs(o.dist().to(units.kpc).value - oc.dist(quantity=False)) < 10.0**-8.0 ), "Orbit method dist does not return the correct value as Quantity" assert ( numpy.fabs(o.pmra().to(units.mas / units.yr).value - oc.pmra(quantity=False)) @@ -2819,25 +2810,19 @@ def test_orbits_method_returnunit(): "Orbit method zmax does not return Quantity with the right units" ) try: - o.jr(pot=MWPotential2014, type="staeckel", delta=0.5).to( - units.km**2 / units.s - ) + o.jr(pot=MWPotential2014, type="staeckel", delta=0.5).to(units.km**2 / units.s) except units.UnitConversionError: raise AssertionError( "Orbit method jr does not return Quantity with the right units" ) try: - o.jp(pot=MWPotential2014, type="staeckel", delta=0.5).to( - units.km**2 / units.s - ) + o.jp(pot=MWPotential2014, type="staeckel", delta=0.5).to(units.km**2 / units.s) except units.UnitConversionError: raise AssertionError( "Orbit method jp does not return Quantity with the right units" ) try: - o.jz(pot=MWPotential2014, type="staeckel", delta=0.5).to( - units.km**2 / units.s - ) + o.jz(pot=MWPotential2014, type="staeckel", delta=0.5).to(units.km**2 / units.s) except units.UnitConversionError: raise AssertionError( "Orbit method jz does not return Quantity with the right units" @@ -3370,8 +3355,7 @@ def test_orbits_method_value(): numpy.fabs(o.bb().to(units.deg).value - oc.bb(quantity=False)) < 10.0**-8.0 ), "Orbit method bb does not return the correct value as Quantity" assert numpy.all( - numpy.fabs(o.dist().to(units.kpc).value - oc.dist(quantity=False)) - < 10.0**-8.0 + numpy.fabs(o.dist().to(units.kpc).value - oc.dist(quantity=False)) < 10.0**-8.0 ), "Orbit method dist does not return the correct value as Quantity" assert numpy.all( numpy.fabs(o.pmra().to(units.mas / units.yr).value - oc.pmra(quantity=False)) @@ -3775,16 +3759,13 @@ def test_integrate_orbits_timeAsQuantity(): numpy.fabs(numpy.array(o.z(ts)) - numpy.array(oc.z(ts_nounits))) < 10.0**-8.0 ), "Orbit integrated with times specified as Quantity does not agree with Orbit integrated with time specified as array" assert numpy.all( - numpy.fabs(numpy.array(o.vx(ts)) - numpy.array(oc.vx(ts_nounits))) - < 10.0**-8.0 + numpy.fabs(numpy.array(o.vx(ts)) - numpy.array(oc.vx(ts_nounits))) < 10.0**-8.0 ), "Orbit integrated with times specified as Quantity does not agree with Orbit integrated with time specified as array" assert numpy.all( - numpy.fabs(numpy.array(o.vy(ts)) - numpy.array(oc.vy(ts_nounits))) - < 10.0**-8.0 + numpy.fabs(numpy.array(o.vy(ts)) - numpy.array(oc.vy(ts_nounits))) < 10.0**-8.0 ), "Orbit integrated with times specified as Quantity does not agree with Orbit integrated with time specified as array" assert numpy.all( - numpy.fabs(numpy.array(o.vz(ts)) - numpy.array(oc.vz(ts_nounits))) - < 10.0**-8.0 + numpy.fabs(numpy.array(o.vz(ts)) - numpy.array(oc.vz(ts_nounits))) < 10.0**-8.0 ), "Orbit integrated with times specified as Quantity does not agree with Orbit integrated with time specified as array" return None @@ -3872,16 +3853,13 @@ def test_orbits_integrate_timeAsQuantity_Myr(): numpy.fabs(numpy.array(o.z(ts)) - numpy.array(oc.z(ts_nounits))) < 10.0**-8.0 ), "Orbit integrated with times specified as Quantity does not agree with Orbit integrated with time specified as array" assert numpy.all( - numpy.fabs(numpy.array(o.vx(ts)) - numpy.array(oc.vx(ts_nounits))) - < 10.0**-8.0 + numpy.fabs(numpy.array(o.vx(ts)) - numpy.array(oc.vx(ts_nounits))) < 10.0**-8.0 ), "Orbit integrated with times specified as Quantity does not agree with Orbit integrated with time specified as array" assert numpy.all( - numpy.fabs(numpy.array(o.vy(ts)) - numpy.array(oc.vy(ts_nounits))) - < 10.0**-8.0 + numpy.fabs(numpy.array(o.vy(ts)) - numpy.array(oc.vy(ts_nounits))) < 10.0**-8.0 ), "Orbit integrated with times specified as Quantity does not agree with Orbit integrated with time specified as array" assert numpy.all( - numpy.fabs(numpy.array(o.vz(ts)) - numpy.array(oc.vz(ts_nounits))) - < 10.0**-8.0 + numpy.fabs(numpy.array(o.vz(ts)) - numpy.array(oc.vz(ts_nounits))) < 10.0**-8.0 ), "Orbit integrated with times specified as Quantity does not agree with Orbit integrated with time specified as array" return None @@ -3972,16 +3950,13 @@ def test_orbits_integrate_dtimeAsQuantity(): numpy.fabs(numpy.array(o.z(ts)) - numpy.array(oc.z(ts_nounits))) < 10.0**-8.0 ), "Orbit integrated with times specified as Quantity does not agree with Orbit integrated with time specified as array" assert numpy.all( - numpy.fabs(numpy.array(o.vx(ts)) - numpy.array(oc.vx(ts_nounits))) - < 10.0**-8.0 + numpy.fabs(numpy.array(o.vx(ts)) - numpy.array(oc.vx(ts_nounits))) < 10.0**-8.0 ), "Orbit integrated with times specified as Quantity does not agree with Orbit integrated with time specified as array" assert numpy.all( - numpy.fabs(numpy.array(o.vy(ts)) - numpy.array(oc.vy(ts_nounits))) - < 10.0**-8.0 + numpy.fabs(numpy.array(o.vy(ts)) - numpy.array(oc.vy(ts_nounits))) < 10.0**-8.0 ), "Orbit integrated with times specified as Quantity does not agree with Orbit integrated with time specified as array" assert numpy.all( - numpy.fabs(numpy.array(o.vz(ts)) - numpy.array(oc.vz(ts_nounits))) - < 10.0**-8.0 + numpy.fabs(numpy.array(o.vz(ts)) - numpy.array(oc.vz(ts_nounits))) < 10.0**-8.0 ), "Orbit integrated with times specified as Quantity does not agree with Orbit integrated with time specified as array" return None @@ -4643,8 +4618,7 @@ def test_potential_method_value(): potu = PlummerPotential(normalize=True) assert ( numpy.fabs( - pot(1.1, 0.1).to(units.km**2 / units.s**2).value - - potu(1.1, 0.1) * vo**2.0 + pot(1.1, 0.1).to(units.km**2 / units.s**2).value - potu(1.1, 0.1) * vo**2.0 ) < 10.0**-8.0 ), "Potential method __call__ does not return the correct value as Quantity" @@ -4699,27 +4673,21 @@ def test_potential_method_value(): ), "Potential method mass does not return the correct value as Quantity" assert ( numpy.fabs( - pot.R2deriv(1.1, 0.1) - .to(units.km**2 / units.s**2.0 / units.kpc**2) - .value + pot.R2deriv(1.1, 0.1).to(units.km**2 / units.s**2.0 / units.kpc**2).value - potu.R2deriv(1.1, 0.1) * vo**2.0 / ro**2.0 ) < 10.0**-8.0 ), "Potential method R2deriv does not return the correct value as Quantity" assert ( numpy.fabs( - pot.z2deriv(1.1, 0.1) - .to(units.km**2 / units.s**2.0 / units.kpc**2) - .value + pot.z2deriv(1.1, 0.1).to(units.km**2 / units.s**2.0 / units.kpc**2).value - potu.z2deriv(1.1, 0.1) * vo**2.0 / ro**2.0 ) < 10.0**-8.0 ), "Potential method z2deriv does not return the correct value as Quantity" assert ( numpy.fabs( - pot.Rzderiv(1.1, 0.1) - .to(units.km**2 / units.s**2.0 / units.kpc**2) - .value + pot.Rzderiv(1.1, 0.1).to(units.km**2 / units.s**2.0 / units.kpc**2).value - potu.Rzderiv(1.1, 0.1) * vo**2.0 / ro**2.0 ) < 10.0**-8.0 @@ -4796,8 +4764,7 @@ def test_potential_method_value(): numpy.fabs(pot.rl(1.1).to(units.kpc).value - potu.rl(1.1) * ro) < 10.0**-8.0 ), "Potential method rl does not return the correct value as Quantity" assert ( - numpy.fabs(pot.rE(-1.14).to(units.kpc).value - potu.rE(-1.14) * ro) - < 10.0**-8.0 + numpy.fabs(pot.rE(-1.14).to(units.kpc).value - potu.rE(-1.14) * ro) < 10.0**-8.0 ), "Potential method rE does not return the correct value as Quantity" assert ( numpy.fabs( @@ -4819,9 +4786,7 @@ def test_potential_method_value(): ), "Potential method rtide does not return the correct value as Quantity" assert numpy.all( numpy.fabs( - pot.ttensor(1.0, 0.0) - .to(units.km**2 / units.s**2.0 / units.kpc**2) - .value + pot.ttensor(1.0, 0.0).to(units.km**2 / units.s**2.0 / units.kpc**2).value - potu.ttensor(1.0, 0.0) * vo**2.0 / ro**2.0 ) < 10.0**-8.0 @@ -4869,9 +4834,7 @@ def test_planarPotential_method_value(): pot = PlummerPotential(normalize=True, ro=ro, vo=vo).toPlanar() potu = PlummerPotential(normalize=True).toPlanar() assert ( - numpy.fabs( - pot(1.1).to(units.km**2 / units.s**2).value - potu(1.1) * vo**2.0 - ) + numpy.fabs(pot(1.1).to(units.km**2 / units.s**2).value - potu(1.1) * vo**2.0) < 10.0**-8.0 ), "Potential method __call__ does not return the correct value as Quantity" assert ( @@ -4942,9 +4905,7 @@ def test_linearPotential_method_value(): pot = PlummerPotential(normalize=True, ro=ro, vo=vo).toVertical(1.1) potu = PlummerPotential(normalize=True).toVertical(1.1) assert ( - numpy.fabs( - pot(1.1).to(units.km**2 / units.s**2).value - potu(1.1) * vo**2.0 - ) + numpy.fabs(pot(1.1).to(units.km**2 / units.s**2).value - potu(1.1) * vo**2.0) < 10.0**-8.0 ), "Potential method __call__ does not return the correct value as Quantity" assert ( @@ -5962,8 +5923,7 @@ def test_potential_method_inputAsQuantity(): < 10.0**-8.0 ), "Potential method verticalfreq does not return the correct value when input is Quantity" assert ( - numpy.fabs(pot.vesc(1.1 * ro, use_physical=False) - potu.vesc(1.1)) - < 10.0**-8.0 + numpy.fabs(pot.vesc(1.1 * ro, use_physical=False) - potu.vesc(1.1)) < 10.0**-8.0 ), "Potential method vesc does not return the correct value when input is Quantity" assert ( numpy.fabs( @@ -6003,12 +5963,8 @@ def test_potential_method_inputAsQuantity(): ), "Potential method vterm does not return the correct value when input is Quantity" assert ( numpy.fabs( - pot.rtide( - 1.1 * ro, 0.1 * ro, M=10.0**9.0 * units.Msun, use_physical=False - ) - - potu.rtide( - 1.1, 0.1, M=10.0**9.0 / conversion.mass_in_msol(vo, ro.value) - ) + pot.rtide(1.1 * ro, 0.1 * ro, M=10.0**9.0 * units.Msun, use_physical=False) + - potu.rtide(1.1, 0.1, M=10.0**9.0 / conversion.mass_in_msol(vo, ro.value)) ) < 10.0**-8.0 ), "Potential method rtide does not return the correct value when input is Quantity" @@ -6049,8 +6005,7 @@ def test_potential_method_inputAsQuantity(): < 10.0**-8.0 ), "Potential method zvc does not return the correct value when input is Quantity" assert ( - numpy.fabs(pot.tdyn(1.1 * ro, use_physical=False) - potu.tdyn(1.1)) - < 10.0**-8.0 + numpy.fabs(pot.tdyn(1.1 * ro, use_physical=False) - potu.tdyn(1.1)) < 10.0**-8.0 ), "Potential method tdyn does not return the correct value when input is Quantity" return None @@ -6304,9 +6259,7 @@ def test_potential_method_inputAsQuantity_Rzaskwargs(): pot.rtide( R=1.1 * ro, z=0.1 * ro, M=10.0**9.0 * units.Msun, use_physical=False ) - - potu.rtide( - 1.1, 0.1, M=10.0**9.0 / conversion.mass_in_msol(vo, ro.value) - ) + - potu.rtide(1.1, 0.1, M=10.0**9.0 / conversion.mass_in_msol(vo, ro.value)) ) < 10.0**-8.0 ), "Potential method rtide does not return the correct value when input is Quantity" @@ -6380,8 +6333,7 @@ def test_planarPotential_method_inputAsQuantity(): < 10.0**-8.0 ), "Potential method epifreq does not return the correct value as Quantity" assert ( - numpy.fabs(pot.vesc(1.1 * ro, use_physical=False) - potu.vesc(1.1)) - < 10.0**-8.0 + numpy.fabs(pot.vesc(1.1 * ro, use_physical=False) - potu.vesc(1.1)) < 10.0**-8.0 ), "Potential method vesc does not return the correct value as Quantity" assert ( numpy.fabs( @@ -8716,14 +8668,10 @@ def test_potential_ampunits_wrongunits(): ) # NFWPotential with pytest.raises(units.UnitConversionError) as excinfo: - potential.NFWPotential( - amp=20.0 * units.km**2 / units.s**2, a=2.0, ro=ro, vo=vo - ) + potential.NFWPotential(amp=20.0 * units.km**2 / units.s**2, a=2.0, ro=ro, vo=vo) # SCFPotential, default = Hernquist with pytest.raises(units.UnitConversionError) as excinfo: - potential.SCFPotential( - amp=20.0 * units.Msun / units.pc**3, a=2.0, ro=ro, vo=vo - ) + potential.SCFPotential(amp=20.0 * units.Msun / units.pc**3, a=2.0, ro=ro, vo=vo) # TwoPowerTriaxialPotential with pytest.raises(units.UnitConversionError) as excinfo: potential.TwoPowerTriaxialPotential( @@ -9063,8 +9011,7 @@ def test_potential_paramunits(): vo=vo, ) assert ( - numpy.fabs(numpy.arccos(pot._rot[0, 0]) - 30.0 / 180.0 * numpy.pi) - < 10.0**-8.0 + numpy.fabs(numpy.arccos(pot._rot[0, 0]) - 30.0 / 180.0 * numpy.pi) < 10.0**-8.0 ), "TriaxialNFWPotential w/ parameters w/ units does not behave as expected" # FlattenedPowerPotential pot = potential.FlattenedPowerPotential( @@ -13273,9 +13220,7 @@ def test_df_method_turnphysicalon(): assert isinstance( df(Orbit([1.1, 0.1, 1.1])), units.Quantity ), "df method does not return Quantity when turn_physical_on has been called" - assert ( - numpy.fabs(df._ro - 7.0) < 10.0**-10.0 - ), "df method does not work as expected" + assert numpy.fabs(df._ro - 7.0) < 10.0**-10.0, "df method does not work as expected" assert ( numpy.fabs(df._vo - 230.0) < 10.0**-10.0 ), "df method turn_physical_on does not work as expected" @@ -13283,9 +13228,7 @@ def test_df_method_turnphysicalon(): assert isinstance( df(Orbit([1.1, 0.1, 1.1])), units.Quantity ), "df method does not return Quantity when turn_physical_on has been called" - assert ( - numpy.fabs(df._ro - 9.0) < 10.0**-10.0 - ), "df method does not work as expected" + assert numpy.fabs(df._ro - 9.0) < 10.0**-10.0, "df method does not work as expected" assert ( numpy.fabs(df._vo - 230.0) < 10.0**-10.0 ), "df method turn_physical_on does not work as expected" @@ -13293,9 +13236,7 @@ def test_df_method_turnphysicalon(): assert isinstance( df(Orbit([1.1, 0.1, 1.1])), units.Quantity ), "df method does not return Quantity when turn_physical_on has been called" - assert ( - numpy.fabs(df._ro - 9.0) < 10.0**-10.0 - ), "df method does not work as expected" + assert numpy.fabs(df._ro - 9.0) < 10.0**-10.0, "df method does not work as expected" assert ( numpy.fabs(df._vo - 210.0) < 10.0**-10.0 ), "df method turn_physical_on does not work as expected" @@ -14412,8 +14353,7 @@ def test_evolveddiskdf_method_value(): edfwarm.sigmaT2(1.2, grid=True, returnGrid=False, gridpoints=3) .to((units.km / units.s) ** 2) .value - - edfwarmnou.sigmaT2(1.2, grid=True, returnGrid=False, gridpoints=3) - * vo**2 + - edfwarmnou.sigmaT2(1.2, grid=True, returnGrid=False, gridpoints=3) * vo**2 ) < 10.0**-8.0 ), "evolveddiskdf method sigmaT2 does not return correct Quantity when it should" @@ -14422,8 +14362,7 @@ def test_evolveddiskdf_method_value(): edfwarm.sigmaR2(1.2, grid=True, returnGrid=False, gridpoints=3) .to((units.km / units.s) ** 2) .value - - edfwarmnou.sigmaR2(1.2, grid=True, returnGrid=False, gridpoints=3) - * vo**2 + - edfwarmnou.sigmaR2(1.2, grid=True, returnGrid=False, gridpoints=3) * vo**2 ) < 10.0**-8.0 ), "evolveddiskdf method sigmaR2 does not return correct Quantity when it should" @@ -14432,8 +14371,7 @@ def test_evolveddiskdf_method_value(): edfwarm.sigmaRT(1.2, grid=True, returnGrid=False, gridpoints=3) .to((units.km / units.s) ** 2) .value - - edfwarmnou.sigmaRT(1.2, grid=True, returnGrid=False, gridpoints=3) - * vo**2 + - edfwarmnou.sigmaRT(1.2, grid=True, returnGrid=False, gridpoints=3) * vo**2 ) < 10.0**-8.0 ), "evolveddiskdf method sigmaRT does not return correct Quantity when it should" @@ -14597,8 +14535,7 @@ def test_evolveddiskdf_method_inputAsQuantity(): ) .to((units.km / units.s) ** 2) .value - - edfwarmnou.sigmaT2(1.2, grid=True, returnGrid=False, gridpoints=3) - * vo**2 + - edfwarmnou.sigmaT2(1.2, grid=True, returnGrid=False, gridpoints=3) * vo**2 ) < 10.0**-8.0 ), "evolveddiskdf method sigmaT2 does not return correct Quantity when it should" @@ -14609,8 +14546,7 @@ def test_evolveddiskdf_method_inputAsQuantity(): ) .to((units.km / units.s) ** 2) .value - - edfwarmnou.sigmaR2(1.2, grid=True, returnGrid=False, gridpoints=3) - * vo**2 + - edfwarmnou.sigmaR2(1.2, grid=True, returnGrid=False, gridpoints=3) * vo**2 ) < 10.0**-8.0 ), "evolveddiskdf method sigmaR2 does not return correct Quantity when it should" @@ -14621,8 +14557,7 @@ def test_evolveddiskdf_method_inputAsQuantity(): ) .to((units.km / units.s) ** 2) .value - - edfwarmnou.sigmaRT(1.2, grid=True, returnGrid=False, gridpoints=3) - * vo**2 + - edfwarmnou.sigmaRT(1.2, grid=True, returnGrid=False, gridpoints=3) * vo**2 ) < 10.0**-8.0 ), "evolveddiskdf method sigmaRT does not return correct Quantity when it should" @@ -15111,9 +15046,7 @@ def test_quasiisothermaldf_method_returnunit(): "quasiisothermaldf method pvRvz does not return Quantity with the right units" ) try: - qdf.pvTvz(1.1, 0.2, 1, 1.1, 0.1).to( - 1 / (units.km / units.s) ** 2 / units.pc**3 - ) + qdf.pvTvz(1.1, 0.2, 1, 1.1, 0.1).to(1 / (units.km / units.s) ** 2 / units.pc**3) except units.UnitConversionError: raise AssertionError( "quasiisothermaldf method pvTvz does not return Quantity with the right units" @@ -16155,17 +16088,13 @@ def test_sphericaldf_method_returnunit(): "sphericaldf method vmomentdensity does not return Quantity with the right units" ) try: - dfh.vmomentdensity(1.1, 0, 2).to( - 1 / units.kpc**3 * units.km**2 / units.s**2 - ) + dfh.vmomentdensity(1.1, 0, 2).to(1 / units.kpc**3 * units.km**2 / units.s**2) except units.UnitConversionError: raise AssertionError( "sphericaldf method vmomentdensity does not return Quantity with the right units" ) try: - dfa.vmomentdensity(1.1, 0, 2).to( - 1 / units.kpc**3 * units.km**2 / units.s**2 - ) + dfa.vmomentdensity(1.1, 0, 2).to(1 / units.kpc**3 * units.km**2 / units.s**2) except units.UnitConversionError: raise AssertionError( "sphericaldf method vmomentdensity does not return Quantity with the right units" @@ -16206,9 +16135,7 @@ def test_sphericaldf_method_value(): ), "sphericaldf method __call__ does not return correct Quantity" assert ( numpy.fabs( - dfh((o.E(pot=pot),)) - .to(1 / units.kpc**3 / (units.km / units.s) ** 3) - .value + dfh((o.E(pot=pot),)).to(1 / units.kpc**3 / (units.km / units.s) ** 3).value - dfh_nou((o.E(pot=pot),)) / ro**3 / vo**3 ) < 10.0**-8.0 @@ -16320,9 +16247,7 @@ def test_sphericaldf_method_inputAsQuantity(): o = Orbit([1.1, 0.1, 1.1, 0.1, 0.03, 0.4], ro=ro, vo=vo) assert ( numpy.fabs( - dfh((o.E(pot=pot),)) - .to(1 / units.kpc**3 / (units.km / units.s) ** 3) - .value + dfh((o.E(pot=pot),)).to(1 / units.kpc**3 / (units.km / units.s) ** 3).value - dfh_nou((o.E(pot=pot, use_physical=False),)) / ro**3 / vo**3 ) < 10.0**-8.0 diff --git a/tests/test_streamdf.py b/tests/test_streamdf.py index 73d622055..a3cde9073 100644 --- a/tests/test_streamdf.py +++ b/tests/test_streamdf.py @@ -1105,48 +1105,42 @@ def test_bovy14_gaussApprox_onemissing(bovy14_setup): XvX[0] = None meanp, varp = sdf_bovy14.gaussApprox(XvX, interp=False) assert ( - numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackXY[trackp, 0]) - < 10.0**tol + numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackXY[trackp, 0]) < 10.0**tol ), "gaussApprox along track does not work for X" # Y XvX = list(sdf_bovy14._interpolatedObsTrackXY[trackp, :].flatten()) XvX[1] = None meanp, varp = sdf_bovy14.gaussApprox(XvX, interp=False) assert ( - numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackXY[trackp, 1]) - < 10.0**tol + numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackXY[trackp, 1]) < 10.0**tol ), "gaussApprox along track does not work for Y" # Z XvX = list(sdf_bovy14._interpolatedObsTrackXY[trackp, :].flatten()) XvX[2] = None meanp, varp = sdf_bovy14.gaussApprox(XvX, interp=False) assert ( - numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackXY[trackp, 2]) - < 10.0**tol + numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackXY[trackp, 2]) < 10.0**tol ), "gaussApprox along track does not work for Z" # vX XvX = list(sdf_bovy14._interpolatedObsTrackXY[trackp, :].flatten()) XvX[3] = None meanp, varp = sdf_bovy14.gaussApprox(XvX, interp=False) assert ( - numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackXY[trackp, 3]) - < 10.0**tol + numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackXY[trackp, 3]) < 10.0**tol ), "gaussApprox along track does not work for vX" # vY XvX = list(sdf_bovy14._interpolatedObsTrackXY[trackp, :].flatten()) XvX[4] = None meanp, varp = sdf_bovy14.gaussApprox(XvX, interp=False) assert ( - numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackXY[trackp, 4]) - < 10.0**tol + numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackXY[trackp, 4]) < 10.0**tol ), "gaussApprox along track does not work for vY" # vZ XvX = list(sdf_bovy14._interpolatedObsTrackXY[trackp, :].flatten()) XvX[5] = None meanp, varp = sdf_bovy14.gaussApprox(XvX, interp=False) assert ( - numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackXY[trackp, 5]) - < 10.0**tol + numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackXY[trackp, 5]) < 10.0**tol ), "gaussApprox along track does not work for vZ" return None @@ -1165,16 +1159,13 @@ def test_bovy14_gaussApprox_threemissing(bovy14_setup): XvX[4] = None meanp, varp = sdf_bovy14.gaussApprox(XvX, interp=False) assert ( - numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackXY[trackp, 0]) - < 10.0**tol + numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackXY[trackp, 0]) < 10.0**tol ), "gaussApprox along track does not work for X" assert ( - numpy.fabs(meanp[1] - sdf_bovy14._interpolatedObsTrackXY[trackp, 3]) - < 10.0**tol + numpy.fabs(meanp[1] - sdf_bovy14._interpolatedObsTrackXY[trackp, 3]) < 10.0**tol ), "gaussApprox along track does not work for vX" assert ( - numpy.fabs(meanp[2] - sdf_bovy14._interpolatedObsTrackXY[trackp, 4]) - < 10.0**tol + numpy.fabs(meanp[2] - sdf_bovy14._interpolatedObsTrackXY[trackp, 4]) < 10.0**tol ), "gaussApprox along track does not work for vY" # Y,Z,vZ XvX = list(sdf_bovy14._interpolatedObsTrackXY[trackp, :].flatten()) @@ -1183,16 +1174,13 @@ def test_bovy14_gaussApprox_threemissing(bovy14_setup): XvX[5] = None meanp, varp = sdf_bovy14.gaussApprox(XvX, interp=False) assert ( - numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackXY[trackp, 1]) - < 10.0**tol + numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackXY[trackp, 1]) < 10.0**tol ), "gaussApprox along track does not work for Y" assert ( - numpy.fabs(meanp[1] - sdf_bovy14._interpolatedObsTrackXY[trackp, 2]) - < 10.0**tol + numpy.fabs(meanp[1] - sdf_bovy14._interpolatedObsTrackXY[trackp, 2]) < 10.0**tol ), "gaussApprox along track does not work for Z" assert ( - numpy.fabs(meanp[2] - sdf_bovy14._interpolatedObsTrackXY[trackp, 5]) - < 10.0**tol + numpy.fabs(meanp[2] - sdf_bovy14._interpolatedObsTrackXY[trackp, 5]) < 10.0**tol ), "gaussApprox along track does not work for vZ" return None @@ -1213,24 +1201,19 @@ def test_bovy14_gaussApprox_fivemissing(bovy14_setup): XvX[5] = None meanp, varp = sdf_bovy14.gaussApprox(XvX, interp=False, cindx=1) assert ( - numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackXY[trackp, 0]) - < 10.0**tol + numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackXY[trackp, 0]) < 10.0**tol ), "gaussApprox along track does not work for X" assert ( - numpy.fabs(meanp[1] - sdf_bovy14._interpolatedObsTrackXY[trackp, 2]) - < 10.0**tol + numpy.fabs(meanp[1] - sdf_bovy14._interpolatedObsTrackXY[trackp, 2]) < 10.0**tol ), "gaussApprox along track does not work for Z" assert ( - numpy.fabs(meanp[2] - sdf_bovy14._interpolatedObsTrackXY[trackp, 3]) - < 10.0**tol + numpy.fabs(meanp[2] - sdf_bovy14._interpolatedObsTrackXY[trackp, 3]) < 10.0**tol ), "gaussApprox along track does not work for vX" assert ( - numpy.fabs(meanp[3] - sdf_bovy14._interpolatedObsTrackXY[trackp, 4]) - < 10.0**tol + numpy.fabs(meanp[3] - sdf_bovy14._interpolatedObsTrackXY[trackp, 4]) < 10.0**tol ), "gaussApprox along track does not work for vY" assert ( - numpy.fabs(meanp[4] - sdf_bovy14._interpolatedObsTrackXY[trackp, 5]) - < 10.0**tol + numpy.fabs(meanp[4] - sdf_bovy14._interpolatedObsTrackXY[trackp, 5]) < 10.0**tol ), "gaussApprox along track does not work for vZ" # Y,Z,vX,vY,vZ XvX = list(sdf_bovy14._interpolatedObsTrackXY[trackp, :].flatten()) @@ -1241,24 +1224,19 @@ def test_bovy14_gaussApprox_fivemissing(bovy14_setup): XvX[5] = None meanp, varp = sdf_bovy14.gaussApprox(XvX, interp=False, cindx=1) assert ( - numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackXY[trackp, 1]) - < 10.0**tol + numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackXY[trackp, 1]) < 10.0**tol ), "gaussApprox along track does not work for Y" assert ( - numpy.fabs(meanp[1] - sdf_bovy14._interpolatedObsTrackXY[trackp, 2]) - < 10.0**tol + numpy.fabs(meanp[1] - sdf_bovy14._interpolatedObsTrackXY[trackp, 2]) < 10.0**tol ), "gaussApprox along track does not work for Z" assert ( - numpy.fabs(meanp[2] - sdf_bovy14._interpolatedObsTrackXY[trackp, 3]) - < 10.0**tol + numpy.fabs(meanp[2] - sdf_bovy14._interpolatedObsTrackXY[trackp, 3]) < 10.0**tol ), "gaussApprox along track does not work for vX" assert ( - numpy.fabs(meanp[3] - sdf_bovy14._interpolatedObsTrackXY[trackp, 4]) - < 10.0**tol + numpy.fabs(meanp[3] - sdf_bovy14._interpolatedObsTrackXY[trackp, 4]) < 10.0**tol ), "gaussApprox along track does not work for vY" assert ( - numpy.fabs(meanp[4] - sdf_bovy14._interpolatedObsTrackXY[trackp, 5]) - < 10.0**tol + numpy.fabs(meanp[4] - sdf_bovy14._interpolatedObsTrackXY[trackp, 5]) < 10.0**tol ), "gaussApprox along track does not work for vZ" return None @@ -1274,22 +1252,18 @@ def test_bovy14_gaussApprox_interp(bovy14_setup): XvX[2] = None meanp, varp = sdf_bovy14.gaussApprox(XvX, interp=True) assert ( - numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackXY[trackp, 1]) - < 10.0**tol + numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackXY[trackp, 1]) < 10.0**tol ), "Gaussian approximation when using interpolation does not work as expected for Y" assert ( - numpy.fabs(meanp[1] - sdf_bovy14._interpolatedObsTrackXY[trackp, 2]) - < 10.0**tol + numpy.fabs(meanp[1] - sdf_bovy14._interpolatedObsTrackXY[trackp, 2]) < 10.0**tol ), "Gaussian approximation when using interpolation does not work as expected for Y" # also w/ default (which should be interp=True) meanp, varp = sdf_bovy14.gaussApprox(XvX) assert ( - numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackXY[trackp, 1]) - < 10.0**tol + numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackXY[trackp, 1]) < 10.0**tol ), "Gaussian approximation when using interpolation does not work as expected for Y" assert ( - numpy.fabs(meanp[1] - sdf_bovy14._interpolatedObsTrackXY[trackp, 2]) - < 10.0**tol + numpy.fabs(meanp[1] - sdf_bovy14._interpolatedObsTrackXY[trackp, 2]) < 10.0**tol ), "Gaussian approximation when using interpolation does not work as expected for Y" return None @@ -1306,48 +1280,42 @@ def test_bovy14_gaussApproxLB_onemissing(bovy14_setup): LB[0] = None meanp, varp = sdf_bovy14.gaussApprox(LB, interp=False, lb=True) assert ( - numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackLB[trackp, 0]) - < 10.0**tol + numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackLB[trackp, 0]) < 10.0**tol ), "gaussApprox along track does not work for l" # b LB = list(sdf_bovy14._interpolatedObsTrackLB[trackp, :].flatten()) LB[1] = None meanp, varp = sdf_bovy14.gaussApprox(LB, interp=False, lb=True) assert ( - numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackLB[trackp, 1]) - < 10.0**tol + numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackLB[trackp, 1]) < 10.0**tol ), "gaussApprox along track does not work for b" # d LB = list(sdf_bovy14._interpolatedObsTrackLB[trackp, :].flatten()) LB[2] = None meanp, varp = sdf_bovy14.gaussApprox(LB, interp=False, lb=True) assert ( - numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackLB[trackp, 2]) - < 10.0**tol + numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackLB[trackp, 2]) < 10.0**tol ), "gaussApprox along track does not work for d" # vlos LB = list(sdf_bovy14._interpolatedObsTrackLB[trackp, :].flatten()) LB[3] = None meanp, varp = sdf_bovy14.gaussApprox(LB, interp=False, lb=True) assert ( - numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackLB[trackp, 3]) - < 10.0**tol + numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackLB[trackp, 3]) < 10.0**tol ), "gaussApprox along track does not work for vlos" # pmll LB = list(sdf_bovy14._interpolatedObsTrackLB[trackp, :].flatten()) LB[4] = None meanp, varp = sdf_bovy14.gaussApprox(LB, interp=False, lb=True) assert ( - numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackLB[trackp, 4]) - < 10.0**tol + numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackLB[trackp, 4]) < 10.0**tol ), "gaussApprox along track does not work for pmll" # pmbb LB = list(sdf_bovy14._interpolatedObsTrackLB[trackp, :].flatten()) LB[5] = None meanp, varp = sdf_bovy14.gaussApprox(LB, interp=False, lb=True) assert ( - numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackLB[trackp, 5]) - < 10.0**tol + numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackLB[trackp, 5]) < 10.0**tol ), "gaussApprox along track does not work for pmbb" return None @@ -1366,16 +1334,13 @@ def test_bovy14_gaussApproxLB_threemissing(bovy14_setup): LB[4] = None meanp, varp = sdf_bovy14.gaussApprox(LB, interp=False, lb=True) assert ( - numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackLB[trackp, 0]) - < 10.0**tol + numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackLB[trackp, 0]) < 10.0**tol ), "gaussApprox along track does not work for l" assert ( - numpy.fabs(meanp[1] - sdf_bovy14._interpolatedObsTrackLB[trackp, 3]) - < 10.0**tol + numpy.fabs(meanp[1] - sdf_bovy14._interpolatedObsTrackLB[trackp, 3]) < 10.0**tol ), "gaussApprox along track does not work for vlos" assert ( - numpy.fabs(meanp[2] - sdf_bovy14._interpolatedObsTrackLB[trackp, 4]) - < 10.0**tol + numpy.fabs(meanp[2] - sdf_bovy14._interpolatedObsTrackLB[trackp, 4]) < 10.0**tol ), "gaussApprox along track does not work for pmll" # b,d,pmbb LB = list(sdf_bovy14._interpolatedObsTrackLB[trackp, :].flatten()) @@ -1384,16 +1349,13 @@ def test_bovy14_gaussApproxLB_threemissing(bovy14_setup): LB[5] = None meanp, varp = sdf_bovy14.gaussApprox(LB, interp=False, lb=True) assert ( - numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackLB[trackp, 1]) - < 10.0**tol + numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackLB[trackp, 1]) < 10.0**tol ), "gaussApprox along track does not work for b" assert ( - numpy.fabs(meanp[1] - sdf_bovy14._interpolatedObsTrackLB[trackp, 2]) - < 10.0**tol + numpy.fabs(meanp[1] - sdf_bovy14._interpolatedObsTrackLB[trackp, 2]) < 10.0**tol ), "gaussApprox along track does not work for d" assert ( - numpy.fabs(meanp[2] - sdf_bovy14._interpolatedObsTrackLB[trackp, 5]) - < 10.0**tol + numpy.fabs(meanp[2] - sdf_bovy14._interpolatedObsTrackLB[trackp, 5]) < 10.0**tol ), "gaussApprox along track does not work for pmbb" return None @@ -1414,24 +1376,19 @@ def test_bovy14_gaussApproxLB_fivemissing(bovy14_setup): LB[5] = None meanp, varp = sdf_bovy14.gaussApprox(LB, interp=False, cindx=1, lb=True) assert ( - numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackLB[trackp, 0]) - < 10.0**tol + numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackLB[trackp, 0]) < 10.0**tol ), "gaussApprox along track does not work for l" assert ( - numpy.fabs(meanp[1] - sdf_bovy14._interpolatedObsTrackLB[trackp, 2]) - < 10.0**tol + numpy.fabs(meanp[1] - sdf_bovy14._interpolatedObsTrackLB[trackp, 2]) < 10.0**tol ), "gaussApprox along track does not work for d" assert ( - numpy.fabs(meanp[2] - sdf_bovy14._interpolatedObsTrackLB[trackp, 3]) - < 10.0**tol + numpy.fabs(meanp[2] - sdf_bovy14._interpolatedObsTrackLB[trackp, 3]) < 10.0**tol ), "gaussApprox along track does not work for vlos" assert ( - numpy.fabs(meanp[3] - sdf_bovy14._interpolatedObsTrackLB[trackp, 4]) - < 10.0**tol + numpy.fabs(meanp[3] - sdf_bovy14._interpolatedObsTrackLB[trackp, 4]) < 10.0**tol ), "gaussApprox along track does not work for pmll" assert ( - numpy.fabs(meanp[4] - sdf_bovy14._interpolatedObsTrackLB[trackp, 5]) - < 10.0**tol + numpy.fabs(meanp[4] - sdf_bovy14._interpolatedObsTrackLB[trackp, 5]) < 10.0**tol ), "gaussApprox along track does not work for pmbb" # b,d,vlos,pmll,pmbb LB = list(sdf_bovy14._interpolatedObsTrackLB[trackp, :].flatten()) @@ -1442,24 +1399,19 @@ def test_bovy14_gaussApproxLB_fivemissing(bovy14_setup): LB[5] = None meanp, varp = sdf_bovy14.gaussApprox(LB, interp=False, cindx=1, lb=True) assert ( - numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackLB[trackp, 1]) - < 10.0**tol + numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackLB[trackp, 1]) < 10.0**tol ), "gaussApprox along track does not work for b" assert ( - numpy.fabs(meanp[1] - sdf_bovy14._interpolatedObsTrackLB[trackp, 2]) - < 10.0**tol + numpy.fabs(meanp[1] - sdf_bovy14._interpolatedObsTrackLB[trackp, 2]) < 10.0**tol ), "gaussApprox along track does not work for d" assert ( - numpy.fabs(meanp[2] - sdf_bovy14._interpolatedObsTrackLB[trackp, 3]) - < 10.0**tol + numpy.fabs(meanp[2] - sdf_bovy14._interpolatedObsTrackLB[trackp, 3]) < 10.0**tol ), "gaussApprox along track does not work for vlos" assert ( - numpy.fabs(meanp[3] - sdf_bovy14._interpolatedObsTrackLB[trackp, 4]) - < 10.0**tol + numpy.fabs(meanp[3] - sdf_bovy14._interpolatedObsTrackLB[trackp, 4]) < 10.0**tol ), "gaussApprox along track does not work for pmll" assert ( - numpy.fabs(meanp[4] - sdf_bovy14._interpolatedObsTrackLB[trackp, 5]) - < 10.0**tol + numpy.fabs(meanp[4] - sdf_bovy14._interpolatedObsTrackLB[trackp, 5]) < 10.0**tol ), "gaussApprox along track does not work for pmbb" return None @@ -1475,12 +1427,10 @@ def test_bovy14_gaussApproxLB_interp(bovy14_setup): LB[2] = None meanp, varp = sdf_bovy14.gaussApprox(LB, interp=True, lb=True) assert ( - numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackLB[trackp, 1]) - < 10.0**tol + numpy.fabs(meanp[0] - sdf_bovy14._interpolatedObsTrackLB[trackp, 1]) < 10.0**tol ), "Gaussian approximation when using interpolation does not work as expected for b" assert ( - numpy.fabs(meanp[1] - sdf_bovy14._interpolatedObsTrackLB[trackp, 2]) - < 10.0**tol + numpy.fabs(meanp[1] - sdf_bovy14._interpolatedObsTrackLB[trackp, 2]) < 10.0**tol ), "Gaussian approximation when using interpolation does not work as expected for d" return None