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): 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)
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 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 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_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"))
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
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 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
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
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"]
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)
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"]
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)
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()
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
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 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"])
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 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 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
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()
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"]
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 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
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
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"))
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 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