From fa8736263a28d5a2d6672baf34262e51897d5936 Mon Sep 17 00:00:00 2001 From: Alexandr Kalinin Date: Tue, 25 Nov 2025 16:38:26 -0800 Subject: [PATCH 1/2] Fix dtype mismatch in resolution analyses --- src/nanopyx/core/analysis/decorr.pyx | 4 ++-- src/nanopyx/core/analysis/frc.pyx | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/nanopyx/core/analysis/decorr.pyx b/src/nanopyx/core/analysis/decorr.pyx index 07d080c1..e81e99b6 100644 --- a/src/nanopyx/core/analysis/decorr.pyx +++ b/src/nanopyx/core/analysis/decorr.pyx @@ -270,7 +270,7 @@ cdef class DecorrAnalysis: cdef float[:, :] _compute_d(self): cdef float[:] coef, kc, a, dg, result, results_gm, results_max - cdef complex[:, :] fft + cdef float complex[:, :] fft cdef float[:, :] d_curve, img_ref, blurred, mask, fft_real, fft_imag cdef float[:, :, :] normalized_fft cdef int count = 0 @@ -402,7 +402,7 @@ cdef class DecorrAnalysis: cdef _run_analysis(self): cdef float[:] out - cdef complex[:, :] img_fft + cdef float complex[:, :] img_fft cdef float[:, :] img_ref, img_f, temp, fft_real, fft_imag cdef float resolution img_ref = np.copy(self.img) diff --git a/src/nanopyx/core/analysis/frc.pyx b/src/nanopyx/core/analysis/frc.pyx index 25ae1135..a34cbd3f 100644 --- a/src/nanopyx/core/analysis/frc.pyx +++ b/src/nanopyx/core/analysis/frc.pyx @@ -189,8 +189,8 @@ cdef class FIRECalculator: img_1 = self._get_squared_tapered_image(img_1) img_2 = self._get_squared_tapered_image(img_2) - cdef complex[:, :] fft_1 = self.calculate_fft(np.array(img_1, dtype=np.float32)) - cdef complex[:, :] fft_2 = self.calculate_fft(np.array(img_2, dtype=np.float32)) + cdef float complex[:, :] fft_1 = self.calculate_fft(np.array(img_1, dtype=np.float32)) + cdef float complex[:, :] fft_2 = self.calculate_fft(np.array(img_2, dtype=np.float32)) cdef int size = fft_1.shape[0] self.field_of_view = size From 888fdaf74c6b1b3955f485eec50a5d23299257f4 Mon Sep 17 00:00:00 2001 From: Alexandr Kalinin Date: Wed, 26 Nov 2025 15:28:25 -0800 Subject: [PATCH 2/2] Explicitly cast FFT output to complex64 for numpy 2.x compatibility --- src/nanopyx/core/analysis/decorr.pyx | 4 ++-- src/nanopyx/core/analysis/frc.pyx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/nanopyx/core/analysis/decorr.pyx b/src/nanopyx/core/analysis/decorr.pyx index e81e99b6..3ebc9863 100644 --- a/src/nanopyx/core/analysis/decorr.pyx +++ b/src/nanopyx/core/analysis/decorr.pyx @@ -302,7 +302,7 @@ cdef class DecorrAnalysis: blurred = np.copy(self.img_ref) blurred = gaussian_filter(blurred, sig) blurred = np.copy(self.img_ref) - blurred - fft = np.fft.fftshift(np.fft.fft2(blurred)) + fft = np.fft.fftshift(np.fft.fft2(blurred)).astype(np.complex64) fft_real = np.real(fft).astype(np.float32) fft_imag = np.imag(fft).astype(np.float32) normalized_fft = _normalizeFFT(fft_real, fft_imag) @@ -416,7 +416,7 @@ cdef class DecorrAnalysis: img_f = _apodize_edges(img_f) temp = self._get_preprocessed_image(img_f) self.img_ref = np.copy(temp) - img_fft = np.fft.fftshift(np.fft.fft2(temp)) + img_fft = np.fft.fftshift(np.fft.fft2(temp)).astype(np.complex64) fft_real = np.real(img_fft).astype(np.float32) fft_imag = np.imag(img_fft).astype(np.float32) fft_real[fft_real.shape[0]//2, fft_real.shape[1]//2] = 0 diff --git a/src/nanopyx/core/analysis/frc.pyx b/src/nanopyx/core/analysis/frc.pyx index a34cbd3f..a7130110 100644 --- a/src/nanopyx/core/analysis/frc.pyx +++ b/src/nanopyx/core/analysis/frc.pyx @@ -170,7 +170,7 @@ cdef class FIRECalculator: return results def calculate_fft(self, img: np.ndarray): - return np.fft.fftshift(np.fft.fft2(img)) + return np.fft.fftshift(np.fft.fft2(img)).astype(np.complex64) cdef _calculate_frc_curve(self, float[:, :] img1, float[:, :] img2):