Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binary derivatives units and exact #1726

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/pint/models/binary_ell1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Approximate binary model for small eccentricity."""

import astropy.units as u
import numpy as np
from astropy.time import Time
Expand Down Expand Up @@ -81,8 +82,8 @@ class BinaryELL1(PulsarBinary):
- Zhu et al. (2019), MNRAS, 482 (3), 3249-3260 [2]_
- Fiore et al. (2023), arXiv:2305.13624 [astro-ph.HE] [3]_

.. [1] https://ui.adsabs.harvard.edu/abs/2019MNRAS.482.3249Z/abstract
.. [2] https://ui.adsabs.harvard.edu/abs/2001MNRAS.326..274L/abstract
.. [1] https://ui.adsabs.harvard.edu/abs/2001MNRAS.326..274L/abstract
.. [2] https://ui.adsabs.harvard.edu/abs/2019MNRAS.482.3249Z/abstract
.. [3] https://arxiv.org/abs/2305.13624

Notes
Expand Down
110 changes: 103 additions & 7 deletions src/pint/models/stand_alone_psr_binaries/BT_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,17 @@
"""Full BT model delay"""
return (self.delayL1() + self.delayL2()) * self.delayR()

# NOTE: Below, OMEGA is supposed to be in RADIANS!
# TODO: Fix UNITS!!!
def d_delayL1_d_E(self):
a1 = self.a1() / c.c
return -a1 * np.sin(self.omega()) * np.sin(self.E())
return -a1 * np.sin(self.omega()) * np.sin(self.E()) / u.rad

def d_delayL2_d_E(self):
a1 = self.a1() / c.c
return (
a1 * np.cos(self.omega()) * np.sqrt(1 - self.ecc() ** 2) + self.GAMMA
) * np.cos(self.E())
(a1 * np.cos(self.omega()) * np.sqrt(1 - self.ecc() ** 2) + self.GAMMA)
* np.cos(self.E())
/ u.rad
)

def d_delayL1_d_A1(self):
return np.sin(self.omega()) * (np.cos(self.E()) - self.ecc()) / c.c
Expand All @@ -171,15 +171,19 @@

def d_delayL1_d_OM(self):
a1 = self.a1() / c.c
return a1 * np.cos(self.omega()) * (np.cos(self.E()) - self.ecc())
return a1 * np.cos(self.omega()) * (np.cos(self.E()) - self.ecc()) / u.rad

def d_delayL1_d_OMDOT(self):
return self.tt0 * self.d_delayL1_d_OM()

def d_delayL2_d_OM(self):
a1 = self.a1() / c.c
return (
-a1 * np.sin(self.omega()) * np.sqrt(1 - self.ecc() ** 2) * np.sin(self.E())
-a1
* np.sin(self.omega())
* np.sqrt(1 - self.ecc() ** 2)
* np.sin(self.E())
/ u.rad
)

def d_delayL2_d_OMDOT(self):
Expand Down Expand Up @@ -207,6 +211,8 @@
def d_delayL2_d_GAMMA(self):
return np.sin(self.E())

# NOTE: The two derivatives below are taken care by lines 222, 237
# TODO: Remove if indeed redundant
def d_delayL1_d_T0(self):
return self.d_delayL1_d_E() * self.d_E_d_T0()

Expand Down Expand Up @@ -245,3 +251,93 @@

def d_BTdelay_d_par(self, par):
return self.delayR() * (self.d_delayL1_d_par(par) + self.d_delayL2_d_par(par))


class BTmodel_extended_derivatives(BTmodel):
"""
This class extends the BTmodel class to include the exact first derivatives and some second derivatives.
"""

def __init__(self, t=None, input_params=None):
super().__init__(t, input_params)

Check warning on line 262 in src/pint/models/stand_alone_psr_binaries/BT_model.py

View check run for this annotation

Codecov / codecov/patch

src/pint/models/stand_alone_psr_binaries/BT_model.py#L262

Added line #L262 was not covered by tests

def d_delayR_d_E(self):
a1 = self.a1() / c.c
omega = self.omega()
ecc = self.ecc()
E = self.E()
num = np.sqrt(1 - ecc**2) * np.cos(omega) * np.sin(E) + (

Check warning on line 269 in src/pint/models/stand_alone_psr_binaries/BT_model.py

View check run for this annotation

Codecov / codecov/patch

src/pint/models/stand_alone_psr_binaries/BT_model.py#L265-L269

Added lines #L265 - L269 were not covered by tests
np.cos(E) - ecc
) * np.sin(omega)
den = (1 - ecc * np.cos(E)) ** 2
return 2 * np.pi * a1 * num / (den * self.pb().to(u.second))

Check warning on line 273 in src/pint/models/stand_alone_psr_binaries/BT_model.py

View check run for this annotation

Codecov / codecov/patch

src/pint/models/stand_alone_psr_binaries/BT_model.py#L272-L273

Added lines #L272 - L273 were not covered by tests

def d_delayR_d_A1(self):
omega = self.omega()
ecc = self.ecc()
E = self.E()
num = np.cos(omega) * np.sqrt(1 - ecc**2) * np.cos(E) - np.sin(

Check warning on line 279 in src/pint/models/stand_alone_psr_binaries/BT_model.py

View check run for this annotation

Codecov / codecov/patch

src/pint/models/stand_alone_psr_binaries/BT_model.py#L276-L279

Added lines #L276 - L279 were not covered by tests
omega
) * np.sin(E)
den = 1.0 - ecc * np.cos(E)
return 1.0 - 2 * np.pi * num / (den * self.pb().to(u.second))

Check warning on line 283 in src/pint/models/stand_alone_psr_binaries/BT_model.py

View check run for this annotation

Codecov / codecov/patch

src/pint/models/stand_alone_psr_binaries/BT_model.py#L282-L283

Added lines #L282 - L283 were not covered by tests

def d_delayR_d_A1DOT(self):
return self.tt0 * self.d_delayR_d_A1()

Check warning on line 286 in src/pint/models/stand_alone_psr_binaries/BT_model.py

View check run for this annotation

Codecov / codecov/patch

src/pint/models/stand_alone_psr_binaries/BT_model.py#L286

Added line #L286 was not covered by tests

def d_delayR_d_OM(self):
a1 = self.a1() / c.c
omega = self.omega()
ecc = self.ecc()
E = self.E()
num = -np.sin(omega) * np.sqrt(1 - ecc**2) * np.cos(E) - np.cos(

Check warning on line 293 in src/pint/models/stand_alone_psr_binaries/BT_model.py

View check run for this annotation

Codecov / codecov/patch

src/pint/models/stand_alone_psr_binaries/BT_model.py#L289-L293

Added lines #L289 - L293 were not covered by tests
omega
) * np.sin(E)
den = 1.0 - ecc * np.cos(E)
return -2 * np.pi * a1 * num / (den * self.pb().to(u.second))

Check warning on line 297 in src/pint/models/stand_alone_psr_binaries/BT_model.py

View check run for this annotation

Codecov / codecov/patch

src/pint/models/stand_alone_psr_binaries/BT_model.py#L296-L297

Added lines #L296 - L297 were not covered by tests

def d_delayR_d_OMDOT(self):
return self.tt0 * self.d_delayR_d_OM()

Check warning on line 300 in src/pint/models/stand_alone_psr_binaries/BT_model.py

View check run for this annotation

Codecov / codecov/patch

src/pint/models/stand_alone_psr_binaries/BT_model.py#L300

Added line #L300 was not covered by tests

def d_delayR_d_ECC(self):
a1 = self.a1() / c.c
omega = self.omega()
ecc = self.ecc()
E = self.E()
num = (ecc - np.cos(E)) * np.cos(omega) + np.sqrt(1 - ecc**2) * np.sin(

Check warning on line 307 in src/pint/models/stand_alone_psr_binaries/BT_model.py

View check run for this annotation

Codecov / codecov/patch

src/pint/models/stand_alone_psr_binaries/BT_model.py#L303-L307

Added lines #L303 - L307 were not covered by tests
E
) * np.sin(omega)
den = np.sqrt(1 - ecc**2) * (1 - ecc * np.cos(E)) ** 2
return (

Check warning on line 311 in src/pint/models/stand_alone_psr_binaries/BT_model.py

View check run for this annotation

Codecov / codecov/patch

src/pint/models/stand_alone_psr_binaries/BT_model.py#L310-L311

Added lines #L310 - L311 were not covered by tests
2 * np.pi * a1 * np.cos(E) * num / (den * self.pb().to(u.second))
+ self.d_delayR_d_E() * self.d_E_d_ECC()
)

def d_delayR_d_EDOT(self):
return self.tt0 * self.d_delayR_d_ECC()

Check warning on line 317 in src/pint/models/stand_alone_psr_binaries/BT_model.py

View check run for this annotation

Codecov / codecov/patch

src/pint/models/stand_alone_psr_binaries/BT_model.py#L317

Added line #L317 was not covered by tests

def d_delayR_d_GAMMA(self):
return np.zeros(len(self.t)) * u.second / u.second

Check warning on line 320 in src/pint/models/stand_alone_psr_binaries/BT_model.py

View check run for this annotation

Codecov / codecov/patch

src/pint/models/stand_alone_psr_binaries/BT_model.py#L320

Added line #L320 was not covered by tests

def d_delayR_d_T0(self):
return self.d_delayR_d_E() * self.d_E_d_T0()

Check warning on line 323 in src/pint/models/stand_alone_psr_binaries/BT_model.py

View check run for this annotation

Codecov / codecov/patch

src/pint/models/stand_alone_psr_binaries/BT_model.py#L323

Added line #L323 was not covered by tests

def d_delayR_d_par(self, par):
if par not in self.binary_params:
errorMesg = f"{par} is not in binary parameter list."
raise ValueError(errorMesg)

Check warning on line 328 in src/pint/models/stand_alone_psr_binaries/BT_model.py

View check run for this annotation

Codecov / codecov/patch

src/pint/models/stand_alone_psr_binaries/BT_model.py#L327-L328

Added lines #L327 - L328 were not covered by tests

par_obj = getattr(self, par)

Check warning on line 330 in src/pint/models/stand_alone_psr_binaries/BT_model.py

View check run for this annotation

Codecov / codecov/patch

src/pint/models/stand_alone_psr_binaries/BT_model.py#L330

Added line #L330 was not covered by tests
if not hasattr(self, f"d_delayR_d_{par}"):
return (

Check warning on line 332 in src/pint/models/stand_alone_psr_binaries/BT_model.py

View check run for this annotation

Codecov / codecov/patch

src/pint/models/stand_alone_psr_binaries/BT_model.py#L332

Added line #L332 was not covered by tests
self.d_delayR_d_E() * self.d_E_d_par(par)
if par in self.orbits_cls.orbit_params
else np.zeros(len(self.t)) * u.second / par_obj.unit
)
func = getattr(self, f"d_delayR_d_{par}")
return func()

Check warning on line 338 in src/pint/models/stand_alone_psr_binaries/BT_model.py

View check run for this annotation

Codecov / codecov/patch

src/pint/models/stand_alone_psr_binaries/BT_model.py#L337-L338

Added lines #L337 - L338 were not covered by tests

def d_BTdelay_d_par(self, par):
return self.delayR() * (

Check warning on line 341 in src/pint/models/stand_alone_psr_binaries/BT_model.py

View check run for this annotation

Codecov / codecov/patch

src/pint/models/stand_alone_psr_binaries/BT_model.py#L341

Added line #L341 was not covered by tests
self.d_delayL1_d_par(par) + self.d_delayL2_d_par(par)
) + (self.delayL1() + self.delayL2()) * self.d_delayR_d_par(par)
8 changes: 3 additions & 5 deletions src/pint/models/stand_alone_psr_binaries/DD_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Damour and Deruelle binary model."""

import astropy.constants as c
import astropy.units as u
import numpy as np
Expand Down Expand Up @@ -301,7 +302,7 @@ def d_beta_d_par(self, par):
d_eTheta_d_par = self.d_eTheta_d_par(par)

d_beta_d_a1 = 1.0 / c.c * (1 - eTheta**2) ** 0.5 * cosOmg
d_beta_d_omega = -a1 / c.c * (1 - eTheta**2) ** 0.5 * sinOmg
d_beta_d_omega = -a1 / c.c * (1 - eTheta**2) ** 0.5 * sinOmg / u.rad
d_beta_d_eTheta = a1 / c.c * (-eTheta) / np.sqrt(1 - eTheta**2) * cosOmg
with u.set_enabled_equivalencies(u.dimensionless_angles()):
return (
Expand Down Expand Up @@ -756,10 +757,7 @@ def d_delayS_d_par(self, par):
-2
* TM2
/ logNum
* (
e * sE
- self.SINI * (np.sqrt(1 - e**2) * cE * cOmega - sE * sOmega)
)
* (e * sE - self.SINI * (np.sqrt(1 - e**2) * cE * cOmega - sE * sOmega))
)
domega_dpar = self.prtl_der("omega", par)
dsDelay_domega = (
Expand Down
2 changes: 1 addition & 1 deletion src/pint/models/stand_alone_psr_binaries/binary_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ def d_E_d_T0(self):

def d_E_d_ECC(self):
E = self.E()
return np.sin(E) / (1.0 - self.ecc() * np.cos(E))
return np.sin(E) / (1.0 - self.ecc() * np.cos(E)) * u.rad

def d_E_d_EDOT(self):
return self.tt0 * self.d_E_d_ECC()
Expand Down
Loading