From 10701994ecf909b6710b7a58748668afb68e23a6 Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Mon, 3 Nov 2025 19:45:37 +0100 Subject: [PATCH] removed all manual array.tolist() conversions (and similar) that were needed for json serializability --- dap/algos/peakfind.py | 4 ++-- dap/algos/radprof.py | 2 +- dap/algos/roi.py | 2 +- dap/algos/spiana.py | 2 +- dap/algos/streakfind.py | 5 ++--- dap/worker.py | 4 ++-- 6 files changed, 9 insertions(+), 10 deletions(-) diff --git a/dap/algos/peakfind.py b/dap/algos/peakfind.py index a706cb9..c4ef8e5 100644 --- a/dap/algos/peakfind.py +++ b/dap/algos/peakfind.py @@ -54,8 +54,8 @@ def calc_peakfinder_analysis(results, data, pixel_mask): results["number_of_spots"] = number_of_spots # to coordinates where position of first pixel/point is (1, 1) - results["spot_x"] = [x + 0.5 for x in peak_list_x] - results["spot_y"] = [y + 0.5 for y in peak_list_y] + results["spot_x"] = peak_list_x + 0.5 + results["spot_y"] = peak_list_y + 0.5 results["spot_intensity"] = copy(peak_list_value) #TODO: why is this copy needed? npeaks_threshold_hit = results.get("npeaks_threshold_hit", 15) diff --git a/dap/algos/radprof.py b/dap/algos/radprof.py index 438e796..0f21e3f 100644 --- a/dap/algos/radprof.py +++ b/dap/algos/radprof.py @@ -33,7 +33,7 @@ def calc_radial_integration(results, data, pixel_mask): rp = rp / integral_silent_region results["radint_normalised"] = [silent_min, silent_max] - results["radint_I"] = rp[r_min:].tolist() #TODO: why not stop at r_max? + results["radint_I"] = rp[r_min:] #TODO: why not stop at r_max? results["radint_q"] = [r_min, r_max] diff --git a/dap/algos/roi.py b/dap/algos/roi.py index b44f241..5d55fb3 100644 --- a/dap/algos/roi.py +++ b/dap/algos/roi.py @@ -40,7 +40,7 @@ def calc_roi(results, data): roi_sum_norm = np.nanmean(data_roi, dtype=float) # data_roi is np.float32, which cannot be json serialized roi_indices_x = [ix1, ix2] - roi_proj_x = np.nansum(data_roi, axis=0).tolist() + roi_proj_x = np.nansum(data_roi, axis=0) roi_intensities.append(roi_sum) roi_intensities_normalised.append(roi_sum_norm) diff --git a/dap/algos/spiana.py b/dap/algos/spiana.py index e3d3686..6cbd2dc 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"] = bool(hit) # json does not like numpy bool_ scalars + results["is_hit_frame"] = hit diff --git a/dap/algos/streakfind.py b/dap/algos/streakfind.py index 10971bd..a2b991c 100644 --- a/dap/algos/streakfind.py +++ b/dap/algos/streakfind.py @@ -205,17 +205,16 @@ def _calc_streakfinder_analysis(results, snr, mask): streak_lengths = np.sqrt( np.power((streak_lines[..., 2] - streak_lines[..., 0]), 2) + np.power((streak_lines[..., 2] - streak_lines[..., 0]), 2) - ).tolist() + ) streak_lines = streak_lines.T _, number_of_streaks = streak_lines.shape - list_result = streak_lines.tolist() # arr(4, n_lines); coord x0, y0, x1, y1 bragg_counts = [streak.total_mass() for streak in detected_streaks] results["number_of_streaks"] = number_of_streaks results["is_hit_frame"] = (number_of_streaks > min_hit_streaks) - results["streaks"] = list_result + results["streaks"] = streak_lines # arr(4, n_lines); coord x0, y0, x1, y1 results["streak_lengths"] = streak_lengths results["bragg_counts"] = bragg_counts diff --git a/dap/worker.py b/dap/worker.py index 2b96866..cba2103 100644 --- a/dap/worker.py +++ b/dap/worker.py @@ -110,8 +110,8 @@ def work(backend_addr, accumulator_addr, visualisation_addr, fn_config, skip_fra if pixel_mask is not None: saturated_pixels_y, saturated_pixels_x = jfdata.get_saturated_pixels(raw_image, double_pixels) results["saturated_pixels"] = len(saturated_pixels_x) - results["saturated_pixels_x"] = saturated_pixels_x.tolist() - results["saturated_pixels_y"] = saturated_pixels_y.tolist() + results["saturated_pixels_x"] = saturated_pixels_x + results["saturated_pixels_y"] = saturated_pixels_y calc_radial_integration(results, image, pixel_mask)