Skip to content

Commit

Permalink
Finish updating string syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
aarchiba committed Feb 25, 2024
1 parent 8c0f22f commit 7ff5a75
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 53 deletions.
40 changes: 17 additions & 23 deletions src/pint/derived_quantities.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ def pferrs(porf, porferr, pdorfd=None, pdorfderr=None):
return [1.0 / porf, porferr / porf**2.0]
forperr = porferr / porf**2.0
fdorpderr = np.sqrt(
(4.0 * pdorfd**2.0 * porferr**2.0) / porf**6.0
+ pdorfderr**2.0 / porf**4.0
(4.0 * pdorfd**2.0 * porferr**2.0) / porf**6.0 + pdorfderr**2.0 / porf**4.0
)
[forp, fdorpd] = p_to_f(porf, pdorfd)
return [forp, forperr, fdorpd, fdorpderr]
Expand Down Expand Up @@ -165,7 +164,7 @@ def pulsar_age(f: u.Hz, fdot: u.Hz / u.s, n=3, fo=1e99 * u.Hz):
.. math::
\\tau = \\frac{f}{(n-1)\dot f}\\left(1-\\left(\\frac{f}{f_0}\\right)^{n-1}\\right)
\tau = \frac{f}{(n-1)\dot f}\left(1-\left(\frac{f}{f_0}\right)^{n-1}\right)
"""
return (-f / ((n - 1.0) * fdot) * (1.0 - (f / fo) ** (n - 1.0))).to(u.yr)

Expand Down Expand Up @@ -515,17 +514,12 @@ def companion_mass(pb: u.d, x: u.cm, i=60.0 * u.deg, mp=1.4 * u.solMass):
# delta1 is always <0
# delta1 = 2 * b ** 3 - 9 * a * b * c + 27 * a ** 2 * d
delta1 = (
-2 * massfunct**3
- 18 * a * mp * massfunct**2
- 27 * a**2 * massfunct * mp**2
-2 * massfunct**3 - 18 * a * mp * massfunct**2 - 27 * a**2 * massfunct * mp**2
)
# Q**2 is always > 0, so this is never a problem
# in terms of complex numbers
# Q = np.sqrt(delta1**2 - 4*delta0**3)
Q = np.sqrt(
108 * a**3 * mp**3 * massfunct**3
+ 729 * a**4 * mp**4 * massfunct**2
)
Q = np.sqrt(108 * a**3 * mp**3 * massfunct**3 + 729 * a**4 * mp**4 * massfunct**2)
# this could be + or - Q
# pick the - branch since delta1 is <0 so that delta1 - Q is never near 0
Ccubed = 0.5 * (delta1 + Q)
Expand Down Expand Up @@ -770,7 +764,7 @@ def sini(mp: u.Msun, mc: u.Msun, pb: u.d, x: u.cm):

@u.quantity_input
def dr(mp: u.Msun, mc: u.Msun, pb: u.d):
"""Post-Keplerian Roemer delay term
r"""Post-Keplerian Roemer delay term
dr (:math:`\delta_r`) is part of the relativistic deformation of the orbit
Expand Down Expand Up @@ -820,9 +814,9 @@ def dr(mp: u.Msun, mc: u.Msun, pb: u.d):

@u.quantity_input
def dth(mp: u.Msun, mc: u.Msun, pb: u.d):
"""Post-Keplerian Roemer delay term
r"""Post-Keplerian Roemer delay term
dth (:math:`\delta_{\\theta}`) is part of the relativistic deformation of the orbit
dth (:math:`\delta_{\theta}`) is part of the relativistic deformation of the orbit
Parameters
----------
Expand Down Expand Up @@ -850,8 +844,8 @@ def dth(mp: u.Msun, mc: u.Msun, pb: u.d):
.. math::
\delta_{\\theta} = T_{\odot}^{2/3} \\left(\\frac{P_b}{2\pi}\\right)^{2/3}
\\frac{3.5 m_p^2+6 m_p m_c +2m_c^2}{(m_p+m_c)^{4/3}}
\delta_{\theta} = T_{\odot}^{2/3} \left(\frac{P_b}{2\pi}\right)^{2/3}
\frac{3.5 m_p^2+6 m_p m_c +2m_c^2}{(m_p+m_c)^{4/3}}
with :math:`T_\odot = GM_\odot c^{-3}`.
Expand All @@ -870,7 +864,7 @@ def dth(mp: u.Msun, mc: u.Msun, pb: u.d):

@u.quantity_input
def omdot_to_mtot(omdot: u.deg / u.yr, pb: u.d, e: u.dimensionless_unscaled):
"""Determine total mass from Post-Keplerian longitude of periastron precession rate omdot,
r"""Determine total mass from Post-Keplerian longitude of periastron precession rate omdot,
assuming general relativity.
omdot (:math:`\dot \omega`) is the relativistic advance of periastron. It relates to the total
Expand Down Expand Up @@ -904,8 +898,8 @@ def omdot_to_mtot(omdot: u.deg / u.yr, pb: u.d, e: u.dimensionless_unscaled):
.. math::
\dot \omega = 3T_{\odot}^{2/3} \\left(\\frac{P_b}{2\pi}\\right)^{-5/3}
\\frac{1}{1-e^2}(m_p+m_c)^{2/3}
\dot \omega = 3T_{\odot}^{2/3} \left(\frac{P_b}{2\pi}\right)^{-5/3}
\frac{1}{1-e^2}(m_p+m_c)^{2/3}
to calculate :math:`m_{\\rm tot} = m_p + m_c`,
with :math:`T_\odot = GM_\odot c^{-3}`.
Expand All @@ -930,7 +924,7 @@ def omdot_to_mtot(omdot: u.deg / u.yr, pb: u.d, e: u.dimensionless_unscaled):

@u.quantity_input(pb=u.d, mp=u.Msun, mc=u.Msun, i=u.deg)
def a1sini(mp, mc, pb, i=90 * u.deg):
"""Pulsar's semi-major axis.
r"""Pulsar's semi-major axis.
The full semi-major axis is given by Kepler's third law. This is the
projection (:math:`\sin i`) of just the pulsar's orbit (:math:`m_c/(m_p+m_c)`
Expand Down Expand Up @@ -966,8 +960,8 @@ def a1sini(mp, mc, pb, i=90 * u.deg):
.. math::
\\frac{a_p \sin i}{c} = \\frac{m_c \sin i}{(m_p+m_c)^{2/3}}
G^{1/3}\\left(\\frac{P_b}{2\pi}\\right)^{2/3}
\frac{a_p \sin i}{c} = \frac{m_c \sin i}{(m_p+m_c)^{2/3}}
G^{1/3}\left(\frac{P_b}{2\pi}\right)^{2/3}
More details in :ref:`Timing Models`. Also see [8]_
Expand All @@ -982,7 +976,7 @@ def a1sini(mp, mc, pb, i=90 * u.deg):

@u.quantity_input
def shklovskii_factor(pmtot: u.mas / u.yr, D: u.kpc):
"""Compute magnitude of Shklovskii correction factor.
r"""Compute magnitude of Shklovskii correction factor.
Computes the Shklovskii correction factor, as defined in Eq 8.12 of Lorimer & Kramer (2005) [10]_
This is the factor by which :math:`\dot P /P` is increased due to the transverse velocity.
Expand All @@ -991,7 +985,7 @@ def shklovskii_factor(pmtot: u.mas / u.yr, D: u.kpc):
.. math::
\dot P_{\\rm intrinsic} = \dot P_{\\rm observed} - a_s P
\dot P_{\rm intrinsic} = \dot P_{\rm observed} - a_s P
Parameters
----------
Expand Down
2 changes: 1 addition & 1 deletion src/pint/models/binary_dd.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def validate(self):


class BinaryDDS(BinaryDD):
"""Damour and Deruelle model with alternate Shapiro delay parameterization.
r"""Damour and Deruelle model with alternate Shapiro delay parameterization.
This extends the :class:`pint.models.binary_dd.BinaryDD` model with
:math:`SHAPMAX = -\log(1-s)` instead of just :math:`s=\sin i`, which behaves better
Expand Down
6 changes: 3 additions & 3 deletions src/pint/models/binary_ddk.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def _convert_kom(kom):


class BinaryDDK(BinaryDD):
"""Damour and Deruelle model with kinematics.
r"""Damour and Deruelle model with kinematics.
This extends the :class:`pint.models.binary_dd.BinaryDD` model with
"Shklovskii" and "Kopeikin" terms that account for the finite distance
Expand Down Expand Up @@ -220,14 +220,14 @@ def validate(self):
warnings.warn("Using A1DOT with a DDK model is not advised.")

def alternative_solutions(self):
"""Alternative Kopeikin solutions (potential local minima)
r"""Alternative Kopeikin solutions (potential local minima)
There are 4 potential local minima for a DDK model where a1dot is the same
These are given by where Eqn. 8 in Kopeikin (1996) is equal to the best-fit value.
We first define the symmetry point where a1dot is zero (in equatorial coordinates):
:math:`KOM_0 = \\tan^{-1} (\mu_{\delta} / \mu_{\\alpha})`
:math:`KOM_0 = \tan^{-1} (\mu_{\delta} / \mu_{\alpha})`
The solutions are then:
Expand Down
2 changes: 1 addition & 1 deletion src/pint/models/pulsar_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@


class PulsarBinary(DelayComponent):
"""Base class for binary models in PINT.
r"""Base class for binary models in PINT.
This class provides a wrapper for internal classes that do the actual calculations.
The calculations are done by the classes located in
Expand Down
24 changes: 11 additions & 13 deletions src/pint/models/stand_alone_psr_binaries/DDK_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


class DDKmodel(DDmodel):
"""DDK model, a Kopeikin method corrected DD model.
r"""DDK model, a Kopeikin method corrected DD model.
The main difference is that DDK model considers the effects on the pulsar binary parameters from the annual parallax of earth and the proper motion of the pulsar.
Expand Down Expand Up @@ -155,7 +155,7 @@ def SINI(self, val):
# Update binary parameters due to the pulser proper motion

def delta_kin_proper_motion(self):
"""The time dependent inclination angle
r"""The time dependent inclination angle
(Kopeikin 1996 Eq 10):
.. math::
Expand Down Expand Up @@ -231,7 +231,7 @@ def d_kin_d_par(self, par):
return func()

def delta_a1_proper_motion(self):
"""The correction on a1 (projected semi-major axis)
r"""The correction on a1 (projected semi-major axis)
due to the pulsar proper motion
(Kopeikin 1996 Eq 8):
Expand Down Expand Up @@ -289,7 +289,7 @@ def d_delta_a1_proper_motion_d_T0(self):
return d_delta_a1_proper_motion_d_T0.to(a1.unit / self.T0.unit)

def delta_omega_proper_motion(self):
"""The correction on omega (Longitude of periastron)
r"""The correction on omega (Longitude of periastron)
due to the pulsar proper motion
(Kopeikin 1996 Eq 9):
Expand Down Expand Up @@ -353,15 +353,15 @@ def d_delta_omega_proper_motion_d_T0(self):
# Reference KOPEIKIN. 1995 Eq 18 -> Eq 19.

def delta_I0(self):
"""
r"""
:math:`\Delta_{I0}`
Reference: (Kopeikin 1995 Eq 15)
"""
return -self.obs_pos[:, 0] * self.sin_long + self.obs_pos[:, 1] * self.cos_long

def delta_J0(self):
"""
r"""
:math:`\Delta_{J0}`
Reference: (Kopeikin 1995 Eq 16)
Expand All @@ -373,19 +373,19 @@ def delta_J0(self):
)

def delta_sini_parallax(self):
"""Reference (Kopeikin 1995 Eq 18). Computes:
r"""Reference (Kopeikin 1995 Eq 18). Computes:
.. math::
x_{obs} = \\frac{a_p \sin(i)_{obs}}{c}
x_{obs} = \frac{a_p \sin(i)_{obs}}{c}
Since :math:`a_p` and :math:`c` will not be changed by parallax:
.. math::
x_{obs} = \\frac{a_p}{c}(\sin(i)_{\\rm intrisic} + \delta_{\sin(i)})
x_{obs} = \frac{a_p}{c}(\sin(i)_{\rm intrisic} + \delta_{\sin(i)})
\delta_{\sin(i)} = \sin(i)_{\\rm intrisic} \\frac{\cot(i)_{\\rm intrisic}}{d} (\Delta_{I0} \sin KOM - \Delta_{J0} \cos KOM)
\delta_{\sin(i)} = \sin(i)_{\rm intrisic} \frac{\cot(i)_{\rm intrisic}}{d} (\Delta_{I0} \sin KOM - \Delta_{J0} \cos KOM)
"""
PX_kpc = self.PX.to(u.kpc, equivalencies=u.parallax())
Expand Down Expand Up @@ -518,9 +518,7 @@ def d_delta_omega_parallax_d_T0(self):
PX_kpc = self.PX.to(u.kpc, equivalencies=u.parallax())
kom_projection = self.delta_I0() * self.cos_KOM + self.delta_J0() * self.sin_KOM
d_kin_d_T0 = self.d_kin_d_par("T0")
d_delta_omega_d_T0 = (
cos_kin / sin_kin**2 / PX_kpc * d_kin_d_T0 * kom_projection
)
d_delta_omega_d_T0 = cos_kin / sin_kin**2 / PX_kpc * d_kin_d_T0 * kom_projection
return d_delta_omega_d_T0.to(
self.OM.unit / self.T0.unit, equivalencies=u.dimensionless_angles()
)
Expand Down
2 changes: 1 addition & 1 deletion src/pint/models/stand_alone_psr_binaries/DDS_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


class DDSmodel(DDmodel):
"""Damour and Deruelle model with alternate Shapiro delay parameterization.
r"""Damour and Deruelle model with alternate Shapiro delay parameterization.
This extends the :class:`pint.models.binary_dd.BinaryDD` model with
:math:`SHAPMAX = -\log(1-s)` instead of just :math:`s=\sin i`, which behaves better
Expand Down
4 changes: 2 additions & 2 deletions src/pint/models/stand_alone_psr_binaries/ELL1H_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


class ELL1Hmodel(ELL1BaseModel):
"""ELL1H pulsar binary model using H3, H4 or STIGMA as shapiro delay parameters.
r"""ELL1H pulsar binary model using H3, H4 or STIGMA as shapiro delay parameters.
Note
----
Expand All @@ -21,7 +21,7 @@ class ELL1Hmodel(ELL1BaseModel):
.. math::
\\Delta_S = -2r \\left( \\frac{a_0}{2} + \\Sum_k (a_k \\cos k\\phi + b_k \\sin k \phi) \\right)
\Delta_S = -2r \left( \frac{a_0}{2} + \Sum_k (a_k \cos k\phi + b_k \sin k \phi) \right)
The first two harmonics are generlly absorbed by the ELL1 Roemer delay.
Thus, :class:`~pint.models.binary_ell1.BinaryELL1H` uses the series from the third
Expand Down
19 changes: 10 additions & 9 deletions src/pint/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1644,9 +1644,10 @@ def get_wavex_amps(model, index=None, quantity=False):
model.components["WaveX"].get_prefix_mapping_component("WXSIN_").keys()
)
if len(indices) == 1:
values = getattr(
model.components["WaveX"], f"WXSIN_{int(indices):04d}"
), getattr(model.components["WaveX"], f"WXCOS_{int(indices):04d}")
values = (
getattr(model.components["WaveX"], f"WXSIN_{int(indices):04d}"),
getattr(model.components["WaveX"], f"WXCOS_{int(indices):04d}"),
)
else:
values = [
(
Expand All @@ -1657,8 +1658,9 @@ def get_wavex_amps(model, index=None, quantity=False):
]
elif isinstance(index, (int, float, np.int64)):
idx_rf = f"{int(index):04d}"
values = getattr(model.components["WaveX"], f"WXSIN_{idx_rf}"), getattr(
model.components["WaveX"], f"WXCOS_{idx_rf}"
values = (
getattr(model.components["WaveX"], f"WXSIN_{idx_rf}"),
getattr(model.components["WaveX"], f"WXCOS_{idx_rf}"),
)
elif isinstance(index, (list, set, np.ndarray)):
idx_rf = [f"{int(idx):04d}" for idx in index]
Expand Down Expand Up @@ -1784,12 +1786,12 @@ def weighted_mean(arrin, weights_in, inputmean=None, calcerr=False, sdev=False):
def ELL1_check(
A1: u.cm, E: u.dimensionless_unscaled, TRES: u.us, NTOA: int, outstring=True
):
"""Check for validity of assumptions in ELL1 binary model
r"""Check for validity of assumptions in ELL1 binary model
Checks whether the assumptions that allow ELL1 to be safely used are
satisfied. To work properly, we should have:
:math:`asini/c e^4 \ll {\\rm timing precision} / \sqrt N_{\\rm TOA}`
or :math:`A1 E^4 \ll TRES / \sqrt N_{\\rm TOA}`
:math:`asini/c e^4 \ll {\rm timing precision} / \sqrt N_{\rm TOA}`
or :math:`A1 E^4 \ll TRES / \sqrt N_{\rm TOA}`
since the ELL1 model now includes terms up to O(E^3)
Expand All @@ -1810,7 +1812,6 @@ def ELL1_check(
bool or str
Returns True if ELL1 is safe to use, otherwise False.
If outstring is True then returns a string summary instead.
"""
lhs = A1 / const.c * E**4.0
rhs = TRES / np.sqrt(NTOA)
Expand Down

0 comments on commit 7ff5a75

Please sign in to comment.