Coverage for enpt/utils/path_generator.py: 60%
30 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 path generator module for generating file paths for all kinds of EnMAP images."""
32from glob import glob
33import os
34from xml.etree import ElementTree
36from ..model.metadata import L1B_product_props
38__author__ = 'Daniel Scheffler'
41# NOTE:
42# paths belonging to providers L1B product are included in the *_header.xml file and read within metadata reader
45class PathGenL1BProduct(object):
46 """Path generator class for generating file pathes corresponding to the EnMAP L1B product."""
48 # TODO update this class
50 def __init__(self, root_dir: str, detector_name: str):
51 """Get an instance of the EnPT L1B image path generator.
53 :param root_dir:
54 :param detector_name:
55 """
56 self.root_dir = root_dir
57 assert len(os.listdir(self.root_dir)) > 0, 'Image root directory must contain files.'
59 self.detector_name = detector_name
60 self.detector_label = L1B_product_props['xml_detector_label'][detector_name]
61 self.detector_fn_suffix = L1B_product_props['fn_detector_suffix'][detector_name]
62 self.xml = ElementTree.parse(self.get_path_metaxml()).getroot()
64 def get_path_metaxml(self):
65 """Return the path of the metadata XML file."""
66 return glob(os.path.join(self.root_dir, "*_header.xml"))[0]
68 def get_path_data(self):
69 """Return the path of the image data file."""
70 return os.path.join(self.root_dir, self._find_in_metaxml("%s/filename" % self.detector_label))
72 def get_path_cloudmask(self):
73 """Return the path of the cloud mask file."""
74 # FIXME filename currently not included in XML
75 return glob(os.path.join(self.root_dir, "*_%s_cloudmask.tif" % self.detector_fn_suffix))[0]
77 def get_path_deadpixelmap(self):
78 """Return the path of the dead pixel mask file."""
79 return os.path.join(self.root_dir, self._find_in_metaxml("%s/dead_pixel_map/filename" % self.detector_label))
81 def get_path_quicklook(self):
82 """Return the path of the quicklook file."""
83 return os.path.join(self.root_dir, self._find_in_metaxml("%s/quicklook/filename" % self.detector_label))
85 def _find_in_metaxml(self, expression):
86 return self.xml.findall(expression)[0].text.replace("\n", "").strip()
89def get_path_ac_options() -> str:
90 """Return the path of the options json file needed for atmospheric correction."""
91 from sicor import options
92 path_ac = os.path.join(os.path.dirname(options.__file__), 'enmap_options.json')
93 # FIXME temporarily disabled because not implemented at the moment:
94 # path_ac = os.path.join(os.path.dirname(options.__file__), 'sicor_enmap_user_options.json')
96 return path_ac