diff --git a/README.md b/README.md index ac8310d..701eea5 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 ``` diff --git a/dap/algos/spiana.py b/dap/algos/spiana.py index 5a8e935..e3d3686 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_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 diff --git a/dap/worker.py b/dap/worker.py index 18ba946..b7f9f4a 100644 --- a/dap/worker.py +++ b/dap/worker.py @@ -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) # ??? 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++" )