diff --git a/enpt/execution/controller.py b/enpt/execution/controller.py index d8d051bf967e4296d0cb4bc7d43843d9eafa1e41..9466f54ecce8fc120a7614a6d2e64e63e5b6423a 100644 --- a/enpt/execution/controller.py +++ b/enpt/execution/controller.py @@ -81,7 +81,7 @@ class EnPT_Controller(object): def run_atmospheric_correction(self): """Run atmospheric correction only.""" - pass + self.L1_obj.run_AC() def write_output(self): if self.cfg.output_dir: diff --git a/enpt/model/images.py b/enpt/model/images.py index a6551ed3ed9c69f021903050759f2bbd7c8afd8a..1fc3b282d555b8edb158697081b03954e79dbec1 100644 --- a/enpt/model/images.py +++ b/enpt/model/images.py @@ -472,6 +472,11 @@ class EnMAPL1Product_SensorGeo(object): if self.swir.detector_meta.unitcode != 'TOARad': self.swir.DN2TOARadiance() + def run_AC(self): + from ..processors import AtmosphericCorrector + AC = AtmosphericCorrector(config=self.cfg) + AC.run_ac(self) + def save(self, outdir: str, suffix="") -> str: """Save this product to disk using almost the same format as for reading. diff --git a/enpt/processors/__init__.py b/enpt/processors/__init__.py index ffcaa00784346cb00d3c33f54ed70f5053727758..5ce1f347d7370a8350f3b231896af1bc4756e3c8 100644 --- a/enpt/processors/__init__.py +++ b/enpt/processors/__init__.py @@ -1,2 +1,10 @@ # -*- coding: utf-8 -*- """EnPT 'processors' module containing all EnPT processor sub-modules.""" + +from .radiometric_transform.radiometric_transform import Radiometric_Transformer +from .atmospheric_correction.atmospheric_correction import AtmosphericCorrector + +__all__ = [ + "Radiometric_Transformer", + "AtmosphericCorrector" +] diff --git a/enpt/processors/atmospheric_correction/__init__.py b/enpt/processors/atmospheric_correction/__init__.py index b6134021198291185cf0ebaf2fe443fd1592cdc9..a60f20ad0ac7d81326fe58ae1b34729d11c72187 100644 --- a/enpt/processors/atmospheric_correction/__init__.py +++ b/enpt/processors/atmospheric_correction/__init__.py @@ -1,2 +1,6 @@ # -*- coding: utf-8 -*- """EnPT 'atmospheric correction module.""" + +from .atmospheric_correction import AtmosphericCorrector + +__all__ = ['AtmosphericCorrector'] \ No newline at end of file diff --git a/enpt/processors/atmospheric_correction/atmospheric_correction.py b/enpt/processors/atmospheric_correction/atmospheric_correction.py index a55ee1726475bcf622563d18b194615ebc0ae5b1..803cc4de4aa8fa1cab698a1b5423b8a363493345 100644 --- a/enpt/processors/atmospheric_correction/atmospheric_correction.py +++ b/enpt/processors/atmospheric_correction/atmospheric_correction.py @@ -3,3 +3,37 @@ Performs the atmospheric correction of EnMAP L1B data. """ + +from sicor.sicor_enmap import sicor_ac_enmap +from sicor.options import get_options as get_ac_options + +from ...model.images import EnMAPL1Product_SensorGeo +from ...options.config import EnPTConfig +from ...utils.path_generator import get_path_ac_options + + +class AtmosphericCorrector(object): + """Class for performing atmospheric correction of EnMAP L1 images using SICOR.""" + + def __init__(self, config: EnPTConfig=None): + """Create an instance of AtmosphericCorrector.""" + self.cfg = config + + @property + def options(self): + path_opts = get_path_ac_options() + + try: + return get_ac_options(path_opts) + except FileNotFoundError: + raise FileNotFoundError('Could not locate options file for atmospheric correction at %s.' % path_opts) + + def run_ac(self, enmap_ImageL1: EnMAPL1Product_SensorGeo): + enmap_ImageL1.logger.info("Starting atmospheric correction for VNIR and SWIR detector. " + "Source radiometric unit code is '%s'." % enmap_ImageL1.meta.vnir.unitcode) + + # run AC + enmap_l2a_sens_geo, state, fits = sicor_ac_enmap(enmap_l1b=enmap_ImageL1, options=self.options, + logger=enmap_ImageL1.logger, debug=True) + + return enmap_l2a_sens_geo diff --git a/enpt/processors/radiometric_transform/__init__.py b/enpt/processors/radiometric_transform/__init__.py index c0335e5880e607742ecdce93364bc9b988b8b255..53c484986288ff340b4dd1564d52446024200cf2 100644 --- a/enpt/processors/radiometric_transform/__init__.py +++ b/enpt/processors/radiometric_transform/__init__.py @@ -1,6 +1,2 @@ # -*- coding: utf-8 -*- """EnPT 'radiometric transform' module containing eveything related to radiometric transformations.""" - -from .radiometric_transform import Radiometric_Transformer - -__all__ = ['Radiometric_Transformer'] diff --git a/enpt/utils/path_generator.py b/enpt/utils/path_generator.py index 0b8c6f009dfd5c51bbb43caf6a6f71f24da80354..ec3ed8513ba116adb3382314db902587be2583e9 100644 --- a/enpt/utils/path_generator.py +++ b/enpt/utils/path_generator.py @@ -48,3 +48,11 @@ class PathGenL1BProduct(object): def _find_in_metaxml(self, expression): return self.xml.findall(expression)[0].text.replace("\n", "").strip() + + +def get_path_ac_options() -> str: + """Returns the path of the options json file needed for atmospheric correction.""" + from sicor import options + path_ac = os.path.join(os.path.dirname(options.__file__), 'enmap_options.json') + + return path_ac diff --git a/tests/test_radiometric_transform.py b/tests/test_radiometric_transform.py index 61c8a0a9d532b5daa994ce4fbf65cdf5c760710b..ccf927008b426a532858252795fe002170e7b3b1 100644 --- a/tests/test_radiometric_transform.py +++ b/tests/test_radiometric_transform.py @@ -7,7 +7,7 @@ import tempfile import zipfile from datetime import datetime -from enpt.processors.radiometric_transform import Radiometric_Transformer +from enpt.processors import Radiometric_Transformer from enpt.options.config import EnPTConfig from . import config_for_testing