From fbb6275dc5119995235c606063af524a59407a8e Mon Sep 17 00:00:00 2001 From: andresgur Date: Sun, 30 Mar 2025 12:43:29 +0100 Subject: [PATCH 01/15] Changed valid statistic None to 'None' --- stingray/lightcurve.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stingray/lightcurve.py b/stingray/lightcurve.py index c6cff03b6..b2380ba64 100644 --- a/stingray/lightcurve.py +++ b/stingray/lightcurve.py @@ -39,7 +39,7 @@ __all__ = ["Lightcurve"] -valid_statistics = ["poisson", "gauss", None] +valid_statistics = ["poisson", "gauss", "None"] logger = setup_logger() From e3b60843e7709cc26684882ea7c5eb3c86d3cb94 Mon Sep 17 00:00:00 2001 From: andresgur Date: Sun, 30 Mar 2025 12:45:02 +0100 Subject: [PATCH 02/15] Made 'none' default err_dist to reflect doc --- stingray/lightcurve.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stingray/lightcurve.py b/stingray/lightcurve.py index b2380ba64..6e13a9d70 100644 --- a/stingray/lightcurve.py +++ b/stingray/lightcurve.py @@ -215,7 +215,7 @@ def __init__( err=None, input_counts=True, gti=None, - err_dist="poisson", + err_dist="none", bg_counts=None, bg_ratio=None, frac_exp=None, From a03a85b3a6fd0f16fecec3e667c680f6347b78d5 Mon Sep 17 00:00:00 2001 From: andresgur Date: Thu, 3 Apr 2025 23:19:16 +0100 Subject: [PATCH 03/15] Fixed valid_statistics, changed 'None' to 'none' in Lightcurve --- stingray/lightcurve.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stingray/lightcurve.py b/stingray/lightcurve.py index 6e13a9d70..8f0d58c01 100644 --- a/stingray/lightcurve.py +++ b/stingray/lightcurve.py @@ -39,7 +39,7 @@ __all__ = ["Lightcurve"] -valid_statistics = ["poisson", "gauss", "None"] +valid_statistics = ["poisson", "gauss", "none"] logger = setup_logger() From 099a1f5443032867dbbbe318c1526614930dd7c3 Mon Sep 17 00:00:00 2001 From: Matteo Bachetti Date: Sat, 5 Apr 2025 17:20:11 +0200 Subject: [PATCH 04/15] Avoid breaking the API, and improve consistency --- stingray/lightcurve.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/stingray/lightcurve.py b/stingray/lightcurve.py index 8f0d58c01..a186811bd 100644 --- a/stingray/lightcurve.py +++ b/stingray/lightcurve.py @@ -215,7 +215,7 @@ def __init__( err=None, input_counts=True, gti=None, - err_dist="none", + err_dist=None, bg_counts=None, bg_ratio=None, frac_exp=None, @@ -275,6 +275,9 @@ def __init__( if not skip_checks: time, counts, err = self.initial_optional_checks(time, counts, err, gti=gti) + if err_dist is None: + err_dist = "none" + if err_dist.lower() not in valid_statistics: # err_dist set can be increased with other statistics raise StingrayError( @@ -283,10 +286,8 @@ def __init__( ) elif not err_dist.lower() == "poisson": simon( - "Stingray only uses poisson err_dist at the moment. " - "All analysis in the light curve will assume Poisson " - "errors. " - "Sorry for the inconvenience." + "Beware! Stingray only supports poisson err_dist at the moment in many methods" + ", and 'gauss' in a few more. " ) self._time = time From 2531bf57c5d25120b4d35ae8eb9417bd293c8380 Mon Sep 17 00:00:00 2001 From: Matteo Bachetti Date: Sun, 6 Apr 2025 00:38:13 +0200 Subject: [PATCH 05/15] If the input is counts, the err_dist should be Poisson --- stingray/lightcurve.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/stingray/lightcurve.py b/stingray/lightcurve.py index a186811bd..8e35595ea 100644 --- a/stingray/lightcurve.py +++ b/stingray/lightcurve.py @@ -275,7 +275,9 @@ def __init__( if not skip_checks: time, counts, err = self.initial_optional_checks(time, counts, err, gti=gti) - if err_dist is None: + if err_dist is None and input_counts: + err_dist = "poisson" + else: err_dist = "none" if err_dist.lower() not in valid_statistics: From 5d204fc82555da4381e908e6c7633d2bfccc1b5c Mon Sep 17 00:00:00 2001 From: Matteo Bachetti Date: Sun, 6 Apr 2025 11:02:00 +0200 Subject: [PATCH 06/15] Fix bug when defining default err_dist --- stingray/lightcurve.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stingray/lightcurve.py b/stingray/lightcurve.py index 8e35595ea..d9c3a080d 100644 --- a/stingray/lightcurve.py +++ b/stingray/lightcurve.py @@ -277,7 +277,7 @@ def __init__( if err_dist is None and input_counts: err_dist = "poisson" - else: + elif err_dist is None: err_dist = "none" if err_dist.lower() not in valid_statistics: From 538f23fc37c8c889c19f8ca54219e35f11917a1f Mon Sep 17 00:00:00 2001 From: andresgur Date: Tue, 8 Apr 2025 04:40:01 +0100 Subject: [PATCH 07/15] Added .rst for PR 909 --- docs/changes/909.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/changes/909.bugfix.rst diff --git a/docs/changes/909.bugfix.rst b/docs/changes/909.bugfix.rst new file mode 100644 index 000000000..19c829fc5 --- /dev/null +++ b/docs/changes/909.bugfix.rst @@ -0,0 +1 @@ +Fix ligthcurve breaking when err_dist=None and changed default err_dist to None to match docs From 61dee3c933170475aa105601c5e8609458d82fb3 Mon Sep 17 00:00:00 2001 From: andresgur Date: Tue, 8 Apr 2025 17:59:29 +0100 Subject: [PATCH 08/15] Added err_dist=poiss to avoid warnings crashing tests --- stingray/sampledata.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stingray/sampledata.py b/stingray/sampledata.py index 75c3dd92b..cee8331e7 100644 --- a/stingray/sampledata.py +++ b/stingray/sampledata.py @@ -24,4 +24,4 @@ def sample_data(): counts = data[0 : len(data), 1] # Return class:`Lightcurve` object - return lightcurve.Lightcurve(dates, counts, dt=dt, skip_checks=True) + return lightcurve.Lightcurve(dates, counts, dt=dt, skip_checks=True, err_dist="poisson") From 4dc40bcfa1c952818d945b69a68b28374210f32a Mon Sep 17 00:00:00 2001 From: andresgur Date: Tue, 8 Apr 2025 18:49:43 +0100 Subject: [PATCH 09/15] Fixed warnings related to err_dist=none not passing tests in test_simulator --- stingray/simulator/tests/test_simulator.py | 161 +++++++++++++-------- stingray/tests/test_crosscorrelation.py | 18 +-- stingray/tests/test_lombscargle.py | 24 +-- stingray/tests/test_varenergyspectrum.py | 15 +- 4 files changed, 130 insertions(+), 88 deletions(-) diff --git a/stingray/simulator/tests/test_simulator.py b/stingray/simulator/tests/test_simulator.py index 053f37b06..beb17c225 100644 --- a/stingray/simulator/tests/test_simulator.py +++ b/stingray/simulator/tests/test_simulator.py @@ -32,7 +32,8 @@ def calculate_lag(self, lc, h, delay): Class method to calculate lag between two light curves. """ s = lc.counts - output = self.simulator.simulate(s, h, "same")[delay:] + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + output = self.simulator.simulate(s, h, "same")[delay:] s = s[delay:] time = lc.time[delay:] output = output.counts @@ -51,7 +52,8 @@ def test_simulate_with_seed(self): self.simulator = Simulator( N=self.N, mean=self.mean, dt=self.dt, rms=self.rms, random_state=12 ) - assert len(self.simulator.simulate(2).counts), self.N + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + assert len(self.simulator.simulate(2).counts), self.N def test_simulate_with_tstart(self): """ @@ -80,28 +82,32 @@ def test_simulate_channel(self): """ Simulate an energy channel. """ - self.simulator.simulate_channel("3.5-4.5", "generalized_lorentzian", [1, 2, 3, 4]) + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + self.simulator.simulate_channel("3.5-4.5", "generalized_lorentzian", [1, 2, 3, 4]) self.simulator.delete_channel("3.5-4.5") def test_simulate_channel_odd(self): """ Simulate an energy channel. """ - self.simulator_odd.simulate_channel("3.5-4.5", "generalized_lorentzian", [1, 2, 3, 4]) + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + self.simulator_odd.simulate_channel("3.5-4.5", "generalized_lorentzian", [1, 2, 3, 4]) self.simulator_odd.delete_channel("3.5-4.5") def test_incorrect_simulate_channel(self): """Test simulating a channel that already exists.""" - self.simulator.simulate_channel("3.5-4.5", 2) - with pytest.raises(KeyError): + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): self.simulator.simulate_channel("3.5-4.5", 2) + with pytest.raises(KeyError): + self.simulator.simulate_channel("3.5-4.5", 2) self.simulator.delete_channel("3.5-4.5") def test_get_channel(self): """ Retrieve an energy channel after it has been simulated. """ - self.simulator.simulate_channel("3.5-4.5", 2) + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + self.simulator.simulate_channel("3.5-4.5", 2) lc = self.simulator.get_channel("3.5-4.5") self.simulator.delete_channel("3.5-4.5") @@ -109,16 +115,18 @@ def test_get_channels(self): """ Retrieve multiple energy channel after it has been simulated. """ - self.simulator.simulate_channel("3.5-4.5", 2) - self.simulator.simulate_channel("4.5-5.5", "smoothbknpo", [1, 2, 3, 4]) + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + self.simulator.simulate_channel("3.5-4.5", 2) + self.simulator.simulate_channel("4.5-5.5", "smoothbknpo", [1, 2, 3, 4]) lc = self.simulator.get_channels(["3.5-4.5", "4.5-5.5"]) self.simulator.delete_channels(["3.5-4.5", "4.5-5.5"]) def test_get_all_channels(self): """Retrieve all energy channels.""" - self.simulator.simulate_channel("3.5-4.5", 2) - self.simulator.simulate_channel("4.5-5.5", 1) + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + self.simulator.simulate_channel("3.5-4.5", 2) + self.simulator.simulate_channel("4.5-5.5", 1) lc = self.simulator.get_all_channels() self.simulator.delete_channels(["3.5-4.5", "4.5-5.5"]) @@ -127,8 +135,9 @@ def test_count_channels(self): """ Count energy channels after they have been simulated. """ - self.simulator.simulate_channel("3.5-4.5", 2) - self.simulator.simulate_channel("4.5-5.5", 1) + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + self.simulator.simulate_channel("3.5-4.5", 2) + self.simulator.simulate_channel("4.5-5.5", 1) assert self.simulator.count_channels() == 2 self.simulator.delete_channels(["3.5-4.5", "4.5-5.5"]) @@ -173,8 +182,8 @@ def test_rms_and_mean(self, model_kind): model = astropy_model(freq_fine) elif model_kind == "float": model = 2.0 - - lc_all = [self.simulator.simulate(model) for i in range(nsim)] + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + lc_all = [self.simulator.simulate(model) for i in range(nsim)] mean_all = np.mean([np.mean(lc.counts) for lc in lc_all]) std_all = np.mean([np.std(lc.counts) for lc in lc_all]) @@ -195,7 +204,8 @@ def test_rms_zero_mean(self): mean = 0.0 with pytest.warns(UserWarning, match="Careful! A mean of zero is unphysical!"): sim = Simulator(dt=self.dt, N=self.N, rms=self.rms, mean=mean) - lc_all = [sim.simulate(-2.0) for i in range(nsim)] + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + lc_all = [sim.simulate(-2.0) for i in range(nsim)] mean_all = np.mean([np.mean(lc.counts) for lc in lc_all]) std_all = np.mean([np.std(lc.counts) for lc in lc_all]) @@ -207,13 +217,15 @@ def test_simulate_powerlaw(self): """ Simulate light curve from power law spectrum. """ - assert len(self.simulator.simulate(2).counts), 1024 + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + assert len(self.simulator.simulate(2).counts), 1024 def test_simulate_powerlaw_odd(self): """ Simulate light curve from power law spectrum. """ - assert len(self.simulator_odd.simulate(2).counts), 2039 + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + assert len(self.simulator_odd.simulate(2).counts), 2039 def test_compare_powerlaw(self): """ @@ -222,7 +234,8 @@ def test_compare_powerlaw(self): B, N, red_noise, dt = 2, 1024, 10, 1 self.simulator = Simulator(N=N, dt=dt, mean=5, rms=1, red_noise=red_noise) - lc = [self.simulator.simulate(B) for i in range(1, 30)] + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + lc = [self.simulator.simulate(B) for i in range(1, 30)] simulated = self.simulator.powerspectrum(lc, lc[0].tseg) w = np.fft.rfftfreq(N, d=dt)[1:] @@ -238,7 +251,8 @@ def test_simulate_powerspectrum(self): Simulate light curve from any power spectrum. """ s = np.random.rand(1024) - assert len(self.simulator.simulate(s)), self.N + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + assert len(self.simulator.simulate(s)), self.N def test_simulate_model_pars_not_list_or_dict(self): """ @@ -252,13 +266,15 @@ def test_simulate_lorentzian(self): """ Simulate light curve using lorentzian model. """ - assert len(self.simulator.simulate("generalized_lorentzian", [1, 2, 3, 4])), 1024 + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + assert len(self.simulator.simulate("generalized_lorentzian", [1, 2, 3, 4])), 1024 def test_simulate_lorentzian_odd(self): """ Simulate light curve using lorentzian model. """ - assert len(self.simulator_odd.simulate("generalized_lorentzian", [1, 2, 3, 4])), 1024 + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + assert len(self.simulator_odd.simulate("generalized_lorentzian", [1, 2, 3, 4])), 1024 def test_compare_lorentzian(self): """ @@ -267,10 +283,11 @@ def test_compare_lorentzian(self): N, red_noise, dt = 1024, 10, 1 self.simulator = Simulator(N=N, dt=dt, mean=0.1, rms=0.4, red_noise=red_noise) - lc = [ - self.simulator.simulate("generalized_lorentzian", [0.3, 0.9, 0.6, 0.5]) - for i in range(1, 30) - ] + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + lc = [ + self.simulator.simulate("generalized_lorentzian", [0.3, 0.9, 0.6, 0.5]) + for i in range(1, 30) + ] simulated = self.simulator.powerspectrum(lc, lc[0].tseg) w = np.fft.rfftfreq(N, d=dt)[1:] @@ -285,7 +302,8 @@ def test_simulate_smoothbknpo(self): """ Simulate light curve using smooth broken power law model. """ - assert len(self.simulator.simulate("smoothbknpo", [1, 2, 3, 4])), 1024 + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + assert len(self.simulator.simulate("smoothbknpo", [1, 2, 3, 4])), 1024 def test_compare_smoothbknpo(self): """ @@ -295,7 +313,8 @@ def test_compare_smoothbknpo(self): N, red_noise, dt = 1024, 10, 1 self.simulator = Simulator(N=N, dt=dt, mean=0.1, rms=0.7, red_noise=red_noise) - lc = [self.simulator.simulate("smoothbknpo", [0.6, 0.2, 0.6, 0.5]) for i in range(1, 30)] + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + lc = [self.simulator.simulate("smoothbknpo", [0.6, 0.2, 0.6, 0.5]) for i in range(1, 30)] simulated = self.simulator.powerspectrum(lc, lc[0].tseg) @@ -312,22 +331,24 @@ def test_simulate_GeneralizedLorentz1D_str(self): Simulate a light curve using the GeneralizedLorentz1D model called as a string """ - assert len( - self.simulator.simulate( - "GeneralizedLorentz1D", {"x_0": 10, "fwhm": 1.0, "value": 10.0, "power_coeff": 2} - ) - ), 1024 + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + assert len( + self.simulator.simulate( + "GeneralizedLorentz1D", {"x_0": 10, "fwhm": 1.0, "value": 10.0, "power_coeff": 2} + ) + ), 1024 def test_simulate_GeneralizedLorentz1D_odd_str(self): """ Simulate a light curve using the GeneralizedLorentz1D model called as a string """ - assert len( - self.simulator_odd.simulate( - "GeneralizedLorentz1D", {"x_0": 10, "fwhm": 1.0, "value": 10.0, "power_coeff": 2} - ) - ), 2039 + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + assert len( + self.simulator_odd.simulate( + "GeneralizedLorentz1D", {"x_0": 10, "fwhm": 1.0, "value": 10.0, "power_coeff": 2} + ) + ), 2039 def test_simulate_GeneralizedLorentz1D(self): """ @@ -335,19 +356,21 @@ def test_simulate_GeneralizedLorentz1D(self): called as a astropy.modeling.Model class """ mod = models.GeneralizedLorentz1D(x_0=10, fwhm=1.0, value=10.0, power_coeff=2) - assert len(self.simulator.simulate(mod)), 1024 + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + assert len(self.simulator.simulate(mod)), 1024 def test_simulate_SmoothBrokenPowerLaw_str(self): """ Simulate a light curve using SmoothBrokenPowerLaw model called as a string """ - assert len( - self.simulator.simulate( - "SmoothBrokenPowerLaw", - {"norm": 1.0, "gamma_low": 1.0, "gamma_high": 2.0, "break_freq": 1.0}, - ) - ), 1024 + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + assert len( + self.simulator.simulate( + "SmoothBrokenPowerLaw", + {"norm": 1.0, "gamma_low": 1.0, "gamma_high": 2.0, "break_freq": 1.0}, + ) + ), 1024 def test_simulate_SmoothBrokenPowerLaw(self): """ @@ -355,7 +378,8 @@ def test_simulate_SmoothBrokenPowerLaw(self): called as a astropy.modeling.Model class """ mod = models.SmoothBrokenPowerLaw(norm=1.0, gamma_low=1.0, gamma_high=2.0, break_freq=1.0) - assert len(self.simulator.simulate(mod)), 1024 + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + assert len(self.simulator.simulate(mod)), 1024 def test_simulate_generic_model(self): """ @@ -363,7 +387,8 @@ def test_simulate_generic_model(self): called as a astropy.modeling.Model class """ mod = astropy.modeling.models.Gaussian1D(amplitude=10.0, mean=1.0, stddev=2.0) - assert len(self.simulator.simulate(mod)), 1024 + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + assert len(self.simulator.simulate(mod)), 1024 def test_simulate_generic_model_odd(self): """ @@ -371,7 +396,8 @@ def test_simulate_generic_model_odd(self): called as a astropy.modeling.Model class """ mod = astropy.modeling.models.Gaussian1D(amplitude=10.0, mean=1.0, stddev=2.0) - assert len(self.simulator_odd.simulate(mod)), 2039 + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + assert len(self.simulator_odd.simulate(mod)), 2039 @pytest.mark.parametrize("poisson", [True, False]) def test_compare_composite(self, poisson): @@ -451,7 +477,8 @@ def test_simulate_simple_impulse(self): lc = sampledata.sample_data() s = lc.counts h = self.simulator.simple_ir(10, 1, 1) - _ = self.simulator.simulate(s, h) + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + _ = self.simulator.simulate(s, h) def test_simulate_simple_impulse_odd(self): """ @@ -460,20 +487,23 @@ def test_simulate_simple_impulse_odd(self): lc = sampledata.sample_data() s = lc.counts h = self.simulator_odd.simple_ir(10, 1, 1) - _ = self.simulator_odd.simulate(s, h) + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + _ = self.simulator_odd.simulate(s, h) def test_powerspectrum(self): """ Create a power spectrum from light curve. """ - lc = self.simulator.simulate(2) + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + lc = self.simulator.simulate(2) self.simulator.powerspectrum(lc) def test_powerspectrum_odd(self): """ Create a power spectrum from light curve. """ - lc = self.simulator_odd.simulate(2) + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + lc = self.simulator_odd.simulate(2) self.simulator_odd.powerspectrum(lc) def test_simulate_relativistic_impulse(self): @@ -484,7 +514,8 @@ def test_simulate_relativistic_impulse(self): s = lc.counts h = self.simulator.relativistic_ir() - output = self.simulator.simulate(s, h) + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + output = self.simulator.simulate(s, h) def test_filtered_simulate(self): """ @@ -494,7 +525,8 @@ def test_filtered_simulate(self): s = lc.counts h = self.simulator.simple_ir() - output = self.simulator.simulate(s, h, "filtered") + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + output = self.simulator.simulate(s, h, "filtered") def test_filtered_simulate_odd(self): """ @@ -504,7 +536,8 @@ def test_filtered_simulate_odd(self): s = lc.counts h = self.simulator_odd.simple_ir() - output = self.simulator_odd.simulate(s, h, "filtered") + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + output = self.simulator_odd.simulate(s, h, "filtered") def test_simple_lag_spectrum(self): """ @@ -553,10 +586,11 @@ def test_position_varying_channels(self): delays = [int(5 / lc.dt), int(10 / lc.dt)] outputs = [] - for i in h: - lc2 = self.simulator.simulate(s, i) - lc2 = lc2.shift(-lc2.time[0] + lc.time[0]) - outputs.append(lc2) + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + for i in h: + lc2 = self.simulator.simulate(s, i) + lc2 = lc2.shift(-lc2.time[0] + lc.time[0]) + outputs.append(lc2) with pytest.warns(UserWarning, match="Your lightcurves have different statistics"): cross = [Crossspectrum(lc2, lc).rebin(0.0075) for lc2 in outputs] @@ -582,10 +616,11 @@ def test_intensity_varying_channels(self): delay = int(5 / lc.dt) outputs = [] - for i in h: - lc2 = self.simulator.simulate(s, i) - lc2 = lc2.shift(-lc2.time[0] + lc.time[0]) - outputs.append(lc2) + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + for i in h: + lc2 = self.simulator.simulate(s, i) + lc2 = lc2.shift(-lc2.time[0] + lc.time[0]) + outputs.append(lc2) with pytest.warns(UserWarning, match="Your lightcurves have different statistics"): cross = [Crossspectrum(lc2, lc).rebin(0.0075) for lc2 in outputs] diff --git a/stingray/tests/test_crosscorrelation.py b/stingray/tests/test_crosscorrelation.py index 6545bc27d..1479a1554 100644 --- a/stingray/tests/test_crosscorrelation.py +++ b/stingray/tests/test_crosscorrelation.py @@ -23,9 +23,9 @@ def setup_class(cls): freq = 1 / 50 flux1 = 0.5 + 0.5 * np.sin(2 * np.pi * freq * times) flux2 = 0.5 + 0.5 * np.sin(2 * np.pi * freq * (times - 20)) - - cls.lc1 = Lightcurve(times, flux1, dt=dt, err_dist="gauss", gti=gti, skip_checks=True) - cls.lc2 = Lightcurve(times, flux2, dt=dt, err_dist="gauss", gti=gti, skip_checks=True) + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + cls.lc1 = Lightcurve(times, flux1, dt=dt, err_dist="gauss", gti=gti, skip_checks=True) + cls.lc2 = Lightcurve(times, flux2, dt=dt, err_dist="gauss", gti=gti, skip_checks=True) def test_crosscorr(self): cr = CrossCorrelation(self.lc1, self.lc2) @@ -41,16 +41,16 @@ def test_crosscorr_norm(self): class TestCrossCorrelation(object): @classmethod def setup_class(cls): - cls.lc1 = Lightcurve([1, 2, 3, 4, 5], [2, 3, 2, 4, 1]) - cls.lc2 = Lightcurve([1, 2, 3, 4, 5], [4, 8, 1, 9, 11]) + cls.lc1 = Lightcurve([1, 2, 3, 4, 5], [2, 3, 2, 4, 1], err_dist="poisson") + cls.lc2 = Lightcurve([1, 2, 3, 4, 5], [4, 8, 1, 9, 11], err_dist="poisson") # Smaller Light curve - cls.lc_s = Lightcurve([1, 2, 3], [5, 3, 2]) + cls.lc_s = Lightcurve([1, 2, 3], [5, 3, 2], err_dist="poisson") # lc with different time resolution - cls.lc_u = Lightcurve([1, 3, 5, 7, 9], [4, 8, 1, 9, 11]) + cls.lc_u = Lightcurve([1, 3, 5, 7, 9], [4, 8, 1, 9, 11], err_dist="poisson") # Light curve with odd number of data points - cls.lc_odd = Lightcurve([1, 2, 3, 4, 5], [2, 3, 2, 4, 1]) + cls.lc_odd = Lightcurve([1, 2, 3, 4, 5], [2, 3, 2, 4, 1], err_dist="poisson") # Light curve with even number of data points - cls.lc_even = Lightcurve([1, 2, 3, 4, 5, 6], [2, 3, 2, 4, 1, 3]) + cls.lc_even = Lightcurve([1, 2, 3, 4, 5, 6], [2, 3, 2, 4, 1, 3], err_dist="poisson") def test_empty_cross_correlation(self): cr = CrossCorrelation() diff --git a/stingray/tests/test_lombscargle.py b/stingray/tests/test_lombscargle.py index 27e2beb52..daa06ff84 100644 --- a/stingray/tests/test_lombscargle.py +++ b/stingray/tests/test_lombscargle.py @@ -35,8 +35,9 @@ def test_autofrequency(): class TestLombScargleCrossspectrum: def setup_class(self): sim = Simulator(0.0001, 50, 100, 1, random_state=42, tstart=0) - lc1 = sim.simulate(0) - lc2 = sim.simulate(0) + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + lc1 = sim.simulate(0) + lc2 = sim.simulate(0) self.rate1 = lc1.countrate self.rate2 = lc2.countrate low, high = lc1.time.min(), lc1.time.max() @@ -48,15 +49,15 @@ def setup_class(self): t_new[1:-1] = t[1:-1] + (rng.rand(len(t) - 2) / (high - low)) s1_new = interp1d(t, s1, fill_value="extrapolate")(t_new) s2_new = interp1d(t, s2, fill_value="extrapolate")(t_new) - self.lc1 = Lightcurve(t, s1_new, dt=lc1.dt) - self.lc2 = Lightcurve(t, s2_new, dt=lc2.dt) + self.lc1 = Lightcurve(t, s1_new, dt=lc1.dt, err_dist="poisson") + self.lc2 = Lightcurve(t, s2_new, dt=lc2.dt, err_dist="poisson") self.lscs = LombScargleCrossspectrum(lc1, lc2) def test_eventlist(self): counts = rng.poisson(10, 1000) times = np.arange(0, 1000, 1) - lc1 = Lightcurve(times, counts, dt=1) - lc2 = Lightcurve(times, counts, dt=1) + lc1 = Lightcurve(times, counts, dt=1, err_dist="poisson") + lc2 = Lightcurve(times, counts, dt=1, err_dist="poisson") ev1 = EventList.from_lc(lc1) ev2 = EventList.from_lc(lc2) ev_lscs = LombScargleCrossspectrum(ev1, ev2, dt=1) @@ -147,7 +148,9 @@ def test_init_with_negative_max_freq(self): lscs = LombScargleCrossspectrum(self.lc1, self.lc2, max_freq=-1) def test_make_crossspectrum_diff_lc_counts_shape(self): - lc_ = Simulator(0.0001, 103, 100, 1, random_state=42, tstart=0).simulate(0) + sim = Simulator(0.0001, 103, 100, 1, random_state=42, tstart=0) + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + lc_ = sim.simulate(0) with pytest.warns(UserWarning) as record: lscs = LombScargleCrossspectrum(self.lc1, lc_) assert np.any(["different statistics" in r.message.args[0] for r in record]) @@ -246,7 +249,8 @@ def func(time, phase=0): class TestLombScarglePowerspectrum: def setup_class(self): sim = Simulator(0.0001, 100, 100, 1, random_state=42, tstart=0) - lc = sim.simulate(0) + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + lc = sim.simulate(0) self.rate = lc.countrate low, high = lc.time.min(), lc.time.max() s1 = lc.counts @@ -254,7 +258,7 @@ def setup_class(self): t_new = t.copy() t_new[1:-1] = t[1:-1] + (rng.rand(len(t) - 2) / (high - low)) s_new = interp1d(t, s1, fill_value="extrapolate")(t_new) - self.lc = Lightcurve(t, s_new, dt=lc.dt) + self.lc = Lightcurve(t, s_new, dt=lc.dt, err_dist="poisson") @pytest.mark.parametrize("norm", ["leahy", "frac", "abs", "none"]) def test_normalize_powerspectrum(self, norm): @@ -284,7 +288,7 @@ def test_make_empty_powerspectrum(self): def test_ps_real(self): counts = rng.poisson(10, 1000) times = np.arange(0, 1000, 1) - lc = Lightcurve(times, counts, dt=1) + lc = Lightcurve(times, counts, dt=1, err_dist="poisson") ps = LombScarglePowerspectrum(lc) assert np.allclose(ps.power.imag, np.zeros_like(ps.power.imag), atol=1e-4) diff --git a/stingray/tests/test_varenergyspectrum.py b/stingray/tests/test_varenergyspectrum.py index a1e5cf446..c281ba73e 100644 --- a/stingray/tests/test_varenergyspectrum.py +++ b/stingray/tests/test_varenergyspectrum.py @@ -48,7 +48,8 @@ def setup_class(cls): from ..simulator import Simulator simulator = Simulator(0.1, 10000, rms=0.2, mean=200) - test_lc = simulator.simulate(1) + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + test_lc = simulator.simulate(1) cls.test_ev1, cls.test_ev2 = EventList(), EventList() cls.test_ev1.simulate_times(test_lc) cls.test_ev1.energy = np.random.uniform(0.3, 12, len(cls.test_ev1.time)) @@ -190,9 +191,10 @@ def setup_class(cls): flux = data / 40 times = np.arange(data.size) * cls.bin_time gti = np.asanyarray([[0, data.size * cls.bin_time]]) - test_lc = Lightcurve( - times, flux, err_dist="gauss", gti=gti, dt=cls.bin_time, skip_checks=True - ) + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + test_lc = Lightcurve( + times, flux, err_dist="gauss", gti=gti, dt=cls.bin_time, skip_checks=True + ) cls.test_ev1, cls.test_ev2 = EventList(), EventList() cls.test_ev1.simulate_times(test_lc) @@ -551,8 +553,9 @@ def setup_class(cls): times, flux, rolled_flux = times[good], flux[good], rolled_flux[good] length = times[-1] - times[0] - test_ref = Lightcurve(times, flux, err_dist="gauss", dt=dt, skip_checks=True) - test_sub = Lightcurve(test_ref.time, rolled_flux, err_dist=test_ref.err_dist, dt=dt) + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + test_ref = Lightcurve(times, flux, err_dist="gauss", dt=dt, skip_checks=True) + test_sub = Lightcurve(test_ref.time, rolled_flux, err_dist=test_ref.err_dist, dt=dt) test_ref_ev, test_sub_ev = EventList(), EventList() test_ref_ev.simulate_times(test_ref) test_sub_ev.simulate_times(test_sub) From f6ce539db272739334ac9962f7b1f0bc424d03c0 Mon Sep 17 00:00:00 2001 From: andresgur Date: Tue, 8 Apr 2025 18:50:06 +0100 Subject: [PATCH 10/15] Fixed warnings related to err_dist=none not passing tests in test_crosscorrelation --- stingray/tests/test_crosscorrelation.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/stingray/tests/test_crosscorrelation.py b/stingray/tests/test_crosscorrelation.py index 1479a1554..71a998a39 100644 --- a/stingray/tests/test_crosscorrelation.py +++ b/stingray/tests/test_crosscorrelation.py @@ -41,16 +41,16 @@ def test_crosscorr_norm(self): class TestCrossCorrelation(object): @classmethod def setup_class(cls): - cls.lc1 = Lightcurve([1, 2, 3, 4, 5], [2, 3, 2, 4, 1], err_dist="poisson") - cls.lc2 = Lightcurve([1, 2, 3, 4, 5], [4, 8, 1, 9, 11], err_dist="poisson") + cls.lc1 = Lightcurve([1, 2, 3, 4, 5], [2, 3, 2, 4, 1]) + cls.lc2 = Lightcurve([1, 2, 3, 4, 5], [4, 8, 1, 9, 11]) # Smaller Light curve - cls.lc_s = Lightcurve([1, 2, 3], [5, 3, 2], err_dist="poisson") + cls.lc_s = Lightcurve([1, 2, 3], [5, 3, 2]) # lc with different time resolution - cls.lc_u = Lightcurve([1, 3, 5, 7, 9], [4, 8, 1, 9, 11], err_dist="poisson") + cls.lc_u = Lightcurve([1, 3, 5, 7, 9], [4, 8, 1, 9, 11]) # Light curve with odd number of data points - cls.lc_odd = Lightcurve([1, 2, 3, 4, 5], [2, 3, 2, 4, 1], err_dist="poisson") + cls.lc_odd = Lightcurve([1, 2, 3, 4, 5], [2, 3, 2, 4, 1]) # Light curve with even number of data points - cls.lc_even = Lightcurve([1, 2, 3, 4, 5, 6], [2, 3, 2, 4, 1, 3], err_dist="poisson") + cls.lc_even = Lightcurve([1, 2, 3, 4, 5, 6], [2, 3, 2, 4, 1, 3]) def test_empty_cross_correlation(self): cr = CrossCorrelation() From 4d0fa09d412b2713fae159476cc954ca49e39151 Mon Sep 17 00:00:00 2001 From: andresgur Date: Tue, 8 Apr 2025 19:00:43 +0100 Subject: [PATCH 11/15] Fixed warnings related to err_dist=none not passing tests in test_lombscargle --- stingray/tests/test_lombscargle.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/stingray/tests/test_lombscargle.py b/stingray/tests/test_lombscargle.py index daa06ff84..5cfd42ba3 100644 --- a/stingray/tests/test_lombscargle.py +++ b/stingray/tests/test_lombscargle.py @@ -49,15 +49,15 @@ def setup_class(self): t_new[1:-1] = t[1:-1] + (rng.rand(len(t) - 2) / (high - low)) s1_new = interp1d(t, s1, fill_value="extrapolate")(t_new) s2_new = interp1d(t, s2, fill_value="extrapolate")(t_new) - self.lc1 = Lightcurve(t, s1_new, dt=lc1.dt, err_dist="poisson") - self.lc2 = Lightcurve(t, s2_new, dt=lc2.dt, err_dist="poisson") + self.lc1 = Lightcurve(t, s1_new, dt=lc1.dt) + self.lc2 = Lightcurve(t, s2_new, dt=lc2.dt) self.lscs = LombScargleCrossspectrum(lc1, lc2) def test_eventlist(self): counts = rng.poisson(10, 1000) times = np.arange(0, 1000, 1) - lc1 = Lightcurve(times, counts, dt=1, err_dist="poisson") - lc2 = Lightcurve(times, counts, dt=1, err_dist="poisson") + lc1 = Lightcurve(times, counts, dt=1) + lc2 = Lightcurve(times, counts, dt=1) ev1 = EventList.from_lc(lc1) ev2 = EventList.from_lc(lc2) ev_lscs = LombScargleCrossspectrum(ev1, ev2, dt=1) @@ -258,7 +258,7 @@ def setup_class(self): t_new = t.copy() t_new[1:-1] = t[1:-1] + (rng.rand(len(t) - 2) / (high - low)) s_new = interp1d(t, s1, fill_value="extrapolate")(t_new) - self.lc = Lightcurve(t, s_new, dt=lc.dt, err_dist="poisson") + self.lc = Lightcurve(t, s_new, dt=lc.dt) @pytest.mark.parametrize("norm", ["leahy", "frac", "abs", "none"]) def test_normalize_powerspectrum(self, norm): @@ -288,7 +288,7 @@ def test_make_empty_powerspectrum(self): def test_ps_real(self): counts = rng.poisson(10, 1000) times = np.arange(0, 1000, 1) - lc = Lightcurve(times, counts, dt=1, err_dist="poisson") + lc = Lightcurve(times, counts, dt=1) ps = LombScarglePowerspectrum(lc) assert np.allclose(ps.power.imag, np.zeros_like(ps.power.imag), atol=1e-4) From 90c3772043679763228c20189899e3b07e88d73c Mon Sep 17 00:00:00 2001 From: andresgur Date: Tue, 8 Apr 2025 19:04:06 +0100 Subject: [PATCH 12/15] Fixed warnings related to err_dist=none not passing tests in test_crossspectrum --- stingray/tests/test_crossspectrum.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/stingray/tests/test_crossspectrum.py b/stingray/tests/test_crossspectrum.py index 4b5b9dbe8..b84414511 100644 --- a/stingray/tests/test_crossspectrum.py +++ b/stingray/tests/test_crossspectrum.py @@ -505,14 +505,15 @@ def setup_class(self): counts1 = np.random.poisson(10000, size=time.shape[0]) counts1_norm = counts1 / 13.4 counts1_norm_err = np.std(counts1) / 13.4 - self.lc1_norm = Lightcurve( - time, - counts1_norm, - gti=[[tstart, self.tseg]], - dt=dt, - err_dist="gauss", - err=np.zeros_like(counts1_norm) + counts1_norm_err, - ) + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + self.lc1_norm = Lightcurve( + time, + counts1_norm, + gti=[[tstart, self.tseg]], + dt=dt, + err_dist="gauss", + err=np.zeros_like(counts1_norm) + counts1_norm_err, + ) self.lc1 = Lightcurve(time, counts1, gti=[[tstart, self.tseg]], dt=dt) self.rate1 = np.mean(counts1) / dt # mean count rate (counts/sec) of light curve 1 @@ -1217,7 +1218,8 @@ def test_rebin_log_returns_complex_values_and_errors(self): def test_timelag(self): dt = 0.1 simulator = Simulator(dt, 10000, rms=0.2, mean=1000) - test_lc1 = simulator.simulate(2) + with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + test_lc1 = simulator.simulate(2) test_lc1.counts -= np.min(test_lc1.counts) with pytest.warns(UserWarning): @@ -1417,7 +1419,7 @@ def setup_class(cls): with warnings.catch_warnings(): warnings.simplefilter("ignore", category=UserWarning) - lc = Lightcurve(timestamps, signal, err_dist="poisson", dt=dt, gti=[[0, 100]]) + lc = Lightcurve(timestamps, signal, dt=dt, gti=[[0, 100]]) cls.lc = lc From 79b7a2db9adc2d40fc654d5e6743261ce1d4cae7 Mon Sep 17 00:00:00 2001 From: andresgur Date: Tue, 8 Apr 2025 21:42:59 +0100 Subject: [PATCH 13/15] Fixed warnings related to err_dist=none not passing tests in test_lightcurve --- stingray/tests/test_lightcurve.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/stingray/tests/test_lightcurve.py b/stingray/tests/test_lightcurve.py index 8dc528b2c..68548d932 100644 --- a/stingray/tests/test_lightcurve.py +++ b/stingray/tests/test_lightcurve.py @@ -391,7 +391,7 @@ def test_irregular_time_warning(self): ) with pytest.warns(UserWarning, match=warn_str): - _ = Lightcurve(times, counts, err_dist="poisson") + _ = Lightcurve(times, counts) def test_unrecognize_err_dist_warning(self): """ @@ -399,7 +399,7 @@ def test_unrecognize_err_dist_warning(self): """ times = [1, 2, 3, 4, 5] counts = [2, 2, 2, 2, 2] - warn_str = "SIMON says: Stingray only uses poisson err_dist at " "the moment" + warn_str = "SIMON says: Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more." with warnings.catch_warnings(record=True) as w: warnings.filterwarnings("always") @@ -554,7 +554,7 @@ def test_input_countrate(self): mean_counts = 2.0 times = np.arange(0 + dt / 2, 5 - dt / 2, dt) countrate = np.zeros_like(times) + mean_counts - lc = Lightcurve(times, countrate, input_counts=False) + lc = Lightcurve(times, countrate, input_counts=False, err_dist="poisson") assert np.allclose(lc.counts, np.zeros_like(countrate) + mean_counts * dt) def test_meanrate(self): @@ -726,7 +726,7 @@ def test_slicing(self): dt=self.dt, gti=self.gti, err=self.counts / 10, - err_dist="gauss", + err_dist="poisson", ) assert np.allclose(lc[1:3].counts, np.array([4, 6])) assert np.allclose(lc[:2].counts, np.array([2, 4])) @@ -1326,14 +1326,14 @@ def test_split_lc_by_gtis_minpoints(self): def test_shift(self): times = [1, 2, 3, 4, 5, 6, 7, 8] counts = [1, 1, 1, 1, 2, 3, 3, 2] - lc = Lightcurve(times, counts, input_counts=True) + lc = Lightcurve(times, counts, input_counts=True, err_dist="poisson") lc2 = lc.shift(1) assert np.allclose(lc2.time - 1, times) lc2 = lc.shift(-1) assert np.allclose(lc2.time + 1, times) assert np.allclose(lc2.counts, lc.counts) assert np.allclose(lc2.countrate, lc.countrate) - lc = Lightcurve(times, counts, input_counts=False) + lc = Lightcurve(times, counts, input_counts=False, err_dist="poisson") lc2 = lc.shift(1) assert np.allclose(lc2.counts, lc.counts) assert np.allclose(lc2.countrate, lc.countrate) @@ -1350,6 +1350,7 @@ def test_table_roundtrip(self): mission="BUBU", instr="BABA", mjdref=53467.0, + err_dist="poisson" ) ts = lc.to_astropy_table() @@ -1378,6 +1379,7 @@ def test_table_roundtrip_ctrate(self): instr="BABA", mjdref=53467.0, input_counts=False, + err_dist="poisson" ) ts = lc.to_astropy_table() @@ -1393,7 +1395,7 @@ def test_timeseries_roundtrip(self): wrong format is provided. """ N = len(self.times) - lc = Lightcurve(self.times, self.counts, mission="BUBU", instr="BABA", mjdref=53467.0) + lc = Lightcurve(self.times, self.counts, mission="BUBU", instr="BABA", mjdref=53467.0, err_dist="poisson") ts = lc.to_astropy_timeseries() new_lc = lc.from_astropy_timeseries(ts) @@ -1413,7 +1415,7 @@ def test_timeseries_roundtrip_ctrate(self): countrate = np.zeros_like(times) + mean_counts lc = Lightcurve( - times, countrate, mission="BUBU", instr="BABA", mjdref=53467.0, input_counts=False + times, countrate, mission="BUBU", instr="BABA", mjdref=53467.0, input_counts=False, err_dist="poisson" ) ts = lc.to_astropy_timeseries() @@ -1558,7 +1560,7 @@ def test_apply_gtis_lc_rate(self, inplace): time = np.arange(1, 10, dt) countrate = np.zeros_like(time) + 5 # create the lightcurve from countrare - lc_rate = Lightcurve(time, counts=countrate, input_counts=False, gti=[[-0.5, 10.5]]) + lc_rate = Lightcurve(time, counts=countrate, input_counts=False, gti=[[-0.5, 10.5]], err_dist="poisson") lc_rate.gti = [[-0.5, 2.5]] lc_rate_new = lc_rate.apply_gtis(inplace=inplace) if inplace: From bf9d22ab9b52be24106a959ee6bfea8f7be5db63 Mon Sep 17 00:00:00 2001 From: andresgur Date: Tue, 8 Apr 2025 21:43:24 +0100 Subject: [PATCH 14/15] Fixed warnings related to err_dist=none in simulator.rst causing the test not to pass --- docs/simulator.rst | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/docs/simulator.rst b/docs/simulator.rst index 84e78ed92..606378423 100644 --- a/docs/simulator.rst +++ b/docs/simulator.rst @@ -25,6 +25,7 @@ The examples here assume that the following libraries and modules have been impo >>> import numpy as np >>> from stingray import Lightcurve, sampledata >>> from stingray.simulator import simulator, models + >>> import pytest Creating a Simulator Object --------------------------- @@ -48,7 +49,8 @@ Simulate Method Stingray provides multiple ways to simulate a light curve. However, all these methods follow a common recipe:: >>> sim = simulator.Simulator(N=1024, mean=0.5, dt=0.125, rms=1.0) - >>> lc = sim.simulate(2) + >>> with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + ... lc = sim.simulate(2) Using Power-Law Spectrum ------------------------ @@ -154,7 +156,8 @@ Channel Simulation The `simulator` class provides the functionality to simulate light curves independently for each channel. This is useful, for example, when dealing with energy dependent impulse responses where we can create a di↵erent simulation channel for each energy range. The module provides options to count, retrieve and delete channels.:: >>> sim = simulator.Simulator(N=1024, mean=0.5, dt=0.125, rms=1.0) - >>> sim.simulate_channel('3.5 - 4.5', 2) + >>> with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + ... sim.simulate_channel('3.5 - 4.5', 2) >>> sim.count_channels() 1 >>> lc = sim.get_channel('3.5 - 4.5') @@ -164,9 +167,10 @@ Alternatively, assume that we have light curves in the simulated energy channels >>> sim.count_channels() 0 - >>> sim.simulate_channel('3.5 - 4.5', 2) - >>> sim.simulate_channel('4.5 - 5.5', 2) - >>> sim.simulate_channel('5.5 - 6.5', 2) + >>> with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): + ... sim.simulate_channel('3.5 - 4.5', 2) + ... sim.simulate_channel('4.5 - 5.5', 2) + ... sim.simulate_channel('5.5 - 6.5', 2) >>> chans = sim.get_channels(['3.5 - 4.5','4.5 - 5.5','5.5 - 6.5']) >>> sim.delete_channels(['3.5 - 4.5','4.5 - 5.5','5.5 - 6.5']) From 9383422b231b5293d850594b07df913d1645674e Mon Sep 17 00:00:00 2001 From: andresgur Date: Wed, 9 Apr 2025 16:57:41 +0100 Subject: [PATCH 15/15] Removed pytest dependency, ignored warnings instead with doctest: +IGNORE_WARNINGS --- docs/simulator.rst | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/docs/simulator.rst b/docs/simulator.rst index 606378423..ba382ef29 100644 --- a/docs/simulator.rst +++ b/docs/simulator.rst @@ -25,7 +25,6 @@ The examples here assume that the following libraries and modules have been impo >>> import numpy as np >>> from stingray import Lightcurve, sampledata >>> from stingray.simulator import simulator, models - >>> import pytest Creating a Simulator Object --------------------------- @@ -49,8 +48,7 @@ Simulate Method Stingray provides multiple ways to simulate a light curve. However, all these methods follow a common recipe:: >>> sim = simulator.Simulator(N=1024, mean=0.5, dt=0.125, rms=1.0) - >>> with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): - ... lc = sim.simulate(2) + >>> lc = sim.simulate(2) # doctest: +IGNORE_WARNINGS Using Power-Law Spectrum ------------------------ @@ -156,8 +154,7 @@ Channel Simulation The `simulator` class provides the functionality to simulate light curves independently for each channel. This is useful, for example, when dealing with energy dependent impulse responses where we can create a di↵erent simulation channel for each energy range. The module provides options to count, retrieve and delete channels.:: >>> sim = simulator.Simulator(N=1024, mean=0.5, dt=0.125, rms=1.0) - >>> with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): - ... sim.simulate_channel('3.5 - 4.5', 2) + >>> sim.simulate_channel('3.5 - 4.5', 2) # doctest: +IGNORE_WARNINGS >>> sim.count_channels() 1 >>> lc = sim.get_channel('3.5 - 4.5') @@ -167,10 +164,9 @@ Alternatively, assume that we have light curves in the simulated energy channels >>> sim.count_channels() 0 - >>> with pytest.warns(UserWarning, match="Beware! Stingray only supports poisson err_dist at the moment in many methods, and 'gauss' in a few more."): - ... sim.simulate_channel('3.5 - 4.5', 2) - ... sim.simulate_channel('4.5 - 5.5', 2) - ... sim.simulate_channel('5.5 - 6.5', 2) + >>> sim.simulate_channel('3.5 - 4.5', 2) # doctest: +IGNORE_WARNINGS + >>> sim.simulate_channel('4.5 - 5.5', 2) # doctest: +IGNORE_WARNINGS + >>> sim.simulate_channel('5.5 - 6.5', 2) # doctest: +IGNORE_WARNINGS >>> chans = sim.get_channels(['3.5 - 4.5','4.5 - 5.5','5.5 - 6.5']) >>> sim.delete_channels(['3.5 - 4.5','4.5 - 5.5','5.5 - 6.5'])