From 38a44047dec683e6d74188fad72b307fd65e5ad4 Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Mon, 15 Jan 2024 18:41:37 +0000 Subject: [PATCH] set new y_err with value zero (#215) closes #215 --- .gitea/workflows/build-appimage.yaml | 4 +-- src/nmreval/math/smooth.py | 51 ++++++++++++++++++++-------- 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/.gitea/workflows/build-appimage.yaml b/.gitea/workflows/build-appimage.yaml index 2c43c0b..1b69b69 100644 --- a/.gitea/workflows/build-appimage.yaml +++ b/.gitea/workflows/build-appimage.yaml @@ -29,10 +29,10 @@ jobs: env: GPG_KEYGRIP: ${{ vars.GPG_KEYGRIP }} GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} - GO_PIPELINE_LABEL: ${{ env.YEAR }}.${{ gitea.run_number }}_${{ env.SHA_SHORT }}_bookworm + GO_PIPELINE_LABEL: ${{ env.YEAR }}.${{ gitea.run_number }}_${{ env.SHA_SHORT }} - name: Upload AppImage run: ./tools/upload_gitea.sh env: - GO_PIPELINE_LABEL: ${{ env.YEAR }}.${{ gitea.run_number }}_${{ env.SHA_SHORT }}_bookworm + GO_PIPELINE_LABEL: ${{ env.YEAR }}.${{ gitea.run_number }}_${{ env.SHA_SHORT }} UPLOAD_TOKEN: ${{ secrets.UPLOAD_TOKEN }} UPLOAD_USER: ${{ vars.UPLOAD_USER }} diff --git a/src/nmreval/math/smooth.py b/src/nmreval/math/smooth.py index 5207720..fc5997d 100644 --- a/src/nmreval/math/smooth.py +++ b/src/nmreval/math/smooth.py @@ -3,14 +3,21 @@ import numpy.polynomial.polynomial as poly from scipy import signal as signal -__all__ = ['smooth', 'loess', 'savgol', - 'running_max', 'running_min', - 'running_var', 'running_std', - 'running_median', 'running_mean', - 'running_sum'] +__all__ = [ + 'smooth', + 'loess', + 'savgol', + 'running_max', + 'running_min', + 'running_var', + 'running_std', + 'running_median', + 'running_mean', + 'running_sum', +] -def loess(x, y, window_size, it=0, deg=2): +def loess(x, y, window_size: int, it: int = 0, deg: int = 2): # ULTRA LANGSAM !!! it = max(it, 0) @@ -81,19 +88,19 @@ def savgol(x, y, window_size: int, deg: int = 2, mode: str = 'mirror'): return new_y -def running_mean(x, y, window_size): +def running_mean(x, y, window_size: int): return _running_func(np.nanmean, x, y, window_size) -def running_median(x, y, window_size): +def running_median(x, y, window_size: int): return _running_func(np.nanmedian, x, y, window_size) -def running_std(x, y, window_size): +def running_std(x, y, window_size: int): return _running_func(np.nanstd, x, y, window_size) -def running_var(x, y, window_size): +def running_var(x, y, window_size: int): return _running_func(np.nanvar, x, y, window_size) @@ -132,11 +139,27 @@ def _moving_window(arr, nn): return np.lib.stride_tricks.as_strided(arr, shapes, strides) -_funcs = {'loess': loess, 'savgol': savgol, 'mean': running_mean, 'median': running_median, - 'std': running_std, 'var': running_var, 'max': running_max, 'min': running_min, 'sum': running_sum} +_funcs = { + 'loess': loess, + 'savgol': savgol, + 'mean': running_mean, + 'median': running_median, + 'std': running_std, + 'var': running_var, + 'max': running_max, + 'min': running_min, + 'sum': running_sum, +} -def smooth(data, window_size, mode='mean', logx=False, logy=False, **kwargs): +def smooth( + data: 'Data', + window_size: int, + mode: str = 'mean', + logx: bool = False, + logy: bool = False, + **kwargs +): try: func = _funcs[mode] except KeyError: @@ -162,6 +185,6 @@ def smooth(data, window_size, mode='mean', logx=False, logy=False, **kwargs): new_y = 10**new_y new_data = data.copy() - new_data.set_data(x=new_x, y=new_y, y_err=None) + new_data.set_data(x=new_x, y=new_y, y_err=np.zeros_like(new_y)) return new_data