From 6df25ff37812794e3750ab19927e2f052418537c Mon Sep 17 00:00:00 2001 From: Abhimanyu Susobhanan Date: Mon, 13 Feb 2023 16:26:45 -0600 Subject: [PATCH 1/3] fix conjunction function --- src/pint/models/timing_model.py | 13 +++++++++---- src/pint/pintk/plk.py | 9 +++------ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/pint/models/timing_model.py b/src/pint/models/timing_model.py index 55d0d2473..797170810 100644 --- a/src/pint/models/timing_model.py +++ b/src/pint/models/timing_model.py @@ -752,6 +752,14 @@ def funct(t): scs = [] for bt in bts: # Make 11 times over one orbit after bt + if self.PB.value is not None: + pb = self.PB.value + elif self.FB0.quantity is not None: + pb = (1 / self.FB0.quantity).to("day").value + else: + raise AttributeError( + "Neither PB nor FB0 is present in the timing model." + ) ts = np.linspace(bt, bt + self.PB.value, 11) # Compute the true anomalies and omegas for those times nus = self.orbital_phase(ts, anom="true") @@ -763,10 +771,7 @@ def funct(t): break # Now use scipy to find the root scs.append(brentq(funct, ts[lb], ts[lb + 1])) - if len(scs) == 1: - return scs[0] # Return a float - else: - return np.asarray(scs) # otherwise return an array + return scs[0] if len(scs) == 1 else np.asarray(scs) @property_exists def dm_funcs(self): diff --git a/src/pint/pintk/plk.py b/src/pint/pintk/plk.py index 63564dddf..f1ce099c8 100644 --- a/src/pint/pintk/plk.py +++ b/src/pint/pintk/plk.py @@ -392,10 +392,7 @@ def __init__(self, master): self.fitterSelect.bind("<>", self.changeFitter) def updateFitterChoices(self, wideband): - if wideband: - self.fitterSelect["values"] = wb_fitters - else: - self.fitterSelect["values"] = nb_fitters + self.fitterSelect["values"] = wb_fitters if wideband else nb_fitters def changeFitter(self, event): self.fitter = self.fitterSelect.get() # get current value @@ -438,7 +435,7 @@ def addColorModeCheckbox(self, colorModes): model = self.master.psr.postfit_model else: model = self.master.psr.prefit_model - if not "PhaseJump" in model.components: + if "PhaseJump" not in model.components: self.checkboxes[index].configure(state="disabled") self.updateLayout() @@ -670,7 +667,7 @@ class PlkWidget(tk.Frame): def __init__(self, master=None, **kwargs): tk.Frame.__init__(self, master) self.configure(bg=background) - self.init_loglevel = kwargs["loglevel"] if "loglevel" in kwargs else None + self.init_loglevel = kwargs.get("loglevel") self.initPlk() self.initPlkLayout() self.current_state = State() From a25df2f6098c5321c4c9eb902da009a199e5ae7b Mon Sep 17 00:00:00 2001 From: Abhimanyu Susobhanan Date: Mon, 13 Feb 2023 16:36:25 -0600 Subject: [PATCH 2/3] fix plotting --- src/pint/models/timing_model.py | 2 +- src/pint/pintk/plk.py | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/pint/models/timing_model.py b/src/pint/models/timing_model.py index 797170810..d371c5aa1 100644 --- a/src/pint/models/timing_model.py +++ b/src/pint/models/timing_model.py @@ -760,7 +760,7 @@ def funct(t): raise AttributeError( "Neither PB nor FB0 is present in the timing model." ) - ts = np.linspace(bt, bt + self.PB.value, 11) + ts = np.linspace(bt, bt + pb, 11) # Compute the true anomalies and omegas for those times nus = self.orbital_phase(ts, anom="true") omegas = bbi.omega() diff --git a/src/pint/pintk/plk.py b/src/pint/pintk/plk.py index f1ce099c8..044bf87e4 100644 --- a/src/pint/pintk/plk.py +++ b/src/pint/pintk/plk.py @@ -1095,7 +1095,15 @@ def plotResiduals(self, keepAxes=False): # Get the time of conjunction after T0 or TASC tt = m.T0.value if hasattr(m, "T0") else m.TASC.value mjd = m.conjunction(tt) - phs = (mjd - tt) * u.day / m.PB + if m.PB.value is not None: + pb = m.PB.value + elif m.FB0.quantity is not None: + pb = (1 / m.FB0.quantity).to("day").value + else: + raise AttributeError( + "Neither PB nor FB0 is present in the timing model." + ) + phs = (mjd - tt) / pb self.plkAxes.plot([phs, phs], [ymin, ymax], "k-") else: self.plkAxes.set_ylabel(plotlabels[self.yid]) From 8b8c3b94ec8cfede6b97a6c2447e47e4aebf34f2 Mon Sep 17 00:00:00 2001 From: Abhimanyu Susobhanan Date: Tue, 14 Feb 2023 08:44:59 -0600 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a7f1c2c7c..0cd5b6baa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ and this project, at least loosely, adheres to [Semantic Versioning](https://sem - BIPM correction for simulated TOAs - Added try/except to `test_pldmnoise.py`/`test_PLRedNoise_recovery` to avoid exceptions during CI - Import for `longdouble2str` in `get_tempo_result` +- Plotting orbital phase in `pintk` when FB0 is used instead of PB ### Removed ## [0.9.3] 2022-12-16