From 007df395076d682922e08a627671a9962db946cf Mon Sep 17 00:00:00 2001 From: Abhimanyu Susobhanan Date: Mon, 25 Sep 2023 10:26:52 -0500 Subject: [PATCH] to_value --- src/pint/fitter.py | 22 +++++++++++----------- src/pint/pint_matrix.py | 4 +++- src/pint/plot_utils.py | 4 ++-- src/pint/residuals.py | 4 ++-- src/pint/toa.py | 16 ++++++++-------- src/pint/utils.py | 2 +- 6 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/pint/fitter.py b/src/pint/fitter.py index 61bcd9532..ef58758d4 100644 --- a/src/pint/fitter.py +++ b/src/pint/fitter.py @@ -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) @@ -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 @@ -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)) @@ -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: @@ -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) @@ -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)) @@ -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: @@ -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) diff --git a/src/pint/pint_matrix.py b/src/pint/pint_matrix.py index 1900249ff..ad6aac88b 100644 --- a/src/pint/pint_matrix.py +++ b/src/pint/pint_matrix.py @@ -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 diff --git a/src/pint/plot_utils.py b/src/pint/plot_utils.py index e95dae99e..0d5b96426 100644 --- a/src/pint/plot_utils.py +++ b/src/pint/plot_utils.py @@ -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)) @@ -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)) diff --git a/src/pint/residuals.py b/src/pint/residuals.py index 52c75d2ea..2977e9f19 100644 --- a/src/pint/residuals.py +++ b/src/pint/residuals.py @@ -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) @@ -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) diff --git a/src/pint/toa.py b/src/pint/toa.py index 682ca60ce..2731a649e 100644 --- a/src/pint/toa.py +++ b/src/pint/toa.py @@ -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] @@ -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, ) @@ -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})") diff --git a/src/pint/utils.py b/src/pint/utils.py index 785ae36be..a1c505648 100644 --- a/src/pint/utils.py +++ b/src/pint/utils.py @@ -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