|
|
|
@ -6,8 +6,20 @@ import pickle
@@ -6,8 +6,20 @@ import pickle
|
|
|
|
|
import seaborn |
|
|
|
|
import matplotlib.pyplot as pyplot |
|
|
|
|
|
|
|
|
|
from reportlab.platypus import ( |
|
|
|
|
SimpleDocTemplate, |
|
|
|
|
Paragraph, |
|
|
|
|
PageBreak, |
|
|
|
|
Spacer, |
|
|
|
|
KeepTogether, |
|
|
|
|
Image, |
|
|
|
|
) |
|
|
|
|
from reportlab.lib.pagesizes import A4 |
|
|
|
|
from reportlab.lib.styles import getSampleStyleSheet |
|
|
|
|
from reportlab.lib.units import mm |
|
|
|
|
from scipy.signal import savgol_filter |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from .commons import ROI_STATISTIC_FUNCTIONS |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -394,6 +406,119 @@ def save_data(data_frame, selected_df, extremas_df, parameters):
@@ -394,6 +406,119 @@ def save_data(data_frame, selected_df, extremas_df, parameters):
|
|
|
|
|
writer.save() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_report(data_frame, selected_df, extremas_df, parameters): |
|
|
|
|
styles = getSampleStyleSheet() |
|
|
|
|
style_headline = styles["Heading1"] |
|
|
|
|
style_section = styles["Heading2"] |
|
|
|
|
style_text = styles["Normal"] |
|
|
|
|
|
|
|
|
|
data_dir = parameters.data_dir |
|
|
|
|
path = data_dir / "report.pdf" |
|
|
|
|
doc = SimpleDocTemplate(str(path), pagesize=A4) |
|
|
|
|
|
|
|
|
|
img_width = doc.width * 0.9 |
|
|
|
|
img_height = (900 * img_width / 1200) * 0.9 |
|
|
|
|
|
|
|
|
|
num_images = len(data_frame) |
|
|
|
|
num_selected = len(selected_df) |
|
|
|
|
num_discarded = num_images - num_selected |
|
|
|
|
|
|
|
|
|
def text_and_graph(text, name): |
|
|
|
|
flowable = KeepTogether( |
|
|
|
|
[ |
|
|
|
|
Paragraph(text, style_text), |
|
|
|
|
Image( |
|
|
|
|
str(data_dir / name), width=img_width, height=img_height |
|
|
|
|
), |
|
|
|
|
Spacer(1, 7 * mm), |
|
|
|
|
] |
|
|
|
|
) |
|
|
|
|
return flowable |
|
|
|
|
|
|
|
|
|
story = [ |
|
|
|
|
Paragraph(f"Analysis of {num_images} Tif Images", style_headline), |
|
|
|
|
Spacer(1, 10 * mm), |
|
|
|
|
Paragraph("Estimating Guard Threshold", style_section), |
|
|
|
|
text_and_graph( |
|
|
|
|
( |
|
|
|
|
"In a first step, the histogram of the combined left and " |
|
|
|
|
"right guard values is calculated." |
|
|
|
|
), |
|
|
|
|
"1-histogram-of-guard-avarages-not-filtered.png", |
|
|
|
|
), |
|
|
|
|
text_and_graph( |
|
|
|
|
( |
|
|
|
|
"A Savitzky-Golay filter is applied to the histogram to " |
|
|
|
|
"smooth the curve." |
|
|
|
|
), |
|
|
|
|
"2-histogram-of-guard-avarages-filtered.png", |
|
|
|
|
), |
|
|
|
|
text_and_graph( |
|
|
|
|
( |
|
|
|
|
"The first minima after the first peak is used as the guard " |
|
|
|
|
f"threshold value: {int(parameters.guard_max_value)} au" |
|
|
|
|
), |
|
|
|
|
"3-histogram-of-guard-avarages-filtered-with-first-minima.png", |
|
|
|
|
), |
|
|
|
|
text_and_graph( |
|
|
|
|
( |
|
|
|
|
"The images with one of the guard values above the threshold " |
|
|
|
|
"are discarded." |
|
|
|
|
), |
|
|
|
|
"4-image-selection-based-on-guard-values.png", |
|
|
|
|
), |
|
|
|
|
Image( |
|
|
|
|
str(data_dir / "5-selected-values-based-on-guard-values.png"), |
|
|
|
|
width=img_width, |
|
|
|
|
height=img_height, |
|
|
|
|
), |
|
|
|
|
PageBreak(), |
|
|
|
|
Paragraph("Removing Outliers", style_section), |
|
|
|
|
text_and_graph( |
|
|
|
|
"From the remaining values, outliers are removed.", |
|
|
|
|
"6-boxplot-of-guarded-values.png", |
|
|
|
|
), |
|
|
|
|
text_and_graph( |
|
|
|
|
( |
|
|
|
|
f"From {num_images} images {num_discarded} images were " |
|
|
|
|
f"discarded, leaving {num_selected} selected. The finally " |
|
|
|
|
"selected values are listed in the excel sheet 'selection' " |
|
|
|
|
"in the data file." |
|
|
|
|
), |
|
|
|
|
"7-selected-images-outliers-removed.png", |
|
|
|
|
), |
|
|
|
|
PageBreak(), |
|
|
|
|
Paragraph( |
|
|
|
|
"Experimental: Applying a rolling min calculation", style_section |
|
|
|
|
), |
|
|
|
|
text_and_graph( |
|
|
|
|
( |
|
|
|
|
"Due to the nature of the experiment, unusable images tend " |
|
|
|
|
"to have a higher value as the desiered ones. Therfore a " |
|
|
|
|
"rolling min filter is applied" |
|
|
|
|
), |
|
|
|
|
"8-selected-images-outliers-removed-rolling-min-applied.png", |
|
|
|
|
), |
|
|
|
|
Paragraph("Experimental: Finding Maxima and Minima", style_section), |
|
|
|
|
text_and_graph( |
|
|
|
|
"To smooth the resulting curve, a Savitzky-Golay filter is used.", |
|
|
|
|
( |
|
|
|
|
"9-selected-images-outliers-" |
|
|
|
|
"removed-rolling-min-savgol-filtered.png" |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
text_and_graph( |
|
|
|
|
( |
|
|
|
|
"The most interesting data points should be the maxima and " |
|
|
|
|
"minima of this curve. These are listed in the sheet " |
|
|
|
|
"'extremas' in the data file" |
|
|
|
|
), |
|
|
|
|
"11-finding-minimas.png", |
|
|
|
|
), |
|
|
|
|
] |
|
|
|
|
doc.build(story) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def save_temp(data_frame, parameters): |
|
|
|
|
csv_path = parameters.tif_dir / "_data.csv" |
|
|
|
|
data_frame.to_csv(csv_path, sep="\t") |
|
|
|
|