Skip to content

Commit

Permalink
Merge branch 'master' into np.compat
Browse files Browse the repository at this point in the history
  • Loading branch information
dlakaplan authored Mar 14, 2024
2 parents a4585f2 + 870f340 commit 8468a18
Show file tree
Hide file tree
Showing 10 changed files with 218 additions and 160 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ the released changes.
- `TimingModel.compare()` now calls `change_binary_epoch()`.
- When clock files contain out-of-order entries, the exception now records the first MJDs that are out of order
- `np.compat.long` -> `int` (former is deprecated)
- Turned ErfaWarning into an exception during testing; cleaned up test suite.
### Added
- Added numdifftools to setup.cfg to match requirements.txt
- Documentation: Added `convert_parfile` to list of command-line tools in RTD
Expand Down
3 changes: 3 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pytest]
filterwarnings =
error::erfa.ErfaWarning
1 change: 1 addition & 0 deletions src/pint/data/runtime/observatories.json
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,7 @@
"leap2effix.clk",
"effix2gps.clk"
],
"bogus_last_correction": true,
"fullname": "The Large European Array for Pulsars",
"origin": "This is the same as the position of the Effelsberg radio telescope.\nImported from TEMPO2 observatories.dat 2021 June 7."
},
Expand Down
8 changes: 5 additions & 3 deletions src/pint/models/astrometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,9 +801,11 @@ def get_psr_coords(self, epoch=None):
epoch if isinstance(epoch, Time) else Time(epoch, scale="tdb", format="mjd")
)
position_now = add_dummy_distance(self.get_psr_coords())
return remove_dummy_distance(
position_now.apply_space_motion(new_obstime=newepoch)
)
with warnings.catch_warnings():
# This is a fake position, no point ERFA warning the user it's bogus
warnings.filterwarnings("ignore", r".*distance overridden", ErfaWarning)
position_then = position_now.apply_space_motion(new_obstime=newepoch)
return remove_dummy_distance(position_then)

def coords_as_ICRS(self, epoch=None):
"""Return the pulsar's ICRS coordinates as an astropy coordinate object."""
Expand Down
4 changes: 4 additions & 0 deletions src/pint/observatory/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,13 @@ def _load_bipm_clock(bipm_version):
try:
log.info(f"Loading BIPM clock version {bipm_version}")
# FIXME: error handling?
# FIXME: BIPM2019 and earlier come fromm the TEMPO2 repository and have a bogus last correction
# later ones are generated and don't; how to manage this?
bogus_last_correction = bipm_version.lower() <= "bipm2019"
_bipm_clock_versions[bipm_version] = find_clock_file(
f"tai2tt_{bipm_version}.clk",
format="tempo2",
bogus_last_correction=bogus_last_correction,
)
except Exception as e:
raise ValueError(
Expand Down
31 changes: 20 additions & 11 deletions src/pint/observatory/clock_file.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"""Routines for reading and writing various formats of clock file."""

import re
import warnings
from pathlib import Path
from textwrap import dedent
from warnings import warn

import astropy.units as u
import erfa
import numpy as np
from loguru import logger as log

Expand Down Expand Up @@ -522,16 +524,22 @@ def add_comment(s):
mjd = mjd[1:]
clk = clk[1:]
comments = comments[1:]
return ClockFile(
mjd,
clk * u.s,
filename=filename,
comments=comments,
leading_comment=leading_comment,
header=header,
friendly_name=friendly_name,
valid_beyond_ends=valid_beyond_ends,
)
with warnings.catch_warnings():
# Some clock files have dubious years in them
# Most are removed by automatically ignoring MJD 0, or with "bogus_last_correction"
# But Parkes incudes a non-zero correction for MJD 0 so it isn't removed
# In any case, the user doesn't need a warning about strange years in clock files
warnings.filterwarnings("ignore", r".*dubious year", erfa.ErfaWarning)
return ClockFile(
mjd,
clk * u.s,
filename=filename,
comments=comments,
leading_comment=leading_comment,
header=header,
friendly_name=friendly_name,
valid_beyond_ends=valid_beyond_ends,
)


ClockFile._formats["tempo2"] = read_tempo2_clock_file
Expand Down Expand Up @@ -865,7 +873,8 @@ def evaluate(self, t, limits="warn"):
corrections : astropy.units.Quantity
The corrections in units of microseconds.
"""
if np.any(t > self.clock_file.time[-1]):
needs_update = np.any(t > self.clock_file.time[-1])
if needs_update:
self.update()
return self.clock_file.evaluate(t, limits=limits)

Expand Down
1 change: 1 addition & 0 deletions src/pint/pulsar_mjd.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
.. _leap_smear: https://developers.google.com/time/smear
"""
import warnings

import erfa
import astropy.time
Expand Down
65 changes: 29 additions & 36 deletions tests/test_astrometry.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import os.path
from io import StringIO
from packaging import version

import astropy.units as u
import erfa
import hypothesis.strategies as st
import numpy as np
import pytest
from astropy.coordinates import Latitude, Longitude

from hypothesis import example, given
from pint.models import get_model
from pinttestdata import datadir

Expand Down Expand Up @@ -98,7 +101,6 @@ def test_pm_one_set_other_not():
CLK UTC(NIST)
UNITS TDB
TIMEEPH FB90
T2CMETHOD TEMPO
CORRECT_TROPOSPHERE N
PLANET_SHAPIRO N
DILATEFREQ N
Expand All @@ -108,19 +110,16 @@ def test_pm_one_set_other_not():
"""


ntests = 200


@pytest.mark.parametrize(
("ra,dec,pmra,pmdec"),
list(
zip(
np.random.uniform(0, 360, ntests),
np.random.uniform(-90, 90, ntests),
np.random.normal(0, scale=10, size=ntests),
np.random.normal(0, scale=10, size=ntests),
)
),
@given(
st.floats(0, 360),
st.floats(-89.9, 89.9),
st.floats(0, 10),
st.floats(0, 10),
)
@example(ra=1.0, dec=1.0, pmra=2.0, pmdec=4.345847379899e-311)
@pytest.mark.xfail(
version.parse(erfa.__version__) < version.parse("2.0.1"),
reason="Old version of pyerfa had a bug",
)
def test_ssb_accuracy_ICRS(ra, dec, pmra, pmdec):
m = get_model(StringIO(parICRS), RAJ=ra, DECJ=dec, PMRA=pmra, PMDEC=pmdec)
Expand All @@ -147,7 +146,6 @@ def test_ssb_accuracy_ICRS(ra, dec, pmra, pmdec):
CLK UTC(NIST)
UNITS TDB
TIMEEPH FB90
T2CMETHOD TEMPO
CORRECT_TROPOSPHERE N
PLANET_SHAPIRO N
DILATEFREQ N
Expand All @@ -157,16 +155,11 @@ def test_ssb_accuracy_ICRS(ra, dec, pmra, pmdec):
"""


@pytest.mark.parametrize(
("elong,elat,pmelong,pmelat"),
list(
zip(
np.random.uniform(0, 360, ntests),
np.random.uniform(-90, 90, ntests),
np.random.normal(0, scale=10, size=ntests),
np.random.normal(0, scale=10, size=ntests),
)
),
@given(
st.floats(0, 360),
st.floats(-89.9, 89.9),
st.floats(0, 10),
st.floats(0, 10),
)
def test_ssb_accuracy_ICRS_ECLmodel(elong, elat, pmelong, pmelat):
m = get_model(
Expand All @@ -180,16 +173,16 @@ def test_ssb_accuracy_ICRS_ECLmodel(elong, elat, pmelong, pmelat):
assert np.allclose(xyznew, xyzastropy)


@pytest.mark.parametrize(
("elong,elat,pmelong,pmelat"),
list(
zip(
np.random.uniform(0, 360, ntests),
np.random.uniform(-90, 90, ntests),
np.random.normal(0, scale=10, size=ntests),
np.random.normal(0, scale=10, size=ntests),
)
),
@given(
st.floats(0, 360),
st.floats(-89.9, 89.9),
st.floats(0, 10),
st.floats(0, 10),
)
@example(1.0, 1.0, 0.5, 4.345847379899e-311)
@pytest.mark.xfail(
version.parse(erfa.__version__) < version.parse("2.0.1"),
reason="Old version of pyerfa had a bug",
)
def test_ssb_accuracy_ECL_ECLmodel(elong, elat, pmelong, pmelat):
m = get_model(
Expand Down
Loading

0 comments on commit 8468a18

Please sign in to comment.