diff --git a/pyspectral/_compat.py b/pyspectral/_compat.py deleted file mode 100644 index db91199..0000000 --- a/pyspectral/_compat.py +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright (c) 2024 Pytroll developers -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -"""Various helpers for backwards and forwards compatibility.""" - -import numpy as np - -np_trapezoid = np.trapezoid if hasattr(np, "trapezoid") else np.trapz diff --git a/pyspectral/radiance_tb_conversion.py b/pyspectral/radiance_tb_conversion.py index 8b0b10c..549fa51 100644 --- a/pyspectral/radiance_tb_conversion.py +++ b/pyspectral/radiance_tb_conversion.py @@ -28,17 +28,12 @@ from numbers import Number import numpy as np +from scipy.integrate import trapezoid -from pyspectral._compat import np_trapezoid from pyspectral.blackbody import C_SPEED, H_PLANCK, K_BOLTZMANN, blackbody, blackbody_wn from pyspectral.rsr_reader import RelativeSpectralResponse from pyspectral.utils import BANDNAMES, WAVE_LENGTH, WAVE_NUMBER, convert2wavenumber, get_bandname_from_wavelength -try: - from scipy.integrate import trapezoid -except ImportError: - from scipy.integrate import trapz as trapezoid - LOG = logging.getLogger(__name__) BLACKBODY_FUNC = {WAVE_LENGTH: blackbody, @@ -160,7 +155,7 @@ def _get_rsr(self): self._wave_si_scale) self.response = self.rsr[self.bandname][self.detector]['response'] # Get the integral of the spectral response curve: - self.rsr_integral = np_trapezoid(self.response, self.wavelength_or_wavenumber) + self.rsr_integral = trapezoid(self.response, self.wavelength_or_wavenumber) def _getsatname(self): """Get the satellite name used in the rsr-reader, from the platform and number.""" diff --git a/pyspectral/rsr_reader.py b/pyspectral/rsr_reader.py index 50eea61..a107758 100644 --- a/pyspectral/rsr_reader.py +++ b/pyspectral/rsr_reader.py @@ -24,7 +24,8 @@ from glob import glob from os.path import expanduser -from pyspectral._compat import np_trapezoid +from scipy.integrate import trapezoid + from pyspectral.bandnames import BANDNAMES from pyspectral.config import get_config from pyspectral.utils import ( @@ -213,7 +214,7 @@ def integral(self, bandname): for det in self.rsr[bandname].keys(): wvl = self.rsr[bandname][det]['wavelength'] resp = self.rsr[bandname][det]['response'] - intg[det] = np_trapezoid(resp, wvl) + intg[det] = trapezoid(resp, wvl) return intg def convert(self): diff --git a/pyspectral/solar.py b/pyspectral/solar.py index e13e8f0..172bb32 100644 --- a/pyspectral/solar.py +++ b/pyspectral/solar.py @@ -29,8 +29,7 @@ from pathlib import Path import numpy as np - -from pyspectral._compat import np_trapezoid +from scipy.integrate import trapezoid LOG = logging.getLogger(__name__) @@ -123,9 +122,9 @@ def _load(self): def solar_constant(self): """Calculate the solar constant.""" if self.wavenumber is not None: - return np_trapezoid(self.irradiance, self.wavenumber) + return trapezoid(self.irradiance, self.wavenumber) if self.wavelength is not None: - return np_trapezoid(self.irradiance, self.wavelength) + return trapezoid(self.irradiance, self.wavelength) raise TypeError('Neither wavelengths nor wavenumbers available!') @@ -206,10 +205,10 @@ def _band_calculations(self, rsr, flux, scale, **options): # Calculate the solar-flux: (w/m2) if flux: - return np_trapezoid(irr * resp_ipol, wvl) + return trapezoid(irr * resp_ipol, wvl) # Divide by the equivalent band width: - return np_trapezoid(irr * resp_ipol, wvl) / np_trapezoid(resp_ipol, wvl) + return trapezoid(irr * resp_ipol, wvl) / trapezoid(resp_ipol, wvl) def interpolate(self, **options): """Interpolate Irradiance to a specified evenly spaced resolution/grid. diff --git a/pyspectral/utils.py b/pyspectral/utils.py index 32ec687..3ffe149 100644 --- a/pyspectral/utils.py +++ b/pyspectral/utils.py @@ -29,8 +29,8 @@ import numpy as np import requests +from scipy.integrate import trapezoid -from pyspectral._compat import np_trapezoid from pyspectral.bandnames import BANDNAMES from pyspectral.config import get_config @@ -226,7 +226,7 @@ def get_central_wave(wav, resp, weight=1.0): # if info['unit'].find('-1') > 0: # Wavenumber: # res *= - return np_trapezoid(resp * wav * weight, wav) / np_trapezoid(resp * weight, wav) + return trapezoid(resp * wav * weight, wav) / trapezoid(resp * weight, wav) def get_bandname_from_wavelength(sensor, wavelength, rsr, epsilon=0.1, multiple_bands=False): diff --git a/rsr_convert_scripts/seviri_rsr.py b/rsr_convert_scripts/seviri_rsr.py index 951a804..cca4a2c 100644 --- a/rsr_convert_scripts/seviri_rsr.py +++ b/rsr_convert_scripts/seviri_rsr.py @@ -25,6 +25,7 @@ import numpy as np import pkg_resources +from scipy.integrate import trapezoid from xlrd import open_workbook from pyspectral.config import get_config @@ -210,7 +211,7 @@ def get_centrals(self): def get_central_wave(wavl, resp): """Calculate the central wavelength (or the central wavenumber if inputs are wave numbers).""" - return np.trapz(resp * wavl, wavl) / np.trapz(resp, wavl) + return trapezoid(resp * wavl, wavl) / trapezoid(resp, wavl) def generate_seviri_file(seviri, platform_name): diff --git a/setup.py b/setup.py index f16e2e3..b851fa2 100644 --- a/setup.py +++ b/setup.py @@ -29,7 +29,7 @@ with open('./README.md', 'r') as fd: long_description = fd.read() -requires = ['numpy', 'scipy', 'python-geotiepoints>=1.1.1', +requires = ['numpy', 'scipy>=1.6.0', 'python-geotiepoints>=1.1.1', 'h5py>=2.5', 'requests', 'pyyaml', 'platformdirs'] dask_extra = ['dask[array]']