Skip to content

Commit

Permalink
Merge pull request #515 from djhoese/style-fixes
Browse files Browse the repository at this point in the history
Fix all flake8 errors in satpy package code
  • Loading branch information
djhoese authored Nov 25, 2018
2 parents c2a2a44 + fcd71f6 commit 6e5ec68
Show file tree
Hide file tree
Showing 48 changed files with 350 additions and 555 deletions.
3 changes: 2 additions & 1 deletion .stickler.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
linters:
flake8:
max-line-length: 120
python: 3
config: setup.cfg
93 changes: 31 additions & 62 deletions satpy/composites/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import logging
import os
import time
import warnings
from weakref import WeakValueDictionary

import numpy as np
Expand All @@ -36,10 +37,8 @@
import dask.array as da
import yaml

from satpy.config import (CONFIG_PATH, config_search_paths,
recursive_dict_update)
from satpy.dataset import (DATASET_KEYS, DatasetID, MetadataObject,
combine_metadata)
from satpy.config import CONFIG_PATH, config_search_paths, recursive_dict_update
from satpy.dataset import DATASET_KEYS, DatasetID, MetadataObject, combine_metadata
from satpy.readers import DatasetDict
from satpy.utils import sunzen_corr_cos, atmospheric_path_length_correction
from satpy.writers import get_enhanced_image
Expand All @@ -49,25 +48,17 @@


class IncompatibleAreas(Exception):

"""
Error raised upon compositing things of different shapes.
"""
"""Error raised upon compositing things of different shapes."""
pass


class IncompatibleTimes(Exception):

"""
Error raised upon compositing things from different times.
"""
"""Error raised upon compositing things from different times."""
pass


class CompositorLoader(object):

"""Read composites using the configuration files on disk.
"""
"""Read composites using the configuration files on disk."""

def __init__(self, ppp_config_dir=CONFIG_PATH):
self.modifiers = {}
Expand Down Expand Up @@ -260,11 +251,7 @@ def sub_arrays(proj1, proj2):

class CompositeBase(MetadataObject):

def __init__(self,
name,
prerequisites=None,
optional_prerequisites=None,
**kwargs):
def __init__(self, name, prerequisites=None, optional_prerequisites=None, **kwargs):
# Required info
kwargs["name"] = name
kwargs["prerequisites"] = prerequisites or []
Expand Down Expand Up @@ -322,8 +309,7 @@ def check_areas(self, data_arrays):


class SunZenithCorrectorBase(CompositeBase):

"""Base class for sun zenith correction"""
"""Base class for sun zenith correction."""

coszen = WeakValueDictionary()

Expand Down Expand Up @@ -371,23 +357,22 @@ def _apply_correction(self, proj, coszen):


class SunZenithCorrector(SunZenithCorrectorBase):

"""Standard sun zenith correction, 1/cos(sunz)"""
"""Standard sun zenith correction, 1/cos(sunz)."""

def _apply_correction(self, proj, coszen):
LOG.debug("Apply the standard sun-zenith correction [1/cos(sunz)]")
return sunzen_corr_cos(proj, coszen)


class EffectiveSolarPathLengthCorrector(SunZenithCorrectorBase):
"""Special sun zenith correction with the method proposed by Li and Shibata.
"""Special sun zenith correction with the method proposed by Li and Shibata
(2006): https://doi.org/10.1175/JAS3682.1
"""

def _apply_correction(self, proj, coszen):
LOG.debug(
"Apply the effective solar atmospheric path length correction method by Li and Shibata")
LOG.debug("Apply the effective solar atmospheric path length correction method by Li and Shibata")
return atmospheric_path_length_correction(proj, coszen)


Expand Down Expand Up @@ -474,8 +459,10 @@ def __call__(self, projectables, optional_datasets=None, **info):
class NIRReflectance(CompositeBase):

def __call__(self, projectables, optional_datasets=None, **info):
"""Get the reflectance part of an NIR channel. Not supposed to be used
for wavelength outside [3, 4] µm.
"""Get the reflectance part of an NIR channel.
Not supposed to be used for wavelength outside [3, 4] µm.
"""
self._init_refl3x(projectables)
_nir, _ = projectables
Expand All @@ -489,8 +476,7 @@ def __call__(self, projectables, optional_datasets=None, **info):
return proj

def _init_refl3x(self, projectables):
"""Initiate the 3.x reflectance derivations
"""
"""Initiate the 3.x reflectance derivations."""
try:
from pyspectral.near_infrared_reflectance import Calculator
except ImportError:
Expand All @@ -501,7 +487,7 @@ def _init_refl3x(self, projectables):
self._refl3x = Calculator(_nir.attrs['platform_name'], _nir.attrs['sensor'], _nir.attrs['name'])

def _get_reflectance(self, projectables, optional_datasets):
"""Calculate 3.x reflectance with pyspectral"""
"""Calculate 3.x reflectance with pyspectral."""
_nir, _tb11 = projectables
LOG.info('Getting reflective part of %s', _nir.attrs['name'])

Expand Down Expand Up @@ -530,7 +516,9 @@ class NIREmissivePartFromReflectance(NIRReflectance):

def __call__(self, projectables, optional_datasets=None, **info):
"""Get the emissive part an NIR channel after having derived the reflectance.
Not supposed to be used for wavelength outside [3, 4] µm.
"""
self._init_refl3x(projectables)
# Derive the sun-zenith angles, and use the nir and thermal ir
Expand All @@ -552,8 +540,7 @@ def __call__(self, projectables, optional_datasets=None, **info):
class PSPAtmosphericalCorrection(CompositeBase):

def __call__(self, projectables, optional_datasets=None, **info):
"""Get the atmospherical correction. Uses pyspectral.
"""
"""Get the atmospherical correction. Uses pyspectral."""
from pyspectral.atm_correction_ir import AtmosphericalCorrection

band = projectables[0]
Expand Down Expand Up @@ -593,14 +580,14 @@ def __call__(self, projectables, optional_datasets=None, **info):
class CO2Corrector(CompositeBase):

def __call__(self, projectables, optional_datasets=None, **info):
"""CO2 correction of the brightness temperature of the MSG 3.9um
channel.
"""CO2 correction of the brightness temperature of the MSG 3.9um channel.
.. math::
T4_CO2corr = (BT(IR3.9)^4 + Rcorr)^0.25
Rcorr = BT(IR10.8)^4 - (BT(IR10.8)-dt_CO2)^4
dt_CO2 = (BT(IR10.8)-BT(IR13.4))/4.0
"""
(ir_039, ir_108, ir_134) = projectables
LOG.info('Applying CO2 correction')
Expand Down Expand Up @@ -707,38 +694,29 @@ def __call__(self, projectables, nonprojectables=None, **info):
projectables[3] = projectables[3].fillna(projectables[0])
return super(FillingCompositor, self).__call__(projectables[1:], **info)


class RGBCompositor(GenericCompositor):

def __call__(self, projectables, nonprojectables=None, **info):

import warnings
warnings.warn("RGBCompositor is deprecated, use GenericCompositor "
"instead.", DeprecationWarning)

warnings.warn("RGBCompositor is deprecated, use GenericCompositor instead.", DeprecationWarning)
if len(projectables) != 3:
raise ValueError("Expected 3 datasets, got %d" %
(len(projectables), ))
raise ValueError("Expected 3 datasets, got %d" % (len(projectables),))
return super(RGBCompositor, self).__call__(projectables, **info)


class BWCompositor(GenericCompositor):

def __call__(self, projectables, nonprojectables=None, **info):

import warnings
warnings.warn("BWCompositor is deprecated, use GenericCompositor "
"instead.", DeprecationWarning)

warnings.warn("BWCompositor is deprecated, use GenericCompositor instead.", DeprecationWarning)
return super(BWCompositor, self).__call__(projectables, **info)


class ColormapCompositor(GenericCompositor):

"""A compositor that uses colormaps."""

@staticmethod
def build_colormap(palette, dtype, info):
"""Create the colormap from the `raw_palette` and the valid_range."""

from trollimage.colormap import Colormap

palette = np.asanyarray(palette).squeeze()
Expand All @@ -760,10 +738,7 @@ def build_colormap(palette, dtype, info):


class ColorizeCompositor(ColormapCompositor):

"""A compositor colorizing the data, interpolating the palette colors when
needed.
"""
"""A compositor colorizing the data, interpolating the palette colors when needed."""

def __call__(self, projectables, **info):
if len(projectables) != 2:
Expand Down Expand Up @@ -791,14 +766,11 @@ def __call__(self, projectables, **info):


class PaletteCompositor(ColormapCompositor):

"""A compositor colorizing the data, not interpolating the palette colors.
"""
"""A compositor colorizing the data, not interpolating the palette colors."""

def __call__(self, projectables, **info):
if len(projectables) != 2:
raise ValueError("Expected 2 datasets, got %d" %
(len(projectables), ))
raise ValueError("Expected 2 datasets, got %d" % (len(projectables),))

# TODO: support datasets with palette to delegate this to the image
# writer.
Expand Down Expand Up @@ -959,7 +931,6 @@ def __call__(self, projectables, *args, **kwargs):
| WV6.2 | 243 to 208 K | gamma 1 |
+--------------------+--------------------+--------------------+
"""
import warnings
warnings.warn("Airmass compositor is deprecated, use GenericCompositor "
"with DifferenceCompositor instead.", DeprecationWarning)
ch1 = sub_arrays(projectables[0], projectables[1])
Expand All @@ -985,7 +956,6 @@ def __call__(self, projectables, *args, **kwargs):
| IR1.6 - VIS0.6 | -70 to 20 % | gamma 1 |
+--------------------+--------------------+--------------------+
"""
import warnings
warnings.warn("Convection ompositor is deprecated, use GenericCompositor "
"with DifferenceCompositor instead.", DeprecationWarning)

Expand Down Expand Up @@ -1024,7 +994,6 @@ def __call__(self, projectables, *args, **kwargs):
| IR10.8 | 261 to 289 K | gamma 1 |
+--------------------+--------------------+--------------------+
"""
import warnings
warnings.warn("Dust compositor is deprecated, use GenericCompositor "
"with DifferenceCompositor instead.", DeprecationWarning)

Expand Down
2 changes: 1 addition & 1 deletion satpy/composites/abi.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"""

import logging
from satpy.composites import GenericCompositor, IncompatibleAreas
from satpy.composites import GenericCompositor

LOG = logging.getLogger(__name__)

Expand Down
11 changes: 4 additions & 7 deletions satpy/composites/crefl_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@
Ralph's code was originally based on the C crefl code distributed for VIIRS and MODIS.
"""
import logging
import os
import sys

import numpy as np
# from memory_profiler import profile
import xarray.ufuncs as xu
import xarray as xr
import dask.array as da

Expand Down Expand Up @@ -62,8 +58,8 @@ def csalbr(tau):
# Previously 3 functions csalbr fintexp1, fintexp3
a = [-.57721566, 0.99999193, -0.24991055, 0.05519968, -0.00976004,
0.00107857]
#xx = a[0] + a[1] * tau + a[2] * tau**2 + a[3] * tau**3 + a[4] * tau**4 + a[5] * tau**5
#xx = np.polyval(a[::-1], tau)
# xx = a[0] + a[1] * tau + a[2] * tau**2 + a[3] * tau**3 + a[4] * tau**4 + a[5] * tau**5
# xx = np.polyval(a[::-1], tau)

# xx = a[0]
# xftau = 1.0
Expand All @@ -76,6 +72,7 @@ def csalbr(tau):
return (3.0 * tau - fintexp3 *
(4.0 + 2.0 * tau) + 2.0 * np.exp(-tau)) / (4.0 + 3.0 * tau)


# From crefl.1.7.1
if bUseV171:
aH2O = np.array([-5.60723, -5.25251, 0, 0, -6.29824, -7.70944, -3.91877, 0,
Expand Down Expand Up @@ -414,7 +411,7 @@ def run_crefl(refl, coeffs,
# Get digital elevation map data for our granule, set ocean fill value to 0
if avg_elevation is None:
LOG.debug("No average elevation information provided in CREFL")
#height = np.zeros(lon.shape, dtype=np.float)
# height = np.zeros(lon.shape, dtype=np.float)
height = 0.
else:
LOG.debug("Using average elevation information provided to CREFL")
Expand Down
Loading

0 comments on commit 6e5ec68

Please sign in to comment.