|
21 | 21 | HumanReadableFileCallback, |
22 | 22 | ) |
23 | 23 | from ibex_bluesky_core.callbacks._fitting import LiveFit, LiveFitLogger |
24 | | -from ibex_bluesky_core.callbacks._plotting import LivePlot, show_plot |
| 24 | +from ibex_bluesky_core.callbacks._plotting import LivePlot, PlotPNGSaver, show_plot |
25 | 25 | from ibex_bluesky_core.callbacks._utils import get_default_output_path |
26 | 26 | from ibex_bluesky_core.fitting import FitMethod |
27 | 27 | from ibex_bluesky_core.utils import is_matplotlib_backend_qt |
|
38 | 38 | "LiveFit", |
39 | 39 | "LiveFitLogger", |
40 | 40 | "LivePlot", |
| 41 | + "PlotPNGSaver", |
41 | 42 | "get_default_output_path", |
42 | 43 | "show_plot", |
43 | 44 | ] |
@@ -67,6 +68,9 @@ def __init__( # noqa: PLR0912 |
67 | 68 | live_fit_logger_output_dir: str | PathLike[str] | None = None, |
68 | 69 | live_fit_logger_postfix: str = "", |
69 | 70 | human_readable_file_postfix: str = "", |
| 71 | + save_plot_to_png: bool = True, |
| 72 | + plot_png_output_dir: str | PathLike[str] | None = None, |
| 73 | + plot_png_postfix: str = "", |
70 | 74 | live_fit_update_every: int | None = 1, |
71 | 75 | live_plot_update_on_every_event: bool = True, |
72 | 76 | ) -> None: |
@@ -127,9 +131,13 @@ def _inner(): |
127 | 131 | live_fit_logger_output_dir: the output directory for live fit logger. |
128 | 132 | live_fit_logger_postfix: the postfix to add to live fit logger. |
129 | 133 | human_readable_file_postfix: optional postfix to add to human-readable file logger. |
| 134 | + save_plot_to_png: whether to save the plot to a PNG file. |
| 135 | + plot_png_output_dir: the output directory for plotting PNG files. |
| 136 | + plot_png_postfix: the postfix to add to PNG plot files. |
130 | 137 | live_fit_update_every: How often, in points, to recompute the fit. If None, do not compute until the end. |
131 | 138 | live_plot_update_on_every_event: whether to show the live plot on every event, or just at the end. |
132 | 139 | """ # noqa |
| 140 | + fig = None |
133 | 141 | self._subs = [] |
134 | 142 | self._peak_stats = None |
135 | 143 | self._live_fit = None |
@@ -230,6 +238,16 @@ def start(self, doc: RunStart) -> None: |
230 | 238 | update_on_every_event=live_plot_update_on_every_event, |
231 | 239 | ) |
232 | 240 | ) |
| 241 | + if save_plot_to_png and ax is not None: |
| 242 | + self._subs.append( |
| 243 | + PlotPNGSaver( |
| 244 | + x=x, |
| 245 | + y=y, |
| 246 | + ax=ax, |
| 247 | + output_dir=plot_png_output_dir, |
| 248 | + postfix=plot_png_postfix, |
| 249 | + ) |
| 250 | + ) |
233 | 251 |
|
234 | 252 | @property |
235 | 253 | def live_fit(self) -> LiveFit: |
|
0 commit comments