diff --git a/python_src/SAR_MultiSlc.py b/python_src/SAR_MultiSlc.py index 32be6d5c12a5baaa97ff0ed58eef6a57e9c59d4e..674198473244bdb97ae5c149975bc854f7fee792 100644 --- a/python_src/SAR_MultiSlc.py +++ b/python_src/SAR_MultiSlc.py @@ -545,7 +545,8 @@ if __name__ == "__main__": master_slc = "" if not master_ext[0] == "h5" and roi is None: - master_slc = master_Image_base[:30] + master_Image_base[46:53]+str(relative_orbit) + ".tif" + master_slc = func_utils.getSlcMlNamming_fromProductName(master_Image_base, mode="S1SM") + ".tif" + # === Here we convert master single band CInt16 to dual band FLOAT32 # === To do so, OTB_ExtractRoi is much faster than OTB_DynamicConvert diapOTBApp.extractROI(master_Image, @@ -553,7 +554,7 @@ if __name__ == "__main__": ram) if master_ext[0] == "h5": - master_slc = master_Image_base[:35]+".tif" + master_slc = func_utils.getSlcMlNamming_fromProductName(master_Image_base, mode="Cosmo") + ".tif" ds = gdal.Open(master_Image, gdal.GA_ReadOnly) ds = gdal.Translate(os.path.join(master_data_dir, master_slc), ds, format="GTiff", outputType=gdal.GDT_Float32, creationOptions=['TILED=YES']) @@ -667,9 +668,9 @@ if __name__ == "__main__": slave_Image_CoRe = "" if not master_ext[0] == "h5": - slave_Image_CoRe = slave_Image_base[:30] + slave_Image_base[46:53]+str(relative_orbit) + ".tif" + slave_Image_CoRe = func_utils.getSlcMlNamming_fromProductName(slave_Image_base, mode="S1SM") + ".tif" if master_ext[0] == "h5": - slave_Image_CoRe = slave_Image_base[:35]+".tif" + slave_Image_CoRe = func_utils.getSlcMlNamming_fromProductName(slave_Image_base, mode="Cosmo") + ".tif" param['slave_CoRe_Name'] = slave_Image_CoRe @@ -691,6 +692,30 @@ if __name__ == "__main__": func_utils.printOnStd("\n Post Processing chain \n") func_utils.log(logging.INFO, "Post Processing chain") + + ### Names definition ### + InterferoB123 = "" + Interfero_Ortho = "" + Interfero_roi = "" + Interfo_Filt = "" + + if not master_ext[0] == "h5": + interf_base = func_utils.getInterfNamming_fromProductName(master_Image_base, slave_Image_base, + mode="S1SM") + InterferoB123 = interf_base + "_Interferogram.tif" + Interfero_Ortho = interf_base + "_Ortho-Interferogram.tif" + Interfero_roi = interf_base + "_ROI_Ortho-Interferogram.tif" + Interfo_Filt = interf_base + "_Filtred-Interferogram.tif" + + if master_ext[0] == "h5": + interf_base = func_utils.getInterfNamming_fromProductName(master_Image_base, slave_Image_base, + mode="Cosmo") + InterferoB123 = interf_base + "_Interferogram.tif" + Interfero_Ortho = interf_base + "_Ortho-Interferogram.tif" + Interfero_roi = interf_base + "_ROI_Ortho-Interferogram.tif" + Interfo_Filt = interf_base + "_Filtred-Interferogram.tif" + + # Phase Filtering (if required) if func_utils.str2bool(activateFiltering): # Default paramater @@ -706,6 +731,7 @@ if __name__ == "__main__": paramPost['ml_filt_interf_gain'] = gain_interfero paramPost['filt_alpha'] = interf_filt_alpha paramPost['ram'] = ram + paramPost['filtered_Name'] = Interfo_Filt Post_Processing.filtering(master_Image, master_Image_base, slave_Image, slave_Image_base, master_data_dir, output_dir, paramPost, @@ -715,35 +741,19 @@ if __name__ == "__main__": # === Multilook on Coregistrated Slave func_utils.silentremove(output_dir, slave_Image_ML) - slave_Image_ML = os.path.splitext(slave_Image_base)[0] + "_ml" + str(ml_azimut) + str(ml_range) + ".tif" + slave_Image_ML_old = slave_Image_ML + if not master_ext[0] == "h5" : + slave_Image_ML = func_utils.getSlcMlNamming_fromProductName(slave_Image_base, mode="S1SM") + \ + "_ml" + str(ml_azimut) + str(ml_range) + ".tif" + else : + slave_Image_ML = func_utils.getSlcMlNamming_fromProductName(slave_Image_base, mode="Cosmo") + \ + "_ml" + str(ml_azimut) + str(ml_range) + ".tif" + diapOTBApp.multilook(os.path.join(output_dir, slave_Image_CoRe), ml_range, ml_azimut, ml_gain, os.path.join(output_dir, slave_Image_ML), ram) - ### Names definition ### - mib = master_Image_base - sib = slave_Image_base - - InterferoB123 = "" - Interfero_Ortho = "" - - if not master_ext[0] == "h5": - InterferoB123 = mib[:14]+"M"+mib[14:30]+mib[47:53]+"S"+sib[ - 14:22]+"-"+sib[47:53]+str(relative_orbit)+"_Interferogram.tif" - Interfero_Ortho = mib[:14]+"M"+mib[14:30]+mib[47:53]+"S"+sib[ - 14:22]+"-"+sib[47:53]+str(relative_orbit)+"_Ortho-Interferogram.tif" - Interfero_roi = mib[:15]+"M"+mib[14:30]+"-"+mib[ - 47:54]+"S"+sib[14:23]+"-"+sib[47:53]+"-"+str(relative_orbit)+"_ROI_Ortho-Interferogram.tif" - - if master_ext[0] == "h5": - InterferoB123 = mib[:27]+"M_"+mib[27:35]+"_S_"+sib[ - 27:35]+"_Interferogram.tif" - Interfero_Ortho = mib[:27]+"M_"+mib[27:35]+"_S_"+sib[ - 27:35]+"_Ortho-Interferogram.tif" - Interfero_roi = mib[:27]+"M_"+mib[27:35]+"_S_"+sib[ - 27:35]+"_ROI_Ortho-Interferogram.tif" - - + ### ROI, Ortho and band_extract ### if func_utils.str2bool(ortho_interferogram): @@ -775,7 +785,9 @@ if __name__ == "__main__": if func_utils.str2bool(ortho_interferogram): interferogram_ortho = "interferogram_ortho.tif" func_utils.silentremove(output_dir, interferogram_ortho) - func_utils.silentremove(output_dir, interferogram_ortho.split(".")[0]+".geom") + + os.rename(os.path.join(output_dir, interferogram_ortho.split(".")[0]+".geom"), + os.path.join(output_dir, Interfero_Ortho.split(".")[0]+".geom")) if roi: func_utils.silentremove(output_dir, interf_roi) @@ -788,7 +800,7 @@ if __name__ == "__main__": func_utils.silentremove(output_dir, demProj_Slave.split(".")[0]+".geom") func_utils.silentremove(os.path.dirname(grid_path), os.path.basename(grid_path)) func_utils.silentremove(os.path.dirname(grid_path), os.path.basename(grid_path).split(".")[0]+".geom") - func_utils.silentremove(output_dir, slave_Image_ML.split(".")[0]+".geom") + func_utils.silentremove(output_dir, slave_Image_ML_old.split(".")[0]+".geom") # Remove .tif.aux.xml files into output_dir aux_files = func_utils.get_AllFilesWithExt(output_dir, ".tif.aux.xml") @@ -800,6 +812,26 @@ if __name__ == "__main__": func_utils.silentremove(output_dir, i_file) + + # After processing loop : rename and clean master_data_dir + # Rename master_ML and geom file + if not master_ext[0] == "h5" : + master_new_ML = func_utils.getSlcMlNamming_fromProductName(master_Image_base, mode="S1SM") + \ + "_ml" + str(ml_azimut) + str(ml_range) + ".tif" + master_new_ML_geom = func_utils.getSlcMlNamming_fromProductName(master_Image_base, mode="S1SM") + \ + "_ml" + str(ml_azimut) + str(ml_range) + ".geom" + else : + master_new_ML = func_utils.getSlcMlNamming_fromProductName(master_Image_base, mode="Cosmo") + \ + "_ml" + str(ml_azimut) + str(ml_range) + ".tif" + master_new_ML_geom = func_utils.getSlcMlNamming_fromProductName(master_Image_base, mode="Cosmo") + \ + "_ml" + str(ml_azimut) + str(ml_range) + ".geom" + + os.rename(os.path.join(master_data_dir, master_Image_ML), + os.path.join(master_data_dir, master_new_ML)) + + master_ML_geom = master_Image_ML.split(".")[0] + ".geom" + os.rename(os.path.join(master_data_dir, master_ML_geom), + os.path.join(master_data_dir, master_new_ML_geom)) if light_version is True: func_utils.log(logging.INFO, "\n Removing files for light version \n") @@ -807,7 +839,6 @@ if __name__ == "__main__": func_utils.silentremove(master_data_dir, dop_file) func_utils.silentremove(master_data_dir, demProj_Master) func_utils.silentremove(master_data_dir, demProj_Master.split(".")[0]+".geom") - func_utils.silentremove(master_data_dir, master_Image_ML.split(".")[0]+".geom") func_utils.silentremove(master_data_dir, master_cartesian_mean) func_utils.silentremove(master_data_dir, master_cartesian_mean.split(".")[0]+".geom") if master_ext[0] == "h5": diff --git a/python_src/SAR_MultiSlc_IW.py b/python_src/SAR_MultiSlc_IW.py index 74b50ca0228bf8c09983d362387fe74c7cfc129b..f5640f50cffefc0974c109eee708c7a8aedfd6f3 100644 --- a/python_src/SAR_MultiSlc_IW.py +++ b/python_src/SAR_MultiSlc_IW.py @@ -139,7 +139,7 @@ if __name__ == "__main__": if 'optram' in dict_Global['parameter']: ram = str(dict_Global['parameter']['optram']) if int(ram) > 4000 : - ram = 4000 + ram = str(4000) if 'clean' in dict_Global['parameter']: light_version = dict_Global['parameter']['clean'] if 'burst_index' in dict_Global['parameter']: @@ -548,7 +548,7 @@ if __name__ == "__main__": # ###### Concatenating and georeferencing bursts ###### # # Master SLC - masterSlc = master_Image_base[:30] + master_Image_base[46:53]+ "-" +str(relative_orbit) + ".tif" + masterSlc = func_utils.getSlcMlNamming_fromProductName(master_Image_base, mode="S1IW") + ".tif" Con_masterSlc = os.path.join(master_data_dir, masterSlc) diapOTBApp.concatenate(BurstToConcatenateM, master_Image, firstBurst, Con_masterSlc, ram) @@ -645,7 +645,7 @@ if __name__ == "__main__": # ###### Concatenating and georeferencing bursts ###### # # Slave Coregistrated Reramped - slaveCorRE = slave_Image_base[:30] + slave_Image_base[46:53]+"-"+str(relative_orbit) + ".tif" + slaveCorRE = func_utils.getSlcMlNamming_fromProductName(slave_Image_base, mode="S1IW") + ".tif" Con_slaveCorRE = os.path.join(output_dir, slaveCorRE) diapOTBApp.concatenate(slaveCorRerampToConcatenate, master_Image, firstBurst, Con_slaveCorRE, ram) @@ -665,8 +665,8 @@ if __name__ == "__main__": func_utils.log(logging.INFO, "Post Processing chain") # Multilook on coregistred - CoRe_ML = os.path.splitext(slave_Image_base)[0] + "_ml" + str(ml_azimut) + str(ml_range) + ".tif" - #ml(os.path.join(output_dir, slaveCorRE), os.path.join(output_dir, CoRe_ML)) + CoRe_ML = func_utils.getSlcMlNamming_fromProductName(slave_Image_base, mode="S1IW") + \ + "_ml" + str(ml_azimut) + str(ml_range) + ".tif" diapOTBApp.multilook(os.path.join(output_dir, slaveCorRE), ml_range, ml_azimut, ml_gain, os.path.join(output_dir, CoRe_ML), ram) @@ -679,8 +679,13 @@ if __name__ == "__main__": if func_utils.str2bool(version_interferogram): Interferogram_Multiband = mib[:15]+"M"+mib[14:30]+"-"+mib[ 47:54]+"S"+sib[14:23]+"-"+sib[47:53]+"-"+ str(relative_orbit)+"_interf.tif" - Interferogram_ = mib[:15]+"M"+mib[14:30]+"-"+mib[ - 47:54]+"S"+sib[14:23]+"-"+sib[47:53]+"-"+str(relative_orbit)+"_interferogram.tif" + + interf_base = func_utils.getInterfNamming_fromProductName(master_Image_base, slave_Image_base, + mode="S1IW") + + Interferogram_ = interf_base +"_Interferogram.tif" + + Interfo_Filt = interf_base + "_Filtred-Interferogram.tif" Con_Interf = os.path.join(output_dir, Interferogram_Multiband) diapOTBApp.concatenate(interfToConcatenate, master_Image, firstBurst, Con_Interf, ram) @@ -701,6 +706,7 @@ if __name__ == "__main__": paramPost['filt_alpha'] = interf_filt_alpha paramPost['interf_Name'] = Con_Interf paramPost['ram'] = ram + paramPost['filtered_Name'] = Interfo_Filt Post_Processing.filtering(master_Image, master_Image_base, slave_Image, slave_Image_base, Master_temp_dir, temp_dir, paramPost, @@ -711,10 +717,9 @@ if __name__ == "__main__": # C === Ortho Interferogram if func_utils.str2bool(version_interferogram) and func_utils.str2bool(ortho_interferogram): - Ortho_ = mib[:15]+"M"+mib[14:30]+"-"+mib[ - 47:54]+"S"+sib[14:23]+"-"+sib[47:53]+"-"+str(relative_orbit)+"_Ortho-Interferogram.tif" - Ortho_roi = mib[:15]+"M"+mib[14:30]+"-"+mib[ - 47:54]+"S"+sib[14:23]+"-"+sib[47:53]+"-"+str(relative_orbit)+"_ROI_Ortho-Interferogram.tif" + Ortho_ = interf_base + "_Ortho-Interferogram.tif" + Ortho_roi = interf_base + "_ROI_Ortho-Interferogram.tif" + diapOTBApp.orthorectification(os.path.join(output_dir, Interferogram_), spacingxy, hgts_path, geoid_path, os.path.join(output_dir, Ortho_), ram) @@ -728,21 +733,18 @@ if __name__ == "__main__": # ==================================== # # Remove # # ================================ # - func_utils.silentremove(output_dir, CoRe_ML.split(".")[0]+".geom") func_utils.silentremove(output_dir, dop_file) if func_utils.str2bool(version_interferogram): func_utils.silentremove(output_dir, Interferogram_Multiband) - if func_utils.str2bool(version_interferogram) and func_utils.str2bool(ortho_interferogram): - func_utils.silentremove(output_dir, Ortho_.split(".")[0]+".geom") shutil.rmtree(temp_dir) # Multilook on master reramped - Reramp_ML = os.path.splitext(master_Image_base)[0] + "_ml" + str(ml_azimut) + str(ml_range) + ".tif" + Reramp_ML = func_utils.getSlcMlNamming_fromProductName(master_Image_base, mode="S1IW") + \ + "_ml" + str(ml_azimut) + str(ml_range) + ".tif" diapOTBApp.multilook(os.path.join(master_data_dir, masterRerampMl), ml_range, ml_azimut, ml_gain, os.path.join(master_data_dir, Reramp_ML), ram) func_utils.silentremove(master_data_dir, masterRerampMl) func_utils.silentremove(master_data_dir, masterRerampMl.split(".")[0]+".geom") - func_utils.silentremove(master_data_dir, Reramp_ML.split(".")[0]+".geom") shutil.rmtree(Master_temp_dir) diff --git a/python_src/processings/Post_Processing.py b/python_src/processings/Post_Processing.py index dd854dbfdc7448330b800fdf6e8e653c4f3e0e67..0a503fba6824d9dd1f672550c5182ec443ce9659 100644 --- a/python_src/processings/Post_Processing.py +++ b/python_src/processings/Post_Processing.py @@ -194,6 +194,8 @@ def filtering_Others(master_Image, master_Image_base, slave_Image, slave_Image_b # Eventually SARAddBandInterfergoram filt_interferogram = "filtered_interferogram.tif" + if "filtered_Name" in param : + filt_interferogram = param['filtered_Name'] appAddAmp = otb.Registry.CreateApplication("SARAddBandInterferogram") appAddAmp.SetParameterInputImage("incomplexamp", appComplex.GetParameterOutputImage("out")) appAddAmp.SetParameterString("ininterf", filt_phacoh_path) @@ -289,6 +291,8 @@ def filtering_S1IW(master_Image, master_Image_base, slave_Image, slave_Image_bas # SARAddBandInterfergoram filt_interferogram = "filtered_interferogram.tif" + if "filtered_Name" in param : + filt_interferogram = param['filtered_Name'] addAmpApp(inForAmp=os.path.join(output_dir, interf_name), inForPhaCoh=filt_phacoh_path, outPath=os.path.join(output_dir, filt_interferogram)) diff --git a/python_src/utils/func_utils.py b/python_src/utils/func_utils.py index 6b721a8f81b7499b29dd5c0da363388d1dfa60a2..871456227ed32ddec70cb03779d209c4691bd517 100644 --- a/python_src/utils/func_utils.py +++ b/python_src/utils/func_utils.py @@ -302,6 +302,98 @@ def check_image_pattern(img, mode="S1SM") : return correct_pattern +def getSlcMlNamming_fromProductName(product_name, mode="S1SM") : + """ + Get correct names (with conventions) for SLC and ML outputs (without extension) + """ + + # At the end, the name for slc and ml images must be : + # fullsensor_subwath_product_pol_UTCfirstdate with + # fullsensor : S1A/B for S1 or CSK for Cosmo + # subwath : for instance, s4 for S1SM and Cosmo or iw1 for S1 IW + # product : SCS_U/B for Cosmo or SLC for S1 + # UTCdate : date with YYYYMMDDthhmmss format + slcMlName = "" + + if mode == "Cosmo": + # Mode Cosmo : CSKS<i>_SCS_U/B_Sk_*_pol_<YYYYMMDDhhmmss>_<YYYYMMDDhhmmss> + # i : Identifier of the satellite (1, 2, 3 or 4) + # Sk : Mode/Beam (s1-s6) + # pol : Polarisations (HH or VV or VH or HV) + # YYYYMMDDhhmmss : Product start/stop date and times + # * : Others representations such as identifier for orbit direction or look side + productName_list = product_name.split("_") + + slcMlName = productName_list[0][:3] + "_" + productName_list[3] + "_" + \ + productName_list[1] + productName_list[2] + "_" + productName_list[5] + \ + "_" + productName_list[8][:8] + "t" + productName_list[8][8:] + + else : + # Mode S1 IW : mmm-bb-ttt-pp-yyyymmddthhmmss-yyyymmddthhmmss* + # mmm : Mission identifier (s1A or s1B) + # bb : Mode/Beam (iw1-iw3 for IW or s1-s6) + # ttt : Product type (always slc here) + # pp : Polarisations (2 letters : hh or vv or vh or hv) + # yyyymmddthhmmss : Product start/stop date and times + # (14 digits representing the date and time separated by the character "t") + # * : Others representations such as orbits number or images number ... + productName_list = product_name.split("-") + + slcMlName = productName_list[0] + "_" + productName_list[1] + "_" + \ + productName_list[2] + "_" + productName_list[3] + "_" + \ + productName_list[4] + + # Return output name without extension or ml factors + return slcMlName.lower() + + + +def getInterfNamming_fromProductName(productMaster_name, productSlave_name, mode="S1SM") : + """ + Get correct names (with conventions) for interferogram outputs (without extension) + """ + # At the end, the name for interf images must be : + # sensor_M_UTCfirstdatemaster_S_* UTCfirstdateslave with + # sensor : S1 for S1 or CSK for Cosmo + # UTCdate : date with YYYYMMDDthhmss format + interfName = "" + + if mode == "Cosmo": + # Mode Cosmo : CSKS<i>_SCS_U/B_Sk_*_pol_<YYYYMMDDhhmmss>_<YYYYMMDDhhmmss> + # i : Identifier of the satellite (1, 2, 3 or 4) + # Sk : Mode/Beam (s1-s6) + # pol : Polarisations (HH or VV or VH or HV) + # YYYYMMDDhhmmss : Product start/stop date and times + # * : Others representations such as identifier for orbit direction or look side + productM_list = productMaster_name.split("_") + productS_list = productSlave_name.split("_") + + interfName = productM_list[0][:3] + "_M_" + \ + productM_list[8][:8] + "t" + productM_list[8][8:] + "_S_" + \ + productS_list[8][:8] + "t" + productS_list[8][8:] + + else : + # Mode S1 IW : mmm-bb-ttt-pp-yyyymmddthhmmss-yyyymmddthhmmss* + # mmm : Mission identifier (s1A or s1B) + # bb : Mode/Beam (iw1-iw3 or s1-s6 for IW) + # ttt : Product type (always slc here) + # pp : Polarisations (2 letters : hh or vv or vh or hv) + # yyyymmddthhmmss : Product start/stop date and times + # (14 digits representing the date and time separated by the character "t") + # * : Others representations such as orbits number or images number ... + productM_list = productMaster_name.split("-") + productS_list = productSlave_name.split("-") + + interfName = productM_list[0][:2].upper() + "_M_" + \ + productM_list[4] + "_S_" + \ + productS_list[4] + + # Return output name without extension or ml factors + return interfName + + + + def image_envelope(inTIF, outSHP): """ This method returns a shapefile of an image