コード例 #1
0
    def generate_toa_caching(self, listOfTOAImageFileNames,
                             reflectanceMultiplicationValues, working):
        """

        :param listOfTOAImageFileNames: ListOfStrings
        :param reflectanceMultiplicationValues: ListOfDoubles
        :return:
        """
        if len(reflectanceMultiplicationValues) != len(
                listOfTOAImageFileNames):
            raise MajaDataException(
                "Not the same number of band images and coefficients")

        # ---------------------------------------------------------------
        # Get the number of band with the number of TOA image files set in the input product directory
        l_NbBand = len(listOfTOAImageFileNames)  # int

        # Convert the input jp2 images in tif
        for i in range(l_NbBand):
            toaFilename = listOfTOAImageFileNames[i]
            LOGGER.debug("Caching the <%s> image filename...", toaFilename)
            LOGGER.debug("Reflectance quantification value: %s",
                         reflectanceMultiplicationValues[i])
            # Initialize the TOA reader
            l_ImageFilename = os.path.join(working,
                                           "toaconverted_" + str(i) + ".tif")
            # extract_roi(toaFilename,[0],l_ImageFilename,working)
            app = multiply_by_scalar(toaFilename,
                                     reflectanceMultiplicationValues[i],
                                     output_image=l_ImageFilename,
                                     write_output=True)
            self._pipeline.add_otb_app(app)
            self._toa_scalar_list.append(app.getoutput()["out"])
コード例 #2
0
    def initialize(self, filename, working_dir, has_snow):
        file_hdr = os.path.splitext(filename)[0] + ".HDR"
        file_dbl = os.path.splitext(filename)[0] + ".DBL"
        file_dbldir = os.path.splitext(filename)[0] + ".DBL.DIR"
        LOGGER.info("AUX_REFDE2 filename: " + filename)
        # uncompress dbl
        uncompress_dbl_product(file_dbl)

        # DEM filenames provider
        list_of_file = os.listdir(file_dbldir)
        nbresol = 0
        for f in list_of_file:
            if "_ALT" in f and "TIF" in os.path.splitext(f)[1]:
                nbresol = nbresol + 1
        LOGGER.info("Nb resolution found " + str(nbresol))
        self.initialize_res_list(nbresol)

        LOGGER.info(
            "DEMFilenamesProvider::Initialize. Nb resolution computed:" +
            str(len(self._resList)))
        for resol in self._resList:
            LOGGER.debug("DEMFilenamesProvider::Initialize. Prefix resol : " +
                         resol)

        handler = EarthExplorerXMLFileHandler(file_hdr)
        list_of_dbl_files = handler.get_list_of_packaged_dbl_files(True, False)
        LOGGER.info("DEMFileNames found " + str(len(list_of_dbl_files)) +
                    " files")

        for i in range(0, len(list_of_dbl_files)):
            if list_of_dbl_files[i].split('.TIF')[-1]:
                raise MajaDataException(
                    "Wrong file extension detected. Delete the file: " +
                    str(list_of_dbl_files[i]))

        # --------------------------------------
        # Find the correct filename
        for fi in list_of_dbl_files:
            # LAIG - FA - MAC - 1610 - CNES
            # ../ CONTEXTES_ANOMALIES / TMA_VENUS_maccs_errors / 4398 / VE_TEST_AUX_REFDE2_BRASCHAT_0001.DBL.DIR / VE_TEST_AUX_REFDE2_BRASCHAT_0001_SLP.TIF
            # Extract the last value -> SLP
            # ../ CONTEXTES_ANOMALIES / TMA_VENUS_maccs_errors / 4398 / VE_TEST_AUX_REFDE2_BRASCHAT_0001.DBL.DIR / VE_TEST_AUX_REFDE2_BRASCHAT_0001_ALT_R1.TIF
            # Extract the last value -> ALT
            l_splitted = (os.path.splitext(os.path.basename(fi))[0]).split("_")
            l_lenghtlistfilenamename = len(l_splitted)
            # Extract the tow last values -> ex: 0001 _SLP or ALT_R1
            l_keytype = l_splitted[-1]
            if l_lenghtlistfilenamename > 2:
                l_keytype = l_splitted[-2] + "_" + l_keytype
            # --------------------------------------
            # Test if the filename is ALC
            if "ALC" in l_keytype:
                self.ALC = fi
            # --------------------------------------
            # Test if the filename is MSK
            elif "MSK" in l_keytype:
                self.MSK = fi
            # --------------------------------------
            # Test if the filename is ASC
            elif "ASC" in l_keytype:
                self.ASC = fi
            # --------------------------------------
            # Test if the filename is SLC
            elif "SLC" in l_keytype:
                self.__SLCInternal = fi
            else:
                # --------------------------------------
                # Lop under resolutions
                for res in self._resList:
                    # --------------------------------------
                    # Test if the filename is SLP
                    if "SLP" in l_keytype:
                        if res in l_keytype:
                            self.__SLPListInternal.append(fi)
                    # --------------------------------------
                    # Test if the filename is ALT
                    elif "ALT" in l_keytype:
                        if res in l_keytype:
                            self.ALTList.append(fi)
                    # --------------------------------------
                    # Test if the filename is ASP
                    elif "ASP" in l_keytype:
                        if res in l_keytype:
                            self.__ASPListInternal.append(fi)
                    else:
                        LOGGER.debug(
                            "Unknown Filename and associated product type.")
                # endloop resol
        # --------------------------------------
        # Check existent of ALC filename
        if not os.path.exists(self.ALC):
            raise MajaDataException("The ALC file '" + self.ALC +
                                    "' of the DTM doesn't exist !")

        # --------------------------------------
        # Check existent of MSK filename
        if not os.path.exists(self.MSK):
            raise MajaDataException("The MSK file '" + self.MSK +
                                    "' of the DTM doesn't exist !")

        # --------------------------------------
        # Check existent of SLC filename
        if not os.path.exists(self.__SLCInternal):
            raise MajaDataException("The SLC file '" + self.__SLCInternal +
                                    "' of the DTM doesn't exist !")
        else:
            LOGGER.debug("Starting multiply " + self.__SLCInternal + " * " +
                         str(self._coeff))
            self.SLC = os.path.join(
                working_dir, "Mul_" + os.path.basename(self.__SLCInternal))
            self._apps.add_otb_app(
                multiply_by_scalar(self.__SLCInternal,
                                   self._coeff,
                                   output_image=self.SLC))
            mtdat = GdalDatasetInfo(self.__SLCInternal)
            self.CoarseArea = Area()
            self.CoarseArea.size = mtdat.size
            self.CoarseArea.origin = mtdat.origin
            self.CoarseArea.spacing = mtdat.pixel_size
            LOGGER.debug("Done")

        # --------------------------------------
        for resol in range(0, len(self._resList)):
            # --------------------------------------
            # Check existent of SLP filename
            if not os.path.exists(self.__SLPListInternal[resol]):
                raise MajaDataException("One of the SLP file '" +
                                        self.__SLPListInternal[resol] +
                                        "' of the DTM doesn't exist !")
            else:
                LOGGER.debug("Starting multiply " +
                             self.__SLPListInternal[resol] + " * " +
                             str(self._coeff))
                tmp = os.path.join(
                    working_dir,
                    "Mul_" + os.path.basename(self.__SLPListInternal[resol]))
                slp_mul_app = multiply_by_scalar(self.__SLPListInternal[resol],
                                                 self._coeff,
                                                 output_image=tmp,
                                                 write_output=False)
                self._apps.add_otb_app(slp_mul_app)
                mtdat = GdalDatasetInfo(self.__SLPListInternal[resol])
                l2area = Area()
                l2area.size = mtdat.size
                l2area.origin = mtdat.origin
                l2area.spacing = mtdat.pixel_size
                self.ProjRef = mtdat.dataset.GetProjectionRef()
                self.L2Areas.append(l2area)
                LOGGER.debug("Done")
                self.SLPList.append(slp_mul_app.getoutput().get("out"))
            # --------------------------------------
            # Check existent of ALT filename
            if not os.path.exists(self.ALTList[resol]):
                raise MajaDataException("One of the ALT file '" +
                                        self.ALTList[resol] +
                                        "' of the DTM doesn't exist !")
            # --------------------------------------
            # Check existent of ASP filename
            if not os.path.exists(self.__ASPListInternal[resol]):
                raise MajaDataException("One of the ASP file '" +
                                        self.__ASPListInternal[resol] +
                                        "' of the DTM doesn't exist !")
            else:
                LOGGER.debug("Starting multiply " +
                             self.__ASPListInternal[resol] + " * " +
                             str(self._coeff))
                tmp = os.path.join(
                    working_dir,
                    "Mul_" + os.path.basename(self.__ASPListInternal[resol]))
                asp_mul_app = multiply_by_scalar(self.__ASPListInternal[resol],
                                                 self._coeff,
                                                 output_image=tmp,
                                                 write_output=False)
                self._apps.add_otb_app(asp_mul_app)
                LOGGER.debug("Done")
                self.ASPList.append(asp_mul_app.getoutput().get("out"))

        # end loop resol

        LOGGER.debug(nbresol)

        l_cartoCode = xml_tools.get_only_value(
            handler.root,
            "//DEM_Information/Cartographic/Coordinate_Reference_System/Code",
            namespaces=handler.nss,
            check=True)
        l_geoCode = xml_tools.get_only_value(
            handler.root,
            "//DEM_Information/Geographic/Coordinate_Reference_System/Code",
            namespaces=handler.nss,
            check=True)
        if l_cartoCode is not None:
            self.ProjCode = l_cartoCode.text
            self.ProjType = "PROJECTED"
        elif l_geoCode is not None:
            self.ProjCode = l_geoCode.text
            self.ProjType = "GEOGRAPHIC"
        else:
            raise MajaDataException("Unknown DEM type")

        LOGGER.debug("DEM Projection Code: " + self.ProjCode)
        LOGGER.debug("DEM Projection Type: " + self.ProjType)

        self.Site = xml_tools.get_xml_string_value(
            handler.root,
            "//Specific_Product_Header/Instance_Id/Applicable_Site_Nick_Name",
            namespaces=handler.nss)

        if nbresol != 0:
            param_stats = {"im": self.ALTList[0]}
            stat_app = stats(self.ALTList[0])
            self.ALT_Mean = stat_app.getoutput().get("mean")
            self.ALT_Max = stat_app.getoutput().get("max")
            self.ALT_Min = stat_app.getoutput().get("min")
            self.ALT_Stdv = stat_app.getoutput().get("stdv")
            self.ALT_LogicalName = "LOCAL=" + os.path.splitext(
                os.path.basename(file_hdr))[0]
            LOGGER.info("DEM Mean : " + str(self.ALT_Mean))
            LOGGER.info("DEM Max : " + str(self.ALT_Max))
            LOGGER.info("DEM Min : " + str(self.ALT_Min))
            LOGGER.info("DEM Stdv : " + str(self.ALT_Stdv))
コード例 #3
0
    def write_private_images(
            self,
            p_L2PrivateImageFilenamesProvider,
            p_ReflectanceQuantificationValue,
            p_CLDDataBandsSelected,
            p_CLDCoreAlgorithmsMapBand,
            p_WriteOnlyCLACLD,
            p_WriteLTC,
            working_dir):
        LOGGER.debug("Write LTC: " + str(p_WriteLTC))
        LOGGER.debug("Write WriteOnlyCLACLD: " + str(p_WriteOnlyCLACLD))
        LOGGER.debug("p_L2PrivateImageFilenamesProvider.GetLTCImageDirFileName(): %s",
                     p_L2PrivateImageFilenamesProvider.get_ltc_image_dir_filename())

        if not p_WriteOnlyCLACLD:
            # ** ** PRIVATE DATA ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **

            # START WRITING PXD Image file DATA
            # Create the writer
            # Initialize the writer filter
            otb_file_utils.otb_copy_image_to_file(
                self._pxd,
                p_L2PrivateImageFilenamesProvider.get_pxd_image_filename() +
                file_utils.get_extended_filename_write_image_file_standard())

            # START WRITING WAM Image file DATA
            # Create the concatenate imagefilter
            # Create the writer UnsignedIntegerVectorImageFileWriterPointer

            # Convert Binary PWA and TWA images
            tmp_pwa_concat = os.path.join(working_dir, "tmp_pwa_concat.tif")
            param_pwa_concat = {"im": self._possiblewatermask,
                                "out": tmp_pwa_concat
                                }
            pwa_concat_app = OtbAppHandler("BinaryConcatenate", param_pwa_concat, write_output=False)

            tmp_twa_concat = os.path.join(working_dir, "tmp_twa_concat.tif")
            param_twa_concat = {"im": self._testedwatermask,
                                "out": tmp_twa_concat
                                }
            twa_concat_app = OtbAppHandler("BinaryConcatenate", param_twa_concat, write_output=False)

            # Concatenate into one file
            param_wam_concat = {
                "il": [
                    self._wasimage,
                    pwa_concat_app.getoutput().get("out"),
                    twa_concat_app.getoutput().get("out")],
                "out": p_L2PrivateImageFilenamesProvider.get_wam_image_filename() +
                ":uint16"+  file_utils.get_extended_filename_write_image_file_standard()}

            OtbAppHandler("ConcatenateImages", param_wam_concat)

            # START WRITING STO Image file DATA
            # Scalar filter
            multiply_by_scalar(self._sto,p_ReflectanceQuantificationValue,
                               p_L2PrivateImageFilenamesProvider.get_sto_image_filename() +
                               file_utils.get_extended_filename_write_image_file_standard() + ":int16")


            # START WRITING NDT Image file DATA
            # Create the writer
            # Evol 4 - 1: NDT ecris sur 8 bits(et non 16  bits car seuilement un masque)
            otb_file_utils.otb_copy_image_to_file(
                self._ndt,
                p_L2PrivateImageFilenamesProvider.get_ndt_image_filename() +
                file_utils.get_extended_filename_write_image_file_standard())

            # START WRITING LTC Image file DATA
            # Create the image list
            if p_WriteLTC:
                otb_file_utils.otb_copy_image_to_file(self._ltc_image,
                                             p_L2PrivateImageFilenamesProvider.get_ltc_image_filename())

            # START WRITING RTA Image file DATA
            multiply_by_scalar(self._rta, p_ReflectanceQuantificationValue,
                               p_L2PrivateImageFilenamesProvider.get_rta_image_filename() +
                               file_utils.get_extended_filename_write_image_file_standard()+":int16")

            # START WRITING RTC Image file DATA
            multiply_by_scalar(self._rtc, p_ReflectanceQuantificationValue,
                               p_L2PrivateImageFilenamesProvider.get_rtc_image_filename() +
                               file_utils.get_extended_filename_write_image_file_standard()+":int16")

            # START WRITING RCR Image file DATA
            multiply_by_scalar(self._rcr, p_ReflectanceQuantificationValue,
                               p_L2PrivateImageFilenamesProvider.get_rcr_image_filename() +
                               file_utils.get_extended_filename_write_image_file_standard()+":int16")


        # End od condition
        self.write_cld_image(
            self._cld,
            p_CLDDataBandsSelected,
            p_L2PrivateImageFilenamesProvider.get_cld_image_filename(), use_filenames=True)

        # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
        # START WRITING CLA Sub Image file DATA
        # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
        # LAIG - DM - MAC - 1691 - CNES: Write CLA only is available(only for VENUS - stereo)
        if self._cld_l2cla is not None:

            otb_file_utils.otb_copy_image_to_file(
                self._cld_l2cla,
                p_L2PrivateImageFilenamesProvider.get_cla_image_filename() +
                file_utils.get_extended_filename_write_image_file_standard())
    def generate_vie_image(self, view_href, working_dir):
        LOGGER.debug("VenusMuscateL1ImageFileReader::GenerateVIEImage()")
        # *********************************************************************************************************
        # VIE image pipeline connection
        # Get the VIE filename from the muscate xml
        l_D01_DX_ImageFileName = self._header_handler.get_vie_image_filename(
            "01", "DX")
        LOGGER.debug(l_D01_DX_ImageFileName)
        l_D01_DY_ImageFileName = self._header_handler.get_vie_image_filename(
            "01", "DY")
        LOGGER.debug(l_D01_DY_ImageFileName)

        l_D04_DX_ImageFileName = self._header_handler.get_vie_image_filename(
            "04", "DX")
        LOGGER.debug(l_D04_DX_ImageFileName)
        l_D04_DY_ImageFileName = self._header_handler.get_vie_image_filename(
            "04", "DY")
        LOGGER.debug(l_D04_DY_ImageFileName)

        # --------------------------------------
        # VIE Expand image to the L2 Coarse resolution
        # Multiply by spacing since it is in m/m
        vie5b1_mult_filename = os.path.join(working_dir, "vie5b1_mult.tif")
        vie5b1_mult_app = multiply_by_scalar(l_D01_DX_ImageFileName,
                                             self._dem.L2Areas[0].spacing[0],
                                             vie5b1_mult_filename,
                                             write_output=False)

        vie5b2_mult_filename = os.path.join(working_dir, "vie5b1_mult_DX.tif")
        vie5b2_mult_app = multiply_by_scalar(l_D01_DY_ImageFileName,
                                             -1 *
                                             self._dem.L2Areas[0].spacing[1],
                                             vie5b2_mult_filename,
                                             write_output=False)

        vie6b1_mult_filename = os.path.join(working_dir, "vie6b1_mult.tif")
        vie6b1_mult_app = multiply_by_scalar(l_D04_DX_ImageFileName,
                                             self._dem.L2Areas[0].spacing[0],
                                             vie6b1_mult_filename,
                                             write_output=False)

        vie6b2_mult_filename = os.path.join(working_dir, "vie6b1_mult_DX.tif")
        vie6b2_mult_app = multiply_by_scalar(l_D04_DY_ImageFileName,
                                             -1 *
                                             self._dem.L2Areas[0].spacing[1],
                                             vie6b2_mult_filename,
                                             write_output=False)

        # Concatenate to get the final VIE
        out_concatenate = os.path.join(working_dir, "vie_concat.tif")
        param_concatenate = {
            "il": [
                vie5b1_mult_app.getoutput().get("out"),
                vie5b2_mult_app.getoutput().get("out"),
                vie6b1_mult_app.getoutput().get("out"),
                vie6b2_mult_app.getoutput().get("out")
            ],
            "out":
            out_concatenate
        }
        concat_app = OtbAppHandler("ConcatenateDoubleImages",
                                   param_concatenate,
                                   write_output=False)

        LOGGER.debug("Start DTMVIEExpand ...")
        out_resample = os.path.join(working_dir, "vie_concat_resamp.tif")
        resamp_app = resample(concat_app.getoutput().get("out"),
                              self._dem.ALC,
                              out_resample,
                              OtbResampleType.LINEAR,
                              padradius=4,
                              write_output=True)
        LOGGER.debug("DTMVIEExpand Done")
        self._vieimagelist.append(resamp_app.getoutput().get("out"))
        # *********************************************************************************************************
        # VIE SHAD image pipeline connection
        # *********************************************************************************************************
        out_shad_concatenate = os.path.join(working_dir, "vie_concat.tif")
        param_shad_concatenate = {
            "il": [l_D01_DX_ImageFileName, l_D01_DY_ImageFileName],
            "out": out_shad_concatenate
        }
        concat_shad_app = OtbAppHandler("ConcatenateDoubleImages",
                                        param_shad_concatenate,
                                        write_output=False)

        LOGGER.debug("Start DTMSHADExpand ...")
        out_shad_resample = os.path.join(working_dir,
                                         "vieshadconcat_resamp.tif")
        resamp_shad_app = resample(concat_shad_app.getoutput().get("out"),
                                   self._dem.ALC,
                                   out_shad_resample,
                                   OtbResampleType.LINEAR,
                                   padradius=4,
                                   write_output=True)
        LOGGER.debug("DTMSHADExpand Done")
        self._vieimagelist.append(resamp_shad_app.getoutput().get("out"))
    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]