reader.py 2.47 KB
Newer Older
1
# -*- coding: utf-8 -*-
Daniel Scheffler's avatar
Daniel Scheffler committed
2
"""Reader module for reading all kinds of EnMAP images."""
3
4

from datetime import datetime
5
import logging
6

7
from ..model.images import EnMAPL1Product_SensorGeo
8
from ..model.metadata import EnMAP_Metadata_L1B_SensorGeo
9
10
11
12
13


class L1B_Reader(object):
    """Reader for EnMAP Level-1B products."""

14
    def __init__(self, logger=None, **user_inputs):
Daniel Scheffler's avatar
Daniel Scheffler committed
15
        """Get an instance of L1B_Reader."""
16
        self.logger = logger or logging.getLogger(__name__)
17
18
19
        self.cfg = user_inputs

    @staticmethod
20
    def read_inputdata(root_dir, observation_time: datetime, lon_lat_smpl=(15, 15), nsmile_coef=5):
21
        # TODO move to init?
Daniel Scheffler's avatar
Daniel Scheffler committed
22
        """Read L1B, DEM and spatial reference data.
23
24
25
26
27
28
29
30

        :param root_dir: Root directory of EnMAP Level-1B product
        :param observation_time: datetime of observation time (currently missing in metadata)
        :param lon_lat_smpl: number if sampling points in lon, lat fields
        :param nsmile_coef: number of polynomial coefficients for smile
        :return: instance of EnMAPL1Product_MapGeo
        """
        # get a new instance of EnMAPL1Product_MapGeo
31
        L1_obj = EnMAPL1Product_SensorGeo(root_dir)
32
33

        # read metadata
34
        L1_obj.meta = EnMAP_Metadata_L1B_SensorGeo(L1_obj.paths.metaxml)
Daniel Scheffler's avatar
Daniel Scheffler committed
35
        L1_obj.meta.read_metadata(observation_time=observation_time, lon_lat_smpl=lon_lat_smpl, nsmile_coef=nsmile_coef)
36
37
38

        # read VNIR data
        # call L1_obj.vnir.arr.setter which sets L1_obj.swir.arr to an instance of GeoArray class
39
        L1_obj.vnir.data = L1_obj.paths.vnir.imagedata
40
        L1_obj.vnir.mask_clouds = L1_obj.paths.vnir.mask_clouds
41
        L1_obj.vnir.deadpixelmap = L1_obj.paths.vnir.deadpixelmap
Daniel Scheffler's avatar
Bugfix    
Daniel Scheffler committed
42
        L1_obj.vnir.detector_meta = L1_obj.meta.vnir
43
44
45

        # read SWIR data
        # call L1_obj.swir.arr.setter which sets L1_obj.swir.arr to an instance of GeoArray class
46
        L1_obj.swir.data = L1_obj.paths.swir.imagedata
47
        L1_obj.swir.mask_clouds = L1_obj.paths.swir.mask_clouds
48
        L1_obj.swir.deadpixelmap = L1_obj.paths.swir.deadpixelmap
Daniel Scheffler's avatar
Bugfix    
Daniel Scheffler committed
49
        L1_obj.swir.detector_meta = L1_obj.meta.swir
50
51

        # compute radiance and calculate snr
52
        L1_obj.DN2TOARadiance()
Daniel Scheffler's avatar
Bugfix    
Daniel Scheffler committed
53
54
        L1_obj.vnir.detector_meta.calc_snr(data=L1_obj.vnir.data)
        L1_obj.swir.detector_meta.calc_snr(data=L1_obj.swir.data)
55
56
57
58

        return L1_obj

    def validate_input(self):
Daniel Scheffler's avatar
Daniel Scheffler committed
59
        """Validate user inputs."""
60
61
62
        pass

    def validate_output(self):
Daniel Scheffler's avatar
Daniel Scheffler committed
63
        """Validate outputs of L1B_Reader."""
64
        pass