diff --git a/CHANGELOG.md b/CHANGELOG.md index 8271b71..24ce838 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,15 @@ Versions follow [Semantic Versioning](https://semver.org) (`.. st return fig +def plot_timestamp_jumps( + timestamps: npt.NDArray | list, std_threshold: float = 2.0, as_html: bool = False +) -> str | go.Figure: + try: + timestamps = np.array([datetime.fromisoformat(str(ts, encoding="utf-8")) for ts in np.array(timestamps)]) + except ValueError: + timestamps = np.array([float(ts) for ts in timestamps]) + timedeltas = np.diff(timestamps).astype("timedelta64[ms]").astype(float) + zscored_intervals = stats.zscore(timedeltas) + + fig = go.Figure( + layout=go.Layout( + xaxis={"title": {"text": "Frame index"}}, + yaxis={"title": {"text": "Timedelta (ms)"}}, + margin={"l": 20, "r": 20, "t": 20, "b": 20}, + ) + ) + + fig.add_trace(go.Scatter(y=timedeltas, mode="lines", name="Timestamp")) + if as_html: + return fig.to_html(full_html=False) + return fig + + def plot_raw_timeseries(raw_timeseries: npt.NDArray, as_html: bool = False) -> str | go.Figure: """Plots a raw timeseries signal using Plotly. diff --git a/src/mesoscopy/report/__init__.py b/src/mesoscopy/report/__init__.py index e941a0f..ab45573 100644 --- a/src/mesoscopy/report/__init__.py +++ b/src/mesoscopy/report/__init__.py @@ -94,10 +94,23 @@ def generate_preprocessing_report(path: str, out_dir: str = ".") -> str: ), "frame_num": len(preproc.get("F")), # type: ignore[attr-defined] "filesize": preproc.id.get_filesize() / (1024 * 1024), + "qa_histogram_separation": preproc.attrs.get("/qa/checks/histogram_separation"), + "qa_timestamp_consistency": preproc.attrs.get("/qa/checks/timestamp_consistency"), + "qa_timestamp_jump": preproc.attrs.get("/qa/checks/timestamp_jump"), + "qa_check_noise": preproc.attrs.get("/qa/checks/noise_check"), + "qa_median_noise": np.median(np.array(preproc.get("/qa/noise_levels", 0))), + "qa_check_snr": preproc.attrs.get("/qa/checks/snr_check"), + "qa_snr": preproc.attrs.get("/qa/checks/snr"), + "qa_check_bleaching": preproc.attrs.get("/qa/checks/bleaching_check"), + "qa_bleaching_factor": preproc.attrs.get("/qa/checks/bleaching_factor"), "fig_integrity_timestamps": preqa.plot_timestamps( [np.datetime64(ts) for ts in preproc.get("timestamps")], # type: ignore[attr-defined] as_html=True, ), + "fig_integrity_timestamp_jumps": preqa.plot_timestamp_jumps( + preproc.get("timestamps"), # type: ignore[attr-defined] + as_html=True, + ), "fig_separation_pre_timeseries_mean": preqa.plot_raw_timeseries( preproc.get("qa").get("frame_means_timeseries"), # type: ignore[attr-defined] as_html=True, diff --git a/src/mesoscopy/report/templates/preprocessing.html b/src/mesoscopy/report/templates/preprocessing.html index eb178ad..750307d 100644 --- a/src/mesoscopy/report/templates/preprocessing.html +++ b/src/mesoscopy/report/templates/preprocessing.html @@ -7,11 +7,22 @@ Metadata +