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 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"))
Exemple #3
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
Exemple #4
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
Exemple #5
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)
Exemple #6
0
    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"]
Exemple #7
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 generate_sol1_image(self, sol_h1, working_dir):
     LOGGER.debug("MuscateL1ImageFileReader::GenerateSOL1Image()")
     const_pi_18 = 0.01745329251994329577
     # SOL1 image pipeline connection
     # *********************************************************************************************************
     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])
     LOGGER.debug("SOL1 parameters : ")
     LOGGER.debug(mean_solar)
     LOGGER.debug(l_sol1)
     LOGGER.debug(l_sol2)
     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
     }
     OtbAppHandler("ConcatenateDoubleImages", param_concatenate)
     self._sol1image = out_concatenate
Exemple #9
0
def write_images(img_list, img_filenames):
    # TODO : Remove fixed streaming lines

    if len(img_list) != len(img_filenames):
        raise MajaBusinessException(
            "Not the same number of image and filename given to write_images")

    tmp_img_list_clean = []
    tmp_filename_list_clean = []
    for f in range(len(img_list)):
        if type(img_list[f]).__name__ != "str":
            tmp_img_list_clean.append(img_list[f])
            tmp_filename_list_clean.append(img_filenames[f])
        else:
            LOGGER.debug("source : " + img_list[f] + " , dest : " +
                         img_filenames[f])
            try:
                if not os.path.exists(
                        img_filenames[f]) or not os.path.samefile(
                            img_list[f], img_filenames[f]):
                    shutil.copyfile(img_list[f], img_filenames[f])
            except IOError as err:
                raise MajaIOError(err)

    if len(tmp_img_list_clean) == 0:
        return

    parameters = {
        "il": tmp_img_list_clean,
        "filenames": tmp_filename_list_clean
    }

    app = OtbAppHandler("ImageListWriter", parameters)
    del app
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
Exemple #11
0
def band_math(input_file_path_list, exp, output_image, write_output=True):

    parameters = {"exp": exp, "il": input_file_path_list, "out": output_image}

    app = OtbAppHandler("BandMathDouble", parameters, write_output)

    return app
Exemple #12
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
    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()
 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
    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"))
Exemple #17
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)
Exemple #18
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)
Exemple #19
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_vie_image(self, view_href, working_dir):
     # *********************************************************************************************************
     # VIE image pipeline connection
     # *********************************************************************************************************
     sol_filename = os.path.join(working_dir, "cla_constant_tmp.tif")
     mean_view = self._header_handler.get_mean_viewing_angles()
     l_vie1 = view_href * math.tan(mean_view[0]) * math.sin(mean_view[1])
     l_vie2 = view_href * math.tan(mean_view[0]) * math.cos(mean_view[1])
     vie_app_1 = constant_image(self._dem.ALC,
                                l_vie1,
                                sol_filename,
                                write_output=False)
     vie_app_2 = constant_image(self._dem.ALC,
                                l_vie2,
                                sol_filename,
                                write_output=False)
     out_concatenate = os.path.join(working_dir, "cla_constant.tif")
     param_concatenate = {
         "il": [
             vie_app_1.getoutput().get("out"),
             vie_app_2.getoutput().get("out")
         ],
         "out":
         out_concatenate
     }
     OtbAppHandler("ConcatenateDoubleImages", param_concatenate)
     l_BandsDefinitions = self._plugin.BandsDefinitions
     self._vieimagelist.append(out_concatenate)
    def run(self, dict_of_input, dict_of_output):
        LOGGER.info("Water masking computation start")

        caching = dict_of_input.get("Params").get("Caching")
        if caching:
            water_working = dict_of_input.get("AppHandler").get_directory_manager().get_temporary_directory("WaterMaskingProc_",
                                            do_always_remove=True)
        else:
            water_working = ""

        water_mask = os.path.join(water_working, "water_sub.tif")
        possible_water_mask = os.path.join(water_working, "possible_water_sub.tif")
        tested_water_mask = os.path.join(water_working, "tested_water_sub.tif")
        param_water = {"tocr": dict_of_output.get("RayleighIPTOCR"),
                       "edg": dict_of_input.get("L1Reader").get_value("IPEDGSubOutput"),
                       "cldsum": dict_of_output.get(constants.CLOUD_MASK_ALL_CLOUDS),
                       "dtmshd": dict_of_output["dtm_shd"],
                       "srtmwat": dict_of_input.get("DEM").MSK,
                       "demslc": dict_of_input.get("DEM").SLC,
                       "redbandtocr": dict_of_input.get("Params").get("RedBandIndex_DateD"),
                       "nirbandtocr": dict_of_input.get("Params").get("NIRBandIndex_DateD"),
                       "nirbandrcr": dict_of_input.get("Params").get("NIRBandIndex_DateDm1"),
                       "waterndvithreshold": dict_of_input.get("L2COMM").get_value_f("WaterNDVIThreshold"),
                       "waterreflectancevariationthreshold": dict_of_input.get("L2COMM").get_value_f(
                           "WaterReflectanceVariationThreshold"),
                       "maximumsunglintreflectance": dict_of_input.get("L2COMM").get_value_f(
                           "MaximumSunglintReflectance"),
                       "srtmgaussiansigma": dict_of_input.get("L2COMM").get_value_f("SRTMSigmaSmoothing"),
                       "srtmpercent": dict_of_input.get("L2COMM").get_value_f("SRTMPercent"),
                       "watermasknumber": dict_of_input.get("L2COMM").get_value_i("WaterMaskNumber"),
                       "minpercentpossiblewater": dict_of_input.get("L2COMM").get_value_f("MinPercentPossibleWater"),
                       "waterslopethreshold": dict_of_input.get("L2COMM").get_value_f("WaterSlopeThreshold"),
                       "waterredreflectancethreshold": dict_of_input.get("L2COMM").get_value_f(
                           "WaterRedReflectanceThreshold"),
                       "reall2nodata": dict_of_input.get("Params").get("RealL2NoData"),
                       "was": water_mask + ":uint8",
                       "pwa": possible_water_mask + ":uint8",
                       "twa": tested_water_mask + ":uint8"
                       }

        if not dict_of_input.get("Params").get("InitMode"):
            param_water["l2rcr"] = dict_of_input.get("L2Reader").get_value("RCRImage")
            param_water["l2pwa"] = dict_of_input.get("L2Reader").get_value("PWAImage")
            param_water["l2twa"] = dict_of_input.get("L2Reader").get_value("TWAImage")

        if dict_of_input.get("Params").get("InitMode"):
            param_water["initmode"] = dict_of_input.get("Params").get("InitMode")

        if dict_of_output["SunglintFlag"]:
            param_water["sunglintflag"] = dict_of_output["SunglintFlag"]

        self._water_app = OtbAppHandler("WaterMask", param_water, write_output=True)

        #  Update output dictionary
        dict_of_output["WaterMask"] = self._water_app.getoutput()["was"]
        dict_of_output["PossibleWaterMask"] = self._water_app.getoutput()["pwa"]
        dict_of_output["TestedWaterMask"] = self._water_app.getoutput()["twa"]
Exemple #22
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()
Exemple #23
0
def multiply_by_scalar(input_file_path,
                       scalar,
                       output_image,
                       write_output=True):

    parameters = {"coef": scalar, "im": input_file_path, "out": output_image}

    app = OtbAppHandler("MultiplyByScalar", parameters, write_output)

    return app
    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
Exemple #25
0
def extract_roi(input_file_path, channels, output_image, write_output=True):
    parameters = {
        "in": input_file_path,
        "cl": ["Channel" + str(idx + 1) for idx in channels],
        "out": output_image
    }
    if get_test_mode():
        parameters.pop("cl")
    app = OtbAppHandler("ExtractChannels", parameters, write_output)

    return app
Exemple #26
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)
Exemple #27
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
Exemple #28
0
def stats(input_file_path, exclude_value=None, input_mask=None, mask_foreground=None, write_output=True):

    param_stats = {"im": input_file_path}

    if input_mask is not None:
        param_stats["mask"] = input_mask
    if mask_foreground is not None:
        param_stats["maskforeground"] = mask_foreground
    if exclude_value is not None:
        param_stats["exclude"] = exclude_value

    app = OtbAppHandler("Stats", param_stats, write_output)

    return app
Exemple #29
0
def constant_image(dtm, value, output_image, write_output=True):
    """

    :param output_image:
    :param dtm:
    :param value:
    :param write_output:
    :return:
    """
    parameters = {"value": value, "dtm": dtm, "out": output_image}

    app = OtbAppHandler("ConstantImage", parameters, write_output)

    return app
def solar_angle(solar_angle_image, sol1_height, sol_href, output_image, sol2_in=None, sol2_height=None,
                write_output=True):
    # test about input and raise MajaNotYetImplemented is case of sol2 case
    if sol2_in is not None or sol2_height is not None:
        raise MajaNotYetImplemented()

    parameters = {"sol1.in": solar_angle_image,
                  "sol1.h": sol1_height,
                  "solhref": sol_href,
                  "sol": output_image}

    app = OtbAppHandler("SolarAngle", parameters, write_output)

    return app