def generate_sat_images(self, working_dir):
        """

        :return:
        """

        # *******************************************************************************************************
        # IPSAT Sub image pipeline connection
        # *******************************************************************************************************
        out_concatenate = os.path.join(working_dir, "SubSatVector.tif")
        param_concatenate = {"il": self._satmasksublist,
                             "out": out_concatenate + ":uint8"
                             }
        concat_app = OtbAppHandler("ConcatenateDoubleImages", param_concatenate)
        self._subsatimage = concat_app.getoutput().get("out")
        # *******************************************************************************************************
        # L2SAT image pipeline connection
        # *******************************************************************************************************
        l_BandsDefinitions = self._plugin.BandsDefinitions
        l_ListOfL2Resolution = l_BandsDefinitions.ListOfL2Resolution
        # At L2 resolution
        l_NbL2Res = len(l_ListOfL2Resolution)
        for i in range(l_NbL2Res):
            str_res = l_ListOfL2Resolution[i]
            out_concatenate = os.path.join(working_dir, "L2SATVector_{}.tif".format(str_res))
            param_concatenate = {"il": self._l2satimagelist[i],
                                 "out": out_concatenate + ":uint8"
                                 }
            sat_image = OtbAppHandler("ConcatenateDoubleImages", param_concatenate, write_output=False)
            self._pipeline.add_otb_app(sat_image)
            self._l2satmasklist.append(sat_image.getoutput().get("out"))
Esempio n. 2
0
    def run(self, dict_of_input, dict_of_output):
        LOGGER.info("Rain detection computation start")
        rain_working = dict_of_input.get(
            "AppHandler").get_directory_manager().get_temporary_directory(
                "RainFlagProc_", do_always_remove=True)
        image_list = [
            dict_of_output.get(constants.CLOUD_MASK_ALL_CLOUDS),
            dict_of_output.get("WaterMask")
        ]
        image_list.append(
            dict_of_input.get("L1Reader").get_value("IPEDGSubOutput"))
        image_list.append(dict_of_input.get("L2Reader").get_value("WASImage"))
        image_list.append(dict_of_input.get("L2Reader").get_value("NDTImage"))
        exp = "im1b1 || im2b1 || im3b1 || im4b1 || im5b1"
        or_all = os.path.join(rain_working, "OrAll.tif")

        if dict_of_input.get("Params").get("SnowBandAvailable"):
            image_list.append(dict_of_output.get("cld_snow"))
            exp = exp + " || im6b1"

        param_orall = {"il": image_list, "exp": exp, "out": or_all}
        orall_app = OtbAppHandler("BandMath", param_orall, write_output=False)

        tocr_extract = os.path.join(rain_working, "Tocr_Extract.tif")
        tocrextract_image_app = extract_roi(
            dict_of_output.get("RayleighIPTOCR"),
            [dict_of_input.get("Params").get("WaterBandIndex_DateD")],
            tocr_extract,
            write_output=False)
        rcr_extract = os.path.join(rain_working, "Rcr_Extract.tif")

        rcrextract_image_app = extract_roi(
            dict_of_input.get("L2Reader").get_value("RCRImage"),
            [dict_of_input.get("Params").get("WaterBandIndex_DateDm1")],
            rcr_extract,
            write_output=False)
        param_rcrstat = {
            "im": rcrextract_image_app.getoutput()["out"],
            "mask": orall_app.getoutput()["out"],
        }
        rcrstat_app = OtbAppHandler("Stats", param_rcrstat, write_output=False)
        rcr_mean = rcrstat_app.getoutput()["mean"]

        param_tocrstat = {
            "im": tocrextract_image_app.getoutput()["out"],
            "mask": orall_app.getoutput()["out"],
        }
        tocrstat_app = OtbAppHandler("Stats",
                                     param_tocrstat,
                                     write_output=False)
        tocr_mean = tocrstat_app.getoutput()["mean"]

        diffMean = rcr_mean - tocr_mean

        if diffMean > dict_of_input.get("L2COMM").get_value_f(
                "ReflectanceDecreaseThreshold"):
            dict_of_output["RainFlag"] = True
        else:
            dict_of_output["RainFlag"] = False
Esempio n. 3
0
    def write_qlt_product(self, p_res, p_qlt_image_filename, working_dir):
        LOGGER.info("EarthExplorerL2ImageFileWriter:WriteQLTproduct()")
        l_BandsDefinitions = self._plugin.BandsDefinitions
        l_StrRes = l_BandsDefinitions.ListOfL2Resolution[p_res]
        QOTHImageList = []

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

        # Concat to get atb
        qoth_tmp_concat = os.path.join(working_dir,
                                       "tmp_qoth_" + l_StrRes + ".tif")
        param_qoth_concat = {
            "il": QOTHImageList,
            "out": qoth_tmp_concat + ":uint8"
        }
        qoth_concat_app = OtbAppHandler("ConcatenateDoubleImages",
                                        param_qoth_concat,
                                        write_output=False)
        qoth_tmp_binconcat = os.path.join(working_dir,
                                          "tmp_binqoth_" + l_StrRes + ".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_StrRes + ".tif")
        param_sat_binconcat = {
            "im": self._l2satimagelist[p_res],
            "out": sat_tmp_concat + ":uint8"
        }
        sat_binconcat_app = OtbAppHandler("BinaryConcatenate",
                                          param_sat_binconcat,
                                          write_output=False)

        # Create the QLT vector image
        QLTImageList = []
        QLTImageList.append(sat_binconcat_app.getoutput().get("out"))
        QLTImageList.append(self._l2piximagelist[p_res])
        QLTImageList.append(qoth_binconcat_app.getoutput().get("out"))
        param_qlt_concat = {
            "il": QLTImageList,
            "out": p_qlt_image_filename + ":uint8"
        }
        OtbAppHandler("ConcatenateDoubleImages", param_qlt_concat)
Esempio n. 4
0
def clean_pipe(input_file_path):

    parameters = {"in": input_file_path,
                "startx": 0,
                "starty": 0,
                "sizex": 1,
                "sizey": 1,
                "out": "tmp.tif"}
    otb_app = OtbAppHandler("ExtractROI",parameters,write_output=False)
    parameters2 = {"im": otb_app.getoutput().get("out")}
    otb_app2 = OtbAppHandler("Stats", parameters2, write_output=True)
    LOGGER.debug("Stats on clean: "+str(otb_app2.getoutput().get("mean")))
    del otb_app2
    del otb_app
 def run(self, dict_of_input, dict_of_output):
     LOGGER.info("Snow percentage computation start")
     param_stats = {"im": dict_of_output.get("cld_snow"), "exclude": 1}
     l2_stat = OtbAppHandler("Stats", param_stats)
     # Test on the value
     if (l2_stat.getoutput()["excludedcount"] == 0
             and l2_stat.getoutput()["validcount"] == 0):
         l_snowrate = 0
     else:
         l_snowrate = l2_stat.getoutput()["excludedcount"] * 100.0 / (
             l2_stat.getoutput()["excludedcount"] +
             l2_stat.getoutput()["validcount"])
     LOGGER.debug("L2 snowrate : " + str(l_snowrate))
     dict_of_output["SnowRate"] = l_snowrate
     return l_snowrate
 def run(self, dict_of_input, dict_of_output):
     LOGGER.info("Cirrus flag computation start")
     param_cirrus = {
         "cla":
         dict_of_output["CLA_Sub"],
         "edg":
         dict_of_input.get("L1Reader").get_value("IPEDGSubOutput"),
         "altthreshold":
         int(dict_of_input.get("L2COMM").get_value("AltitudeThreshold")),
         "minpercentcirrus":
         float(dict_of_input.get("L2COMM").get_value("MinPercentCirrus")),
         "minpercentcloud":
         float(dict_of_input.get("L2COMM").get_value("MinPercentCloud")),
         "minstdcirrus":
         float(dict_of_input.get("L2COMM").get_value("MinRstdCirrus")),
         "minpercentstdcirrus":
         float(
             dict_of_input.get("L2COMM").get_value("MinPercentStdCirrus")),
         "nodata":
         dict_of_input.get("L1Info").RealL1NoData
     }
     cirrus_mask_app = OtbAppHandler("CirrusFlag",
                                     param_cirrus,
                                     write_output=True)
     dict_of_output["CirrusFlag"] = cirrus_mask_app.getoutput(
     )["cirrusflag"]
     cirrus_mask_app = None
Esempio n. 7
0
    def generate_l2_sat_images(self, l_ListOfL2Resolution, working_dir):
        for l1res in range(len(l_ListOfL2Resolution)):
            curL1Res = l_ListOfL2Resolution[l1res]
            l_ListOfL2BandCode = self._plugin.BandsDefinitions.get_list_of_l2_band_code(
                curL1Res)
            dtm = self._dem.ALTList[0]
            tmp_constant_sat_filename = os.path.join(
                working_dir, "SAT_constant_image_{}.tif".format(l1res))
            app_constant_sat_app = constant_image(dtm,
                                                  0,
                                                  tmp_constant_sat_filename,
                                                  write_output=False)
            self._sat_pipeline.add_otb_app(app_constant_sat_app)
            # ******************************************************************************************************
            # L2 SAT image pipeline connection
            # ******************************************************************************************************
            for band in l_ListOfL2BandCode:
                self._satmasklist.append(
                    app_constant_sat_app.getoutput().get("out"))

            out_sat_concatenate = os.path.join(
                working_dir, "SATVectorImageList{}.tif".format(l1res))
            param_concatenate_sat = {
                "il": self._satmasklist,
                "out": out_sat_concatenate + ":uint8"
            }
            concatenate_sat_app = OtbAppHandler("ConcatenateDoubleImages",
                                                param_concatenate_sat,
                                                write_output=False)
            self._sat_pipeline.add_otb_app(concatenate_sat_app)
            # L2SAT
            self._l2satmasklist.append(
                concatenate_sat_app.getoutput().get("out"))
    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
Esempio n. 9
0
 def generate_sol1_image(self, sol_h1, working_dir):
     const_pi_18 = math.pi / 180
     sol_filename = os.path.join(working_dir, "sol1.tif")
     mean_solar = self._header_handler.get_mean_solar_angles()
     l_sol1 = sol_h1 * math.tan(const_pi_18 * mean_solar[0]) * math.sin(
         const_pi_18 * mean_solar[1])
     l_sol2 = sol_h1 * math.tan(const_pi_18 * mean_solar[0]) * math.cos(
         const_pi_18 * mean_solar[1])
     cla_app_1 = constant_image(self._dem.ALC,
                                l_sol1,
                                sol_filename,
                                write_output=False)
     cla_app_2 = constant_image(self._dem.ALC,
                                l_sol2,
                                sol_filename,
                                write_output=False)
     out_concatenate = os.path.join(working_dir, "sol1_concat.tif")
     param_concatenate = {
         "il": [
             cla_app_1.getoutput().get("out"),
             cla_app_2.getoutput().get("out")
         ],
         "out":
         out_concatenate
     }
     app = OtbAppHandler("ConcatenateDoubleImages", param_concatenate)
     self._sol1image = app.getoutput().get("out")
     self._sol1_pipeline.add_otb_app(app)
    def write_cld_image(self,
                        p_cldimages,
                        p_clddatabandsselected,
                        cld_image_filename,
                        use_filenames=False):
        il = []
        for c in p_clddatabandsselected:
            band = self._plugin.get_cld_algoindex_from_bandname(c)
            il.append(p_cldimages[band])

        param_concat = {"il": il, "out": "tmp.tif:uint8"}
        if not use_filenames:
            concat_app = OtbAppHandler("ConcatenateMaskImages",
                                       param_concat,
                                       write_output=False)
        else:
            concat_app = OtbAppHandler("ConcatenateImages",
                                       param_concat,
                                       write_output=False)
        param_bin_concat = {
            "im":
            concat_app.getoutput().get("out"),
            "out":
            cld_image_filename + ":uint8" +
            file_utils.get_extended_filename_write_image_file_standard()
        }
        bin_concat_app = OtbAppHandler("BinaryConcatenate",
                                       param_bin_concat,
                                       write_output=True)
def get_ozone_amount(ozone_filename, corner):
    ozoneamount = 0.0
    l_gribfilename = os.path.splitext(ozone_filename)[0] + ".DBL.BIN"
    if os.path.exists(l_gribfilename):
        LOGGER.info("Reading meteo file : " + l_gribfilename)
        param_app = {
            "im": l_gribfilename + "?&resol=7",
            "lat": corner.latitude,
            "lon": corner.longitude
        }
        app = OtbAppHandler("OzoneExtractor", param_app)
        ozoneamount = app.getoutput()["ozone"]
        # ------------------------------------------------------------------------------------
        # Conversion from Kg/m2 to cm.atm (Dobson Unit/1000)
        # Note:
        # - 1 kg[O3]/m2 = 1/2.1416 x 10-5 = 46694.06 dobson
        # - 1 cm.atm = 1 jacobson = 1000 dobson
        # In the ozone file, the value is in 1 kg[O3]/m2.
        # The ozone value computed is in Jacobson (cm.atm/m2)
        l_dobsonconversionfactor = 46.694
        ozoneamount = ozoneamount * l_dobsonconversionfactor
        LOGGER.debug(
            "OzoneAmountValue patched with the following Dobson conversion factor "
            + str(l_dobsonconversionfactor) + ".")
    return ozoneamount
Esempio n. 12
0
 def generate_vie_image(self, view_href, working_dir):
     const_pi_18 = math.pi / 180
     vie_filename = os.path.join(working_dir, "vie.tif")
     mean_solar = self._header_handler.get_mean_solar_angles()
     l_vie1 = view_href * math.tan(const_pi_18 * mean_solar[0]) * math.sin(
         const_pi_18 * mean_solar[1])
     l_vie2 = view_href * math.tan(const_pi_18 * mean_solar[0]) * math.cos(
         const_pi_18 * mean_solar[1])
     app_1 = constant_image(self._dem.ALC,
                            l_vie1,
                            vie_filename,
                            write_output=False)
     app_2 = constant_image(self._dem.ALC,
                            l_vie2,
                            vie_filename,
                            write_output=False)
     out_concatenate = os.path.join(working_dir, "vie_concat.tif")
     param_concatenate = {
         "il": [app_1.getoutput().get("out"),
                app_2.getoutput().get("out")],
         "out": out_concatenate
     }
     app = OtbAppHandler("ConcatenateDoubleImages", param_concatenate)
     self._vieimage.append(app.getoutput().get("out"))
     self._vie_pipeline.add_otb_app(app)
Esempio n. 13
0
    def generate_sat_sub_image(self, l2comm, working):
        # Sat are not provided on landsat 8 thus no need to resample or threshold anything, just create constant
        # images at coarse resolution
        dtm_coarse = self._dem.ALC

        l_ListOfCoarseBandCode = self._plugin.BandsDefinitions.get_list_of_band_id_in_l2_coarse(
        )
        tmp_constant_sat_filename = os.path.join(working,
                                                 "SATSub_constant_image.tif")
        app_constant_sat_app = constant_image(dtm_coarse,
                                              0,
                                              tmp_constant_sat_filename +
                                              ":uint8",
                                              write_output=False)
        self._sat_sub_pipeline.add_otb_app(app_constant_sat_app)
        # ******************************************************************************************************
        # Sub SAT image pipeline connection
        # ******************************************************************************************************
        for band in l_ListOfCoarseBandCode:
            self._satsublist.append(
                app_constant_sat_app.getoutput().get("out"))
        # end band loop
        #concatenate const image to have the vector image with coarse nb bands
        sat_sub_image = os.path.join(working, "sat_sub.tif")
        param_concatenate = {
            "il": self._satsublist,
            "out": sat_sub_image + ":uint8"
        }
        app_concatenate = OtbAppHandler("ConcatenateMaskImages",
                                        param_concatenate)
        self._subsatimage = app_concatenate.getoutput().get("out")
        self._sat_sub_pipeline.add_otb_app(app_concatenate)
        self._sat_sub_pipeline.free_otb_app()
    def generate_l2_toa_images(self, working_dir):
        """
        :param 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]

            # 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
                list_of_image.append(self._toa_scalar_list[l1BandIdx])
            out_concatenate = os.path.join(
                working_dir, "L2TOAImageListVector_" + curRes + ".tif")
            param_concatenate = {"il": list_of_image, "out": out_concatenate}
            l2toa_concat_app = OtbAppHandler(
                "ConcatenateDoubleImages",
                param_concatenate,
                write_output=(False
                              or is_croco_on("sentinel2.l1reader.l2toa")))
            self._pipeline.add_otb_app(l2toa_concat_app)
            self._l2toaimagelist.append(
                l2toa_concat_app.getoutput().get("out"))
Esempio n. 15
0
 def run(self, dict_of_input, dict_of_output):
     LOGGER.info("Scattering Correction start")
     scat_working = dict_of_input.get(
         "AppHandler").get_directory_manager().get_temporary_directory(
             "ScatteringProc_", do_always_remove=True)
     l_caching = dict_of_input.get("Params").get("Caching")
     l_writeL2 = dict_of_input.get("Params").get(
         "WriteL2ProductToL2Resolution")
     tocr_sub_image = os.path.join(scat_working, "tocr_sub.tif")
     bands_definition = dict_of_input.get("Plugin").BandsDefinitions
     #  Coarse scattering correction
     param_scattering = {
         "lutmap": dict_of_output["hr_lutmap"],
         "toac": dict_of_output["AtmoAbsIPTOAC"],
         "aot": dict_of_output["AOT_Sub"],
         "edg": dict_of_input.get("L1Reader").get_value("IPEDGSubOutput"),
         "dtm": dict_of_input.get("DEM").ALC,
         "l2nodata": dict_of_input.get("Params").get("RealL2NoData"),
         "l2bandincoarse":
         bands_definition.get_list_of_band_id_in_l2_coarse(),
         "tocr": tocr_sub_image
     }
     self._scattering_sub_app = OtbAppHandler("ScatteringCorrection",
                                              param_scattering,
                                              write_output=False)
     dict_of_output["TOC_sub"] = self._scattering_sub_app.getoutput(
     )["tocr"]
     # l2 scattering correction
     tocr_list = []
     if l_writeL2:
         l_nbRes = len(bands_definition.ListOfL2Resolution)
         for r in range(0, l_nbRes):
             l_res = bands_definition.ListOfL2Resolution[r]
             tocr_image = os.path.join(scat_working,
                                       "tocr_" + l_res + ".tif")
             if dict_of_input.get("Plugin").WideFieldSensor:
                 param_scattering["anglezone"] = dict_of_input.get(
                     "L1Reader").get_value("AngleZoneMaskList")[r]
             param_scattering["dtm"] = dict_of_input.get("DEM").ALTList[r]
             param_scattering["edg"] = dict_of_input.get(
                 "L1Reader").get_value("L2EDGOutputList")[r]
             param_scattering["aot"] = dict_of_output["AOT_" + l_res]
             param_scattering["toac"] = dict_of_output["L2TOA_" + l_res]
             param_scattering["tocr"] = tocr_image
             l_l2bandids = bands_definition.get_list_of_l2_coarse_band_id_associated_to_l2_band_code(
                 bands_definition.get_list_of_l2_band_code(l_res))
             param_scattering["l2bandincoarse"] = [
                 str(b) for b in l_l2bandids
             ]
             scat_app = OtbAppHandler(
                 "ScatteringCorrection",
                 param_scattering,
                 write_output=is_croco_on("scatteringcorrection"))
             self._l2_pipeline.add_otb_app(scat_app)
             dict_of_output["TOC_" +
                            l_res] = scat_app.getoutput().get("tocr")
             tocr_list.append(dict_of_output["TOC_" + l_res])
         dict_of_output["L2TOCList"] = tocr_list
Esempio n. 16
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()
Esempio n. 17
0
class MajaRayleighCorrection(MajaModule):
    """
    classdocs
    """

    NAME = "RayleighCorrection"

    def __init__(self):
        """
        Constructor
        """
        super(MajaRayleighCorrection, self).__init__()
        self._rayleigh_app = None
        self.in_keys_to_check = [
            "Params.Caching", "AppHandler", "Plugin", "L1Reader", "L2COMM",
            "DEM", "L2TOCR", "Params.RealL2NoData"
        ]
        self.out_keys_to_check = ["AtmoAbsIPTOAC", "cr_lut"]
        self.out_keys_provided = ["RayleighIPTOCR"]

    def run(self, dict_of_input, dict_of_output):
        LOGGER.info("Rayleigh Correction start")
        caching = dict_of_input.get("Params").get("Caching")
        if caching:
            ray_working = dict_of_input.get(
                "AppHandler").get_directory_manager().get_temporary_directory(
                    "RayleighProc_", do_always_remove=True)
        else:
            ray_working = ""

        tocr_image = os.path.join(ray_working, "tocr_sub.tif")
        param_rayleigh = {
            "lutimage":
            dict_of_output.get("cr_lut"),
            "lutheader":
            dict_of_input.get("L2TOCR"),
            "toa":
            dict_of_output.get("AtmoAbsIPTOAC"),
            "edg":
            dict_of_input.get("L1Reader").get_value("IPEDGSubOutput"),
            "dtm":
            dict_of_input.get("DEM").ALC,
            "nodata":
            dict_of_input.get("Params").get("RealL2NoData"),
            "defaultaot":
            float(
                dict_of_input.get("L2COMM").get_value(
                    "RayleighCorrectionDefaultAOT")),
            "tocr":
            tocr_image
        }
        self._rayleigh_app = OtbAppHandler("RayleighCorrection",
                                           param_rayleigh,
                                           write_output=True)
        dict_of_output["RayleighIPTOCR"] = self._rayleigh_app.getoutput(
        )["tocr"]
Esempio n. 18
0
def assign_zenith_and_azimuth_image_to_grid_to_image(input_image_zen, input_value_azi, output_filename):
    """

    :param output_filename:
    :param input_image_zen:
    :param input_value_azi:
    :return:
    """
    band_math_1 = OtbAppHandler("BandMath", {"il": [input_image_zen, input_value_azi],
                                             "exp": "tan(im1b1)*sin(im2b1)"}, write_output=False)

    pipeline = OtbPipelineManager()
    pipeline.add_otb_app(band_math_1)
    band_math_2 = OtbAppHandler("BandMath", {"il": [input_image_zen, input_value_azi],
                                             "exp": "tan(im1b1)*cos(im2b1)"}, write_output=False)
    pipeline.add_otb_app(band_math_2)

    concat = OtbAppHandler("ConcatenateImages", {"il": [band_math_1.getoutput().get(
        "out"), band_math_2.getoutput().get("out")], "out": output_filename}, write_output=True)
    pipeline.add_otb_app(concat)

    return pipeline
Esempio n. 19
0
 def generate_qb_mask(self, qb_filename, working_dir):
     img_binaryqb = os.path.join(working_dir, "NoDataFromQBFilter.tif")
     param_bintovec_qb = {
         "im": qb_filename,
         "out": img_binaryqb + ":uint8",
         "nbcomp": 16
     }
     app = OtbAppHandler("BinaryToVector",
                         param_bintovec_qb,
                         write_output=False)
     self._toa_pipeline.add_otb_app(app)
     self._qbmask = app.getoutput().get("out")
     self._qb_pipeline.add_otb_app(app)
Esempio n. 20
0
class MajaCloudMaskUndersampling(MajaModule):
    """
    classdocs
    """

    NAME = "CloudMaskUndersampling"

    def __init__(self):
        """
        Constructor
        """
        super(MajaCloudMaskUndersampling, self).__init__()
        self._undersampling_app = None

    def run(self, dict_of_input, dict_of_output):
        LOGGER.info("Cloud Mask Undersampling start")
        caching = dict_of_input.get("Params").get("Caching")
        cla_working = ""
        if caching:
            cla_working = dict_of_input.get(
                "AppHandler").get_directory_manager().get_temporary_directory(
                    "CloudMaskUnderProc_", do_always_remove=True)
        l1_cla = dict_of_input.get("L1Reader").get_value("CLAImage")
        cla_image = os.path.join(cla_working, "cla_image_sub.tif")
        clalt_image = os.path.join(cla_working, "clalt_image_sub.tif")
        param_resamp_cla = {
            "dtm": dict_of_input.get("DEM").ALC,
            "im": l1_cla,
            "nodata": dict_of_input.get("L1Info").RealL1NoData,
            "cla": cla_image,
            "clalt": clalt_image
        }
        self._undersampling_app = OtbAppHandler("CloudMaskUndersampling",
                                                param_resamp_cla,
                                                write_output=caching)
        dict_of_output["CLA_Sub"] = self._undersampling_app.getoutput()["cla"]
        dict_of_output["CLALT_Sub"] = self._undersampling_app.getoutput(
        )["clalt"]
Esempio n. 21
0
 def run(self, dict_of_input, dict_of_output):
     LOGGER.info("Validity L2 nominal computation start")
     param_stats = {
         "im": dict_of_input.get("L2Reader").get_value("NDTImage"),
         "exclude": 1
     }
     l2_stat = OtbAppHandler("Stats", param_stats)
     # Test on the value
     l_L2inNoDataRate = 0
     if l2_stat.getoutput()["excludedcount"] == 0 and l2_stat.getoutput(
     )["validcount"] == 0:
         l_L2inNoDataRate = 0
     else:
         l_L2inNoDataRate = l2_stat.getoutput()["excludedcount"] * 100.0 / \
             (l2_stat.getoutput()["excludedcount"] + l2_stat.getoutput()["validcount"])
     LOGGER.debug("L2 no data rate : " + str(l_L2inNoDataRate))
     dict_of_output["L2inNoDataRate"] = l_L2inNoDataRate
     dict_of_output["L2inValidity"] = False
     if l_L2inNoDataRate > float(
             dict_of_input.get("L2COMM").get_value("MaxNoDataPercentage")):
         dict_of_output["L2inValidity"] = False
     else:
         dict_of_output["L2inValidity"] = True
 def generate_sat_images(self, working_dir):
     """
     :return:
     """
     # *******************************************************************************************************
     # IPSAT Sub image pipeline connection
     # *******************************************************************************************************
     out_concatenate = os.path.join(working_dir, "SubSatVector.tif")
     param_concatenate = {"il": self._satmasksublist,
                          "out": out_concatenate + ":uint8"
                          }
     concat_app = OtbAppHandler("ConcatenateDoubleImages", param_concatenate)
     self._subsatimage = concat_app.getoutput().get("out")
     self._sub_sat_pipeline.free_otb_app()
class MajaCirrusMaskComputation(MajaModule):
    """
    classdocs
    """
    NAME = "CirrusMask"

    def __init__(self):
        """
        Constructor
        """
        super(MajaCirrusMaskComputation, self).__init__()
        self._cirrus_mask_app = None
        self.in_keys_to_check = [ "AppHandler", "Plugin", "L1Reader","L2COMM", "DEM"]
        self.out_keys_to_check = []
        self.out_keys_provided = ["CirrusFlag", "CirrusMask"]

    def run(self, dict_of_input, dict_of_output):
        LOGGER.info("Cirrus mask computation start")
        cirrus_working = dict_of_input.get("AppHandler").get_directory_manager().get_temporary_directory("CirrusMask_Computation_",
                                            do_always_remove=True)
        cirrus_mask = os.path.join(cirrus_working, "cirrus_mask_sub.tif")
        cirrus_band_code = dict_of_input.get("L2COMM").get_value("CirrusBandCode")
        bands_definition = dict_of_input.get("Plugin").BandsDefinitions
        cirrus_band_idx = bands_definition.get_band_id_in_l2_coarse(cirrus_band_code)
        param_cirrus = {"toa": dict_of_input.get("L1Reader").get_value("IPTOASubOutput"),
                        "edg": dict_of_input.get("L1Reader").get_value("IPEDGSubOutput"),
                        "dtm": dict_of_input.get("DEM").ALC,
                        "bandidx": cirrus_band_idx,
                        "threshoff": float(dict_of_input.get("L2COMM").get_value("CirrusMaskThresholdOffset")),
                        "threshgain": float(dict_of_input.get("L2COMM").get_value("CirrusMaskThresholdGain")),
                        "minpercent": float(dict_of_input.get("L2COMM").get_value("MinPercentMaskCirrus")),
                        "altref" : float(dict_of_input.get("L2COMM").get_value("CirrusAltRef")),
                        "mask": cirrus_mask + ":uint8"
                        }
        self._cirrus_mask_app = OtbAppHandler("CirrusMask", param_cirrus, write_output=True)
        dict_of_output["CirrusMask"] = self._cirrus_mask_app.getoutput()["mask"]
        dict_of_output["CirrusFlag"] = self._cirrus_mask_app.getoutput()["cirrusflag"]
    def generate_l1_toa_images(self, working_dir):
        """

        :return:
        """

        out_concatenate = os.path.join(working_dir, "L1TOAVector.tif")
        param_concatenate = {
            "il": self._toa_scalar_list,
            "out": out_concatenate
        }
        app = OtbAppHandler("ConcatenateDoubleImages",
                            param_concatenate,
                            write_output=False)
        self._l1toa_pipeline.add_otb_app(app)
        self._l1toaimagelist.append(app.getoutput()["out"])
Esempio n. 25
0
    def generate_l1_toa_image(self, l2comm, factor, solzenith, L1ResolList,
                              working_dir):
        for l1res in range(len(L1ResolList)):
            curL1Res = L1ResolList[l1res]
            l_ListOfL1BandCode = self._plugin.BandsDefinitions.get_list_of_l1_band_code(
                curL1Res)

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

                img_toaconverter = os.path.join(
                    working_dir, "TOAConverter_{}.tif".format(band))
                app_bandmath = band_math([
                    self._header_handler.get_toa_image_filename_from_band_code(
                        band), self._qbmask
                ],
                                         expression_bandmath,
                                         img_toaconverter,
                                         write_output=False)
                self._toascalarlist.append(app_bandmath.getoutput().get("out"))
                self._toa_pipeline.add_otb_app(app_bandmath)
            img_concatenate_toa = os.path.join(working_dir,
                                               "l1toa_{}.tif".format(l1res))
            param_concatenate_toa = {
                "il": self._toascalarlist,
                "out": img_concatenate_toa
            }
            app_concatenate_toa = OtbAppHandler("ConcatenateDoubleImages",
                                                param_concatenate_toa,
                                                write_output=True)
            self._l1toaimagelist.append(app_concatenate_toa.getoutput()["out"])
            self._qb_pipeline.free_otb_app()
            self._toa_pipeline.free_otb_app()
 def run(self, dict_of_input, dict_of_output):
     LOGGER.info("NoData percentage validity check start")
     param_stats = {"im": dict_of_output["Composite_ndt"], "exclude": 1}
     l2_stat = OtbAppHandler("Stats", param_stats)
     # Test on the value
     LOGGER.debug("L2Nodata : excludedcount : " +
                  str(l2_stat.getoutput()["excludedcount"]))
     LOGGER.debug("L2Nodata : validcount : " +
                  str(l2_stat.getoutput()["validcount"]))
     l_nodatarate = 0
     if l2_stat.getoutput()["excludedcount"] == 0 and l2_stat.getoutput(
     )["validcount"] == 0:
         l_nodatarate = 0
     else:
         l_nodatarate = l2_stat.getoutput()["excludedcount"] * 100.0 / \
             (l2_stat.getoutput()["excludedcount"] + l2_stat.getoutput()["validcount"])
     LOGGER.debug("L2 nodatarate : " + str(l_nodatarate))
     dict_of_output["NoDataRate"] = l_nodatarate
    def _dilate_and_mask(input, temp, output, mask, radius, caching):
        param_dilate = {
            "in": input,
            "out": temp + ":uint8",
            "structype": "ball",
            "xradius": radius,
            "yradius": radius,
            "filter": "dilate"
        }
        dilate_app = OtbAppHandler("BinaryMorphologicalOperation",
                                   param_dilate,
                                   write_output=caching)

        param_mask = {
            "il": [dilate_app.getoutput()["out"], mask],
            "out": output + ":uint8",
            "exp": "(im2b1 !=0)?0:im1b1"
        }
        mask_app = OtbAppHandler("BandMath", param_mask, write_output=caching)
        return mask_app
    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"))
 def run(self, dict_of_input, dict_of_output):
     LOGGER.info("Cloud percentage validity check start")
     param_stats = {
         "im": dict_of_output.get(CLOUD_MASK_ALL_CLOUDS),
         "exclude": 1
     }
     l2_stat = OtbAppHandler("Stats", param_stats)
     # Test on the value
     LOGGER.debug("L2Cloud : excludedcount : " +
                  str(l2_stat.getoutput()["excludedcount"]))
     LOGGER.debug("L2Cloud : validcount : " +
                  str(l2_stat.getoutput()["validcount"]))
     LOGGER.debug("L2Cloud : nodatanumber : " +
                  str(dict_of_output["L2NoDataNumber"]))
     l_cloudrate = 0
     if l2_stat.getoutput()["excludedcount"] == 0 and l2_stat.getoutput(
     )["validcount"] == 0:
         l_cloudrate = 0
     else:
         l_cloudrate = l2_stat.getoutput()["excludedcount"] * 100.0 / \
             (l2_stat.getoutput()["excludedcount"] + l2_stat.getoutput()["validcount"] - dict_of_output["L2NoDataNumber"])
     LOGGER.debug("L2 cloudrate : " + str(l_cloudrate))
     dict_of_output["CloudRate"] = l_cloudrate
Esempio n. 30
0
class MajaDTMProcessing(MajaModule):
    """
    classdocs
    """

    NAME = "DTMProcessing"

    def __init__(self):
        """
        Constructor
        """
        super(MajaDTMProcessing, self).__init__()
        self._solar_app = None
        self._dtm_app = None
        self.in_keys_to_check = [
            "Params.Caching", "AppHandler", "Plugin", "L1Reader", "L2COMM",
            "DEM"
        ]
        self.out_keys_to_check = []
        self.out_keys_provided = ["dtm_shd", "dtm_hid"]

    def run(self, dict_of_input, dict_of_output):
        LOGGER.info("DTMProcessing computation start")
        LOGGER.debug("Caching %s", dict_of_input.get("Params").get("Caching"))
        dtm_working = dict_of_input.get(
            "AppHandler").get_directory_manager().get_temporary_directory(
                "DTmProc_", do_always_remove=True)
        solar_imge = os.path.join(dtm_working, "solar_angle.tif")
        hid_imge = os.path.join(dtm_working, "dtm_hid.tif")
        shd_imge = os.path.join(dtm_working, "dtm_shd.tif")
        grid_ref_alt = dict_of_input.get(
            "Plugin").ConfigUserCamera.get_Algorithms(
            ).get_GRID_Reference_Altitudes()
        param_solar = {
            "sol1.in": dict_of_input.get("L1Reader").get_value("SOL1Image"),
            "sol1.h": grid_ref_alt.get_SOLH1(),
            "solhref": grid_ref_alt.get_SOLHRef(),
            "sol": solar_imge
        }
        if dict_of_input.get("Plugin").GRIDReferenceAltitudesSOL2GridAvailable:
            param_solar["sol2.in"] = dict_of_input.get("L1Reader").get_value(
                "SOL2Image")
            param_solar["sol2.h"] = grid_ref_alt.get_SOLH2()

        self._solar_app = OtbAppHandler("SolarAngle",
                                        param_solar,
                                        write_output=True)

        param_dtm = {
            "viedtm":
            dict_of_input.get("L1Reader").get_value("DTMVIEImage"),
            "edg":
            dict_of_input.get("L1Reader").get_value("IPEDGSubOutput"),
            "distthreshold":
            float(dict_of_input.get("L2COMM").get_value("DistanceThreshold")),
            "solhref":
            self._solar_app.getoutput().get("outhref"),
            "viehref":
            grid_ref_alt.get_VIEHRef(),
            "hid":
            hid_imge,
            "shd":
            shd_imge,
            "dtm":
            dict_of_input.get("DEM").ALC,
            "solar":
            self._solar_app.getoutput()["sol"]
        }
        self._dtm_app = OtbAppHandler("DTMProcessing",
                                      param_dtm,
                                      write_output=True)
        # Update global dict with new output
        dict_of_output["dtm_shd"] = self._dtm_app.getoutput()["shd"]
        dict_of_output["dtm_hid"] = self._dtm_app.getoutput()["hid"]