Skip to content

Commit

Permalink
Merge pull request #56 from pytroll/rsr-download-fix
Browse files Browse the repository at this point in the history
Rsr download fix
  • Loading branch information
adybbroe authored Nov 28, 2018
2 parents 866a52c + 8f8a4ec commit 1ad2b38
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 34 deletions.
3 changes: 2 additions & 1 deletion pyspectral/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (c) 2013 - 2018 PyTroll
# Copyright (c) 2013 - 2018 PyTroll Community


# Author(s):

Expand Down
12 changes: 9 additions & 3 deletions pyspectral/rayleigh.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,14 @@ def get_effective_wavelength(self, bandname):
"""Get the effective wavelength with Rayleigh scattering in mind"""
try:
rsr = RelativeSpectralResponse(self.platform_name, self.sensor)
except IOError:
except(IOError, OSError):
LOG.exception(
"No spectral responses for this platform and sensor: %s %s", self.platform_name, self.sensor)
if isinstance(bandname, (float, integer_types)):
LOG.warning(
"Effective wavelength is set to the requested band wavelength = %f", bandname)
return bandname
raise
return None

if isinstance(bandname, str):
bandname = BANDNAMES.get(self.sensor, BANDNAMES['generic']).get(bandname, bandname)
Expand Down Expand Up @@ -214,7 +214,13 @@ def get_reflectance(self, sun_zenith, sat_zenith, azidiff, bandname, redband=Non
'it is the effective wavelength: %f (micro meter)', bandname)
wvl = bandname * 1000.0
else:
wvl = self.get_effective_wavelength(bandname) * 1000.0
wvl = self.get_effective_wavelength(bandname)
if wvl is None:
LOG.error("Can't get effective wavelength for band %s on platform %s and sensor %s",
str(bandname), self.platform_name, self.sensor)
return None
else:
wvl = wvl * 1000.0

rayl, wvl_coord, azid_coord, satz_sec_coord, sunz_sec_coord = \
self.get_reflectance_lut()
Expand Down
14 changes: 10 additions & 4 deletions pyspectral/rsr_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,17 @@ def _get_filename(self):

LOG.debug('Filename: %s', str(self.filename))
if not os.path.exists(self.filename) or not os.path.isfile(self.filename):
# Try download from the internet!
LOG.warning("No rsr file %s on disk", self.filename)
if self.do_download:
LOG.info("Will download from internet...")
download_rsr()

if self._rsr_data_version_uptodate:
LOG.info("RSR data up to date, so seems there is no support for this platform and sensor")
else:
# Try download from the internet!
if self.do_download:
LOG.info("Will download from internet...")
download_rsr()
if self._get_rsr_data_version() == RSR_DATA_VERSION:
self._rsr_data_version_uptodate = True

if not self._rsr_data_version_uptodate:
LOG.warning("rsr data may not be up to date: %s", self.filename)
Expand Down
13 changes: 9 additions & 4 deletions pyspectral/tests/test_rad_tb_conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,17 @@
from pyspectral.radiance_tb_conversion import RadTbConverter
from pyspectral.radiance_tb_conversion import SeviriRadTbConverter
from pyspectral.utils import get_central_wave
import unittest
import numpy as np
try:
from unittest.mock import patch
except ImportError:
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


TEST_TBS = np.array([200., 270., 300., 302., 350.], dtype='float32')

Expand Down
11 changes: 5 additions & 6 deletions pyspectral/tests/test_raw_readers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (c) 2017 Adam.Dybbroe
# Copyright (c) 2017, 2018 Adam.Dybbroe

# Author(s):

Expand All @@ -23,15 +23,14 @@
"""Test the raw satellite instrument rsr readers."""

import sys
try:
from unittest import mock
except ImportError:
import mock

if sys.version_info < (2, 7):
import unittest2 as unittest
else:
import unittest
if sys.version_info < (3,):
import mock
else:
from unittest import mock

AATSR_PATH = '/home/a000680/data/SpectralResponses/aatsr/consolidatedsrfs.xls'
RSR_DIR = '/home/a000680/data/pyspectral'
Expand Down
8 changes: 4 additions & 4 deletions pyspectral/tests/test_rayleigh.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@

import os
import sys
try:
from unittest.mock import patch
except ImportError:
from mock import patch
import numpy as np
import dask.array as da
from pyspectral import rayleigh
Expand All @@ -46,6 +42,10 @@
else:
import unittest

if sys.version_info < (3,):
from mock import patch
else:
from unittest.mock import patch

TEST_RAYLEIGH_RESULT1 = np.array([10.40727436, 8.69775471], dtype='float32')
TEST_RAYLEIGH_RESULT2 = np.array([9.71695252, 8.51415601], dtype='float32')
Expand Down
14 changes: 9 additions & 5 deletions pyspectral/tests/test_reflectance.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@
"""Unit testing the 3.7 micron reflectance calculations"""

from pyspectral.near_infrared_reflectance import Calculator
try:
from unittest.mock import patch
except ImportError:
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
import numpy as np

TEST_RSR = {'20': {},
'99': {}}
Expand Down
11 changes: 5 additions & 6 deletions pyspectral/tests/test_rsr_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,18 @@
import sys
from pyspectral.rsr_reader import RelativeSpectralResponse
from pyspectral.utils import WAVE_NUMBER
from pyspectral.utils import WAVE_LENGTH
from pyspectral.utils import RSR_DATA_VERSION
import numpy as np

try:
from unittest.mock import patch
except ImportError:
from mock import patch
if sys.version_info < (2, 7):
import unittest2 as unittest
else:
import unittest

import numpy as np
if sys.version_info < (3,):
from mock import patch
else:
from unittest.mock import patch

TEST_RSR = {'20': {}, }
TEST_RSR['20']['det-1'] = {}
Expand Down
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
import os.path
import versioneer

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', 'r') as fd:
long_description = fd.read()
Expand Down Expand Up @@ -58,7 +61,7 @@
setup(name='pyspectral',
version=versioneer.get_version(),
cmdclass=versioneer.get_cmdclass(),
description='Reading and manipulaing satellite sensor spectral responses and the solar spectrum, to perfom various corrections to VIS and NIR band data',
description=description,
author='Adam Dybbroe',
author_email='[email protected]',
classifiers=['Development Status :: 4 - Beta',
Expand Down

0 comments on commit 1ad2b38

Please sign in to comment.