From c0995a34dfbee4fc5be64d7fea6de2dfd0db92b8 Mon Sep 17 00:00:00 2001 From: Danilo Ferreira de Lima <danilo.enoque.ferreira.de.lima@xfel.de> Date: Wed, 1 Mar 2023 14:04:38 +0100 Subject: [PATCH] Detect faster convolution method. --- pes_to_spec/__init__.py | 2 +- pes_to_spec/model.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pes_to_spec/__init__.py b/pes_to_spec/__init__.py index fb5f5ab..c0fb2a7 100644 --- a/pes_to_spec/__init__.py +++ b/pes_to_spec/__init__.py @@ -2,4 +2,4 @@ Estimate high-resolution photon spectrometer data from low-resolution non-invasive measurements. """ -VERSION = "0.1.4" +VERSION = "0.1.5" diff --git a/pes_to_spec/model.py b/pes_to_spec/model.py index 2276bac..13e72ac 100644 --- a/pes_to_spec/model.py +++ b/pes_to_spec/model.py @@ -3,7 +3,7 @@ from __future__ import annotations import joblib import numpy as np -from scipy.signal import fftconvolve +from scipy.signal import convolve #from scipy.signal import find_peaks_cwt from scipy.optimize import fmin_l_bfgs_b from sklearn.decomposition import PCA @@ -331,7 +331,7 @@ class HighResolutionSmoother(TransformerMixin, BaseEstimator): gaussian = np.exp(-0.5*(energy - mu)**2/self.high_res_sigma**2) gaussian /= np.sum(gaussian, axis=1, keepdims=True) # apply it to the data - high_res_gc = fftconvolve(X, gaussian, mode="same", axes=1) + high_res_gc = convolve(X, gaussian, mode="same", axes=1) return high_res_gc def inverse_transform(self, Xt: np.ndarray) -> np.ndarray: @@ -519,7 +519,7 @@ class SelectRelevantLowResolution(TransformerMixin, BaseEstimator): gaussian = np.exp(-0.5*(axis - sum_low_res.shape[0]//2)**2/20**2) gaussian /= np.sum(gaussian, axis=0, keepdims=True) # apply it to the data - smoothened = fftconvolve(sum_low_res, gaussian, mode="same", axes=0) + smoothened = convolve(sum_low_res, gaussian, mode="same", axes=0) peak_idx = [np.argmax(smoothened)] if len(peak_idx) < 1: raise PromptNotFoundError() @@ -1009,7 +1009,7 @@ class Model(TransformerMixin, BaseEstimator): M = self.wiener_filter.shape[0] B = expected.shape[0] assert expected.shape[1] == M - deconvolved = fftconvolve(expected, + deconvolved = convolve(expected, np.broadcast_to(self.wiener_filter.reshape(1, -1), (B, M)), mode="same", axes=1) -- GitLab