From 9fb746a86619c9e58056aff4977b1ea3e05ba885 Mon Sep 17 00:00:00 2001 From: Matteo Bachetti Date: Fri, 29 Sep 2023 08:28:06 +0200 Subject: [PATCH 1/5] The power type of Crossspectrum should be all by default --- stingray/crossspectrum.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stingray/crossspectrum.py b/stingray/crossspectrum.py index c5f909ac8..27a5e382e 100644 --- a/stingray/crossspectrum.py +++ b/stingray/crossspectrum.py @@ -547,7 +547,7 @@ def __init__( gti=None, lc1=None, lc2=None, - power_type="real", + power_type="all", dt=None, fullspec=False, skip_checks=False, From 9e1e9f2b8c81ff520c3c2bdee668eac9451e9e11 Mon Sep 17 00:00:00 2001 From: Matteo Bachetti Date: Fri, 29 Sep 2023 08:28:40 +0200 Subject: [PATCH 2/5] Use power type real where it should be used --- stingray/tests/test_crossspectrum.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stingray/tests/test_crossspectrum.py b/stingray/tests/test_crossspectrum.py index d434adc56..ceb8c1deb 100644 --- a/stingray/tests/test_crossspectrum.py +++ b/stingray/tests/test_crossspectrum.py @@ -869,7 +869,7 @@ def test_classical_significances_fails_in_rms(self): @pytest.mark.slow def test_classical_significances_threshold(self): with pytest.warns(UserWarning) as record: - cs = Crossspectrum(self.lc1, self.lc2, norm="leahy") + cs = Crossspectrum(self.lc1, self.lc2, norm="leahy", power_type="real") # change the powers so that just one exceeds the threshold cs.power = np.zeros_like(cs.power) + 2.0 @@ -886,7 +886,7 @@ def test_classical_significances_threshold(self): @pytest.mark.slow def test_classical_significances_trial_correction(self): with pytest.warns(UserWarning) as record: - cs = Crossspectrum(self.lc1, self.lc2, norm="leahy") + cs = Crossspectrum(self.lc1, self.lc2, norm="leahy", power_type="real") # change the powers so that just one exceeds the threshold cs.power = np.zeros_like(cs.power) + 2.0 index = 1 @@ -897,7 +897,7 @@ def test_classical_significances_trial_correction(self): def test_classical_significances_with_logbinned_psd(self): with pytest.warns(UserWarning) as record: - cs = Crossspectrum(self.lc1, self.lc2, norm="leahy") + cs = Crossspectrum(self.lc1, self.lc2, norm="leahy", power_type="real") cs_log = cs.rebin_log() pval = cs_log.classical_significances(threshold=1.1, trial_correction=False) @@ -905,7 +905,7 @@ def test_classical_significances_with_logbinned_psd(self): @pytest.mark.slow def test_pvals_is_numpy_array(self): - cs = Crossspectrum(self.lc1, self.lc2, norm="leahy") + cs = Crossspectrum(self.lc1, self.lc2, norm="leahy", power_type="real") # change the powers so that just one exceeds the threshold cs.power = np.zeros_like(cs.power) + 2.0 From 7b284ac1377ccdc010f26d13bdb8841c0aee1e49 Mon Sep 17 00:00:00 2001 From: Matteo Bachetti Date: Fri, 29 Sep 2023 10:35:07 +0200 Subject: [PATCH 3/5] Fix tests using the Crossspectrum to calculate lags --- stingray/simulator/tests/test_simulator.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stingray/simulator/tests/test_simulator.py b/stingray/simulator/tests/test_simulator.py index 25c9d68ac..053f37b06 100644 --- a/stingray/simulator/tests/test_simulator.py +++ b/stingray/simulator/tests/test_simulator.py @@ -39,7 +39,7 @@ def calculate_lag(self, lc, h, delay): lc1 = Lightcurve(time, s) lc2 = Lightcurve(time, output) - cross = Crossspectrum(lc1, lc2) + cross = Crossspectrum(lc2, lc1) cross = cross.rebin(0.0075) return np.angle(cross.power) / (2 * np.pi * cross.freq) @@ -559,7 +559,7 @@ def test_position_varying_channels(self): outputs.append(lc2) with pytest.warns(UserWarning, match="Your lightcurves have different statistics"): - cross = [Crossspectrum(lc, lc2).rebin(0.0075) for lc2 in outputs] + cross = [Crossspectrum(lc2, lc).rebin(0.0075) for lc2 in outputs] lags = [np.angle(c.power) / (2 * np.pi * c.freq) for c in cross] v_cutoffs = [1.0 / (2.0 * 5), 1.0 / (2.0 * 10)] @@ -588,7 +588,7 @@ def test_intensity_varying_channels(self): outputs.append(lc2) with pytest.warns(UserWarning, match="Your lightcurves have different statistics"): - cross = [Crossspectrum(lc, lc2).rebin(0.0075) for lc2 in outputs] + cross = [Crossspectrum(lc2, lc).rebin(0.0075) for lc2 in outputs] lags = [np.angle(c.power) / (2 * np.pi * c.freq) for c in cross] v_cutoff = 1.0 / (2.0 * 5) From 5245470bf77a01cd9c59434f308c77702daf68d0 Mon Sep 17 00:00:00 2001 From: Matteo Bachetti Date: Fri, 29 Sep 2023 11:10:06 +0200 Subject: [PATCH 4/5] Add changelog --- docs/changes/762.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/changes/762.bugfix.rst diff --git a/docs/changes/762.bugfix.rst b/docs/changes/762.bugfix.rst new file mode 100644 index 000000000..a449dfe71 --- /dev/null +++ b/docs/changes/762.bugfix.rst @@ -0,0 +1 @@ +Crossspectrum had "real" as default value. This meant that, for example, lags could not be calculated. Now the default value is "all", as it should be. From 53242112d0cf2c4e38a9fdd67e949895259d386e Mon Sep 17 00:00:00 2001 From: Matteo Bachetti Date: Sun, 1 Oct 2023 08:37:21 +0200 Subject: [PATCH 5/5] blacken --- stingray/modeling/gpmodeling.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/stingray/modeling/gpmodeling.py b/stingray/modeling/gpmodeling.py index 360272373..6ee794c2d 100644 --- a/stingray/modeling/gpmodeling.py +++ b/stingray/modeling/gpmodeling.py @@ -37,8 +37,7 @@ tfp_available = False -__all__ = ["get_kernel", "get_mean", "get_prior", - "get_log_likelihood", "GPResult", "get_gp_params"] +__all__ = ["get_kernel", "get_mean", "get_prior", "get_log_likelihood", "GPResult", "get_gp_params"] def get_kernel(kernel_type, kernel_params): @@ -575,8 +574,7 @@ def __init__(self, lc: Lightcurve) -> None: self.counts = lc.counts self.result = None - def sample(self, prior_model=None, likelihood_model=None, max_samples=1e4, - num_live_points=500): + def sample(self, prior_model=None, likelihood_model=None, max_samples=1e4, num_live_points=500): """ Makes a Jaxns nested sampler over the Gaussian Process, given the prior and likelihood model @@ -619,7 +617,9 @@ def sample(self, prior_model=None, likelihood_model=None, max_samples=1e4, nsmodel = Model(prior_model=self.prior_model, log_likelihood=self.log_likelihood_model) nsmodel.sanity_check(random.PRNGKey(10), S=100) - self.exact_ns = ExactNestedSampler(nsmodel, num_live_points=num_live_points, max_samples=max_samples) + self.exact_ns = ExactNestedSampler( + nsmodel, num_live_points=num_live_points, max_samples=max_samples + ) termination_reason, state = self.exact_ns( random.PRNGKey(42), term_cond=TerminationCondition(live_evidence_frac=1e-4)