From 1ccca4795d46edc529a2105cf675cf566bcd6563 Mon Sep 17 00:00:00 2001 From: Leonardo Schwarz Date: Tue, 4 Jun 2024 15:56:38 +0200 Subject: [PATCH] minor formatting --- .../spectrum/calibration_method_mcc.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/depiction/calibration/spectrum/calibration_method_mcc.py b/src/depiction/calibration/spectrum/calibration_method_mcc.py index 3c32f3b..a07f656 100644 --- a/src/depiction/calibration/spectrum/calibration_method_mcc.py +++ b/src/depiction/calibration/spectrum/calibration_method_mcc.py @@ -16,31 +16,32 @@ def __init__( model_smoothing_activated: bool = True, model_smoothing_kernel_size: int = 27, model_smoothing_kernel_std: float = 10.0, + max_pairwise_distance: float = 500, ) -> None: self._model_smoothing_activated = model_smoothing_activated self._model_smoothing_kernel_size = model_smoothing_kernel_size self._model_smoothing_kernel_std = model_smoothing_kernel_std + self._max_pairwise_distance = max_pairwise_distance def extract_spectrum_features(self, peak_mz_arr: NDArray[float], peak_int_arr: NDArray[float]) -> DataArray: l_none = 1.000482 # c_0 = 0.029 # c_1 = 4.98*10e-4 - # compute all differences for elements in peak_mz_arr amd store in a DataArray - # delta = scipy.spatial.distance_matrix(np.expand_dims(peak_mz_arr,1), np.expand_dims(peak_mz_arr,1), p = 1) + # Compute all differences for elements in peak_mz_arr amd store in a DataArray delta = scipy.spatial.distance.pdist(np.expand_dims(peak_mz_arr, 1), metric="cityblock") - # get all distances smaller then 500 - delta = delta[delta < 500] - # for each x compute + + # Get all distances smaller than the max pairwise distance + delta = delta[delta < self._max_pairwise_distance] + # Compute delta_lambda for each x delta_lambda = np.zeros_like(delta) for i, mi in enumerate(delta): - term1 = (mi) % l_none + term1 = mi % l_none if term1 < 0.5: delta_lambda[i] = term1 else: delta_lambda[i] = -1 + term1 - # create a scatterplot of delte_lambda vs x sorted_indices = np.argsort(delta) delta = delta[sorted_indices] @@ -57,11 +58,12 @@ def extract_spectrum_features(self, peak_mz_arr: NDArray[float], peak_int_arr: N delta_intercept = np.zeros_like(peak_mz_corrected) for i, mi in enumerate(peak_mz_corrected): - term1 = (mi) % l_none + term1 = mi % l_none if term1 < 0.5: delta_intercept[i] = term1 else: delta_intercept[i] = -1 + term1 + intercept_coef = stats.trim_mean(delta_intercept, 0.3) return DataArray([intercept_coef, slope], dims=["c"])