Skip to content

Commit

Permalink
Fix code quality issues from Codacy and Codeclimate
Browse files Browse the repository at this point in the history
Signed-off-by: Adam.Dybbroe <adam.dybbroe@smhi.se>
  • Loading branch information
adybbroe committed Jan 4, 2018
1 parent 273d5da commit b29cf70
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 57 deletions.
8 changes: 4 additions & 4 deletions pyspectral/near_infrared_reflectance.py
Expand Up @@ -59,7 +59,7 @@ class Calculator(RadTbConverter):
The relfectance calculated is without units and should be between 0 and 1.
"""

def __init__(self, platform_name, instrument, band, solar_flux=None, **kwargs):
def __init__(self, platform_name, instrument, band, **kwargs):
super(Calculator, self).__init__(platform_name, instrument, band, **kwargs)

from numbers import Number
Expand All @@ -79,10 +79,10 @@ def __init__(self, platform_name, instrument, band, solar_flux=None, **kwargs):

options = get_config()

if solar_flux is None:
self.solar_flux = kwargs.get('solar_flux', None)
if self.solar_flux is None:
self._get_solarflux()
else:
self.solar_flux = solar_flux

self._rad3x = None
self._rad3x_t11 = None
self._solar_radiance = None
Expand Down
62 changes: 9 additions & 53 deletions pyspectral/radiance_tb_conversion.py
Expand Up @@ -111,26 +111,16 @@ def __init__(self, platform_name, instrument, band, **options):
self.bandwavelength = None
self.band = band

if 'wavespace' in options:
if options['wavespace'] not in [WAVE_LENGTH, WAVE_NUMBER]:
raise AttributeError('Wave space not {0} or {1}!'.format(WAVE_LENGTH,
WAVE_NUMBER))
self.wavespace = options['wavespace']
else:
self.wavespace = WAVE_LENGTH
self.wavespace = options.get('wavespace', WAVE_LENGTH)
if self.wavespace not in [WAVE_LENGTH, WAVE_NUMBER]:
raise AttributeError('Wave space not {0} or {1}!'.format(WAVE_LENGTH,
WAVE_NUMBER))

self._wave_unit = 'm'
self._wave_si_scale = 1.0

if 'detector' in options:
self.detector = options['detector']
else:
self.detector = 'det-1'

if 'tb_resolution' in options:
self.tb_resolution = options['tb_resolution']
else:
self.tb_resolution = 0.1
self.detector = options.get('detector', 'det-1')
self.tb_resolution = options.get('tb_resolution', 0.1)
self.tb_scale = 1. / self.tb_resolution

self.blackbody_function = BLACKBODY_FUNC[self.wavespace]
Expand All @@ -144,7 +134,6 @@ def _get_rsr(self):
convert to the requested wave-spave (wavelength or wave number)
"""

sensor = RelativeSpectralResponse(self.platform_name, self.instrument)

if self.wavespace == WAVE_NUMBER:
Expand Down Expand Up @@ -175,7 +164,6 @@ def _getsatname(self):
and number
"""

if self.platform_name.startswith("Meteosat"):
return self.platform_name
else:
Expand All @@ -197,7 +185,6 @@ def tb2radiance(self, tb_, **kwargs):
If False the radiance is the band integrated radiance. Default is True.
"""

lut = kwargs.get('lut', None)
normalized = kwargs.get('normalized', True)

Expand Down Expand Up @@ -257,7 +244,6 @@ def radiance2tb(self, rad):
rad:
Radiance in SI units
"""

return radiance2tb(rad, self.rsr[self.bandname][self.detector]['central_wavelength'] * 1e-6)


Expand All @@ -270,7 +256,6 @@ def radiance2tb(rad, wavelength):
wavelength:
Wavelength in SI units (meter)
"""

from pyspectral.blackbody import blackbody_rad2temp as rad2temp
return rad2temp(wavelength, rad)

Expand All @@ -288,60 +273,32 @@ def __init__(self, platform_name, band, **kwargs):
E.g.:
platform_name = Meteosat-9
band = 3.75
"""
"""
super(SeviriRadTbConverter, self).__init__(platform_name, 'seviri',
band, **kwargs)

self.response = None
self.wavelength_or_wavenumber = None
self.band = band

if isinstance(self.band, str):
self.bandname = BANDNAMES.get(self.band, self.band)
else:
raise AttributeError('Band name provided as a string is required')

if 'wavespace' in kwargs:
if kwargs['wavespace'] not in [WAVE_LENGTH, WAVE_NUMBER]:
raise AttributeError('Wave space not {0} or {1}!'.format(WAVE_LENGTH,
WAVE_NUMBER))
self.wavespace = kwargs['wavespace']
else:
self.wavespace = WAVE_LENGTH

self._wave_unit = 'm'
self._wave_si_scale = 1.0

if 'detector' in kwargs:
self.detector = kwargs['detector']
else:
self.detector = 'det-1'

if 'tb_resolution' in kwargs:
self.tb_resolution = kwargs['tb_resolution']
else:
self.tb_resolution = 0.1
self.tb_scale = 1. / self.tb_resolution

self.blackbody_function = BLACKBODY_FUNC[self.wavespace]
self.rsr_integral = 1.0

def _get_rsr(self):
"""Overload the _get_rsr method, since RSR data are ignored here"""
pass

def radiance2tb(self, rad):
"""Get the Tb from the radiance using the simple non-linear regression
method.
rad: Radiance in units = 'mW/m^2 sr^-1 (cm^-1)^-1'
"""
#
# Tb = C2 * νc/{α * log[C1*νc**3 / L + 1]} - β/α
#
# C1 = 2 * h * c**2 and C2 = hc/k
#

c_1 = 2 * H_PLANCK * C_SPEED ** 2
c_2 = H_PLANCK * C_SPEED / K_BOLTZMANN

Expand All @@ -364,7 +321,6 @@ def tb2radiance(self, tb_, **kwargs):
#
# C1 = 2 * h * c**2 and C2 = hc/k
#

lut = kwargs.get('lut', None)
normalized = kwargs.get('normalized', True)

Expand Down

0 comments on commit b29cf70

Please sign in to comment.