|
from reports.BrightnessReport import BrightnessReport |
|
from reports.DecodabilityReport import DecodabilityReport |
|
from reports.MaskedBrightnessReport import MaskedBrightnessReport |
|
from reports.FocusReport import FocusReport |
|
import numpy as np |
|
import matplotlib.pyplot as plt |
|
from matplotlib.backends.backend_pdf import PdfPages |
|
|
|
import pandas as pd |
|
|
|
|
|
|
|
def generate_brightness_reports(image_stack_file,coord_info,out_file,fov,z): |
|
|
|
import multiprocessing |
|
job = multiprocessing.Process(target=brightness_worker,args=(image_stack_file,coord_info,out_file,fov,z)) |
|
job.start() |
|
|
|
|
|
|
|
def brightness_worker(image_stack_file,coord_info,out_file,fov,z): |
|
br = BrightnessReport(image_stack_file,coord_info,fov,z) |
|
br.set_pdf(PdfPages(filename=out_file)) |
|
|
|
br.preview_images() |
|
br.brightness_infov_z() |
|
br.brightness_on_images() |
|
br.contrast_heatmap() |
|
br.closePdf() |
|
|
|
|
|
def generate_masked_brightness_reports(image_stack_file,coord_info,out_file,fov,z,mask_stack): |
|
|
|
import multiprocessing |
|
job = multiprocessing.Process(target=masked_brightness_worker,args=(image_stack_file,mask_stack,coord_info,out_file,fov,z)) |
|
job.start() |
|
|
|
def masked_brightness_worker(image_stack_file,mask_stack,coord_info,out_file,fov,z): |
|
mbr = MaskedBrightnessReport(image_stack_file,mask_stack,coord_info,fov,z) |
|
mbr.set_pdf(PdfPages(filename=out_file)) |
|
|
|
mbr.preview_images() |
|
mbr.brightness_infov_z() |
|
mbr.brightness_on_images() |
|
mbr.contrast_heatmap() |
|
mbr.closePdf() |
|
|
|
|
|
|
|
def generate_decodability_reports(image_stack_file,coord_info,out_file,codebook_file,data_org_file,fov,z,out_detection_stats,): |
|
|
|
import multiprocessing |
|
job = multiprocessing.Process(target=decodability_worker,args=(image_stack_file,coord_info,out_file,codebook_file,data_org_file,fov,z,out_detection_stats)) |
|
job.start() |
|
|
|
def decodability_worker(image_stack_file,coord_info,out_file,codebook_file,data_org_file,fov,z,out_detection_stats): |
|
dr = DecodabilityReport(image_stack_file,coord_info,codebook_file,data_org_file,fov,z,out_detection_stats) |
|
dr.set_pdf(PdfPages(filename=out_file)) |
|
|
|
dr.make_bit_imgs() |
|
dr.make_decodability_hists() |
|
dr.closePdf() |
|
|
|
|
|
|
|
def generate_focus_reports(image_stack_file,coord_info,out_file,out_csv,fov): |
|
|
|
import multiprocessing |
|
job = multiprocessing.Process(target=focus_worker,args=(image_stack_file,coord_info,out_file,out_csv,fov)) |
|
job.start() |
|
|
|
|
|
|
|
def focus_worker(image_stack_file,coord_info,out_file,out_csv,fov): |
|
fr = FocusReport(image_stack_file,coord_info,fov,out_csv) |
|
fr.set_pdf(PdfPages(filename=out_file)) |
|
fr.f_measure_report() |
|
fr.closePdf() |
|
|
|
|
|
|
|
def compile_focus_report(file_list:list,output,irs,wvs): |
|
|
|
full_df = pd.DataFrame() |
|
for fl in file_list: |
|
test = pd.read_csv(fl) |
|
full_df = full_df.append(test,ignore_index=True) |
|
|
|
full_df.to_csv(output) |
|
if not isinstance(irs,list): |
|
irs = list(irs) |
|
report_pdf = PdfPages(filename = output) |
|
|
|
|
|
compiled_matrix = np.zeros(( |
|
len(file_list), |
|
len(wvs), |
|
len(irs) |
|
)) |
|
|
|
for iir, ir in enumerate(irs): |
|
|
|
for iwv, wv in enumerate(wvs): |
|
data = full_df[["FOV",str(wv)]][(full_df["IR"]==int(ir))] |
|
|
|
data = data.to_numpy() |
|
|
|
compiled_matrix[:,iwv,iir] = data[:,1] |
|
|
|
|
|
|
|
f,ax = plt.subplots(nrows = len(wvs),ncols = 1,sharex=True,sharey=True,figsize=(8,len(irs)*4)) |
|
|
|
if not isinstance(ax,np.ndarray): |
|
ax = np.array(ax) |
|
|
|
for iwv, wv in enumerate(wvs): |
|
ax[iwv].imshow(compiled_matrix[:,iwv,:]) |
|
ax[iwv].set_xticks(np.arange(len(irs)), irs) |
|
ax[iwv].set_yticks(np.arange(len(file_list)), np.arange(len(file_list))) |
|
ax[iwv].set_ylabel("FOVS ") |
|
ax[iwv].set_xlabel("Imaging Round") |
|
plt.setp(ax[iwv].get_xticklabels(), rotation=45, ha="right", rotation_mode="anchor") |
|
|
|
for iir in range(len(irs)): |
|
for ifl in range(len(file_list)): |
|
text = ax[iwv].text(iir, ifl, int(compiled_matrix[ifl,iwv, iir]), ha="center", va="center", color="w") |
|
ax[iwv].set_title(f"Wavelength: {wv} nm") |
|
|
|
|
|
report_pdf.savefig() |
|
report_pdf.close() |
|
|