Skip to content

Commit

Permalink
to_value
Browse files Browse the repository at this point in the history
  • Loading branch information
abhisrkckl committed Sep 25, 2023
1 parent b506825 commit 007df39
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 25 deletions.
22 changes: 11 additions & 11 deletions src/pint/fitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ def get_derived_params(self):
tasc = ufloat(
# This is a time in MJD
self.model.TASC.quantity.mjd,
self.model.TASC.uncertainty.to(u.d).value,
self.model.TASC.uncertainty.to_value(u.d),
)
if hasattr(self.model, "PB") and self.model.PB.value is not None:
pb = self.model.PB.as_ufloat(u.d)
Expand Down Expand Up @@ -578,8 +578,8 @@ def get_derived_params(self):
pberr = pberr.to(u.d) if btx else self.model.PB.uncertainty
if not self.model.A1.frozen:
pbs = ufloat(
pb.to(u.s).value,
pberr.to(u.s).value,
pb.to_value(u.s),
pberr.to_value(u.s),
)
a1 = self.model.A1.as_ufloat(pint.ls)
# This is the mass function, done explicitly so that we get
Expand Down Expand Up @@ -1289,8 +1289,8 @@ def step(self):
toas=self.fitter.toas, incfrozen=False, incoffset=True
)
# Get residuals and TOA uncertainties in seconds
Nvec = self.model.scaled_toa_uncertainty(self.fitter.toas).to(u.s).value
scaled_resids = self.resids.time_resids.to(u.s).value / Nvec
Nvec = self.model.scaled_toa_uncertainty(self.fitter.toas).to_value(u.s)
scaled_resids = self.resids.time_resids.to_value(u.s) / Nvec

# "Whiten" design matrix and residuals by dividing by uncertainties
M = M / Nvec.reshape((-1, 1))
Expand Down Expand Up @@ -1442,7 +1442,7 @@ def step(self):
covariance_matrix_labels = [covariance_matrix_labels] * 2
self.parameter_covariance_matrix_labels = covariance_matrix_labels

residuals = self.resids.time_resids.to(u.s).value
residuals = self.resids.time_resids.to_value(u.s)

# get any noise design matrices and weight vectors
if not self.full_cov:
Expand Down Expand Up @@ -1470,7 +1470,7 @@ def step(self):
phiinv /= norm**2
# Why are we scaling residuals by the *square* of the uncertainty?
Nvec = (
self.model.scaled_toa_uncertainty(self.fitter.toas).to(u.s).value ** 2
self.model.scaled_toa_uncertainty(self.fitter.toas).to_value(u.s) ** 2
)
cinv = 1 / Nvec
mtcm = np.dot(M.T, cinv[:, None] * M)
Expand Down Expand Up @@ -1989,8 +1989,8 @@ def fit_toas(self, maxiter=1, threshold=None, debug=False):
M, params, units = self.get_designmatrix()
# Get residuals and TOA uncertainties in seconds
self.update_resids()
residuals = self.resids.time_resids.to(u.s).value
Nvec = self.model.scaled_toa_uncertainty(self.toas).to(u.s).value
residuals = self.resids.time_resids.to_value(u.s)
Nvec = self.model.scaled_toa_uncertainty(self.toas).to_value(u.s)

# "Whiten" design matrix and residuals by dividing by uncertainties
M = M / Nvec.reshape((-1, 1))
Expand Down Expand Up @@ -2161,7 +2161,7 @@ def fit_toas(self, maxiter=1, threshold=0, full_cov=False, debug=False):
if i == 0:
# Why is this here?
self.update_resids()
residuals = self.resids.time_resids.to(u.s).value
residuals = self.resids.time_resids.to_value(u.s)

# get any noise design matrices and weight vectors
if not full_cov:
Expand All @@ -2188,7 +2188,7 @@ def fit_toas(self, maxiter=1, threshold=0, full_cov=False, debug=False):

else:
phiinv /= norm**2
Nvec = self.model.scaled_toa_uncertainty(self.toas).to(u.s).value ** 2
Nvec = self.model.scaled_toa_uncertainty(self.toas).to_value(u.s) ** 2
cinv = 1 / Nvec
mtcm = np.dot(M.T, cinv[:, None] * M)
mtcm += np.diag(phiinv)
Expand Down
4 changes: 3 additions & 1 deletion src/pint/pint_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,9 @@ def __call__(self, data, model, derivative_params, offset=True, offset_padding=1
else:
param_unit = getattr(model, param).units
# Since this is the phase derivative, we know the quantity unit.
q = deriv_func(data, delay, param).to(u.Unit("") / param_unit)
q = deriv_func(data, delay, param).to(
u.dimensionless_unscaled / param_unit
)

# NOTE Here we have negative sign here. Since in pulsar timing
# the residuals are calculated as (Phase - int(Phase)), which is different
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 @@ -45,7 +45,7 @@ def phaseogram(
else:
mjds = mjds_in

years = (mjds.to(u.d).value - 51544.0) / 365.25 + 2000.0
years = (mjds.to_value(u.d) - 51544.0) / 365.25 + 2000.0
phss = phases + rotate
phss[phss >= 1.0] -= 1.0
plt.figure(figsize=(width, 8))
Expand Down Expand Up @@ -133,7 +133,7 @@ def phaseogram_binned(
else:
mjds = mjds_in

years = (mjds.to(u.d).value - 51544.0) / 365.25 + 2000.0
years = (mjds.to_value(u.d) - 51544.0) / 365.25 + 2000.0
phss = phases + rotate
phss[phss >= 1.0] -= 1.0
plt.figure(figsize=(width, 8))
Expand Down
4 changes: 2 additions & 2 deletions src/pint/residuals.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ def _calc_gls_chi2(self):
If the system is singular, it uses singular value decomposition instead."""
self.update()

residuals = self.time_resids.to(u.s).value
residuals = self.time_resids.to_value(u.s)

M = self.model.noise_model_designmatrix(self.toas)
phi = self.model.noise_model_basis_weight(self.toas)
Expand All @@ -520,7 +520,7 @@ def _calc_gls_chi2(self):
M, norm = normalize_designmatrix(M, None)

phiinv /= norm**2
Nvec = self.model.scaled_toa_uncertainty(self.toas).to(u.s).value ** 2
Nvec = self.model.scaled_toa_uncertainty(self.toas).to_value(u.s) ** 2
cinv = 1 / Nvec
mtcm = np.dot(M.T, cinv[:, None] * M)
mtcm += np.diag(phiinv)
Expand Down
16 changes: 8 additions & 8 deletions src/pint/toa.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ def format_toa_line(
freq = 0.0 * u.MHz
flagstring = ""
if dm != 0.0 * pint.dmu:
flagstring += "-dm {:.5f}".format(dm.to(pint.dmu).value)
flagstring += "-dm {:.5f}".format(dm.to_value(pint.dmu))
# Here I need to append any actual flags
for flag in flags.keys():
v = flags[flag]
Expand All @@ -651,9 +651,9 @@ def format_toa_line(
obscode = obs.name
out = "%s %f %s %.3f %s %s\n" % (
name,
freq.to(u.MHz).value,
freq.to_value(u.MHz),
toa_str,
toaerr.to(u.us).value,
toaerr.to_value(u.us),
alias_translation.get(obscode, obscode),
flagstring,
)
Expand All @@ -677,17 +677,17 @@ def format_toa_line(
if dm != 0.0 * pint.dmu:
out = obs.tempo_code + " %13s%9.3f%20s%9.2f %9.4f\n" % (
name,
freq.to(u.MHz).value,
freq.to_value(u.MHz),
toa_str,
toaerr.to(u.us).value,
dm.to(pint.dmu).value,
toaerr.to_value(u.us),
dm.to_value(pint.dmu),
)
else:
out = obs.tempo_code + " %13s%9.3f%20s%9.2f\n" % (
name,
freq.to(u.MHz).value,
freq.to_value(u.MHz),
toa_str,
toaerr.to(u.us).value,
toaerr.to_value(u.us),
)
else:
raise ValueError(f"Unknown TOA format ({format})")
Expand Down
2 changes: 1 addition & 1 deletion src/pint/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2476,7 +2476,7 @@ def divide_times(t, t0, offset=0.5):
"""
dt = t - t0
values = (dt.to(u.yr).value + offset) // 1
values = (dt.to_value(u.yr) + offset) // 1
indices = np.digitize(values, np.unique(values), right=True)
return indices

Expand Down

0 comments on commit 007df39

Please sign in to comment.