diff --git a/mlair/plotting/preprocessing_plotting.py b/mlair/plotting/preprocessing_plotting.py index da5916fbf82b78975e5fd56e64515f898e8eff15..70c007c6f8f35a2da8fc8c57bbb2ac79a7e52208 100644 --- a/mlair/plotting/preprocessing_plotting.py +++ b/mlair/plotting/preprocessing_plotting.py @@ -454,6 +454,8 @@ class PlotPeriodogram(AbstractPlotClass): self._prepare_pgram(generator, pos) self._plot(raw=True) self._plot(raw=False) + self._plot_total(raw=True) + self._plot_total(raw=False) def _prepare_pgram(self, generator, pos): raw_data = dict() @@ -529,3 +531,41 @@ class PlotPeriodogram(AbstractPlotClass): # close all open figures / plots pdf_pages.close() plt.close('all') + + def _plot_total(self, raw=True): + plot_path = os.path.join(os.path.abspath(self.plot_folder), + f"{self.plot_name}{'_raw' if raw else ''}_{self._sampling}_total.pdf") + pdf_pages = matplotlib.backends.backend_pdf.PdfPages(plot_path) + fig, ax = plt.subplots() + res = None + for var in self.plot_data_raw.keys(): + d_var = self.plot_data_raw[var][1] + res = d_var if res is None else np.concatenate((res, d_var), axis=-1) + if raw is True: + for i in range(res.shape[1]): + ax.plot(self.f_index, res[:, i], "lightblue") + ax.plot(self.f_index, res.mean(axis=1), "blue") + else: + ma = pd.DataFrame(np.vstack(res)).rolling(5, center=True, axis=0) + mean = ma.mean().mean(axis=1).values.flatten() + upper, lower = ma.max().mean(axis=1).values.flatten(), ma.min().mean(axis=1).values.flatten() + ax.plot(self.f_index, mean, "blue") + ax.fill_between(self.f_index, lower, upper, color="lightblue") + plt.yscale("log") + plt.xscale("log") + ax.set_ylabel("power", fontsize='x-large') + ax.set_xlabel("frequency $[day^{-1}$]", fontsize='x-large') + lims = ax.get_ylim() + self._add_annotation_line([1, 2, 3], 365.25, lims, "yr") # per year + self._add_annotation_line(1, 365.25 / 12, lims, "m") # per month + self._add_annotation_line(1, 7, lims, "w") # per week + self._add_annotation_line([1, 0.5], 1, lims, "d") # per day + if self._sampling == "hourly": + self._add_annotation_line(2, 1, lims, "d") # per day + self._add_annotation_line([1, 0.5], 1 / 24., lims, "h") # per hour + title = f"Periodogram (total)" + plt.title(title) + pdf_pages.savefig() + # close all open figures / plots + pdf_pages.close() + plt.close('all')