Skip to content

Commit 0ee50c2

Browse files
Warn about missing imageio; save best detection info
1 parent 5a1c93e commit 0ee50c2

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

hendrics/efsearch.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from astropy.logger import AstropyUserWarning
2828
from astropy.table import Table
2929
from astropy.utils.introspection import minversion
30+
from astropy.table import vstack
3031

3132
from .base import (
3233
HENDRICS_STAR_VALUE,
@@ -630,10 +631,16 @@ def plot_transient_search(results, gif_name=None):
630631
import matplotlib as mpl
631632
import matplotlib.pyplot as plt
632633

634+
if not HAS_IMAGEIO:
635+
warnings.warn("imageio needed to save the transient search results into a gif image.")
636+
return None
637+
633638
mpl.use("Agg")
634639
if gif_name is None:
635640
gif_name = "transients.gif"
636641

642+
result_name = gif_name.replace(".gif", ".csv")
643+
max_stats_rows = []
637644
all_images = []
638645
for i, (ima, nave) in enumerate(zip(results.stats, results.nave)):
639646
f = results.freqs
@@ -692,7 +699,6 @@ def plot_transient_search(results, gif_name=None):
692699
)
693700
elif maxline >= 5 and i_f == 0: # pragma: no cover
694701
print(f"{gif_name}: Candidate at step {i}: {best_f} Hz (~{maxline:.1f} sigma)")
695-
696702
axf.plot(f, mean_line, lw=1, c="k", zorder=10, label="mean", ls="-")
697703

698704
axima.set_xlabel("Frequency")
@@ -703,6 +709,9 @@ def plot_transient_search(results, gif_name=None):
703709
xmin = max(best_f - df, results.f0)
704710
xmax = min(best_f + df, results.f1)
705711
if i_f == 0:
712+
max_stats_rows.append(
713+
{"step": i + 1, "nave": nave, "best_f": best_f, "max_stat": maxline}
714+
)
706715
axf.set_xlim([results.f0, results.f1])
707716
axf.axvline(xmin, ls="--", c="b", lw=2)
708717
axf.axvline(xmax, ls="--", c="b", lw=2)
@@ -715,11 +724,9 @@ def plot_transient_search(results, gif_name=None):
715724

716725
plt.close(fig)
717726
all_images.append(image)
727+
vstack(max_stats_rows).write(result_name, overwrite=True)
718728

719-
if HAS_IMAGEIO:
720-
imageio.v3.imwrite(gif_name, all_images, duration=1000.0)
721-
else:
722-
warnings.warn("imageio needed to save the transient search results " "into a gif image.")
729+
imageio.v3.imwrite(gif_name, all_images, duration=1000.0)
723730

724731
return all_images
725732

0 commit comments

Comments
 (0)