diff --git a/doc/rtd_requirements.txt b/doc/rtd_requirements.txt
deleted file mode 100644
index 7c7729ea..00000000
--- a/doc/rtd_requirements.txt
+++ /dev/null
@@ -1,10 +0,0 @@
-python-geotiepoints>=1.1.1
-numpy>=1.22.2
-scipy>=0.14
-h5py>=2.5
-six
-requests
-tqdm
-pyyaml
-xlrd
-git-lfs
diff --git a/pyspectral/_compat.py b/pyspectral/_compat.py
new file mode 100644
index 00000000..db911999
--- /dev/null
+++ b/pyspectral/_compat.py
@@ -0,0 +1,19 @@
+# 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 8521b8e0..8b0b10c5 100644
--- a/pyspectral/radiance_tb_conversion.py
+++ b/pyspectral/radiance_tb_conversion.py
@@ -29,6 +29,7 @@
import numpy as np
+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
@@ -159,7 +160,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.trapz(self.response, self.wavelength_or_wavenumber)
+ self.rsr_integral = np_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 bbc2d690..50eea61b 100644
--- a/pyspectral/rsr_reader.py
+++ b/pyspectral/rsr_reader.py
@@ -24,8 +24,7 @@
from glob import glob
from os.path import expanduser
-import numpy as np
-
+from pyspectral._compat import np_trapezoid
from pyspectral.bandnames import BANDNAMES
from pyspectral.config import get_config
from pyspectral.utils import (
@@ -214,7 +213,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.trapz(resp, wvl)
+ intg[det] = np_trapezoid(resp, wvl)
return intg
def convert(self):
diff --git a/pyspectral/solar.py b/pyspectral/solar.py
index 0cb30f5e..e13e8f05 100644
--- a/pyspectral/solar.py
+++ b/pyspectral/solar.py
@@ -30,6 +30,8 @@
import numpy as np
+from pyspectral._compat import np_trapezoid
+
LOG = logging.getLogger(__name__)
# STANDARD SPECTRA from Air Mass Zero: http://rredc.nrel.gov/solar/spectra/am0/
@@ -121,9 +123,9 @@ def _load(self):
def solar_constant(self):
"""Calculate the solar constant."""
if self.wavenumber is not None:
- return np.trapz(self.irradiance, self.wavenumber)
+ return np_trapezoid(self.irradiance, self.wavenumber)
if self.wavelength is not None:
- return np.trapz(self.irradiance, self.wavelength)
+ return np_trapezoid(self.irradiance, self.wavelength)
raise TypeError('Neither wavelengths nor wavenumbers available!')
@@ -204,10 +206,10 @@ def _band_calculations(self, rsr, flux, scale, **options):
# Calculate the solar-flux: (w/m2)
if flux:
- return np.trapz(irr * resp_ipol, wvl)
+ return np_trapezoid(irr * resp_ipol, wvl)
# Divide by the equivalent band width:
- return np.trapz(irr * resp_ipol, wvl) / np.trapz(resp_ipol, wvl)
+ return np_trapezoid(irr * resp_ipol, wvl) / np_trapezoid(resp_ipol, wvl)
def interpolate(self, **options):
"""Interpolate Irradiance to a specified evenly spaced resolution/grid.
diff --git a/pyspectral/tests/__init__.py b/pyspectral/tests/__init__.py
index 4688c7dd..b6039d76 100644
--- a/pyspectral/tests/__init__.py
+++ b/pyspectral/tests/__init__.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-
+#
# Copyright (c) 2013-2022 Pytroll Developers
#
#
@@ -8,48 +8,12 @@
# 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 .
-
"""The tests package."""
-
-import doctest
-import os
-import sys
-
-from pyspectral import blackbody, near_infrared_reflectance, solar
-
-if sys.version_info < (2, 7):
- import unittest2 as unittest
-else:
- import unittest
-
-TRAVIS = os.environ.get("TRAVIS", False)
-APPVEYOR = os.environ.get("APPVEYOR", False)
-
-
-def suite():
- """Perform the unit testing."""
- mysuite = unittest.TestSuite()
- if not TRAVIS and not APPVEYOR:
- # Test sphinx documentation pages:
- mysuite.addTests(doctest.DocFileSuite('../../doc/usage.rst'))
- mysuite.addTests(doctest.DocFileSuite('../../doc/rad_definitions.rst'))
- # mysuite.addTests(doctest.DocFileSuite('../../doc/seviri_example.rst'))
- mysuite.addTests(doctest.DocFileSuite('../../doc/37_reflectance.rst'))
- # Test the documentation strings
- mysuite.addTests(doctest.DocTestSuite(solar))
- mysuite.addTests(doctest.DocTestSuite(near_infrared_reflectance))
- mysuite.addTests(doctest.DocTestSuite(blackbody))
-
- return mysuite
-
-
-if __name__ == '__main__':
- unittest.TextTestRunner(verbosity=2).run(suite())
diff --git a/pyspectral/utils.py b/pyspectral/utils.py
index 38f54e21..32ec687a 100644
--- a/pyspectral/utils.py
+++ b/pyspectral/utils.py
@@ -21,6 +21,7 @@
import logging
import os
+import sys
import tarfile
import warnings
from functools import wraps
@@ -29,6 +30,7 @@
import numpy as np
import requests
+from pyspectral._compat import np_trapezoid
from pyspectral.bandnames import BANDNAMES
from pyspectral.config import get_config
@@ -224,7 +226,7 @@ def get_central_wave(wav, resp, weight=1.0):
# if info['unit'].find('-1') > 0:
# Wavenumber:
# res *=
- return np.trapz(resp * wav * weight, wav) / np.trapz(resp * weight, wav)
+ return np_trapezoid(resp * wav * weight, wav) / np_trapezoid(resp * weight, wav)
def get_bandname_from_wavelength(sensor, wavelength, rsr, epsilon=0.1, multiple_bands=False):
@@ -413,7 +415,8 @@ def _download_tarball_and_extract(tarball_url, local_pathname, extract_dir):
handle.write(data)
tar = tarfile.open(local_pathname)
- tar.extractall(extract_dir)
+ tar_kwargs = {} if sys.version_info < (3, 12) else {"filter": "data"}
+ tar.extractall(extract_dir, **tar_kwargs)
tar.close()
os.remove(local_pathname)
diff --git a/requirements.txt b/requirements.txt
deleted file mode 100644
index 30be0433..00000000
--- a/requirements.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-python-geotiepoints>=1.1.1
-numpy>=1.5.1
-scipy>=0.14
-h5py>=2.5
-six
diff --git a/setup.py b/setup.py
index 7b5f009b..f16e2e3b 100644
--- a/setup.py
+++ b/setup.py
@@ -26,13 +26,10 @@
description = ('Reading and manipulaing satellite sensor spectral responses and the '
'solar spectrum, to perfom various corrections to VIS and NIR band data')
-try:
- with open('./README.md', 'r') as fd:
- long_description = fd.read()
-except IOError:
- long_description = ''
+with open('./README.md', 'r') as fd:
+ long_description = fd.read()
-requires = ['docutils>=0.3', 'numpy', 'scipy', 'python-geotiepoints>=1.1.1',
+requires = ['numpy', 'scipy', 'python-geotiepoints>=1.1.1',
'h5py>=2.5', 'requests', 'pyyaml', 'platformdirs']
dask_extra = ['dask[array]']
@@ -74,14 +71,13 @@
'matplotlib': ['matplotlib'],
'pandas': ['pandas'],
'tqdm': ['tqdm'],
+ 'test': test_requires,
'dask': dask_extra},
scripts=['bin/plot_rsr.py', 'bin/composite_rsr_plot.py',
'bin/download_atm_correction_luts.py',
'bin/download_rsr.py'],
data_files=[('share', ['pyspectral/data/e490_00a.dat',
'pyspectral/data/MSG_SEVIRI_Spectral_Response_Characterisation.XLS'])],
- test_suite='pyspectral.tests.suite',
- tests_require=test_requires,
python_requires='>=3.10',
zip_safe=False,
)