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 write_quicklook_image_from_files( filename, p_WritePublicProduct, p_QuicklookRedBandImage, p_QuicklookGreenBandImage, p_QuicklookBlueBandImage, p_QuicklookMinReflRedBand, p_QuicklookMaxReflRedBand, p_QuicklookMinReflGreenBand, p_QuicklookMaxReflGreenBand, p_QuicklookMinReflBlueBand, p_QuicklookMaxReflBlueBand, p_RealL2NoData, dtm, working_dir): # ==================================================================== # IF PUBLIC PART OF L2 PRODUCT IS WRITTEN # ==================================================================== if p_WritePublicProduct: LOGGER.debug("Start QLK wiring...") # Replace NoData value by min # TODO # Generate he quicklook tmp_qlk_red_sub = os.path.join(working_dir, "tmp_qck_red_sub.tif") tmp_qlk_green_sub = os.path.join(working_dir, "tmp_qck_green_sub.tif") tmp_qlk_blue_sub = os.path.join(working_dir, "tmp_qck_blue_sub.tif") # Call the resampling app resampling_app_red = resample(p_QuicklookRedBandImage, dtm, tmp_qlk_red_sub, OtbResampleType.LINEAR_WITH_RADIUS, padradius=4, outarea=[1000,1000], write_output=False) resampling_app_green = resample(p_QuicklookGreenBandImage, dtm, tmp_qlk_green_sub, OtbResampleType.LINEAR_WITH_RADIUS, padradius=4, outarea=[1000,1000], write_output=False) resampling_app_blue = resample(p_QuicklookBlueBandImage, dtm, tmp_qlk_blue_sub, OtbResampleType.LINEAR_WITH_RADIUS, padradius=4, outarea=[1000,1000], write_output=False) # Concatenate images tmp_qlk = os.path.join(working_dir, "tmp_qck_sub.tif") param_concat = { "il": [ resampling_app_red.getoutput().get("out"), resampling_app_blue.getoutput().get("out"), resampling_app_green.getoutput().get("out")], "out": tmp_qlk, "ram": str(OtbAppHandler.ram_to_use / 3) } concat_app = OtbAppHandler("ConcatenateDoubleImages", param_concat,write_output=True) # Rescale between 0 and 255 rescale_intensity( concat_app.getoutput().get("out"), 0, 255, filename + file_utils.get_extended_filename_write_image_file_standard()+":uint8", inmin=[str(p_QuicklookMinReflRedBand), str(p_QuicklookMinReflGreenBand), str(p_QuicklookMinReflBlueBand)], inmax=[str(p_QuicklookMaxReflRedBand), str(p_QuicklookMaxReflGreenBand), str(p_QuicklookMaxReflBlueBand)] ) if (os.path.exists(filename + '.aux.xml')): LOGGER.debug("Removing " + filename + '.aux.xml file') os.remove(filename + '.aux.xml')
def write_private_images( self, p_L2PrivateImageFilenamesProvider, p_ReflectanceQuantificationValue, p_CLDDataBandsSelected, p_CLDCoreAlgorithmsMapBand, p_WriteOnlyCLACLD, p_WriteLTC, working_dir): LOGGER.debug("Write LTC: " + str(p_WriteLTC)) LOGGER.debug("Write WriteOnlyCLACLD: " + str(p_WriteOnlyCLACLD)) LOGGER.debug("p_L2PrivateImageFilenamesProvider.GetLTCImageDirFileName(): %s", p_L2PrivateImageFilenamesProvider.get_ltc_image_dir_filename()) if not p_WriteOnlyCLACLD: # ** ** PRIVATE DATA ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** # START WRITING PXD Image file DATA # Create the writer # Initialize the writer filter otb_file_utils.otb_copy_image_to_file( self._pxd, p_L2PrivateImageFilenamesProvider.get_pxd_image_filename() + file_utils.get_extended_filename_write_image_file_standard()) # START WRITING WAM Image file DATA # Create the concatenate imagefilter # Create the writer UnsignedIntegerVectorImageFileWriterPointer # Convert Binary PWA and TWA images tmp_pwa_concat = os.path.join(working_dir, "tmp_pwa_concat.tif") param_pwa_concat = {"im": self._possiblewatermask, "out": tmp_pwa_concat } pwa_concat_app = OtbAppHandler("BinaryConcatenate", param_pwa_concat, write_output=False) tmp_twa_concat = os.path.join(working_dir, "tmp_twa_concat.tif") param_twa_concat = {"im": self._testedwatermask, "out": tmp_twa_concat } twa_concat_app = OtbAppHandler("BinaryConcatenate", param_twa_concat, write_output=False) # Concatenate into one file param_wam_concat = { "il": [ self._wasimage, pwa_concat_app.getoutput().get("out"), twa_concat_app.getoutput().get("out")], "out": p_L2PrivateImageFilenamesProvider.get_wam_image_filename() + ":uint16"+ file_utils.get_extended_filename_write_image_file_standard()} OtbAppHandler("ConcatenateImages", param_wam_concat) # START WRITING STO Image file DATA # Scalar filter multiply_by_scalar(self._sto,p_ReflectanceQuantificationValue, p_L2PrivateImageFilenamesProvider.get_sto_image_filename() + file_utils.get_extended_filename_write_image_file_standard() + ":int16") # START WRITING NDT Image file DATA # Create the writer # Evol 4 - 1: NDT ecris sur 8 bits(et non 16 bits car seuilement un masque) otb_file_utils.otb_copy_image_to_file( self._ndt, p_L2PrivateImageFilenamesProvider.get_ndt_image_filename() + file_utils.get_extended_filename_write_image_file_standard()) # START WRITING LTC Image file DATA # Create the image list if p_WriteLTC: otb_file_utils.otb_copy_image_to_file(self._ltc_image, p_L2PrivateImageFilenamesProvider.get_ltc_image_filename()) # START WRITING RTA Image file DATA multiply_by_scalar(self._rta, p_ReflectanceQuantificationValue, p_L2PrivateImageFilenamesProvider.get_rta_image_filename() + file_utils.get_extended_filename_write_image_file_standard()+":int16") # START WRITING RTC Image file DATA multiply_by_scalar(self._rtc, p_ReflectanceQuantificationValue, p_L2PrivateImageFilenamesProvider.get_rtc_image_filename() + file_utils.get_extended_filename_write_image_file_standard()+":int16") # START WRITING RCR Image file DATA multiply_by_scalar(self._rcr, p_ReflectanceQuantificationValue, p_L2PrivateImageFilenamesProvider.get_rcr_image_filename() + file_utils.get_extended_filename_write_image_file_standard()+":int16") # End od condition self.write_cld_image( self._cld, p_CLDDataBandsSelected, p_L2PrivateImageFilenamesProvider.get_cld_image_filename(), use_filenames=True) # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** # START WRITING CLA Sub Image file DATA # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** # LAIG - DM - MAC - 1691 - CNES: Write CLA only is available(only for VENUS - stereo) if self._cld_l2cla is not None: otb_file_utils.otb_copy_image_to_file( self._cld_l2cla, p_L2PrivateImageFilenamesProvider.get_cla_image_filename() + file_utils.get_extended_filename_write_image_file_standard())
def write_public_images( self, p_L2ImageFilenamesProvider, p_ReflectanceQuantificationValue, p_AOTQuantificationValue, p_AOTNodataValue, p_VAPQuantificationValue, p_VAPNodataValue, p_CLDDataBandsSelected, p_CLDCoreAlgorithmsMapBand, p_WritePublicProduct, p_EnvCorOption, working_dir): # == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == # IF PUBLIC PART OF L2 PRODUCT IS WRITTEN # == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == if p_WritePublicProduct: l_NumberOfResolutions = len(p_L2ImageFilenamesProvider.get_sre_headers()) LOGGER.debug("L2ImageFileWriterBase::Initialize Number of resolutions: " + str(l_NumberOfResolutions) + ".") l_BandsDefinitions = self._plugin.BandsDefinitions l_RedBandId = 0 l_GreenBandId = 0 l_BlueBandId = 0 resol_QLK = 0 l_Resolution = "" l_BandsDefinitions = self._plugin.BandsDefinitions l_RedBandId, l_BlueBandId, l_GreenBandId = l_BandsDefinitions.get_l2_information_for_quicklook_band_code( self._quicklookredbandcode, self._quicklookgreenbandcode, self._quicklookbluebandcode, ) # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** * # ** ** LOOP on RESOLUTION ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** for resol in range(0, l_NumberOfResolutions): l_StrResolution = l_BandsDefinitions.ListOfL2Resolution[resol] # -------------------------------------------------------- # L2 area AreaType l_AreaToL2Resolution l_AreaFile = self._sre_list[resol] l_ListOfBand = l_BandsDefinitions.get_list_of_l2_band_code(l_StrResolution) LOGGER.debug("L2ImageFileReader::Gen Public image file for the resolution " + l_StrResolution + ".") # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** # Read the Coef apply for SRE and FRE images LOGGER.info( "SRE and FRE values multiply by the reflectance quantification value " + str(p_ReflectanceQuantificationValue) + ".") # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** # ** ** PUBLIC DATA ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** #Store image pointer and filename tmp_l2_filename_list = [] tmp_l2_image_list = [] tmp_l2_pipe = OtbPipelineManager() # START WRITING SRE Image file DATA # Caching the SRE image, before computing the QuickLook. # Create the scalar image filter sre_filename = p_L2ImageFilenamesProvider.get_sre_filenames()[ resol] + file_utils.get_extended_filename_write_image_file_standard() param_scaled_sre = { "im": self._sre_list[resol], "coef": p_ReflectanceQuantificationValue, "out": sre_filename+":int16"} sre_scal_app = OtbAppHandler("MultiplyByScalar", param_scaled_sre, write_output=is_croco_on("earthexplorer.l2writer.sre")) tmp_l2_image_list.append(sre_scal_app.getoutput().get("out")) tmp_l2_filename_list.append(sre_filename) tmp_l2_pipe.add_otb_app(sre_scal_app) #QuickLook stuff if resol == resol_QLK : tmp_sre_roi_red = os.path.join(working_dir, "tmp_sre_roi_red.tif") tmp_sre_roi_red_app = extract_roi(self._sre_list[resol], [l_RedBandId], tmp_sre_roi_red, write_output=is_croco_on("earthexplorer.l2writer.roi")) tmp_l2_image_list.append(tmp_sre_roi_red_app.getoutput().get("out")) tmp_l2_filename_list.append(tmp_sre_roi_red) self._qckl_red_image = tmp_sre_roi_red tmp_l2_pipe.add_otb_app(tmp_sre_roi_red_app) tmp_sre_roi_green = os.path.join(working_dir, "tmp_sre_roi_green.tif") tmp_sre_roi_green_app = extract_roi(self._sre_list[resol], [l_GreenBandId], tmp_sre_roi_green, write_output=is_croco_on("earthexplorer.l2writer.roi")) tmp_l2_image_list.append(tmp_sre_roi_green_app.getoutput().get("out")) tmp_l2_filename_list.append(tmp_sre_roi_green) self._qckl_green_image = tmp_sre_roi_green tmp_l2_pipe.add_otb_app(tmp_sre_roi_green_app) tmp_sre_roi_blue = os.path.join(working_dir, "tmp_sre_roi_blue.tif") tmp_sre_roi_blue_app = extract_roi(self._sre_list[resol], [l_BlueBandId], tmp_sre_roi_blue, write_output=is_croco_on("earthexplorer.l2writer.roi")) tmp_l2_image_list.append(tmp_sre_roi_blue_app.getoutput().get("out")) tmp_l2_filename_list.append(tmp_sre_roi_blue) self._qckl_blue_image = tmp_sre_roi_blue tmp_l2_pipe.add_otb_app(tmp_sre_roi_blue_app) # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** # START WRITING FRE Image file DATA fre_scal_app = None if p_EnvCorOption: fre_filename = p_L2ImageFilenamesProvider.get_fre_filenames()[ resol] + file_utils.get_extended_filename_write_image_file_standard() param_scaled_fre = { "im": self._fre_list[resol], "coef": p_ReflectanceQuantificationValue, "out": fre_filename+":int16"} fre_scal_app = OtbAppHandler("MultiplyByScalar", param_scaled_fre, write_output=is_croco_on("earthexplorer.l2writer.fre")) #Write SRE and FRE simultaneously tmp_l2_image_list.append(fre_scal_app.getoutput().get("out")) tmp_l2_filename_list.append(fre_filename) tmp_l2_pipe.add_otb_app(fre_scal_app) # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** # START WRITING ATB Image file DATA # Initialize the Scalar filter # FA1424: Temporary Fix to address cosmetic aspects of FA1424 # VAPThreshold.SetInput(self.GetVAPImageList()[resol)) # VAPThreshold.SetOutsideValue(255. / p_VAPQuantificationValue) # VAPThreshold.ThresholdAbove(255. / p_VAPQuantificationValue) # VAPScalar.SetInput(VAPThreshold.GetOutput()) # VAPScalar.SetCoef(p_VAPQuantificationValue) tmp_vap = os.path.join(working_dir, "tmp_vap_scaled_" + l_StrResolution + ".tif") param_bandmath_vap = { "il": [ self._l2vapimagelist[resol], self._l2edgimagelist[resol]], "exp": "(im2b1 == 1)?" + str(p_VAPNodataValue) + ":" + "rint(im1b1*" + str(p_VAPQuantificationValue)+")", "out": tmp_vap + ":uint8"} vap_scal_app = OtbAppHandler("BandMathDouble", param_bandmath_vap, write_output=False) tmp_aot = os.path.join(working_dir, "tmp_aot_scaled_" + l_StrResolution + ".tif") param_bandmath_aot = {"il": [self._l2aotlist[resol], self._l2edgimagelist[resol]], "exp": "(im2b1 == 1)?" + str(p_AOTNodataValue) + ":" + "rint(im1b1*" + str( p_AOTQuantificationValue)+")", "out": tmp_aot + ":uint8" } aot_scal_app = OtbAppHandler("BandMathDouble", param_bandmath_aot, write_output=False) tmp_l2_pipe.add_otb_app(aot_scal_app) atb_filename = p_L2ImageFilenamesProvider.get_atb_image_filename()[resol] param_atb_concat = {"il": [vap_scal_app.getoutput().get("out"), aot_scal_app.getoutput().get("out")], "out": atb_filename + ":uint8" } atb_concat_app = OtbAppHandler("ConcatenateMaskImages", param_atb_concat, write_output=is_croco_on("earthexplorer.l2writer.atb")) tmp_l2_image_list.append(atb_concat_app.getoutput().get("out")) tmp_l2_filename_list.append(atb_filename) tmp_l2_pipe.add_otb_app(atb_concat_app) # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** # START WRITING MSK Image file DATA # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** # Connect the WAM image was_resampled = os.path.join(working_dir, "was_resampled_" + l_StrResolution + ".tif") app_resample_was = resample(self._wasimage, self._dtm.ALTList[resol], was_resampled, threshold=0.25, write_output=False) tmp_l2_pipe.add_otb_app(app_resample_was) # Connect the HID image hid_resampled = os.path.join(working_dir, "hid_resampled_" + l_StrResolution + ".tif") app_resample_hid = resample(self._dtm_hid, self._dtm.ALTList[resol], hid_resampled, threshold=0.25, write_output=False) tmp_l2_pipe.add_otb_app(app_resample_hid) # Connect the SHDimage shd_resampled = os.path.join(working_dir, "shd_resampled_" + l_StrResolution + ".tif") app_resample_shd = resample(self._dtm_shd, self._dtm.ALTList[resol], shd_resampled, threshold=0.25, write_output=False) tmp_l2_pipe.add_otb_app(app_resample_shd) # Create the MOTH image that concatenates the WAT, HID, SHD, STL and TGS masks MOTHImageList = [] MOTHImageList.append(app_resample_was.getoutput().get("out")) MOTHImageList.append(app_resample_hid.getoutput().get("out")) MOTHImageList.append(app_resample_shd.getoutput().get("out")) # Append STL MOTHImageList.append(self._stl_list[resol]) # Append TGS MOTHImageList.append(self._tgs_list[resol]) app_resample_snow = None if self._cld_snow is not None: snow_resampled = os.path.join(working_dir, "snow_resampled_" + l_StrResolution + ".tif") app_resample_snow = resample(self._cld_snow, self._dtm.ALTList[resol], snow_resampled, working_dir, 0.25, write_output=False) tmp_l2_pipe.add_otb_app(app_resample_snow) MOTHImageList.append(app_resample_snow.getoutput().get("out")) # Concat to get atb moth_tmp_concat = os.path.join(working_dir, "tmp_moth_" + l_StrResolution + ".tif") param_moth_concat = {"il": MOTHImageList, "out": moth_tmp_concat } # Concatenate to produce the MOTH file app_moth_concat = OtbAppHandler("ConcatenateMaskImages", param_moth_concat, write_output=False) tmp_l2_pipe.add_otb_app(app_moth_concat) # Binary concatenation of WAT, HID, SHD, STL and TGS masks msk_filename = p_L2ImageFilenamesProvider.get_msk_filename()[resol] param_moth_binconcat = {"im": app_moth_concat.getoutput().get("out"), "out": msk_filename + ":uint8" } moth_binconcat_app = OtbAppHandler("BinaryConcatenate", param_moth_binconcat, write_output=is_croco_on("earthexplorer.l2writer.msk")) tmp_l2_image_list.append(moth_binconcat_app.getoutput().get("out")) tmp_l2_filename_list.append(msk_filename) tmp_l2_pipe.add_otb_app(moth_binconcat_app) # Concatenation of the MSK mask with the CLD and MOTH masks # -------------------------------------------------------- # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** # START WRITING QLT Image file DATA # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** QOTHImageList = [] QOTHImageList.append(self._l2edgimagelist[resol]) QOTHImageList.append(self._l2taomasklist[resol]) if self._plugin.WaterVapourDetermination: QOTHImageList.append(self._l2iwcmasklist[resol]) # Concat to get atb qoth_tmp_concat = os.path.join(working_dir, "tmp_qoth_" + l_StrResolution + ".tif") param_qoth_concat = {"il": QOTHImageList, "out": qoth_tmp_concat + ":uint8" } qoth_concat_app = OtbAppHandler("ConcatenateImages", param_qoth_concat, write_output=False) qoth_tmp_binconcat = os.path.join(working_dir, "tmp_binqoth_" + l_StrResolution + ".tif") param_qoth_binconcat = {"im": qoth_concat_app.getoutput().get("out"), "out": qoth_tmp_binconcat + ":uint8" } qoth_binconcat_app = OtbAppHandler("BinaryConcatenate", param_qoth_binconcat, write_output=False) # ------------------------------------------------------- # Concatenation of the QLT mask with the SAT, PIX and OTH masks # -------------------------------------------------------- # As for the PIX mask, the SAT mask in concatenate in one band where each bit matches one band sat_tmp_concat = os.path.join(working_dir, "tmp_sat_" + l_StrResolution + ".tif") param_sat_binconcat = {"im": self._l2satimagelist[resol], "out": sat_tmp_concat + ":uint8" } sat_binconcat_app = OtbAppHandler("BinaryConcatenate", param_sat_binconcat, write_output=False) # Create the QLT vector image qlt_tmp_concat = os.path.join(working_dir, "tmp_qlt_" + l_StrResolution + ".tif") QLTImageList = [] QLTImageList.append(sat_binconcat_app.getoutput().get("out")) QLTImageList.append(self._l2piximagelist[resol]) QLTImageList.append(qoth_binconcat_app.getoutput().get("out")) param_qlt_concat = {"il": QLTImageList, "out": qlt_tmp_concat + ":uint8" } qlt_concat_app = OtbAppHandler("ConcatenateImages", param_qlt_concat, write_output=is_croco_on("earthexplorer.l2writer.qlt")) tmp_l2_image_list.append(qlt_concat_app.getoutput().get("out")) tmp_l2_filename_list.append(p_L2ImageFilenamesProvider.get_qlt_filenames()[resol]) tmp_l2_pipe.add_otb_app(qlt_concat_app) # -------------------------- # Write all the images at L2 Reso write_images(tmp_l2_image_list, tmp_l2_filename_list) tmp_l2_pipe.free_otb_app() clean_pipe(self._sre_list[resol]) if p_EnvCorOption: clean_pipe(self._fre_list[resol]) # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** * # START WRITING CLD Public Image file DATA # ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** * # Connect the CLD image # ------------------------------------- self.write_cld_image(self._l2cldlist[resol], p_CLDDataBandsSelected, p_L2ImageFilenamesProvider.get_cld_image_filename()[resol]) LOGGER.debug("Writing L2 resolution image done !")