コード例 #1
0
    def get_solar_grids(self, dtm, solarAnglesFile, solH1, working):

        solar_grid_filename = os.path.join(working, "solar_grid.tif")

        # angle_list_to_image()
        solarangle_grid_app = angle_list_to_image(dtm,
                                                  solarAnglesFile,
                                                  solar_grid_filename,
                                                  write_output=False)
        # Multiply by the solar reference altitude
        solar_grid_mult_filename = os.path.join(working, "solar_grid_mult.tif")
        param_scaled_solar = {
            "im": solarangle_grid_app.getoutput().get("out"),
            "coef": float(solH1),
            "out": solar_grid_mult_filename
        }
        rta_scal_app = OtbAppHandler("MultiplyByScalar",
                                     param_scaled_solar,
                                     write_output=False)
        # Expand at L2Coarse.
        solar_grid_resamp_filename = os.path.join(working,
                                                  "solar_grid_resamp.tif")
        resample(rta_scal_app.getoutput().get("out"), dtm,
                 solar_grid_resamp_filename, OtbResampleType.LINEAR)
        self._sol1image = solar_grid_resamp_filename
コード例 #2
0
    def generate_toa_sub_images(self, working):
        dtm_coarse = self._dem.ALC

        # For each band of the input product
        tmp_sub_toa_pipe = OtbPipelineManager()
        for i, toa in enumerate(self._toa_scalar_list):
            # undersampling at L2CoarseResolution
            toa_sub_image = os.path.join(working, "aot_sub_{}.tif".format(i))
            app = resample(toa,
                           dtm_coarse,
                           toa_sub_image,
                           OtbResampleType.LINEAR_WITH_RADIUS,
                           write_output=False)
            self._toa_sub_list.append(app.getoutput()["out"])
            tmp_sub_toa_pipe.add_otb_app(app)
        # end band loop

        # *******************************************************************************************************
        # TOA Sub image pipeline connection
        # *******************************************************************************************************
        toa_sub_image = os.path.join(working, "aot_sub.tif")
        param_concatenate = {"il": self._toa_sub_list, "out": toa_sub_image}
        OtbAppHandler("ConcatenateDoubleImages", param_concatenate)
        self._sub_toa = toa_sub_image
        tmp_sub_toa_pipe.free_otb_app()
コード例 #3
0
    def generate_l2_toa_images(self, l_ListOfL2Resolution, working_dir):

        for l1res in range(len(l_ListOfL2Resolution)):
            curL1Res = l_ListOfL2Resolution[l1res]
            dtm = self._dem.ALTList[l1res]
            l_ListOfL2BandCode = self._plugin.BandsDefinitions.get_list_of_l2_band_code(
                curL1Res)
            LOGGER.debug("Read the nb bands" + str(len(l_ListOfL2BandCode)) +
                         " of the TOA images...")
            l_l1bandidx = [
                self._plugin.BandsDefinitions.get_band_id_in_l1(b)
                for b in l_ListOfL2BandCode
            ]
            tmp_toa_resample = os.path.join(working_dir,
                                            "tmp_toa_resample.tif")
            app_toa_resample = resample(self._l1toaimagelist[l1res],
                                        dtm,
                                        tmp_toa_resample,
                                        OtbResampleType.LINEAR_WITH_RADIUS,
                                        write_output=False)
            self._l2toa_pipeline.add_otb_app(app_toa_resample)
            # L2TOA has less band than L1 so extract
            tmp_toa_roi = os.path.join(
                working_dir, "L2TOAImageList_{}.tif".format(curL1Res))
            l2toa_roi_app = extract_roi(
                app_toa_resample.getoutput().get("out"),
                l_l1bandidx,
                tmp_toa_roi,
                write_output=False)
            self._l2toa_pipeline.add_otb_app(l2toa_roi_app)
            self._l2toaimagelist.append(l2toa_roi_app.getoutput().get("out"))
コード例 #4
0
 def generate_toa_sub_image(self, working):
     dtm_coarse = self._dem.ALC
     # For each res of the input L1 product
     for i, toa in enumerate(self._l1toaimagelist):
         # undersampling at L2CoarseResolution
         toa_sub_image = os.path.join(working, "aot_sub_{}.tif".format(i))
         app_resample = resample(toa,
                                 dtm_coarse,
                                 toa_sub_image,
                                 OtbResampleType.LINEAR_WITH_RADIUS,
                                 write_output=False)
         self._toa_sub_pipeline.add_otb_app(app_resample)
         self._toasublist.append(app_resample.getoutput().get("out"))
     # end res loop
     #concat
     toa_sub_image = os.path.join(working, "aot_sub.tif")
     param_concatenate = {"il": self._toasublist, "out": toa_sub_image}
     app_concatenate = OtbAppHandler("ConcatenateDoubleImages",
                                     param_concatenate,
                                     write_output=False)
     self._toa_sub_pipeline.add_otb_app(app_concatenate)
     #apply edg
     #invert EDG for masking
     out_edgsub_threshold = os.path.join(working, "edgsubthreshold.tif")
     param_edgsub_threshold = {
         "im": self._edgsubmask,
         "thresholdvalue": self._toathresholdminvalue,
         "equalvalue": 1,
         "outsidevalue": 0,
         "out": out_edgsub_threshold + ":uint8"
     }
     app_edgsub_threshold = OtbAppHandler("OneBandEqualThreshold",
                                          param_edgsub_threshold,
                                          write_output=False)
     self._toa_sub_pipeline.add_otb_app(app_edgsub_threshold)
     #apply mask to sub toa
     tmp_l2subtoa = os.path.join(working, "toasub.tif")
     app_l2subtoa = apply_mask(app_concatenate.getoutput().get("out"),
                               app_edgsub_threshold.getoutput().get("out"),
                               self._reall1nodata,
                               tmp_l2subtoa,
                               write_output=True)
     self._subtoaimage = app_l2subtoa.getoutput().get("out")
     self._toa_sub_pipeline.free_otb_app()
コード例 #5
0
    def generate_l2_toa_images(self, working_dir):
        """

        :return:
        """
        l_BandsDefinitions = self._plugin.BandsDefinitions
        l_ListOfL2Resolution = l_BandsDefinitions.ListOfL2Resolution  # ListOfStrings
        l_NbL2Res = len(l_ListOfL2Resolution)

        for l2res in range(l_NbL2Res):
            # Current resolution: "R1" or "R2"
            curRes = l_ListOfL2Resolution[l2res]
            dtm = self._dem.ALTList[l2res]
            # Get the list of band of the current resolution
            listOfL2Bands = l_BandsDefinitions.get_list_of_l2_band_code(curRes)
            nbBand = len(listOfL2Bands)
            list_of_image = []
            # For each band of the current resolution
            for l_StrBandIdL2 in listOfL2Bands:
                # Get the L1 band index associated to the L2 band code
                l1BandIdx = l_BandsDefinitions.get_band_id_in_l1(l_StrBandIdL2)
                # Generate the list of L2 TOA images per resolution
                toa_l2_image = os.path.join(
                    working_dir, "aot_l2_{}.tif".format(l_StrBandIdL2))
                app = resample(self._toa_scalar_list[l1BandIdx],
                               dtm,
                               toa_l2_image,
                               OtbResampleType.LINEAR_WITH_RADIUS,
                               write_output=False)
                self._toa_pipeline.add_otb_app(app)
                list_of_image.append(app.getoutput()["out"])
            out_concatenate = os.path.join(
                working_dir, "L2TOAImageListVector_" + curRes + ".tif")
            param_concatenate = {"il": list_of_image, "out": out_concatenate}
            concat_app = OtbAppHandler("ConcatenateDoubleImages",
                                       param_concatenate,
                                       write_output=False)
            self._toa_pipeline.add_otb_app(concat_app)
            self._l2toaimagelist.append(concat_app.getoutput().get("out"))
コード例 #6
0
    def GetViewingGrids(self, band, nbL1Bands, vieHRef, satFilename,
                        zoneFilenames, nodataFilename, listOfZone,
                        view_angle_col_step, view_angle_row_step,
                        viewing_angles_zenith, viewing_angles_azimuth,
                        working):
        LOGGER.debug("GetViewingGrids - Band: " + band)

        dtm_coarse = self._dem.ALC
        l_BandsDefinitions = self._plugin.BandsDefinitions
        l1BandIdx = l_BandsDefinitions.get_band_id_in_l1(band)

        # ---- Viewing angle Grid --------------------------------------------------------------------
        l_VieAnglesGridList = []
        l_nbDetectors = len(viewing_angles_azimuth)
        # Detector loop
        LOGGER.debug("For each detectors (nb=%s) ...", l_nbDetectors)
        view_resamp_pipeline = OtbPipelineManager()
        for detId in range(len(viewing_angles_azimuth)):
            # Generate an image with the list of viewing angle values set in the header file
            det = listOfZone[detId]
            LOGGER.debug("ZenithViewingAngles for band " + band + " and det " +
                         det + " ,  nb values: " +
                         str(len(viewing_angles_zenith[detId])))
            LOGGER.debug(viewing_angles_zenith[detId])
            LOGGER.debug("AzimuthViewingAngles " + band + " and det " + det +
                         " nb values: " +
                         str(len(viewing_angles_azimuth[detId])))
            LOGGER.debug(viewing_angles_azimuth[detId])
            output_filename = "/tmp/internal_angles_test_{}_{}.xml".format(
                band, det)
            LOGGER.debug("Angles output_filename : %s", output_filename)
            writer = MajaInternalXmlInputAngles(viewing_angles_zenith[detId],
                                                viewing_angles_azimuth[detId],
                                                view_angle_col_step,
                                                view_angle_row_step,
                                                output_filename)
            writer.write()
            if not os.path.exists(output_filename):
                raise MajaExceptionPluginSentinel2Muscate(
                    "File does not exist " + output_filename)

            viewing_grid_filename = os.path.join(
                working, "viewing_grid_{}_{}.tif".format(det, band))

            # angle_list_to_image()
            viewing_angle_app = angle_list_to_image(dtm_coarse,
                                                    output_filename,
                                                    viewing_grid_filename,
                                                    extrapolation=False,
                                                    write_output=False)
            view_resamp_pipeline.add_otb_app(viewing_angle_app)
            # Expand at L2Coarse.
            viewing_grid_resamp_filename = os.path.join(
                working, "viewing_grid_resamp_{}_{}.tif".format(detId, band))
            viewing_grid_resamp_app = resample(
                viewing_angle_app.getoutput().get("out"),
                dtm_coarse,
                viewing_grid_resamp_filename,
                OtbResampleType.LINEAR,
                write_output=False)
            view_resamp_pipeline.add_otb_app(viewing_grid_resamp_app)
            # add images in a list
            l_VieAnglesGridList.append(
                viewing_grid_resamp_app.getoutput().get("out"))
            # end detector loop

        # Generate the angle images using the zone (detector) mask
        LOGGER.debug(
            "Start ConcatenatePerZoneVectorImageFilter for band id [" + band +
            "]...")

        # Concatenate all the detectors
        viewing_concat_filename = os.path.join(
            working, "viewing_concat_{}.tif".format(band))
        param_concat_perzone = {
            "mask": self._zonemasksublist[l1BandIdx],
            "il": l_VieAnglesGridList,
            "zonelist": listOfZone,
            "out": viewing_concat_filename
        }
        concat_perzone_app = OtbAppHandler("ConcatenatePerZone",
                                           param_concat_perzone,
                                           write_output=False)
        # Multiply by reference altitude
        viewing_grid_mult_filename = os.path.join(
            working, "viewing_grid_mult_{}.tif".format(band))
        param_scaled_solar = {
            "im": concat_perzone_app.getoutput().get("out"),
            "coef": float(vieHRef),
            "out": viewing_grid_mult_filename
        }
        view_scale_app = OtbAppHandler("MultiplyByScalar",
                                       param_scaled_solar,
                                       write_output=True)
        self._vieimagelist.append(view_scale_app.getoutput().get("out"))

        l_nbZones = len(listOfZone)
        LOGGER.debug("Start Loop for Zone (nb=" + str(l_nbZones) + ")...")
        for d in range(l_nbZones):
            l_zone = listOfZone[d]
            # -----------------------------------------------------------------------------------
            # Compute average values of zenithal and azimuthal angles grid per zone (detector in level1B)
            # -----------------------------------------------------------------------------------
            # VAP Reader connection (from ATB)
            tmp_azi = os.path.join(working,
                                   "tmp_azi_{}_{}.tif".format(band, l_zone))
            tmp_azi_image = extract_roi(l_VieAnglesGridList[d], [1],
                                        tmp_azi,
                                        write_output=False)
            param_stats = {
                "im": tmp_azi_image.getoutput().get("out"),
                "exclude": 1,
                "mask": self._zonemasksublist[l1BandIdx],
                "maskforeground": int(l_zone)
            }
            l2_stat = OtbAppHandler("Stats", param_stats)

            azi_mean = l2_stat.getoutput().get("mean")
            tmp_zen = os.path.join(working,
                                   "tmp_zen_{}_{}.tif".format(band, l_zone))
            tmp_zen_app = extract_roi(l_VieAnglesGridList[d], [0],
                                      tmp_zen,
                                      write_output=False)
            param_stats = {
                "im": tmp_zen_app.getoutput().get("out"),
                "exclude": 1,
                "mask": self._zonemasksublist[l1BandIdx],
                "maskforeground": int(l_zone)
            }
            l2_stat = OtbAppHandler("Stats", param_stats)
            zen_mean = l2_stat.getoutput().get("mean")
            tmp_mean = (zen_mean, azi_mean)
            l_ViewingAngleMean = grid_to_angle(tmp_mean)
            l_ViewingAngleMeanDeg = (l_ViewingAngleMean[0] * 180.0 / math.pi,
                                     l_ViewingAngleMean[1] * 180.0 / math.pi)
            # Add a vector to mean maps
            if l_zone not in self._meanZenithMap:
                self._meanZenithMap[listOfZone[d]] = []
            if l_zone not in self._meanAzimuthMap:
                self._meanAzimuthMap[listOfZone[d]] = []
            self._meanZenithMap[listOfZone[d]].append(
                str(l_ViewingAngleMeanDeg[0]))
            self._meanAzimuthMap[listOfZone[d]].append(
                str(l_ViewingAngleMeanDeg[1]))
            LOGGER.debug(" For BandId[" + str(band) + "], zone [" +
                         str(listOfZone[d]) + "]  . Mean 'GRID View angles'=" +
                         str(tmp_mean) + " . Mean 'View angles'=" +
                         str(l_ViewingAngleMean[0]) + ":" +
                         str(l_ViewingAngleMean[1]) + " rad. ou  " +
                         str(l_ViewingAngleMeanDeg[0]) + ":" +
                         str(l_ViewingAngleMeanDeg[1]) + " deg.")
        LOGGER.debug("Start Loop for Zone done.")
        view_resamp_pipeline.free_otb_app()
コード例 #7
0
    def generate_mask_rasters(self, satPixFileNames, defectivPixFileNames,
                              zoneMaskFileNames, noDataMaskFileNames,
                              p_ListOfTOABandCode, working):
        """

        :param satPixFileNames: ListOfStrings
        :param defectivPixFileNames: ListOfStrings
        :param zoneMaskFileNames: ListOfStrings
        :param noDataMaskFileNames: ListOfStrings
        :param p_ListOfTOABandCode: ListOfStrings
        :param working: string
        :return:
        """

        # *******************************************************************************************************
        # Generate mask rasters by rasterizing the gml mask per L2 resolution per band
        # *******************************************************************************************************
        LOGGER.info("Starting GenerateMaskRasters")

        l_BandsDefinitions = self._plugin.BandsDefinitions
        l2Area = None
        l_ListOfL2Resolution = l_BandsDefinitions.ListOfL2Resolution  # ListOfStrings
        l_NbL2Res = len(l_ListOfL2Resolution)
        l_ListOfL1Resolution = l_BandsDefinitions.ListOfL1Resolution  # ListOfStrings
        l_NbL1Res = len(l_ListOfL1Resolution)
        l_NbL1Band = len(defectivPixFileNames)
        dtm_coarse = self._dem.ALC

        # Set a constant image if the gml masks are empty
        tmp_constant_filename = os.path.join(working, "Masks_const.tif")
        #constant_image(dtm_coarse, 0, tmp_constant_filename, write_output=True)

        # Initialize the L2 Elements
        for l2res in range(l_NbL2Res):
            self._l2defectmasklist.append([])
            self._l2zonemasklist.append([])
            self._l2satimagelist.append([])
            self._l2dfpimagelist.append(None)
            self._l2zoneimagelist.append(None)
        # Init the coarse elements
        for coarseband in p_ListOfTOABandCode:
            self._satmasksublist.append(None)
            self._nodatamasksublist.append(None)
            self._zonemasksublist.append(None)
            self._l2satmasklist.append(None)

        # Loop on L1Res
        for l1res in range(l_NbL1Res):
            # Current resolution: "R1" or "R2" or "R3"
            curL1Res = l_ListOfL1Resolution[l1res]

            # Get the list of band of the current resolution
            listOfL1Bands = l_BandsDefinitions.get_list_of_l1_band_code(
                curL1Res)
            nbL1Bands = len(listOfL1Bands)
            # For each band of the current resolution
            l_l2zone_pipeline = OtbPipelineManager()
            firstBandIdx = l_BandsDefinitions.get_band_id_in_l1(
                listOfL1Bands[-1])

            # Verify if we can optimize the work if its the same file for all bands of
            # the resolution and if the bands are in correct bit order
            l_strDefectFileNameRef = defectivPixFileNames[firstBandIdx]
            l_isDefectSameFilesForBands = True
            l_strSatFileNameRef = satPixFileNames[firstBandIdx]
            l_isSatSameFilesForBands = True
            l_strNoDataFileNameRef = noDataMaskFileNames[firstBandIdx]
            l_isNoDataSameFilesForBands = True
            for l_BandIdxL1 in range(len(listOfL1Bands)):
                # Get the L1 band index associated to the L2 band code
                l_StrBandIdL1 = listOfL1Bands[l_BandIdxL1]
                l1BandIdx = l_BandsDefinitions.get_band_id_in_l1(l_StrBandIdL1)
                # Filenameverify
                if l_strDefectFileNameRef != defectivPixFileNames[l1BandIdx]:
                    l_isDefectSameFilesForBands = False
                if l_strSatFileNameRef != satPixFileNames[l1BandIdx]:
                    l_isSatSameFilesForBands = False
                if l_strNoDataFileNameRef != noDataMaskFileNames[l1BandIdx]:
                    l_isNoDataSameFilesForBands = False
            LOGGER.debug("l_isDefectSameFilesForBands = " +
                         str(l_isDefectSameFilesForBands))
            LOGGER.debug("l_isSatSameFilesForBands = " +
                         str(l_isSatSameFilesForBands))
            LOGGER.debug("l_isNoDataSameFilesForBands = " +
                         str(l_isSatSameFilesForBands))

            # Defective PIX (only in L2 resolution)
            if l_isDefectSameFilesForBands:
                if curL1Res in l_ListOfL2Resolution:
                    l_StrBandIdL1 = listOfL1Bands[0]
                    l1BandIdx = l_BandsDefinitions.get_band_id_in_l1(
                        l_StrBandIdL1)
                    LOGGER.debug("l_StrBandIdL1 : ")
                    LOGGER.debug(l_StrBandIdL1)
                    self._l2piximagelist.append(
                        defectivPixFileNames[l1BandIdx])
                    dfp_mask = os.path.join(
                        working, "L1_DFP_Masks_{}.tif".format(curL1Res))
                    param_bintovec_dfp = {
                        "im": defectivPixFileNames[l1BandIdx],
                        "out": dfp_mask + ":uint8",
                        "nbcomp": nbL1Bands
                    }
                    dfp_mask_app = OtbAppHandler("BinaryToVector",
                                                 param_bintovec_dfp,
                                                 write_output=False)
                    self._l2_dfp_pipeline.add_otb_app(dfp_mask_app)
                    self._l2dfpimagelist[l_ListOfL2Resolution.index(
                        curL1Res)] = dfp_mask_app.getoutput().get("out")
            else:
                raise MajaExceptionPluginSentinel2Muscate(
                    "Product format not supported : not the same file for band on PIX"
                )

            # SAT Mask generation
            if l_isSatSameFilesForBands:
                # Sat Masks generation
                l_StrBandIdL1 = listOfL1Bands[0]
                l1BandIdx = l_BandsDefinitions.get_band_id_in_l1(l_StrBandIdL1)
                l_SATFFilename = satPixFileNames[l1BandIdx]
                sat_mask = os.path.join(working,
                                        "L1_SAT_Masks_{}.tif".format(curL1Res))
                param_bintovec_dfp = {
                    "im": l_SATFFilename,
                    "out": sat_mask + ":uint8",
                    "nbcomp": nbL1Bands
                }
                sat_mask_app = OtbAppHandler("BinaryToVector",
                                             param_bintovec_dfp,
                                             write_output=True)
                # self._l2_sat_pipeline.add_otb_app(sat_mask_app)
                if curL1Res in l_ListOfL2Resolution:
                    self._l2satmasklist[l_ListOfL2Resolution.index(
                        curL1Res)] = sat_mask_app.getoutput().get("out")
                tmp_sat_resample = os.path.join(
                    working,
                    "tmp_extract_roi_sat_resample_{}.tif".format(curL1Res))
                sat_resamp_app = resample(sat_mask_app.getoutput().get("out"),
                                          dtm_coarse,
                                          tmp_sat_resample,
                                          OtbResampleType.LINEAR,
                                          write_output=False)
                self._sub_sat_pipeline.add_otb_app(sat_resamp_app)
                for l1band in listOfL1Bands:
                    l1BandIdx = l_BandsDefinitions.get_band_id_in_l1(l1band)
                    tmp_sat_roi = os.path.join(
                        working, "tmp_extract_roi_sat_{}.tif".format(l1band))
                    tmp_sat_roi_app = extract_roi(
                        sat_resamp_app.getoutput().get("out"), [
                            self.m_headerHandler.get_l1_sat_image_index(
                                l1BandIdx) - 1
                        ],
                        tmp_sat_roi,
                        write_output=False)
                    self._sub_sat_pipeline.add_otb_app(tmp_sat_roi_app)
                    self._satmasksublist[
                        l1BandIdx] = tmp_sat_roi_app.getoutput().get("out")
            else:
                raise MajaExceptionPluginSentinel2Muscate(
                    "Product format not supported : not the same file for band on SAT"
                )

            # No_data mask at L2 coarse
            if l_isNoDataSameFilesForBands:
                ndt_mask = os.path.join(
                    working, "L2_NDT_VecMasks_{}.tif".format(curL1Res))
                l_StrBandIdL1 = listOfL1Bands[0]
                l1BandIdx = l_BandsDefinitions.get_band_id_in_l1(l_StrBandIdL1)
                l_NoDataFilename = noDataMaskFileNames[l1BandIdx]
                param_bintovec_ndt = {
                    "im": l_NoDataFilename,
                    "out": ndt_mask + ":uint8",
                    "nbcomp": nbL1Bands
                }
                ndt_mask_app = OtbAppHandler("BinaryToVector",
                                             param_bintovec_ndt,
                                             write_output=False)
                self._subedg_pipeline.add_otb_app(ndt_mask_app)
                tmp_ndt_resample = os.path.join(
                    working,
                    "tmp_extract_roi_ndt_resample_{}.tif".format(curL1Res))
                ndt_resamp_app = resample(ndt_mask_app.getoutput().get("out"),
                                          dtm_coarse,
                                          tmp_ndt_resample,
                                          OtbResampleType.LINEAR,
                                          write_output=False)
                self._subedg_pipeline.add_otb_app(ndt_resamp_app)
                for l1band in listOfL1Bands:
                    l1BandIdx = l_BandsDefinitions.get_band_id_in_l1(l1band)
                    tmp_ndt_roi = os.path.join(
                        working, "tmp_extract_roi_ndt_{}.tif".format(l1band))
                    tmp_ndt_roi_app = extract_roi(
                        ndt_resamp_app.getoutput().get("out"), [
                            self.m_headerHandler.get_l1_ndt_image_index(
                                l1BandIdx) - 1
                        ],
                        tmp_ndt_roi,
                        write_output=False)
                    self._subedg_pipeline.add_otb_app(tmp_ndt_roi_app)
                    self._nodatamasksublist[
                        l1BandIdx] = tmp_ndt_roi_app.getoutput().get("out")
            else:
                raise MajaExceptionPluginSentinel2Muscate(
                    "Product format not supported : not the same file for band on NoData"
                )

            # Detectors FootPrint Masks Generation
            # Get all the detectors files realted to this resolution
            # Test if they all refers to the same files
            tmp_res_det_filenames = None
            all_same_det_for_bands = True
            for l_BandIdxL1 in range(len(listOfL1Bands)):
                # Get the L1 band index associated to the L2 band code
                l_StrBandIdL1 = listOfL1Bands[l_BandIdxL1]
                l1BandIdx = l_BandsDefinitions.get_band_id_in_l1(l_StrBandIdL1)
                LOGGER.debug(
                    "Sentinel2MuscateL1ImageFileReader::GenerateMaskRasters: CurrentResol = %s, reading the "
                    "BandId L1 (associated) <%s> with index <%s>.", curL1Res,
                    l_StrBandIdL1, l1BandIdx)
                # Detectors FootPrint Masks
                l_bandDetFnames = zoneMaskFileNames[l1BandIdx]
                if tmp_res_det_filenames is not None:
                    if len(tmp_res_det_filenames) != len(l_bandDetFnames):
                        all_same_det_for_bands = False
                        break
                else:
                    tmp_res_det_filenames = l_bandDetFnames
            #Construct file and det number list
            tmp_list_of_detf_filenames = []
            tmp_list_of_detf_num = []
            tmp_list_of_band_idx = []
            if all_same_det_for_bands:
                l_ListOfZone = self.m_headerHandler.get_list_of_zones(
                    listOfL1Bands[0])
                nbDetector = len(l_ListOfZone)
                # For each detector of the current band
                for det in range(nbDetector):
                    tmp_list_of_detf_filenames.append(
                        tmp_res_det_filenames[l_ListOfZone[det]])
                    tmp_list_of_detf_num.append(str(int(l_ListOfZone[det])))
            else:
                #some bands are not in all det rare case
                tmp_det_info_map = {}
                for l_BandIdxL1 in range(len(listOfL1Bands)):
                    # Get the L1 band index associated to the L2 band code
                    l_StrBandIdL1 = listOfL1Bands[l_BandIdxL1]
                    l1BandIdx = l_BandsDefinitions.get_band_id_in_l1(
                        l_StrBandIdL1)
                    LOGGER.debug(
                        "Sentinel2MuscateL1ImageFileReader::GenerateMaskRasters: CurrentResol = %s, reading the "
                        "BandId L1 (associated) <%s> with index <%s>.",
                        curL1Res, l_StrBandIdL1, l1BandIdx)
                    # Detectors FootPrint Masks
                    l_bandDetFnames = zoneMaskFileNames[l1BandIdx]
                    l_ListOfZone = self.m_headerHandler.get_list_of_zones(
                        l_StrBandIdL1)
                    nbDetector = len(l_ListOfZone)
                    # For each detector of the current band
                    for det in range(nbDetector):
                        det_num = l_ListOfZone[det]
                        if det_num not in tmp_det_info_map.keys():
                            tmp_det_info_map[det_num] = (
                                zoneMaskFileNames[l1BandIdx][det_num],
                                [0] * len(listOfL1Bands))
                        tmp_det_info_map[det_num][1][l_BandIdxL1] = \
                            self.m_headerHandler.get_l1_dtf_image_index(l1BandIdx, det_num)[0]
                #once the info map is done
                for det in tmp_det_info_map.keys():
                    det_info = tmp_det_info_map[det]
                    tmp_list_of_detf_filenames.append(det_info[0])
                    tmp_list_of_detf_num.append(str(int(det)))
                    for x in det_info[1]:
                        tmp_list_of_band_idx.append(str(x))
            #create params
            detf_mask = os.path.join(working,
                                     "L1_DETF_Masks_{}.tif".format(curL1Res))
            param_dispacth_zone = {
                "il": tmp_list_of_detf_filenames,
                "out": detf_mask + ':uint8',
                "nbcomp": len(listOfL1Bands),
                "outvals": tmp_list_of_detf_num
            }
            #handle not all det/band case
            if not all_same_det_for_bands:
                param_dispacth_zone["outindexes"] = tmp_list_of_band_idx
            #Call the app
            dispatch_app = OtbAppHandler("DispatchZonesToVector",
                                         param_dispacth_zone,
                                         write_output=True)
            #This is the L2 output
            if curL1Res in l_ListOfL2Resolution:
                self._l2zoneimagelist[l_ListOfL2Resolution.index(
                    curL1Res)] = dispatch_app.getoutput().get("out")
            #extract the coarse bands
            for l1band in listOfL1Bands:
                l1BandIdx = l_BandsDefinitions.get_band_id_in_l1(l1band)
                tmp_zone_roi = os.path.join(
                    working, "tmp_extract_roi_ndt_{}.tif".format(l1band))
                tmp_zone_roi_app = extract_roi(
                    dispatch_app.getoutput().get("out"), [
                        self.m_headerHandler.get_l1_ndt_image_index(l1BandIdx)
                        - 1
                    ],
                    tmp_zone_roi,
                    write_output=False)
                self._subedg_pipeline.add_otb_app(tmp_zone_roi_app)
                tmp_zone_with_nodata = os.path.join(
                    working, "tmp_zone_with_nodata_{}".format(curL1Res))
                masterExpr = "( im1b1 > 0 ) ? im1b1 : -10000"
                param_bandmath_zone = {
                    "il": [tmp_zone_roi_app.getoutput().get("out")],
                    "exp": masterExpr,
                    "out": tmp_zone_with_nodata
                }
                zone_thresh_bandmath_app = OtbAppHandler("BandMathDouble",
                                                         param_bandmath_zone,
                                                         write_output=False)
                # LAIG-FA-MAC-1652-CNES : probleme reech detecteur en unsigned char : detecteur 1 devient 0.....
                tmp_zone_resample = os.path.join(
                    working,
                    "tmp_extract_roi_zone_resample_{}.tif".format(l1BandIdx))
                zone_resample_app = resample(
                    zone_thresh_bandmath_app.getoutput().get("out"),
                    dtm_coarse,
                    tmp_zone_resample,
                    OtbResampleType.LINEAR,
                    write_output=False)
                # threshold everything negative to 0
                Thresholdexpr = "im1b1 > 0 ? im1b1 : 0"
                tmp_zone_threshold = os.path.join(
                    working, "tmp_zone_threshold_{}".format(l1BandIdx))
                param_bandmath_zone_threshold = {
                    "il": [zone_resample_app.getoutput().get("out")],
                    "exp": Thresholdexpr,
                    "out": tmp_zone_threshold
                }
                zone_bandmath_threshold_app = OtbAppHandler(
                    "BandMathDouble",
                    param_bandmath_zone_threshold,
                    write_output=False)
                # Rounding
                tmp_zone_round = os.path.join(
                    working, "tmp_zone_round_{}".format(l1BandIdx))
                param_bandmath_zone_round = {
                    "im": zone_bandmath_threshold_app.getoutput().get("out"),
                    "out": tmp_zone_round
                }
                zone_round_app = OtbAppHandler("RoundImage",
                                               param_bandmath_zone_round,
                                               write_output=True)
                # Add to the official output
                self._zonemasksublist[l1BandIdx] = zone_round_app.getoutput(
                ).get("out")
                # Log current loop
                LOGGER.debug("band loop: " + str(l1BandIdx + 1) + " / " +
                             str(nbL1Bands) + " (" + curL1Res + ")")
            # band loop
            LOGGER.debug("band loop: END")
            self._l2_detf_pipeline.free_otb_app()
    def generate_sol1_image(self, sol_h1, working_dir):
        LOGGER.debug("VenusMuscateL1ImageFileReader::GenerateSOL1Image()")
        # SOL1 image pipeline connection
        # *********************************************************************************************************

        LOGGER.debug("MuscateL1ImageFileReader::GenerateSOL1Image()")
        l_SOL1_DX_ImageFileName = self._header_handler.get_sol_image_filename(
            sol_h1, "DX")
        LOGGER.debug("l_SOL1_DX_ImageFileName :" + l_SOL1_DX_ImageFileName)
        l_SOL1_DY_ImageFileName = self._header_handler.get_sol_image_filename(
            sol_h1, "DY")
        LOGGER.debug("l_SOL1_DY_ImageFileName :" + l_SOL1_DY_ImageFileName)

        # SOL1 image pipeline connection
        # *********************************************************************************************************
        # Read the vector images containing the SOL DX and DY
        # Extract the corresponding channels since it is vector images
        m_SOL1ExtractDXChannel = self._header_handler.get_sol_image_index(
            sol_h1, "DX")[0]
        # --------------------------------------
        # Transform the image coordinates in ground coordinates by multiplying by the L1 product spacing (spec : ImageToGround)
        # All viewing and solar angles are transformed in ground coordinates
        sol1_mult_DX_filename = os.path.join(working_dir, "sol1_mult_DX.tif")
        sol1_mult_DX_app = band_math([l_SOL1_DX_ImageFileName],
                                     "im1b" + str(m_SOL1ExtractDXChannel) +
                                     "*" +
                                     str(self._dem.L2Areas[0].spacing[0]),
                                     sol1_mult_DX_filename + ":double",
                                     write_output=False)

        # DY Stuff
        m_SOL1ExtractDYChannel = self._header_handler.get_sol_image_index(
            sol_h1, "DY")[0]
        # --------------------------------------
        # Transform the image coordinates in ground coordinates by multiplying by the L1 product spacing (spec : ImageToGround)
        # All viewing and solar angles are transformed in ground coordinates
        # x(-1) if the spacing Y is negative
        sol1_mult_DY_filename = os.path.join(working_dir, "sol1_mult_DY.tif")
        sol1_mult_DY_app = band_math([l_SOL1_DY_ImageFileName],
                                     "im1b" + str(m_SOL1ExtractDYChannel) +
                                     "* -1.0 *" +
                                     str(self._dem.L2Areas[0].spacing[1]),
                                     sol1_mult_DY_filename + ":double",
                                     write_output=False)
        # Concatenate DX and DY
        out_concatenate = os.path.join(working_dir, "sol1_concat.tif")
        param_concatenate = {
            "il": [
                sol1_mult_DX_app.getoutput().get("out"),
                sol1_mult_DY_app.getoutput().get("out")
            ],
            "out":
            out_concatenate
        }
        concat_app = OtbAppHandler("ConcatenateDoubleImages",
                                   param_concatenate,
                                   write_output=False)
        # Resample the SOL images
        out_resample = os.path.join(working_dir, "sol1_concat_resamp.tif")
        resamp_app = resample(concat_app.getoutput().get("out"),
                              self._dem.ALC,
                              out_resample,
                              OtbResampleType.LINEAR,
                              padradius=4,
                              write_output=True)
        # , 0 /* edgePaddingValue */)
        # V 4.2 - ITK4                m_SOL1Expand->SetEdgePaddingValue(0)
        # Par defaut le filtre initialise le pixel a zero
        self._sol1image = resamp_app.getoutput().get("out")
    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"))
コード例 #10
0
    def run(self, dict_of_input, dict_of_output):
        LOGGER.info("Cloud mask resampling start")
        p_working = dict_of_input.get("AppHandler").get_directory_manager().get_temporary_directory("CloudMaskResampling_",
                                            do_always_remove=True)
        bands_definition = dict_of_input.get("Plugin").BandsDefinitions
        do_write = is_croco_on("cloudmaskresampling")
        l2_cld_list = []
        for p_res in range(0, len(bands_definition.ListOfL2Resolution)):
            l_res = bands_definition.ListOfL2Resolution[p_res]
            # ---------- Resample All to resolution ---------------
            cld_all_resampled = os.path.join(p_working, "cloud_all_" + l_res + ".tif")
            cld_all_app = resample(dict_of_output[CLOUD_MASK_ALL], dict_of_input.get("DEM").ALTList[p_res],
                     cld_all_resampled, OtbResampleType.LINEAR,threshold=0.25,write_output=do_write)
            self._apps.add_otb_app(cld_all_app)
            dict_of_output[CLOUD_MASK_ALL + "_" + l_res] = cld_all_app.getoutput().get("out")
            # ---------- Resample All cloud to resolution ---------------
            cld_allclouds_resampled = os.path.join(p_working, "cloud_allclouds_" + l_res + ".tif")
            cld_allclouds_app = resample(dict_of_output[CLOUD_MASK_ALL_CLOUDS], dict_of_input.get("DEM").ALTList[p_res],
                     cld_allclouds_resampled, OtbResampleType.LINEAR,threshold=0.25,write_output=do_write)
            self._apps.add_otb_app(cld_allclouds_app)
            dict_of_output[CLOUD_MASK_ALL_CLOUDS + "_" + l_res] = cld_allclouds_app.getoutput().get("out")
            # ---------- Resample shadow to resolution ---------------
            cld_shadows_resampled = os.path.join(p_working, "cloud_shadows_" + l_res + ".tif")
            cld_shadows_app = resample(dict_of_output[CLOUD_MASK_SHADOWS], dict_of_input.get("DEM").ALTList[p_res],
                     cld_shadows_resampled, OtbResampleType.LINEAR,threshold=0.25,write_output=do_write)
            self._apps.add_otb_app(cld_shadows_app)
            dict_of_output[CLOUD_MASK_SHADOWS + "_" + l_res] = cld_shadows_app.getoutput().get("out")
            # ---------- Resample shadvar to resolution ---------------
            cld_shadvar_resampled = os.path.join(p_working, "cloud_shadvar_" + l_res + ".tif")
            cld_shadvar_app = resample(dict_of_output[CLOUD_MASK_SHADVAR], dict_of_input.get("DEM").ALTList[p_res],
                     cld_shadvar_resampled, OtbResampleType.LINEAR,threshold=0.25,write_output=do_write)
            self._apps.add_otb_app(cld_shadvar_app)
            dict_of_output[CLOUD_MASK_SHADVAR + "_" + l_res] = cld_shadvar_app.getoutput().get("out")
            # ---------- Resample Refl cloud to resolution ---------------
            cld_refl_resampled = os.path.join(p_working, "cloud_refl_" + l_res + ".tif")
            cld_refl_app = resample(dict_of_output[CLOUD_MASK_REFL], dict_of_input.get("DEM").ALTList[p_res], cld_refl_resampled,
                     OtbResampleType.LINEAR,threshold=0.25,write_output=do_write)
            self._apps.add_otb_app(cld_refl_app)
            dict_of_output[CLOUD_MASK_REFL + "_" + l_res] = cld_refl_app.getoutput().get("out")
            # ---------- Resample ReflVar cloud to resolution ---------------
            cld_reflvar_resampled = os.path.join(p_working, "cloud_reflvar_" + l_res + ".tif")
            cld_reflvar_app = resample(dict_of_output[CLOUD_MASK_REFL_VAR], dict_of_input.get("DEM").ALTList[p_res],
                     cld_reflvar_resampled,
                     OtbResampleType.LINEAR,threshold=0.25,write_output=do_write)
            self._apps.add_otb_app(cld_reflvar_app)
            dict_of_output[CLOUD_MASK_REFL_VAR + "_" + l_res] = cld_reflvar_app.getoutput().get("out")
            # ---------- Resample Extension cloud to resolution ---------------
            cld_ext_resampled = os.path.join(p_working, "cloud_ext_" + l_res + ".tif")
            cld_ext_app = resample(dict_of_output[CLOUD_MASK_EXTENSION], dict_of_input.get("DEM").ALTList[p_res], cld_ext_resampled,
                     OtbResampleType.LINEAR,threshold=0.25,write_output=do_write)
            self._apps.add_otb_app(cld_ext_app)
            dict_of_output[CLOUD_MASK_EXTENSION + "_" + l_res] = cld_ext_app.getoutput().get("out")
            # ---------- Resample Alt to resolution ---------------
            cld_alt_resampled = os.path.join(p_working, "cloud_alt_" + l_res + ".tif")
            cld_alt_app = resample(dict_of_output[CLOUD_MASK_ALT], dict_of_input.get("DEM").ALTList[p_res], cld_alt_resampled,
                     OtbResampleType.LINEAR,threshold=0.25,write_output=do_write)
            self._apps.add_otb_app(cld_alt_app)
            dict_of_output[CLOUD_MASK_ALT + "_" + l_res] = cld_alt_app.getoutput().get("out")
            # ---------- Resample Cirrus cloud to resolution ---------------
            cld_cirrus_resampled = os.path.join(p_working, "cloud_cirrus_" + l_res + ".tif")
            cld_cirrus_app = resample(dict_of_output[CLOUD_MASK_CIRRUS], dict_of_input.get("DEM").ALTList[p_res], cld_cirrus_resampled,
                     OtbResampleType.LINEAR,threshold=0.25,write_output=do_write)
            self._apps.add_otb_app(cld_cirrus_app)
            dict_of_output[CLOUD_MASK_CIRRUS + "_" + l_res] = cld_cirrus_app.getoutput().get("out")

            # APRES MEMORY IN CHAIN CORE ALGORITHMS : V 4-1-0
            #                    Bit 1 - Cloud_Mask.all : summary Logical or of All cloud, extension and shadow masks
            #                    Bit 2 - Cloud_Mask.all clouds: Logical or of All cloud masks and extension
            #                    Bit 3 - Cloud_Mask.shadows : shadows mask from clouds within image
            #                    Bit 4 - Cloud_Mask.shadvar: shadows mask from clouds outside image bit 1 : Cloud_Mask.all
            #                    Bit 5 - Cloud_Mask.refl : reflectance threshold
            #                    Bit 6 - Cloud_Mask.refl_var : reflectance variation threshold
            #                    Bit 7 - Cloud_Mask.extension : extension of the cloud mask
            #                        Bit 8 - Cloud_Mask.alt : stereoscopic mask  =>  VENUS et vide pour les autres
            #                    Bit 9 - Cirrus : Pour  L8 et S2 et vide pour les autres

            # FORMAT DISK
            #                    Bit 1 - Cloud_Mask.all : summary Logical or of All cloud and shadow masks
            #                    Bit 2 - Cloud_Mask.all clouds: Logical or of All cloud masks
            #                    Bit 3 - Cloud_Mask.shadows : shadows mask from clouds within image
            #                    Bit 4 - Cloud_Mask.shadvar: shadows mask from clouds outside image bit 1 : Cloud_Mask.all
            #                    Bit 5 - Cloud_Mask.refl : reflectance threshold
            #                    Bit 6 - Cloud_Mask.refl_var : reflectance variation threshold
            #                    Bit 7 - Cloud_Mask.extension : extension of the cloud mask
            #                    Bit 8 - VENUS : Cloud_Mask.alt : stereoscopic mask
            #                    Bit 8 - L8 et S2 : Bit 9 - Cirrus
            #                    Bit 8 - Vide pour les autres
            cld_list = []
            cld_list.append(dict_of_output[CLOUD_MASK_ALL + "_" + l_res])
            cld_list.append(dict_of_output[CLOUD_MASK_ALL_CLOUDS + "_" + l_res])
            cld_list.append(dict_of_output[CLOUD_MASK_SHADOWS + "_" + l_res])
            cld_list.append(dict_of_output[CLOUD_MASK_SHADVAR + "_" + l_res])
            cld_list.append(dict_of_output[CLOUD_MASK_REFL + "_" + l_res])
            cld_list.append(dict_of_output[CLOUD_MASK_REFL_VAR + "_" + l_res])
            cld_list.append(dict_of_output[CLOUD_MASK_EXTENSION + "_" + l_res])
            cld_list.append(dict_of_output[CLOUD_MASK_ALT + "_" + l_res])
            cld_list.append(dict_of_output[CLOUD_MASK_CIRRUS + "_" + l_res])
            l2_cld_list.append(cld_list)


        dict_of_output["L2CLDList"] = l2_cld_list
コード例 #11
0
    def get_viewing_grids(self, band, l2CoarseArea, projectionRef, vieHRef,
                          satFilename, zoneFilename, nodataFilename,
                          listOfZone, boundingBox, viewing_angles,
                          gdalRasterizeMaskCmd, gdalRasterizeDetCmd,
                          gdalRasterizeNdtCmd, nbCoarseBands, working):
        """

        :param band: int
        :param l2CoarseArea: AreaType
        :param projectionRef: string
        :param vieHRef: double
        :param satFilename: string
        :param zoneFilename: string
        :param nodataFilename: string
        :param listOfZone: ListOfUIntegers
        :param boundingBox: BoundingBoxType
        :param viewing_angles:
        :param gdalRasterizeMaskCmd: string
        :param gdalRasterizeDetCmd: string
        :param gdalRasterizeNdtCmd: string
        :return:
        """
        dtm_coarse = self._dem.ALC

        # Set a constant image if the gml masks are empty
        tmp_constant_filename = os.path.join(working, "Masks_sat_const.tif")
        constant_image(dtm_coarse,
                       0,
                       tmp_constant_filename + ":uint8",
                       write_output=True)

        # -----------------------------------------------------------------------------------
        # Rasterize all the gml maks at L2 coarse resolution
        # to generate the viewing grids
        # -----------------------------------------------------------------------------------

        # -----------------------------------------------------------------------------------
        # Detectors FootPrint
        # check if the gml mask contains features
        count = self.get_mask_feature_count(zoneFilename)

        if count > 0:
            # Get the shift between the detector index and the feature index
            shift_res = self.get_detfoo_index_shift(zoneFilename)

            if shift_res[0]:
                l_image_raster_filename = os.path.join(
                    working, "SubZoneMask_band_id_{}.tif".format(band))
                # Additional parameters of the gdal_rasterize system command
                sqlRequest = gdalRasterizeDetCmd + \
                    "-a fid2 -sql 'select fid + {} as fid2, * from MaskFeature'".format(shift_res[1])

                GdalRasterize().internal_rasterize_gml_macro(
                    zoneFilename, boundingBox.xmin, boundingBox.ymin,
                    boundingBox.xmax, boundingBox.ymax, l2CoarseArea.size[0],
                    l2CoarseArea.size[1], projectionRef,
                    l_image_raster_filename, sqlRequest)

                submask_resamp_filename = os.path.join(
                    working,
                    "SubZoneMask_resampled_band_id_{}.tif".format(band))
                resample(l_image_raster_filename, dtm_coarse,
                         submask_resamp_filename, OtbResampleType.LINEAR)

                self._zonemasksublist.append(submask_resamp_filename)
            else:
                LOGGER.debug("Bad Order DETFOO detected")
                l_image_raster_filename = os.path.join(
                    working, "SubZoneMask_band_id_{}.tif".format(band))
                # Additional parameters of the gdal_rasterize system command
                sqlRequest = gdalRasterizeDetCmd + \
                             "-a fid2 -sql 'select fid + 1 as fid2, * from MaskFeature'"

                GdalRasterize().internal_rasterize_gml_macro(
                    zoneFilename, boundingBox.xmin, boundingBox.ymin,
                    boundingBox.xmax, boundingBox.ymax, l2CoarseArea.size[0],
                    l2CoarseArea.size[1], projectionRef,
                    l_image_raster_filename, sqlRequest)
                l_fid_dets = self.get_detfoo_index_detector_list(
                    zoneFilename, 1)
                l_image_changed_filename = os.path.join(
                    working, "SubZoneMaskChanged_band_id_{}.tif".format(band))
                change_values_param = {
                    "im": l_image_raster_filename,
                    "out": l_image_changed_filename + ":uint8",
                    "invals": [str(a) for a in l_fid_dets.keys()],
                    "outvals": [str(a) for a in l_fid_dets.values()]
                }
                change_values_app = OtbAppHandler("ChangeValues",
                                                  change_values_param)

                submask_resamp_filename = os.path.join(
                    working,
                    "SubZoneMask_resampled_band_id_{}.tif".format(band))
                resample(change_values_app.getoutput().get("out"), dtm_coarse,
                         submask_resamp_filename, OtbResampleType.LINEAR)

                self._zonemasksublist.append(submask_resamp_filename)

        else:
            submask_resamp_filename = os.path.join(
                working, "SubZoneMask_resampled_band_id_{}.tif".format(band))
            resample(tmp_constant_filename, dtm_coarse,
                     submask_resamp_filename, OtbResampleType.LINEAR)
            self._zonemasksublist.append(submask_resamp_filename)

        # -----------------------------------------------------------------------------------
        # Saturated pixel mask at L2 coarse
        count = self.get_mask_feature_count(satFilename)

        if count > 0:
            l_image_raster_filename = os.path.join(
                working, "SubSatMask_band_id_{}.tif".format(band))
            GdalRasterize().internal_rasterize_gml_macro(
                satFilename, boundingBox.xmin, boundingBox.ymin,
                boundingBox.xmax, boundingBox.ymax, l2CoarseArea.size[0],
                l2CoarseArea.size[1], projectionRef, l_image_raster_filename,
                gdalRasterizeMaskCmd)
            self._satmasksublist.append(l_image_raster_filename)
        else:
            self._satmasksublist.append(tmp_constant_filename)

        # -----------------------------------------------------------------------------------
        # No_data mask at L2 coarse
        count = self.get_mask_feature_count(nodataFilename, "NODATA")

        if count > 0:
            l_image_raster_filename = os.path.join(
                working, "SubNoDataMask_band_id_{}.tif".format(band))
            GdalRasterize().internal_rasterize_gml_macro(
                nodataFilename, boundingBox.xmin, boundingBox.ymin,
                boundingBox.xmax, boundingBox.ymax, l2CoarseArea.size[0],
                l2CoarseArea.size[1], projectionRef, l_image_raster_filename,
                gdalRasterizeNdtCmd)
            self._nodatamasksublist.append(l_image_raster_filename)
        else:
            self._nodatamasksublist.append(tmp_constant_filename)

        l_VieAnglesGridList = []
        l_nbDetectors = len(viewing_angles)

        # Detector loop
        LOGGER.debug("For each detectors (nb=%s) ...", l_nbDetectors)
        for angle in viewing_angles:
            l_vieAngleFile = angle.write(working)
            # ---------------------------------------------------------------------------------
            # Generate an image with the list of viewing angle values set in the header file
            # ---------------------------------------------------------------------------------
            viewing_grid_filename = os.path.join(
                working,
                "viewing_grid_{}_{}.tif".format(angle.detector_id, band))

            # angle_list_to_image()
            viewing_angle_app = angle_list_to_image(dtm_coarse,
                                                    l_vieAngleFile,
                                                    viewing_grid_filename,
                                                    write_output=False,
                                                    extrapolation=True)

            # Expand at L2Coarse.
            viewing_grid_resamp_filename = os.path.join(
                working,
                "viewing_grid_resamp_{}_{}.tif".format(angle.detector_id,
                                                       band))
            resample(viewing_angle_app.getoutput().get("out"), dtm_coarse,
                     viewing_grid_resamp_filename, OtbResampleType.LINEAR)

            # add images in a list
            l_VieAnglesGridList.append(viewing_grid_resamp_filename)

        # end detector loop
        LOGGER.debug(
            "Start ConcatenatePerZoneVectorImageFilter for band id [%s]...",
            band)

        # -----------------------------------------------------------------------------------
        # Generate the angle images using the zone (detector) mask
        # -----------------------------------------------------------------------------------
        # Concatenate all the detectors
        viewing_concat_filename = os.path.join(
            working, "viewing_concat_{}.tif".format(band))
        param_concat_perzone = {
            "mask": self._zonemasksublist[-1],
            "il": l_VieAnglesGridList,
            "zonelist": listOfZone,
            "out": viewing_concat_filename
        }
        concat_perzone = OtbAppHandler("ConcatenatePerZone",
                                       param_concat_perzone)
        # Multiply by reference altitude
        viewing_grid_mult_filename = os.path.join(
            working, "viewing_grid_mult_{}.tif".format(band))
        param_scaled_solar = {
            "im": viewing_concat_filename,
            "coef": float(vieHRef),
            "out": viewing_grid_mult_filename
        }
        view_scale_app = OtbAppHandler("MultiplyByScalar",
                                       param_scaled_solar,
                                       write_output=True)
        self._vieimagelist.append(view_scale_app.getoutput().get("out"))

        l_nbZones = len(listOfZone)
        LOGGER.debug("Start Loop for Zone (nb=" + str(l_nbZones) + ")...")
        for d in range(l_nbZones):
            l_zone = listOfZone[d]
            # -----------------------------------------------------------------------------------
            # Compute average values of zenithal and azimuthal angles grid per zone (detector in level1B)
            # -----------------------------------------------------------------------------------
            # VAP Reader connection (from ATB)
            tmp_azi = os.path.join(working,
                                   "tmp_azi_{}_{}.tif".format(band, l_zone))
            tmp_azi_image = extract_roi(l_VieAnglesGridList[d], [1], tmp_azi)
            param_stats = {
                "im": tmp_azi,
                "exclude": 1,
                "mask": self._zonemasksublist[band],
                "maskforeground": int(l_zone)
            }
            l2_stat = OtbAppHandler("Stats", param_stats)

            azi_mean = l2_stat.getoutput().get("mean")
            tmp_zen = os.path.join(working,
                                   "tmp_zen_{}_{}.tif".format(band, l_zone))
            tmp_zen_image = extract_roi(l_VieAnglesGridList[d], [0], tmp_zen)
            param_stats = {
                "im": tmp_zen,
                "exclude": 1,
                "mask": self._zonemasksublist[band],
                "maskforeground": int(l_zone)
            }
            l2_stat = OtbAppHandler("Stats", param_stats)
            zen_mean = l2_stat.getoutput().get("mean")
            tmp_mean = (zen_mean, azi_mean)
            l_ViewingAngleMean = grid_to_angle(tmp_mean)
            l_ViewingAngleMeanDeg = (l_ViewingAngleMean[0] * 180.0 / math.pi,
                                     l_ViewingAngleMean[1] * 180.0 / math.pi)
            # Add a vector to mean maps
            if l_zone not in self._meanZenithMap:
                self._meanZenithMap[listOfZone[d]] = ["0"] * nbCoarseBands
            if l_zone not in self._meanAzimuthMap:
                self._meanAzimuthMap[listOfZone[d]] = ["0"] * nbCoarseBands
            self._meanZenithMap[listOfZone[d]][band] = str(
                l_ViewingAngleMeanDeg[0])
            self._meanAzimuthMap[listOfZone[d]][band] = str(
                l_ViewingAngleMeanDeg[1])
            LOGGER.debug(" For BandId[" + str(band) + "], zone [" +
                         str(listOfZone[d]) + "]  . Mean 'GRID View angles'=" +
                         str(tmp_mean) + " . Mean 'View angles'=" +
                         str(l_ViewingAngleMean[0]) + ":" +
                         str(l_ViewingAngleMean[1]) + " rad. ou  " +
                         str(l_ViewingAngleMeanDeg[0]) + ":" +
                         str(l_ViewingAngleMeanDeg[1]) + " deg.")
        LOGGER.debug("Start Loop for Zone done.")
    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]
コード例 #13
0
    def read_private_images(self, p_L2PrivateImageFilenamesProvider,
                            p_ReflectanceQuantificationValue, p_PluginBase,
                            working_dir):
        l_NumberOfComponentsPerPixelForPWAAndTWA = len(
            p_PluginBase.BandsDefinitions.L2CoarseBandMap)

        # *************************************************************************************************************
        # Register the Header for the L2 Input image file
        # *************************************************************************************************************
        l_ReflectanceQuantificationValue = p_ReflectanceQuantificationValue
        # Read the  list of wavelength of the RTA/RTC and RCR list of bands in the HDR xml header file
        l_RTAHeaderFilename = p_L2PrivateImageFilenamesProvider.get_rta_header_filename(
        )
        l_RTAHandler = HeaderImageEarthExplorerXMLFileHandler(
            l_RTAHeaderFilename)
        self.ListOfBandTheoreticalWavelengthOfTheReflectancesComposite = l_RTAHandler.get_list_of_band_theoretical_wavelength(
        )

        # ********************************************************************************************************/
        # #* RTA Reader connection */
        LOGGER.debug(
            "L2ImageFileReaderBase::ReadPrivateImages - RTA image filename: " +
            p_L2PrivateImageFilenamesProvider.get_rta_image_filename() + ".")

        tmp_rta_resample = os.path.join(working_dir, "tmp_rta_resample.tif")
        app_rta_resample = resample(
            p_L2PrivateImageFilenamesProvider.get_rta_image_filename(),
            self._dem.ALC,
            tmp_rta_resample,
            OtbResampleType.BCO,
            padradius=4.0,
            write_output=False)
        tmp_rta_scale = os.path.join(working_dir, "tmp_rta_scale.tif")
        param_scaled_rta = {
            "im": app_rta_resample.getoutput().get("out"),
            "coef": l_ReflectanceQuantificationValue,
            "out": tmp_rta_scale
        }
        rta_scal_app = OtbAppHandler("MultiplyByScalar",
                                     param_scaled_rta,
                                     write_output=True)
        self._coarse_pipeline.add_otb_app(rta_scal_app)
        self._coarse_pipeline.add_otb_app(app_rta_resample)
        self.dict_of_vals["RTAImage"] = rta_scal_app.getoutput()["out"]
        # ********************************************************************************************************/
        # * RTC Reader connection */
        # ********************************************************************************************************/
        LOGGER.debug(
            "L2ImageFileReaderBase::ReadPrivateImages - RTC image filename: " +
            p_L2PrivateImageFilenamesProvider.get_rtc_image_filename() + ".")

        tmp_rtc_resample = os.path.join(working_dir, "tmp_rtc_resample.tif")
        app_rtc_resample = resample(
            p_L2PrivateImageFilenamesProvider.get_rtc_image_filename(),
            self._dem.ALC,
            tmp_rtc_resample,
            OtbResampleType.BCO,
            padradius=4.0,
            write_output=False)

        tmp_rtc_scale = os.path.join(working_dir, "tmp_rtc_scale.tif")
        param_scaled_rtc = {
            "im": app_rtc_resample.getoutput().get("out"),
            "coef": l_ReflectanceQuantificationValue,
            "out": tmp_rtc_scale
        }
        rtc_scal_app = OtbAppHandler("MultiplyByScalar",
                                     param_scaled_rtc,
                                     write_output=True)
        self._coarse_pipeline.add_otb_app(rtc_scal_app)
        self._coarse_pipeline.add_otb_app(app_rtc_resample)
        self.dict_of_vals["RTCImage"] = rtc_scal_app.getoutput()["out"]
        # ********************************************************************************************************/
        # * RCR Reader connection */
        # ********************************************************************************************************/
        LOGGER.debug(
            "L2ImageFileReaderBase::ReadPrivateImages - RCR image filename: " +
            p_L2PrivateImageFilenamesProvider.get_rcr_image_filename() + ".")
        tmp_rcr_resample = os.path.join(working_dir, "tmp_rcr_resample.tif")
        app_rcr_resample = resample(
            p_L2PrivateImageFilenamesProvider.get_rcr_image_filename(),
            self._dem.ALC,
            tmp_rcr_resample,
            OtbResampleType.BCO,
            padradius=4.0,
            write_output=False)
        tmp_rcr_scale = os.path.join(working_dir, "tmp_rcr_scale.tif")
        param_scaled_rcr = {
            "im": app_rcr_resample.getoutput().get("out"),
            "coef": l_ReflectanceQuantificationValue,
            "out": tmp_rcr_scale
        }
        rcr_scal_app = OtbAppHandler("MultiplyByScalar",
                                     param_scaled_rcr,
                                     write_output=True)
        self._coarse_pipeline.add_otb_app(rcr_scal_app)
        self._coarse_pipeline.add_otb_app(app_rcr_resample)

        self.dict_of_vals["RCRImage"] = rcr_scal_app.getoutput()["out"]
        # ********************************************************************************************************/
        # * PXD Reader connection */
        # ********************************************************************************************************/
        LOGGER.debug(
            "L2ImageFileReaderBase::ReadPrivateImages - PXD image filename: " +
            p_L2PrivateImageFilenamesProvider.get_pxd_image_filename() + ".")
        tmp_pxd_resample = os.path.join(working_dir, "tmp_pxd_resample.tif")
        app_pxd_resample = resample(
            p_L2PrivateImageFilenamesProvider.get_pxd_image_filename(),
            self._dem.ALC,
            tmp_pxd_resample,
            OtbResampleType.BCO,
            padradius=4.0,
            write_output=True)
        self._coarse_pipeline.add_otb_app(app_pxd_resample)
        self.dict_of_vals["PXDImage"] = app_pxd_resample.getoutput().get("out")

        # ********************************************************************************************************/
        # * WAS Reader connection (WAM product) */
        # ********************************************************************************************************/
        tmp_was = os.path.join(working_dir, "tmp_was.tif")
        was_extr_app = extract_roi(
            p_L2PrivateImageFilenamesProvider.get_wam_image_filename(), [0],
            tmp_was,
            write_output=False)

        tmp_was_resample = os.path.join(working_dir, "tmp_was_resample.tif")
        app_was_resample = resample(was_extr_app.getoutput().get("out"),
                                    self._dem.ALC,
                                    tmp_was_resample,
                                    OtbResampleType.BCO,
                                    padradius=4.0,
                                    write_output=True)
        self._coarse_pipeline.add_otb_app(was_extr_app)
        self._coarse_pipeline.add_otb_app(app_was_resample)
        self.dict_of_vals["WASImage"] = app_was_resample.getoutput()["out"]
        # ********************************************************************************************************/
        # * PWA Reader connection (WAM product) */
        # ********************************************************************************************************/
        tmp_pwa = os.path.join(working_dir, "tmp_pwa.tif")
        pwa_image_app = extract_roi(
            p_L2PrivateImageFilenamesProvider.get_wam_image_filename(), [1],
            tmp_pwa + ":uint8",
            write_output=False)
        self._coarse_pipeline.add_otb_app(pwa_image_app)

        tmp_pwa_resample = os.path.join(working_dir, "tmp_pwa_resample.tif")
        app_pwa_resample = resample(pwa_image_app.getoutput().get("out"),
                                    self._dem.ALC,
                                    tmp_pwa_resample,
                                    OtbResampleType.BCO,
                                    padradius=4.0,
                                    write_output=False)
        self._coarse_pipeline.add_otb_app(app_pwa_resample)

        tmp_vecpwa = os.path.join(working_dir, "tmp_pwa_vec.tif")
        param_binpwa = {
            "im": app_pwa_resample.getoutput()["out"],
            "out": tmp_vecpwa,
            "nbcomp": l_NumberOfComponentsPerPixelForPWAAndTWA
        }
        binpwa_app = OtbAppHandler("BinaryToVector",
                                   param_binpwa,
                                   write_output=True)
        self._coarse_pipeline.add_otb_app(binpwa_app)
        self.dict_of_vals["PWAImage"] = binpwa_app.getoutput()["out"]

        # ********************************************************************************************************/
        # * TWA Reader connection (WAM product) */
        # ********************************************************************************************************/
        tmp_twa = os.path.join(working_dir, "tmp_twa.tif")
        twa_image = extract_roi(
            p_L2PrivateImageFilenamesProvider.get_wam_image_filename(), [2],
            tmp_twa + ":uint8",
            write_output=False)

        tmp_twa_resample = os.path.join(working_dir, "tmp_twa_resample.tif")
        app_twa_resample = resample(twa_image.getoutput().get("out"),
                                    self._dem.ALC,
                                    tmp_twa_resample,
                                    OtbResampleType.BCO,
                                    padradius=4.0,
                                    write_output=False)
        self._coarse_pipeline.add_otb_app(app_twa_resample)

        tmp_vectwa = os.path.join(working_dir, "tmp_twa_vec.tif")
        param_bintwa = {
            "im": app_twa_resample.getoutput().get("out"),
            "out": tmp_vectwa,
            "nbcomp": l_NumberOfComponentsPerPixelForPWAAndTWA
        }
        bintwa_app = OtbAppHandler("BinaryToVector",
                                   param_bintwa,
                                   write_output=True)
        self._coarse_pipeline.add_otb_app(bintwa_app)
        self.dict_of_vals["TWAImage"] = bintwa_app.getoutput()["out"]

        # ********************************************************************************************************/
        # * STO Reader connection */
        # ********************************************************************************************************/
        l_STOHeaderFilename = p_L2PrivateImageFilenamesProvider.get_sto_header_filename(
        )
        l_STOHandler = HeaderImageEarthExplorerXMLFileHandler(
            l_STOHeaderFilename)

        try:
            self.STOBandTheoreticalWavelengthIsPresent = (
                l_STOHandler.get_theoretical_wavelength() is not None)
            self.STOBandTheoreticalWavelengthValue = l_STOHandler.get_theoretical_wavelength(
            )
        except BaseException:
            LOGGER.debug("Could not retrive STO wavelength !!!")

        # 4.3: Get the lis of date (in Bands nodes)
        self.STOListOfStringDates = l_STOHandler.get_list_of_bands()

        LOGGER.debug(
            "L2ImageFileReaderBase::ReadPrivateImages - STO image filename: " +
            p_L2PrivateImageFilenamesProvider.get_sto_image_filename() + ".")

        tmp_sto_resample = os.path.join(working_dir, "tmp_sto_resample.tif")
        app_sto_resample = resample(
            p_L2PrivateImageFilenamesProvider.get_sto_image_filename(),
            self._dem.ALC,
            tmp_sto_resample,
            OtbResampleType.BCO,
            padradius=4.0,
            write_output=False)
        self._coarse_pipeline.add_otb_app(app_sto_resample)

        tmp_sto_scale = os.path.join(working_dir, "tmp_sto_scale.tif")
        param_scaled_sto = {
            "im": app_sto_resample.getoutput().get("out"),
            "coef": l_ReflectanceQuantificationValue,
            "out": tmp_sto_scale
        }
        sto_scal_app = OtbAppHandler("MultiplyByScalar",
                                     param_scaled_sto,
                                     write_output=True)
        self._coarse_pipeline.add_otb_app(sto_scal_app)
        self.dict_of_vals["STOImage"] = sto_scal_app.getoutput()["out"]
        # ********************************************************************************************************/
        # * NDT Reader connection */
        # ********************************************************************************************************/
        LOGGER.debug(
            "L2ImageFileReaderBase::ReadPrivateImages - NDT image filename: " +
            p_L2PrivateImageFilenamesProvider.get_ndt_image_filename() + ".")

        tmp_ndt_resample = os.path.join(working_dir, "tmp_ndt_resample.tif")
        app_ndt_resample = resample(
            p_L2PrivateImageFilenamesProvider.get_ndt_image_filename(),
            self._dem.ALC,
            tmp_ndt_resample,
            OtbResampleType.BCO,
            padradius=4.0,
            threshold=0.25,
            write_output=True)
        self._coarse_pipeline.add_otb_app(app_ndt_resample)
        self.dict_of_vals["NDTImage"] = app_ndt_resample.getoutput().get("out")

        # 4-1-0 : HandlingConnectionCLD DM 1039
        #            #********************************************************************************************************/
        #            #* CLD sub (summary) Reader connection */
        #            #********************************************************************************************************/
        LOGGER.debug(
            "L2ImageFileReaderBase::ReadPrivateImages - CLD image filename: " +
            p_L2PrivateImageFilenamesProvider.get_cld_image_filename() + ".")

        # TODO ATTENTION m_CLDSubOutput est la sortie du Reader (donc pas toute le
        # s 9 bandes algo, ou laors sortie du m_ReorganizeBinaryCLDSub ??!!!
        self.dict_of_vals[
            "CLDSubImage"] = p_L2PrivateImageFilenamesProvider.get_cld_image_filename(
            )

        # MACCS 5.0.0 : DM 982 . Need CLD bands (for example extract Shadow and ShadVar bands in L2CoarseResolution)

        # For GetVectorizedCLDImageList method
        tmp_cld_vec = os.path.join(working_dir, "tmp_cld_vec.tif")
        param_vec_cld = {
            "im": p_L2PrivateImageFilenamesProvider.get_cld_image_filename(),
            "out": tmp_cld_vec,
            "nbcomp": len(p_PluginBase.CLDCoreAlgorithmsMapBand)
        }
        cld_vec_app = OtbAppHandler("BinaryToVector",
                                    param_vec_cld,
                                    write_output=False)
        self._coarse_pipeline.add_otb_app(cld_vec_app)
        cld_vec_image = cld_vec_app.getoutput()["out"]
        # In this case some cld bits are not available in the data
        tmp_cld_zero = os.path.join(working_dir, "tmp_cld_zero.tif")
        cld_const_zero_app = None
        if len(p_PluginBase.CLDCoreAlgorithmsMapBand) > len(
                p_PluginBase.CLDDataBandsSelected):
            cld_const_zero_app = constant_image(cld_vec_image,
                                                0,
                                                os.path.join(
                                                    working_dir,
                                                    "tmp_zero_cld.tif"),
                                                write_output=False)
            self._coarse_pipeline.add_otb_app(cld_const_zero_app)
        self.dict_of_vals["VectorizedCLDSubOutput"] = {}
        for b in list(p_PluginBase.CLDCoreAlgorithmsMapBand.keys()):
            if b in p_PluginBase.CLDDataBandsSelected:
                tmp_cld_chan = os.path.join(working_dir, "tmp_" + b + ".tif")
                chan = p_PluginBase.CLDDataBandsSelected.index(b)
                app_extract_cld = extract_roi(cld_vec_image, [chan],
                                              tmp_cld_chan,
                                              write_output=False)
                self._coarse_pipeline.add_otb_app(app_extract_cld)

                tmp_cld_resample = os.path.join(working_dir,
                                                "tmp_cld_resample.tif")
                app_cld_resample = resample(
                    app_extract_cld.getoutput().get("out"),
                    self._dem.ALC,
                    tmp_cld_resample,
                    OtbResampleType.BCO,
                    padradius=4.0,
                    threshold=0.25,
                    write_output=True)
                self._coarse_pipeline.add_otb_app(app_cld_resample)

                self.dict_of_vals["VectorizedCLDSubOutput"][
                    b] = app_cld_resample.getoutput()["out"]
            else:
                tmp_cld_resample = os.path.join(working_dir,
                                                "tmp_cld_resample.tif")
                app_cld_resample = resample(
                    cld_const_zero_app.getoutput()["out"],
                    self._dem.ALC,
                    tmp_cld_resample,
                    OtbResampleType.BCO,
                    padradius=4.0,
                    threshold=0.25,
                    write_output=True)
                self._coarse_pipeline.add_otb_app(app_cld_resample)

                self.dict_of_vals["VectorizedCLDSubOutput"][
                    b] = app_cld_resample.getoutput()["out"]

        # *************************************************************************************************************
        #  Generate a map of LUT containing all TOCR miniLUTs of the L2 product at D-1 (L2inTOCR)
        # *************************************************************************************************************
        if p_L2PrivateImageFilenamesProvider.get_dealing_ltc():
            LOGGER.debug(
                "L2ImageFileReaderBase::ReadPrivateImages - Start reading LTC ..."
            )
            l_Filename = p_L2PrivateImageFilenamesProvider.get_ltc_header_filename(
            )
            # --------------------------------------------
            # Load the XML file
            LOGGER.debug(
                "L2ImageFileReaderBase::Start loading the LTC header filename <"
                + l_Filename + "> ....")
            l_LUTXMLHandler = GippLUTEarthExplorerXMLFileHandler(l_Filename)

            self.ListOfBandTheoreticalWavelengthOfTheLTCComposite = \
                l_LUTXMLHandler.get_list_of_band_theoretical_wavelength()

            # Read the files
            l_L2P_LTC_ListOfFilenames = l_LUTXMLHandler.get_list_of_packaged_dbl_files(
                True, True)

            # convert the lut indexes
            new_lut_indexes = IndexesType()
            for ind, vals in list(l_LUTXMLHandler.get_lut_indexes().items()):
                if ind == "Solar_Zenith_Angle_Indexes":
                    new_lut_indexes.set_Solar_Zenith_Angle_Indexes(vals)
                elif ind == "Relative_Azimuth_Angle_Indexes":
                    new_lut_indexes.set_Relative_Azimuth_Angle_Indexes(vals)
                elif ind == "Altitude_Indexes":
                    new_lut_indexes.set_Altitude_Indexes(vals)
                elif ind == "AOT_Indexes":
                    new_lut_indexes.set_AOT_Indexes(vals)
                elif ind == "TOA_Reflectance_Indexes":
                    new_lut_indexes.set_TOA_Reflectance_Indexes(vals)
                elif ind == "Zenithal_Angle_Indexes":
                    new_lut_indexes.set_Zenithal_Angle_Indexes(vals)
                elif ind == "View_Zenith_Angle_Indexes":
                    new_lut_indexes.set_View_Zenith_Angle_Indexes(vals)
                elif ind == "Reflectance_Ratio_Indexes":
                    new_lut_indexes.set_Reflectance_Ratio_Indexes(vals)
                else:
                    raise MajaDataException("Unhandled lut index type : " +
                                            ind)

            # Initialize the LookUpTable reader
            # --------------------------------------------
            # Set the list of minilut filenames to the mapReader
            l_lutmap = LUTMap()
            l_JdayRef = date_utils.get_julianday_as_int(
                date_utils.get_datetime_from_yyyymmdd(
                    p_PluginBase.ReferenceDate))

            for f in l_L2P_LTC_ListOfFilenames:
                # Generate the LUT Map
                # --------------------------------------------
                l_jday = maja_utils.get_integer_jday_from_filename(f)
                if l_jday < l_JdayRef:
                    raise MajaDataException(
                        "Cannot fill the LookUpTable with filename <" + f +
                        "> detected at Julian Day " + l_jday +
                        " as it's prior to reference date " +
                        p_PluginBase.ReferenceDate + " (" + l_JdayRef + ").")
                l_jday = int(l_jday - l_JdayRef)
                LOGGER.debug("l_jday " + str(l_jday) + " from filename " + f)
                LOGGER.debug("l_JDayRef : " + str(l_JdayRef))
                # Add cr lut to map
                l_listoffile = List_Of_FilesType()
                l_listoffile.add_Relative_File_Path("LTC_Lut_" + str(l_jday) +
                                                    ".mha")
                file_utils.copy_file(
                    f,
                    os.path.join(working_dir,
                                 "LTC_Lut_" + str(l_jday) + ".mha"))
                l_lut = LUT(index=str(l_jday),
                            Indexes=new_lut_indexes,
                            List_Of_Files=l_listoffile)
                l_lutmap.add_LUT(l_lut)
            # Write down the lut map
            output = io.StringIO()
            output.write('<?xml version="1.0" ?>\n')

            l_lutmap.export(output,
                            0,
                            name_='LUTMap',
                            namespacedef_='',
                            pretty_print=True)
            l_lutmap_filename = os.path.join(working_dir, "LTC_LutMap.xml")
            with open(l_lutmap_filename, "w") as fh:
                fh.write(output.getvalue().replace("    ", "  "))
                LOGGER.info("Writed new gipp lutmap to " + l_lutmap_filename)

            output.close()
            self.dict_of_vals["LTCImage"] = l_lutmap_filename
コード例 #14
0
    def generate_edg_images(self, working_dir):
        dtm_coarse = self._dem.ALC
        # One band equal threshold
        out_edg = os.path.join(working_dir, "tmp_EDG_oneBandEqual.tif")
        param_edg = {
            "im": self._l1toaimagelist[0],
            "thresholdvalue": self._reall1nodata,
            "equalvalue": 255,
            "outsidevalue": 0,
            "out": out_edg + ":double"
        }
        onebandequal_app = OtbAppHandler("OneBandEqualThreshold",
                                         param_edg,
                                         write_output=False)
        self._edg_pipeline.add_otb_app(onebandequal_app)
        # Resample to coarse
        LOGGER.debug("Start IPEDGSub.")
        tmp_edg_sub_resample = os.path.join(working_dir, "tmp_edg_sub.tif")
        edg_sub_resample_app = resample(
            onebandequal_app.getoutput().get("out"),
            dtm_coarse,
            tmp_edg_sub_resample,
            OtbResampleType.LINEAR_WITH_RADIUS,
            padradius=4.0,
            write_output=False)
        # Threshold the output
        out_sub_edg = os.path.join(working_dir, "IPEDGSubOutput.tif")
        param_sub_edg = {
            "im": edg_sub_resample_app.getoutput().get("out"),
            "thresholdvalue": 0,
            "equalvalue": 0,
            "outsidevalue": 1,
            "out": out_sub_edg + ":uint8"
        }
        onebandequal_sub_app = OtbAppHandler("OneBandEqualThreshold",
                                             param_sub_edg,
                                             write_output=True)
        # Put in internal data
        self._edgsubmask = onebandequal_sub_app.getoutput().get("out")

        LOGGER.debug("Start IPEDGSub done.")

        # *******************************************************************************************************
        # L2EDG pipeline connection
        # *******************************************************************************************************
        LOGGER.debug("Start L2EDG ...")
        l_BandsDefinitions = self._plugin.BandsDefinitions
        l_ListOfL2Resolution = l_BandsDefinitions.ListOfL2Resolution  # ListOfStrings
        # At L2 resolution
        l_NbL2Res = len(l_ListOfL2Resolution)
        for r in range(l_NbL2Res):
            res_str = l_ListOfL2Resolution[r]
            # ExpandFilterPointer => PadAndResampleImageFilter => app ressampling
            out_ressampling = os.path.join(
                working_dir, "IPEDGRealL2_{}.tif".format(res_str))
            #threshold to 0.001 has the same result as multiplynig by 1000 and threshold to 1 after
            app = resample(self._edgsubmask,
                           self._dem.ALTList[r],
                           out_ressampling + ":uint8",
                           OtbResampleType.LINEAR,
                           threshold=0.001,
                           write_output=False)
            self._edg_pipeline.add_otb_app(app)
            self._l2edgmasklist.append(app.getoutput().get("out"))
コード例 #15
0
    def generate_edg_images(self, working_dir):
        """
        :param working_dir: Path
        :return:
        """
        dtm_coarse = self._dem.ALC

        # Get the mask filename
        edg_mask_filename = self._header_handler.get_designated_fill_mask_filename()

        # Resample to coarse
        LOGGER.debug("Start IPEDGSub.")
        tmp_edg_sub_resample = os.path.join(working_dir, "tmp_edg_sub.tif")
        edg_sub_resample_app = resample(edg_mask_filename, dtm_coarse, tmp_edg_sub_resample,
                                        OtbResampleType.LINEAR_WITH_RADIUS, padradius=4.0,write_output=False)
        # Threshold the output
        out_sub_edg = os.path.join(working_dir, "tmp_edg_sub_oneBandEqual.tif")
        param_sub_edg = {"im": edg_sub_resample_app.getoutput().get("out"),
                         "thresholdvalue": 0,
                         "equalvalue": 0,
                         "outsidevalue": 1,
                         "out": out_sub_edg + ":uint8"
                         }
        onebandequal_sub_app = OtbAppHandler("OneBandEqualThreshold", param_sub_edg)
        # Put in internal data
        self._edgsubmask = onebandequal_sub_app.getoutput().get("out")
        LOGGER.debug("Start IPEDGSub done.")

        # *******************************************************************************************************
        # L2EDG pipeline connection
        # *******************************************************************************************************
        LOGGER.debug("Start L2EDG ...")

        l_BandsDefinitions = self._plugin.BandsDefinitions
        l_ListOfL2Resolution = l_BandsDefinitions.ListOfL2Resolution  # ListOfStrings
        # At L2 resolution
        l_NbL2Res = len(l_ListOfL2Resolution)
        # Set 1000 to edge pixels to identify the pixel contaminated by an edge pixel after resampling
        #out_thresh = os.path.join(working_dir, "EDGThreshL2.tif")
        #m_L2EDGThresholdApp = binary_threshold(self._edgsubmask,
        #                                         lower_threshold=0,
        #                                         inside_value=10000,
        #                                         outside_value=0,
        #                                         output_image=out_thresh + ":double",
        #                                         write_output=False)  # //l_ThresholdImageFilter
        #self._l2edg_pipeline.add_otb_app(m_L2EDGThresholdApp)
        for r in range(l_NbL2Res):
            res_str = l_ListOfL2Resolution[r]
            # ExpandFilterPointer => PadAndResampleImageFilter => app ressampling
            out_ressampling = os.path.join(working_dir, "IPEDGRealL2_{}.tif".format(res_str))
            l2_edg_resamp_app = resample(self._edgsubmask,
                                         self._dem.ALTList[r], out_ressampling, OtbResampleType.LINEAR,threshold=0.0001)
            self._l2edg_pipeline.add_otb_app(l2_edg_resamp_app)
            # Set Threshold value to one because the expand filter interpolates values set to 0
            # or 1000 in the first threshold and adds systematically CONST_EPSILON to the output value.
            #m_L2EDGThresholdImage2_out = os.path.join(working_dir, "IPEDGMaskL2_{}.tif".format(res_str))
            #m_L2EDGThresholdApp2 = binary_threshold(l2_edg_resamp_app.getoutput().get("out"),
            #                                          lower_threshold=1.,
            #                                          inside_value=1,
            #                                          outside_value=0,
            #                                          output_image=m_L2EDGThresholdImage2_out + ":uint8",
            #                                          write_output=False)
            #self._l2edg_pipeline.add_otb_app(m_L2EDGThresholdApp2)
            self._l2edgmasklist.append(l2_edg_resamp_app.getoutput().get("out"))
コード例 #16
0
    def generate_edg_images_from_toa(self, listOfTOAImageFileNames, working):
        """

        :param listOfTOAImageFileNames: list
        :param working: path
        :return:
        """
        # Get the number of band with the number of TOA image files set in the input product directory
        l_NbBand = len(listOfTOAImageFileNames)  # int

        # *******************************************************************************************************
        # L2SubEDG pipeline connection
        # *******************************************************************************************************
        LOGGER.debug("Start IPEDGSub")
        m_OneBandFilterList = []
        m_ResamplingList = []
        m_OrFilterList = []
        tmp_edg_pipe = OtbPipelineManager()
        for i in range(2):
            toaFilename = listOfTOAImageFileNames[i]
            LOGGER.debug(("toaFilename : ", toaFilename))
            out_oneBandValue = os.path.join(working,
                                            "OneBandValue" + str(i) + ".tif")
            band_math_OneBand = one_band_equal_value(
                self._toa_scalar_list[i],
                output_image=out_oneBandValue + ":uint8",
                threshold=0.0,
                write_output=False)
            tmp_edg_pipe.add_otb_app(band_math_OneBand)
            m_OneBandFilterList.append(band_math_OneBand.getoutput()["out"])
            out_resample = os.path.join(working,
                                        "mask_resample" + str(i) + ".tif")
            resample_mask = resample(band_math_OneBand.getoutput()["out"],
                                     self._dem.ALC,
                                     out_resample + ":uint8",
                                     OtbResampleType.LINEAR_WITH_RADIUS,
                                     threshold=0.5,
                                     write_output=False)
            tmp_edg_pipe.add_otb_app(resample_mask)
            m_ResamplingList.append(resample_mask.getoutput()["out"])

        for i in range(l_NbBand - 2):
            out_oneBandValue = os.path.join(
                working, "OneBandValue" + str(i + 2) + ".tif")
            band_math_OneBand = one_band_equal_value(
                self._toa_scalar_list[i + 2],
                output_image=out_oneBandValue + ":uint8",
                threshold=0.0,
                write_output=False)
            tmp_edg_pipe.add_otb_app(band_math_OneBand)
            m_OneBandFilterList.append(band_math_OneBand.getoutput()["out"])

            out_resample = os.path.join(working,
                                        "mask_resample" + str(i + 2) + ".tif")
            resample_mask = resample(band_math_OneBand.getoutput()["out"],
                                     self._dem.ALC,
                                     out_resample + ":uint8",
                                     OtbResampleType.LINEAR_WITH_RADIUS,
                                     threshold=0.5,
                                     write_output=False)
            tmp_edg_pipe.add_otb_app(resample_mask)
            m_ResamplingList.append(resample_mask.getoutput()["out"])

        out_concat = os.path.join(working, "ConcatSubEdgOneBand.tif")
        param_oneband_concat = {
            "il": m_ResamplingList,
            "out": out_concat + ":uint8"
        }
        qoth_concat_app = OtbAppHandler("ConcatenateMaskImages",
                                        param_oneband_concat,
                                        write_output=False)
        tmp_edg_pipe.add_otb_app(qoth_concat_app)
        out_or0 = os.path.join(working, "MaskOrMask_0.tif")
        band_math_or_b1 = one_band_equal_value(
            qoth_concat_app.getoutput().get("out"),
            output_image=out_or0 + ":uint8",
            threshold=1)
        self._edgsubmask = band_math_or_b1.getoutput().get("out")
        tmp_edg_pipe.add_otb_app(band_math_or_b1)
        tmp_edg_pipe.free_otb_app()
        LOGGER.debug("End IPEDGSub.")

        # *******************************************************************************************************
        # L2EDG pipeline connection
        # *******************************************************************************************************
        LOGGER.debug("Start L2EDG ...")

        l_BandsDefinitions = self._plugin.BandsDefinitions
        LOGGER.debug("BANDS DEFINITION")
        LOGGER.debug(l_BandsDefinitions)

        l_ListOfL2Resolution = l_BandsDefinitions.ListOfL2Resolution  # ListOfStrings
        # At L2 resolution
        l_NbL2Res = len(l_ListOfL2Resolution)

        for r in range(l_NbL2Res):
            res_str = l_ListOfL2Resolution[r]
            # Set the threshold to 0.0.001 so that all pixel above 1/1000 to edge pixels
            # to identify the pixel contaminated by an edge pixel after resampling
            # ExpandFilterPointer => PadAndResampleImageFilter => app ressampling
            out_ressampling = os.path.join(
                working, "IPEDGRealL2_{}.tif".format(res_str))
            l2edg_resamp_app = resample(
                self._edgsubmask,
                self._dem.ALTList[r],
                out_ressampling + ":uint8",
                OtbResampleType.LINEAR,
                threshold=0.0,
                write_output=(False
                              or is_croco_on("sentinel2.l1reader.l2edg")))
            self._l2edg_pipeline.add_otb_app(l2edg_resamp_app)
            self._l2edgmasklist.append(l2edg_resamp_app.getoutput().get("out"))
        LOGGER.debug("End L2EDG ...")
コード例 #17
0
    def generate_mask_rasters(self, p_ListOfTOABandCode, working):
        # Generate mask rasters by rasterizing the gml mask per L2 resolution per band
        LOGGER.info("Starting Muscate GenerateMaskRasters")

        l_BandsDefinitions = self._plugin.BandsDefinitions
        l2Area = None
        l_ListOfL2Resolution = l_BandsDefinitions.ListOfL2Resolution  # ListOfStrings
        l_NbL2Res = len(l_ListOfL2Resolution)
        l_ListOfL1Resolution = l_BandsDefinitions.ListOfL1Resolution  # ListOfStrings
        l_NbL1Res = len(l_ListOfL1Resolution)
        dtm_coarse = self._dem.ALC

        # Set a constant image if the gml masks are empty
        tmp_constant_filename = os.path.join(working, "Masks_const.tif")

        # initialize the L2 Elements
        for l2res in range(l_NbL2Res):
            self._l2defectmasklist.append([])
            self._l2dfpimagelist.append(None)

        # Init the coarse elements
        for coarseband in p_ListOfTOABandCode:
            self._l2satmasklist.append(None)
        for l1res in range(l_NbL1Res):
            self._satmasksublist.append(None)
        # Test if the plugin has PIX and SAT ?
        has_pix_masks = False
        defectivPixFileNames = []
        pix_node = xml_tools.get_only_value(
            self._header_handler.root,
            "//Mask_List/Mask/Mask_Properties/NATURE[.='Aberrant_Pixels']",
            check=True)
        if pix_node is not None:
            has_pix_masks = True
            defectivPixFileNames = self._header_handler.get_list_of_pix_mask_filenames(
            )
        has_sat_masks = False
        satPixFileNames = []
        sat_node = xml_tools.get_only_value(
            self._header_handler.root,
            "//Mask_List/Mask/Mask_Properties/NATURE[.='Saturation']",
            check=True)
        if sat_node is not None:
            has_sat_masks = True
            satPixFileNames = self._header_handler.get_list_of_l1_sat_image_filenames(
            )

        # Loop on L1Res
        for l1res in range(l_NbL1Res):
            # Current resolution: "R1" or "R2" or "R3"
            curL1Res = l_ListOfL1Resolution[l1res]
            # Create constant mask if it will be necessary at a time
            tmp_constant_coarse_app = None
            tmp_constant_L2_app = None
            if not has_sat_masks or not has_pix_masks:
                tmp_constant_coarse_filename = os.path.join(
                    working, "Masks_const_.tif")
                tmp_constant_coarse_app = constant_image(
                    dtm_coarse,
                    0,
                    tmp_constant_coarse_filename,
                    write_output=False)
                if curL1Res in l_ListOfL2Resolution:
                    tmp_constant_L2_filename = os.path.join(
                        working, "Masks_const_.tif")
                    tmp_constant_L2_app = constant_image(
                        self._dem.ALTList[l1res],
                        0,
                        tmp_constant_L2_filename + ":uint8",
                        write_output=False)
                    self._l2_sat_pipeline.add_otb_app(tmp_constant_L2_app)

            # Get the list of band of the current resolution
            listOfL1Bands = l_BandsDefinitions.get_list_of_l1_band_code(
                curL1Res)
            nbL1Bands = len(listOfL1Bands)
            # For each band of the current resolution
            l_l2zone_pipeline = OtbPipelineManager()
            firstBandIdx = l_BandsDefinitions.get_band_id_in_l1(
                listOfL1Bands[0])

            if has_sat_masks:
                l_strSatFileNameRef = satPixFileNames[firstBandIdx]
                l_isSatSameFilesForBands = True

                for l_BandIdxL1 in range(len(listOfL1Bands)):
                    # Get the L1 band index associated to the L2 band code
                    l_StrBandIdL1 = listOfL1Bands[l_BandIdxL1]
                    l1BandIdx = self._header_handler.get_index_of_band_code(
                        l_StrBandIdL1)
                    # Filenameverify
                    LOGGER.debug(l_StrBandIdL1 + " : " + str(l1BandIdx) +
                                 " : " + satPixFileNames[l1BandIdx])
                    if l_strSatFileNameRef != satPixFileNames[l1BandIdx]:
                        l_isSatSameFilesForBands = False
                LOGGER.debug("l_isSatSameFilesForBands = " +
                             str(l_isSatSameFilesForBands))

                # SAT Mask generation
                if l_isSatSameFilesForBands:
                    # Sat Masks generation
                    l_StrBandIdL1 = listOfL1Bands[0]
                    l1BandIdx = self._header_handler.get_index_of_band_code(
                        l_StrBandIdL1)
                    l_SATFFilename = satPixFileNames[l1BandIdx]
                    sat_mask = os.path.join(
                        working, "L1_SAT_Masks_{}.tif".format(curL1Res))
                    param_bintovec_dfp = {
                        "im": l_SATFFilename,
                        "out": sat_mask,
                        "nbcomp": nbL1Bands
                    }
                    sat_mask_app = OtbAppHandler("BinaryToVector",
                                                 param_bintovec_dfp,
                                                 write_output=False)
                    self._satmask_pipeline.add_otb_app(sat_mask_app)

                    if curL1Res in l_ListOfL2Resolution:
                        tmp_sat_l2_resample = os.path.join(
                            working, "tmp_sat_resample_{}.tif".format(l1res))

                        if l_BandsDefinitions.get_list_of_l1_band_code(curL1Res) != \
                                l_BandsDefinitions.get_list_of_l2_band_code(curL1Res):
                            tmp_l2_band_idx_list = []
                            #Create the list of index to build the current res sat mask
                            for l2band in l_BandsDefinitions.get_list_of_l2_band_code(
                                    curL1Res):
                                l2BandIdxInHeader = self._header_handler.get_index_of_band_code(
                                    l2band)
                                tmp_l2_band_idx_list.append(
                                    self._header_handler.
                                    get_l1_sat_image_index(l2BandIdxInHeader) -
                                    1)
                            tmp_satmask_roi = os.path.join(
                                working,
                                "tmp_sat_extract_{}.tif".format(l1res))
                            tmp_extract_sat_toi_app = extract_roi(
                                sat_mask_app.getoutput()["out"],
                                tmp_l2_band_idx_list,
                                tmp_satmask_roi,
                                write_output=False)
                            self._satmask_pipeline.add_otb_app(
                                tmp_extract_sat_toi_app)
                            resamp_l2_app = resample(
                                tmp_extract_sat_toi_app.getoutput()["out"],
                                self._dem.ALTList[l1res],
                                tmp_sat_l2_resample,
                                OtbResampleType.LINEAR_WITH_RADIUS,
                                threshold=0.5,
                                padradius=4,
                                write_output=False)
                            self._satmask_pipeline.add_otb_app(resamp_l2_app)
                            self._l2satmasklist[l_ListOfL2Resolution.index(
                                curL1Res)] = resamp_l2_app.getoutput().get(
                                    "out")
                        else:
                            resamp_l2_app = resample(
                                sat_mask_app.getoutput()["out"],
                                self._dem.ALTList[l1res],
                                tmp_sat_l2_resample + ":uint8",
                                OtbResampleType.LINEAR_WITH_RADIUS,
                                threshold=0.25,
                                padradius=4,
                                write_output=False)
                            self._satmask_pipeline.add_otb_app(resamp_l2_app)
                            self._l2satmasklist[l_ListOfL2Resolution.index(
                                curL1Res)] = resamp_l2_app.getoutput()["out"]

                    tmp_l1_band_idx_list = []
                    for l1band in listOfL1Bands:
                        l1BandIdxInHeader = self._header_handler.get_index_of_band_code(
                            l1band)
                        tmp_l1_band_idx_list.append(
                            self._header_handler.get_l1_sat_image_index(
                                l1BandIdxInHeader) - 1)
                    tmp_sat_roi = os.path.join(
                        working, "tmp_l1_extract_roi_sat_{}.tif".format(l1res))
                    tmp_sat_roi_app = extract_roi(
                        sat_mask_app.getoutput()["out"],
                        tmp_l1_band_idx_list,
                        tmp_sat_roi,
                        write_output=False)
                    l_sat_subthresholdvalue = self._GIPPL2COMMHandler.get_value_f(
                        "SaturationThresholdSub")
                    tmp_sat_resample = os.path.join(
                        working,
                        "tmp_extract_roi_sat_resample_{}.tif".format(l1res))
                    app_resample = resample(
                        tmp_sat_roi_app.getoutput().get("out"),
                        dtm_coarse,
                        tmp_sat_resample,
                        OtbResampleType.LINEAR_WITH_RADIUS,
                        threshold=l_sat_subthresholdvalue,
                        padradius=4,
                        write_output=True)
                    self._satmasksublist[l1res] = app_resample.getoutput(
                    )["out"]

                else:
                    raise MajaExceptionPluginMuscate(
                        "Product format not supported : not the same file for band on SAT"
                    )
            else:
                # No sat available then put constants masks in outout
                if curL1Res in l_ListOfL2Resolution:
                    self._l2satmasklist[l_ListOfL2Resolution.index(
                        curL1Res)] = tmp_constant_L2_app.getoutput().get("out")
                for l1band in listOfL1Bands:
                    l1BandIdx = l_BandsDefinitions.get_band_id_in_l1(l1band)
                    self._satmasksublist[
                        l1BandIdx] = tmp_constant_coarse_app.getoutput().get(
                            "out")

            # Verify if we can optimize the work if its the same file for all bands of
            # the resolution and if the bands are in correct bit order
            if has_pix_masks:
                l_strDefectFileNameRef = defectivPixFileNames[firstBandIdx]
                l_isDefectSameFilesForBands = True
                for l_BandIdxL1 in range(len(listOfL1Bands)):
                    # Get the L1 band index associated to the L2 band code
                    l_StrBandIdL1 = listOfL1Bands[l_BandIdxL1]
                    l1BandIdx = self._header_handler.get_index_of_band_code(
                        l_StrBandIdL1)
                    # Filenameverify
                    if l_strDefectFileNameRef != defectivPixFileNames[
                            l1BandIdx]:
                        l_isDefectSameFilesForBands = False
                LOGGER.debug("l_isDefectSameFilesForBands = " +
                             str(l_isDefectSameFilesForBands))

                # Defective PIX (only in L2 resolution)
                if l_isDefectSameFilesForBands:
                    if curL1Res in l_ListOfL2Resolution:
                        l_StrBandIdL1 = listOfL1Bands[0]
                        l1BandIdx = self._header_handler.get_index_of_band_code(
                            l_StrBandIdL1)

                        self._l2piximagelist.append(
                            defectivPixFileNames[l1BandIdx])

                        dfp_mask = os.path.join(
                            working, "L1_DFP_Masks_{}.tif".format(curL1Res))
                        param_bintovec_dfp = {
                            "im": defectivPixFileNames[l1BandIdx],
                            "out": dfp_mask,
                            "nbcomp": nbL1Bands
                        }

                        dfp_mask_app = OtbAppHandler("BinaryToVector",
                                                     param_bintovec_dfp,
                                                     write_output=False)
                        self._l2_dfp_pipeline.add_otb_app(dfp_mask_app)
                        tmp_dfp_l2_resample = os.path.join(
                            working, "tmp_dfp_resample_{}.tif".format(l1res))
                        resamp_l2_dfp_app = resample(
                            dfp_mask_app.getoutput().get("out"),
                            self._dem.ALTList[l1res],
                            tmp_dfp_l2_resample + ":uint8",
                            OtbResampleType.LINEAR_WITH_RADIUS,
                            threshold=0.25,
                            padradius=4,
                            write_output=False)
                        self._l2dfpimagelist[l_ListOfL2Resolution.index(
                            curL1Res)] = resamp_l2_dfp_app.getoutput().get(
                                "out")
                        self._l2_dfp_pipeline.add_otb_app(resamp_l2_dfp_app)
                else:
                    raise MajaExceptionPluginMuscate(
                        "Product format not supported : not the same file for band on PIX"
                    )
            else:
                if curL1Res in l_ListOfL2Resolution:
                    self._l2dfpimagelist[l_ListOfL2Resolution.index(
                        curL1Res)] = tmp_constant_L2_app.getoutput().get("out")
                    self._l2piximagelist.append(
                        tmp_constant_L2_app.getoutput().get("out"))
コード例 #18
0
    def write_public_images(
            self,
            p_L2ImageFilenamesProvider,
            p_ReflectanceQuantificationValue,
            p_AOTQuantificationValue,
            p_AOTNodataValue,
            p_VAPQuantificationValue,
            p_VAPNodataValue,
            p_CLDDataBandsSelected,
            p_CLDCoreAlgorithmsMapBand,
            p_WritePublicProduct,
            p_EnvCorOption,
            working_dir):
        # == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == ==
        # IF PUBLIC PART OF L2 PRODUCT  IS WRITTEN
        # == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == ==
        if p_WritePublicProduct:
            l_NumberOfResolutions = len(p_L2ImageFilenamesProvider.get_sre_headers())
            LOGGER.debug("L2ImageFileWriterBase::Initialize Number of resolutions: " + str(l_NumberOfResolutions) + ".")
            l_BandsDefinitions = self._plugin.BandsDefinitions
            l_RedBandId = 0
            l_GreenBandId = 0
            l_BlueBandId = 0
            resol_QLK = 0
            l_Resolution = ""
            l_BandsDefinitions = self._plugin.BandsDefinitions
            l_RedBandId, l_BlueBandId, l_GreenBandId = l_BandsDefinitions.get_l2_information_for_quicklook_band_code(
                self._quicklookredbandcode,
                self._quicklookgreenbandcode,
                self._quicklookbluebandcode,
            )
            # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** *
            # ** ** LOOP on RESOLUTION ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
            for resol in range(0, l_NumberOfResolutions):
                l_StrResolution = l_BandsDefinitions.ListOfL2Resolution[resol]
                # --------------------------------------------------------
                # L2 area AreaType l_AreaToL2Resolution
                l_AreaFile = self._sre_list[resol]
                l_ListOfBand = l_BandsDefinitions.get_list_of_l2_band_code(l_StrResolution)

                LOGGER.debug("L2ImageFileReader::Gen Public image file for the resolution " + l_StrResolution + ".")

                # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
                # Read the Coef apply for SRE and FRE images
                LOGGER.info(
                    "SRE and FRE values multiply by the reflectance quantification value " +
                    str(p_ReflectanceQuantificationValue) +
                    ".")
                # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
                # ** ** PUBLIC  DATA ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
                #Store image pointer and filename
                tmp_l2_filename_list = []
                tmp_l2_image_list = []
                tmp_l2_pipe = OtbPipelineManager()
                # START WRITING SRE Image file DATA
                # Caching the SRE image, before computing the QuickLook.
                # Create the scalar image filter
                sre_filename = p_L2ImageFilenamesProvider.get_sre_filenames()[
                                   resol] + file_utils.get_extended_filename_write_image_file_standard()
                param_scaled_sre = {
                    "im": self._sre_list[resol],
                    "coef": p_ReflectanceQuantificationValue,
                    "out": sre_filename+":int16"}
                sre_scal_app = OtbAppHandler("MultiplyByScalar", param_scaled_sre,
                                             write_output=is_croco_on("earthexplorer.l2writer.sre"))
                tmp_l2_image_list.append(sre_scal_app.getoutput().get("out"))
                tmp_l2_filename_list.append(sre_filename)
                tmp_l2_pipe.add_otb_app(sre_scal_app)
                #QuickLook stuff
                if resol == resol_QLK :
                    tmp_sre_roi_red = os.path.join(working_dir, "tmp_sre_roi_red.tif")
                    tmp_sre_roi_red_app = extract_roi(self._sre_list[resol], [l_RedBandId],
                                                  tmp_sre_roi_red, write_output=is_croco_on("earthexplorer.l2writer.roi"))
                    tmp_l2_image_list.append(tmp_sre_roi_red_app.getoutput().get("out"))
                    tmp_l2_filename_list.append(tmp_sre_roi_red)
                    self._qckl_red_image = tmp_sre_roi_red
                    tmp_l2_pipe.add_otb_app(tmp_sre_roi_red_app)
                    tmp_sre_roi_green = os.path.join(working_dir, "tmp_sre_roi_green.tif")
                    tmp_sre_roi_green_app = extract_roi(self._sre_list[resol], [l_GreenBandId],
                                                      tmp_sre_roi_green, write_output=is_croco_on("earthexplorer.l2writer.roi"))
                    tmp_l2_image_list.append(tmp_sre_roi_green_app.getoutput().get("out"))
                    tmp_l2_filename_list.append(tmp_sre_roi_green)
                    self._qckl_green_image = tmp_sre_roi_green
                    tmp_l2_pipe.add_otb_app(tmp_sre_roi_green_app)
                    tmp_sre_roi_blue = os.path.join(working_dir, "tmp_sre_roi_blue.tif")
                    tmp_sre_roi_blue_app = extract_roi(self._sre_list[resol], [l_BlueBandId],
                                                      tmp_sre_roi_blue, write_output=is_croco_on("earthexplorer.l2writer.roi"))
                    tmp_l2_image_list.append(tmp_sre_roi_blue_app.getoutput().get("out"))
                    tmp_l2_filename_list.append(tmp_sre_roi_blue)
                    self._qckl_blue_image = tmp_sre_roi_blue
                    tmp_l2_pipe.add_otb_app(tmp_sre_roi_blue_app)

                # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
                # START WRITING FRE Image file DATA
                fre_scal_app = None
                if p_EnvCorOption:
                    fre_filename = p_L2ImageFilenamesProvider.get_fre_filenames()[
                                       resol] + file_utils.get_extended_filename_write_image_file_standard()
                    param_scaled_fre = {
                        "im": self._fre_list[resol],
                        "coef": p_ReflectanceQuantificationValue,
                        "out": fre_filename+":int16"}
                    fre_scal_app = OtbAppHandler("MultiplyByScalar", param_scaled_fre,
                                                 write_output=is_croco_on("earthexplorer.l2writer.fre"))
                    #Write SRE and FRE simultaneously
                    tmp_l2_image_list.append(fre_scal_app.getoutput().get("out"))
                    tmp_l2_filename_list.append(fre_filename)
                    tmp_l2_pipe.add_otb_app(fre_scal_app)

                # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
                # START WRITING ATB Image file DATA
                # Initialize the Scalar filter
                # FA1424: Temporary Fix to address cosmetic aspects of FA1424
                # VAPThreshold.SetInput(self.GetVAPImageList()[resol))
                # VAPThreshold.SetOutsideValue(255. / p_VAPQuantificationValue)
                # VAPThreshold.ThresholdAbove(255. / p_VAPQuantificationValue)

                # VAPScalar.SetInput(VAPThreshold.GetOutput())
                # VAPScalar.SetCoef(p_VAPQuantificationValue)
                tmp_vap = os.path.join(working_dir, "tmp_vap_scaled_" + l_StrResolution + ".tif")
                param_bandmath_vap = {
                    "il": [
                        self._l2vapimagelist[resol],
                        self._l2edgimagelist[resol]],
                    "exp": "(im2b1 == 1)?" +
                    str(p_VAPNodataValue) +
                    ":" +
                    "rint(im1b1*" +
                    str(p_VAPQuantificationValue)+")",
                    "out": tmp_vap + ":uint8"}
                vap_scal_app = OtbAppHandler("BandMathDouble", param_bandmath_vap, write_output=False)

                tmp_aot = os.path.join(working_dir, "tmp_aot_scaled_" + l_StrResolution + ".tif")
                param_bandmath_aot = {"il": [self._l2aotlist[resol], self._l2edgimagelist[resol]],
                                      "exp": "(im2b1 == 1)?" + str(p_AOTNodataValue) + ":" + "rint(im1b1*" + str(
                                          p_AOTQuantificationValue)+")",
                                      "out": tmp_aot + ":uint8"
                                      }
                aot_scal_app = OtbAppHandler("BandMathDouble", param_bandmath_aot, write_output=False)
                tmp_l2_pipe.add_otb_app(aot_scal_app)
                atb_filename = p_L2ImageFilenamesProvider.get_atb_image_filename()[resol]
                param_atb_concat = {"il": [vap_scal_app.getoutput().get("out"), aot_scal_app.getoutput().get("out")],
                                    "out": atb_filename + ":uint8"
                                    }
                atb_concat_app = OtbAppHandler("ConcatenateMaskImages", param_atb_concat,
                                               write_output=is_croco_on("earthexplorer.l2writer.atb"))
                tmp_l2_image_list.append(atb_concat_app.getoutput().get("out"))
                tmp_l2_filename_list.append(atb_filename)
                tmp_l2_pipe.add_otb_app(atb_concat_app)
                # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
                # START WRITING MSK Image file DATA
                # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
                # Connect the WAM image
                was_resampled = os.path.join(working_dir, "was_resampled_" + l_StrResolution + ".tif")
                app_resample_was = resample(self._wasimage, self._dtm.ALTList[resol],
                                            was_resampled, threshold=0.25, write_output=False)
                tmp_l2_pipe.add_otb_app(app_resample_was)
                # Connect the HID image
                hid_resampled = os.path.join(working_dir, "hid_resampled_" + l_StrResolution + ".tif")
                app_resample_hid = resample(self._dtm_hid, self._dtm.ALTList[resol],
                                            hid_resampled, threshold=0.25, write_output=False)
                tmp_l2_pipe.add_otb_app(app_resample_hid)
                # Connect the SHDimage
                shd_resampled = os.path.join(working_dir, "shd_resampled_" + l_StrResolution + ".tif")
                app_resample_shd = resample(self._dtm_shd, self._dtm.ALTList[resol],
                                            shd_resampled, threshold=0.25, write_output=False)
                tmp_l2_pipe.add_otb_app(app_resample_shd)

                # Create the MOTH image that concatenates the WAT, HID, SHD, STL and TGS masks
                MOTHImageList = []
                MOTHImageList.append(app_resample_was.getoutput().get("out"))
                MOTHImageList.append(app_resample_hid.getoutput().get("out"))
                MOTHImageList.append(app_resample_shd.getoutput().get("out"))
                # Append STL
                MOTHImageList.append(self._stl_list[resol])
                # Append TGS
                MOTHImageList.append(self._tgs_list[resol])
                app_resample_snow = None
                if self._cld_snow is not None:
                    snow_resampled = os.path.join(working_dir, "snow_resampled_" + l_StrResolution + ".tif")
                    app_resample_snow = resample(self._cld_snow, self._dtm.ALTList[resol],
                                                 snow_resampled, working_dir, 0.25, write_output=False)
                    tmp_l2_pipe.add_otb_app(app_resample_snow)
                    MOTHImageList.append(app_resample_snow.getoutput().get("out"))
                # Concat to get atb
                moth_tmp_concat = os.path.join(working_dir, "tmp_moth_" + l_StrResolution + ".tif")
                param_moth_concat = {"il": MOTHImageList,
                                     "out": moth_tmp_concat
                                     }
                # Concatenate to produce the MOTH file
                app_moth_concat = OtbAppHandler("ConcatenateMaskImages", param_moth_concat, write_output=False)
                tmp_l2_pipe.add_otb_app(app_moth_concat)
                # Binary concatenation of WAT, HID, SHD, STL and TGS masks
                msk_filename = p_L2ImageFilenamesProvider.get_msk_filename()[resol]
                param_moth_binconcat = {"im": app_moth_concat.getoutput().get("out"),
                                        "out": msk_filename + ":uint8"
                                        }
                moth_binconcat_app = OtbAppHandler("BinaryConcatenate", param_moth_binconcat,
                                                   write_output=is_croco_on("earthexplorer.l2writer.msk"))
                tmp_l2_image_list.append(moth_binconcat_app.getoutput().get("out"))
                tmp_l2_filename_list.append(msk_filename)
                tmp_l2_pipe.add_otb_app(moth_binconcat_app)
                # Concatenation of the MSK mask with the CLD and MOTH masks
                # --------------------------------------------------------

                # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
                # START WRITING QLT Image file DATA
                # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
                QOTHImageList = []

                QOTHImageList.append(self._l2edgimagelist[resol])
                QOTHImageList.append(self._l2taomasklist[resol])
                if self._plugin.WaterVapourDetermination:
                    QOTHImageList.append(self._l2iwcmasklist[resol])

                # Concat to get atb
                qoth_tmp_concat = os.path.join(working_dir, "tmp_qoth_" + l_StrResolution + ".tif")
                param_qoth_concat = {"il": QOTHImageList,
                                     "out": qoth_tmp_concat + ":uint8"
                                     }
                qoth_concat_app = OtbAppHandler("ConcatenateImages", param_qoth_concat, write_output=False)
                qoth_tmp_binconcat = os.path.join(working_dir, "tmp_binqoth_" + l_StrResolution + ".tif")
                param_qoth_binconcat = {"im": qoth_concat_app.getoutput().get("out"),
                                        "out": qoth_tmp_binconcat + ":uint8"
                                        }
                qoth_binconcat_app = OtbAppHandler("BinaryConcatenate", param_qoth_binconcat, write_output=False)

                # -------------------------------------------------------
                # Concatenation of the QLT mask with the SAT, PIX and OTH masks
                # --------------------------------------------------------
                # As for the PIX mask, the SAT mask in concatenate in one band where each bit matches one band
                sat_tmp_concat = os.path.join(working_dir, "tmp_sat_" + l_StrResolution + ".tif")
                param_sat_binconcat = {"im": self._l2satimagelist[resol],
                                       "out": sat_tmp_concat + ":uint8"
                                       }
                sat_binconcat_app = OtbAppHandler("BinaryConcatenate", param_sat_binconcat, write_output=False)

                # Create the QLT vector image
                qlt_tmp_concat = os.path.join(working_dir, "tmp_qlt_" + l_StrResolution + ".tif")
                QLTImageList = []
                QLTImageList.append(sat_binconcat_app.getoutput().get("out"))
                QLTImageList.append(self._l2piximagelist[resol])
                QLTImageList.append(qoth_binconcat_app.getoutput().get("out"))
                param_qlt_concat = {"il": QLTImageList,
                                    "out": qlt_tmp_concat + ":uint8"
                                    }
                qlt_concat_app = OtbAppHandler("ConcatenateImages", param_qlt_concat,
                                               write_output=is_croco_on("earthexplorer.l2writer.qlt"))
                tmp_l2_image_list.append(qlt_concat_app.getoutput().get("out"))
                tmp_l2_filename_list.append(p_L2ImageFilenamesProvider.get_qlt_filenames()[resol])
                tmp_l2_pipe.add_otb_app(qlt_concat_app)

                # --------------------------
                # Write all the images at L2 Reso
                write_images(tmp_l2_image_list, tmp_l2_filename_list)
                tmp_l2_pipe.free_otb_app()
                clean_pipe(self._sre_list[resol])
                if p_EnvCorOption:
                    clean_pipe(self._fre_list[resol])

                # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** *
                # START WRITING CLD Public Image file DATA
                # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** *

                # Connect the CLD image
                # -------------------------------------
                self.write_cld_image(self._l2cldlist[resol], p_CLDDataBandsSelected,
                                   p_L2ImageFilenamesProvider.get_cld_image_filename()[resol])

            LOGGER.debug("Writing L2 resolution image done !")
コード例 #19
0
    def write_quicklook_image_from_files(
            filename,
            p_WritePublicProduct,
            p_QuicklookRedBandImage,
            p_QuicklookGreenBandImage,
            p_QuicklookBlueBandImage,
            p_QuicklookMinReflRedBand,
            p_QuicklookMaxReflRedBand,
            p_QuicklookMinReflGreenBand,
            p_QuicklookMaxReflGreenBand,
            p_QuicklookMinReflBlueBand,
            p_QuicklookMaxReflBlueBand,
            p_RealL2NoData,
            dtm,
            working_dir):

        # ====================================================================
        # IF PUBLIC PART OF L2 PRODUCT IS WRITTEN
        # ====================================================================
        if p_WritePublicProduct:
            LOGGER.debug("Start QLK wiring...")

            # Replace NoData value by min
            # TODO
            # Generate he quicklook
            tmp_qlk_red_sub = os.path.join(working_dir, "tmp_qck_red_sub.tif")
            tmp_qlk_green_sub = os.path.join(working_dir, "tmp_qck_green_sub.tif")
            tmp_qlk_blue_sub = os.path.join(working_dir, "tmp_qck_blue_sub.tif")

            # Call the resampling app
            resampling_app_red = resample(p_QuicklookRedBandImage, dtm, tmp_qlk_red_sub,
                                          OtbResampleType.LINEAR_WITH_RADIUS,
                                          padradius=4, outarea=[1000,1000], write_output=False)
            resampling_app_green = resample(p_QuicklookGreenBandImage, dtm, tmp_qlk_green_sub,
                                            OtbResampleType.LINEAR_WITH_RADIUS,
                                            padradius=4, outarea=[1000,1000], write_output=False)
            resampling_app_blue = resample(p_QuicklookBlueBandImage, dtm, tmp_qlk_blue_sub,
                                           OtbResampleType.LINEAR_WITH_RADIUS,
                                           padradius=4, outarea=[1000,1000], write_output=False)

            # Concatenate images
            tmp_qlk = os.path.join(working_dir, "tmp_qck_sub.tif")
            param_concat = {
                "il": [
                    resampling_app_red.getoutput().get("out"),
                    resampling_app_blue.getoutput().get("out"),
                    resampling_app_green.getoutput().get("out")],
                "out": tmp_qlk,
                "ram": str(OtbAppHandler.ram_to_use / 3)
                }
            concat_app = OtbAppHandler("ConcatenateDoubleImages", param_concat,write_output=True)

            # Rescale between 0 and 255
            rescale_intensity(
                concat_app.getoutput().get("out"),
                0,
                255,
                filename +
                file_utils.get_extended_filename_write_image_file_standard()+":uint8",
                inmin=[str(p_QuicklookMinReflRedBand), str(p_QuicklookMinReflGreenBand), str(p_QuicklookMinReflBlueBand)],
                inmax=[str(p_QuicklookMaxReflRedBand), str(p_QuicklookMaxReflGreenBand), str(p_QuicklookMaxReflBlueBand)]
            )
            if (os.path.exists(filename + '.aux.xml')):
                LOGGER.debug("Removing " + filename + '.aux.xml file')
                os.remove(filename + '.aux.xml')
コード例 #20
0
    def generate_edg_images(self, working_dir):
        """

        :param working_dir: String
        :return:
        """
        dtm_coarse = self._dem.ALC

        list_of_binary_threshold = []
        m_OrFilter1List = []
        m_OrFilter2List = []

        # *******************************************************************************************************
        # IPEDGSub pipeline connection
        # *******************************************************************************************************
        LOGGER.debug("Start IPEDGSub ...")
        # At L2 coarse resolution

        # Set to 0 the pixel that are not edges in the zone (detector) mask image raster
        out_thresh_0 = os.path.join(working_dir, "IPEDGOrFilter1SubMask_0.tif")
        out_binary_threshold_ipedg_image_b1 = binary_threshold(
            input_image=self._zonemasksublist[0],
            inside_value=0,
            outside_value=1,
            output_image=out_thresh_0 + ":uint8",
            lower_threshold=1,
            write_output=False)

        # Concatenate the zone image and the nodata one
        m_OrFilter2List.append(
            out_binary_threshold_ipedg_image_b1.getoutput()["out"])
        m_OrFilter2List.append(self._nodatamasksublist[0])
        l_NbBand = len(self._zonemasksublist)
        # band loop
        for l_band in range(l_NbBand - 1):
            out_thresh_1 = os.path.join(
                working_dir,
                "IPEDGThreshFilter1SubMask_{}.tif".format(l_band + 1))
            out_binary_threshold_ipedg_image = binary_threshold(
                input_image=self._zonemasksublist[l_band + 1],
                lower_threshold=1,
                inside_value=0,
                outside_value=1,
                output_image=out_thresh_1 + ":uint8",
                write_output=False)
            self._subedg_pipeline.add_otb_app(out_binary_threshold_ipedg_image)
            m_OrFilter2List.append(
                out_binary_threshold_ipedg_image.getoutput().get("out"))
            m_OrFilter2List.append(self._nodatamasksublist[l_band + 1])

        #OR filter
        out_edg = os.path.join(working_dir, "IPEDGubMask.tif")
        or_edg_sub_app = band_math_or(m_OrFilter2List,
                                      out_edg + ":uint8",
                                      write_output=True)
        # Allocation of 7 Go in S2 MUSCATE case
        self._edgsubmask = or_edg_sub_app.getoutput().get("out")
        self._subedg_pipeline.free_otb_app()
        LOGGER.debug("Start IPEDGSub done.")

        # *******************************************************************************************************
        # L2EDG pipeline connection
        # *******************************************************************************************************
        LOGGER.debug("Start L2EDG ...")

        l_BandsDefinitions = self._plugin.BandsDefinitions
        l_ListOfL2Resolution = l_BandsDefinitions.ListOfL2Resolution  # ListOfStrings
        # At L2 resolution
        l_NbL2Res = len(l_ListOfL2Resolution)

        for r in range(l_NbL2Res):
            res_str = l_ListOfL2Resolution[r]
            # Set 1000 to edge pixels to identify the pixel contaminated by an edge pixel after resampling
            out_thresh = os.path.join(working_dir,
                                      "EDGThreshL2_{}.tif".format(res_str))
            #m_L2EDGThreshold_app = binary_threshold(self._edgsubmask,
            #                                         lower_threshold=0,
            #                                         inside_value=0,
            #                                         outside_value=1000,
            #                                         output_image=out_thresh + ":uint8",
            #                                         write_output=False)
            #self._pipeline.add_otb_app(m_L2EDGThreshold_app)
            # ExpandFilterPointer => PadAndResampleImageFilter => app ressampling
            out_ressampling = os.path.join(
                working_dir, "IPEDGRealL2_{}.tif".format(res_str))
            resamp_app = resample(self._edgsubmask,
                                  self._dem.ALTList[r],
                                  out_ressampling + ":uint8",
                                  OtbResampleType.LINEAR,
                                  threshold=0.000001,
                                  write_output=False)
            self._pipeline.add_otb_app(resamp_app)

            # Set Threshold value to one because the expand filter interpolates values set to 0
            # or 1000 in the first threshold and adds systematically CONST_EPSILON to the output value.
            #m_L2EDGThresholdImage2_out = os.path.join(working_dir, "IPEDGMaskL2_{}.tif".format(res_str))
            #m_L2EDGThresholdImageApp2 = binary_threshold(
            #    resamp_app.getoutput().get("out"),
            #    lower_threshold=0.,
            #    inside_value=0,
            #    outside_value=1,
            #    output_image=m_L2EDGThresholdImage2_out + ":uint8",
            #    write_output=False)
            #self._pipeline.add_otb_app(m_L2EDGThresholdImageApp2)
            self._l2edgmasklist.append(resamp_app.getoutput().get("out"))
コード例 #21
0
    def write_public_images(self, p_PublicDirectory, p_L2BaseFilename,
                            p_ReflectanceQuantificationValue,
                            p_AOTQuantificationValue, p_AOTNodataValue,
                            p_VAPQuantificationValue, p_VAPNodataValue,
                            p_CLDDataBandsSelected, p_CLDCoreAlgorithmsMapBand,
                            p_WritePublicProduct, p_EnvCorOption, working_dir):

        # IF PUBLIC PART OF L2 PRODUCT IS WRITTEN
        if p_WritePublicProduct:
            l_BandsDefinitions = self._plugin.BandsDefinitions

            l_ListOfL2Res = l_BandsDefinitions.ListOfL2Resolution
            l_NumberOfResolutions = len(l_ListOfL2Res)
            LOGGER.debug(
                "L2ImageFileWriterBase::Initialize Number of resolutions: " +
                str(l_NumberOfResolutions) + ".")
            # Not use the list of XS band because for Landsat8, the band B9 is not
            # selected in the L2 resolution (only in L2Coarse resolution)
            l_BaseL2FullFilename = os.path.join(p_PublicDirectory,
                                                p_L2BaseFilename)
            l_MASKSDirectory = os.path.join(p_PublicDirectory, "MASKS")
            l_BaseL2FullMASKSFilename = os.path.join(l_MASKSDirectory,
                                                     p_L2BaseFilename)
            file_utils.create_directory(l_MASKSDirectory)
            resol_QLK = 0
            l_RedBandId, l_BlueBandId, l_GreenBandId = l_BandsDefinitions.get_l2_information_for_quicklook_band_code(
                self._quicklookredbandcode, self._quicklookgreenbandcode,
                self._quicklookbluebandcode)

            # *************************************************************************************************************
            # ****  LOOP on RESOLUTION   *********************************************
            # *************************************************************************************************************
            for resol in range(0, l_NumberOfResolutions):
                l_StrResolution = l_BandsDefinitions.ListOfL2Resolution[resol]
                # --------------------------------------------------------
                # L2 area AreaType l_AreaToL2Resolution

                l_AreaFile = self._sre_list[resol]
                l_ListOfBand = l_BandsDefinitions.get_list_of_l2_band_code(
                    l_StrResolution)

                l_NumberOfBands = len(l_ListOfBand)
                LOGGER.debug(
                    "L2ImageFileReader::Gen Public image file for the resolution "
                    + l_StrResolution + ".")
                l_grpSuffix = ""
                if l_NumberOfResolutions == 1:
                    l_grpSuffix = "XS"
                else:
                    l_grpSuffix = l_ListOfL2Res[resol]
                l_StrResolution = l_BandsDefinitions.ListOfL2Resolution[resol]

                # Read the Coef apply for SRE and FRE images
                LOGGER.info(
                    "SRE and FRE values multiply by the reflectance quantification value "
                    + str(p_ReflectanceQuantificationValue) + ".")
                # *************************************************************************************************************
                # ****  PUBLIC  DATA      ************************************************
                # *************************************************************************************************************

                # START WRITING SRE Image file DATA
                # Initialize the Scalar filter
                sre_pipeline = OtbPipelineManager()

                #Extract each channel for each file
                tmp_l2_filename_list = []
                tmp_l2_image_list = []
                tmp_sre_scaled = os.path.join(
                    working_dir,
                    "tmp_sre_multi_round_" + l_StrResolution + ".tif")
                param_scaled_sre = {
                    "im": self._sre_list[resol],
                    "coef": p_ReflectanceQuantificationValue,
                    "out": tmp_sre_scaled
                }
                scaled_sre_app = OtbAppHandler("RoundImage",
                                               param_scaled_sre,
                                               write_output=False)
                sre_pipeline.add_otb_app(scaled_sre_app)
                for i in range(l_NumberOfBands):
                    if resol == resol_QLK and (l_RedBandId == i
                                               or l_GreenBandId == i
                                               or l_BlueBandId == i):
                        tmp_sre_roi = os.path.join(
                            working_dir,
                            "tmp_sre_roi_" + l_ListOfBand[i] + ".tif")
                        tmp_sre_roi_app = extract_roi(self._sre_list[resol],
                                                      [i],
                                                      tmp_sre_roi,
                                                      write_output=False)
                        tmp_l2_image_list.append(
                            tmp_sre_roi_app.getoutput().get("out"))
                        tmp_l2_filename_list.append(tmp_sre_roi)
                        if l_RedBandId == i:
                            self._qckl_red_image = tmp_sre_roi
                        elif l_GreenBandId == i:
                            self._qckl_green_image = tmp_sre_roi
                        elif l_BlueBandId == i:
                            self._qckl_blue_image = tmp_sre_roi
                        sre_pipeline.add_otb_app(tmp_sre_roi_app)
                    tmp_sre_scaled_roi = os.path.join(
                        working_dir,
                        "tmp_sre_scaled_roi_" + l_ListOfBand[i] + ".tif")
                    tmp_sre_scaled_roi_app = extract_roi(
                        scaled_sre_app.getoutput().get("out"), [i],
                        tmp_sre_scaled_roi + ":int16",
                        write_output=False)
                    tmp_l2_image_list.append(
                        tmp_sre_scaled_roi_app.getoutput().get("out"))
                    sre_pipeline.add_otb_app(tmp_sre_scaled_roi_app)
                    tmp_l2_filename_list.append(
                        l_BaseL2FullFilename + "_SRE_" + l_ListOfBand[i] +
                        ".tif" + file_utils.
                        get_extended_filename_write_image_file_standard())

                # START WRITING FRE Image file DATA
                tmp_tgs_filename = os.path.join(
                    working_dir, "tmp_tgs_" + l_StrResolution + ".tif")
                tmp_stl_filename = os.path.join(
                    working_dir, "tmp_stl_" + l_StrResolution + ".tif")
                fre_pipeline = OtbPipelineManager()
                if p_EnvCorOption:
                    # Initialize the Scalar filter
                    tmp_fre_scaled = os.path.join(
                        working_dir,
                        "tmp_fre_multi_round_" + l_StrResolution + ".tif")
                    param_scaled_fre = {
                        "im": self._fre_list[resol],
                        "coef": p_ReflectanceQuantificationValue,
                        "out": tmp_fre_scaled
                    }
                    scaled_fre_app = OtbAppHandler("RoundImage",
                                                   param_scaled_fre,
                                                   write_output=False)
                    fre_pipeline.add_otb_app(scaled_fre_app)
                    # Extract each channel for each file
                    for i in range(l_NumberOfBands):
                        tmp_fre_roi = os.path.join(
                            working_dir,
                            "tmp_fre_roi_" + l_ListOfBand[i] + ".tif")
                        tmp_fre_roi_app = extract_roi(
                            scaled_fre_app.getoutput().get("out"), [i],
                            tmp_fre_roi + ":int16",
                            write_output=False)
                        tmp_l2_image_list.append(
                            tmp_fre_roi_app.getoutput().get("out"))
                        fre_pipeline.add_otb_app(tmp_fre_roi_app)
                        tmp_l2_filename_list.append(
                            l_BaseL2FullFilename + "_FRE_" + l_ListOfBand[i] +
                            ".tif" + file_utils.
                            get_extended_filename_write_image_file_standard())
                    #Add tgs and stl also provided by the envcorr
                    tmp_l2_image_list.append(self._tgs_list[resol])
                    tmp_l2_filename_list.append(tmp_tgs_filename)
                    tmp_l2_image_list.append(self._stl_list[resol])
                    tmp_l2_filename_list.append(tmp_stl_filename)

                # START WRITING ATB Image file DATA
                # Initialize the Scalar filter
                # FA1424: Temporary Fix to address cosmetic aspects of FA1424
                # VAPThreshold.SetInput(self.GetVAPImageList()[resol))
                # VAPThreshold.SetOutsideValue(255. / p_VAPQuantificationValue)
                # VAPThreshold.ThresholdAbove(255. / p_VAPQuantificationValue)

                # VAPScalar.SetInput(VAPThreshold.GetOutput())
                # VAPScalar.SetCoef(p_VAPQuantificationValue)
                atb_pipeline = OtbPipelineManager()
                tmp_vap = os.path.join(
                    working_dir, "tmp_vap_scaled_" + l_StrResolution + ".tif")
                param_bandmath_vap = {
                    "il":
                    [self._l2vapimagelist[resol], self._l2edgimagelist[resol]],
                    "exp":
                    "(im2b1 == 1)?" + str(p_VAPNodataValue) + ":" + "im1b1*" +
                    str(p_VAPQuantificationValue),
                    "out":
                    tmp_vap
                }
                vap_scal_app = OtbAppHandler("BandMathDouble",
                                             param_bandmath_vap,
                                             write_output=False)
                atb_pipeline.add_otb_app(vap_scal_app)

                tmp_round_vap = os.path.join(
                    working_dir, "tmp_vap_round_" + l_StrResolution + ".tif")
                param_round_vap = {
                    "im": vap_scal_app.getoutput().get("out"),
                    "out": tmp_round_vap
                }
                vap_round_app = OtbAppHandler("RoundImage",
                                              param_round_vap,
                                              write_output=False)
                atb_pipeline.add_otb_app(vap_round_app)
                tmp_aot = os.path.join(
                    working_dir, "tmp_aot_scaled_" + l_StrResolution + ".tif")
                param_bandmath_aot = {
                    "il":
                    [self._l2aotlist[resol], self._l2edgimagelist[resol]],
                    "exp":
                    "(im2b1 == 1)?" + str(p_AOTNodataValue) + ":" + "im1b1*" +
                    str(p_AOTQuantificationValue),
                    "out":
                    tmp_aot
                }
                aot_scal_app = OtbAppHandler("BandMathDouble",
                                             param_bandmath_aot,
                                             write_output=False)
                atb_pipeline.add_otb_app(aot_scal_app)
                tmp_round_aot = os.path.join(
                    working_dir, "tmp_aot_round_" + l_StrResolution + ".tif")
                param_round_aot = {
                    "im": aot_scal_app.getoutput().get("out"),
                    "out": tmp_round_aot
                }
                aot_round_app = OtbAppHandler("RoundImage",
                                              param_round_aot,
                                              write_output=False)
                atb_pipeline.add_otb_app(aot_round_app)
                atb_filename = l_BaseL2FullFilename + "_ATB_" + l_grpSuffix + ".tif"
                param_atb_concat = {
                    "il": [
                        vap_round_app.getoutput().get("out"),
                        aot_round_app.getoutput().get("out")
                    ],
                    "out":
                    atb_filename + ":uint8" + file_utils.
                    get_extended_filename_write_image_file_standard()
                }

                atb_binconcat_app = OtbAppHandler("ConcatenateImages",
                                                  param_atb_concat,
                                                  write_output=False)
                #tmp_l2_image_list.append(atb_binconcat_app.getoutput().get("out"))
                #tmp_l2_filename_list.append(atb_filename)
                atb_pipeline.add_otb_app(atb_binconcat_app)

                # START WRITING IAB MASK
                iab_pipeline = OtbPipelineManager()
                # Create the image list
                tmp_iab = os.path.join(
                    working_dir, "tmp_iab_concat_" + l_StrResolution + ".tif")
                param_iab_concat = {
                    "il":
                    [self._l2iwcmasklist[resol], self._l2taomasklist[resol]],
                    "out": tmp_iab + ":uint8"
                }
                tmp_iab_concat_app = OtbAppHandler("ConcatenateImages",
                                                   param_iab_concat,
                                                   write_output=False)
                iab_pipeline.add_otb_app(tmp_iab_concat_app)
                iab_filename = l_BaseL2FullMASKSFilename + "_IAB_" + l_grpSuffix + ".tif"
                param_iab_binconcat = {
                    "im":
                    tmp_iab_concat_app.getoutput().get("out"),
                    "out":
                    iab_filename + ":uint8" + file_utils.
                    get_extended_filename_write_image_file_standard()
                }
                iab_binconcat_app = OtbAppHandler("BinaryConcatenate",
                                                  param_iab_binconcat,
                                                  write_output=False)
                iab_pipeline.add_otb_app(iab_binconcat_app)
                write_images([
                    atb_binconcat_app.getoutput().get("out"),
                    iab_binconcat_app.getoutput().get("out")
                ], [atb_filename, iab_filename])

                #tmp_l2_image_list.append(iab_binconcat_app.getoutput().get("out"))
                #tmp_l2_filename_list.append(iab_filename)

                # START WRITING EDG Image file DATA
                tmp_l2_image_list.append(self._l2edgimagelist[resol])
                tmp_l2_filename_list.append(l_BaseL2FullMASKSFilename +
                                            "_EDG_" + l_grpSuffix + ".tif")
                #--------------------------
                # Write all the images at L2 Reso
                write_images(tmp_l2_image_list, tmp_l2_filename_list)
                atb_pipeline.free_otb_app()
                iab_pipeline.free_otb_app()
                fre_pipeline.free_otb_app()
                sre_pipeline.free_otb_app()
                # --------------------------

                #Caching of cloud images needed for MG2
                l_cm2_index = p_CLDCoreAlgorithmsMapBand[CLOUD_MASK_ALL_CLOUDS]
                l_shadows_index = p_CLDCoreAlgorithmsMapBand[
                    CLOUD_MASK_SHADOWS]
                l_shadvar_index = p_CLDCoreAlgorithmsMapBand[
                    CLOUD_MASK_SHADVAR]

                # START WRITING MG2 Image file DATA
                l_mg2_image_list = []
                mg2_pipeline = OtbPipelineManager()
                # Connect the WAM image
                wat_resampled = os.path.join(
                    working_dir, "wat_resampled_" + l_StrResolution + ".tif")
                app_resample_wat = resample(self._wasimage,
                                            self._dtm.ALTList[resol],
                                            wat_resampled,
                                            method=OtbResampleType.LINEAR,
                                            threshold=0.25,
                                            write_output=False)
                l_mg2_image_list.append(
                    app_resample_wat.getoutput().get("out"))
                mg2_pipeline.add_otb_app(app_resample_wat)
                # Extract the CM2 cloud mask
                l_mg2_image_list.append(self._l2cldlist[resol][l_cm2_index])

                #Connect the SNW image if any
                if self._cld_snow is not None:
                    LOGGER.debug(
                        "Snow mask has been successfully computed, adding it to the MG2"
                    )
                    snw_resampled = os.path.join(
                        working_dir,
                        "snw_resampled_" + l_StrResolution + ".tif")
                    app_resample_snw = resample(self._cld_snow,
                                                self._dtm.ALTList[resol],
                                                snw_resampled,
                                                method=OtbResampleType.LINEAR,
                                                threshold=0.25,
                                                write_output=False)
                    l_mg2_image_list.append(
                        app_resample_snw.getoutput().get("out"))
                    mg2_pipeline.add_otb_app(app_resample_snw)
                else:
                    # Add a constant mask
                    tmp_constant_filename = os.path.join(
                        working_dir, "Const_shd_masks.tif")
                    cst_snw_app = constant_image(self._dtm.ALTList[resol],
                                                 0,
                                                 tmp_constant_filename +
                                                 ":uint8",
                                                 write_output=False)
                    l_mg2_image_list.append(cst_snw_app.getoutput().get("out"))
                    mg2_pipeline.add_otb_app(cst_snw_app)

                # Connect the shadow or mask
                tmp_shador_bandmath = os.path.join(
                    working_dir,
                    "tmp_shador_bandmath_" + l_StrResolution + ".tif")
                tmp_band_math_app = band_math([
                    self._l2cldlist[resol][l_shadows_index],
                    self._l2cldlist[resol][l_shadvar_index]
                ],
                                              "im1b1 || im2b1",
                                              tmp_shador_bandmath + ":uint8",
                                              write_output=False)
                l_mg2_image_list.append(
                    tmp_band_math_app.getoutput().get("out"))
                mg2_pipeline.add_otb_app(tmp_band_math_app)
                # Connect the HID image
                hid_resampled = os.path.join(
                    working_dir, "hid_resampled_" + l_StrResolution + ".tif")
                app_resample_hid = resample(self._dtm_hid,
                                            self._dtm.ALTList[resol],
                                            hid_resampled,
                                            method=OtbResampleType.LINEAR,
                                            threshold=0.25,
                                            write_output=False)
                l_mg2_image_list.append(
                    app_resample_hid.getoutput().get("out"))
                mg2_pipeline.add_otb_app(app_resample_hid)
                # Connect the SHDimage
                shd_resampled = os.path.join(
                    working_dir, "shd_resampled_" + l_StrResolution + ".tif")
                app_resample_shd = resample(self._dtm_shd,
                                            self._dtm.ALTList[resol],
                                            shd_resampled,
                                            method=OtbResampleType.LINEAR,
                                            threshold=0.25,
                                            write_output=False)
                mg2_pipeline.add_otb_app(app_resample_shd)
                l_mg2_image_list.append(
                    app_resample_shd.getoutput().get("out"))
                if p_EnvCorOption:
                    # Append STL
                    l_mg2_image_list.append(tmp_stl_filename)
                    # Append TGS
                    l_mg2_image_list.append(tmp_tgs_filename)
                else:
                    # Append STL
                    l_mg2_image_list.append(self._stl_list[resol])
                    # Append TGS
                    l_mg2_image_list.append(self._tgs_list[resol])
                # Concatenate all
                tmp_mg2 = os.path.join(
                    working_dir, "tmp_mg2_concat_" + l_StrResolution + ".tif")
                param_mg2_concat = {"il": l_mg2_image_list, "out": tmp_mg2}
                tmp_mg2_concat_app = OtbAppHandler("ConcatenateImages",
                                                   param_mg2_concat,
                                                   write_output=False)
                param_mg2_binconcat = {
                    "im":
                    tmp_mg2_concat_app.getoutput().get("out"),
                    "out":
                    l_BaseL2FullMASKSFilename + "_MG2_" + l_grpSuffix +
                    ".tif" + ":uint8" + file_utils.
                    get_extended_filename_write_image_file_standard()
                }
                mg2_binconcat_app = OtbAppHandler("BinaryConcatenate",
                                                  param_mg2_binconcat,
                                                  write_output=True)
                mg2_pipeline.add_otb_app(mg2_binconcat_app)
                mg2_pipeline.free_otb_app()

                # START WRITING SAT Image file DATA
                # TODO Create the writer with test on number of bands
                param_sat_binconcat = {
                    "im":
                    self._l2satimagelist[resol],
                    "out":
                    l_BaseL2FullMASKSFilename + "_SAT_" + l_grpSuffix +
                    ".tif" + ":uint8" + file_utils.
                    get_extended_filename_write_image_file_standard()
                }
                sat_binconcat_app = OtbAppHandler("BinaryConcatenate",
                                                  param_sat_binconcat,
                                                  write_output=True)

                # START WRITING PIX Image file DATA
                if "PIXImages" in self._l1_image_info.MuscateData:
                    LOGGER.debug(
                        "The L1 product have 'Aberrant_Pixels' masks. There are writed in the L2 out product..."
                    )
                    otb_file_utils.otb_copy_image_to_file(
                        self._l2piximagelist[resol],
                        l_BaseL2FullMASKSFilename + "_PIX_" + l_grpSuffix +
                        ".tif")
                else:
                    LOGGER.debug("No PIX node detected to write")

                # START WRITING USI Image file DATA
                if "Node_Useful_Image" in self._l1_image_info.MuscateData:
                    LOGGER.debug(
                        "The L1 product have 'Useful_Image' files. There are copied in the L2 out product..."
                    )

                    # Write the USI in the Xml file, in the Useful_Imagenode !
                    l_XPathRootUSI_In = "//Mask[Mask_Properties/NATURE='Useful_Image']/Mask_File_List/MASK_FILE[@group_id='{}']"
                    xnodes_in = xml_tools.get_all_values(
                        self._l1_image_info.MuscateData["Node_Useful_Image"],
                        l_XPathRootUSI_In.format(l_grpSuffix))
                    # Get the path in the xml product filename
                    lPath = os.path.dirname(self._l1_image_info.HeaderFilename)
                    for node_in in xnodes_in:
                        l_FullPathFilename = os.path.join(lPath, node_in.text)
                        # Expand threshold the file
                        usi_resampled = l_BaseL2FullMASKSFilename + "_USI_" + l_grpSuffix + ".tif"\
                                        + file_utils.get_extended_filename_write_mask_file_muscate()
                        resample(l_FullPathFilename,
                                 self._dtm.ALTList[resol],
                                 usi_resampled,
                                 threshold=0.25,
                                 method=OtbResampleType.LINEAR,
                                 write_output=True)

                    else:
                        LOGGER.debug(
                            "No 'Useful_Image' mask detected in the L1 product."
                        )
                # Fin si manage USI

                # START WRITING DFP Image file DATA (=DFP in MUSCATE) #TODO
                if self._l2dfpimagelist is not None:
                    param_dfp_binconcat = {
                        "im":
                        self._l2dfpimagelist[resol],
                        "out":
                        l_BaseL2FullMASKSFilename + "_DFP_" + l_grpSuffix +
                        ".tif"
                    }
                    dfp_binconcat_app = OtbAppHandler("BinaryConcatenate",
                                                      param_dfp_binconcat,
                                                      write_output=True)
                else:
                    LOGGER.debug("DFP Masks not available.")

                # START WRITING CLM (CLD) Image file DATA
                # Connect the CLD image
                # Connect the CLD image
                # -------------------------------------
                l_cld_uses_filenames = False
                for f in self._l2cldlist[resol]:
                    if not otb_is_swig_pointer(f) and os.path.exists(f):
                        l_cld_uses_filenames = True
                self.write_cld_image(self._l2cldlist[resol],
                                     p_CLDDataBandsSelected,
                                     l_BaseL2FullMASKSFilename + "_CLM_" +
                                     l_grpSuffix + ".tif",
                                     use_filenames=l_cld_uses_filenames)
                LOGGER.debug("Writing L2 resolution image done !")