Coverage for enpt/processors/radiometric_transform/radiometric_transform.py: 100%
22 statements
« prev ^ index » next coverage.py v7.4.1, created at 2024-03-07 11:39 +0000
« prev ^ index » next coverage.py v7.4.1, created at 2024-03-07 11:39 +0000
1# -*- coding: utf-8 -*-
3# EnPT, EnMAP Processing Tool - A Python package for pre-processing of EnMAP Level-1B data
4#
5# Copyright (C) 2018-2024 Karl Segl (GFZ Potsdam, segl@gfz-potsdam.de), Daniel Scheffler
6# (GFZ Potsdam, danschef@gfz-potsdam.de), Niklas Bohn (GFZ Potsdam, nbohn@gfz-potsdam.de),
7# Stéphane Guillaso (GFZ Potsdam, stephane.guillaso@gfz-potsdam.de)
8#
9# This software was developed within the context of the EnMAP project supported
10# by the DLR Space Administration with funds of the German Federal Ministry of
11# Economic Affairs and Energy (on the basis of a decision by the German Bundestag:
12# 50 EE 1529) and contributions from DLR, GFZ and OHB System AG.
13#
14# This program is free software: you can redistribute it and/or modify it under
15# the terms of the GNU General Public License as published by the Free Software
16# Foundation, either version 3 of the License, or (at your option) any later
17# version. Please note the following exception: `EnPT` depends on tqdm, which
18# is distributed under the Mozilla Public Licence (MPL) v2.0 except for the files
19# "tqdm/_tqdm.py", "setup.py", "README.rst", "MANIFEST.in" and ".gitignore".
20# Details can be found here: https://github.com/tqdm/tqdm/blob/master/LICENCE.
21#
22# This program is distributed in the hope that it will be useful, but WITHOUT
23# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
24# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
25# details.
26#
27# You should have received a copy of the GNU Lesser General Public License along
28# with this program. If not, see <https://www.gnu.org/licenses/>.
30"""EnPT 'radiometric transform' module.
32Contained Transformations:
33 - TOA radiance to TOA reflectance
34"""
36import math
37import numpy as np
39from ...model.images import EnMAPL1Product_SensorGeo, EnMAP_Detector_SensorGeo # noqa F401 # flake8 issue
40from ...options.config import EnPTConfig
42__author__ = 'Daniel Scheffler'
45class Radiometric_Transformer(object):
46 """Class for performing all kinds of radiometric transformations of EnMAP images."""
48 def __init__(self, config: EnPTConfig = None):
49 """Create an instance of Radiometric_Transformer.
51 :param config: EnPT configuration object
52 """
53 self.cfg = config
54 self.solarIrr = config.path_solar_irr # path of model for solar irradiance
55 self.earthSunDist = config.path_earthSunDist # path of model for earth sun distance
57 def transform_TOARad2TOARef(self, enmap_ImageL1: EnMAPL1Product_SensorGeo):
58 """Transform top-of-atmosphere radiance to top-of-atmosphere reflectance (16-bit signed-integer).
60 NOTE: The following formula is used:
61 toaRef = (scale_factor * math.pi * toaRad * earthSunDist**2) /
62 (solIrr * math.cos(zenithAngleDeg))
64 :param enmap_ImageL1: instance of the class 'EnMAPL1Product_ImGeo'
65 :return:
66 """
67 for detectorName in enmap_ImageL1.detector_attrNames:
68 detector: EnMAP_Detector_SensorGeo = getattr(enmap_ImageL1, detectorName)
70 enmap_ImageL1.logger.info('Converting TOA radiance to TOA reflectance for %s detector...'
71 % detector.detector_name)
73 # compute TOA reflectance
74 constant = \
75 self.cfg.scale_factor_toa_ref * math.pi * enmap_ImageL1.meta.earthSunDist ** 2 / \
76 (math.cos(math.radians(enmap_ImageL1.meta.geom_sun_zenith)))
77 solIrr = detector.detector_meta.solar_irrad.reshape(1, 1, detector.data.bands)
78 toaRef = (constant * detector.data[:] / solIrr).astype(np.int16)
80 # update EnMAP image
81 detector.data = toaRef
82 detector.detector_meta.unit = '0-%d' % self.cfg.scale_factor_toa_ref
83 detector.detector_meta.unitcode = 'TOARef'
85 return enmap_ImageL1