Repository: StingraySoftware/HENDRICS

Issue:
Tests are failing with MemoryError or Sigkill. 
We need to make quicker tests, in particular for the very slow efsearch ones.

https://github.com/StingraySoftware/HENDRICS/runs/1804391756?check_suite_focus=true
This one fails with SIGKILL after having run for 20+ minutes
https://github.com/StingraySoftware/HENDRICS/runs/1804391809?check_suite_focus=true
This one with MemoryError

Discussion:

Patch:
diff --git a/hendrics/calibrate.py b/hendrics/calibrate.py
index 46ddf09..559a772 100644
--- a/hendrics/calibrate.py
+++ b/hendrics/calibrate.py
@@ -76,7 +76,7 @@ def read_calibration(pis, rmf_file=None):
         the one given by default_nustar_rmf() is used.
     """
     calp, calEmin, calEmax = read_rmf(rmf_file)
-    es = np.zeros(len(pis), dtype=np.float)
+    es = np.zeros(len(pis), dtype=float)
     for ic, c in enumerate(calp):
         good = pis == c
         if not np.any(good):
diff --git a/hendrics/efsearch.py b/hendrics/efsearch.py
index b085cb3..c4dbe49 100644
--- a/hendrics/efsearch.py
+++ b/hendrics/efsearch.py
@@ -135,12 +135,12 @@ def decide_binary_parameters(
 
         dX = 1 / (TWOPI * freq)
 
-        nX = np.int(np.diff(asini_range) // dX) + 1
+        nX = int(np.diff(asini_range) // dX) + 1
         Xs = np.random.uniform(asini_range[0], asini_range[1], nX)
 
         for X in Xs:
             dOmega = 1 / (TWOPI * freq * X * length) * D_OMEGA_FACTOR
-            nOmega = np.int(np.diff(omega_range) // dOmega) + 1
+            nOmega = int(np.diff(omega_range) // dOmega) + 1
             Omegas = np.random.uniform(omega_range[0], omega_range[1], nOmega)
 
             for Omega in Omegas:
@@ -263,7 +263,7 @@ def shift_and_sum(
     for k in range(nprof):
         total_shift = base_shift[k] * lshift + quadbaseshift[k] * qshift
         total_shift = mod(np.rint(total_shift), nbin)
-        total_shift_int = np.int(total_shift)
+        total_shift_int = int(total_shift)
 
         splat_prof[:] += repeated_profiles[
             k, nbin - total_shift_int : twonbin - total_shift_int
@@ -366,7 +366,7 @@ def _average_and_z_sub_search(profiles, n=2):
 
     for ave_i in range(len(n_ave)):
         n_ave_i = n_ave[ave_i]
-        shape_0 = np.int(profiles.shape[0] / n_ave_i)
+        shape_0 = int(profiles.shape[0] / n_ave_i)
         # new_profiles = np.zeros((shape_0, profiles.shape[1]))
         for i in range(shape_0):
             new_profiles = np.sum(
@@ -578,7 +578,9 @@ def plot_transient_search(results, gif_name=None):
             axf = plt.subplot(gs[0, i_f])
             axima = plt.subplot(gs[1, i_f], sharex=axf)
 
-            axima.pcolormesh(f, t, ima / detl * 3, vmax=3, vmin=0.3)
+            axima.pcolormesh(
+                f, t, ima / detl * 3, vmax=3, vmin=0.3, shading="nearest"
+            )
 
             mean_line = np.mean(ima, axis=0) / sum_detl * 3
             maxidx = np.argmax(mean_line)
@@ -1037,7 +1039,7 @@ def dyn_folding_search(
             stats.append(np.zeros_like(trial_freqs))
     times = (start + stop) / 2
     fig = plt.figure("Dynamical search")
-    plt.pcolormesh(frequencies, times, np.array(stats))
+    plt.pcolormesh(frequencies, times, np.array(stats), shading="nearest")
     plt.xlabel("Frequency")
     plt.ylabel("Time")
     plt.savefig("Dyn.png")
@@ -1122,6 +1124,13 @@ def _common_parser(args=None):
         help="Size of search parameter space",
         default=2,
     )
+    parser.add_argument(
+        "--n-transient-intervals",
+        type=int,
+        required=False,
+        help="Number of transient intervals to investigate",
+        default=None,
+    )
     parser.add_argument(
         "-n",
         "--nbin",
@@ -1291,7 +1300,7 @@ def _common_main(args, func):
                 fdot=0,
                 nbin=args.nbin,
                 n=n,
-                nprof=None,
+                nprof=args.n_transient_intervals,
                 oversample=oversample,
             )
             plot_transient_search(results, hen_root(fname) + "_transient.gif")
diff --git a/hendrics/fake.py b/hendrics/fake.py
index 8b37d5d..6848502 100644
--- a/hendrics/fake.py
+++ b/hendrics/fake.py
@@ -102,6 +102,12 @@ def filter_for_deadtime(
         event_list_obj = event_list
 
     ev_list = event_list_obj.time
+    additional_arrays = {}
+    for arr in "pi,energy".split(","):
+        if hasattr(event_list_obj, arr):
+            values = getattr(event_list_obj, arr)
+            if values is not None:
+                additional_arrays[arr] = values
 
     if deadtime <= 0.0:
         return copy.copy(event_list)
@@ -109,6 +115,7 @@ def filter_for_deadtime(
     # Create the total lightcurve, and a "kind" array that keeps track
     # of the events classified as "signal" (True) and "background" (False)
     if bkg_ev_list is not None:
+        Nback = bkg_ev_list.size
         tot_ev_list = np.append(ev_list, bkg_ev_list)
         ev_kind = np.append(
             np.ones(len(ev_list), dtype=bool),
@@ -117,6 +124,10 @@ def filter_for_deadtime(
         order = np.argsort(tot_ev_list)
         tot_ev_list = tot_ev_list[order]
         ev_kind = ev_kind[order]
+        for arr in additional_arrays.keys():
+            newarr = np.append(additional_arrays[arr], np.zeros(Nback))
+            additional_arrays[arr] = newarr[order]
+
         del order
     else:
         tot_ev_list = ev_list
@@ -149,13 +160,15 @@ def filter_for_deadtime(
         "filter_for_deadtime: "
         "{0}/{1} events rejected".format(initial_len - final_len, initial_len)
     )
-    retval = EventList(time=tot_ev_list[ev_kind], mjdref=event_list_obj.mjdref)
 
-    if hasattr(event_list_obj, "pi") and event_list_obj.pi is not None:
-        warnings.warn(
-            "PI information is lost during dead time filtering",
-            AstropyUserWarning,
-        )
+    for arr in additional_arrays.keys():
+        additional_arrays[arr] = additional_arrays[arr][saved_mask][ev_kind]
+
+    retval = EventList(
+        time=tot_ev_list[ev_kind],
+        mjdref=event_list_obj.mjdref,
+        **additional_arrays,
+    )
 
     if not isinstance(event_list, EventList):
         retval = retval.time
diff --git a/hendrics/ffa.py b/hendrics/ffa.py
index 2540731..a0e16c0 100644
--- a/hendrics/ffa.py
+++ b/hendrics/ffa.py
@@ -338,7 +338,7 @@ def _ffa(array_reshaped, bin_period, ntables, z_n_n=2):
         [bin_period + n / (ntables - 1) for n in range(ntables)]
     )
 
-    for step in range(0, np.int(np.log2(ntables))):
+    for step in range(0, int(np.log2(ntables))):
         array_reshaped = ffa_step(array_reshaped, step, ntables)
 
     twopiphases = np.pi * 2 * np.arange(0, 1, 1 / array_reshaped.shape[1])
@@ -362,7 +362,7 @@ def _ffa(array_reshaped, bin_period, ntables, z_n_n=2):
 def ffa(array, bin_period, z_n_n=2):
     """Fast folding algorithm search"""
     N_raw = len(array)
-    ntables = np.int(2 ** np.ceil(np.log2(N_raw // bin_period + 1)))
+    ntables = int(2 ** np.ceil(np.log2(N_raw // bin_period + 1)))
     if ntables <= 1:
         return np.zeros(1), np.zeros(1)
     N = ntables * bin_period
diff --git a/hendrics/io.py b/hendrics/io.py
index 280b5bb..9c31c74 100644
--- a/hendrics/io.py
+++ b/hendrics/io.py
@@ -506,28 +506,16 @@ def load_lcurve(fname):
     elif get_file_format(fname) == "nc":
         data = _load_data_nc(fname)
 
-    try:
-        lcurve = Lightcurve(
-            data["time"],
-            data["counts"],
-            err=data["counts_err"],
-            gti=data["gti"],
-            err_dist=data["err_dist"],
-            mjdref=data["mjdref"],
-            dt=data["dt"],
-            skip_checks=True,
-        )
-    except TypeError:
-        # Old stingray version
-        lcurve = Lightcurve(
-            data["time"],
-            data["counts"],
-            err=data["counts_err"],
-            gti=data["gti"],
-            err_dist=data["err_dist"],
-            mjdref=data["mjdref"],
-            dt=data["dt"],
-        )
+    lcurve = Lightcurve(
+        data["time"],
+        data["counts"],
+        err=data["counts_err"],
+        gti=data["gti"],
+        err_dist=data["err_dist"],
+        mjdref=data["mjdref"],
+        dt=data["dt"],
+        skip_checks=True,
+    )
 
     if hasattr(lcurve, "_apply_gtis"):  # pragma: no cover
         # Compatibility with old versions of stingray
@@ -609,7 +597,7 @@ def save_pds(cpds, fname, save_all=False):
     if not hasattr(cpds, "instr"):
         outdata["instr"] = "unknown"
 
-    for attr in ['show_progress', 'amplitude']:
+    for attr in ["show_progress", "amplitude"]:
         if hasattr(cpds, attr):
             outdata[attr] = getattr(cpds, attr)
 
@@ -617,22 +605,15 @@ def save_pds(cpds, fname, save_all=False):
     if save_all:
         mkdir_p(outdir)
 
-    for attr in ['lc1', 'lc2', 'pds1', 'pds2']:
+    for attr in ["lc1", "lc2", "pds1", "pds2"]:
         if save_all and hasattr(cpds, attr):
             value = getattr(cpds, attr)
 
             outf = f"__{attr}__" + HEN_FILE_EXTENSION
             if "lc" in attr and isinstance(value, Lightcurve):
-                save_lcurve(
-                    value,
-                    os.path.join(outdir, outf)
-                )
+                save_lcurve(value, os.path.join(outdir, outf))
             elif "pds" in attr and isinstance(value, Crossspectrum):
-                save_pds(
-                    value,
-                    os.path.join(outdir, outf),
-                    save_all=False
-                )
+                save_pds(value, os.path.join(outdir, outf), save_all=False)
         outdata.pop(attr, None)
 
     if "cs_all" in outdata:
@@ -819,7 +800,7 @@ def _split_high_precision_number(varname, var, probesize):
             var_log10 = np.floor(np.log10(np.abs(var)))
 
         var = np.asarray(var) / 10.0 ** var_log10
-        var_I = np.long(np.floor(var))
+        var_I = int(np.floor(var))
         var_F = np.double(var - var_I)
     return var_I, var_F, var_log10, kind_str
 
@@ -1137,6 +1118,7 @@ def _get_gti_from_all_extensions(
     for extn in gtiextn:
         gtihdu = lchdulist[extn]
         gti_lists.append(_get_gti_from_hdu(gtihdu))
+
     return cross_gtis(gti_lists)
 
 
@@ -1206,7 +1188,7 @@ def _get_detector_id(lctable):
     for column in ["CCDNR", "ccd_id", "PCUID"]:  # XMM  # Chandra  # XTE
         for name in lctable.columns.names:
             if column.lower() == name.lower():
-                return np.array(lctable.field(name), dtype=np.int)
+                return np.array(lctable.field(name), dtype=int)
 
     return None
 
diff --git a/hendrics/lcurve.py b/hendrics/lcurve.py
index 8d5330f..f0a597f 100644
--- a/hendrics/lcurve.py
+++ b/hendrics/lcurve.py
@@ -630,7 +630,7 @@ def lcurve_from_fits(
         _look_for_array_in_array(["RATE", "RATE1", "COUNTS"], lctable.names),
     )
 
-    rate = np.array(lctable.field(ratecolumn), dtype=np.float)
+    rate = np.array(lctable.field(ratecolumn), dtype=float)
 
     try:
         rate_e = np.array(lctable.field("ERROR"), dtype=np.longdouble)
@@ -743,7 +743,7 @@ def lcurve_from_txt(
 
     time, counts = np.genfromtxt(txt_file, delimiter=" ", unpack=True)
     time = np.array(time, dtype=np.longdouble)
-    counts = np.array(counts, dtype=np.float)
+    counts = np.array(counts, dtype=float)
 
     lc = Lightcurve(time=time, counts=counts, gti=gti, mjdref=mjdref)
 
diff --git a/hendrics/phaseogram.py b/hendrics/phaseogram.py
index cead714..9adbcde 100644
--- a/hendrics/phaseogram.py
+++ b/hendrics/phaseogram.py
@@ -261,11 +261,7 @@ class BasePhaseogram(object):
         self.slider_axes = []
 
         def newax_fn(*args, **kwargs):
-            try:
-                ax = plt.axes(*args, facecolor=axcolor)
-            except AttributeError:
-                # MPL < 2
-                ax = plt.axes(*args, axis_bgcolor=axcolor)
+            ax = self.fig.add_axes(*args, facecolor=axcolor)
             return ax
 
         self.slider_axes.append(
@@ -280,32 +276,32 @@ class BasePhaseogram(object):
 
         self._construct_widgets(**kwargs)
 
-        self.closeax = plt.axes([0.15, 0.020, 0.15, 0.04])
+        self.closeax = self.fig.add_axes([0.15, 0.020, 0.15, 0.04])
         self.button_close = Button(
             self.closeax, "Quit", color=axcolor, hovercolor="0.8"
         )
 
-        self.recalcax = plt.axes([0.3, 0.020, 0.15, 0.04])
+        self.recalcax = self.fig.add_axes([0.3, 0.020, 0.15, 0.04])
         self.button_recalc = Button(
             self.recalcax, "Recalculate", color=axcolor, hovercolor="0.975"
         )
 
-        self.resetax = plt.axes([0.45, 0.020, 0.15, 0.04])
+        self.resetax = self.fig.add_axes([0.45, 0.020, 0.15, 0.04])
         self.button_reset = Button(
             self.resetax, "Reset", color=axcolor, hovercolor="0.975"
         )
 
-        self.zoominax = plt.axes([0.6, 0.020, 0.1, 0.04])
+        self.zoominax = self.fig.add_axes([0.6, 0.020, 0.1, 0.04])
         self.button_zoomin = Button(
             self.zoominax, "+Zoom", color=axcolor, hovercolor="0.975"
         )
 
-        self.zoomoutax = plt.axes([0.7, 0.020, 0.1, 0.04])
+        self.zoomoutax = self.fig.add_axes([0.7, 0.020, 0.1, 0.04])
         self.button_zoomout = Button(
             self.zoomoutax, "-Zoom", color=axcolor, hovercolor="0.975"
         )
 
-        self.toaax = plt.axes([0.8, 0.020, 0.1, 0.04])
+        self.toaax = self.fig.add_axes([0.8, 0.020, 0.1, 0.04])
         self.button_toa = Button(
             self.toaax, "TOA", color=axcolor, hovercolor="0.975"
         )
@@ -532,15 +528,15 @@ class InteractivePhaseogram(BasePhaseogram):
         tseg = np.median(np.diff(self.times))
         tobs = tseg * self.nt
         delta_df_start = 4 / tobs
-        self.df_order_of_mag = np.int(np.log10(delta_df_start))
+        self.df_order_of_mag = int(np.log10(delta_df_start))
         delta_df = delta_df_start / 10 ** self.df_order_of_mag
 
         delta_dfdot_start = 8 / tobs ** 2
-        self.dfdot_order_of_mag = np.int(np.log10(delta_dfdot_start))
+        self.dfdot_order_of_mag = int(np.log10(delta_dfdot_start))
         delta_dfdot = delta_dfdot_start / 10 ** self.dfdot_order_of_mag
 
         delta_dfddot_start = 16 / tobs ** 3
-        self.dfddot_order_of_mag = np.int(np.log10(delta_dfddot_start))
+        self.dfddot_order_of_mag = int(np.log10(delta_dfddot_start))
         delta_dfddot = delta_dfddot_start / 10 ** self.dfddot_order_of_mag
 
         freq_str = r"$\Delta$ F0" "x$10^{" + f"{self.df_order_of_mag}" + r"}$"
@@ -652,19 +648,21 @@ class InteractivePhaseogram(BasePhaseogram):
         template = gaussian_filter1d(template_raw, sigma=1)
 
         if self.nph < 64:
-            warnings.warn("TOA calculation is not robust if the "
-                          "number of bins is < 64. Oversampling.")
+            warnings.warn(
+                "TOA calculation is not robust if the "
+                "number of bins is < 64. Oversampling."
+            )
             nbin = 64
             phases = np.arange(self.nph * 2 + 1) / (self.nph * 2)
-            fun = interp1d(phases,
-                           np.concatenate((template, [template[0]])),
-                           kind='cubic')
+            fun = interp1d(
+                phases, np.concatenate((template, [template[0]])), kind="cubic"
+            )
             new_phases = np.arange(0, nbin * 2) / (nbin * 2)
             template = fun(new_phases)
 
-        template = template[nbin // 2: nbin // 2 + template.size // 2]
+        template = template[nbin // 2 : nbin // 2 + template.size // 2]
 
-        template = (np.roll(template, -np.argmax(template)) / self.nt)
+        template = np.roll(template, -np.argmax(template)) / self.nt
 
         toa, toaerr = get_TOAs_from_events(
             self.ev_times,
@@ -885,7 +883,7 @@ def run_interactive_phaseogram(
 
     position = name = None
 
-    if hasattr(events, 'header') and events.header is not None:
+    if hasattr(events, "header") and events.header is not None:
         header = Header.fromstring(events.header)
 
         try:
@@ -898,7 +896,7 @@ def run_interactive_phaseogram(
         except (KeyError, AttributeError):
             position = None
 
-        if 'OBJECT' in header:
+        if "OBJECT" in header:
             name = header["OBJECT"]
 
     pepoch_mjd = pepoch
@@ -1068,7 +1066,7 @@ def main_phaseogram(args=None):
             fdot = args.fdot
             fddot = args.fddot
 
-        _ = run_interactive_phaseogram(
+        ip = run_interactive_phaseogram(
             args.file,
             freq=frequency,
             fdot=fdot,
@@ -1085,3 +1083,4 @@ def main_phaseogram(args=None):
             emin=args.emin,
             emax=args.emax,
         )
+    plt.close(ip.fig)
diff --git a/hendrics/plot.py b/hendrics/plot.py
index 90176c0..9c02f48 100644
--- a/hendrics/plot.py
+++ b/hendrics/plot.py
@@ -379,7 +379,7 @@ def plot_folding(
         ntrial = ef.stat.size
         if hasattr(ef, "oversample") and ef.oversample is not None:
             ntrial /= ef.oversample
-            ntrial = np.int(ntrial)
+            ntrial = int(ntrial)
         if ef.kind == "Z2n":
             vmin = ef.N - 1
             vmax = z2_n_detection_level(
@@ -499,8 +499,8 @@ def plot_folding(
             # print(df, dfdot)
             # # noinspection PyPackageRequirements
             # ax.text(0.1, 0.9, "Profile for F0={} Hz, F1={} Hz/s".format(
-            #     round(f, -np.int(np.floor(np.log10(np.abs(df))))),
-            #     round(fdot, -np.int(np.floor(np.log10(np.abs(dfdot)))))),
+            #     round(f, -int(np.floor(np.log10(np.abs(df))))),
+            #     round(fdot, -int(np.floor(np.log10(np.abs(dfdot)))))),
             #     horizontalalignment='left', verticalalignment='center',
             #     transform=ax.transAxes)
             ax.plot(
@@ -583,7 +583,12 @@ def plot_folding(
                 axfdot.axvline(vmax)
             axffdot = plt.subplot(gs[1, 0], sharex=axf, sharey=axfdot)
             axffdot.pcolormesh(
-                ef.freq, np.asarray(ef.fdots), ef.stat, vmin=vmin, vmax=vmax
+                ef.freq,
+                np.asarray(ef.fdots),
+                ef.stat,
+                vmin=vmin,
+                vmax=vmax,
+                shading="nearest",
             )
             maximum_idx = 0
             maximum = 0
diff --git a/hendrics/rebin.py b/hendrics/rebin.py
index 23b0fb2..1ef8f31 100644
--- a/hendrics/rebin.py
+++ b/hendrics/rebin.py
@@ -15,7 +15,7 @@ def rebin_file(filename, rebin):
     if ftype not in ["lc", "pds", "cpds"]:
         raise ValueError("This format does not support rebin (yet):", ftype)
 
-    if rebin == np.int(rebin):
+    if rebin == int(rebin):
         contents = contents.rebin(f=rebin)
     else:
         contents = contents.rebin_log(f=rebin)
diff --git a/setup.cfg b/setup.cfg
index 31862bc..0170c7a 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -131,6 +131,7 @@ filterwarnings =
     ignore: SIMON says. Coherence is not ideal:UserWarning
     ignore:SIMON says. The excess variance in the:UserWarning
     ignore:SIMON says. Number of segments used in averaging:UserWarning
+    ignore:deprecated alias for the builtin:DeprecationWarning
 
 [coverage:run]
 omit =


Test patch:
diff --git a/hendrics/tests/test_efsearch.py b/hendrics/tests/test_efsearch.py
index f242cf1..c72460d 100644
--- a/hendrics/tests/test_efsearch.py
+++ b/hendrics/tests/test_efsearch.py
@@ -160,22 +160,7 @@ class TestEFsearch:
         os.unlink(outfile)
         main_fold(
             [
-                evfile,
-                "-f",
-                str(self.pulse_frequency),
-                "-n",
-                "64",
-                "--test",
-                "--norm",
-                "to1",
-            ]
-        )
-        outfile = "Energyprofile_to1.png"
-        assert os.path.exists(outfile)
-        os.unlink(outfile)
-        main_fold(
-            [
-                evfile,
+                evfile_noe,
                 "-f",
                 str(self.pulse_frequency),
                 "-n",
@@ -185,7 +170,7 @@ class TestEFsearch:
                 "blablabla",
             ]
         )
-        outfile = "Energyprofile_to1.png"
+        outfile = "Energyprofile.png"
         assert os.path.exists(outfile)
         os.unlink(outfile)
         main_fold(
@@ -197,27 +182,12 @@ class TestEFsearch:
                 "64",
                 "--test",
                 "--norm",
-                "blablabla",
+                "to1",
             ]
         )
         outfile = "Energyprofile_to1.png"
         assert os.path.exists(outfile)
         os.unlink(outfile)
-        main_fold(
-            [
-                evfile_noe,
-                "-f",
-                str(self.pulse_frequency),
-                "-n",
-                "64",
-                "--test",
-                "--norm",
-                "blablabla",
-            ]
-        )
-        outfile = "Energyprofile.png"
-        assert os.path.exists(outfile)
-        os.unlink(outfile)
 
     def test_fold_invalid(self):
         evfile = self.dum
@@ -365,11 +335,11 @@ class TestEFsearch:
                 "-F",
                 "9.95",
                 "-n",
-                "64",
+                "32",
                 "--fdotmin",
-                " -0.1",
+                " -0.01",
                 "--fdotmax",
-                "0.1",
+                "0.01",
                 "--fit-candidates",
                 "--fit-frequency",
                 str(self.pulse_frequency),
@@ -398,12 +368,14 @@ class TestEFsearch:
                 "-F",
                 "9.95",
                 "-n",
-                "64",
+                "32",
                 "--fdotmin",
                 " -0.1",
                 "--fdotmax",
                 "0.1",
                 "--transient",
+                "--n-transient-intervals",
+                "16",
             ]
         )
         outfile = "events_transient.gif"
@@ -553,17 +525,24 @@ class TestEFsearch:
 
     def test_zsearch_fdots_ffa(self):
         evfile = self.dum
-        main_zsearch(
+        with pytest.warns(UserWarning) as record:
+            main_zsearch(
+                [
+                    evfile,
+                    "-f",
+                    "9.89",
+                    "-F",
+                    "9.92",
+                    "-n",
+                    "32",
+                    "--ffa",
+                    "--find-candidates",
+                ]
+            )
+        assert np.any(
             [
-                evfile,
-                "-f",
-                "9.89",
-                "-F",
-                "9.92",
-                "-n",
-                "64",
-                "--ffa",
-                "--find-candidates",
+                "Folding Algorithm functionality" in r.message.args[0]
+                for r in record
             ]
         )
         outfile = "events_Z22_9.89-9.92Hz_ffa" + HEN_FILE_EXTENSION
@@ -599,6 +578,8 @@ class TestEFsearch:
                 "64",
                 "--fast",
                 "--transient",
+                "--n-transient-intervals",
+                "16",
             ]
         )
 
@@ -704,35 +685,56 @@ class TestEFsearch:
 
     def test_accelsearch(self):
         evfile = self.dum
-        outfile = main_accelsearch(
-            [evfile, "--fmin", "1", "--fmax", "10", "--zmax", "1"]
+        with pytest.warns(UserWarning) as record:
+            outfile = main_accelsearch(
+                [evfile, "--fmin", "1", "--fmax", "10", "--zmax", "1"]
+            )
+        assert np.any(
+            [
+                "The accelsearch functionality is " in r.message.args[0]
+                for r in record
+            ]
         )
         assert os.path.exists(outfile)
         os.unlink(outfile)
 
     def test_accelsearch_nodetections(self):
         evfile = self.dum_scramble
-        outfile = main_accelsearch(
-            [evfile, "--fmin", "1", "--fmax", "1.1", "--zmax", "1"]
+        with pytest.warns(UserWarning) as record:
+            outfile = main_accelsearch(
+                [evfile, "--fmin", "1", "--fmax", "1.1", "--zmax", "1"]
+            )
+        assert np.any(
+            [
+                "The accelsearch functionality is " in r.message.args[0]
+                for r in record
+            ]
         )
         assert os.path.exists(outfile)
         os.unlink(outfile)
 
     def test_accelsearch_energy_and_freq_filt(self):
         evfile = self.dum
-        outfile = main_accelsearch(
+        with pytest.warns(UserWarning) as record:
+            outfile = main_accelsearch(
+                [
+                    evfile,
+                    "--emin",
+                    "3",
+                    "--emax",
+                    "80",
+                    "--fmin",
+                    "0.1",
+                    "--fmax",
+                    "1",
+                    "--zmax",
+                    "5",
+                ]
+            )
+        assert np.any(
             [
-                evfile,
-                "--emin",
-                "3",
-                "--emax",
-                "80",
-                "--fmin",
-                "0.1",
-                "--fmax",
-                "1",
-                "--zmax",
-                "5",
+                "The accelsearch functionality is " in r.message.args[0]
+                for r in record
             ]
         )
         assert os.path.exists(outfile)
@@ -740,19 +742,35 @@ class TestEFsearch:
 
     def test_accelsearch_pad(self):
         evfile = self.dum
-        outfile = main_accelsearch([evfile, "--pad-to-double", "--zmax", "1"])
+        with pytest.warns(UserWarning) as record:
+            outfile = main_accelsearch(
+                [evfile, "--pad-to-double", "--zmax", "1"]
+            )
+        assert np.any(
+            [
+                "The accelsearch functionality is " in r.message.args[0]
+                for r in record
+            ]
+        )
         assert os.path.exists(outfile)
         os.unlink(outfile)
 
     def test_accelsearch_interbin(self):
         evfile = self.dum
-        outfile = main_accelsearch([evfile, "--interbin", "--zmax", "1"])
+        with pytest.warns(UserWarning) as record:
+            outfile = main_accelsearch([evfile, "--interbin", "--zmax", "1"])
+        assert np.any(
+            [
+                "The accelsearch functionality is " in r.message.args[0]
+                for r in record
+            ]
+        )
         assert os.path.exists(outfile)
         os.unlink(outfile)
 
     def test_z2vspf(self):
         evfile = self.dum
-        ip = main_z2vspf([evfile, "--show-z-values", "30"])
+        ip = main_z2vspf([evfile, "--show-z-values", "30", "--ntrial", "10"])
 
     @classmethod
     def teardown_class(cls):
diff --git a/hendrics/tests/test_fake.py b/hendrics/tests/test_fake.py
index a38b7b1..12a5a7f 100644
--- a/hendrics/tests/test_fake.py
+++ b/hendrics/tests/test_fake.py
@@ -81,6 +81,38 @@ def test_filter_for_deadtime_par_bkg():
     )
 
 
+def test_filter_for_deadtime_par_bkg_obj():
+    """Test dead time filter on Eventlist, paral. case, with background."""
+    times = np.array([1.1, 2, 2.2, 3, 3.2])
+    pis = np.arange(times.size) + 5
+    energies = np.arange(times.size) + 10
+    events = EventList(time=times, energy=energies, pi=pis)
+    bkg_events = np.array([1, 3.1])
+    filt_events, info = hen.fake.filter_for_deadtime(
+        events, 0.11, bkg_ev_list=bkg_events, paralyzable=True, return_all=True
+    )
+    expected_ev = np.array([2, 2.2, 3])
+    expected_bk = np.array([1])
+    expected_pi = np.array([6, 7, 8])
+    expected_nrg = np.array([11, 12, 13])
+    filt_times = filt_events.time
+    filt_pis = filt_events.pi
+    filt_nrgs = filt_events.energy
+
+    assert np.all(filt_times == expected_ev), "Wrong: {} vs {}".format(
+        filt_events, expected_ev
+    )
+    assert np.all(filt_pis == expected_pi), "Wrong: {} vs {}".format(
+        filt_events, expected_ev
+    )
+    assert np.all(filt_nrgs == expected_nrg), "Wrong: {} vs {}".format(
+        filt_events, expected_ev
+    )
+    assert np.all(info.bkg == expected_bk), "Wrong: {} vs {}".format(
+        info.bkg, expected_bk
+    )
+
+
 def test_deadtime_mask_par():
     """Test dead time filter, paralyzable case, with background."""
     events = np.array([1.1, 2, 2.2, 3, 3.2])
@@ -164,7 +196,14 @@ class TestFake(object):
         """Test produce a fake event file from input light curve."""
         lcurve_in = os.path.join(self.datadir, "lcurveA.fits")
         fits_file = os.path.join(self.datadir, "monol_test_fake_lc.evt")
-        hen.fake.main(["--lc", lcurve_in, "-o", fits_file])
+        with pytest.warns(UserWarning) as record:
+            hen.fake.main(["--lc", lcurve_in, "-o", fits_file])
+        assert np.any(
+            [
+                "FITS light curve handling is st" in r.message.args[0]
+                for r in record
+            ]
+        )
 
     def test_fake_file_with_deadtime(self):
         """Test produce a fake event file and apply deadtime."""
@@ -203,7 +242,11 @@ class TestFake(object):
     def test_scramble_uncalibrated_events_file_raises(self):
         command = f"{self.first_event_file} -e 3 30"
         with pytest.raises(ValueError):
-            _ = hen.fake.main_scramble(command.split())
+            with pytest.warns(UserWarning) as record:
+                _ = hen.fake.main_scramble(command.split())
+        assert np.any(
+            ["No energy information" in r.message.args[0] for r in record]
+        )
 
     def test_scramble_calibrated_events_file(self):
         command = f"{self.first_event_file_cal} -e 3 30"
diff --git a/hendrics/tests/test_io.py b/hendrics/tests/test_io.py
index 496f1cb..fd32486 100644
--- a/hendrics/tests/test_io.py
+++ b/hendrics/tests/test_io.py
@@ -158,6 +158,9 @@ class TestIO:
             mjdref=54385.3254923845,
             gti=np.longdouble([[-0.5, 3.5]]),
         )
+        # Monkeypatch for compatibility with old versions
+        lcurve.mission = "bububu"
+        lcurve.instr = "bababa"
         save_lcurve(lcurve, self.dum)
         lcurve2 = load_lcurve(self.dum)
         assert np.allclose(lcurve.time, lcurve2.time)
@@ -165,6 +168,9 @@ class TestIO:
         assert np.allclose(lcurve.mjdref, lcurve2.mjdref)
         assert np.allclose(lcurve.gti, lcurve2.gti)
         assert lcurve.err_dist == lcurve2.err_dist
+        assert lcurve.mission == lcurve2.mission
+        assert lcurve2.mission == "bububu"
+        assert lcurve.instr == lcurve2.instr
 
     def test_load_and_save_pds(self):
         pds = Powerspectrum()
@@ -177,7 +183,7 @@ class TestIO:
 
         save_pds(pds, self.dum)
         pds2 = load_pds(self.dum)
-        for attr in ['gti', 'mjdref', 'm', 'show_progress', 'amplitude']:
+        for attr in ["gti", "mjdref", "m", "show_progress", "amplitude"]:
             assert np.allclose(getattr(pds, attr), getattr(pds2, attr))
 
     def test_load_and_save_xps(self):
diff --git a/hendrics/tests/test_phaseogram.py b/hendrics/tests/test_phaseogram.py
index 8565be4..427431f 100644
--- a/hendrics/tests/test_phaseogram.py
+++ b/hendrics/tests/test_phaseogram.py
@@ -85,7 +85,7 @@ class TestPhaseogram:
         # Defaults to 2 harmonics
         assert efperiod.N == 2
 
-    @pytest.mark.parametrize('label', ('', '_info', '_nohead'))
+    @pytest.mark.parametrize("label", ("", "_info", "_nohead"))
     def test_phaseogram_input_periodogram(self, label):
         evfile = getattr(self, "dum" + label)
         main_phaseogram(
@@ -150,8 +150,12 @@ class TestPhaseogram:
         ip.recalculate(1)
         with pytest.warns(UserWarning) as record:
             ip.toa(1)
-        assert np.any(["TOA calculation is not robust" in r.message.args[0]
-                       for r in record])
+        assert np.any(
+            [
+                "TOA calculation is not robust" in r.message.args[0]
+                for r in record
+            ]
+        )
         ip.reset(1)
         ip.fdot = 2
         f, fdot, fddot = ip.get_values()
@@ -184,8 +188,12 @@ class TestPhaseogram:
         ip.recalculate(1)
         with pytest.warns(UserWarning) as record:
             ip.toa(1)
-        assert np.any(["TOA calculation is not robust" in r.message.args[0]
-                       for r in record])
+        assert np.any(
+            [
+                "TOA calculation is not robust" in r.message.args[0]
+                for r in record
+            ]
+        )
         ip.reset(1)
         ip.fdot = 2
         f, fdot, fddot = ip.get_values()
diff --git a/hendrics/tests/test_read_events.py b/hendrics/tests/test_read_events.py
index 30301d6..056f866 100644
--- a/hendrics/tests/test_read_events.py
+++ b/hendrics/tests/test_read_events.py
@@ -68,24 +68,27 @@ class TestMergeEvents:
         cls.f0, cls.f1, cls.f2, cls.f3, cls.f4 = f0, f1, f2, f3, f4
 
     def test_merge_events(self):
-        hen.read_events.main_join(
-            [
-                self.f0,
-                self.f1,
-                "-o",
-                os.path.join(
-                    self.datadir, "monol_merg_ev" + HEN_FILE_EXTENSION
-                ),
-            ]
-        )
+        with pytest.warns(UserWarning) as record:
+            hen.read_events.main_join(
+                [
+                    self.f0,
+                    self.f1,
+                    "-o",
+                    os.path.join(
+                        self.datadir, "monol_merg_ev" + HEN_FILE_EXTENSION
+                    ),
+                ]
+            )
+        assert np.any(["changing MJDREF" in r.message.args[0] for r in record])
 
         out = os.path.join(self.datadir, "monol_merg_ev" + HEN_FILE_EXTENSION)
         assert os.path.exists(out)
         os.unlink(out)
 
     def test_merge_events_no_out_fname(self):
-        hen.read_events.main_join([self.f0, self.f1])
-
+        with pytest.warns(UserWarning) as record:
+            hen.read_events.main_join([self.f0, self.f1])
+        assert np.any(["changing MJDREF" in r.message.args[0] for r in record])
         out = os.path.join(self.datadir, "ev_ev" + HEN_FILE_EXTENSION)
         assert os.path.exists(out)
         os.unlink(out)
@@ -129,7 +132,9 @@ class TestMergeEvents:
     def test_merge_many_events(self):
         outfile = "joint_ev" + HEN_FILE_EXTENSION
         # Note that only 0 and 2 are valid
-        hen.read_events.main_join([self.f0, self.f2, self.f3])
+        with pytest.warns(UserWarning) as record:
+            hen.read_events.main_join([self.f0, self.f2, self.f3])
+
         assert os.path.exists(outfile)
 
         data = load_events(outfile)
@@ -178,6 +183,10 @@ class TestReadEvents:
             cls.datadir, "monol_testB_nustar_fpmb_ev" + HEN_FILE_EXTENSION
         )
 
+    def test_start(self):
+        """Make any warnings in setup_class be dumped here."""
+        pass
+
     def test_treat_event_file_nustar(self):
         treat_event_file(self.fits_fileA)
         new_filename = "monol_testA_nustar_fpma_ev" + HEN_FILE_EXTENSION
@@ -196,6 +205,7 @@ class TestReadEvents:
         assert "instr" in data
         assert "gti" in data
         assert "mjdref" in data
+        assert "pi" in data and data["pi"].size > 0
 
     def test_treat_event_file_xmm_gtisplit(self):
 
@@ -211,7 +221,7 @@ class TestReadEvents:
 
     def test_treat_event_file_xmm_lensplit(self):
 
-        treat_event_file(self.fits_file, length_split=10)
+        treat_event_file(self.fits_file, length_split=100)
         new_filename = (
             "monol_test_fake_xmm_epn_det01_chunk000_ev" + HEN_FILE_EXTENSION
         )
@@ -222,7 +232,7 @@ class TestReadEvents:
         assert "mjdref" in data
         gtis = data["gti"]
         lengths = np.array([g1 - g0 for (g0, g1) in gtis])
-        assert np.all(lengths <= 10)
+        assert np.all(lengths <= 100)
 
     def test_split_events(self):
         treat_event_file(self.fits_fileA)