Skip to content

Commit

Permalink
Merge pull request #232 from djhoese/cleanup-deps
Browse files Browse the repository at this point in the history
Cleanup unused dependencies and deprecated code
  • Loading branch information
djhoese authored Jul 20, 2024
2 parents 6c34706 + d6b5c58 commit 101113b
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 72 deletions.
10 changes: 0 additions & 10 deletions doc/rtd_requirements.txt

This file was deleted.

19 changes: 19 additions & 0 deletions pyspectral/_compat.py
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
"""Various helpers for backwards and forwards compatibility."""

import numpy as np

np_trapezoid = np.trapezoid if hasattr(np, "trapezoid") else np.trapz
3 changes: 2 additions & 1 deletion pyspectral/radiance_tb_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand Down
5 changes: 2 additions & 3 deletions pyspectral/rsr_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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):
Expand Down
10 changes: 6 additions & 4 deletions pyspectral/solar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down Expand Up @@ -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!')

Expand Down Expand Up @@ -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.
Expand Down
42 changes: 3 additions & 39 deletions pyspectral/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,55 +1,19 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

#
# Copyright (c) 2013-2022 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 <http://www.gnu.org/licenses/>.

"""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())
7 changes: 5 additions & 2 deletions pyspectral/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import logging
import os
import sys
import tarfile
import warnings
from functools import wraps
Expand All @@ -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

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand Down
5 changes: 0 additions & 5 deletions requirements.txt

This file was deleted.

12 changes: 4 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]']
Expand Down Expand Up @@ -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,
)

0 comments on commit 101113b

Please sign in to comment.