Streak Finder algorithm for CBD experiment #2

Merged
augustin_s merged 46 commits from ext-dorofe_e/dap:chapman into main 2025-07-14 11:18:07 +02:00
4 changed files with 31 additions and 13 deletions
Showing only changes of commit 6f2fa2d419 - Show all commits

View File

@@ -25,7 +25,7 @@ conda activate test-dap
Clone and install dap
```bash
git clone https://gitlab.psi.ch/sf-daq/dap.git
git clone https://gitea.psi.ch/sf-daq/dap.git
cd dap
make install
```

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)
if not do_spi_analysis:
return
for k in ("spi_limit", "roi_intensities_normalised"):
for k in ("spi_threshold_photon", "spi_threshold_hit_percentage", "roi_x1", "roi_x2", "roi_y1", "roi_y2"):
if k not in results:
return
spi_limit = results["spi_limit"]
roi_intensities_normalised = results["roi_intensities_normalised"]
spi_threshold_photon = results["spi_threshold_photon"]
spi_threshold_hit_percentage = results["spi_threshold_hit_percentage"]
number_of_spots = 0
for index, (rin, sl) in enumerate(zip(roi_intensities_normalised, spi_limit)):
if rin >= sl:
number_of_spots += 25 * (index+1)
roi_x1 = results["roi_x1"]
roi_x2 = results["roi_x2"]
roi_y1 = results["roi_y1"]
roi_y2 = results["roi_y2"]
results["number_of_spots"] = number_of_spots
if len(roi_x1) == 0:
return
if number_of_spots > 0:
results["is_hit_frame"] = True
if not (len(roi_x1) == len(roi_x2) == len(roi_y1) == len(roi_y2)):
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"] = bool(hit) # json does not like numpy bool_ scalars

View File

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

View File

@@ -11,6 +11,7 @@ peakfinder8_ext = Extension(
include_dirs = [peakfinder8_include_dir, numpy.get_include()],
library_dirs = [peakfinder8_library_dir],
libraries = ["peakfinder8"],
define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")],
language = "c++"
)