This commit is contained in:
2025-07-08 08:54:35 +02:00
parent f47e1bbb88
commit e984b336a0
2 changed files with 29 additions and 12 deletions

View File

@ -1,25 +1,42 @@
import numpy as np
def calc_spi_analysis(results):
def calc_spi_analysis(results, data):
do_spi_analysis = results.get("do_spi_analysis", False) do_spi_analysis = results.get("do_spi_analysis", False)
if not do_spi_analysis: if not do_spi_analysis:
return return
for k in ("spi_limit", "roi_intensities_normalised"): for k in ("spi_threshold_photon", "spi_threshold_hit", "roi_x1", "roi_x2", "roi_y1", "roi_y2"):
if k not in results: if k not in results:
return return
spi_limit = results["spi_limit"] spi_threshold_photon = results["spi_threshold_photon"]
roi_intensities_normalised = results["roi_intensities_normalised"] spi_threshold_hit_percentage = results["spi_threshold_hit_percentage"]
number_of_spots = 0 roi_x1 = results["roi_x1"]
for index, (rin, sl) in enumerate(zip(roi_intensities_normalised, spi_limit)): roi_x2 = results["roi_x2"]
if rin >= sl: roi_y1 = results["roi_y1"]
number_of_spots += 25 * (index+1) roi_y2 = results["roi_y2"]
results["number_of_spots"] = number_of_spots if len(roi_x1) == 0:
return
if number_of_spots > 0: if not (len(roi_x1) == len(roi_x2) == len(roi_y1) == len(roi_y2)):
results["is_hit_frame"] = True return
nphotons = 0
npixels = 0
for ix1, ix2, iy1, iy2 in zip(roi_x1, roi_x2, roi_y1, roi_y2):
data_roi = data[iy1:iy2, ix1:ix2]
nphotons += np.sum(data_roi > spi_threshold_photon)
npixels += data_roi.size
photon_percentage = nphotons / npixels * 100
hit = (photon_percentage > spi_threshold_hit_percentage)
results["number_of_spots"] = photon_percentage
results["is_hit_frame"] = hit

View File

@ -111,7 +111,7 @@ def work(backend_address, accumulator_host, accumulator_port, visualisation_host
calc_mask_pixels(pfimage, pixel_mask_pf) # changes pfimage in place calc_mask_pixels(pfimage, pixel_mask_pf) # changes pfimage in place
calc_apply_threshold(results, pfimage) # changes pfimage in place calc_apply_threshold(results, pfimage) # changes pfimage in place
calc_roi(results, pfimage, pixel_mask_pf) calc_roi(results, pfimage, pixel_mask_pf)
calc_spi_analysis(results) calc_spi_analysis(results, pfimage)
calc_peakfinder_analysis(results, pfimage, pixel_mask_pf) calc_peakfinder_analysis(results, pfimage, pixel_mask_pf)
# ??? # ???