Beispiel #1
0
    def generate_l1_toa_image(self, l2comm, factor, solzenith, L1ResolList,
                              working_dir):
        for l1res in range(len(L1ResolList)):
            curL1Res = L1ResolList[l1res]
            l_ListOfL1BandCode = self._plugin.BandsDefinitions.get_list_of_l1_band_code(
                curL1Res)

            for band in l_ListOfL1BandCode:
                curMULT = self._header_handler.get_ref_mutl_factor_from_band_code(
                    band)
                curADD = self._header_handler.get_ref_add_factor_from_band_code(
                    band)
                expression_bandmath = "(im2b1 || (im1b1-0.00001)<0)?" + str(
                    self._reall1nodata) + ":"
                if xml_tools.as_bool(l2comm.get_value("CalAdjustOption")):
                    expression_bandmath = expression_bandmath + str(
                        factor) + "*"
                expression_bandmath = expression_bandmath + "(im1b1*" + str(
                    curMULT) + "+" + str(curADD) + ")/cos(" + str(
                        solzenith) + "*" + str(math.pi / 180) + ")"

                img_toaconverter = os.path.join(
                    working_dir, "TOAConverter_{}.tif".format(band))
                app_bandmath = band_math([
                    self._header_handler.get_toa_image_filename_from_band_code(
                        band), self._qbmask
                ],
                                         expression_bandmath,
                                         img_toaconverter,
                                         write_output=False)
                self._toascalarlist.append(app_bandmath.getoutput().get("out"))
                self._toa_pipeline.add_otb_app(app_bandmath)
            img_concatenate_toa = os.path.join(working_dir,
                                               "l1toa_{}.tif".format(l1res))
            param_concatenate_toa = {
                "il": self._toascalarlist,
                "out": img_concatenate_toa
            }
            app_concatenate_toa = OtbAppHandler("ConcatenateDoubleImages",
                                                param_concatenate_toa,
                                                write_output=True)
            self._l1toaimagelist.append(app_concatenate_toa.getoutput()["out"])
            self._qb_pipeline.free_otb_app()
            self._toa_pipeline.free_otb_app()
    def run(self, dict_of_input, dict_of_output):
        LOGGER.info("Water vapor post processing Correction start")
        caching = dict_of_input.get("Params").get("Caching")
        wvpp_working = dict_of_input.get(
            "AppHandler").get_directory_manager().get_temporary_directory(
                "WaterVaporPPProc_", do_always_remove=True)
        vap_default = float(
            dict_of_input.get("L2COMM").get_value("WaterAmountDefaultValue"))
        bands_definition = dict_of_input.get("Plugin").BandsDefinitions
        l_nbRes = len(bands_definition.ListOfL2Resolution)
        # Does the user choose to compute the VAP image ? (GIP_L2COMM_UseDefaultConstantWaterAmount)
        l_UseDefaultConstantWaterAmount = False
        if not dict_of_input.get("Plugin").WaterVapourDetermination or as_bool(
                dict_of_input.get("L2COMM").get_value(
                    "GIP_L2COMM_UseDefaultConstantWaterAmount")):
            l_UseDefaultConstantWaterAmount = True

        vap_list = []
        vapmask_list = []
        if l_UseDefaultConstantWaterAmount:
            for r in range(0, l_nbRes):
                l_res = bands_definition.ListOfL2Resolution[r]
                vap_image_filename = os.path.join(wvpp_working,
                                                  "vap_" + l_res + ".tif")
                vap_mask_filename = os.path.join(
                    wvpp_working, "vapmask_" + l_res + ".tif:uint8")
                vap_image = constant_image(dict_of_input.get("DEM").ALTList[r],
                                           vap_default,
                                           vap_image_filename,
                                           write_output=False)
                self._l2_pipeline.add_otb_app(vap_image)
                dict_of_output["VAP_" + l_res] = vap_image.getoutput()["out"]
                vap_mask = constant_image(dict_of_input.get("DEM").ALTList[r],
                                          0,
                                          vap_mask_filename,
                                          write_output=False)
                self._l2_pipeline.add_otb_app(vap_mask)
                dict_of_output["VAPMASK_" +
                               l_res] = vap_mask.getoutput()["out"]
                vap_list.append(dict_of_output["VAP_" + l_res])
                vapmask_list.append(dict_of_output["VAPMASK_" + l_res])
        else:
            l_refbandcode = dict_of_input.get("L2COMM").get_value(
                "WaterVaporReferenceBandCode")
            l_bandcode = dict_of_input.get("L2COMM").get_value(
                "WaterVaporBandCode")
            vap_subimage_filename = os.path.join(wvpp_working, "vap_sub.tif")
            vap_submask_filename = os.path.join(wvpp_working,
                                                "vapmask_sub.tif")
            param_watervpp = {
                "tocr":
                dict_of_output["RayleighIPTOCR"],
                "vapin":
                dict_of_output["VAP_Sub"],
                "cldsum":
                dict_of_output[constants.CLOUD_MASK_ALL],
                "defaultwatervapor":
                vap_default,
                "threshold":
                dict_of_input.get("L2COMM").get_value_f(
                    "WaterVaporReflectanceThreshold"),
                "thresholdref":
                dict_of_input.get("L2COMM").get_value_f(
                    "WaterVaporReflectanceThresholdRef"),
                "referencebandcode":
                bands_definition.get_band_id_in_l2_coarse(l_refbandcode),
                "bandcode":
                bands_definition.get_band_id_in_l2_coarse(l_bandcode),
                "nodata":
                dict_of_input.get("L2COMM").get_value_f("VAPNodataValue"),
                "sevalidradius":
                dict_of_input.get("L2COMM").get_value_i(
                    "WaterVaporSEValidRadius"),
                "initwindowradius":
                dict_of_input.get("L2COMM").get_value_i(
                    "WaterVaporInitWindowRadius"),
                "maxwindowradius":
                dict_of_input.get("L2COMM").get_value_i(
                    "WaterVaporMaxWindowRadius"),
                "mask":
                vap_submask_filename + ":uint8",
                "vap":
                vap_subimage_filename
            }
            watervpp_app = OtbAppHandler("WaterVaporPostPro",
                                         param_watervpp,
                                         write_output=False)
            self._l2_pipeline.add_otb_app(watervpp_app)

            for r in range(0, l_nbRes):
                l_res = bands_definition.ListOfL2Resolution[r]
                vap_image_filename = os.path.join(wvpp_working,
                                                  "vap_" + l_res + ".tif")
                vap_mask_filename = os.path.join(wvpp_working,
                                                 "vapmask_" + l_res + ".tif")
                param_subresampling = {
                    "dtm": dict_of_input.get("DEM").ALTList[r],
                    "im": watervpp_app.getoutput()["vap"],
                    "interp": "linear",
                    "out": vap_image_filename
                }
                subresampling_app = OtbAppHandler("Resampling",
                                                  param_subresampling,
                                                  write_output=False)
                self._l2_pipeline.add_otb_app(subresampling_app)

                param_maskresampling = {
                    "dtm": dict_of_input.get("DEM").ALTList[r],
                    "im": watervpp_app.getoutput()["mask"],
                    "interp": "linear",
                    "out": vap_mask_filename + ":uint8",
                    "threshold": 0.25
                }
                maskresampling_app = OtbAppHandler("Resampling",
                                                   param_maskresampling,
                                                   write_output=False)
                self._l2_pipeline.add_otb_app(maskresampling_app)
                if is_croco_on("watervaporpostprocessing"):
                    write_images([
                        subresampling_app.getoutput()["out"],
                        maskresampling_app.getoutput()["out"]
                    ], [vap_image_filename, vap_mask_filename])
                    dict_of_output["VAP_" + l_res] = vap_image_filename
                    dict_of_output["VAPMASK_" + l_res] = vap_mask_filename
                else:
                    dict_of_output[
                        "VAP_" + l_res] = subresampling_app.getoutput()["out"]
                    dict_of_output[
                        "VAPMASK_" +
                        l_res] = maskresampling_app.getoutput()["out"]
                vap_list.append(dict_of_output["VAP_" + l_res])
                vapmask_list.append(dict_of_output["VAPMASK_" + l_res])
        dict_of_output["L2VAPList"] = vap_list
        dict_of_output["L2VAPMaskList"] = vapmask_list
Beispiel #3
0
    def read(self, product_info, app_handler, l2comm, dem, pReadL1Mode):
        """product_info,plugin, l2comm,mode

        :param product_info: L1ImageInformationsBase
        :param pReadL1Mode: ReadL1ModeType
        :return:
        """

        product_filename = product_info.HeaderFilename
        working_dir = app_handler.get_directory_manager(
        ).get_temporary_directory("L1Read_", do_always_remove=True)

        self._plugin.initialize(app_handler)
        self._GIPPL2COMMHandler = l2comm
        LOGGER.info("Start Sentinel2 L1 ImageFileReader ...")
        self._ReadL1Mode = pReadL1Mode
        self._dem = dem

        # --------------------------------------
        # Check the extension of th efile. For Muscate, must be .XML (in upper case)
        IsValidSatellite = (product_info.HeaderHandler is not None)
        if not IsValidSatellite:
            raise MajaPluginSentinel2Exception(
                "The file <{}> is not a valid Sentinel2 L1 product.".format(
                    product_filename))

        # Check the validity with the schema
        lSchemaLocationFile = os.path.join(
            app_handler.get_schemas_root_install_dir(),
            self._plugin.MAJA_INSTALL_SCHEMAS_L1PRODUCT_FILE)

        if app_handler.get_validate_schemas():
            # remplacer par un appel à pylint ? un check xml
            result = check_xml(product_filename, xsd_file=lSchemaLocationFile)
            if not result:
                raise MajaPluginSentinel2Exception(
                    "The xml file <{}> is not conform with its schema <{}> !, Log of execution :{}"
                    .format(product_filename, lSchemaLocationFile,
                            str(result)))

        # --------------------------------------
        # Load the header tile file in the xml tile handler to read tile information
        xmlTileFilename = product_info.xmlTileFilename

        # *******************************************************************************************************
        # TOA & masks Reader connection
        # *******************************************************************************************************
        l_BandsDefinitions = self._plugin.BandsDefinitions  # BandsDefinitions
        l_ListOfTOAImageFileNames = product_info.HeaderHandler.get_list_of_toa_images(
        )  # ListOfStrings
        l_SatPixFileNames = product_info.TileHandler.ListOfSaturatedPixelsHeaderFileName  # ListOfStrings
        l_DefectivPixFileNames = product_info.TileHandler.ListOfDefectivPixelsHeaderFileName  # ListOfStrings
        l_ZoneMaskFileNames = product_info.TileHandler.ListOfDetFootPrintHeaderFileName  # ListOfStrings
        l_NoDataMaskFileNames = product_info.TileHandler.ListOfNoDataPixelsHeaderFileName  # ListOfStrings
        l_ListOfTOABandCode = product_info.HeaderHandler.get_list_of_band_codes(
        )  # ListOfStrings
        l_ListOfL1Resolution = l_BandsDefinitions.ListOfL1Resolution  # ListOfStrings
        l_ListOfL2Resolution = l_BandsDefinitions.ListOfL2Resolution  # ListOfStrings
        l_NbL1Res = len(l_ListOfL1Resolution)  # int
        l_NbL2Res = len(l_ListOfL2Resolution)  # int
        l_NbBand = len(l_ListOfTOAImageFileNames)  # int
        # TODO: check ConfigUserCameraXMLFileHandler
        # TODO; check GetL2CoarseResolution grep L2CoarseResolution

        l_Areas = dem.L2Areas
        l_L2CoarseArea = dem.CoarseArea
        l_L2CoarseResolution = int(round(dem.CoarseArea.spacing[0]))
        LOGGER.debug(l_L2CoarseResolution)

        l_L1NoData = product_info.L1NoData
        l_ReflectanceQuantificationValue = product_info.ReflectanceQuantification
        l_RealL1NoData = l_L1NoData * l_ReflectanceQuantificationValue  # RealNoDataType

        if (len(l_ListOfTOABandCode) != len(l_ListOfTOAImageFileNames)) or (
                len(l_ListOfTOABandCode) != len(l_SatPixFileNames)) or (
                    len(l_ListOfTOABandCode) != len(l_DefectivPixFileNames)):
            raise MajaPluginSentinel2Exception(
                "Sentinel2L1ImageFileReader.CanRead: Internal error: The number of image file, sat file and band code are different !"
            )

        # =======> GENERATE TOA CACHING
        #
        # * Get calibration coeffs if activated

        l_reflectanceMultiplicationValues = []  # ListOfDoubles
        if xml_tools.as_bool(l2comm.get_value("CalAdjustOption")):
            l_factors = xml_tools.as_float_list(
                l2comm.get_value("CalAdjustFactor"))
            if len(l_factors) != len(l_ListOfTOABandCode):
                raise MajaPluginSentinel2Exception(
                    "Not the same number of Calibration coeffs than L1 bands ( {}, {} )"
                    .format(len(l_factors), len(l_ListOfTOABandCode)))
            for i in range(len(l_ListOfTOABandCode)):
                l_reflectanceMultiplicationValues.append(
                    l_ReflectanceQuantificationValue * l_factors[i])
        else:
            for i in range(len(l_ListOfTOABandCode)):
                l_reflectanceMultiplicationValues.append(
                    l_ReflectanceQuantificationValue)

        l_ProjectionRef = self._dem.ProjRef
        self.generate_toa(l_ListOfTOAImageFileNames,
                          l_reflectanceMultiplicationValues,
                          working_dir)  # string

        # ***********************************************************************************************************
        # Generate EDG at L2coarse and L2 resolutions
        # ***********************************************************************************************************
        self.generate_edg_images_from_toa(l_ListOfTOAImageFileNames,
                                          working_dir)

        # ***********************************************************************************************************
        # Get the bounding box of each L1 resolution
        # ***********************************************************************************************************
        # list of bounding box per resolution
        l_L1BoundingBoxMap = {}  # BoundingBoxMapType

        for res in range(l_NbL1Res):
            curRes = l_ListOfL1Resolution[res]  # string
            l_IntResolution = l_BandsDefinitions.get_l1_resolution(curRes)
            # Read the bounding box for the current resolution
            l_BoundingBox = product_info.TileHandler.get_geoposition_boundingbox(
                l_IntResolution)  # BoundingBoxType
            LOGGER.debug(
                "S2 Geoposition BoundingBox computed: xmin, ymin, xmax, ymax: %s, %s, %s, %s.",
                l_BoundingBox.xmin, l_BoundingBox.ymin, l_BoundingBox.xmax,
                l_BoundingBox.ymax)

            # Store the bounding box per resolution
            l_L1BoundingBoxMap[curRes] = l_BoundingBox

        # ***********************************************************************************************************
        # ***********************************************************************************************************
        # ***********************************************************************************************************
        #                                     START READ L1 for ALGORITHMS
        # ***********************************************************************************************************
        # ***********************************************************************************************************
        # ***********************************************************************************************************
        if pReadL1Mode == ReadL1Mode.READ_L1_MODE_FOR_ALGORITHMS:
            # --------------------------------------
            # Get information of areas (footprint) of the product (Origin, Spacing and Size for L2 and L2Coarse resolution)
            # --------------------------------------
            l_L2Dems = dem.ALTList
            l_CoarseDem = dem.ALC

            # ***********************************************************************************************************
            # Get the bounding box of each L1 resolution
            # ***********************************************************************************************************
            # list of bounding box per resolution
            l_L2CoarseBoundingBoxMap = {}  # BoundingBoxMapType

            for res in range(l_NbL1Res):
                curRes = l_ListOfL1Resolution[res]  # string
                l_IntResolution = l_BandsDefinitions.get_l1_resolution(curRes)
                l_PointXY = product_info.TileHandler.get_geoposition_upperleftcorner(
                    l_IntResolution)  # PointXYType
                l_L2CoarseBoundingBox = BoundingBox()
                # ATTENTION: For coordinates, cf. FD 73233
                l_L2CoarseBoundingBox.xmin = l_PointXY.x
                l_L2CoarseBoundingBox.ymin = l_PointXY.y - l_L2CoarseArea.size[
                    1] * l_L2CoarseResolution
                l_L2CoarseBoundingBox.xmax = l_PointXY.x + l_L2CoarseArea.size[
                    0] * l_L2CoarseResolution
                l_L2CoarseBoundingBox.ymax = l_PointXY.y

                l_L2CoarseBoundingBoxMap[curRes] = l_L2CoarseBoundingBox

            LOGGER.debug("Start SubSampling ...")

            # =======> GENERATE TOA SUB IMAGES AT L2 COARSE RESOLUTION
            self.generate_toa_sub_images(working_dir)

            LOGGER.debug("Start SubSampling done.")

            # *******************************************************************************************************
            # L2 TOA image pipeline connection
            # ******************* ************************************************************************************

            # =======> GENERATE L2 TOA IMAGES
            self.generate_l2_toa_images(working_dir)

            # *******************************************************************************************************
            # Rasterize the gml mask per L2 resolution per band
            # *******************************************************************************************************

            # =======> GENERATE MASK RASTERS
            self.generate_mask_rasters_gml(
                l_L1BoundingBoxMap, l_Areas, l_ProjectionRef,
                l_SatPixFileNames, l_DefectivPixFileNames, l_ZoneMaskFileNames,
                self._plugin.
                GDAL_RASTERIZE_GML_MASK_ADDITIONAL_COMMAND_LINE_PARAMETERS,
                self._plugin.
                GDAL_RASTERIZE_GML_DETECTOR_ADDITIONAL_COMMAND_LINE_PARAMETERS,
                working_dir)

            l_CurrentConfigUserCamera = self._plugin.ConfigUserCamera
            grid_ref_alt = l_CurrentConfigUserCamera.get_Algorithms(
            ).get_GRID_Reference_Altitudes()
            l_VIEHRef = grid_ref_alt.get_VIEHRef()  # double
            l_SOLH1 = grid_ref_alt.get_SOLH1()  # double

            # *******************************************************************************************************
            # IPSOL Sub image pipeline connection
            # *******************************************************************************************************
            LOGGER.debug("Start IPSOL SubSampling ...")
            l_solarAngleFile = product_info.TileHandler.angles.sun_angles.write(
                working_dir)

            # =======> GENERATE SOLAR ANGLE GRIDS
            self.get_solar_grids(self._dem.ALC, l_solarAngleFile, l_SOLH1,
                                 working_dir)

            LOGGER.debug("Start IPSOL SubSampling done.")

            # *******************************************************************************************************
            # IPVIE Sub image pipeline connection
            # *******************************************************************************************************
            LOGGER.debug("Start IPVIE SubSampling ...")

            LOGGER.debug("For each band ...")
            for l_band in range(l_NbBand):
                l_L1Resolution = l_BandsDefinitions.get_l1_resolution_for_band_code(
                    l_ListOfTOABandCode[l_band])  # string

                # Get the list of detectors (index)
                l_ListOfZone = product_info.TileHandler.get_list_of_zones(
                    l_band)  # ListOfUIntegers

                l_BoundingBox = l_L2CoarseBoundingBoxMap[
                    l_L1Resolution]  # BoundingBoxType

                # Get the list of viewing angles in the header file of the tile
                l_vieAngles = product_info.TileHandler.angles.viewing_incidence_angle.get_viewing_angles(
                    l_band)  # ListOfListOfStrings
                if len(l_vieAngles) == 0:
                    raise MajaPluginSentinel2Exception(
                        "No viewing angles for band " + str(l_band))
                # =======> GENERATE VIEWING ANGLE GRIDS
                self.get_viewing_grids(
                    l_band, l_L2CoarseArea, l_ProjectionRef, l_VIEHRef,
                    l_SatPixFileNames[l_band], l_ZoneMaskFileNames[l_band],
                    l_NoDataMaskFileNames[l_band], l_ListOfZone, l_BoundingBox,
                    l_vieAngles, self._plugin.
                    GDAL_RASTERIZE_GML_MASK_ADDITIONAL_COMMAND_LINE_PARAMETERS,
                    self._plugin.
                    GDAL_RASTERIZE_GML_DETECTOR_ADDITIONAL_COMMAND_LINE_PARAMETERS,
                    self._plugin.
                    GDAL_RASTERIZE_GML_NODATA_ADDITIONAL_COMMAND_LINE_PARAMETERS,
                    l_NbBand, working_dir)

            LOGGER.debug("Start IPVIE SubSampling done.")
            # To check mean angle values
            # TODO: TBD
            # zones = self.m_ViewingZenithMeanMap.keys()
            # values = zip(zones,
            #             [self.m_ViewingZenithMeanMap.get(zone) for zone in zones],
            #             [self.m_ViewingAzimuthMeanMap.get(zone) for zone in zones])
            # for zone, zenith, azimuth in values:
            #    LOGGER.debug(" Mean for zone %s is [zen;azi] : [%s;%s].", zone, zenith, azimuth)

            # *******************************************************************************************************
            # IPEDGSub and L2EDG pipeline connection
            # *******************************************************************************************************

            # *******************************************************************************************************
            # IPSAT Sub and L2SAT image pipeline connection
            # *******************************************************************************************************

            # =======> GENERATE SAT IMAGES
            self.generate_sat_images(working_dir)

            # *******************************************************************************************************
            # CLA image pipeline connection
            # *******************************************************************************************************

            # =======> GENERATE CLA IMAGES
            self.generate_cla_images(l_RealL1NoData, working_dir)

            # Fill the datas
            self.dict_of_vals["IPEDGSubOutput"] = self._edgsubmask
            self.dict_of_vals["SOL1Image"] = self._sol1image
            l_DTMBandCode = xml_tools.as_string_list(
                l2comm.get_value("DTMViewingDirectionBandCode"))[0]
            l_DTMBandIdx = self._plugin.BandsDefinitions.get_band_id_in_l2_coarse(
                l_DTMBandCode)
            LOGGER.info("DTMBandCode= " + l_DTMBandCode)
            self.dict_of_vals["DTMVIEImage"] = self._vieimagelist[l_DTMBandIdx]
            self.dict_of_vals["IPTOASubOutput"] = self._sub_toa
            self.dict_of_vals["L2TOAImageList"] = self._l2toaimagelist

            self.dict_of_vals["ViewingZenithMeanMap"] = self._meanZenithMap
            self.dict_of_vals["ViewingAzimuthMeanMap"] = self._meanAzimuthMap

            self.dict_of_vals["CLAImage"] = self._claimage

            self.dict_of_vals["IPSATSubOutput"] = self._subsatimage
            l_CLDBandCode = l2comm.get_value("CLDViewingDirectionBandCode")
            l_CLDBandIdx = self._plugin.BandsDefinitions.get_band_id_in_l2_coarse(
                l_CLDBandCode)
            self.dict_of_vals["ShadowVIEImage"] = self._vieimagelist[
                l_CLDBandIdx]
            l_CirrusBandCode = l2comm.get_value("CirrusBandCode")
            l_CirrusBandIdx = self._plugin.BandsDefinitions.get_band_id_in_l2_coarse(
                l_CirrusBandCode)

            self.dict_of_vals["L1TOACirrusImage"] = self._toa_scalar_list[
                l_CirrusBandIdx]

            self.dict_of_vals["AngleZoneMaskList"] = self._l2zoneimagelist
            self.dict_of_vals["L2EDGOutputList"] = self._l2edgmasklist
            self.dict_of_vals["L2SATImageList"] = self._l2satmasklist
            self.dict_of_vals["L2PIXImageList"] = self._l2piximagelist
    def read(self, product_info, app_handler, l2comm, dem, pReadL1Mode):
        """product_info,plugin, l2comm,mode

        :param product_info: L1ImageInformationsBase
        :param pReadL1Mode: ReadL1ModeType
        :return:
        """
        LOGGER.info("Start Sentinel2Muscate L1 ImageFileReader ...")
        product_filename = product_info.HeaderFilename
        LOGGER.info(
            "Start Sentinel2Muscate L1 ImageFileReader with filename : " +
            product_filename)
        working_dir = app_handler.get_directory_manager(
        ).get_temporary_directory("L1Read_", do_always_remove=True)
        self._plugin.initialize(app_handler)
        self._GIPPL2COMMHandler = l2comm
        LOGGER.info("Start Sentinel2Muscate L1 ImageFileReader ...")
        self._ReadL1Mode = pReadL1Mode
        self._dem = dem

        # --------------------------------------
        # Check the extension of th efile. For Muscate, must be .XML (in upper case)
        IsValidSatellite = (product_info.HeaderHandler is not None)
        if not IsValidSatellite:
            raise MajaExceptionPluginSentinel2Muscate(
                "The file <{}> is not a valid Sentinel2 L1 product.".format(
                    product_filename))
        self.m_headerHandler = product_info.HeaderHandler
        # Get satellite name
        self.m_Satellite = product_info.Satellite

        # --------------------------------------
        # Load the header tile file in the xml tile handler to read tile information
        xmlTileFilename = product_info.xmlTileFilename
        l_BandsDefinitions = self._plugin.BandsDefinitions  # BandsDefinitions

        # TOA & masks Reader connection
        l_ListOfTOAImageFileNames = product_info.HeaderHandler.get_list_of_toa_image_filenames(
        )
        l_SatPixFileNames = product_info.HeaderHandler.get_list_of_l1_sat_image_filenames(
        )
        l_DefectivPixFileNames = product_info.HeaderHandler.get_list_of_defective_pixel_image_filenames(
        )
        l_ZoneMaskFileNames = product_info.HeaderHandler.get_map_list_of_detector_footprint_image_filenames(
        )
        l_NoDataMaskFileNames = product_info.HeaderHandler.get_list_of_l1_ndt_image_filenames(
        )
        l_ListOfTOABandCode = product_info.HeaderHandler.get_list_of_band_code(
        )  # ListOfStrings
        l_NbBand = len(l_ListOfTOAImageFileNames)  # int
        l_L1NoData = product_info.L1NoData
        l_ReflectanceQuantificationValue = product_info.ReflectanceQuantification
        l_RealL1NoData = l_L1NoData * l_ReflectanceQuantificationValue  # RealNoDataType

        if (len(l_ListOfTOABandCode) != len(l_ListOfTOAImageFileNames)) or (
                len(l_ListOfTOABandCode) != len(l_SatPixFileNames)) or (
                    len(l_ListOfTOABandCode) != len(l_DefectivPixFileNames)):
            raise MajaExceptionPluginSentinel2Muscate(
                "Sentinel2L1ImageFileReader.CanRead: Internal error: The number of image file, sat file and band code are different !"
            )

        # =======> GENERATE TOA
        # Get calibration coeffs if activated
        l_reflectanceMultiplicationValues = []  # ListOfDoubles
        if xml_tools.as_bool(l2comm.get_value("CalAdjustOption")):
            l_factors = xml_tools.as_float_list(
                l2comm.get_value("CalAdjustFactor"))
            if len(l_factors) != len(l_ListOfTOABandCode):
                raise MajaDataException(
                    "Not the same number of Calibration coeffs than L1 bands ( {}, {} )"
                    .format(len(l_factors), len(l_ListOfTOABandCode)))
            for i in range(len(l_ListOfTOABandCode)):
                l_reflectanceMultiplicationValues.append(
                    l_ReflectanceQuantificationValue * l_factors[i])
        else:
            for i in range(len(l_ListOfTOABandCode)):
                l_reflectanceMultiplicationValues.append(
                    l_ReflectanceQuantificationValue)

        l_ProjectionRef = self._dem.ProjRef
        self.generate_toa(l_ListOfTOAImageFileNames,
                          l_reflectanceMultiplicationValues,
                          working_dir)  # string

        #                                     START READ L1 for ALGORITHMS
        if pReadL1Mode == ReadL1Mode.READ_L1_MODE_FOR_ALGORITHMS:
            # =======> GENERATE TOA SUB IMAGES AT L2 COARSE RESOLUTION
            LOGGER.debug("Start SubSampling ...")
            self.generate_toa_sub_images(working_dir)
            LOGGER.debug("Start SubSampling done.")
            #  the gml mask per L2 resolution per band
            self.generate_mask_rasters(l_SatPixFileNames,
                                       l_DefectivPixFileNames,
                                       l_ZoneMaskFileNames,
                                       l_NoDataMaskFileNames,
                                       l_ListOfTOABandCode, working_dir)

            LOGGER.debug("Filenames Mask Rasters : ")
            LOGGER.debug(l_SatPixFileNames)
            LOGGER.debug(l_DefectivPixFileNames)
            LOGGER.debug(l_ZoneMaskFileNames)
            LOGGER.debug(l_NoDataMaskFileNames)
            LOGGER.debug(l_ListOfTOABandCode)

            # Get the ref altitude
            l_CurrentConfigUserCamera = self._plugin.ConfigUserCamera
            grid_ref_alt = l_CurrentConfigUserCamera.get_Algorithms(
            ).get_GRID_Reference_Altitudes()
            l_VIEHRef = grid_ref_alt.get_VIEHRef()  # double
            l_SOLH1 = grid_ref_alt.get_SOLH1()  # double

            # IPSOL Sub image pipeline connection
            LOGGER.debug("Start IPSOL SubSampling ...")
            sun_angle_col_step = int(
                product_info.HeaderHandler.get_string_value_of(
                    "SunAngleColStep"))
            sun_angle_row_step = int(
                product_info.HeaderHandler.get_string_value_of(
                    "SunAngleRowStep"))
            # ATTENTION : * -1 for compatibility negative spacing
            LOGGER.debug(
                "Angle Resolution Spacing computed in 5000 resolution: " +
                str(sun_angle_col_step) + " , " + str(sun_angle_row_step))

            l_zenithSolarAngles = product_info.HeaderHandler.get_sun_zenithal_angles(
            )
            l_azimuthSolarAngles = product_info.HeaderHandler.get_sun_azimuthal_angles(
            )
            LOGGER.debug("ZenithSolarAngles nb values: " +
                         str(len(l_zenithSolarAngles)))
            LOGGER.debug("AzimuthSolarAngles nb values: " +
                         str(len(l_azimuthSolarAngles)))

            l_solarAngleFile = app_handler.get_directory_manager(
            ).get_temporary_file("sun_angles_") + ".xml"

            LOGGER.debug("Angles output_filename : %s", l_solarAngleFile)
            writer = MajaInternalXmlInputAngles(l_zenithSolarAngles,
                                                l_azimuthSolarAngles,
                                                sun_angle_col_step,
                                                sun_angle_row_step,
                                                l_solarAngleFile)
            writer.write()
            # =======> GENERATE SOLAR ANGLE GRIDS
            self.get_solar_grids(self._dem.ALC, l_solarAngleFile, l_SOLH1,
                                 working_dir)
            LOGGER.debug("Start IPSOL SubSampling done.")

            # IPVIE Sub image pipeline connection
            LOGGER.debug("Start IPVIE SubSampling ...")
            vie_angle_col_step = int(
                product_info.HeaderHandler.get_string_value_of(
                    "SunAngleColStep"))
            vie_angle_row_step = int(
                product_info.HeaderHandler.get_string_value_of(
                    "SunAngleRowStep"))
            LOGGER.debug("For each band ...")
            for l_band in l_ListOfTOABandCode:
                l1BandIdx = l_BandsDefinitions.get_band_id_in_l1(l_band)
                # Get the list of detectors (index)
                l_ListOfZone = product_info.HeaderHandler.get_list_of_zones(
                    l_band)
                # Get the list of viewing angles in the header file of the tile
                l_zenithVieAngles = product_info.HeaderHandler.get_viewing_zenithal_angles(
                    l_band)
                l_azimuthVieAngles = product_info.HeaderHandler.get_viewing_azimuthal_angles(
                    l_band)
                if len(l_zenithVieAngles) != len(l_azimuthVieAngles):
                    raise MajaExceptionPluginSentinel2Muscate(
                        "The number of detector for viewing zenithal angles and viewing azimuthal angles is different or null !"
                    )

                # =======> GENERATE VIEWING ANGLE GRIDS
                self.GetViewingGrids(l_band, l_NbBand, l_VIEHRef,
                                     l_SatPixFileNames[l1BandIdx],
                                     l_ZoneMaskFileNames[l1BandIdx],
                                     l_NoDataMaskFileNames[l1BandIdx],
                                     l_ListOfZone, vie_angle_col_step,
                                     vie_angle_row_step, l_zenithVieAngles,
                                     l_azimuthVieAngles, working_dir)

            # end loop nbBand

            LOGGER.debug("Start IPVIE SubSampling done.")

            # To check mean angle values
            # TODO

            # IPEDGSub and L2EDG pipeline connection
            # =======> GENERATE EDG IMAGES
            self.generate_edg_images(working_dir)
            # L2 TOA image pipeline connection
            # =======> GENERATE L2 TOA IMAGES
            self.generate_l2_toa_images(working_dir)
            # IPSAT Sub and L2SAT image pipeline connection
            # =======> GENERATE SAT IMAGES
            self.generate_sat_images(working_dir)
            # CLA image pipeline connection
            # =======> GENERATE CLA IMAGES
            self.generate_cla_images(l_RealL1NoData, working_dir)

            # Fill the datas
            self.dict_of_vals["IPEDGSubOutput"] = self._edgsubmask
            self.dict_of_vals["SOL1Image"] = self._sol1image
            l_DTMBandCode = xml_tools.as_string_list(
                l2comm.get_value("DTMViewingDirectionBandCode"))[0]
            l_DTMBandIdx = self._plugin.BandsDefinitions.get_band_id_in_l2_coarse(
                l_DTMBandCode)

            self.dict_of_vals["DTMVIEImage"] = self._vieimagelist[l_DTMBandIdx]

            LOGGER.debug("l_DTMBandIdx : ")
            LOGGER.debug(l_DTMBandIdx)
            self.dict_of_vals["IPTOASubOutput"] = self._sub_toa
            self.dict_of_vals["L2TOAImageList"] = self._l2toaimagelist

            self.dict_of_vals["ViewingZenithMeanMap"] = self._meanZenithMap
            self.dict_of_vals["ViewingAzimuthMeanMap"] = self._meanAzimuthMap

            self.dict_of_vals["CLAImage"] = self._claimage

            self.dict_of_vals["IPSATSubOutput"] = self._subsatimage
            l_CLDBandCode = l2comm.get_value("CLDViewingDirectionBandCode")
            l_CLDBandIdx = self._plugin.BandsDefinitions.get_band_id_in_l2_coarse(
                l_CLDBandCode)
            LOGGER.debug("l_CLDBandIdx: ")
            LOGGER.debug(l_CLDBandIdx)
            self.dict_of_vals["ShadowVIEImage"] = self._vieimagelist[
                l_CLDBandIdx]
            l_CirrusBandCode = l2comm.get_value("CirrusBandCode")
            l_CirrusBandIdx = self._plugin.BandsDefinitions.get_band_id_in_l2_coarse(
                l_CirrusBandCode)

            LOGGER.debug("l_CirrusBandIdx: ")
            LOGGER.debug(l_CirrusBandIdx)

            self.dict_of_vals["L1TOACirrusImage"] = self._toa_scalar_list[
                l_CirrusBandIdx]

            self.dict_of_vals["AngleZoneMaskList"] = self._l2zoneimagelist
            self.dict_of_vals["L2EDGOutputList"] = self._l2edgmasklist
            self.dict_of_vals["L2SATImageList"] = self._l2satmasklist
            self.dict_of_vals["L2PIXImageList"] = self._l2piximagelist
            self.dict_of_vals["L2DFPImageList"] = self._l2dfpimagelist
    def run(self, dict_of_input, dict_of_output):
        LOGGER.info("AthmosphericAbsorption start")
        atm_working = dict_of_input.get("AppHandler").get_directory_manager().get_temporary_directory("AtmoProc_",
                                            do_always_remove=True)
        l_writeL2 = dict_of_input.get("Params").get("WriteL2ProductToL2Resolution")
        bands_definition = dict_of_input.get("Plugin").BandsDefinitions
        # Get some datas

        pressure_image_sub = os.path.join(atm_working, "atmo_pressure_sub.tif")
        param_pressure = {"dtm": dict_of_input.get("DEM").ALC,
                          "pressure": pressure_image_sub}
        pressure_app_sub = OtbAppHandler("PressureFilter", param_pressure,
                                         write_output=True)
        self._coarse_pipeline.add_otb_app(pressure_app_sub)
        viewing_zenith = dict_of_input.get("L1Info").ListOfViewingZenithAnglesPerBandAtL2CoarseResolution
        water_amount_image_sub = os.path.join(atm_working, "atmo_wateramount_sub.tif")
        if dict_of_input.get("Plugin").WaterVapourDetermination and not as_bool(
           dict_of_input.get("L2COMM").get_value("GIP_L2COMM_UseDefaultConstantWaterAmount")):
            watervaporreferencebandid = bands_definition.get_band_id_in_l2_coarse(
                dict_of_input.get("L2COMM").get_value("WaterVaporReferenceBandCode"))
            watervaporbandid = bands_definition.get_band_id_in_l2_coarse(
                dict_of_input.get("L2COMM").get_value("WaterVaporBandCode"))

            viewing_zenith_vapor_band = float(viewing_zenith[watervaporbandid])
            param_watervapour = {"toa": dict_of_input.get("L1Reader").get_value("IPTOASubOutput"),
                                 "watervaporreferencebandid": watervaporreferencebandid,
                                 "watervaporbandid": watervaporbandid,
                                 "vapnodatavalue": float(dict_of_input.get("L2COMM").get_value("VAPNodataValue")),
                                 "watervapormaxthreshold": float(
                                     dict_of_input.get("L2COMM").get_value("WaterVaporMaxThreshold")),
                                 "solarzenith": float(dict_of_input.get("L1Info").SolarAngle["sun_zenith_angle"]),
                                 "viewingzenith": viewing_zenith_vapor_band,
                                 "wateramount": water_amount_image_sub,
                                 "gipwatv": dict_of_input.get("L2WATV").new_gipp_filename}
            water_vapour_app_sub = OtbAppHandler("WaterAmountGeneratorFilter", param_watervapour,
                                                 write_output=False)
            self._coarse_pipeline.add_otb_app(water_vapour_app_sub)
            dict_of_output["VAP_Sub"] = water_vapour_app_sub.getoutput()["wateramount"]

        toac_image_sub = os.path.join(atm_working, "atmo_toac_sub.tif")
        param_toa_correction = {"toa": dict_of_input.get("L1Reader").get_value("IPTOASubOutput"),
                                "pressure": pressure_app_sub.getoutput()["pressure"],
                                "smac": dict_of_input.get("L2SMAC").new_gipp_filename,
                                "wateramountdefault": float(
                                    dict_of_input.get("L2COMM").get_value("WaterAmountDefaultValue")),
                                "nodata": dict_of_input.get("Params").get("RealL2NoData"),
                                "ozoneamount": dict_of_input.get("Params").get("OzoneAmount"),
                                "thetas": float(dict_of_input.get("L1Info").SolarAngle["sun_zenith_angle"]),
                                "thetav": viewing_zenith,
                                "bandlist": bands_definition.get_list_of_band_id_in_l2_coarse(),
                                "toac": toac_image_sub}
        if (dict_of_input.get("Plugin").WaterVapourDetermination and
                dict_of_input.get("L2COMM").get_value("GIP_L2COMM_UseDefaultConstantWaterAmount")):
            param_toa_correction["wateramount"] = dict_of_output["VAP_Sub"]

        toa_correction_app_sub = OtbAppHandler("TOACorrection", param_toa_correction, write_output=l_writeL2)
        if not l_writeL2:
            self._coarse_pipeline.add_otb_app(toa_correction_app_sub)

        dict_of_output["AtmoAbsIPTOAC"] = toa_correction_app_sub.getoutput()["toac"]

        if dict_of_input.get("Params").get("WriteL2ProductToL2Resolution"):
            l_nbRes = len(bands_definition.ListOfL2Resolution)
            for r in range(0, l_nbRes):
                l_res = bands_definition.ListOfL2Resolution[r]
                pressure_image = os.path.join(atm_working, "atmo_pressure_" + l_res + ".tif")
                param_pressure["dtm"] = dict_of_input.get("DEM").ALTList[r]
                param_pressure["pressure"] = pressure_image
                pressure_app = OtbAppHandler("PressureFilter", param_pressure,write_output=False)
                self._l2_pipeline.add_otb_app(pressure_app)
                water_image = os.path.join(atm_working, "atmo_wateramount_" + l_res + ".tif")
                if (dict_of_input.get("Plugin").WaterVapourDetermination and
                        dict_of_input.get("L2COMM").get_value("GIP_L2COMM_UseDefaultConstantWaterAmount")):
                    param_resamp = {"dtm": dict_of_input.get("DEM").ALTList[r],
                                    "im": dict_of_output["VAP_Sub"],
                                    "interp": "linear",
                                    "padradius": 4.0,
                                    "out": water_image}
                    water_app = OtbAppHandler("Resampling", param_resamp, write_output=False)
                    self._l2_pipeline.add_otb_app(water_app)
                    param_toa_correction["wateramount"] = water_app.getoutput().get("out")
                toac_image = os.path.join(atm_working, "atmo_toa_" + l_res + ".tif")
                param_toa_correction["toa"] = dict_of_input.get("L1Reader").get_value("L2TOAImageList")[r]
                param_toa_correction["pressure"] = pressure_app.getoutput().get("pressure")
                band_list = bands_definition.get_list_of_l2_band_id(l_res)
                LOGGER.debug("Athmo band_list")
                LOGGER.debug(band_list)

                viewing_zenith_l2 = []
                band_list_l2 = []
                for i in band_list:
                    viewing_zenith_l2.append(viewing_zenith[i])
                    band_list_l2.append(str(i))
                param_toa_correction["bandlist"] = band_list_l2
                param_toa_correction["thetav"] = viewing_zenith_l2
                param_toa_correction["toac"] = toac_image
                toa_app = OtbAppHandler("TOACorrection", param_toa_correction,write_output=False)
                self._l2_pipeline.add_otb_app(toa_app)
                dict_of_output["AtmoAbsIPTOA_" + l_res] = toa_app.getoutput().get("toac")
                dict_of_output["L2TOA_" + l_res] = toa_app.getoutput().get("toac")
    def read(self, product_info, app_handler, l2comm, dem, pReadL1Mode):
        """product_info,plugin, l2comm,mode

        :param product_info: L1ImageInformationsBase
        :param pReadL1Mode: ReadL1ModeType
        :return:
        """
        LOGGER.info("Start Muscate L1 ImageFileReader ...")
        product_filename = product_info.HeaderFilename
        LOGGER.info("Start Muscate L1 ImageFileReader with filename : " +
                    product_filename)
        working_dir = app_handler.get_directory_manager(
        ).get_temporary_directory("L1Read_", do_always_remove=True)

        self._plugin.initialize(app_handler)
        self._GIPPL2COMMHandler = l2comm
        LOGGER.info("Start Muscate L1 ImageFileReader ...")
        self._ReadL1Mode = pReadL1Mode
        self._dem = dem
        self._header_handler = product_info.HeaderHandler
        # --------------------------------------
        # Check the extension of th efile. For Muscate, must be .XML (in upper case)
        IsValidSatellite = (self._header_handler is not None)
        if not IsValidSatellite:
            raise MajaExceptionPluginMuscate(
                "The file <{}> is not a valid Muscate L1 product.".format(
                    product_filename))
        # Get satellite name
        self.m_Satellite = product_info.Satellite

        # --------------------------------------
        # Load the header tile file in the xml tile handler to read tile information
        xmlTileFilename = product_info.xmlTileFilename
        l_BandsDefinitions = self._plugin.BandsDefinitions  # BandsDefinitions

        # TOA & masks Reader connection
        l_ListOfTOAImageFileNamesInHeader = self._header_handler.get_list_of_toa_image_filenames(
        )
        l_ListOfTOAImageFileNames = []
        l_ListOfTOABandCode = l_BandsDefinitions.get_list_of_band_code_in_l2_coarse_sorted_by_index(
        )  # ListOfStrings
        for band in l_ListOfTOABandCode:
            LOGGER.debug(band)
            l_ListOfTOAImageFileNames.append(l_ListOfTOAImageFileNamesInHeader[
                self._header_handler.get_index_of_band_code(band)])
        l_ListOfL1Resolution = l_BandsDefinitions.ListOfL1Resolution  # ListOfStrings
        l_ListOfL2Resolution = l_BandsDefinitions.ListOfL2Resolution  # ListOfStrings

        l_L1NoData = product_info.L1NoData
        l_ReflectanceQuantificationValue = product_info.ReflectanceQuantification
        l_RealL1NoData = l_L1NoData * l_ReflectanceQuantificationValue  # RealNoDataType

        # =======> GENERATE TOA
        # Get calibration coeffs if activated
        l_reflectanceMultiplicationValues = []  # ListOfDoubles
        if xml_tools.as_bool(l2comm.get_value("CalAdjustOption")):
            l_factors = xml_tools.as_float_list(
                l2comm.get_value("CalAdjustFactor"))
            if len(l_factors) != len(l_ListOfTOABandCode):
                raise MajaDataException(
                    "Not the same number of Calibration coeffs than L1 bands ( {}, {} )"
                    .format(len(l_factors), len(l_ListOfTOABandCode)))
            for i in range(len(l_ListOfTOABandCode)):
                l_reflectanceMultiplicationValues.append(
                    l_ReflectanceQuantificationValue * l_factors[i])
        else:
            for i in range(len(l_ListOfTOABandCode)):
                l_reflectanceMultiplicationValues.append(
                    l_ReflectanceQuantificationValue)

        l_ProjectionRef = self._dem.ProjRef
        self.generate_toa(l_ListOfTOAImageFileNames,
                          l_reflectanceMultiplicationValues,
                          working_dir)  # string
        if pReadL1Mode == ReadL1Mode.READ_L1_MODE_FOR_ALGORITHMS:
            # --------------------------------------
            # Get information of areas (footprint) of the product (Origin, Spacing and Size for L2 and L2Coarse resolution)
            l_L2Dems = dem.ALTList
            l_CoarseDem = dem.ALC

            # =======> GENERATE TOA SUB IMAGES AT L2 COARSE RESOLUTION
            LOGGER.debug("Start SubSampling ...")
            self.generate_toa_sub_images(working_dir)
            LOGGER.debug("Start SubSampling done.")
            #  the gml mask per L2 resolution per band
            self.generate_mask_rasters(l_ListOfTOABandCode, working_dir)
            # IPEDGSub and L2EDG pipeline connection
            # L2 TOA image pipeline connection
            # =======> GENERATE L2 TOA IMAGES
            self.generate_l2_toa_images(working_dir)
            # =======> GENERATE L1 TOA IMAGES
            self.generate_l1_toa_images(working_dir)
            # =======> GENERATE EDG IMAGES
            self.generate_edg_images(working_dir)
            # IPSAT Sub and L2SAT image pipeline connection
            # =======> GENERATE SAT IMAGES
            self.generate_sat_images(working_dir)
            # CLA image pipeline connection
            # *********************************************************************************************************
            self.generate_cla_image(l_RealL1NoData, working_dir)
            # SOL1 image pipeline connection
            # *********************************************************************************************************
            sol_h1 = self._plugin.ConfigUserCamera.get_Algorithms(
            ).get_GRID_Reference_Altitudes().get_SOLH1()
            LOGGER.debug("sol_H1 : ")
            LOGGER.debug(sol_h1)
            self.generate_sol1_image(sol_h1, working_dir)
            # SOL2 image pipeline connection
            # *********************************************************************************************************
            if self._plugin.GRIDReferenceAltitudesSOL2GridAvailable:
                sol_h2 = self._plugin.ConfigUserCamera.get_Algorithms(
                ).get_GRID_Reference_Altitudes().get_SOLH2()
                self.generate_sol2_image(sol_h2, working_dir)
            # VIE image pipeline connection
            # *********************************************************************************************************
            vie_href = self._plugin.ConfigUserCamera.get_Algorithms(
            ).get_GRID_Reference_Altitudes().get_VIEHRef()
            self.generate_vie_image(vie_href, working_dir)

            # Fill the datas
            self.dict_of_vals["IPEDGSubOutput"] = self._edgsubmask
            self.dict_of_vals["SOL1Image"] = self._sol1image
            self.dict_of_vals["SOL2Image"] = self._sol2image

            if len(self._vieimagelist) > 2:
                l_DTMBandCode = xml_tools.as_string_list(
                    l2comm.get_value("DTMViewingDirectionBandCode"))[0]
                l_DTMBandIdx = self._plugin.BandsDefinitions.get_band_id_in_l2_coarse(
                    l_DTMBandCode)
                LOGGER.info("DTMBandCode= " + l_DTMBandCode)

                self.dict_of_vals["DTMVIEImage"] = self._vieimagelist[
                    l_DTMBandIdx]
            else:
                self.dict_of_vals["DTMVIEImage"] = self._vieimagelist[0]
            self.dict_of_vals["IPTOASubOutput"] = self._sub_toa
            self.dict_of_vals["L2TOAImageList"] = self._l2toaimagelist
            self.dict_of_vals["ViewingZenithMeanMap"] = self._meanZenithMap
            self.dict_of_vals["ViewingAzimuthMeanMap"] = self._meanAzimuthMap
            self.dict_of_vals["CLAImage"] = self._claimage
            self.dict_of_vals["IPSATSubOutput"] = self._subsatimage
            if len(self._vieimagelist) > 2:
                l_CLDBandCode = l2comm.get_value("CLDViewingDirectionBandCode")
                l_CLDBandIdx = self._plugin.BandsDefinitions.get_band_id_in_l2_coarse(
                    l_CLDBandCode)
                self.dict_of_vals["ShadowVIEImage"] = self._vieimagelist[
                    l_CLDBandIdx]
            elif len(self._vieimagelist) > 1:
                self.dict_of_vals["ShadowVIEImage"] = self._vieimagelist[1]
            else:
                self.dict_of_vals["ShadowVIEImage"] = self._vieimagelist[0]
            if self._plugin.CirrusMasking:
                l_CirrusBandCode = l2comm.get_value("CirrusBandCode")
                l_CirrusBandIdx = self._plugin.BandsDefinitions.get_band_id_in_l2_coarse(
                    l_CirrusBandCode)
                self.dict_of_vals["L1TOACirrusImage"] = self._toa_scalar_list[
                    l_CirrusBandIdx]
            self.dict_of_vals["L2EDGOutputList"] = self._l2edgmasklist
            self.dict_of_vals["L2SATImageList"] = self._l2satmasklist
            self.dict_of_vals["L2PIXImageList"] = self._l2dfpimagelist
    def read(self, product_info, app_handler, l2comm, dem, pReadL1Mode):
        """product_info,plugin, l2comm,mode

        :param product_info: L1ImageInformationsBase
        :param pReadL1Mode: ReadL1ModeType
        :return:
        """
        LOGGER.debug("Start Venus L1 ImageFileReader ...")
        product_filename = product_info.HeaderFilename
        LOGGER.debug("Start Venus L1 ImageFileReader with the filename: " +
                     product_filename)
        self._plugin.initialize(app_handler)
        self.headerHandler = product_info.HeaderHandler
        self._dem = dem
        # working_dir = get_working_directory("L1Read_", app_handler.get_working_directory())
        working_dir = app_handler.get_directory_manager(
        ).get_temporary_directory("L1Read_", do_always_remove=True)
        self.ReadL1Mode = pReadL1Mode
        self._GIPPL2COMMHandler = l2comm
        l_BandsDefinitions = self._plugin.BandsDefinitions
        # --------------------------------------
        # Initialize the Image filename provider
        l_FilenameProvider = VenusL1ImageFilenames()
        #product_info.FilenamesProvider
        IsValidSatellite = (l_FilenameProvider.initialize(product_filename)
                            is not False)
        if not IsValidSatellite:
            raise MajaPluginVenusException(
                "The file <{}> is not a valid Venus L1 product.".format(
                    product_filename))

        # *********************************************************************************************************
        # Register the Header o the Input image file
        # *********************************************************************************************************
        LOGGER.debug("Load the Venus L1 Header file : '" + product_filename +
                     "'")
        l_L1XMLHandler = HeaderImageEarthExplorerXMLFileHandler(
            product_filename)

        # *********************************************************************************************************
        # TOA Reader connection
        # *********************************************************************************************************
        l_L1NoData = l_L1XMLHandler.get_no_data_value_as_double()
        l_ReflectanceQuantificationValue = l_L1XMLHandler.get_reflectance_quantification_value(
        )
        l_reflectanceMultiplicationValues = []

        if xml_tools.as_bool(l2comm.get_value("CalAdjustOption")):
            l_factor = xml_tools.as_float_list(
                l2comm.get_value("CalAdjustFactor"))
            if len(l_factor) != (VenusL1ImageFileReader.TOALastChannel -
                                 VenusL1ImageFileReader.TOAFirstChannel + 1):
                raise MajaPluginVenusException(
                    "Not the same number of Calibration coeffs than L1 bands")
            for i in range(0, len(l_factor)):
                l_reflectanceMultiplicationValues.append(
                    l_ReflectanceQuantificationValue * l_factor[i])
        else:
            for i in range(VenusL1ImageFileReader.TOALastChannel -
                           VenusL1ImageFileReader.TOAFirstChannel + 1):
                l_reflectanceMultiplicationValues.append(
                    l_ReflectanceQuantificationValue)

        l_RealL1NoData = l_L1NoData * l_ReflectanceQuantificationValue

        # *********************************************************************************************************
        # L1 TOA image pipeline connection
        # *********************************************************************************************************
        if not l_FilenameProvider.m_TOAImageFileName:
            raise MajaPluginVenusException(
                "VenusL1ImageFileReader : The TOA image does not exist !")

        tmp_l1toa_roi = os.path.join(working_dir, "l1toa_roi.tif")
        app_l1_toa_roi = extract_roi(l_FilenameProvider.m_TOAImageFileName, [
            channel
            for channel in range(VenusL1ImageFileReader.TOALastChannel -
                                 VenusL1ImageFileReader.TOAFirstChannel + 1)
        ],
                                     tmp_l1toa_roi,
                                     write_output=False)
        self._l1toa_pipeline.add_otb_app(app_l1_toa_roi)

        tmp_sat_roi = os.path.join(working_dir, "sat_roi.tif")
        app_sat_roi = extract_roi(l_FilenameProvider.m_TOAImageFileName,
                                  [VenusL1ImageFileReader.SATChannel - 1],
                                  tmp_sat_roi,
                                  write_output=False)
        self._sat_pipeline.add_otb_app(app_sat_roi)
        #Multiply scalar by quantif
        tmp_l1toa_mbs = os.path.join(working_dir, "l1toa.tif")
        app_l1toa_mbs = multiply_by_scalar(
            app_l1_toa_roi.getoutput().get("out"),
            l_ReflectanceQuantificationValue,
            output_image=tmp_l1toa_mbs,
            write_output=False)
        self._l1toa_pipeline.add_otb_app(app_l1toa_mbs)
        # update all extract ROI in once
        write_images([
            app_l1toa_mbs.getoutput().get("out"),
            app_sat_roi.getoutput().get("out")
        ], [tmp_l1toa_mbs, tmp_sat_roi])

        self._toascalar = tmp_l1toa_mbs

        # *********************************************************************************************************
        # L1 PIX image pipeline connection
        # *********************************************************************************************************
        tmp_l1pix_roi = os.path.join(working_dir, "l1pix.tif")
        app_l1_pix_roi = extract_roi(l_FilenameProvider.m_TOAImageFileName,
                                     [VenusL1ImageFileReader.PIXChannel - 1],
                                     tmp_l1pix_roi + ":uint16",
                                     write_output=False)
        self._l1pix_pipeline.add_otb_app(app_l1_pix_roi)
        self._l1pix = app_l1_pix_roi.getoutput().get("out")

        # *********************************************************************************************************
        #                                     START READ L1 for ALGORITHMS
        # *********************************************************************************************************
        if pReadL1Mode == ReadL1Mode.READ_L1_MODE_FOR_ALGORITHMS:
            # *********************************************************************************************************
            # L2 PIX image pipeline connection
            # *********************************************************************************************************
            # LAIG-FA-MAC-131720-CS : New for 4.2
            # Before resample, binarytovector -> resample -> vectortobinary
            tmp_l2pix_bin2vec = os.path.join(working_dir, "l2pix_bin2vec.tif")
            param_l2pix_bin2vec = {
                "im": app_l1_pix_roi.getoutput().get("out"),
                "out": tmp_l2pix_bin2vec + ":uint8",
                "nbcomp": VenusL1ImageFileReader.PIXNumberOfComponentsPerPixel
            }
            app_l2pix_bin2vec = OtbAppHandler("BinaryToVector",
                                              param_l2pix_bin2vec,
                                              write_output=False)
            self._l2pix_pipeline.add_otb_app(app_l2pix_bin2vec)

            tmp_l2pix_resample = os.path.join(working_dir,
                                              "l2pix_resample.tif")
            app_l2pix_resample = resample(
                app_l2pix_bin2vec.getoutput().get("out"),
                self._dem.ALTList[0],
                tmp_l2pix_resample,
                OtbResampleType.LINEAR_WITH_RADIUS,
                padradius=4.0,
                threshold=0.0,
                write_output=False)
            self._l2pix_pipeline.add_otb_app(app_l2pix_resample)
            #L2 PIX is concatenate
            tmp_l2pix_binconcat = os.path.join(working_dir, "l2pix.tif")
            param_l2pix_binconcat = {
                "im": app_l2pix_resample.getoutput().get("out"),
                "out": tmp_l2pix_binconcat + ":uint16"
            }
            app_l2pix_binconcat = OtbAppHandler("BinaryConcatenate",
                                                param_l2pix_binconcat,
                                                write_output=False)
            self._l2pix = app_l2pix_binconcat.getoutput().get("out")
            self._l2pix_pipeline.add_otb_app(app_l2pix_binconcat)

            # *********************************************************************************************************
            # L2 EDG image pipeline connection
            # *********************************************************************************************************
            tmp_edg_thresholder = os.path.join(working_dir,
                                               "edg_thresholder1.tif")
            param_edg_thresholder1 = {
                "im": self._toascalar,
                "thresholdvalue": l_RealL1NoData,
                "equalvalue": 255,
                "outsidevalue": 0,
                "out": tmp_edg_thresholder + ":uint8"
            }
            app_edg_thresholder1 = OtbAppHandler("OneBandEqualThreshold",
                                                 param_edg_thresholder1,
                                                 write_output=True)
            self._edg_pipeline.add_otb_app(app_edg_thresholder1)

            tmp_edg_resample = os.path.join(working_dir, "edg_resample.tif")
            app_edg_resample = resample(
                app_edg_thresholder1.getoutput().get("out"),
                self._dem.ALTList[0],
                tmp_edg_resample,
                OtbResampleType.BCO,
                padradius=4.0,
                write_output=True)
            self._edg_pipeline.add_otb_app(app_edg_resample)

            # Threshold the output
            out_sub_edg = os.path.join(working_dir, "edg_thresholder2.tif")
            param_edg_thresholder2 = {
                "im": app_edg_resample.getoutput().get("out"),
                "thresholdvalue": 0,
                "equalvalue": 1,
                "outsidevalue": 0,
                "out": out_sub_edg + ":uint8"
            }
            app_edg_thresholder2 = OtbAppHandler("OneBandEqualThreshold",
                                                 param_edg_thresholder2,
                                                 write_output=True)
            self._edg_pipeline.add_otb_app(app_edg_thresholder2)

            # *********************************************************************************************************
            # IPEDGSub image pipeline connection
            # *********************************************************************************************************
            tmp_edgsub_resample = os.path.join(working_dir,
                                               "edgsub_resample.tif")
            app_edgsub_resample = resample(
                app_edg_thresholder1.getoutput().get("out"),
                self._dem.ALC,
                tmp_edgsub_resample,
                OtbResampleType.LINEAR_WITH_RADIUS,
                padradius=12.0,
                write_output=True)
            self._edg_pipeline.add_otb_app(app_edgsub_resample)
            # Threshold the output
            out_sub_edgsub = os.path.join(working_dir, "edgsub.tif")
            param_edgsub_thresholder2 = {
                "im": app_edgsub_resample.getoutput().get("out"),
                "thresholdvalue": 0,
                "equalvalue": 0,
                "outsidevalue": 1,
                "out": out_sub_edgsub + ":uint8"
            }
            app_edgsub_thresholder2 = OtbAppHandler("OneBandEqualThreshold",
                                                    param_edgsub_thresholder2,
                                                    write_output=True)
            self._edgsub = app_edgsub_thresholder2.getoutput().get("out")
            self._edg_pipeline.add_otb_app(app_edgsub_thresholder2)

            # *********************************************************************************************************
            # L2 TOA image pipeline connection
            # *********************************************************************************************************
            tmp_l2toa_resample = os.path.join(working_dir,
                                              "l2toa_resample.tif")
            app_l2toa_resample = resample(self._toascalar,
                                          self._dem.ALTList[0],
                                          tmp_l2toa_resample,
                                          OtbResampleType.BCO,
                                          padradius=4.0,
                                          write_output=False)
            self._l2toa_pipeline.add_otb_app(app_l2toa_resample)
            l2toa_list = []
            l_toathresholdminvalue = 0
            l_toathresholvalue = -10

            #Apply EDG mask on l2toa resampled
            tmp_l2toa = os.path.join(working_dir, "l2toa.tif")
            app_l2toa = apply_mask(app_l2toa_resample.getoutput().get("out"),
                                   app_edg_thresholder2.getoutput().get("out"),
                                   l_toathresholvalue,
                                   tmp_l2toa,
                                   write_output=False)
            self._l2toa = app_l2toa.getoutput().get("out")
            self._l2toa_pipeline.add_otb_app(app_l2toa)

            # *********************************************************************************************************
            # TOA Sub image pipeline connection
            # *********************************************************************************************************
            tmp_toasub_resample = os.path.join(working_dir,
                                               "toasub_resample.tif")
            app_toasub_resample = resample(self._toascalar,
                                           self._dem.ALC,
                                           tmp_toasub_resample,
                                           OtbResampleType.LINEAR_WITH_RADIUS,
                                           padradius=4.0,
                                           write_output=True)
            self._l2toa_pipeline.add_otb_app(app_toasub_resample)

            # Threshold the output
            out_edgsub_threshold = os.path.join(working_dir,
                                                "edgsubthreshold.tif")
            param_edgsub_threshold = {
                "im": app_edgsub_resample.getoutput().get("out"),
                "thresholdvalue": 0,
                "equalvalue": 1,
                "outsidevalue": 0,
                "out": out_edgsub_threshold + ":uint8"
            }
            app_edgsub_threshold = OtbAppHandler("OneBandEqualThreshold",
                                                 param_edgsub_threshold,
                                                 write_output=True)
            self._edg_pipeline.add_otb_app(app_edgsub_threshold)

            tmp_l2subtoa = os.path.join(working_dir, "toasub.tif")
            app_l2subtoa = apply_mask(
                app_toasub_resample.getoutput().get("out"),
                app_edgsub_threshold.getoutput().get("out"),
                l_toathresholvalue,
                tmp_l2subtoa,
                write_output=True)
            self._toasub = app_l2subtoa.getoutput().get("out")
            self._l2toa_pipeline.add_otb_app(app_l2subtoa)

            # *********************************************************************************************************
            # L2EDG - Actualization of the L2 edge mask
            # *********************************************************************************************************
            #tmp_l2edg_threshold = os.path.join(working_dir, "l2edg_threshold.tif")
            #app_l2edg_threshold = binary_threshold(self._edgsub,
            #                                         lower_threshold=0,
            #                                         inside_value=1000,
            #                                         outside_value=0,
            #                                         output_image=tmp_l2edg_threshold + ":uint8",
            #                                         write_output=True)
            #self._l2edg_pipeline.add_otb_app(app_l2edg_threshold)
            tmp_l2edg_resample = os.path.join(working_dir, "l2edg.tif")
            app_l2edg_resample = resample(self._edgsub,
                                          self._dem.ALTList[0],
                                          tmp_l2edg_resample + ":uint8",
                                          OtbResampleType.LINEAR,
                                          padradius=4.0,
                                          threshold=0.001,
                                          write_output=True)
            self._l2edg = app_l2edg_resample.getoutput().get("out")
            self._l2edg_pipeline.add_otb_app(app_l2edg_resample)

            # *********************************************************************************************************
            # SAT image pipeline connection
            # *********************************************************************************************************
            tmp_sat_bin2vec = os.path.join(working_dir, "sat_bin2vec.tif")
            param_sat_bin2vec = {
                "im": tmp_sat_roi,
                "out": tmp_sat_bin2vec + ":uint8",
                "nbcomp": VenusL1ImageFileReader.SATNumberOfComponentsPerPixel
            }
            app_sat_bin2vec = OtbAppHandler("BinaryToVector",
                                            param_sat_bin2vec,
                                            write_output=False)
            self._sat_pipeline.add_otb_app(app_sat_bin2vec)

            l_l2sat_thresholdvalue = l2comm.get_value_f("SaturationThreshold")

            tmp_sat_resample = os.path.join(working_dir, "l2sat.tif")
            app_sat_resample = resample(app_sat_bin2vec.getoutput().get("out"),
                                        self._dem.ALTList[0],
                                        tmp_sat_resample + ":uint8",
                                        OtbResampleType.BCO,
                                        padradius=4.0,
                                        threshold=l_l2sat_thresholdvalue,
                                        write_output=False)
            self._l2sat = app_sat_resample.getoutput().get("out")
            self._sat_pipeline.add_otb_app(app_sat_resample)

            # *********************************************************************************************************
            # IPSAT Sub image pipeline connection
            # *********************************************************************************************************
            l_sat_subthresholdvalue = l2comm.get_value_f(
                "SaturationThresholdSub")
            tmp_satsub_resample = os.path.join(working_dir, "satsub.tif")
            app_satsub_resample = resample(
                app_sat_bin2vec.getoutput().get("out"),
                self._dem.ALC,
                tmp_satsub_resample + ":uint8",
                OtbResampleType.LINEAR_WITH_RADIUS,
                padradius=4.0,
                threshold=l_sat_subthresholdvalue)
            self._satsub = app_satsub_resample.getoutput().get("out")
            self._sat_pipeline.add_otb_app(app_satsub_resample)

            # *********************************************************************************************************
            # CLA image pipeline connection
            # *********************************************************************************************************

            LOGGER.debug(
                "VenusL1ImageFileReader::Initialize - CLA image filename: '" +
                l_FilenameProvider.m_CLAImageFileName + "'")
            if not l_FilenameProvider.m_CLAImageFileName:
                raise MajaPluginVenusException(
                    "The CLA image does not exist !! ")
            self._cla = l_FilenameProvider.m_CLAImageFileName

            # *********************************************************************************************************
            # SOL1 image pipeline connection
            # *********************************************************************************************************
            LOGGER.debug(
                "VenusL1ImageFileReader::Initialize - SOL image filename: '" +
                l_FilenameProvider.m_SOLImageFileName + "'")
            if not l_FilenameProvider.m_SOLImageFileName:
                raise MajaPluginVenusException(
                    "The SOL image does not exist !! ")
            mtdat = GdalDatasetInfo(l_FilenameProvider.m_TOAImageFileName)
            toaarea = Area()
            toaarea.size = mtdat.size
            toaarea.origin = mtdat.origin
            toaarea.spacing = mtdat.pixel_size
            l_SOLHeaderHandler = HeaderImageEarthExplorerXMLFileHandler(
                l_FilenameProvider.m_SOLHeaderFileName)
            l_L1SOLSubsamplingFactor = l_SOLHeaderHandler.get_sampling_factor()
            LOGGER.debug(l_L1SOLSubsamplingFactor)
            # SOL1
            tmp_sol1_b1 = os.path.join(working_dir, "sol1_B1.tif")
            app_sol1_b1 = multiply_by_scalar(
                l_FilenameProvider.m_SOLImageFileName +
                VenusL1ImageFileReader.SOL1ChannelB1,
                toaarea.spacing[0],
                tmp_sol1_b1,
                write_output=False)
            self._sol_pipeline.add_otb_app(app_sol1_b1)

            tmp_sol1_b2 = os.path.join(working_dir, "sol1_B2.tif")
            app_sol1_b2 = multiply_by_scalar(
                l_FilenameProvider.m_SOLImageFileName +
                VenusL1ImageFileReader.SOL1ChannelB2,
                (-1) * toaarea.spacing[1],
                tmp_sol1_b2,
                write_output=False)
            self._sol_pipeline.add_otb_app(app_sol1_b2)
            tmp_sol1_concat = os.path.join(working_dir, "sol1_concat.tif")
            param_sol1_concat = {
                "il": [
                    app_sol1_b1.getoutput().get("out"),
                    app_sol1_b2.getoutput().get("out")
                ],
                "out":
                tmp_sol1_concat
            }
            app_sol1_concat = OtbAppHandler("ConcatenateDoubleImages",
                                            param_sol1_concat)
            update_projection(l_FilenameProvider.m_TOAImageFileName,
                              app_sol1_concat.getoutput().get("out"),
                              l_L1SOLSubsamplingFactor)

            self._sol_pipeline.add_otb_app(app_sol1_concat)

            tmp_sol1_resample = os.path.join(working_dir, "sol1.tif")
            app_sol1_resample = resample(
                app_sol1_concat.getoutput().get("out"),
                self._dem.ALC,
                tmp_sol1_resample,
                OtbResampleType.LINEAR,
                padradius=4.0)
            self._sol1 = app_sol1_resample.getoutput().get("out")
            self._sol_pipeline.add_otb_app(app_sol1_resample)

            # SOL2
            tmp_sol2_b1 = os.path.join(working_dir, "sol2_B1.tif")
            app_sol2_b1 = multiply_by_scalar(
                l_FilenameProvider.m_SOLImageFileName +
                VenusL1ImageFileReader.SOL2ChannelB1,
                toaarea.spacing[0],
                tmp_sol2_b1,
                write_output=False)
            self._sol_pipeline.add_otb_app(app_sol2_b1)
            tmp_sol2_b2 = os.path.join(working_dir, "sol2_B2.tif")
            app_sol2_b2 = multiply_by_scalar(
                l_FilenameProvider.m_SOLImageFileName +
                VenusL1ImageFileReader.SOL2ChannelB2,
                (-1) * toaarea.spacing[1],
                tmp_sol2_b2,
                write_output=False)
            self._sol_pipeline.add_otb_app(app_sol2_b2)

            tmp_sol2_concat = os.path.join(working_dir, "sol2_concat.tif")
            param_sol2_concat = {
                "il": [
                    app_sol2_b1.getoutput().get("out"),
                    app_sol2_b2.getoutput().get("out")
                ],
                "out":
                tmp_sol2_concat
            }
            app_sol2_concat = OtbAppHandler("ConcatenateDoubleImages",
                                            param_sol2_concat)
            update_projection(l_FilenameProvider.m_TOAImageFileName,
                              app_sol2_concat.getoutput().get("out"),
                              l_L1SOLSubsamplingFactor)
            self._sol_pipeline.add_otb_app(app_sol2_concat)

            tmp_sol2_resample = os.path.join(working_dir, "sol2.tif")
            app_sol2_resample = resample(
                app_sol2_concat.getoutput().get("out"),
                self._dem.ALC,
                tmp_sol2_resample,
                OtbResampleType.LINEAR,
                padradius=4.0)
            self._sol2 = app_sol2_resample.getoutput().get("out")
            self._sol_pipeline.add_otb_app(app_sol2_resample)

            # *********************************************************************************************************
            # DTMVIE image pipeline connection
            # *********************************************************************************************************
            LOGGER.debug(
                "VenusL1ImageFileReader::Initialize - VIE image filename: '" +
                l_FilenameProvider.m_VIEImageFileName + "'")

            l_VIEHeaderHandler = HeaderImageEarthExplorerXMLFileHandler(
                l_FilenameProvider.m_VIEHeaderFileName)
            l_L1VIESubsamplingFactor = l_VIEHeaderHandler.get_sampling_factor()
            LOGGER.debug(l_L1VIESubsamplingFactor)

            tmp_vieb5b1_mult = os.path.join(working_dir, "vie5b1_mult.tif")
            app_vieb5b1_mult = multiply_by_scalar(
                l_FilenameProvider.m_VIEImageFileName +
                VenusL1ImageFileReader.VIEB5ChannelB1,
                toaarea.spacing[0],
                tmp_vieb5b1_mult,
                write_output=False)
            self._dtmvie_pipeline.add_otb_app(app_vieb5b1_mult)

            tmp_vieb5b2_mult = os.path.join(working_dir, "vie5b2_mult.tif")
            app_vieb5b2_mult = multiply_by_scalar(
                l_FilenameProvider.m_VIEImageFileName +
                VenusL1ImageFileReader.VIEB5ChannelB2,
                (-1) * toaarea.spacing[1],
                tmp_vieb5b2_mult,
                write_output=False)
            self._dtmvie_pipeline.add_otb_app(app_vieb5b2_mult)

            tmp_vieb6b1_mult = os.path.join(working_dir, "vie6b1_mult.tif")
            app_vieb6b1_mult = multiply_by_scalar(
                l_FilenameProvider.m_VIEImageFileName +
                VenusL1ImageFileReader.VIEB6ChannelB1,
                toaarea.spacing[0],
                tmp_vieb6b1_mult,
                write_output=False)
            self._dtmvie_pipeline.add_otb_app(app_vieb6b1_mult)

            tmp_vieb6b2_mult = os.path.join(working_dir, "vie6b2_mult.tif")
            app_vieb6b2_mult = multiply_by_scalar(
                l_FilenameProvider.m_VIEImageFileName +
                VenusL1ImageFileReader.VIEB6ChannelB2,
                (-1) * toaarea.spacing[1],
                tmp_vieb6b2_mult,
                write_output=False)
            self._dtmvie_pipeline.add_otb_app(app_vieb6b2_mult)

            tmp_dtmvie_concat = os.path.join(working_dir, "dtmvie_concat.tif")
            param_dtmvie_concat = {
                "il": [
                    app_vieb5b1_mult.getoutput().get("out"),
                    app_vieb5b2_mult.getoutput().get("out"),
                    app_vieb6b1_mult.getoutput().get("out"),
                    app_vieb6b2_mult.getoutput().get("out")
                ],
                "out":
                tmp_dtmvie_concat
            }
            app_dtmvie_concat = OtbAppHandler("ConcatenateDoubleImages",
                                              param_dtmvie_concat)
            update_projection(l_FilenameProvider.m_TOAImageFileName,
                              app_dtmvie_concat.getoutput().get("out"),
                              l_L1VIESubsamplingFactor)
            self._dtmvie_pipeline.add_otb_app(app_dtmvie_concat)

            tmp_dtmvie_resample = os.path.join(working_dir, "dtmvie.tif")
            app_dtmvie_resample = resample(
                app_dtmvie_concat.getoutput().get("out"),
                self._dem.ALC,
                tmp_dtmvie_resample,
                OtbResampleType.LINEAR,
                padradius=4.0)
            self._dtmvie = app_dtmvie_resample.getoutput().get("out")
            self._dtmvie_pipeline.add_otb_app(app_dtmvie_resample)

            # *********************************************************************************************************
            # VIE image pipeline connection
            # *********************************************************************************************************
            tmp_shadowvie_concat = os.path.join(working_dir,
                                                "shadowvie_concat.tif")
            param_shadowvie_concat = {
                "il": [
                    app_vieb5b1_mult.getoutput().get("out"),
                    app_vieb5b2_mult.getoutput().get("out")
                ],
                "out":
                tmp_shadowvie_concat
            }
            app_shadowvie_concat = OtbAppHandler("ConcatenateDoubleImages",
                                                 param_shadowvie_concat)
            self._shadowvie_pipeline.add_otb_app(app_shadowvie_concat)
            update_projection(l_FilenameProvider.m_TOAImageFileName,
                              app_shadowvie_concat.getoutput().get("out"),
                              l_L1VIESubsamplingFactor)
            tmp_shadowvie_resample = os.path.join(working_dir, "shadowvie.tif")
            app_shadowvie_resample = resample(
                app_shadowvie_concat.getoutput().get("out"),
                self._dem.ALC,
                tmp_shadowvie_resample,
                OtbResampleType.LINEAR,
                padradius=4.0)
            self._shadowvie = app_shadowvie_resample.getoutput().get("out")
            self._shadowvie_pipeline.add_otb_app(app_shadowvie_resample)

            # Fill the datas
            self.dict_of_vals["IPEDGSubOutput"] = self._edgsub
            self.dict_of_vals["SOL1Image"] = self._sol1
            self.dict_of_vals["SOL2Image"] = self._sol2
            self.dict_of_vals["DTMVIEImage"] = self._dtmvie
            self.dict_of_vals["IPTOASubOutput"] = self._toasub

            self.dict_of_vals["L2TOAImageList"] = [self._l2toa]
            self.dict_of_vals["ViewingZenithMeanMap"] = self._meanZenithMap
            self.dict_of_vals["ViewingAzimuthMeanMap"] = self._meanAzimuthMap
            self.dict_of_vals["CLAImage"] = self._cla
            self.dict_of_vals["IPSATSubOutput"] = self._satsub
            self.dict_of_vals["ShadowVIEImage"] = self._shadowvie
            if self._plugin.CirrusMasking:
                l_CirrusBandCode = l2comm.get_value("CirrusBandCode")
                l_CirrusBandIdx = self._plugin.BandsDefinitions.get_band_id_in_l2_coarse(
                    l_CirrusBandCode)
                tmp = os.path.join(working_dir, "l1toacirrus.tif")
                app = extract_roi(self._toascalar, [l_CirrusBandIdx - 1], tmp)
                self.dict_of_vals["L1TOACirrusImage"] = app.getoutput().get(
                    "out")
            self.dict_of_vals["L2EDGOutputList"] = [self._l2edg]
            self.dict_of_vals["L2SATImageList"] = [self._l2sat]
            self.dict_of_vals["L2PIXImageList"] = [self._l2pix]
            self.dict_of_vals["L1PIXImageList"] = [self._l1pix]
            self.dict_of_vals["L1TOAImageList"] = [self._toascalar]
 def get_value_b(self, key, check=False):
     return xml_tools.as_bool(self.get_value(key, check))