Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
EnMAP
GFZ_Tools_EnMAP_BOX
EnPT
Commits
f5c9cd5b
Commit
f5c9cd5b
authored
Aug 24, 2017
by
Daniel Scheffler
Browse files
Added remaining docstrings - pydocstyle now runs successfully.
parent
221103d0
Pipeline
#828
passed with stages
in 6 minutes and 19 seconds
Changes
7
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
enpt/__init__.py
View file @
f5c9cd5b
...
...
@@ -3,5 +3,5 @@
__author__
=
"""Karl Segl"""
__email__
=
'segl@gfz-potsdam.de'
__version__
=
'0.2.
4
'
__versionalias__
=
'2017-08-24_0
5
'
__version__
=
'0.2.
5
'
__versionalias__
=
'2017-08-24_0
6
'
enpt/io/reader.py
View file @
f5c9cd5b
...
...
@@ -5,7 +5,7 @@ from datetime import datetime
import
logging
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
):
...
...
@@ -31,7 +31,7 @@ class L1B_Reader(object):
L1_obj
=
EnMAPL1Product_SensorGeo
(
root_dir
)
# 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
)
# read VNIR data
...
...
enpt/model/images.py
View file @
f5c9cd5b
...
...
@@ -9,7 +9,8 @@ from geoarray import GeoArray, NoDataMask, CloudMask
from
..utils.path_generator
import
PathGenL1BProduct
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):
self
.
paths
=
self
.
get_paths
()
# instance an empty metadata object
self
.
detector_meta
=
\
EnMAP_Metadata_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_
VNIR_SensorGeo
(
self
.
paths
.
metaxml
,
logger
=
logger
)
if
self
.
detector_name
==
'VNIR'
else
\
EnMAP_Metadata_
L1B_
SWIR_SensorGeo
(
self
.
paths
.
metaxml
,
logger
=
logger
)
def
get_paths
(
self
):
"""Get all file paths associated with the current instance of _EnMAP_Detector_SensorGeo.
...
...
@@ -538,7 +539,7 @@ class EnMAPL1Product_SensorGeo(object):
self
.
vnir
=
EnMAP_VNIR_SensorGeo
(
root_dir
)
self
.
swir
=
EnMAP_SWIR_SensorGeo
(
root_dir
)
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'
]
def
get_paths
(
self
):
...
...
enpt/model/metadata.py
View file @
f5c9cd5b
# -*- coding: utf-8 -*-
"""EnPT metadata modules. All object and functions regarding EnMAP metadata are implemented here."""
from
datetime
import
datetime
from
xml.etree
import
ElementTree
...
...
@@ -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.
NOTE:
...
...
@@ -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.
Attributes:
...
...
@@ -160,28 +161,43 @@ class EnMAP_Metadata_SensorGeo(object):
"""
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
.
_path_xml
=
path_metaxml
# defaults
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
.
swir
=
None
# type: EnMAP_Metadata_SWIR_SensorGeo # metadata of SWIR only
self
.
vnir
=
None
# type: EnMAP_Metadata_
L1B_
VNIR_SensorGeo # metadata of VNIR only
self
.
swir
=
None
# type: EnMAP_Metadata_
L1B_
SWIR_SensorGeo # metadata of SWIR only
self
.
detector_attrNames
=
[
'vnir'
,
'swir'
]
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
self
.
observation_datetime
=
observation_time
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
.
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
.
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
)
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.
NOTE:
...
...
@@ -189,17 +205,27 @@ class EnMAP_Metadata_VNIR_SensorGeo(_EnMAP_Metadata_Detector_SensorGeo):
"""
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'
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
.
detector_label
=
L1B_product_props
[
'xml_detector_label'
][
'VNIR'
]
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
)
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.
NOTE:
...
...
@@ -207,8 +233,13 @@ class EnMAP_Metadata_SWIR_SensorGeo(_EnMAP_Metadata_Detector_SensorGeo):
"""
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'
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
.
detector_label
=
L1B_product_props
[
'xml_detector_label'
][
'SWIR'
]
...
...
@@ -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 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
)
enpt/utils/logging.py
View file @
f5c9cd5b
...
...
@@ -99,6 +99,14 @@ class EnPT_Logger(logging.Logger):
@
property
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
:
self
.
_captured_stream
=
self
.
streamObj
.
getvalue
()
...
...
@@ -110,6 +118,7 @@ class EnPT_Logger(logging.Logger):
self
.
_captured_stream
=
string
def
close
(
self
):
"""Close all logging handlers."""
# update captured_stream and flush stream
# self.captured_stream += self.streamObj.getvalue()
# print(self.handlers[:])
...
...
@@ -135,11 +144,16 @@ class EnPT_Logger(logging.Logger):
# print('sh', self.streamHandler)
def
view_logfile
(
self
):
"""View the log file written to disk."""
with
open
(
self
.
path_logfile
)
as
inF
:
print
(
inF
.
read
())
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'
):
for
handler
in
logger
.
handlers
[:]:
# if not called with '[:]' the StreamHandlers are left open
try
:
...
...
@@ -153,15 +167,33 @@ def close_logger(logger):
def
shutdown_loggers
():
"""Shutdown any currently active loggers."""
logging
.
shutdown
()
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
=
""
):
"""Get an instance of LessThanFilter.
:param exclusive_maximum: maximum log level, e.g., logger.WARNING
:param name:
"""
super
(
LessThanFilter
,
self
).
__init__
(
name
)
self
.
max_level
=
exclusive_maximum
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
return
True
if
record
.
levelno
<
self
.
max_level
else
False
setup.py
View file @
f5c9cd5b
...
...
@@ -17,7 +17,7 @@ test_requirements = ['coverage', 'nose', 'nose-htmloutput', 'rednose']
setup
(
name
=
'enpt'
,
version
=
'0.2.
4
'
,
version
=
'0.2.
5
'
,
description
=
"EnMAP PT"
,
long_description
=
readme
+
'
\n\n
'
+
history
,
author
=
"Karl Segl"
,
...
...
tests/linting/pydocstyle.log
View file @
f5c9cd5b
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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment