Skip to content

Commit

Permalink
nena debugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Heerpa committed Apr 9, 2024
1 parent b30017f commit de9f58b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
42 changes: 39 additions & 3 deletions picasso_workflow/analyse.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,16 +730,52 @@ def summarize_dataset(self, i, parameters, results):
for meth, meth_pars in parameters["methods"].items():
if meth.lower() == "nena":
try:
res, best_vals = postprocess.nena(self.locs, self.info)
results["nena"] = {"res": str(res), "best_vals": best_vals}
except ValueError:
res, best_val = postprocess.nena(self.locs, self.info)
fp_plot = os.path.join(results["folder"], "nena.png")
self._plot_nena(res, fp_plot)
all_best_vals = {
"a": res.best_values["a"],
"s": res.best_values["s"],
"ac": res.best_values["ac"],
"dc": res.best_values["dc"],
"sc": res.best_values["sc"],
}
results["nena"] = {
"res": str(all_best_vals),
"chisqr": res.chisqr,
"NeNa": (
f"{best_val:.3f} px;"
+ f" {130*best_val:.3f} nm "
+ "(assuming 130nm pixel size)"
),
"filepath_plot": fp_plot,
}
except ValueError as e:
logger.error(e)
results["nena"] = {"res": "Fitting Error", "best_vals": ""}
except Exception as e:
logger.error(e)
results["nena"] = {
"res": str(e.msg),
"best_vals": "Error.",
}
else:
raise NotImplementedError(
f"Description method {meth} not implemented."
)
return parameters, results

def _plot_nena(self, nena_result, filepath_plot):
fig, ax = plt.subplots()
d = nena_result.userkws["d"]
ax.set_title("Next frame neighbor distance histogram")
ax.plot(d, nena_result.data, label="Data")
ax.plot(d, nena_result.best_fit, label="Fit")
ax.set_xlabel("Distance [px]")
ax.set_ylabel("Counts")
ax.legend(loc="best")
fig.savefig(filepath_plot)

@module_decorator
def save_single_dataset(self, i, parameters, results):
"""Saves the locs and info of a single dataset; makes loading
Expand Down
16 changes: 13 additions & 3 deletions picasso_workflow/confluence.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def undrift_rcc(self, i, pars_undrift, res_undrift):
self.report_page_name, self.report_page_id, text
)

if driftimg_fn := pars_undrift.get("filepath_plot"):
if driftimg_fn := res_undrift.get("filepath_plot"):
self.ci.upload_attachment(self.report_page_id, driftimg_fn)
self.ci.update_page_content_with_image_attachment(
self.report_page_name,
Expand Down Expand Up @@ -289,12 +289,22 @@ def summarize_dataset(self, i, parameters, results):
text += f"""
<p>NeNa</p>
<ul>
<li>Best Values: {str(meth_res.get('best_vals'))}</li>
<li>Result: {str(meth_res.get('res'))}</li>
<li>NeNa value: {str(meth_res.get('NeNa'))}</li>
<li>Best Fit Values: {str(meth_res.get('res'))}</li>
<li>Chi Square: {str(meth_res.get('chisqr'))}</li>
</ul>"""
if fp_nena := meth_res.get("filepath_plot"):
self.ci.upload_attachment(self.report_page_id, fp_nena)
_, fn_nena = os.path.split(fp_nena)
text += (
"<ul><ac:image><ri:attachment "
+ f'ri:filename="{fn_nena}" />'
+ "</ac:image></ul>"
)
text += """
</ac:layout-cell></ac:layout-section></ac:layout>
"""
logger.debug("description text: " + text)
self.ci.update_page_content(
self.report_page_name, self.report_page_id, text
)
Expand Down

0 comments on commit de9f58b

Please sign in to comment.