Commit f5c9cd5b authored by Daniel Scheffler's avatar Daniel Scheffler
Browse files

Added remaining docstrings - pydocstyle now runs successfully.

parent 221103d0
Pipeline #828 passed with stages
in 6 minutes and 19 seconds
...@@ -3,5 +3,5 @@ ...@@ -3,5 +3,5 @@
__author__ = """Karl Segl""" __author__ = """Karl Segl"""
__email__ = 'segl@gfz-potsdam.de' __email__ = 'segl@gfz-potsdam.de'
__version__ = '0.2.4' __version__ = '0.2.5'
__versionalias__ = '2017-08-24_05' __versionalias__ = '2017-08-24_06'
...@@ -5,7 +5,7 @@ from datetime import datetime ...@@ -5,7 +5,7 @@ from datetime import datetime
import logging import logging
from ..model.images import EnMAPL1Product_SensorGeo from ..model.images import EnMAPL1Product_SensorGeo
from ..model.metadata import EnMAP_Metadata_SensorGeo from ..model.metadata import EnMAP_Metadata_L1B_SensorGeo
class L1B_Reader(object): class L1B_Reader(object):
...@@ -31,7 +31,7 @@ class L1B_Reader(object): ...@@ -31,7 +31,7 @@ class L1B_Reader(object):
L1_obj = EnMAPL1Product_SensorGeo(root_dir) L1_obj = EnMAPL1Product_SensorGeo(root_dir)
# read metadata # read metadata
L1_obj.meta = EnMAP_Metadata_SensorGeo(L1_obj.paths.metaxml) L1_obj.meta = EnMAP_Metadata_L1B_SensorGeo(L1_obj.paths.metaxml)
L1_obj.meta.read_metadata(observation_time=observation_time, lon_lat_smpl=lon_lat_smpl, nsmile_coef=nsmile_coef) L1_obj.meta.read_metadata(observation_time=observation_time, lon_lat_smpl=lon_lat_smpl, nsmile_coef=nsmile_coef)
# read VNIR data # read VNIR data
......
...@@ -9,7 +9,8 @@ from geoarray import GeoArray, NoDataMask, CloudMask ...@@ -9,7 +9,8 @@ from geoarray import GeoArray, NoDataMask, CloudMask
from ..utils.path_generator import PathGenL1BProduct from ..utils.path_generator import PathGenL1BProduct
from ..utils.logging import EnPT_Logger from ..utils.logging import EnPT_Logger
from ..model.metadata import EnMAP_Metadata_SensorGeo, EnMAP_Metadata_VNIR_SensorGeo, EnMAP_Metadata_SWIR_SensorGeo from ..model.metadata import \
EnMAP_Metadata_L1B_SensorGeo, EnMAP_Metadata_L1B_VNIR_SensorGeo, EnMAP_Metadata_L1B_SWIR_SensorGeo
############## ##############
...@@ -414,8 +415,8 @@ class _EnMAP_Detector_SensorGeo(_EnMAP_Image): ...@@ -414,8 +415,8 @@ class _EnMAP_Detector_SensorGeo(_EnMAP_Image):
self.paths = self.get_paths() self.paths = self.get_paths()
# instance an empty metadata object # instance an empty metadata object
self.detector_meta = \ self.detector_meta = \
EnMAP_Metadata_VNIR_SensorGeo(self.paths.metaxml, logger=logger) if self.detector_name == 'VNIR' else \ EnMAP_Metadata_L1B_VNIR_SensorGeo(self.paths.metaxml, logger=logger) if self.detector_name == 'VNIR' else \
EnMAP_Metadata_SWIR_SensorGeo(self.paths.metaxml, logger=logger) EnMAP_Metadata_L1B_SWIR_SensorGeo(self.paths.metaxml, logger=logger)
def get_paths(self): def get_paths(self):
"""Get all file paths associated with the current instance of _EnMAP_Detector_SensorGeo. """Get all file paths associated with the current instance of _EnMAP_Detector_SensorGeo.
...@@ -538,7 +539,7 @@ class EnMAPL1Product_SensorGeo(object): ...@@ -538,7 +539,7 @@ class EnMAPL1Product_SensorGeo(object):
self.vnir = EnMAP_VNIR_SensorGeo(root_dir) self.vnir = EnMAP_VNIR_SensorGeo(root_dir)
self.swir = EnMAP_SWIR_SensorGeo(root_dir) self.swir = EnMAP_SWIR_SensorGeo(root_dir)
self.paths = self.get_paths() self.paths = self.get_paths()
self.meta = EnMAP_Metadata_SensorGeo(self.paths.metaxml, logger=logger) self.meta = EnMAP_Metadata_L1B_SensorGeo(self.paths.metaxml, logger=logger)
self.detector_attrNames = ['vnir', 'swir'] self.detector_attrNames = ['vnir', 'swir']
def get_paths(self): def get_paths(self):
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"""EnPT metadata modules. All object and functions regarding EnMAP metadata are implemented here."""
from datetime import datetime from datetime import datetime
from xml.etree import ElementTree from xml.etree import ElementTree
...@@ -21,7 +22,7 @@ L1B_product_props = dict( ...@@ -21,7 +22,7 @@ L1B_product_props = dict(
############## ##############
class _EnMAP_Metadata_Detector_SensorGeo(object): class _EnMAP_Metadata_L1B_Detector_SensorGeo(object):
"""Base class for all EnMAP metadata associated with a single EnMAP detector in sensor geometry. """Base class for all EnMAP metadata associated with a single EnMAP detector in sensor geometry.
NOTE: NOTE:
...@@ -148,7 +149,7 @@ class _EnMAP_Metadata_Detector_SensorGeo(object): ...@@ -148,7 +149,7 @@ class _EnMAP_Metadata_Detector_SensorGeo(object):
######################################################### #########################################################
class EnMAP_Metadata_SensorGeo(object): class EnMAP_Metadata_L1B_SensorGeo(object):
"""EnMAP Metadata class holding the metadata of the complete EnMAP product in sensor geometry incl. VNIR and SWIR. """EnMAP Metadata class holding the metadata of the complete EnMAP product in sensor geometry incl. VNIR and SWIR.
Attributes: Attributes:
...@@ -160,28 +161,43 @@ class EnMAP_Metadata_SensorGeo(object): ...@@ -160,28 +161,43 @@ class EnMAP_Metadata_SensorGeo(object):
""" """
def __init__(self, path_metaxml, logger=None): def __init__(self, path_metaxml, logger=None):
"""Get a metadata object instance for the given EnMAP L1B product in sensor geometry.
:param path_metaxml: file path of the EnMAP L1B metadata XML file
:param logger: instance of logging.logger or subclassed
"""
self.logger = logger or logging.getLogger() self.logger = logger or logging.getLogger()
self._path_xml = path_metaxml self._path_xml = path_metaxml
# defaults # defaults
self.observation_datetime = None # type: datetime # Date and Time of image observation self.observation_datetime = None # type: datetime # Date and Time of image observation
self.vnir = None # type: EnMAP_Metadata_VNIR_SensorGeo # metadata of VNIR only self.vnir = None # type: EnMAP_Metadata_L1B_VNIR_SensorGeo # metadata of VNIR only
self.swir = None # type: EnMAP_Metadata_SWIR_SensorGeo # metadata of SWIR only self.swir = None # type: EnMAP_Metadata_L1B_SWIR_SensorGeo # metadata of SWIR only
self.detector_attrNames = ['vnir', 'swir'] self.detector_attrNames = ['vnir', 'swir']
def read_common_meta(self, observation_time: datetime=None): def read_common_meta(self, observation_time: datetime=None):
"""Read the metadata belonging to both, the VNIR and SWIR detector of the EnMAP L1B product in sensor geometry.
:param observation_time: date and time of image observation (datetime.datetime)
"""
# FIXME observation time is currently missing in the XML # FIXME observation time is currently missing in the XML
self.observation_datetime = observation_time self.observation_datetime = observation_time
def read_metadata(self, observation_time: datetime=None, lon_lat_smpl=(15, 15), nsmile_coef=4): def read_metadata(self, observation_time: datetime=None, lon_lat_smpl=(15, 15), nsmile_coef=4):
"""Read the metadata of the whole EnMAP L1B product in sensor geometry.
:param observation_time: date and time of image observation (datetime.datetime)
:param lon_lat_smpl: number if sampling points in lon, lat fields
:param nsmile_coef: number of polynomial coefficients for smile
"""
self.read_common_meta(observation_time) self.read_common_meta(observation_time)
self.vnir = EnMAP_Metadata_VNIR_SensorGeo(self._path_xml) self.vnir = EnMAP_Metadata_L1B_VNIR_SensorGeo(self._path_xml)
self.vnir.read_metadata(lon_lat_smpl=lon_lat_smpl, nsmile_coef=nsmile_coef) self.vnir.read_metadata(lon_lat_smpl=lon_lat_smpl, nsmile_coef=nsmile_coef)
self.swir = EnMAP_Metadata_SWIR_SensorGeo(self._path_xml) self.swir = EnMAP_Metadata_L1B_SWIR_SensorGeo(self._path_xml)
self.swir.read_metadata(lon_lat_smpl=lon_lat_smpl, nsmile_coef=nsmile_coef) self.swir.read_metadata(lon_lat_smpl=lon_lat_smpl, nsmile_coef=nsmile_coef)
class EnMAP_Metadata_VNIR_SensorGeo(_EnMAP_Metadata_Detector_SensorGeo): class EnMAP_Metadata_L1B_VNIR_SensorGeo(_EnMAP_Metadata_L1B_Detector_SensorGeo):
"""EnMAP Metadata class holding the metadata of the VNIR detector in sensor geometry. """EnMAP Metadata class holding the metadata of the VNIR detector in sensor geometry.
NOTE: NOTE:
...@@ -189,17 +205,27 @@ class EnMAP_Metadata_VNIR_SensorGeo(_EnMAP_Metadata_Detector_SensorGeo): ...@@ -189,17 +205,27 @@ class EnMAP_Metadata_VNIR_SensorGeo(_EnMAP_Metadata_Detector_SensorGeo):
""" """
def __init__(self, path_metaxml, logger=None): def __init__(self, path_metaxml, logger=None):
"""Get a metadata object instance for the VNIR detector of the given EnMAP L1B product in sensor geometry.
:param path_metaxml: file path of the EnMAP L1B metadata XML file
:param logger: instance of logging.logger or subclassed
"""
# get all attributes from base class '_EnMAP_Metadata_Detector_SensorGeo' # get all attributes from base class '_EnMAP_Metadata_Detector_SensorGeo'
super(EnMAP_Metadata_VNIR_SensorGeo, self).__init__('VNIR', logger=logger) super(EnMAP_Metadata_L1B_VNIR_SensorGeo, self).__init__('VNIR', logger=logger)
self._path_xml = path_metaxml self._path_xml = path_metaxml
self.detector_label = L1B_product_props['xml_detector_label']['VNIR'] self.detector_label = L1B_product_props['xml_detector_label']['VNIR']
def read_metadata(self, lon_lat_smpl=(15, 15), nsmile_coef=4): def read_metadata(self, lon_lat_smpl=(15, 15), nsmile_coef=4):
super(EnMAP_Metadata_VNIR_SensorGeo, self)\ """Read the metadata of the VNIR detector in sensor geometry.
:param lon_lat_smpl: number if sampling points in lon, lat fields
:param nsmile_coef: number of polynomial coefficients for smile
"""
super(EnMAP_Metadata_L1B_VNIR_SensorGeo, self)\
._read_metadata(self._path_xml, self.detector_label, lon_lat_smpl=lon_lat_smpl, nsmile_coef=nsmile_coef) ._read_metadata(self._path_xml, self.detector_label, lon_lat_smpl=lon_lat_smpl, nsmile_coef=nsmile_coef)
class EnMAP_Metadata_SWIR_SensorGeo(_EnMAP_Metadata_Detector_SensorGeo): class EnMAP_Metadata_L1B_SWIR_SensorGeo(_EnMAP_Metadata_L1B_Detector_SensorGeo):
"""EnMAP Metadata class holding the metadata of the SWIR detector in sensor geometry. """EnMAP Metadata class holding the metadata of the SWIR detector in sensor geometry.
NOTE: NOTE:
...@@ -207,8 +233,13 @@ class EnMAP_Metadata_SWIR_SensorGeo(_EnMAP_Metadata_Detector_SensorGeo): ...@@ -207,8 +233,13 @@ class EnMAP_Metadata_SWIR_SensorGeo(_EnMAP_Metadata_Detector_SensorGeo):
""" """
def __init__(self, path_metaxml, logger=None): def __init__(self, path_metaxml, logger=None):
"""Get a metadata object instance for the SWIR detector of the given EnMAP L1B product in sensor geometry.
:param path_metaxml: file path of the EnMAP L1B metadata XML file
:param logger: instance of logging.logger or subclassed
"""
# get all attributes from base class '_EnMAP_Metadata_Detector_SensorGeo' # get all attributes from base class '_EnMAP_Metadata_Detector_SensorGeo'
super(EnMAP_Metadata_SWIR_SensorGeo, self).__init__('SWIR', logger=logger) super(EnMAP_Metadata_L1B_SWIR_SensorGeo, self).__init__('SWIR', logger=logger)
self._path_xml = path_metaxml self._path_xml = path_metaxml
self.detector_label = L1B_product_props['xml_detector_label']['SWIR'] self.detector_label = L1B_product_props['xml_detector_label']['SWIR']
...@@ -217,7 +248,6 @@ class EnMAP_Metadata_SWIR_SensorGeo(_EnMAP_Metadata_Detector_SensorGeo): ...@@ -217,7 +248,6 @@ class EnMAP_Metadata_SWIR_SensorGeo(_EnMAP_Metadata_Detector_SensorGeo):
:param lon_lat_smpl: number if sampling points in lon, lat fields :param lon_lat_smpl: number if sampling points in lon, lat fields
:param nsmile_coef: number of polynomial coefficients for smile :param nsmile_coef: number of polynomial coefficients for smile
:return:
""" """
super(EnMAP_Metadata_SWIR_SensorGeo, self)\ super(EnMAP_Metadata_L1B_SWIR_SensorGeo, self)\
._read_metadata(self._path_xml, self.detector_label, lon_lat_smpl=lon_lat_smpl, nsmile_coef=nsmile_coef) ._read_metadata(self._path_xml, self.detector_label, lon_lat_smpl=lon_lat_smpl, nsmile_coef=nsmile_coef)
...@@ -99,6 +99,14 @@ class EnPT_Logger(logging.Logger): ...@@ -99,6 +99,14 @@ class EnPT_Logger(logging.Logger):
@property @property
def captured_stream(self): def captured_stream(self):
"""Return the already captured logging stream.
NOTE:
- set self.captured_stream:
self.captured_stream = 'any string'
:return: str
"""
if not self._captured_stream: if not self._captured_stream:
self._captured_stream = self.streamObj.getvalue() self._captured_stream = self.streamObj.getvalue()
...@@ -110,6 +118,7 @@ class EnPT_Logger(logging.Logger): ...@@ -110,6 +118,7 @@ class EnPT_Logger(logging.Logger):
self._captured_stream = string self._captured_stream = string
def close(self): def close(self):
"""Close all logging handlers."""
# update captured_stream and flush stream # update captured_stream and flush stream
# self.captured_stream += self.streamObj.getvalue() # self.captured_stream += self.streamObj.getvalue()
# print(self.handlers[:]) # print(self.handlers[:])
...@@ -135,11 +144,16 @@ class EnPT_Logger(logging.Logger): ...@@ -135,11 +144,16 @@ class EnPT_Logger(logging.Logger):
# print('sh', self.streamHandler) # print('sh', self.streamHandler)
def view_logfile(self): def view_logfile(self):
"""View the log file written to disk."""
with open(self.path_logfile) as inF: with open(self.path_logfile) as inF:
print(inF.read()) print(inF.read())
def close_logger(logger): def close_logger(logger):
"""Close the handlers of the given logging.Logger instance.
:param logger: logging.Logger instance or subclass instance
"""
if logger and hasattr(logger, 'handlers'): if logger and hasattr(logger, 'handlers'):
for handler in logger.handlers[:]: # if not called with '[:]' the StreamHandlers are left open for handler in logger.handlers[:]: # if not called with '[:]' the StreamHandlers are left open
try: try:
...@@ -153,15 +167,33 @@ def close_logger(logger): ...@@ -153,15 +167,33 @@ def close_logger(logger):
def shutdown_loggers(): def shutdown_loggers():
"""Shutdown any currently active loggers."""
logging.shutdown() logging.shutdown()
class LessThanFilter(logging.Filter): class LessThanFilter(logging.Filter):
# http://stackoverflow.com/questions/2302315/how-can-info-and-debug-logging-message-be-sent-to-stdout-and-higher-level-messag """Filter class to filter log messages by a maximum log level.
Based on http://stackoverflow.com/questions/2302315/
how-can-info-and-debug-logging-message-be-sent-to-stdout-and-higher-level-messag
"""
def __init__(self, exclusive_maximum, name=""): def __init__(self, exclusive_maximum, name=""):
"""Get an instance of LessThanFilter.
:param exclusive_maximum: maximum log level, e.g., logger.WARNING
:param name:
"""
super(LessThanFilter, self).__init__(name) super(LessThanFilter, self).__init__(name)
self.max_level = exclusive_maximum self.max_level = exclusive_maximum
def filter(self, record): def filter(self, record):
"""Filter funtion.
NOTE: Returns True if logging level of the given record is below the maximum log level.
:param record:
:return: bool
"""
# non-zero return means we log this message # non-zero return means we log this message
return True if record.levelno < self.max_level else False return True if record.levelno < self.max_level else False
...@@ -17,7 +17,7 @@ test_requirements = ['coverage', 'nose', 'nose-htmloutput', 'rednose'] ...@@ -17,7 +17,7 @@ test_requirements = ['coverage', 'nose', 'nose-htmloutput', 'rednose']
setup( setup(
name='enpt', name='enpt',
version='0.2.4', version='0.2.5',
description="EnMAP PT", description="EnMAP PT",
long_description=readme + '\n\n' + history, long_description=readme + '\n\n' + history,
author="Karl Segl", author="Karl Segl",
......
enpt/model/metadata.py:1 at module level:
D100: Missing docstring in public module
enpt/model/metadata.py:162 in public method `__init__`:
D102: Missing docstring in public method
enpt/model/metadata.py:172 in public method `read_common_meta`:
D102: Missing docstring in public method
enpt/model/metadata.py:176 in public method `read_metadata`:
D102: Missing docstring in public method
enpt/model/metadata.py:191 in public method `__init__`:
D102: Missing docstring in public method
enpt/model/metadata.py:197 in public method `read_metadata`:
D102: Missing docstring in public method
enpt/model/metadata.py:209 in public method `__init__`:
D102: Missing docstring in public method
enpt/utils/logging.py:101 in public method `captured_stream`:
D102: Missing docstring in public method
enpt/utils/logging.py:112 in public method `close`:
D102: Missing docstring in public method
enpt/utils/logging.py:137 in public method `view_logfile`:
D102: Missing docstring in public method
enpt/utils/logging.py:142 in public function `close_logger`:
D103: Missing docstring in public function
enpt/utils/logging.py:155 in public function `shutdown_loggers`:
D103: Missing docstring in public function
enpt/utils/logging.py:159 in public class `LessThanFilter`:
D101: Missing docstring in public class
enpt/utils/logging.py:161 in public method `__init__`:
D102: Missing docstring in public method
enpt/utils/logging.py:165 in public method `filter`:
D102: Missing docstring in public method
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment