diff --git a/stingray/crossspectrum.py b/stingray/crossspectrum.py index cc034b7f5..43a0e151d 100644 --- a/stingray/crossspectrum.py +++ b/stingray/crossspectrum.py @@ -16,7 +16,7 @@ from .gti import cross_two_gtis, time_intervals_from_gtis from .lightcurve import Lightcurve from .fourier import avg_cs_from_iterables, error_on_averaged_cross_spectrum -from .fourier import avg_cs_from_events, poisson_level +from .fourier import avg_cs_from_timeseries, poisson_level from .fourier import normalize_periodograms, raw_coherence from .fourier import get_flux_iterable_from_segments, power_color from .fourier import get_rms_from_unnorm_periodogram @@ -2456,7 +2456,7 @@ def crossspectrum_from_time_array( force_averaged = segment_size is not None # Suppress progress bar for single periodogram silent = silent or (segment_size is None) - results = avg_cs_from_events( + results = avg_cs_from_timeseries( times1, times2, gti, @@ -2696,7 +2696,7 @@ def crossspectrum_from_timeseries( err1 = getattr(ts1, error_flux_attr) err2 = getattr(ts2, error_flux_attr) - results = avg_cs_from_events( + results = avg_cs_from_timeseries( ts1.time, ts2.time, gti, diff --git a/stingray/fourier.py b/stingray/fourier.py index d51ea4952..ce0b29438 100644 --- a/stingray/fourier.py +++ b/stingray/fourier.py @@ -2243,7 +2243,15 @@ def local_show_progress(a): return results -def avg_pds_from_events( +def avg_pds_from_events(*args, **kwargs): + warnings.warn( + "avg_pds_from_events is deprecated, use avg_cs_from_timeseries instead", DeprecationWarning + ) + + return avg_pds_from_timeseries(*args, **kwargs) + + +def avg_pds_from_timeseries( times, gti, segment_size, @@ -2333,7 +2341,14 @@ def avg_pds_from_events( return cross -def avg_cs_from_events( +def avg_cs_from_events(*args, **kwargs): + warnings.warn( + "avg_cs_from_events is deprecated, use avg_cs_from_timeseries instead", DeprecationWarning + ) + return avg_cs_from_timeseries(*args, **kwargs) + + +def avg_cs_from_timeseries( times1, times2, gti, diff --git a/stingray/powerspectrum.py b/stingray/powerspectrum.py index fe2fb2b2c..4fd262437 100755 --- a/stingray/powerspectrum.py +++ b/stingray/powerspectrum.py @@ -14,7 +14,7 @@ from .lightcurve import Lightcurve from .fourier import avg_pds_from_iterable, unnormalize_periodograms -from .fourier import avg_pds_from_events +from .fourier import avg_pds_from_timeseries from .fourier import get_flux_iterable_from_segments from .fourier import poisson_level from .fourier import get_rms_from_unnorm_periodogram @@ -1134,7 +1134,7 @@ def powerspectrum_from_time_array( force_averaged = segment_size is not None # Suppress progress bar for single periodogram silent = silent or (segment_size is None) - table = avg_pds_from_events( + table = avg_pds_from_timeseries( times, gti, segment_size, @@ -1267,7 +1267,7 @@ def powerspectrum_from_lightcurve( if gti is None: gti = lc.gti - table = avg_pds_from_events( + table = avg_pds_from_timeseries( lc.time, gti, segment_size, @@ -1347,7 +1347,7 @@ def powerspectrum_from_timeseries( if error_flux_attr is not None: err = getattr(ts, error_flux_attr) - results = avg_pds_from_events( + results = avg_pds_from_timeseries( ts.time, gti, segment_size, diff --git a/stingray/tests/test_fourier.py b/stingray/tests/test_fourier.py index 6f5559dd5..860a41528 100644 --- a/stingray/tests/test_fourier.py +++ b/stingray/tests/test_fourier.py @@ -8,6 +8,8 @@ from stingray.fourier import fft, fftfreq, normalize_abs, normalize_frac, poisson_level from stingray.fourier import ( get_flux_iterable_from_segments, + avg_pds_from_timeseries, + avg_cs_from_timeseries, avg_pds_from_events, avg_cs_from_events, ) @@ -91,7 +93,19 @@ def test_avg_pds_imperfect_lc_size(): gti = np.asarray([[-0.5, 99.5]]) segment_size = 5.99 dt = 1 - res = avg_pds_from_events(times, gti, segment_size, dt, fluxes=fluxes) + res = avg_pds_from_timeseries(times, gti, segment_size, dt, fluxes=fluxes) + assert res.meta["segment_size"] == 6 + assert res.meta["dt"] == 1 + + +def test_avg_pds_from_events_warns(): + times = np.arange(100) + fluxes = np.ones(100).astype(float) + gti = np.asarray([[-0.5, 99.5]]) + segment_size = 5.99 + dt = 1 + with pytest.warns(DeprecationWarning, match="avg_pds_from_events is deprecated"): + res = avg_pds_from_events(times, gti, segment_size, dt, fluxes=fluxes) assert res.meta["segment_size"] == 6 assert res.meta["dt"] == 1 @@ -103,13 +117,28 @@ def test_avg_cs_imperfect_lc_size(): gti = np.asarray([[-0.5, 99.5]]) segment_size = 5.99 dt = 1 - res = avg_cs_from_events( + res = avg_cs_from_timeseries( times1, times2, gti, segment_size, dt, fluxes1=fluxes1, fluxes2=fluxes2 ) assert res.meta["segment_size"] == 6 assert res.meta["dt"] == 1 +def test_avg_cs_from_events_warns(): + times1 = times2 = np.arange(100) + fluxes1 = np.ones(100).astype(float) + fluxes2 = np.ones(100).astype(float) + gti = np.asarray([[-0.5, 99.5]]) + segment_size = 5.99 + dt = 1 + with pytest.warns(DeprecationWarning, match="avg_cs_from_events is deprecated"): + res = avg_cs_from_events( + times1, times2, gti, segment_size, dt, fluxes1=fluxes1, fluxes2=fluxes2 + ) + assert res.meta["segment_size"] == 6 + assert res.meta["dt"] == 1 + + class TestCoherence(object): @classmethod def setup_class(cls): @@ -244,7 +273,7 @@ def test_fts_from_segments_cts_and_events_are_equal(self): def test_avg_pds_bad_input(self): times = np.sort(rng.uniform(0, 1000, 1)) - out_ev = avg_pds_from_events(times, self.gti, self.segment_size, self.dt) + out_ev = avg_pds_from_timeseries(times, self.gti, self.segment_size, self.dt) assert out_ev is None @pytest.mark.parametrize("return_subcs", [True, False]) @@ -252,7 +281,7 @@ def test_avg_pds_bad_input(self): def test_avg_cs_bad_input(self, return_auxil, return_subcs): times1 = np.sort(rng.uniform(0, 1000, 1)) times2 = np.sort(rng.uniform(0, 1000, 1)) - out_ev = avg_cs_from_events( + out_ev = avg_cs_from_timeseries( times1, times2, self.gti, @@ -265,7 +294,7 @@ def test_avg_cs_bad_input(self, return_auxil, return_subcs): @pytest.mark.parametrize("norm", ["frac", "abs", "none", "leahy"]) def test_avg_pds_use_common_mean_similar_stats(self, norm): - out_comm = avg_pds_from_events( + out_comm = avg_pds_from_timeseries( self.times, self.gti, self.segment_size, @@ -275,7 +304,7 @@ def test_avg_pds_use_common_mean_similar_stats(self, norm): silent=True, fluxes=None, ) - out = avg_pds_from_events( + out = avg_pds_from_timeseries( self.times, self.gti, self.segment_size, @@ -289,7 +318,7 @@ def test_avg_pds_use_common_mean_similar_stats(self, norm): @pytest.mark.parametrize("norm", ["frac", "abs", "none", "leahy"]) def test_avg_cs_use_common_mean_similar_stats(self, norm): - out_comm = avg_cs_from_events( + out_comm = avg_cs_from_timeseries( self.times, self.times2, self.gti, @@ -300,7 +329,7 @@ def test_avg_cs_use_common_mean_similar_stats(self, norm): silent=True, return_subcs=True, ) - out = avg_cs_from_events( + out = avg_cs_from_timeseries( self.times, self.times2, self.gti, @@ -328,7 +357,7 @@ def test_avg_cs_use_common_mean_similar_stats(self, norm): @pytest.mark.parametrize("use_common_mean", [True, False]) @pytest.mark.parametrize("norm", ["frac", "abs", "none", "leahy"]) def test_avg_pds_cts_and_events_are_equal(self, norm, use_common_mean): - out_ev = avg_pds_from_events( + out_ev = avg_pds_from_timeseries( self.times, self.gti, self.segment_size, @@ -339,7 +368,7 @@ def test_avg_pds_cts_and_events_are_equal(self, norm, use_common_mean): fluxes=None, return_subcs=True, ) - out_ct = avg_pds_from_events( + out_ct = avg_pds_from_timeseries( self.bin_times, self.gti, self.segment_size, @@ -355,7 +384,7 @@ def test_avg_pds_cts_and_events_are_equal(self, norm, use_common_mean): @pytest.mark.parametrize("use_common_mean", [True, False]) @pytest.mark.parametrize("norm", ["frac", "abs", "none", "leahy"]) def test_avg_pds_cts_and_err_and_events_are_equal(self, norm, use_common_mean): - out_ev = avg_pds_from_events( + out_ev = avg_pds_from_timeseries( self.times, self.gti, self.segment_size, @@ -366,7 +395,7 @@ def test_avg_pds_cts_and_err_and_events_are_equal(self, norm, use_common_mean): fluxes=None, return_subcs=True, ) - out_ct = avg_pds_from_events( + out_ct = avg_pds_from_timeseries( self.bin_times, self.gti, self.segment_size, @@ -389,7 +418,7 @@ def test_avg_pds_cts_and_err_and_events_are_equal(self, norm, use_common_mean): @pytest.mark.parametrize("use_common_mean", [True, False]) @pytest.mark.parametrize("norm", ["frac", "abs", "none", "leahy"]) def test_avg_cs_cts_and_events_are_equal(self, norm, use_common_mean): - out_ev = avg_cs_from_events( + out_ev = avg_cs_from_timeseries( self.times, self.times2, self.gti, @@ -399,7 +428,7 @@ def test_avg_cs_cts_and_events_are_equal(self, norm, use_common_mean): use_common_mean=use_common_mean, silent=False, ) - out_ct = avg_cs_from_events( + out_ct = avg_cs_from_timeseries( self.bin_times, self.bin_times, self.gti, @@ -419,7 +448,7 @@ def test_avg_cs_cts_and_events_are_equal(self, norm, use_common_mean): @pytest.mark.parametrize("use_common_mean", [True, False]) @pytest.mark.parametrize("norm", ["frac", "abs", "none", "leahy"]) def test_avg_cs_cts_and_err_and_events_are_equal(self, norm, use_common_mean): - out_ev = avg_cs_from_events( + out_ev = avg_cs_from_timeseries( self.times, self.times2, self.gti, @@ -429,7 +458,7 @@ def test_avg_cs_cts_and_err_and_events_are_equal(self, norm, use_common_mean): use_common_mean=use_common_mean, silent=False, ) - out_ct = avg_cs_from_events( + out_ct = avg_cs_from_timeseries( self.bin_times, self.bin_times, self.gti, diff --git a/stingray/varenergyspectrum.py b/stingray/varenergyspectrum.py index b1a401574..9b1d7a355 100644 --- a/stingray/varenergyspectrum.py +++ b/stingray/varenergyspectrum.py @@ -6,7 +6,12 @@ from stingray.lightcurve import Lightcurve from stingray.utils import assign_value_if_none, simon, excess_variance, show_progress -from stingray.fourier import avg_cs_from_events, avg_pds_from_events, fftfreq, get_average_ctrate +from stingray.fourier import ( + avg_cs_from_timeseries, + avg_pds_from_timeseries, + fftfreq, + get_average_ctrate, +) from stingray.fourier import poisson_level, error_on_averaged_cross_spectrum, cross_to_covariance from abc import ABCMeta, abstractmethod @@ -530,7 +535,7 @@ def _spectrum_function(self): sub2_power_noise = poisson_level(norm="abs", meanrate=countrate_sub2) # Calculate the cross spectrum - results = avg_cs_from_events( + results = avg_cs_from_timeseries( sub_events, sub_events2, self.gti, @@ -550,7 +555,7 @@ def _spectrum_function(self): delta_nu_after_mean * np.sqrt(sub_power_noise * sub2_power_noise) ) else: - results = avg_pds_from_events( + results = avg_pds_from_timeseries( sub_events, self.gti, self.segment_size, self.bin_time, silent=True, norm="abs" ) if results is None: @@ -804,7 +809,7 @@ def _spectrum_function(self): ref_events = self._get_times_from_energy_range(self.events2, self.ref_band[0]) # Calculate the PDS in the reference band. Needed to calculate errors. - results = avg_pds_from_events( + results = avg_pds_from_timeseries( ref_events, self.gti, self.segment_size, self.bin_time, silent=True, norm="none" ) @@ -827,7 +832,7 @@ def _spectrum_function(self): # Extract the photon arrival times from the subject band sub_events = self._get_times_from_energy_range(self.events1, eint) - results_cross = avg_cs_from_events( + results_cross = avg_cs_from_timeseries( sub_events, ref_events, self.gti, @@ -837,7 +842,7 @@ def _spectrum_function(self): norm="none", ) - results_ps = avg_pds_from_events( + results_ps = avg_pds_from_timeseries( sub_events, self.gti, self.segment_size, self.bin_time, silent=True, norm="none" ) @@ -982,7 +987,7 @@ def _spectrum_function(self): countrate_ref = get_average_ctrate(ref_events, self.gti, self.segment_size) ref_power_noise = poisson_level(norm="abs", meanrate=countrate_ref) - results = avg_pds_from_events( + results = avg_pds_from_timeseries( ref_events, self.gti, self.segment_size, self.bin_time, silent=True, norm="abs" ) freq = results["freq"] @@ -1004,7 +1009,7 @@ def _spectrum_function(self): countrate_sub = get_average_ctrate(sub_events, self.gti, self.segment_size) sub_power_noise = poisson_level(norm="abs", meanrate=countrate_sub) - results_cross = avg_cs_from_events( + results_cross = avg_cs_from_timeseries( sub_events, ref_events, self.gti, @@ -1014,7 +1019,7 @@ def _spectrum_function(self): norm="abs", ) - results_ps = avg_pds_from_events( + results_ps = avg_pds_from_timeseries( sub_events, self.gti, self.segment_size, self.bin_time, silent=True, norm="abs" )