From 0f07e48d499d6502f52d17ad7a02304a456121b5 Mon Sep 17 00:00:00 2001 From: Deven Bhakta Date: Sun, 28 Jul 2024 14:56:15 -0400 Subject: [PATCH 01/10] Event_optimize results.txt bug fix --- src/pint/scripts/event_optimize.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/pint/scripts/event_optimize.py b/src/pint/scripts/event_optimize.py index fe92214ac..e4c9dd4ff 100755 --- a/src/pint/scripts/event_optimize.py +++ b/src/pint/scripts/event_optimize.py @@ -1005,20 +1005,24 @@ def plot_chains(chain_dict, file=False): f.close() # Print the best MCMC values and ranges - ranges = map( - lambda v: (v[1], v[2] - v[1], v[1] - v[0]), - zip(*np.percentile(samples, [16, 50, 84], axis=0)), + ranges = list( + map( + lambda v: (v[1], v[2] - v[1], v[1] - v[0]), + zip(*np.percentile(samples, [16, 50, 84], axis=0)), + ) ) log.info(f"Post-MCMC values (50th percentile +/- (16th/84th percentile):") for name, vals in zip(ftr.fitkeys, ranges): - log.info("%8s:" % name + "%25.15g (+ %12.5g / - %12.5g)" % vals) + log.info(f"{name:8s}: {vals[0]:25.15g} (+ {vals[1]:12.5g} / - {vals[2]:12.5g})") # Put the same stuff in a file f = open(filename + "_results.txt", "w") f.write(f"Post-MCMC values (50th percentile +/- (16th/84th percentile):\n") for name, vals in zip(ftr.fitkeys, ranges): - f.write("%8s:" % name + " %25.15g (+ %12.5g / - %12.5g)\n" % vals) + f.write( + f"{name:8s}: {vals[0]:25.15g} (+ {vals[1]:12.5g} / - {vals[2]:12.5g})\n" + ) f.write(f"\nMaximum likelihood par file:\n") f.write(ftr.model.as_parfile()) From 4b0084f0f3e0515e1ac91cc591f26565f5fad235 Mon Sep 17 00:00:00 2001 From: Deven Bhakta Date: Tue, 6 Aug 2024 18:22:15 -0400 Subject: [PATCH 02/10] Test update for event_optimize --- tests/test_event_optimize.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_event_optimize.py b/tests/test_event_optimize.py index 8d7680a26..c829f2ab0 100644 --- a/tests/test_event_optimize.py +++ b/tests/test_event_optimize.py @@ -35,6 +35,10 @@ def test_result(tmp_path): event_optimize.main(cmd.split()) lines = sys.stdout.getvalue() # Need to add some check here. + with open("J0030+0451_results.txt") as f: + lines = f.readlines() + assert lines[1].split()[0] == "F0" + assert len(lines[1].split()[2]) == 16 finally: os.chdir(p) sys.stdout = saved_stdout From 8c1e227ed5b3749470836bec167f543fcd8ddf64 Mon Sep 17 00:00:00 2001 From: Abhimanyu Susobhanan Date: Wed, 7 Aug 2024 16:24:47 +0200 Subject: [PATCH 03/10] type hints in residuals.py --- src/pint/residuals.py | 180 +++++++++++++++++++++++------------------- 1 file changed, 100 insertions(+), 80 deletions(-) diff --git a/src/pint/residuals.py b/src/pint/residuals.py index 98b2b9864..a4ff42e15 100644 --- a/src/pint/residuals.py +++ b/src/pint/residuals.py @@ -6,8 +6,10 @@ (:class:`pint.residuals.Residuals`) and for arrival times that come paired with dispersion measures (:class:`pint.residuals.WidebandTOAResiduals`). """ + import collections import copy +from typing import Dict, Literal, Optional import warnings import astropy.units as u @@ -17,7 +19,9 @@ from pint.models.dispersion_model import Dispersion from pint.models.parameter import maskParameter +from pint.models.timing_model import TimingModel from pint.phase import Phase +from pint.toa import TOAs from pint.utils import ( sherman_morrison_dot, weighted_mean, @@ -83,14 +87,14 @@ class also serves as a base class providing some infrastructure to support def __new__( cls, - toas=None, - model=None, - residual_type="toa", - unit=u.s, - subtract_mean=True, - use_weighted_mean=True, - track_mode=None, - use_abs_phase=True, + toas: Optional[TOAs] = None, + model: Optional[TimingModel] = None, + residual_type: Literal["toa", "dm"] = "toa", + unit: u.Unit | str = u.s, + subtract_mean: bool = True, + use_weighted_mean: bool = True, + track_mode: Optional[Literal["use_pulse_numbers", "nearest"]] = None, + use_abs_phase: bool = True, ): if cls is Residuals: try: @@ -104,14 +108,14 @@ def __new__( def __init__( self, - toas=None, - model=None, - residual_type="toa", - unit=u.s, - subtract_mean=True, - use_weighted_mean=True, - track_mode=None, - use_abs_phase=True, + toas: Optional[TOAs] = None, + model: Optional[TimingModel] = None, + residual_type: Literal["toa", "dm"] = "toa", + unit: u.Unit | str = u.s, + subtract_mean: bool = True, + use_weighted_mean: bool = True, + track_mode: Optional[Literal["use_pulse_numbers", "nearest"]] = None, + use_abs_phase: bool = True, ): self.toas = toas self.model = model @@ -164,18 +168,18 @@ def __init__( self._is_combined = False @property - def resids(self): + def resids(self) -> u.Quantity: """Residuals in time units.""" if self.time_resids is None: self.update() return self.time_resids @property - def resids_value(self): + def resids_value(self) -> np.ndarray: """Residuals in seconds, with the units stripped.""" return self.resids.to_value(self.unit) - def update(self): + def update(self) -> None: """Recalculate everything in residuals class after changing model or TOAs""" if self.toas is None or self.model is None: self.phase_resids = None @@ -190,7 +194,7 @@ def update(self): self._chi2 = None # trigger chi2 recalculation when needed @property - def chi2(self): + def chi2(self) -> float: """Compute chi-squared as needed and cache the result.""" if self._chi2 is None: self._chi2 = self.calc_chi2() @@ -198,7 +202,7 @@ def chi2(self): return self._chi2 @property - def dof(self): + def dof(self) -> int: """Return number of degrees of freedom for the model.""" if self._is_combined: raise AttributeError( @@ -214,12 +218,12 @@ def dof(self): return dof @property - def reduced_chi2(self): + def reduced_chi2(self) -> float: """Return the weighted reduced chi-squared for the model and toas.""" return self.chi2 / self.dof @property - def chi2_reduced(self): + def chi2_reduced(self) -> float: """Reduced chi-squared.""" warnings.warn( "Do not use 'residuals.chi2_reduced'. Please use 'residuals.reduced_chi2' instead.", @@ -228,7 +232,7 @@ def chi2_reduced(self): return self.chi2 / self.dof - def get_data_error(self, scaled=True): + def get_data_error(self, scaled: bool = True) -> u.Quantity: """Get errors on time residuals. This returns the uncertainties on the time residuals, optionally scaled @@ -245,7 +249,7 @@ def get_data_error(self, scaled=True): else self.toas.get_errors() ) - def rms_weighted(self): + def rms_weighted(self) -> u.Quantity: """Compute weighted RMS of the residuals in time.""" # Use scaled errors, if the noise model is not presented, it will # return the raw errors @@ -259,7 +263,7 @@ def rms_weighted(self): wmean, werr, wsdev = weighted_mean(self.time_resids, w, sdev=True) return wsdev.to(u.us) - def get_PSR_freq(self, calctype="modelF0"): + def get_PSR_freq(self, calctype="modelF0") -> u.Quantity: """Return pulsar rotational frequency in Hz. Parameters @@ -308,8 +312,11 @@ def get_PSR_freq(self, calctype="modelF0"): return self.model.d_phase_d_toa(self.toas) def calc_phase_resids( - self, subtract_mean=None, use_weighted_mean=None, use_abs_phase=None - ): + self, + subtract_mean: Optional[bool] = None, + use_weighted_mean: Optional[bool] = None, + use_abs_phase: Optional[bool] = None, + ) -> u.Quantity: """Compute timing model residuals in pulse phase. if ``subtract_mean`` or ``use_weighted_mean`` is None, will use the values set for the object itself @@ -417,7 +424,12 @@ def calc_phase_resids( return full - mean - def _calc_mean(self, weighted, type, calctype=None): + def _calc_mean( + self, + weighted: bool, + type: Literal["time", "phase"], + calctype: Optional[Literal["taylor", "modelF0", "numerical"]] = None, + ) -> u.Quantity: assert type in ["time", "phase"] r = ( @@ -436,7 +448,7 @@ def _calc_mean(self, weighted, type, calctype=None): mean, _ = weighted_mean(r, w) return mean - def calc_phase_mean(self, weighted=True): + def calc_phase_mean(self, weighted: bool = True) -> u.Quantity: """Calculate mean phase of residuals, optionally weighted Parameters @@ -449,7 +461,11 @@ def calc_phase_mean(self, weighted=True): """ return self._calc_mean(weighted, "phase") - def calc_time_mean(self, calctype="taylor", weighted=True): + def calc_time_mean( + self, + calctype: Literal["taylor", "modelF0", "numerical"] = "taylor", + weighted: bool = True, + ) -> u.Quantity: """Calculate mean time of residuals, optionally weighted Parameters @@ -466,11 +482,11 @@ def calc_time_mean(self, calctype="taylor", weighted=True): def calc_time_resids( self, - calctype="taylor", - subtract_mean=None, - use_weighted_mean=None, - use_abs_phase=None, - ): + calctype: Literal["taylor", "modelF0", "numerical"] = "taylor", + subtract_mean: Optional[bool] = None, + use_weighted_mean: Optional[bool] = None, + use_abs_phase: Optional[bool] = None, + ) -> u.Quantity: """Compute timing model residuals in time (seconds). Converts from phase residuals to time residuals using several possible ways @@ -521,7 +537,7 @@ def calc_time_resids( ) return (phase_resids / self.get_PSR_freq(calctype=calctype)).to(u.s) - def calc_whitened_resids(self): + def calc_whitened_resids(self) -> u.Quantity: """Compute whitened timing residuals (dimensionless). Whitened residuals are computed by subtracting the correlated @@ -548,7 +564,7 @@ def calc_whitened_resids(self): sigma = self.get_data_error() return ((r - nr) / sigma).to(u.dimensionless_unscaled) - def _calc_gls_chi2(self, lognorm=False): + def _calc_gls_chi2(self, lognorm: bool = False) -> float: """Compute the chi2 when correlated noise is present in the timing model. If the system is not singular, it uses Cholesky factorization to evaluate this. If the system is singular, it uses singular value decomposition instead. @@ -572,7 +588,7 @@ def _calc_gls_chi2(self, lognorm=False): return (chi2, logdet_C / 2) if lognorm else chi2 - def _calc_ecorr_chi2(self, lognorm=False): + def _calc_ecorr_chi2(self, lognorm: bool = False) -> float: """Compute the chi2 when ECORR is present in the timing model without any other correlated noise components.""" @@ -619,7 +635,7 @@ def _calc_ecorr_chi2(self, lognorm=False): else chisq.to_value(u.dimensionless_unscaled) ) - def _calc_wls_chi2(self, lognorm=False): + def _calc_wls_chi2(self, lognorm: bool = False) -> float: """Compute the chi2 when no correlated noise components are present.""" assert not self.model.has_correlated_errors @@ -650,7 +666,7 @@ def _calc_wls_chi2(self, lognorm=False): log_norm = np.sum(np.log(err.value)) return chi2, log_norm - def calc_chi2(self, lognorm=False): + def calc_chi2(self, lognorm: bool = False) -> float: """Return the weighted chi-squared for the model and toas. If the errors on the TOAs are independent this is a straightforward @@ -694,12 +710,12 @@ def calc_chi2(self, lognorm=False): else: return self._calc_gls_chi2(lognorm=lognorm) - def lnlikelihood(self): + def lnlikelihood(self) -> float: """Compute the log-likelihood for the model and TOAs.""" chi2, log_norm = self.calc_chi2(lognorm=True) return -(chi2 / 2 + log_norm) - def d_lnlikelihood_d_Ndiag(self): + def d_lnlikelihood_d_Ndiag(self) -> u.Quantity: r = self.time_resids sigma = self.get_data_error() @@ -753,14 +769,14 @@ def d_lnlikelihood_d_Ndiag(self): return -0.5 * (term1 + term2 + term3 + term4) - def d_Ndiag_d_param(self, param): + def d_Ndiag_d_param(self, param: str) -> u.Quantity: """Derivative of the white noise covariance matrix diagonal elements w.r.t. a white noise parameter (EFAC or EQUAD).""" sigma = self.get_data_error() d_sigma_d_param = self.model.d_toasigma_d_param(self.toas, param) return 2 * sigma * d_sigma_d_param - def d_lnlikelihood_d_ECORR(self, param): + def d_lnlikelihood_d_ECORR(self, param: str) -> u.Quantity: par = self.model[param] fullmask = par.select_toa_mask(self.toas) @@ -786,13 +802,11 @@ def d_lnlikelihood_d_ECORR(self, param): v_Ninv_v = np.sum(v**2 / Ndiag) denom = 1 + c**2 * v_Ninv_v - result += ( - c * (s_Ninv_v**2 - v_Ninv_v - c**2 * v_Ninv_v**2) / denom**2 - ) + result += c * (s_Ninv_v**2 - v_Ninv_v - c**2 * v_Ninv_v**2) / denom**2 return result - def d_lnlikelihood_d_param(self, param): + def d_lnlikelihood_d_param(self, param: str) -> u.Quantity: par = self.model[param] if self.model.has_correlated_errors and ( @@ -825,7 +839,7 @@ def d_lnlikelihood_d_param(self, param): # d_sigma_d_param = self.model.d_toasigma_d_param(self.toas, param) # return np.sum(((r / sigma) ** 2 - 1) / sigma * d_sigma_d_param).to(1/self.model[param].units) - def ecorr_average(self, use_noise_model=True): + def ecorr_average(self, use_noise_model: bool = True) -> u.Quantity: """Uses the ECORR noise model time-binning to compute "epoch-averaged" residuals. Requires ECORR be used in the timing model. If @@ -919,12 +933,12 @@ class WidebandDMResiduals(Residuals): def __init__( self, - toas=None, - model=None, - residual_type="dm", - unit=u.pc / u.cm**3, - subtract_mean=False, - use_weighted_mean=True, + toas: Optional[TOAs] = None, + model: Optional[TimingModel] = None, + residual_type: Literal["toa", "dm"] = "dm", + unit: u.Unit | str = u.pc / u.cm**3, + subtract_mean: bool = False, + use_weighted_mean: bool = True, ): self.toas = toas self.model = model @@ -941,16 +955,16 @@ def __init__( self.debug_info = {} @property - def resids(self): + def resids(self) -> u.Quantity: return self.calc_resids() @property - def resids_value(self): + def resids_value(self) -> np.ndarray: """Get pure value of the residuals use the given base unit.""" return self.resids.to_value(self.unit) @property - def dof(self): + def dof(self) -> int: """Return number of degrees of freedom for the DM model.""" if self._is_combined: raise AttributeError( @@ -969,7 +983,7 @@ def dof(self): dof -= 1 return dof - def get_data_error(self, scaled=True): + def get_data_error(self, scaled=True) -> u.Quantity: """Get data errors. Parameters @@ -979,7 +993,7 @@ def get_data_error(self, scaled=True): """ return self.model.scaled_dm_uncertainty(self.toas) if scaled else self.dm_error - def calc_resids(self): + def calc_resids(self) -> u.Quantity: model_value = self.get_model_value(self.toas)[self.relevant_toas] resids = self.dm_data - model_value if self.subtract_mean: @@ -997,7 +1011,7 @@ def calc_resids(self): resids -= resids.mean() return resids - def calc_chi2(self): + def calc_chi2(self) -> float: data_errors = self.get_data_error() if (data_errors == 0.0).any(): return np.inf @@ -1006,7 +1020,7 @@ def calc_chi2(self): except ValueError: return ((self.resids / data_errors) ** 2.0).sum().decompose() - def rms_weighted(self): + def rms_weighted(self) -> u.Quantity: """Compute weighted RMS of the residuals in time.""" scaled_errors = self.get_data_error() if np.any(scaled_errors.value == 0): @@ -1018,7 +1032,7 @@ def rms_weighted(self): wmean, werr, wsdev = weighted_mean(self.resids, w, sdev=True) return wsdev - def get_dm_data(self): + def get_dm_data(self) -> u.Quantity: """Get the independent measured DM data from TOA flags. This is to extract DM and uncertainty data from its representation in @@ -1047,7 +1061,7 @@ def get_dm_data(self): valid_error = np.array(dm_error)[valid_error] return valid_dm * self.unit, valid_error * self.unit, valid_data - def update_model(self, new_model, **kwargs): + def update_model(self, new_model: TimingModel, **kwargs) -> None: """Up date DM models from a new PINT timing model Parameters @@ -1076,7 +1090,7 @@ class CombinedResiduals: residuals will have no units. """ - def __init__(self, residuals): + def __init__(self, residuals: Residuals): self.residual_objs = collections.OrderedDict() for res in residuals: res._is_combined = True @@ -1094,34 +1108,34 @@ def model(self): ) @property - def _combined_resids(self): + def _combined_resids(self) -> np.ndarray: """Residuals from all of the residual types.""" all_resids = [res.resids_value for res in self.residual_objs.values()] return np.hstack(all_resids) @property - def _combined_data_error(self): + def _combined_data_error(self) -> np.ndarray: # Since it is the combined residual, the units are removed. dr = self.data_error return np.hstack([rv.value for rv in dr.values()]) @property - def unit(self): + def unit(self) -> dict: return {k: v.unit for k, v in self.residual_objs.items()} @property - def chi2(self): + def chi2(self) -> float: return sum(res.chi2 for res in self.residual_objs.values()) @property - def data_error(self): + def data_error(self) -> collections.OrderedDict: errors = [ (rs.residual_type, rs.get_data_error()) for rs in self.residual_objs.values() ] return collections.OrderedDict(errors) - def rms_weighted(self): + def rms_weighted(self) -> np.ndarray: """Compute weighted RMS of the residuals in time.""" if np.any(self._combined_data_error == 0): @@ -1163,7 +1177,13 @@ class WidebandTOAResiduals(CombinedResiduals): Default: {} """ - def __init__(self, toas, model, toa_resid_args={}, dm_resid_args={}): + def __init__( + self, + toas: TOAs, + model: TimingModel, + toa_resid_args: dict = {}, + dm_resid_args: dict = {}, + ): self.toas = toas self._model = model toa_resid = Residuals( @@ -1175,24 +1195,24 @@ def __init__(self, toas, model, toa_resid_args={}, dm_resid_args={}): super().__init__([toa_resid, dm_resid]) @property - def toa(self): + def toa(self) -> Residuals: """Residuals object containing the TOA residuals.""" return self.residual_objs["toa"] @property - def dm(self): + def dm(self) -> WidebandDMResiduals: """WidebandDMResiduals object containing the DM residuals.""" return self.residual_objs["dm"] @property - def chi2(self): + def chi2(self) -> float: """Compute chi-squared as needed and cache the result.""" if self._chi2 is None: self._chi2 = self.calc_chi2() assert self._chi2 is not None return self._chi2 - def calc_chi2(self, full_cov=False): + def calc_chi2(self, full_cov=False) -> float: """Return the weighted chi-squared for the model and toas. If the errors on the TOAs are independent this is a straightforward @@ -1230,7 +1250,7 @@ def calc_chi2(self, full_cov=False): return np.inf @property - def model(self): + def model(self) -> TimingModel: """The model used to construct the residuals. Modifying this model, even changing its parameters, may have confusing @@ -1240,13 +1260,13 @@ def model(self): return self._model @property - def dof(self): + def dof(self) -> int: """The number of degrees of freedom for the wideband residuals.""" dof = len(self._combined_resids) dof -= len(self.model.free_params) + 1 return dof @property - def reduced_chi2(self): + def reduced_chi2(self) -> float: """Return the weighted reduced chi-squared.""" return self.chi2 / self.dof From bdf4b7b962bc2ec4a7edb061573e7f6d551ca21c Mon Sep 17 00:00:00 2001 From: Abhimanyu Susobhanan Date: Wed, 7 Aug 2024 16:25:43 +0200 Subject: [PATCH 04/10] cleanup --- src/pint/residuals.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pint/residuals.py b/src/pint/residuals.py index a4ff42e15..2c094987f 100644 --- a/src/pint/residuals.py +++ b/src/pint/residuals.py @@ -9,7 +9,7 @@ import collections import copy -from typing import Dict, Literal, Optional +from typing import Literal, Optional import warnings import astropy.units as u From 25ef9a395656767a54f5b331e2279577e8125a42 Mon Sep 17 00:00:00 2001 From: Abhimanyu Susobhanan Date: Wed, 7 Aug 2024 16:34:38 +0200 Subject: [PATCH 05/10] -- --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index bc9b94cf6..87a498e01 100644 --- a/tox.ini +++ b/tox.ini @@ -133,7 +133,7 @@ skip_install = true changedir = . description = use black deps = - black~=23.0 + black~=24.0 commands = black --check src tests examples From 821f02ade99ff05a4f09c0a035f9c82b9abbb88e Mon Sep 17 00:00:00 2001 From: Abhimanyu Susobhanan Date: Wed, 7 Aug 2024 16:35:32 +0200 Subject: [PATCH 06/10] black --- tests/datafile/get_tempo2_result.py | 1 + tests/test_B1855.py | 1 + tests/test_B1855_9yrs.py | 1 + tests/test_B1953.py | 1 + tests/test_J0613.py | 1 + tests/test_TDB_method.py | 1 + tests/test_dd.py | 1 + tests/test_design_matrix.py | 1 + tests/test_dmefac_dmequad.py | 9 +++------ tests/test_early_chime_data.py | 1 + tests/test_fbx.py | 1 + tests/test_fd.py | 1 + tests/test_infostrings.py | 1 + tests/test_parfile_writing.py | 1 + tests/test_pldmnoise.py | 1 - tests/test_plot_utils.py | 1 + tests/test_pulsar_position.py | 1 + tests/test_toa_flag.py | 1 - tests/test_variety_parfiles.py | 1 + tests/utils.py | 1 + 20 files changed, 20 insertions(+), 8 deletions(-) diff --git a/tests/datafile/get_tempo2_result.py b/tests/datafile/get_tempo2_result.py index d55564e54..fb9c6c62f 100644 --- a/tests/datafile/get_tempo2_result.py +++ b/tests/datafile/get_tempo2_result.py @@ -1,6 +1,7 @@ """This is a script for getting tempo/tempo2/libstempo result for the propose of testing PINT """ + # from pint.utils import longdouble2str try: diff --git a/tests/test_B1855.py b/tests/test_B1855.py index 605b6953a..96c0eb17e 100644 --- a/tests/test_B1855.py +++ b/tests/test_B1855.py @@ -1,4 +1,5 @@ """Various tests to assess the performance of the B1855+09.""" + import logging import os diff --git a/tests/test_B1855_9yrs.py b/tests/test_B1855_9yrs.py index 91a848895..063767869 100644 --- a/tests/test_B1855_9yrs.py +++ b/tests/test_B1855_9yrs.py @@ -1,4 +1,5 @@ """Various tests to assess the performance of the B1855+09.""" + import logging import os import pytest diff --git a/tests/test_B1953.py b/tests/test_B1953.py index 6b30077e7..e65d8ea07 100644 --- a/tests/test_B1953.py +++ b/tests/test_B1953.py @@ -1,4 +1,5 @@ """Various tests to assess the performance of the B1953+29.""" + from astropy import log import os import pytest diff --git a/tests/test_J0613.py b/tests/test_J0613.py index 1178afc7f..90c237fe6 100644 --- a/tests/test_J0613.py +++ b/tests/test_J0613.py @@ -1,4 +1,5 @@ """Various tests to assess the performance of the J0623-0200.""" + import logging import os import pytest diff --git a/tests/test_TDB_method.py b/tests/test_TDB_method.py index a25670a2d..e4f0b2576 100644 --- a/tests/test_TDB_method.py +++ b/tests/test_TDB_method.py @@ -1,4 +1,5 @@ """tests for different compute TDB method.""" + import os import pytest diff --git a/tests/test_dd.py b/tests/test_dd.py index 8bbce7f2d..356798781 100644 --- a/tests/test_dd.py +++ b/tests/test_dd.py @@ -1,4 +1,5 @@ """Various tests to assess the performance of the DD model.""" + import os import pytest diff --git a/tests/test_design_matrix.py b/tests/test_design_matrix.py index 443888015..bc952a942 100644 --- a/tests/test_design_matrix.py +++ b/tests/test_design_matrix.py @@ -1,4 +1,5 @@ """ Test for pint design matrix""" + import os import numpy as np diff --git a/tests/test_dmefac_dmequad.py b/tests/test_dmefac_dmequad.py index 3987b0cb8..ab1268e18 100644 --- a/tests/test_dmefac_dmequad.py +++ b/tests/test_dmefac_dmequad.py @@ -1,5 +1,6 @@ """Test for the DM uncertainty rescaling DMEFAC and DMEQUAD """ + from io import StringIO import numpy as np @@ -57,9 +58,7 @@ def test_only_one_equad(test_toas, test_model): test_model.setup() scale_sigma = test_model.scale_dm_sigma(test_toas) mask = test_model.DMEQUAD1.select_toa_mask(test_toas) - scaled_value = ( - np.sqrt(0.01**2 + test_model.DMEQUAD1.value**2) * u.pc / u.cm**3 - ) + scaled_value = np.sqrt(0.01**2 + test_model.DMEQUAD1.value**2) * u.pc / u.cm**3 rest = list(set(range(test_toas.ntoas)).symmetric_difference(mask)) assert np.isclose(scale_sigma[mask], scaled_value).any() assert np.all(scale_sigma[rest] == 0.01 * u.pc / u.cm**3) @@ -100,9 +99,7 @@ def test_only_one_equad_one_efact_different_backend(test_toas, test_model): mask1 = test_model.DMEFAC1.select_toa_mask(test_toas) mask2 = test_model.DMEQUAD1.select_toa_mask(test_toas) scaled_value1 = test_model.DMEFAC1.value * 0.01 * u.pc / u.cm**3 - scaled_value2 = ( - np.sqrt(0.01**2 + test_model.DMEQUAD1.value**2) * u.pc / u.cm**3 - ) + scaled_value2 = np.sqrt(0.01**2 + test_model.DMEQUAD1.value**2) * u.pc / u.cm**3 assert np.isclose(scale_sigma[mask1], scaled_value1).any() assert np.isclose(scale_sigma[mask2], scaled_value2).any() rest1 = list(set(range(test_toas.ntoas)).symmetric_difference(mask1)) diff --git a/tests/test_early_chime_data.py b/tests/test_early_chime_data.py index 96d4121fb..9579768c7 100644 --- a/tests/test_early_chime_data.py +++ b/tests/test_early_chime_data.py @@ -1,4 +1,5 @@ """Various tests to assess the performance of early CHIME data.""" + import os import pytest diff --git a/tests/test_fbx.py b/tests/test_fbx.py index 4cf278b07..6afcadc82 100644 --- a/tests/test_fbx.py +++ b/tests/test_fbx.py @@ -1,4 +1,5 @@ """Various tests to assess the performance of the FBX model.""" + import os import astropy.units as u diff --git a/tests/test_fd.py b/tests/test_fd.py index 75d1d7e4c..0a4c474f7 100644 --- a/tests/test_fd.py +++ b/tests/test_fd.py @@ -1,4 +1,5 @@ """Various tests to assess the performance of the FD model.""" + import copy import os import pytest diff --git a/tests/test_infostrings.py b/tests/test_infostrings.py index f1fc18a48..1aa8caef2 100644 --- a/tests/test_infostrings.py +++ b/tests/test_infostrings.py @@ -1,4 +1,5 @@ """Tests for adding info strings to parfiles and tim files""" + import os import pytest import io diff --git a/tests/test_parfile_writing.py b/tests/test_parfile_writing.py index 5e5dc2a9b..2746787ae 100644 --- a/tests/test_parfile_writing.py +++ b/tests/test_parfile_writing.py @@ -1,4 +1,5 @@ """Various tests to assess the performance of parfile writing.""" + import numbers import os from io import StringIO diff --git a/tests/test_pldmnoise.py b/tests/test_pldmnoise.py index 9a27450c2..c60dd3071 100644 --- a/tests/test_pldmnoise.py +++ b/tests/test_pldmnoise.py @@ -10,7 +10,6 @@ Add test that checks for same results between PINT and enterprise """ - import astropy.units as u import contextlib import io diff --git a/tests/test_plot_utils.py b/tests/test_plot_utils.py index 0110efb7e..7388f7d86 100644 --- a/tests/test_plot_utils.py +++ b/tests/test_plot_utils.py @@ -1,4 +1,5 @@ """Test basic functionality of the :module:`pint.plot_utils`.""" + import numpy as np import astropy.units as u from astropy.time import Time diff --git a/tests/test_pulsar_position.py b/tests/test_pulsar_position.py index 929daa204..9667a7d89 100644 --- a/tests/test_pulsar_position.py +++ b/tests/test_pulsar_position.py @@ -1,5 +1,6 @@ """Various tests to assess the performance of the PINT position. """ + import os import pytest diff --git a/tests/test_toa_flag.py b/tests/test_toa_flag.py index 563578cbe..0c7d8f3f2 100644 --- a/tests/test_toa_flag.py +++ b/tests/test_toa_flag.py @@ -1,6 +1,5 @@ """Various tests to assess the performance of TOA get_flag_value.""" - import os import pytest import io diff --git a/tests/test_variety_parfiles.py b/tests/test_variety_parfiles.py index 920d6784d..c137d59a1 100644 --- a/tests/test_variety_parfiles.py +++ b/tests/test_variety_parfiles.py @@ -1,4 +1,5 @@ """Various test for the bad par files""" + import pytest from io import StringIO diff --git a/tests/utils.py b/tests/utils.py index 005c197bb..17b04a38d 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -1,4 +1,5 @@ """Utility functions for the tests""" + import warnings from pint.models.parameter import funcParameter From ad88a25e3b67b1b7f33c8e64720298db1391f5c7 Mon Sep 17 00:00:00 2001 From: Abhimanyu Susobhanan Date: Wed, 7 Aug 2024 16:35:58 +0200 Subject: [PATCH 07/10] black --- src/pint/binaryconvert.py | 12 ++++++------ src/pint/derived_quantities.py | 12 +++--------- src/pint/eventstats.py | 1 + src/pint/fermi_toas.py | 4 +--- src/pint/gridutils.py | 1 + src/pint/models/priors.py | 1 + .../models/stand_alone_psr_binaries/DDGR_model.py | 5 ++--- .../models/stand_alone_psr_binaries/DDH_model.py | 6 ++---- .../models/stand_alone_psr_binaries/DDK_model.py | 4 +--- .../models/stand_alone_psr_binaries/DDS_model.py | 1 + src/pint/models/stand_alone_psr_binaries/DD_model.py | 6 ++---- .../models/stand_alone_psr_binaries/ELL1_model.py | 1 + .../models/stand_alone_psr_binaries/ELL1k_model.py | 1 + src/pint/models/troposphere_delay.py | 1 + src/pint/observatory/global_clock_corrections.py | 1 + src/pint/orbital/kepler.py | 7 ++----- src/pint/output/publish.py | 1 + src/pint/pint_matrix.py | 10 ++++------ src/pint/pintk/colormodes.py | 7 ++++--- src/pint/scripts/pintpublish.py | 1 + src/pint/templates/lcfitters.py | 1 + src/pint/templates/lcnorm.py | 1 + src/pint/toa_select.py | 1 + 23 files changed, 40 insertions(+), 46 deletions(-) diff --git a/src/pint/binaryconvert.py b/src/pint/binaryconvert.py index 828343d35..9edd2f697 100644 --- a/src/pint/binaryconvert.py +++ b/src/pint/binaryconvert.py @@ -262,9 +262,11 @@ def _from_ELL1(model): (om.s * u.rad).to(u.deg) if om.s > 0 else None, t02.s * u.d if t02.s > 0 else None, edot.s * u.Hz if (edot is not None and edot.s > 0) else None, - (omdot.s * u.rad / u.s).to(u.deg / u.yr) - if (omdot is not None and omdot.s > 0) - else None, + ( + (omdot.s * u.rad / u.s).to(u.deg / u.yr) + if (omdot is not None and omdot.s > 0) + else None + ), ) @@ -476,9 +478,7 @@ def _DDGR_to_PK(model): ) if model.XOMDOT.quantity is not None: omegadot += model.XOMDOT.as_ufloat(u.rad / u.s) - fe = (1 + (73.0 / 24) * ecc**2 + (37.0 / 96) * ecc**4) / (1 - ecc**2) ** ( - 7.0 / 2 - ) + fe = (1 + (73.0 / 24) * ecc**2 + (37.0 / 96) * ecc**4) / (1 - ecc**2) ** (7.0 / 2) # units as s/s pbdot = ( (-192 * np.pi / 5) diff --git a/src/pint/derived_quantities.py b/src/pint/derived_quantities.py index 5d69de328..d5852ae4b 100644 --- a/src/pint/derived_quantities.py +++ b/src/pint/derived_quantities.py @@ -130,8 +130,7 @@ def pferrs( return [1.0 / porf, porferr / porf**2.0] forperr = porferr / porf**2.0 fdorpderr = np.sqrt( - (4.0 * pdorfd**2.0 * porferr**2.0) / porf**6.0 - + pdorfderr**2.0 / porf**4.0 + (4.0 * pdorfd**2.0 * porferr**2.0) / porf**6.0 + pdorfderr**2.0 / porf**4.0 ) [forp, fdorpd] = p_to_f(porf, pdorfd) return (forp, forperr, fdorpd, fdorpderr) @@ -534,17 +533,12 @@ def companion_mass( # delta1 is always <0 # delta1 = 2 * b ** 3 - 9 * a * b * c + 27 * a ** 2 * d delta1 = ( - -2 * massfunct**3 - - 18 * a * mp * massfunct**2 - - 27 * a**2 * massfunct * mp**2 + -2 * massfunct**3 - 18 * a * mp * massfunct**2 - 27 * a**2 * massfunct * mp**2 ) # Q**2 is always > 0, so this is never a problem # in terms of complex numbers # Q = np.sqrt(delta1**2 - 4*delta0**3) - Q = np.sqrt( - 108 * a**3 * mp**3 * massfunct**3 - + 729 * a**4 * mp**4 * massfunct**2 - ) + Q = np.sqrt(108 * a**3 * mp**3 * massfunct**3 + 729 * a**4 * mp**4 * massfunct**2) # this could be + or - Q # pick the - branch since delta1 is <0 so that delta1 - Q is never near 0 Ccubed = 0.5 * (delta1 + Q) diff --git a/src/pint/eventstats.py b/src/pint/eventstats.py index b24c39aae..16fa1b4ad 100644 --- a/src/pint/eventstats.py +++ b/src/pint/eventstats.py @@ -2,6 +2,7 @@ author: M. Kerr """ + import numpy as np from numpy import exp, arange, log from scipy.special import erfc, gamma diff --git a/src/pint/fermi_toas.py b/src/pint/fermi_toas.py index 4bab230af..1b5c64c3a 100644 --- a/src/pint/fermi_toas.py +++ b/src/pint/fermi_toas.py @@ -55,9 +55,7 @@ def calc_lat_weights(energies, angseps, logeref=4.1, logesig=0.5): logE = np.log10(energies) sigma = ( - np.sqrt( - (psfpar0**2 * np.power(100.0 / energies, 2.0 * psfpar1) + psfpar2**2) - ) + np.sqrt((psfpar0**2 * np.power(100.0 / energies, 2.0 * psfpar1) + psfpar2**2)) / scalepsf ) diff --git a/src/pint/gridutils.py b/src/pint/gridutils.py index 517c1fa17..0df17ae0e 100644 --- a/src/pint/gridutils.py +++ b/src/pint/gridutils.py @@ -1,4 +1,5 @@ """Tools for building chi-squared grids.""" + import concurrent.futures import copy import multiprocessing diff --git a/src/pint/models/priors.py b/src/pint/models/priors.py index 368f0f07c..aa4b68ed0 100644 --- a/src/pint/models/priors.py +++ b/src/pint/models/priors.py @@ -6,6 +6,7 @@ such as total proper motion, 2-d sky location, etc. """ + import numpy as np from scipy.stats import rv_continuous, uniform diff --git a/src/pint/models/stand_alone_psr_binaries/DDGR_model.py b/src/pint/models/stand_alone_psr_binaries/DDGR_model.py index 85c40fd39..1aeef6e51 100644 --- a/src/pint/models/stand_alone_psr_binaries/DDGR_model.py +++ b/src/pint/models/stand_alone_psr_binaries/DDGR_model.py @@ -1,4 +1,5 @@ """The DDGR model - Damour and Deruelle with GR assumed""" + import astropy.constants as c import astropy.units as u import numpy as np @@ -504,9 +505,7 @@ def d_PBDOT_d_par(self, par): # other derivatives def d_E_d_MTOT(self): """Eccentric anomaly has MTOT dependence through PBDOT and Kepler's equation""" - d_M_d_MTOT = ( - -2 * np.pi * self.tt0**2 / (2 * self.PB**2) * self.d_PBDOT_d_MTOT() - ) + d_M_d_MTOT = -2 * np.pi * self.tt0**2 / (2 * self.PB**2) * self.d_PBDOT_d_MTOT() return d_M_d_MTOT / (1.0 - np.cos(self.E()) * self.ecc()) def d_nu_d_MTOT(self): diff --git a/src/pint/models/stand_alone_psr_binaries/DDH_model.py b/src/pint/models/stand_alone_psr_binaries/DDH_model.py index 3c4d59dcb..1f8af0896 100644 --- a/src/pint/models/stand_alone_psr_binaries/DDH_model.py +++ b/src/pint/models/stand_alone_psr_binaries/DDH_model.py @@ -1,4 +1,5 @@ """The DDS model - Damour and Deruelle with alternate Shapiro delay parametrization.""" + import astropy.constants as c import astropy.units as u import numpy as np @@ -144,10 +145,7 @@ def d_delayS_d_par(self, par): -2 * TM2 / logNum - * ( - e * sE - - self.SINI * (np.sqrt(1 - e**2) * cE * cOmega - sE * sOmega) - ) + * (e * sE - self.SINI * (np.sqrt(1 - e**2) * cE * cOmega - sE * sOmega)) ) domega_dpar = self.prtl_der("omega", par) dsDelay_domega = ( diff --git a/src/pint/models/stand_alone_psr_binaries/DDK_model.py b/src/pint/models/stand_alone_psr_binaries/DDK_model.py index 709033aae..173254c2e 100644 --- a/src/pint/models/stand_alone_psr_binaries/DDK_model.py +++ b/src/pint/models/stand_alone_psr_binaries/DDK_model.py @@ -518,9 +518,7 @@ def d_delta_omega_parallax_d_T0(self): PX_kpc = self.PX.to(u.kpc, equivalencies=u.parallax()) kom_projection = self.delta_I0() * self.cos_KOM + self.delta_J0() * self.sin_KOM d_kin_d_T0 = self.d_kin_d_par("T0") - d_delta_omega_d_T0 = ( - cos_kin / sin_kin**2 / PX_kpc * d_kin_d_T0 * kom_projection - ) + d_delta_omega_d_T0 = cos_kin / sin_kin**2 / PX_kpc * d_kin_d_T0 * kom_projection return d_delta_omega_d_T0.to( self.OM.unit / self.T0.unit, equivalencies=u.dimensionless_angles() ) diff --git a/src/pint/models/stand_alone_psr_binaries/DDS_model.py b/src/pint/models/stand_alone_psr_binaries/DDS_model.py index 1fc81fc56..ac336ca16 100644 --- a/src/pint/models/stand_alone_psr_binaries/DDS_model.py +++ b/src/pint/models/stand_alone_psr_binaries/DDS_model.py @@ -1,4 +1,5 @@ """The DDS model - Damour and Deruelle with alternate Shapiro delay parametrization.""" + import astropy.constants as c import astropy.units as u import numpy as np diff --git a/src/pint/models/stand_alone_psr_binaries/DD_model.py b/src/pint/models/stand_alone_psr_binaries/DD_model.py index e9b82bdc3..6e925fd58 100644 --- a/src/pint/models/stand_alone_psr_binaries/DD_model.py +++ b/src/pint/models/stand_alone_psr_binaries/DD_model.py @@ -1,4 +1,5 @@ """Damour and Deruelle binary model.""" + import astropy.constants as c import astropy.units as u import numpy as np @@ -756,10 +757,7 @@ def d_delayS_d_par(self, par): -2 * TM2 / logNum - * ( - e * sE - - self.SINI * (np.sqrt(1 - e**2) * cE * cOmega - sE * sOmega) - ) + * (e * sE - self.SINI * (np.sqrt(1 - e**2) * cE * cOmega - sE * sOmega)) ) domega_dpar = self.prtl_der("omega", par) dsDelay_domega = ( diff --git a/src/pint/models/stand_alone_psr_binaries/ELL1_model.py b/src/pint/models/stand_alone_psr_binaries/ELL1_model.py index b3fd8133d..d4b9cd8a0 100644 --- a/src/pint/models/stand_alone_psr_binaries/ELL1_model.py +++ b/src/pint/models/stand_alone_psr_binaries/ELL1_model.py @@ -1,4 +1,5 @@ """The ELL1 model for approximately handling near-circular orbits.""" + import astropy.constants as c import astropy.units as u import numpy as np diff --git a/src/pint/models/stand_alone_psr_binaries/ELL1k_model.py b/src/pint/models/stand_alone_psr_binaries/ELL1k_model.py index 0fe785988..ad5279152 100644 --- a/src/pint/models/stand_alone_psr_binaries/ELL1k_model.py +++ b/src/pint/models/stand_alone_psr_binaries/ELL1k_model.py @@ -1,4 +1,5 @@ """The ELL1k model for approximately handling near-circular orbits.""" + import astropy.constants as c import astropy.units as u import numpy as np diff --git a/src/pint/models/troposphere_delay.py b/src/pint/models/troposphere_delay.py index 911f2ad12..3a068709e 100644 --- a/src/pint/models/troposphere_delay.py +++ b/src/pint/models/troposphere_delay.py @@ -1,4 +1,5 @@ """Delay due to Earth's troposphere""" + import astropy.constants as const import astropy.units as u import numpy as np diff --git a/src/pint/observatory/global_clock_corrections.py b/src/pint/observatory/global_clock_corrections.py index 755895636..16eac7d81 100644 --- a/src/pint/observatory/global_clock_corrections.py +++ b/src/pint/observatory/global_clock_corrections.py @@ -12,6 +12,7 @@ to clear out old files you will want to do ``astropy.utils.data.clear_download_cache()``. """ + import collections import time from pathlib import Path diff --git a/src/pint/orbital/kepler.py b/src/pint/orbital/kepler.py index 9331d65cf..714bb56ab 100644 --- a/src/pint/orbital/kepler.py +++ b/src/pint/orbital/kepler.py @@ -2,6 +2,7 @@ All times are in days, distances in light-seconds, and masses in solar masses. """ + import collections import numpy as np @@ -246,11 +247,7 @@ def kepler_2d(params, t): r = a * (1 - e**2) / (1 + e * np.cos(true_anomaly)) r_prime = ( - a - * e - * (1 - e**2) - * np.sin(true_anomaly) - / (1 + e * np.cos(true_anomaly)) ** 2 + a * e * (1 - e**2) * np.sin(true_anomaly) / (1 + e * np.cos(true_anomaly)) ** 2 ) r_dot = r_prime * true_anomaly_dot d_a = np.array([1, 0, 0, 0, 0, 0]) diff --git a/src/pint/output/publish.py b/src/pint/output/publish.py index 2cb82b0ac..8db9e865e 100644 --- a/src/pint/output/publish.py +++ b/src/pint/output/publish.py @@ -1,4 +1,5 @@ """Generate LaTeX summary of a timing model and TOAs.""" + from pint.models import ( TimingModel, DispersionDMX, diff --git a/src/pint/pint_matrix.py b/src/pint/pint_matrix.py index 1900249ff..1521c7e8f 100644 --- a/src/pint/pint_matrix.py +++ b/src/pint/pint_matrix.py @@ -861,9 +861,7 @@ def __call__(self, data, model): """ func = getattr(model, self.cov_func_name) M = func(data) - label = [ - {self.covariance_quantity: (0, M.shape[0], self.quantity_unit**2)} - ] * 2 + label = [{self.covariance_quantity: (0, M.shape[0], self.quantity_unit**2)}] * 2 return CovarianceMatrix(M, label) @@ -907,9 +905,9 @@ def combine_covariance_matrix(covariance_matrices, crossterm={}, crossterm_paddi for ii, lb1 in enumerate(new_label): for jj, lb2 in enumerate(new_label): if ii == jj: - new_cm[ - lb1[1][0] : lb1[1][1], lb2[1][0] : lb2[1][1] - ] = covariance_matrices[ii].matrix + new_cm[lb1[1][0] : lb1[1][1], lb2[1][0] : lb2[1][1]] = ( + covariance_matrices[ii].matrix + ) else: if crossterm != {}: cross_m = crossterm.get((lb1, lb2), None) diff --git a/src/pint/pintk/colormodes.py b/src/pint/pintk/colormodes.py index 518509d68..a880ddd82 100644 --- a/src/pint/pintk/colormodes.py +++ b/src/pint/pintk/colormodes.py @@ -1,4 +1,5 @@ """ Color modes for graphed pintk TOAs. """ + import numpy as np import matplotlib import matplotlib.colors @@ -297,9 +298,9 @@ def get_obs_mapping(self): obs_name = "MeerKAT" else: obs_name = obs.upper() - obs_text[ - obs - ] = f" {obs_colors[obs].replace('xkcd:','').capitalize()} = {obs_name}" + obs_text[obs] = ( + f" {obs_colors[obs].replace('xkcd:','').capitalize()} = {obs_name}" + ) def displayInfo(self): outstr = '"Observatory" mode selected\n' diff --git a/src/pint/scripts/pintpublish.py b/src/pint/scripts/pintpublish.py index 69b551dc0..6d5b0142f 100644 --- a/src/pint/scripts/pintpublish.py +++ b/src/pint/scripts/pintpublish.py @@ -1,4 +1,5 @@ """Generate LaTeX summary of a timing model and TOAs.""" + from pint.models import get_model_and_toas from pint.output.publish import publish from pint.logging import setup as setup_log diff --git a/src/pint/templates/lcfitters.py b/src/pint/templates/lcfitters.py index 7b02365f8..f5868778f 100644 --- a/src/pint/templates/lcfitters.py +++ b/src/pint/templates/lcfitters.py @@ -14,6 +14,7 @@ author: M. Kerr """ + import numpy as np import scipy from pint.eventstats import hmw diff --git a/src/pint/templates/lcnorm.py b/src/pint/templates/lcnorm.py index dcab992aa..19c36e6e2 100644 --- a/src/pint/templates/lcnorm.py +++ b/src/pint/templates/lcnorm.py @@ -6,6 +6,7 @@ author: M. Kerr """ + import numpy as np # can some of the code be reduced with inheritance here? diff --git a/src/pint/toa_select.py b/src/pint/toa_select.py index 52d1c1c1a..59d861cc5 100644 --- a/src/pint/toa_select.py +++ b/src/pint/toa_select.py @@ -1,4 +1,5 @@ """Tool for selecting a subset of TOAs.""" + import numpy as np __all__ = ["TOASelect"] From 2ecaa2b72741e3b1a85e8995240250c99038edaa Mon Sep 17 00:00:00 2001 From: Abhimanyu Susobhanan Date: Wed, 7 Aug 2024 16:37:53 +0200 Subject: [PATCH 08/10] union --- src/pint/residuals.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pint/residuals.py b/src/pint/residuals.py index 2c094987f..9356a7ebf 100644 --- a/src/pint/residuals.py +++ b/src/pint/residuals.py @@ -9,7 +9,7 @@ import collections import copy -from typing import Literal, Optional +from typing import Literal, Optional, Union import warnings import astropy.units as u @@ -90,7 +90,7 @@ def __new__( toas: Optional[TOAs] = None, model: Optional[TimingModel] = None, residual_type: Literal["toa", "dm"] = "toa", - unit: u.Unit | str = u.s, + unit: Union[u.Unit, str] = u.s, subtract_mean: bool = True, use_weighted_mean: bool = True, track_mode: Optional[Literal["use_pulse_numbers", "nearest"]] = None, @@ -111,7 +111,7 @@ def __init__( toas: Optional[TOAs] = None, model: Optional[TimingModel] = None, residual_type: Literal["toa", "dm"] = "toa", - unit: u.Unit | str = u.s, + unit: Union[u.Unit, str] = u.s, subtract_mean: bool = True, use_weighted_mean: bool = True, track_mode: Optional[Literal["use_pulse_numbers", "nearest"]] = None, @@ -936,7 +936,7 @@ def __init__( toas: Optional[TOAs] = None, model: Optional[TimingModel] = None, residual_type: Literal["toa", "dm"] = "dm", - unit: u.Unit | str = u.pc / u.cm**3, + unit: Union[u.Unit, str] = u.pc / u.cm**3, subtract_mean: bool = False, use_weighted_mean: bool = True, ): From 4e5b5ca5e4d6536cfc4ec0db819a1ff963c4bf01 Mon Sep 17 00:00:00 2001 From: Deven Bhakta Date: Wed, 7 Aug 2024 12:42:27 -0400 Subject: [PATCH 09/10] CHANGELOG entry added --- CHANGELOG-unreleased.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG-unreleased.md b/CHANGELOG-unreleased.md index 017fdc2b2..c52a59440 100644 --- a/CHANGELOG-unreleased.md +++ b/CHANGELOG-unreleased.md @@ -19,6 +19,7 @@ the released changes. - Explicit type conversion in `woodbury_dot()` function - Documentation: Fixed empty descriptions in the timing model components table - BIC implementation +- `event_optimize`: Fixed a bug that was causing the results.txt file to be written without the median values. ### Removed - Removed the argument `--usepickle` in `event_optimize` as the `load_events_weights` function checks the events file type to see if the file is a pickle file. From 9517bc10533d4ed0fa0f037876f79352c18bd606 Mon Sep 17 00:00:00 2001 From: Abhimanyu Susobhanan Date: Thu, 8 Aug 2024 12:43:53 +0200 Subject: [PATCH 10/10] CHANGELOG --- CHANGELOG-unreleased.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG-unreleased.md b/CHANGELOG-unreleased.md index c52a59440..db597c37b 100644 --- a/CHANGELOG-unreleased.md +++ b/CHANGELOG-unreleased.md @@ -11,8 +11,9 @@ the released changes. ### Changed - Moved the events -> TOAs and photon weights code into the function `load_events_weights` within `event_optimize`. - Updated the `maxMJD` argument in `event_optimize` to default to the current mjd +- Bumped `black` version to 24.x ### Added -- Type hints in `pint.derived_quantities` +- Type hints in `pint.derived_quantities` and `pint.residuals` - Doing `model.par = something` will try to assign to `par.quantity` or `par.value` but will give warning - `PLChromNoise` component to model chromatic red noise with a power law spectrum ### Fixed