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 diff --git a/docs/simulator.rst b/docs/simulator.rst index 84e78ed92..ba382ef29 100644 --- a/docs/simulator.rst +++ b/docs/simulator.rst @@ -48,7 +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) - >>> lc = sim.simulate(2) + >>> lc = sim.simulate(2) # doctest: +IGNORE_WARNINGS Using Power-Law Spectrum ------------------------ @@ -154,7 +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) - >>> 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') @@ -164,9 +164,9 @@ 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) + >>> 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']) diff --git a/stingray/lightcurve.py b/stingray/lightcurve.py index c6cff03b6..d9c3a080d 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() @@ -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, @@ -275,6 +275,11 @@ def __init__( if not skip_checks: time, counts, err = self.initial_optional_checks(time, counts, err, gti=gti) + if err_dist is None and input_counts: + err_dist = "poisson" + elif 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 +288,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 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") 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..71a998a39 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) 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 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: diff --git a/stingray/tests/test_lombscargle.py b/stingray/tests/test_lombscargle.py index 27e2beb52..5cfd42ba3 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() @@ -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 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)