Skip to content

Commit

Permalink
Merge branch 'master' into removepar
Browse files Browse the repository at this point in the history
  • Loading branch information
dlakaplan authored Jun 26, 2024
2 parents 605b653 + ebc27d2 commit 3e7c35d
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 23 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ the released changes.
- The following observatories no longer have a default of `include_bipm=False`: magic, lst, virgo, lho, llo, geo600, kagra, hess, hawc
- New algorithm for TCB <-> TDB conversion
- Reordered plotting axes in `pintk`
- Changed `scipy.integrate.simps` to `scipy.integrate.simpson` to work with scipy 1.14
### Added
- `bayesian_information_criterion()` function
- `dmx_setup` function
Expand All @@ -44,4 +45,5 @@ the released changes.
- Fixed bug in residual calculation when adding or removing phase wraps
- Fix #1766 by correcting logic and more clearly naming argument (clkcorr->undo_clkcorr)
- Fix removal of top-level parameter
- Minimal fixes to allow usage of numpy 2.0
### Removed
10 changes: 6 additions & 4 deletions src/pint/fitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,11 @@ def get_derived_params(self, returndict=False):
"""

return self.model.get_derived_params(
rms=self.resids.toa.rms_weighted()
if self.is_wideband
else self.resids.rms_weighted(),
rms=(
self.resids.toa.rms_weighted()
if self.is_wideband
else self.resids.rms_weighted()
),
ntoas=self.toas.ntoas,
returndict=returndict,
)
Expand Down Expand Up @@ -1242,7 +1244,7 @@ def _mloglike(xs):
for fp, x in zip(free_noise_params, xs):
getattr(res.model, fp).value = x

return -res.lnlikelihood()
return -res.lnlikelihood().astype(np.float64)

if not res.model.has_correlated_errors:

Expand Down
4 changes: 2 additions & 2 deletions src/pint/models/model_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -1081,14 +1081,14 @@ def convert_binary_params_dict(
log.debug("Converting KIN to/from IAU <--> DT96")
entries = parfile_dict["KIN"][0].split()
new_value = _convert_kin(float(entries[0]) * u.deg).value
parfile_dict["KIN"] = [" ".join([repr(new_value)] + entries[1:])]
parfile_dict["KIN"] = [" ".join([str(new_value)] + entries[1:])]

# Convert KOM if requested
if convert_komkin and "KOM" in parfile_dict:
log.debug("Converting KOM to/from IAU <--> DT96")
entries = parfile_dict["KOM"][0].split()
new_value = _convert_kom(float(entries[0]) * u.deg).value
parfile_dict["KOM"] = [" ".join([repr(new_value)] + entries[1:])]
parfile_dict["KOM"] = [" ".join([str(new_value)] + entries[1:])]

# Drop SINI if requested
if drop_ddk_sini and binary_model_guesses[0] == "DDK":
Expand Down
2 changes: 1 addition & 1 deletion src/pint/models/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def _return_frequency_asquantity(f):
astropy.units.Quantity
"""

return u.Quantity(f, u.MHz, copy=False)
return f << u.MHz


class Parameter:
Expand Down
4 changes: 2 additions & 2 deletions src/pint/plot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@ def phaseogram_binned(
ax2.scatter(phss, mjds, s=size, color=colarray)
ax2.scatter(phss + 1.0, mjds, s=size, color=colarray)
else:
profile = np.zeros(bins, dtype=np.float_)
profile = np.zeros(bins, dtype=np.float64)
ntoa = 64
toadur = (mjds.max() - mjds.min()) / ntoa
mjdstarts = mjds.min() + toadur * np.arange(ntoa, dtype=np.float_)
mjdstarts = mjds.min() + toadur * np.arange(ntoa, dtype=np.float64)
mjdstops = mjdstarts + toadur
# Loop over blocks to process
a = []
Expand Down
3 changes: 2 additions & 1 deletion 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
Expand Down Expand Up @@ -352,7 +353,7 @@ def quantity2longdouble_withunit(data):

def longdouble2str(x):
"""Convert numpy longdouble to string."""
return repr(x)
return str(x)


def str2longdouble(str_data):
Expand Down
2 changes: 1 addition & 1 deletion src/pint/scripts/event_optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def profile_likelihood(phs, *otherargs):
Likelihood is calculated as per eqn 2 in Pletsch & Clark 2015.
"""
xvals, phases, template, weights = otherargs
phss = phases.astype(np.float64) + phs
phss = phases.astype(np.float64) + phs.astype(np.float64)
phss %= 1
probs = np.interp(phss, xvals, template, right=template[0])
if weights is None:
Expand Down
11 changes: 9 additions & 2 deletions src/pint/templates/lcprimitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@
from math import atan, cosh, tan

import numpy as np
from scipy.integrate import quad, simps
from scipy.integrate import quad

try:
from scipy.integrate import simpson
except ImportError:
# for old versions of scipy that don't have simpson
# this change was made in 1.6.0, so if we support older versions we need this
from scipy.integrate import simps as simpson
from scipy.interpolate import interp1d
from scipy.special import erf, i0, i1, owens_t
from scipy.stats import cauchy, norm, vonmises, skewnorm
Expand Down Expand Up @@ -1593,7 +1600,7 @@ def integrate(self, x1=0, x2=1):
x = self.interpolator.x
y = self.interpolator.y
mask = (x >= x1) & (x <= x2)
return simps(y[mask], x=x[mask])
return simpson(y[mask], x=x[mask])
# return self.interpolator.y[mask].sum()/len(mask)


Expand Down
4 changes: 2 additions & 2 deletions src/pint/toa.py
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ def check_allowed_key(k: Any) -> None:
def check_allowed_value(k: str, v: Any) -> None:
if not isinstance(v, str):
raise ValueError(f"value {v} for key {k} must be a string")
if not v and len(v.split()) != 1:
if len(v.split()) != 1:
raise ValueError(f"value {repr(v)} for key {k} cannot contain whitespace")

def __setitem__(self, key: str, val: str):
Expand Down Expand Up @@ -1601,7 +1601,7 @@ def ntoas(self) -> int:
@property
def observatories(self) -> Set[str]:
"""The set of observatories in use by these TOAs."""
return set(self.get_obss())
return set([str(x) for x in self.get_obss()])

@property
def first_MJD(self) -> time.Time:
Expand Down
20 changes: 14 additions & 6 deletions tests/test_model_derivatives.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def f(value):
dphase = m.phase(toas, abs_phase=False) - phase
except ValueError:
return np.nan * np.zeros_like(phase.frac)
return dphase.int + dphase.frac
return np.float64(dphase.int + dphase.frac)

if param == "ECC":
e = model.ECC.value
Expand All @@ -163,19 +163,27 @@ def f(value):
h3 = model.H3.value
stepgen = numdifftools.MaxStepGenerator(abs(h3) / 2)
elif param == "FB0":
stepgen = numdifftools.MaxStepGenerator(np.abs(model.FB0.value) * 1e-2)
stepgen = numdifftools.MaxStepGenerator(
np.abs(model.FB0.value.astype(np.float64)) * 1e-2
)
elif param == "FB1":
stepgen = numdifftools.MaxStepGenerator(np.abs(model.FB1.value) * 1e3)
stepgen = numdifftools.MaxStepGenerator(
np.abs(model.FB1.value.astype(np.float64)) * 1e3
)
elif param == "FB2":
stepgen = numdifftools.MaxStepGenerator(np.abs(model.FB2.value) * 1e5)
stepgen = numdifftools.MaxStepGenerator(
np.abs(model.FB2.value.astype(np.float64)) * 1e5
)
elif param == "FB3":
stepgen = numdifftools.MaxStepGenerator(np.abs(model.FB3.value) * 1e7)
stepgen = numdifftools.MaxStepGenerator(
np.abs(model.FB3.value.astype(np.float64)) * 1e7
)
else:
stepgen = None
df = numdifftools.Derivative(f, step=stepgen)

a = model.d_phase_d_param(toas, delay=None, param=param).to_value(1 / units)
b = df(getattr(model, param).value)
b = df(getattr(model, param).value.astype(np.float64))
if param.startswith("FB"):
assert np.amax(np.abs(a - b)) / np.amax(np.abs(a) + np.abs(b)) < 1.5e-6
else:
Expand Down
3 changes: 1 addition & 2 deletions tests/test_precision.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,10 @@ def test_longdouble_str_roundtrip_is_exact(i_f):


@given(any_mjd())
def test_longdouble2str_same_as_str_and_repr(i_f):
def test_longdouble2str_same_as_str(i_f):
i, f = i_f
ld = np.longdouble(i) + np.longdouble(f)
assert longdouble2str(ld) == str(ld)
assert longdouble2str(ld) == repr(ld)


@pytest.mark.parametrize("s", ["1.0.2", "1.0.", "1.0e1e0", "twelve"])
Expand Down

0 comments on commit 3e7c35d

Please sign in to comment.