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 007df39 commit 2186fbb
Show file tree
Hide file tree
Showing 17 changed files with 58 additions and 54 deletions.
6 changes: 3 additions & 3 deletions src/pint/models/astrometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def solar_system_geometric_delay(self, toas, acc_delay=None):
if np.any(c):
L_hat = self.ssb_to_psb_xyz_ICRS(epoch=tbl["tdbld"][c].astype(np.float64))
re_dot_L = np.sum(tbl["ssb_obs_pos"][c] * L_hat, axis=1)
delay[c] = -re_dot_L.to(ls).value
delay[c] = -re_dot_L.to_value(ls)
if self.PX.value != 0.0:
L = (1.0 / self.PX.value) * u.kpc
# TODO: np.sum currently loses units in some cases...
Expand All @@ -153,8 +153,8 @@ def solar_system_geometric_delay(self, toas, acc_delay=None):
* tbl["ssb_obs_pos"].unit ** 2
)
delay[c] += (
(0.5 * (re_sqr / L) * (1.0 - re_dot_L**2 / re_sqr)).to(ls).value
)
0.5 * (re_sqr / L) * (1.0 - re_dot_L**2 / re_sqr)
).to_value(ls)
return delay * u.second

def get_d_delay_quantities(self, toas, include="all"):
Expand Down
2 changes: 1 addition & 1 deletion src/pint/models/binary_ell1.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def change_binary_epoch(self, new_epoch):
tasc_ld = self.TASC.quantity.tdb.mjd_long
dt = (new_epoch.tdb.mjd_long - tasc_ld) * u.day
d_orbits = dt / PB - PBDOT * dt**2 / (2.0 * PB**2)
n_orbits = np.round(d_orbits.to(u.Unit("")))
n_orbits = np.round(d_orbits.to(u.dimensionless_unscaled))
if n_orbits == 0:
return
dt_integer_orbits = PB * n_orbits + PB * PBDOT * n_orbits**2 / 2.0
Expand Down
2 changes: 1 addition & 1 deletion src/pint/models/dispersion_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def d_dm_d_DMs(
else:
DMEPOCH = self.DMEPOCH.value
dt = (toas["tdbld"] - DMEPOCH) * u.day
dt_value = (dt.to(u.yr)).value
dt_value = dt.to_value(u.yr)
return taylor_horner(dt_value, dm_terms) * (self.DM.units / par.units)

def change_dmepoch(self, new_epoch):
Expand Down
4 changes: 2 additions & 2 deletions src/pint/models/fdjump.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ def get_freq_y(self, toas):
freq = tbl["freq"]

y = (
np.log(freq.to(u.GHz).value)
np.log(freq.to_value(u.GHz))
if self.FDJUMPLOG.value
else freq.to(u.GHz).value
else freq.to_value(u.GHz)
)
non_finite = np.invert(np.isfinite(y))
y[non_finite] = 0.0
Expand Down
2 changes: 1 addition & 1 deletion src/pint/models/frequency_dependent.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def FD_delay(self, toas, acc_delay=None):
def FD_delay_frequency(self, freq):
"""Compute the FD delay at an array of frequencies."""
FD_mapping = self.get_prefix_mapping_component("FD")
log_freq = np.log(freq.to(u.GHz).value)
log_freq = np.log(freq.to_value(u.GHz))
non_finite = np.invert(np.isfinite(log_freq))
log_freq[non_finite] = 0.0
FD_coeff = [
Expand Down
2 changes: 1 addition & 1 deletion src/pint/models/ifunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def ifunc_phase(self, toas, delays):
# the MJDs(x) and offsets (y) of the interpolation points
x, y = np.asarray([t.quantity for t in terms]).T
# form barycentered times
ts = toas.table["tdbld"] - delays.to(u.day).value
ts = toas.table["tdbld"] - delays.to_value(u.day)
times = np.zeros(len(ts))

# Determine what type of interpolation we are doing.
Expand Down
16 changes: 8 additions & 8 deletions src/pint/models/noise_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def scale_toa_sigma(self, toas):
return sigma_scaled

def sigma_scaled_cov_matrix(self, toas):
scaled_sigma = self.scale_toa_sigma(toas).to(u.s).value ** 2
scaled_sigma = self.scale_toa_sigma(toas).to_value(u.s) ** 2
return np.diag(scaled_sigma)


Expand Down Expand Up @@ -337,7 +337,7 @@ def get_noise_basis(self, toas):
A quantization matrix maps TOAs to observing epochs.
"""
tbl = toas.table
t = (tbl["tdbld"].quantity * u.day).to(u.s).value
t = (tbl["tdbld"].quantity * u.day).to_value(u.s)
ecorrs = self.get_ecorrs()
umats = []
for ec in ecorrs:
Expand All @@ -363,15 +363,15 @@ def get_noise_weights(self, toas, nweights=None):
"""
ecorrs = self.get_ecorrs()
if nweights is None:
ts = (toas.table["tdbld"].quantity * u.day).to(u.s).value
ts = (toas.table["tdbld"].quantity * u.day).to_value(u.s)
nweights = [
get_ecorr_nweights(ts[ec.select_toa_mask(toas)]) for ec in ecorrs
]
nc = sum(nweights)
weights = np.zeros(nc)
nctot = 0
for ec, nn in zip(ecorrs, nweights):
weights[nctot : nn + nctot] = ec.quantity.to(u.s).value ** 2
weights[nctot : nn + nctot] = ec.quantity.to_value(u.s) ** 2
nctot += nn
return weights

Expand Down Expand Up @@ -462,7 +462,7 @@ def get_noise_basis(self, toas):
See the documentation for pl_dm_basis_weight_pair function for details."""

tbl = toas.table
t = (tbl["tdbld"].quantity * u.day).to(u.s).value
t = (tbl["tdbld"].quantity * u.day).to_value(u.s)
freqs = self._parent.barycentric_radio_freq(toas).to(u.MHz)
fref = 1400 * u.MHz
D = (fref.value / freqs.value) ** 2
Expand All @@ -476,7 +476,7 @@ def get_noise_weights(self, toas):
See the documentation for pl_dm_basis_weight_pair for details."""

tbl = toas.table
t = (tbl["tdbld"].quantity * u.day).to(u.s).value
t = (tbl["tdbld"].quantity * u.day).to_value(u.s)
amp, gam, nf = self.get_pl_vals()
Ffreqs = get_rednoise_freqs(t, nf)
return powerlaw(Ffreqs, amp, gam) * Ffreqs[0]
Expand Down Expand Up @@ -592,7 +592,7 @@ def get_noise_basis(self, toas):
See the documentation for pl_rn_basis_weight_pair function for details."""

tbl = toas.table
t = (tbl["tdbld"].quantity * u.day).to(u.s).value
t = (tbl["tdbld"].quantity * u.day).to_value(u.s)
nf = self.get_pl_vals()[2]
return create_fourier_design_matrix(t, nf)

Expand All @@ -602,7 +602,7 @@ def get_noise_weights(self, toas):
See the documentation for pl_rn_basis_weight_pair for details."""

tbl = toas.table
t = (tbl["tdbld"].quantity * u.day).to(u.s).value
t = (tbl["tdbld"].quantity * u.day).to_value(u.s)
amp, gam, nf = self.get_pl_vals()
Ffreqs = get_rednoise_freqs(t, nf)
return powerlaw(Ffreqs, amp, gam) * Ffreqs[0]
Expand Down
14 changes: 7 additions & 7 deletions src/pint/models/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ def _print_uncertainty(self, uncertainty):
This converts the :class:`~astropy.units.Quantity` provided to the
appropriate units, extracts the value, and converts that to a string.
"""
return str(uncertainty.to(self.units).value)
return str(uncertainty.to_value(self.units))

def __repr__(self):
out = "{0:16s}{1:20s}".format(f"{self.__class__.__name__}(", self.name)
Expand Down Expand Up @@ -783,7 +783,7 @@ def _set_uncertainty(self, val):

def str_quantity(self, quan):
"""Quantity as a string (for floating-point values)."""
v = quan.to(self.units).value
v = quan.to_value(self.units)
if self._long_double and not isinstance(v, np.longdouble):
raise ValueError(
"Parameter is supposed to contain long double values but contains a float"
Expand All @@ -798,9 +798,9 @@ def _get_value(self, quan):
return quan
elif isinstance(quan, list):
# for pairParamters
return [x.to(self.units).value for x in quan]
return [x.to_value(self.units) for x in quan]
else:
return quan.to(self.units).value
return quan.to_value(self.units)

def as_ufloat(self, units=None):
"""Return the parameter as a :class:`uncertainties.ufloat`
Expand Down Expand Up @@ -1606,7 +1606,7 @@ def str_quantity(self, quan):
return self.param_comp.str_quantity(quan)

def _print_uncertainty(self, uncertainty):
return str(uncertainty.to(self.units).value)
return str(uncertainty.to_value(self.units))

def name_matches(self, name):
return self.param_comp.name_matches(name)
Expand Down Expand Up @@ -2239,8 +2239,8 @@ def str_quantity(self, quan):
if len(quan) != 2:
raise ValueError(f"Don't know how to print this as a pair: {quan}")

v0 = quan[0].to(self.units).value
v1 = quan[1].to(self.units).value
v0 = quan[0].to_value(self.units)
v1 = quan[1].to_value(self.units)
if self._long_double:
if not isinstance(v0, np.longdouble):
raise TypeError(
Expand Down
2 changes: 1 addition & 1 deletion src/pint/models/pulsar_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ def change_binary_epoch(self, new_epoch):
t0_ld = self.T0.quantity.tdb.mjd_long
dt = (new_epoch.tdb.mjd_long - t0_ld) * u.day
d_orbits = dt / PB - PBDOT * dt**2 / (2.0 * PB**2)
n_orbits = np.round(d_orbits.to(u.Unit("")))
n_orbits = np.round(d_orbits.to(u.dimensionless_unscaled))
if n_orbits == 0:
return
dt_integer_orbits = PB * n_orbits + PB * PBDOT * n_orbits**2 / 2.0
Expand Down
18 changes: 11 additions & 7 deletions src/pint/models/stand_alone_psr_binaries/DDK_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,31 +175,35 @@ def kin(self):

def d_SINI_d_KIN(self):
# with u.set_enabled_equivalencies(u.dimensionless_angles()):
return np.cos(self.kin()).to(u.Unit("") / self.KIN.unit)
return np.cos(self.kin()).to(u.dimensionless_unscaled / self.KIN.unit)

def d_SINI_d_KOM(self):
if not self.K96:
return np.cos(self.kin()) * u.Unit("") / self.KOM.unit
return np.cos(self.kin()) * u.dimensionless_unscaled / self.KOM.unit
d_si_d_kom = (
(-self.PMLONG_DDK * self.cos_KOM - self.PMLAT_DDK * self.sin_KOM)
* self.tt0
* np.cos(self.kin())
)
# with u.set_enabled_equivalencies(u.dimensionless_angles()):
return d_si_d_kom.to(u.Unit("") / self.KOM.unit)
return d_si_d_kom.to(u.dimensionless_unscaled / self.KOM.unit)

def d_SINI_d_T0(self):
if not self.K96:
return np.ones(len(self.tt0)) * u.Unit("") / self.T0.unit
return np.ones(len(self.tt0)) * u.dimensionless_unscaled / self.T0.unit
d_si_d_kom = -(-self.PMLONG_DDK * self.sin_KOM + self.PMLAT_DDK * self.cos_KOM)
return d_si_d_kom.to(u.Unit("") / self.T0.unit)
return d_si_d_kom.to(u.dimensionless_unscaled / self.T0.unit)

def d_SINI_d_par(self, par):
par_obj = getattr(self, par)
try:
ko_func = getattr(self, f"d_SINI_d_{par}")
except Exception:
ko_func = lambda: np.zeros(len(self.tt0)) * u.Unit("") / par_obj.unit
ko_func = (
lambda: np.zeros(len(self.tt0))
* u.dimensionless_unscaled
/ par_obj.unit
)
return ko_func()

def d_kin_proper_motion_d_KOM(self):
Expand Down Expand Up @@ -394,7 +398,7 @@ def delta_sini_parallax(self):
/ PX_kpc
* (self.delta_I0() * self.sin_KOM - self.delta_J0() * self.cos_KOM)
)
return delta_sini.to("")
return delta_sini.to(u.dimensionless_unscaled)

def delta_a1_parallax(self):
"""
Expand Down
4 changes: 2 additions & 2 deletions src/pint/models/stand_alone_psr_binaries/DD_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def d_omega_d_OMDOT(self):
n = 2*pi/PB
dOmega/dOMDOT = PB/2*pi*nu
"""
PB = (self.pb()).to("second")
PB = (self.pb()).to(u.s)
nu = self.nu()

return PB / (2 * np.pi * u.rad) * nu
Expand Down Expand Up @@ -568,7 +568,7 @@ def nhat(self):
n = 2*pi/PB # should here be M()
"""
cosE = np.cos(self.E())
return 2.0 * np.pi / self.pb().to("second") / (1 - self.ecc() * cosE)
return 2.0 * np.pi / self.pb().to(u.s) / (1 - self.ecc() * cosE)

def d_nhat_d_par(self, par):
"""Derivative.
Expand Down
4 changes: 2 additions & 2 deletions src/pint/models/stand_alone_psr_binaries/ELL1H_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def __init__(self):
{
"H3": 0.0 * u.second,
"H4": 0.0 * u.second,
"STIGMA": 0.0 * u.Unit(""),
"NHARMS": 3 * u.Unit(""),
"STIGMA": 0.0 * u.dimensionless_unscaled,
"NHARMS": 3 * u.dimensionless_unscaled,
}
)
self.binary_params = list(self.param_default_value.keys())
Expand Down
12 changes: 6 additions & 6 deletions src/pint/models/stand_alone_psr_binaries/ELL1_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def ttasc(self):
t = self.t
if not hasattr(self.t, "unit") or self.t.unit is None:
t = self.t * u.day
return (t - self.TASC.value * u.day).to("second")
return (t - self.TASC.value * u.day).to(u.s)

def a1(self):
"""ELL1 model a1 calculation.
Expand Down Expand Up @@ -103,14 +103,14 @@ def Phi(self):
return self.M()

def orbits_ELL1(self):
PB = (self.pb()).to("second")
PB = (self.pb()).to(u.s)
PBDOT = self.pbdot()
ttasc = self.ttasc()
return (ttasc / PB - 0.5 * PBDOT * (ttasc / PB) ** 2).decompose()

def d_Phi_d_TASC(self):
"""dPhi/dTASC"""
PB = self.pb().to("second")
PB = self.pb().to(u.s)
PBDOT = self.pbdot()
ttasc = self.ttasc()
return (PBDOT * ttasc / PB - 1.0) * 2 * np.pi * u.rad / PB
Expand Down Expand Up @@ -157,7 +157,7 @@ def delayI(self):
Dre = self.delayR()
Drep = self.Drep()
Drepp = self.Drepp()
PB = self.pb().to("second")
PB = self.pb().to(u.s)
nhat = 2 * np.pi / self.pb()
return (
Dre
Expand All @@ -182,7 +182,7 @@ def d_delayI_d_par(self, par):
Dre = self.delayR()
Drep = self.Drep()
Drepp = self.Drepp()
PB = self.pb().to("second")
PB = self.pb().to(u.s)
nhat = 2 * np.pi / self.pb()

d_delayI_d_Dre = (
Expand Down Expand Up @@ -214,7 +214,7 @@ def ELL1_ecc(self):
def ELL1_T0(self):
return self.TASC + self.pb() / (2 * np.pi) * (
np.arctan(self.eps1() / self.eps2())
).to(u.Unit(""), equivalencies=u.dimensionless_angles())
).to(u.dimensionless_unscaled, equivalencies=u.dimensionless_angles())

###############################
def d_delayR_da1(self):
Expand Down
8 changes: 4 additions & 4 deletions src/pint/models/stand_alone_psr_binaries/binary_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def get_tt0(self, barycentricTOA):
T0 = self.T0
if not hasattr(barycentricTOA, "unit") or barycentricTOA.unit is None:
barycentricTOA = barycentricTOA * u.day
return (barycentricTOA - T0).to("second")
return (barycentricTOA - T0).to(u.s)

def ecc(self):
"""Calculate eccentricity with EDOT"""
Expand Down Expand Up @@ -473,7 +473,7 @@ def d_M_d_par(self, par):
par_obj = getattr(self, par)
result = self.orbits_cls.d_orbits_d_par(par)
with u.set_enabled_equivalencies(u.dimensionless_angles()):
result = result.to(u.Unit("") / par_obj.unit)
result = result.to(u.dimensionless_unscaled / par_obj.unit)
return result

###############################################
Expand Down Expand Up @@ -629,7 +629,7 @@ def d_nu_d_par(self, par):
return np.zeros(len(self.tt0)) * nu.unit / par_obj.unit

def omega(self):
PB = self.pb().to("second")
PB = self.pb().to(u.s)
OMDOT = self.OMDOT
OM = self.OM
return OM + OMDOT * self.tt0
Expand Down Expand Up @@ -682,7 +682,7 @@ def pbprime(self):
return self.pb() - self.pbdot() * self.tt0

def P(self):
return self.P0 + self.P1 * (self.t - self.PEPOCH).to("second")
return self.P0 + self.P1 * (self.t - self.PEPOCH).to(u.s)

def t0(self):
return self.t - self.PEPOCH
Expand Down
Loading

0 comments on commit 2186fbb

Please sign in to comment.