[Git][debian-gis-team/pyspectral][master] 5 commits: New upstream version 0.10.5+ds
Antonio Valentino (@antonio.valentino)
gitlab at salsa.debian.org
Wed Aug 18 08:59:34 BST 2021
Antonio Valentino pushed to branch master at Debian GIS Project / pyspectral
Commits:
a557f883 by Antonio Valentino at 2021-08-18T07:31:43+00:00
New upstream version 0.10.5+ds
- - - - -
ef8dc147 by Antonio Valentino at 2021-08-18T07:31:47+00:00
Update upstream source from tag 'upstream/0.10.5+ds'
Update to upstream version '0.10.5+ds'
with Debian dir f66ad18d24dbc16f9e3fe72e2215ece34462eab3
- - - - -
2da819a1 by Antonio Valentino at 2021-08-18T07:47:11+00:00
New upstream release
- - - - -
99d84c51 by Antonio Valentino at 2021-08-18T07:47:17+00:00
Update copyright file
- - - - -
dfd20925 by Antonio Valentino at 2021-08-18T07:50:49+00:00
Set distribution to unstable
- - - - -
11 changed files:
- CHANGELOG.md
- debian/changelog
- debian/copyright
- doc/seviri_example.rst
- pyspectral/atm_correction_ir.py
- pyspectral/near_infrared_reflectance.py
- pyspectral/tests/test_atm_correction_ir.py
- pyspectral/tests/test_reflectance.py
- rsr_convert_scripts/aatsr_reader.py
- rsr_convert_scripts/ahi_reader.py
- rsr_convert_scripts/cocts_rsr.py
Changes:
=====================================
CHANGELOG.md
=====================================
@@ -1,3 +1,22 @@
+## Version <v0.10.5> (2021/04/29)
+
+### Pull Requests Merged
+
+#### Bugs fixed
+
+* [PR 129](https://github.com/pytroll/pyspectral/pull/129) - Fix so reflectances can be derived from scalar inputs
+
+#### Features added
+
+* [PR 128](https://github.com/pytroll/pyspectral/pull/128) - Fix dask compatibility of IR atmospherical correction
+
+#### Documentation changes
+
+* [PR 129](https://github.com/pytroll/pyspectral/pull/129) - Fix so reflectances can be derived from scalar inputs
+
+In this release 2 pull requests were closed.
+
+
## Version <v0.10.4> (2020/12/07)
=====================================
debian/changelog
=====================================
@@ -1,9 +1,13 @@
-pyspectral (0.10.4+ds-2) UNRELEASED; urgency=medium
+pyspectral (0.10.5+ds-1) unstable; urgency=medium
- * Team upload.
+ [ Bas Couwenberg ]
* Update watch file for GitHub URL changes.
- -- Bas Couwenberg <sebastic at debian.org> Sat, 20 Mar 2021 09:05:12 +0100
+ [ Antonio Valentino ]
+ * New upstream release.
+ * Update debian/copyright file.
+
+ -- Antonio Valentino <antonio.valentino at tiscali.it> Wed, 18 Aug 2021 07:50:30 +0000
pyspectral (0.10.4+ds-1) unstable; urgency=medium
=====================================
debian/copyright
=====================================
@@ -16,7 +16,7 @@ Files-Excluded: pyspectral/data/modis
doc/_static/mersi2_rsr_band_0040_0070_missingbands.png
Files: *
-Copyright: 2013-2020 Pytroll Developers
+Copyright: 2013-2021 Pytroll Developers
Adam Dybbroe
PyTroll Community
Pytroll
=====================================
doc/seviri_example.rst
=====================================
@@ -10,7 +10,7 @@ Let us try calculate the 3.9 micron reflectance for Meteosat-10:
>>> tb4 = 282.0
>>> from pyspectral.near_infrared_reflectance import Calculator
>>> refl39 = Calculator('Meteosat-10', 'seviri', 'IR3.9')
- >>> print('%4.3f' %refl39.reflectance_from_tbs(sunz, tb3, tb4))
+ >>> print('{refl:4.3f}'.format(refl=refl39.reflectance_from_tbs(sunz, tb3, tb4)[0]))
0.555
You can also provide the in-band solar flux from outside when calculating the
@@ -22,12 +22,12 @@ reflectance, saving a few milliseconds per call::
>>> seviri = RelativeSpectralResponse('Meteosat-10', 'seviri')
>>> sflux = solar_irr.inband_solarflux(seviri.rsr['IR3.9'])
>>> refl39 = Calculator('Meteosat-10', 'seviri', 'IR3.9', solar_flux=sflux)
- >>> print('%4.3f' %refl39.reflectance_from_tbs(sunz, tb3, tb4))
+ >>> print('{refl:4.3f}'.format(refl=refl39.reflectance_from_tbs(sunz, tb3, tb4)[0]))
0.555
By default the data are masked outside the default Sun zenith-angle (SZA) correction limit (85.0 degrees).
The masking can be adjusted via `masking_limit` keyword argument to `Calculator`, and turned of by
-defining `Calculator(..., masking_limit=None)`. The SZA limit can be adjusted via `sunz_threshold` keyword argument:
+defining `Calculator(..., masking_limit=None)`. The SZA limit can be adjusted via `sunz_threshold` keyword argument:
`Calculator(..., sunz_threshold=88.0)`.
Integration with SatPy
=====================================
pyspectral/atm_correction_ir.py
=====================================
@@ -59,6 +59,12 @@ from this time are not longer at DWD.'
import numpy as np
+try:
+ import dask.array as da
+except ImportError:
+ da = None
+
+
import logging
LOG = logging.getLogger(__name__)
@@ -128,6 +134,16 @@ def viewzen_corr(data, view_zen):
DELTA_REF = 6.2
return (1 + DELTA_REF)**ratio(z, Z_0, Z_REF) - 1
+ is_dask_data = hasattr(data, 'compute') or hasattr(view_zen, 'compute')
+
+ if is_dask_data:
+ data_tau0 = data + tau0(data)
+ data_tau_delta = data + (tau(data) * delta(view_zen))
+ dask_data = da.where(view_zen == 0, data_tau0,
+ da.where((view_zen > 0) & (view_zen < 90),
+ data_tau_delta, data))
+ return dask_data
+ # expect numpy types otherwise
y0, x0 = np.ma.where(view_zen == 0)
data[y0, x0] += tau0(data[y0, x0])
@@ -143,3 +159,4 @@ if __name__ == "__main__":
SATZ = np.ma.arange(NDIM).reshape(SHAPE) * 60. / float(NDIM)
TBS = np.ma.arange(NDIM).reshape(SHAPE) * 80.0 / float(NDIM) + 220.
atm_corr = this.get_correction(SATZ, 'M4', TBS)
+ atm_corr = this.get_correction(da.from_array(SATZ), 'M4', da.from_array(TBS))
=====================================
pyspectral/near_infrared_reflectance.py
=====================================
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
-# Copyright (c) 2014-2020 Pytroll developers
+# Copyright (c) 2014-2021 Pytroll developers
#
# Author(s):
#
@@ -30,6 +30,7 @@ window channel (usually around 11-12 microns).
"""
import os
+import logging
import numpy as np
try:
from dask.array import where, logical_or, asanyarray, array, isnan
@@ -43,7 +44,7 @@ from pyspectral.utils import TB2RAD_DIR
from pyspectral.utils import WAVE_LENGTH
from pyspectral.radiance_tb_conversion import RadTbConverter
from pyspectral.config import get_config
-import logging
+
LOG = logging.getLogger(__name__)
EPSILON = 0.005
@@ -219,15 +220,9 @@ class Calculator(RadTbConverter):
else:
is_masked = False
- if np.isscalar(tb_near_ir):
- tb_nir = array([tb_near_ir, ])
- else:
- tb_nir = asanyarray(tb_near_ir)
-
- if np.isscalar(tb_thermal):
- tb_therm = array([tb_thermal, ])
- else:
- tb_therm = asanyarray(tb_thermal)
+ tb_nir = get_as_array(tb_near_ir)
+ tb_therm = get_as_array(tb_thermal)
+ sun_zenith = get_as_array(sun_zenith)
if tb_therm.shape != tb_nir.shape:
errmsg = 'Dimensions do not match! {0} and {1}'.format(
@@ -242,10 +237,7 @@ class Calculator(RadTbConverter):
tbco2 = None
else:
co2corr = True
- if np.isscalar(tb_ir_co2):
- tbco2 = array([tb_ir_co2, ])
- else:
- tbco2 = asanyarray(tb_ir_co2)
+ tbco2 = get_as_array(tb_ir_co2)
if not self.rsr:
raise NotImplementedError("Reflectance calculations without "
@@ -266,6 +258,7 @@ class Calculator(RadTbConverter):
LOG.info('l_nir = %s', str(l_nir))
LOG.debug("Apply sun-zenith angle clipping between 0 and %5.2f", self.masking_limit)
+
sunz = sun_zenith.clip(0, self.sunz_threshold)
mu0 = np.cos(np.deg2rad(sunz))
@@ -303,3 +296,14 @@ class Calculator(RadTbConverter):
if is_masked:
res = np.ma.masked_invalid(res)
return res
+
+
+def get_as_array(variable):
+ """Return variable as a Dask or Numpy array.
+
+ Variable may be a scalar, a list or a Numpy/Dask array.
+ """
+ if np.isscalar(variable):
+ return asanyarray([variable, ])
+
+ return asanyarray(variable)
=====================================
pyspectral/tests/test_atm_correction_ir.py
=====================================
@@ -24,6 +24,7 @@
import numpy as np
+import dask.array as da
from pyspectral.atm_correction_ir import AtmosphericalCorrection
import sys
if sys.version_info < (2, 7):
@@ -119,7 +120,13 @@ class TestAtmCorrection(unittest.TestCase):
"""Class for testing pyspectral.atm_correction_ir."""
def test_get_correction(self):
- """Test getting the atm correction."""
+ """Test getting the atm correction (dask data)."""
+ this = AtmosphericalCorrection('EOS-Terra', 'modis')
+ atm_corr = this.get_correction(da.from_array(SATZ), None, da.from_array(TBS))
+ np.testing.assert_almost_equal(RES, atm_corr)
+
+ def test_get_correction_np(self):
+ """Test getting the atm correction (numpy data)."""
this = AtmosphericalCorrection('EOS-Terra', 'modis')
atm_corr = this.get_correction(SATZ, None, TBS)
np.testing.assert_almost_equal(RES, atm_corr)
=====================================
pyspectral/tests/test_reflectance.py
=====================================
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
-# Copyright (c) 2013-2020 Pytroll developers
+# Copyright (c) 2013-2021 Pytroll developers
#
# Author(s):
#
@@ -22,17 +22,10 @@
"""Unit testing the 3.7 micron reflectance calculations."""
-from pyspectral.near_infrared_reflectance import Calculator, TERMINATOR_LIMIT
import numpy as np
-import sys
-if sys.version_info < (2, 7):
- import unittest2 as unittest
-else:
- import unittest
-if sys.version_info < (3,):
- from mock import patch
-else:
- from unittest.mock import patch
+import unittest
+from unittest.mock import patch
+from pyspectral.near_infrared_reflectance import Calculator, TERMINATOR_LIMIT
TEST_RSR = {'20': {},
@@ -164,15 +157,15 @@ class TestReflectance(unittest.TestCase):
self.assertAlmostEqual(refl37_sz88.bandwavelength, 3.780282, 5)
self.assertEqual(refl37_sz88.bandname, '20')
- sunz = np.array([80.])
- tb3 = np.array([290.])
- tb4 = np.array([282.])
+ sunz = 80.
+ tb3 = 290.
+ tb4 = 282.
refl = refl37.reflectance_from_tbs(sunz, tb3, tb4)
np.testing.assert_allclose(refl[0], 0.251245010648, 6)
- sunz = np.array([85.])
- tb3 = np.array([290.])
- tb4 = np.array([282.])
+ sunz = 85.
+ tb3 = 290.
+ tb4 = 282.
refl = refl37.reflectance_from_tbs(sunz, tb3, tb4)
np.testing.assert_allclose(refl[0], 1.12236884, 6)
@@ -221,3 +214,69 @@ class TestReflectance(unittest.TestCase):
self.assertTrue(hasattr(refl, 'compute'))
except ImportError:
pass
+
+
+def test_get_as_array_from_scalar_input_dask():
+ """Test the function to return an array when input is a scalar - using Dask"""
+ from pyspectral.near_infrared_reflectance import get_as_array
+
+ res = get_as_array(2.3)
+ if hasattr(res, 'compute'):
+ assert res.compute()[0] == 2.3
+ else:
+ assert res[0] == 2.3
+
+
+def test_get_as_array_from_scalar_input_numpy():
+ """Test the function to return an array when input is a scalar - using Numpy"""
+ from pyspectral.near_infrared_reflectance import get_as_array
+ import numpy as np
+
+ with patch('pyspectral.near_infrared_reflectance.asanyarray', new=np.asanyarray):
+ res = get_as_array(2.3)
+
+ assert res[0] == 2.3
+
+
+def test_get_as_array_from_numpy_array_input_dask():
+ """Test the function to return an array when input is a numpy array - using Dask"""
+ from pyspectral.near_infrared_reflectance import get_as_array
+
+ res = get_as_array(np.array([1.0, 2.0]))
+
+ if hasattr(res, 'compute'):
+ np.testing.assert_allclose(res.compute(), np.array([1.0, 2.0]), 5)
+ else:
+ np.testing.assert_allclose(res, np.array([1.0, 2.0]), 5)
+
+
+def test_get_as_array_from_numpy_array_input_numpy():
+ """Test the function to return an array when input is a numpy array - using Numpy"""
+ from pyspectral.near_infrared_reflectance import get_as_array
+
+ with patch('pyspectral.near_infrared_reflectance.asanyarray', new=np.asanyarray):
+ res = get_as_array(np.array([1.0, 2.0]))
+
+ np.testing.assert_allclose(res, np.array([1.0, 2.0]), 5)
+
+
+def test_get_as_array_from_list_input_dask():
+ """Test the function to return an array when input is a list - using Dask"""
+ from pyspectral.near_infrared_reflectance import get_as_array
+
+ res = get_as_array([1.0, 2.0])
+
+ if hasattr(res, 'compute'):
+ np.testing.assert_allclose(res.compute(), np.array([1.0, 2.0]), 5)
+ else:
+ np.testing.assert_allclose(res, np.array([1.0, 2.0]), 5)
+
+
+def test_get_as_array_from_list_input_numpy():
+ """Test the function to return an array when input is a list - using Numpy"""
+ from pyspectral.near_infrared_reflectance import get_as_array
+
+ with patch('pyspectral.near_infrared_reflectance.asanyarray', new=np.asanyarray):
+ res = get_as_array([1.1, 2.2])
+
+ np.testing.assert_allclose(res, np.array([1.1, 2.2]), 5)
=====================================
rsr_convert_scripts/aatsr_reader.py
=====================================
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
-# Copyright (c) 2016, 2017 Pytroll developers
+# Copyright (c) 2016, 2017, 2021 Pytroll developers
#
# Author(s):
#
@@ -79,9 +79,13 @@ class AatsrRSR(object):
def main():
- """Main"""
+ """Main.
+
+ """
tohdf5(AatsrRSR, 'Envisat', AATSR_BAND_NAMES)
+
if __name__ == "__main__":
+
main()
=====================================
rsr_convert_scripts/ahi_reader.py
=====================================
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
-# Copyright (c) 2015-2017 Pytroll developers
+# Copyright (c) 2015-2017, 2021 Pytroll developers
#
# Author(s):
#
@@ -26,8 +26,6 @@ http://www.data.jma.go.jp/mscweb/en/himawari89/space_segment/spsg_ahi.html#srf
"""
import logging
-LOG = logging.getLogger(__name__)
-
import os
import numpy as np
from xlrd import open_workbook
@@ -35,6 +33,7 @@ from xlrd import open_workbook
from pyspectral.utils import get_central_wave
from pyspectral.config import get_config
+LOG = logging.getLogger(__name__)
AHI_BAND_NAMES = {'Band 1': 'ch1',
'Band 2': 'ch2',
@@ -149,6 +148,7 @@ def main():
convert2hdf5('Himawari-{0:d}'.format(satnum))
print("Himawari-{0:d} done...".format(satnum))
+
if __name__ == "__main__":
import sys
=====================================
rsr_convert_scripts/cocts_rsr.py
=====================================
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
-# Copyright (c) 2019 Pytroll developers
+# Copyright (c) 2019, 2021 Pytroll developers
#
# Author(s):
#
@@ -20,12 +20,12 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-"""Read the HY-1C COCTS relative spectral responses. Data from
+"""Read the HY-1C COCTS relative spectral responses. Data from
lwk1542 at hotmail.com
NB! The two IR bands are NOT included.
-See issue
+See issue
https://github.com/pytroll/pyspectral/issues/61
"""
import os
View it on GitLab: https://salsa.debian.org/debian-gis-team/pyspectral/-/compare/070914aab0aa2f1e654e9d0837985dcbb5d76cf2...dfd20925c74bfd0cbe671fc5265a9fc1c7100121
--
View it on GitLab: https://salsa.debian.org/debian-gis-team/pyspectral/-/compare/070914aab0aa2f1e654e9d0837985dcbb5d76cf2...dfd20925c74bfd0cbe671fc5265a9fc1c7100121
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-grass-devel/attachments/20210818/4f85460d/attachment-0001.htm>
More information about the Pkg-grass-devel
mailing list