diff --git a/nonos/api/satellite.py b/nonos/api/satellite.py index ce46454c..e8f18f2d 100644 --- a/nonos/api/satellite.py +++ b/nonos/api/satellite.py @@ -1,4 +1,5 @@ import warnings +from importlib.util import find_spec from pathlib import Path from typing import TYPE_CHECKING, Optional @@ -23,8 +24,6 @@ def file_analysis( directory: Optional["PathT"] = None, norb: Optional[int] = None, ) -> "FloatArray": - from scipy.ndimage import uniform_filter1d - if directory is None: directory = Path.cwd() else: @@ -46,8 +45,15 @@ def file_analysis( analysis = ini["Output"]["analysis"] rpini = ini["Planet"]["dpl"] Ntmean = round(norb * 2 * np.pi * pow(rpini, 1.5) / analysis) - for i in range(1, len(columns) - 1): - columns[i] = uniform_filter1d(columns[i], Ntmean) + if find_spec("scipy") is not None: + from scipy.ndimage import uniform_filter1d + + for i, column in enumerate(columns): + columns[i] = uniform_filter1d(column, Ntmean) + else: + # fallback to numpy if scipy isn't available (less performant) + for i, column in enumerate(columns): + columns[i] = np.convolve(column, np.ones_like(column), mode="valid") else: raise NotImplementedError( f"moving average on {norb} orbits is not implemented for the recipe {recipe}" diff --git a/pyproject.toml b/pyproject.toml index 2c25ac0b..ababe5ce 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,7 +27,6 @@ dependencies = [ "numpy>=1.19.3", "packaging>=20.0", "rich>=10.13.0", - "scipy>=1.6.1", "typing_extensions >= 4.4.0 ; python_version < '3.12'", ] diff --git a/requirements/tests_all.txt b/requirements/tests_all.txt index b1db7509..878e09d8 100644 --- a/requirements/tests_all.txt +++ b/requirements/tests_all.txt @@ -3,3 +3,4 @@ cblind>=2.3.0 cmocean>=3.0.3 cmyt>=2.0.0 numexpr>=2.8.3 +scipy>=1.6.1