enpt.model.images package

Submodules

enpt.model.images.image_baseclasses module

EnPT EnMAP object base classes.

class enpt.model.images.image_baseclasses._EnMAP_Image[source]

Bases: object

EnPT base class for all kinds of EnMAP images.

NOTE:
  • Basic functionality that all EnMAP image objects have in common is to be implemented here.

  • All EnMAP image classes should (directly or indirectly) inherit from _EnMAP_image.

Attributes:
  • to be listed here. Check help(_EnMAP_image) in the meanwhile!

Load and hold data needed for processing EnMAP Level-1B data to Level-2A.

Intended usage:
  • only to be used as a base class to be inherited from!

  • Example:
    class EnMAP_Image_Subclass(_EnMAP_Image):
    def __init__(self):

    super(EnMAP_Image_Subclass, self).__init__()

_get_geoarray_with_datalike_geometry(geoArr_initArgs: tuple, attrName: str, nodataVal: int = None, specialclass=None) GeoArray | None[source]
property data: GeoArray

Return the actual EnMAP image data.

Bundled with all the corresponding metadata.

Attributes and functions (most important; for a full list check help(self.data)!):

  • ALL attributes of numpy.ndarray!

  • is_inmem(bool): True if the image data are completely loaded into memory; False if GeoArray only holds a link to a file on disk.

  • arr: np.ndarray holding the pixel values (if is_mem is True)

  • rows(int)

  • cols(int)

  • bands(int)

  • shape(tuple)

  • gt(list): GDAL geotransform: contains the geocoding

  • prj(str): WKT projection string

  • show(): plot the image

  • show_map(): plot a map of the image (based on cartopy library)

  • reproject_to_new_grid()

Usage (there will soon be detailed instructions on usage at https://git.gfz-potsdam.de/danschef/geoarray):

  • Use self.data like a normal numpy.ndarray!
    • NOTE: Operators like *, /, + , - will soon be implemented. In the meanwhile use:

      result = self.data[:] *10

  • How to set self.data?
    • Link an image file to self.data -> all raster data is read into memory ON DEMAND: self.data = ‘/path/to/image.tif’ # sets self.data to GeoArray(‘/path/to/image.tif’)

    • Link a numpy.ndarray instance with self.data (remaining attributes like geocoding, projection, etc.

      are copied from the previous self.data attribute). self.data = numpy.array([[1,2,3],[4,5,6]])

    • Set self.data to an existing instance of GeoArray

      (allows to set specific attributes of GeoArray by yourself) self.data = GeoArray(‘/path/to/image.tif’, geotransform=[…], projection=’WKTString’)

  • Delete self.data:

    del self.data or ‘self.data = None’

Returns:

instance of geoarray.GeoArray

property deadpixelmap: GeoArray

Return the dead pixel map.

Returns:

geoarray.GeoArray

property dem: GeoArray

Return a DEM in the exact dimension and pixel grid of self.data.

Returns:

geoarray.GeoArray

generate_quicklook(bands2use: List[int]) GeoArray[source]

Generate image quicklook and save into a file.

Parameters:

bands2use – band indices of self.data to be used as (red, green, blue) for quicklook image, e.g., [3, 2, 1]

Returns:

GeoArray

property mask_cirrus: GeoArray

Return the cirrus mask (0=none, 1=thin, 2=medium, 3=thick).

Returns:

geoarray.GeoArray

property mask_clouds: GeoArray

Return the cloud mask.

Returns:

geoarray.GeoArray

property mask_cloudshadow: GeoArray

Return the cloud shadow mask (0=no cloud shadow, 1=cloud shadow).

Returns:

geoarray.GeoArray

property mask_haze: GeoArray

Return the haze mask (0=no haze, 1=haze)..

Returns:

geoarray.GeoArray

property mask_landwater: GeoArray

Return the land/water mask.

pixel values: - 0: background within scene dimensions, e.g. due to missing values/errors - 1: no water - 2: water - 3: background outside the scene dimensions (artifact from resampling between map and sensor geometry)

Returns:

geoarray.GeoArray

property mask_snow: GeoArray

Return the snow mask (0=no snow, 1=snow).

Returns:

geoarray.GeoArray

property polymer_bitmask: GeoArray

Quality flags as generated by Polymer AC (bit-encoded mask).

Value 0 represents water, all fine, no flags. Other pixel values are explained below:

Flag name

Flag value

Description

LAND

1

Land mask

CLOUD_BASE

2

Polymer’s basic cloud mask

L1_INVALID

4

Invalid level1 pixel

NEGATIVE_BB

8

(deprecated flag)

OUT_OF_BOUNDS

16

Retrieved marine parameters are outside valid bounds

EXCEPTION

32

A processing error was encountered

THICK_AEROSOL

64

Thick aerosol flag

HIGH_AIR_MASS

128

Air mass exceeds 5

EXTERNAL_MASK

512

Pixel was masked using external mask

CASE2

1024

Pixel was processed in “case2” mode

INCONSISTENCY

2048

Inconsistent result was detected (atmospheric reflectance out of bounds)

ANOMALY_RWMOD_BLUE

4096

Excessive difference was found at 412nm between Rw and Rwmod

Returns:

geoarray.GeoArray

property polymer_logchl: GeoArray

Chlorophyll concentration, in mg/m3, in 10-based logarithm (generated by Polymer AC for water areas).

Data range: -3 to 2.3

Returns:

geoarray.GeoArray

property polymer_logfb: GeoArray

Particle scattering factor fb in Park & Ruddick (2005) (in 10-based logarithm; generated by Polymer AC).

Data range: positive and negative values, maximum range not defined

Returns:

geoarray.GeoArray

property polymer_rgli: GeoArray

Reflectance of the sun glint predicted from ECMWF wind speed (generated by Polymer AC for water areas).

Typical data range: 0-0.2

Returns:

geoarray.GeoArray

property polymer_rnir: GeoArray

TOA reflectance at 865 nm corrected for Rayleigh scattering (generated by Polymer AC for water areas).

Typical data range: 0-0.2

Returns:

geoarray.GeoArray

enpt.model.images.images_mapgeo module

EnPT EnMAP objects in map geometry.

class enpt.model.images.images_mapgeo.EnMAPL2Product_MapGeo(config: EnPTConfig, logger=None)[source]

Bases: _EnMAP_Image

Class for EnPT Level-2 EnMAP object in map geometry.

Attributes:
  • logger:
    • logging.Logger instance or subclass instance

  • paths:
    • paths belonging to the EnMAP product

  • meta:
    • instance of EnMAP_Metadata_SensorGeo class

Load and hold data needed for processing EnMAP Level-1B data to Level-2A.

Intended usage:
  • only to be used as a base class to be inherited from!

  • Example:
    class EnMAP_Image_Subclass(_EnMAP_Image):
    def __init__(self):

    super(EnMAP_Image_Subclass, self).__init__()

classmethod from_L1B_sensorgeo(config: EnPTConfig, enmap_ImageL1: EnMAPL1Product_SensorGeo)[source]
get_paths(l2a_outdir: str)[source]

Get all file paths associated with the current instance of EnMAP_Detector_SensorGeo.

NOTE: This information is read from the detector_meta.

Parameters:

l2a_outdir – output directory of EnMAP Level-2A dataset

Returns:

paths as SimpleNamespace

property log: str

Return a string of all logged messages until now.

NOTE: self.log can also be set to a string.

property logger: EnPT_Logger

Get an instance of enpt.utils.logging.EnPT_Logger.

NOTE:
  • The logging level will be set according to the user inputs of EnPT.

  • The path of the log file is directly derived from the attributes of the _EnMAP_Image instance.

Usage:
  • get the logger:

    logger = self.logger

  • set the logger

    self.logger = logging.getLogger() # NOTE: only instances of logging.Logger are allowed here

  • delete the logger:

    del self.logger # or “self.logger = None”

Returns:

EnPT_Logger instance

save(outdir: str, suffix='') str[source]

Save the product to disk using almost the same input format.

Parameters:
  • outdir – path to the output directory

  • suffix – suffix to be appended to the output filename (???)

Returns:

root path (root directory) where products were written

class enpt.model.images.images_mapgeo.EnMAP_Detector_MapGeo(detector_name: str, logger=None)[source]

Bases: _EnMAP_Image

Base class representing a single detector of an EnMAP image (as map geometry).

NOTE:
  • Inherits all attributes from _EnMAP_Image class.

  • All functionality that VNIR and SWIR detectors (map geometry) have in common is to be implemented here.

  • All EnMAP image subclasses representing a specific EnMAP detector (sensor geometry) should inherit from _EnMAP_Detector_SensorGeo.

Attributes:
  • to be listed here. Check help(_EnMAP_Detector_SensorGeo) in the meanwhile!

Get an instance of _EnMAP_Detector_MapGeo.

Parameters:
  • detector_name – ‘VNIR’ or ‘SWIR’

  • logger

calc_mask_nodata(fromBand=None, overwrite=False) GeoArray[source]

Calculate a no data mask with (values: 0=nodata; 1=data).

Parameters:
  • fromBand – <int> index of the band to be used (if None, all bands are used)

  • overwrite – <bool> whether to overwrite existing nodata mask that has already been calculated

Returns:

property mask_nodata: GeoArray

Return the no data mask.

Bundled with all the corresponding metadata.

For usage instructions and a list of attributes refer to help(self.data). self.mask_nodata works in the same way.

Returns:

instance of geoarray.NoDataMask

enpt.model.images.images_sensorgeo module

EnPT EnMAP objects in sensor geometry.

class enpt.model.images.images_sensorgeo.EnMAPL1Product_SensorGeo(root_dir: str, config: EnPTConfig, logger=None)[source]

Bases: object

Class for EnPT EnMAP object in sensor geometry.

Attributes:
  • logger:
    • logging.Logger instance or subclass instance

  • vnir
    • instance of EnMAP_VNIR_SensorGeo class

  • swir
    • instance of EnMAP_SWIR_SensorGeo class

  • paths:
    • paths belonging to the EnMAP product

  • meta:
    • instance of EnMAP_Metadata_SensorGeo class

  • detector_attrNames:
    • list of attribute names for VNIR and SWIR detectors,

Get instance of EnPT EnMAP object in sensor geometry.

Parameters:
  • root_dir – Root directory of EnMAP Level-1B product

  • config – EnPT configuration object

  • logger – None or logging instance to be appended to EnMAPL1Product_SensorGeo instance (If None, a default EnPT_Logger is used).

DN2TOARadiance()[source]

Convert self.vnir.data and self.swir.data from digital numbers to top-of-atmosphere radiance.

Returns:

None

append_new_image(root_dir, n_line_ext)[source]

Append a second EnMAP Level-1B product below the last line of the current L1B product.

NOTE: We create new files that will be saved into a temporary directory and their path will be stored in the

paths of self. We assume that the dead pixel map does not change between two adjacent images.

Parameters:
  • root_dir – root directory of EnMAP Level-1B product to be appended

  • n_line_ext – number of lines to be added from the new image

Returns:

calc_snr_from_radiance()[source]

Compute EnMAP SNR from radiance data.

SNR equation: SNR = p0 + p1 * LTOA + p2 * LTOA ^ 2 [W/(m^2 sr nm)].

correct_dead_pixels()[source]

Correct dead pixels of both detectors.

get_paths() SimpleNamespace[source]

Get all file paths associated with the current instance of EnMAPL1Product_SensorGeo.

Returns:

paths.SimpleNamespace()

get_preprocessed_dem()[source]
property log: str

Return a string of all logged messages until now.

NOTE: self.log can also be set to a string.

property logger: EnPT_Logger

Get a an instance of enpt.utils.logging.EnPT_Logger.

NOTE:
  • The logging level will be set according to the user inputs of EnPT.

  • The path of the log file is directly derived from the attributes of the _EnMAP_Image instance.

Usage:
  • get the logger:

    logger = self.logger

  • set the logger

    self.logger = logging.getLogger() # NOTE: only instances of logging.Logger are allowed here

  • delete the logger:

    del self.logger # or “self.logger = None”

Returns:

EnPT_Logger instance

run_AC()[source]
save(outdir: str, suffix='') str[source]

Save the product to disk using almost the same input format.

NOTE: Radiance is saved instead of DNs to avoid a radiometric jump between concatenated images.

Parameters:
  • outdir – path to the output directory

  • suffix – suffix to be appended to the output filename (???)

Returns:

root path (root directory) where products were written

set_SWIRattr_with_transformedVNIRattr(attrName: str, resamp_alg: str = 'nearest', respect_keystone: bool = False, src_nodata: int = None, tgt_nodata: int = None) None[source]

Set the specified SWIR raster attribute with a VNIR attribute transformed to SWIR sensor geometry.

Parameters:
  • attrName – name of the attribute to be set

  • resamp_alg – resampling algorithm (‘nearest’, ‘near’, ‘bilinear’, ‘cubic’, ‘cubic_spline’, ‘lanczos’, ‘average’, ‘mode’, ‘max’, ‘min’, ‘med’, ‘q1’, ‘q3’)

  • respect_keystone – whether to use the full geoarray (all bands) in case the attribute to be transformed is ‘data’ (default: False)

  • src_nodata – nodata value of the input array

  • tgt_nodata – pixel value to be used for undetermined pixels in the output

transform_swir_to_vnir_raster(array_swirsensorgeo: ndarray, resamp_alg: str = 'nearest', respect_keystone: bool = False, src_nodata: int = None, tgt_nodata: int = None) ndarray[source]

Transform the given array from SWIR into VNIR sensor geometry.

Parameters:
  • array_swirsensorgeo – raster array in SWIR sensor geometry to be transformed into VNIR sensor geometry

  • resamp_alg – resampling algorithm (‘nearest’, ‘near’, ‘bilinear’, ‘cubic’, ‘cubic_spline’, ‘lanczos’, ‘average’, ‘mode’, ‘max’, ‘min’, ‘med’, ‘q1’, ‘q3’)

  • respect_keystone – whether to use the full geoarray (all bands) in case a 3D array in the dimension of the VNIR detector is passed (default: False)

  • src_nodata – nodata value of the input array

  • tgt_nodata – pixel value to be used for undetermined pixels in the output

transform_vnir_to_swir_raster(array_vnirsensorgeo: ndarray, resamp_alg: str = 'nearest', respect_keystone: bool = False, src_nodata: int = None, tgt_nodata: int = None) ndarray[source]

Transform the given array from VNIR into SWIR sensor geometry.

Parameters:
  • array_vnirsensorgeo – raster array in VNIR sensor geometry to be transformed into SWIR sensor geometry

  • resamp_alg – resampling algorithm (‘nearest’, ‘near’, ‘bilinear’, ‘cubic’, ‘cubic_spline’, ‘lanczos’, ‘average’, ‘mode’, ‘max’, ‘min’, ‘med’, ‘q1’, ‘q3’)

  • respect_keystone – whether to use the full geoarray (all bands) in case a 3D array in the dimension of the VNIR detector is passed (default: False)

  • src_nodata – nodata value of the input array

  • tgt_nodata – pixel value to be used for undetermined pixels in the output

class enpt.model.images.images_sensorgeo.EnMAP_Detector_SensorGeo(detector_name: str, root_dir: str, config: EnPTConfig, logger=None, meta=None)[source]

Bases: _EnMAP_Image

Class representing a single detector of an EnMAP image (in sensor geometry).

NOTE:
  • Inherits all attributes from _EnMAP_Image class.

  • All functionality that VNIR and SWIR detectors (sensor geometry) have in common is to be implemented here.

Attributes:
  • to be listed here. Check help(_EnMAP_Detector_SensorGeo) in the meanwhile!

Get an instance of _EnMAP_Detector_SensorGeo.

Parameters:
  • detector_name – ‘VNIR’ or ‘SWIR’

  • root_dir

  • logger

  • meta – import meta if already loaded

DN2TOARadiance()[source]

Convert DNs to TOA radiance.

Convert the radiometric unit of _EnMAP_Detector_SensorGeo.data from digital numbers to top-of-atmosphere radiance.

Returns:

None

_transform_raster_geometry_from_other_detector(array: ndarray, src_lons: ndarray, src_lats: ndarray, src_epsg: int, resamp_alg: str = 'nearest', respect_keystone: bool = False, src_nodata: int = None, tgt_nodata: int = None) ndarray[source]

Transform the given input raster from VNIR to SWIR sensor geometry or vice-versa.

NOTE:

  • The transformation target is always the EnMAP_Detector_SensorGeo instance sensor geometry (e.g., VNIR sensorgeo if self.detector_name == ‘VNIR’).

  • In case a 3D array is given and the array has the exact dimensions of the source detector, the full geolayer is only used if ‘respect_keystone’ is set to True. This saves computation time for input arrays where the keystone uncertainty does not matter.

Parameters:
  • array – input array to be transformed (2- or 3-dimensional)

  • src_lons – geolayer longitudes corresponding to the input array (same nbands like the source detector)

  • src_lats – geolayer latitudes corresponding to the input array (same nbands like the source detector)

  • src_epsg – projection EPSG code of the source array

  • resamp_alg – resampling algorithm (‘nearest’, ‘near’, ‘bilinear’, ‘cubic’, ‘cubic_spline’, ‘lanczos’, ‘average’, ‘mode’, ‘max’, ‘min’, ‘med’, ‘q1’, ‘q3’)

  • respect_keystone – whether to use the full geoarray (all bands) in case a 3D array in the dimension of the source detector is passed (default: False)

  • src_nodata – nodata value of the input array

  • tgt_nodata – pixel value to be used for undetermined pixels in the output

Returns:

append_new_image(img2: EnMAP_Detector_SensorGeo, n_lines: int = None) None[source]

Check if a second image matches with the first image and if so, append the given number of lines below.

In this version we assume that the image will be added below. If it is the case, the method will create temporary files that will be used in the following.

Parameters:
  • img2

  • n_lines – number of lines to be added from the new image

Returns:

None

correct_dead_pixels()[source]

Correct dead pixels with respect to the dead pixel mask.

get_paths() SimpleNamespace[source]

Get all file paths associated with the current instance of EnMAP_Detector_SensorGeo.

NOTE: This information is read from the detector_meta.

Returns:

paths

get_preprocessed_dem() GeoArray[source]

Get a digital elevation model in EnMAP sensor geometry of the current detector.

save_raster_attributes(attrNames: List[str], outputDir: str)[source]

Save the specified raster attributes to the given output directory.

Parameters:
  • attrNames – list of attribute names to be saved

  • outputDir – output directory

class enpt.model.images.images_sensorgeo.EnMAP_SWIR_SensorGeo(root_dir: str, config: EnPTConfig, logger=None, meta=None)[source]

Bases: EnMAP_Detector_SensorGeo

Get an instance of _EnMAP_Detector_SensorGeo.

Parameters:
  • detector_name – ‘VNIR’ or ‘SWIR’

  • root_dir

  • logger

  • meta – import meta if already loaded

transform_vnir_to_swir_raster(array_vnirsensorgeo: ndarray, vnir_lons: ndarray, vnir_lats: ndarray, vnir_epsg: int, resamp_alg: str = 'nearest', respect_keystone: bool = False, src_nodata: int = None, tgt_nodata: int = None) ndarray[source]

Transform the given VNIR sensor-geometry raster array into SWIR sensor geometry.

Parameters:
  • array_vnirsensorgeo – source array in VNIR sensor geometry to be transformed

  • vnir_lons – longitude geolayer array of the VNIR

  • vnir_lats – latitude geolayer array of the VNIR

  • vnir_epsg – EPSG code of the VNIR when transformed to map geometry

  • resamp_alg – resampling algorith (‘nearest’, ‘near’, ‘bilinear’, ‘cubic’, ‘cubic_spline’, ‘lanczos’, ‘average’, ‘mode’, ‘max’, ‘min’, ‘med’, ‘q1’, ‘q3’)

  • respect_keystone – whether to use the full geoarray (all bands) in case a 3D array in the dimension of the VNIR detector is passed (default: False)

  • src_nodata – nodata value of the input array

  • tgt_nodata – pixel value to be used for undetermined pixels in the output

class enpt.model.images.images_sensorgeo.EnMAP_VNIR_SensorGeo(root_dir: str, config: EnPTConfig, logger=None, meta=None)[source]

Bases: EnMAP_Detector_SensorGeo

Get an instance of _EnMAP_Detector_SensorGeo.

Parameters:
  • detector_name – ‘VNIR’ or ‘SWIR’

  • root_dir

  • logger

  • meta – import meta if already loaded

read_masks()[source]

Read the L1B masks.

transform_swir_to_vnir_raster(array_swirsensorgeo: ndarray, swir_lons: ndarray, swir_lats: ndarray, swir_epsg: int, resamp_alg: str = 'nearest', respect_keystone: bool = False, src_nodata: int = None, tgt_nodata: int = None) ndarray[source]

Transform the given SWIR sensor-geometry raster array into VNIR sensor geometry.

Parameters:
  • array_swirsensorgeo – source array in SWIR sensor geometry to be transformed

  • swir_lons – longitude geolayer array of the SWIR

  • swir_lats – latitude geolayer array of the SWIR

  • swir_epsg – EPSG code of the SWIR when transformed to map geometry

  • resamp_alg – resampling algorith (‘nearest’, ‘near’, ‘bilinear’, ‘cubic’, ‘cubic_spline’, ‘lanczos’, ‘average’, ‘mode’, ‘max’, ‘min’, ‘med’, ‘q1’, ‘q3’)

  • respect_keystone – whether to use the full geoarray (all bands) in case a 3D array in the dimension of the SWIR detector is passed (default: False)

  • src_nodata – nodata value of the input array

  • tgt_nodata – pixel value to be used for undetermined pixels in the output

Module contents

EnPT images module. All EnMAP image objects are defined here.