Skip to content

Commit

Permalink
Merge pull request #762 from StingraySoftware/fix_crossspectrum_all_d…
Browse files Browse the repository at this point in the history
…efault

Fix crossspectrum all default
  • Loading branch information
matteobachetti authored Oct 5, 2023
2 parents 34e6a94 + 5324211 commit 0f746f6
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
1 change: 1 addition & 0 deletions docs/changes/762.bugfix.rst
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion stingray/crossspectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions stingray/modeling/gpmodeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions stingray/simulator/tests/test_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions stingray/tests/test_crossspectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -897,15 +897,15 @@ 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)

assert len(pval[0]) == len(cs_log.power)

@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

Expand Down

0 comments on commit 0f746f6

Please sign in to comment.