Skip to content

Commit 3c72474

Browse files
authored
Merge pull request #1948 from dlakaplan/tzrwarn
Warning when setting TZRMJD, method to set phase offset to 0
2 parents 79e717d + f41e0e5 commit 3c72474

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

CHANGELOG-unreleased.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ the released changes.
1212
### Added
1313
- Anderson-Darling test for normal data with fixed mean/variance
1414
- KS test to check if the whitened residuals are unit-normal distributed
15+
- Warning about setting of TZRMJD from TOAs
16+
- Method to zero out mean residual based on TZRMJD
1517
### Fixed
1618
### Removed

src/pint/models/absolute_phase.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,5 +137,8 @@ def make_TZR_toa(self, toas):
137137
later = [i for i in toas.get_mjds() if i > PEPOCH * u.d]
138138
earlier = [i for i in toas.get_mjds() if i <= PEPOCH * u.d]
139139
TZRMJD = min(later) if later else max(earlier)
140+
log.warning(
141+
f"TZRMJD is not set. Setting TZRMJD to first TOA after PEPOCH or last TOA before PEPOCH. This may leave your residuals with an offset."
142+
)
140143
self.TZRMJD.quantity = TZRMJD.value
141144
self.setup()

src/pint/residuals.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,17 @@ def calc_time_mean(
500500
"""
501501
return self._calc_mean(weighted, "time", calctype=calctype)
502502

503+
def zero_TZR(self, use_weighted_mean: Optional[bool] = True) -> None:
504+
"""
505+
Remove any net offset from the TOAs by subtracting the mean residual from TZRMJD
506+
507+
Parameters
508+
----------
509+
use_weighted_mean : bool or None, optional
510+
Whether to use weighted mean for mean subtraction.
511+
"""
512+
self.model.TZRMJD.quantity += self.calc_time_mean(weighted=use_weighted_mean)
513+
503514
def calc_time_resids(
504515
self,
505516
calctype: Literal["taylor", "modelF0", "numerical"] = "taylor",

tests/test_absphase.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
import os
33
import pytest
44

5+
from astropy import units as u
56
import pint.models
67
import pint.toa
8+
import pint.residuals
9+
import pint.simulation
710
from pinttestdata import datadir
811

912
parfile = os.path.join(datadir, "NGC6440E.par")
@@ -28,3 +31,14 @@ def test_tzr_attr():
2831

2932
assert not toas.tzr
3033
assert model.components["AbsPhase"].get_TZR_toa(toas).tzr
34+
35+
36+
def test_zero_TZR():
37+
model = pint.models.get_model(parfile)
38+
toas = pint.simulation.make_fake_toas_uniform(50000, 51000, 20, model=model)
39+
toas.adjust_TOAs(10 * u.s)
40+
r = pint.residuals.Residuals(toas, model)
41+
assert r.calc_time_mean() > 9 * u.s
42+
r.zero_TZR()
43+
r.update()
44+
assert r.calc_time_mean() < 1 * u.ms

0 commit comments

Comments
 (0)