From e984b336a023dcf9bd33fb8345e6466292a412b5 Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Tue, 8 Jul 2025 08:54:35 +0200 Subject: [PATCH 1/5] SPI v2 --- dap/algos/spiana.py | 39 ++++++++++++++++++++++++++++----------- dap/worker.py | 2 +- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/dap/algos/spiana.py b/dap/algos/spiana.py index 5a8e935..5a80484 100644 --- a/dap/algos/spiana.py +++ b/dap/algos/spiana.py @@ -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", "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"] = hit diff --git a/dap/worker.py b/dap/worker.py index 63fdca3..d32f0d4 100644 --- a/dap/worker.py +++ b/dap/worker.py @@ -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_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) # ??? From 157b7bad8c0affe2cb3f169c97d3d99b987fc323 Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Tue, 8 Jul 2025 11:36:03 +0200 Subject: [PATCH 2/5] typo --- dap/algos/spiana.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dap/algos/spiana.py b/dap/algos/spiana.py index 5a80484..6cbd2dc 100644 --- a/dap/algos/spiana.py +++ b/dap/algos/spiana.py @@ -6,7 +6,7 @@ def calc_spi_analysis(results, data): if not do_spi_analysis: return - for k in ("spi_threshold_photon", "spi_threshold_hit", "roi_x1", "roi_x2", "roi_y1", "roi_y2"): + for k in ("spi_threshold_photon", "spi_threshold_hit_percentage", "roi_x1", "roi_x2", "roi_y1", "roi_y2"): if k not in results: return From 7d5a0f7ad8ea7806bf2b1c0cc605c0b2374d8b68 Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Tue, 8 Jul 2025 15:48:53 +0200 Subject: [PATCH 3/5] disable deprecated APIs in NumPy (from before version 1.7) to silence warning --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index d34ec32..3162f1f 100644 --- a/setup.py +++ b/setup.py @@ -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++" ) From 9bfe0cc8c5d2246e08459f6f05ea858eff573631 Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Tue, 8 Jul 2025 16:05:07 +0200 Subject: [PATCH 4/5] changed gitlab -> gitea --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 794bc42..edb0f89 100644 --- a/README.md +++ b/README.md @@ -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 ``` From da8141b6873bdf25061aac62c987049e7a68949c Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Tue, 8 Jul 2025 18:57:31 +0200 Subject: [PATCH 5/5] convert numpy bool_ scalar to python bool --- dap/algos/spiana.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dap/algos/spiana.py b/dap/algos/spiana.py index 6cbd2dc..e3d3686 100644 --- a/dap/algos/spiana.py +++ b/dap/algos/spiana.py @@ -36,7 +36,7 @@ def calc_spi_analysis(results, data): hit = (photon_percentage > spi_threshold_hit_percentage) results["number_of_spots"] = photon_percentage - results["is_hit_frame"] = hit + results["is_hit_frame"] = bool(hit) # json does not like numpy bool_ scalars