diff --git a/app/otbSARAltAmbig.cxx b/app/otbSARAltAmbig.cxx index e0967e5d6504f53ffd01933fdb40f2ebf9ff8bf3..608e5a7432fa5d1f962b4e320f6dd3825cc9693a 100644 --- a/app/otbSARAltAmbig.cxx +++ b/app/otbSARAltAmbig.cxx @@ -167,6 +167,11 @@ private: SarSensorModelAdapter::Pointer m_SarSensorModelAdapter = SarSensorModelAdapter::New(); bool loadOk = m_SarSensorModelAdapter->LoadState(sarKWL); + if(!loadOk || !m_SarSensorModelAdapter->IsValidSensorModel()) + { + itkExceptionMacro(<<"SAR image does not contain a valid SAR sensor model."); + } + SarSensorModelAdapter::Point3DType satellitePosition[2]; SarSensorModelAdapter::Point3DType satelliteVelocity[2]; @@ -215,6 +220,11 @@ private: // Slave loadOk = m_SarSensorModelAdapter->LoadState(sarKWL_slave); + if(!loadOk || !m_SarSensorModelAdapter->IsValidSensorModel()) + { + itkExceptionMacro(<<"SAR image does not contain a valid SAR sensor model."); + } + otbAppLogDEBUG(<<"Target Image : "); m_SarSensorModelAdapter->WorldToSatPositionAndVelocity(demGeoPoint, satellitePosition[1], satelliteVelocity[1]); otbAppLogDEBUG(<<"Satellite Position : " << satellitePosition[1][0] << " " << satellitePosition[1][1] << " " << satellitePosition[1][2]); diff --git a/app/otbSARCorrectionGrid.cxx b/app/otbSARCorrectionGrid.cxx index 98df03ea7ac9aef1c8078bf545b341fafd63d38e..1c5c613f37b1ba9a06d40b2e05d39a691e23cb5b 100644 --- a/app/otbSARCorrectionGrid.cxx +++ b/app/otbSARCorrectionGrid.cxx @@ -213,9 +213,6 @@ void DoExecute() override double diffMeanRange = meanRangeCor - meanRangeDEM; double diffMeanAzimut = meanAzimutCor - meanAzimutDEM; - std::cout << "diffMeanRange = " << diffMeanRange << std::endl; - std::cout << "diffMeanAzimut = " << diffMeanAzimut << std::endl; - // Correction Filter to replace value into DEMGrid with no occurences (high gap and high threshold) // by mean value CorrectionGridFilterType::Pointer filterCorrectionGrid = CorrectionGridFilterType::New(); diff --git a/app/otbSARESD.cxx b/app/otbSARESD.cxx index 62b66b156dfed84428fb68db65cfaf40205796c3..171a00c486e2413aa13fc84fb306d5912b61edfc 100644 --- a/app/otbSARESD.cxx +++ b/app/otbSARESD.cxx @@ -243,23 +243,6 @@ void DoExecute() override unsigned long startS_Low = samplesLow.first; unsigned long sizeS_Low = minSamples_Low - samplesLow.first + 1; - std::cout << "startL_Up = " << startL_Up << std::endl; - std::cout << "sizeL_Up = " << sizeL_Up << std::endl; - std::cout << "startS_Up = " << startS_Up << std::endl; - std::cout << "sizeS_Up = " << sizeS_Up << std::endl; - - std::cout << "startL_Low = " << startL_Low << std::endl; - std::cout << "sizeL_Low = " << sizeL_Low << std::endl; - std::cout << "startS_Low = " << startS_Low << std::endl; - std::cout << "sizeS_Low = " << sizeS_Low << std::endl; - - std::cout << "samplesLow.first = " << samplesLow.first << std::endl; - std::cout << "samplesUp.first = " << samplesUp.first << std::endl; - std::cout << "samplesLow.second = " << samplesLow.second << std::endl; - std::cout << "samplesUp.second = " << samplesUp.second << std::endl; - std::cout << "minSamples_Low = " << minSamples_Low << std::endl; - std::cout << "minSamples_Up = " << minSamples_Up << std::endl; - ////////// Extract Phase for overlap area ////////// // Set the channel to extract : Phase = 2 extractorUp->SetInput(InterfUpPtr); @@ -333,7 +316,6 @@ void DoExecute() override meanPhase->GetStreamer()->SetAutomaticStrippedStreaming(GetParameterInt("ram")); meanPhase->Update(); - std::cout << "meanPhase->GetMean() = " << meanPhase->GetMean() << std::endl; // Doppler Centroid Filter dcfUp->SetInput(extractorUp->GetOutput()); @@ -378,8 +360,6 @@ void DoExecute() override meanAziShift->GetStreamer()->SetAutomaticStrippedStreaming(GetParameterInt("ram")); meanAziShift->Update(); - std::cout << "meanAziShift->GetMean() = " << meanAziShift->GetMean() << std::endl; - ////////// Outputs : Image of azimut shift (for overlap area) and mean of azimut shift //////////// //SetParameterOutputImage("out", dcfLow->GetOutput()); SetParameterOutputImage("out", subPhase->GetOutput()); diff --git a/app/otbSARMetadataCorrection.cxx b/app/otbSARMetadataCorrection.cxx index f665f58451f20e3061361c63c7b51012333c1148..f83320ea2f54ce8f7034ded711160745958d0376 100644 --- a/app/otbSARMetadataCorrection.cxx +++ b/app/otbSARMetadataCorrection.cxx @@ -406,6 +406,8 @@ int selectOrbits(std::vector<std::string> * vector_time, break; } } + + return 0; } @@ -425,7 +427,7 @@ int createOrbitsAndUpdateKWL(std::vector<double *>* vector_posvel, int orbitCount = std::atoi(outKWL.GetMetadataByKey(ORBIT_NUMBER_KEY).c_str()); - if (vecSize < orbitCount) + if (vecSize < static_cast<unsigned int>(orbitCount)) { // Fine orbit are inferior to original => pb return 1; @@ -435,7 +437,8 @@ int createOrbitsAndUpdateKWL(std::vector<double *>* vector_posvel, outKWL.AddKey(ORBIT_NUMBER_KEY, orbitFineCount); // Create or update each Orbit state - for (unsigned int i = 0; i < std::atoi(orbitFineCount.c_str()); i++) + for (unsigned int i = 0; + i < static_cast<unsigned int>(std::atoi(orbitFineCount.c_str())); i++) { // Add the orbit to kwl char prefix[1024]; @@ -746,8 +749,6 @@ private: /////// Fine orbits /////// if (doFineOrbits) { - double ullat = std::atof(outputKWL.GetMetadataByKey("ul_lat").c_str()); - // Add into SAR Image keyword list, the precise metadata std::string inFile = GetParameterString("infineorbits"); diff --git a/include/otbSARDEMProjectionImageFilter.txx b/include/otbSARDEMProjectionImageFilter.txx index df9bfa394a659c8d41c79639898665e7273f56a9..aadb403150fbcf27bfb3ac9c3f046d81f92e6901 100644 --- a/include/otbSARDEMProjectionImageFilter.txx +++ b/include/otbSARDEMProjectionImageFilter.txx @@ -51,9 +51,7 @@ namespace otb SARDEMProjectionImageFilter<TImageIn ,TImageOut>::SARDEMProjectionImageFilter() : m_SarSensorModelAdapter(ITK_NULLPTR), m_NoData(-32768), m_withXYZ(false), m_withH(false), m_withSatPos(false), m_NbComponents(4), m_indH(4), m_indSatPos(4), m_geoidEmg96(NULL) - { - std::cout << "ConfigurationManager::GetGeoidFile() = " << ConfigurationManager::GetGeoidFile() << std::endl; - + { DEMHandlerPointerType DEMHandler = DEMHandler::Instance(); m_geoidEmg96 = 0; diff --git a/include/otbSARGroupedByOrthoImageFilter.txx b/include/otbSARGroupedByOrthoImageFilter.txx index a8128e705ad62117296872c15a3d190c10c8d7fd..9c4793611df330aec7237529dee6b1ac3ad62469 100644 --- a/include/otbSARGroupedByOrthoImageFilter.txx +++ b/include/otbSARGroupedByOrthoImageFilter.txx @@ -58,9 +58,7 @@ namespace otb { // Inputs required this->SetNumberOfRequiredInputs(2); - - std::cout << "ConfigurationManager::GetGeoidFile() = " << ConfigurationManager::GetGeoidFile() << std::endl; - + DEMHandlerPointerType DEMHandler = DEMHandler::Instance(); m_geoidEmg96 = 0; diff --git a/include/otbSARStreamingMaximumMinimumImageFilter.h b/include/otbSARStreamingMaximumMinimumImageFilter.h index 13861e63f04f452eec0877ebf6ddd90090aed616..c9f06b281486e01beafa324a38c7008d01c495e6 100644 --- a/include/otbSARStreamingMaximumMinimumImageFilter.h +++ b/include/otbSARStreamingMaximumMinimumImageFilter.h @@ -181,12 +181,13 @@ private: PersistentMaximumMinimumImageFilter(const Self &); //purposely not implemented void operator =(const Self&); //purposely not implemented + itk::Array<ValueType> m_ThreadMin; + itk::Array<ValueType> m_ThreadMax; itk::Array<unsigned int> m_ThreadIndexMaxC; itk::Array<unsigned int> m_ThreadIndexMaxL; itk::Array<unsigned int> m_ThreadIndexMinC; itk::Array<unsigned int> m_ThreadIndexMinL; - itk::Array<ValueType> m_ThreadMax; - itk::Array<ValueType> m_ThreadMin; + ; /* Ignored values */ diff --git a/include/otbSARTemporalCorrelationGridImageFilter.txx b/include/otbSARTemporalCorrelationGridImageFilter.txx index 239db269ac459c61973de23e9f920129cdee80ad..1e676917190d114ae2884b3231cdc73767c4e199 100644 --- a/include/otbSARTemporalCorrelationGridImageFilter.txx +++ b/include/otbSARTemporalCorrelationGridImageFilter.txx @@ -665,8 +665,6 @@ namespace otb pixelCorrelationGrid[1] = m_RoughShift_azi + bestShift_azi + dy; pixelCorrelationGrid[2] = VAL_MAX; - //std::cout << arrayPic[1][1] << " at " << bestShift_ran << " , " << bestShift_azi << std::endl; - } else { diff --git a/include/otbSARUpdateMetadataImageFilter.txx b/include/otbSARUpdateMetadataImageFilter.txx index e6e0c1b634161ab47edef24f3bdf130051f35d3f..555d871de1e06310984a68970b758f890b7aa8be 100644 --- a/include/otbSARUpdateMetadataImageFilter.txx +++ b/include/otbSARUpdateMetadataImageFilter.txx @@ -70,8 +70,6 @@ namespace otb str_slantRange.precision(14); str_slantRange << std::fixed << m_SlantRange; - std::cout << "str_slantRange = " << str_slantRange.str() << std::endl; - outputKWL.AddKey("support_data.first_line_time", m_TimeFirstLine); outputKWL.AddKey("support_data.slant_range_to_first_pixel", str_slantRange.str()); outputPtr->SetImageKeywordList(outputKWL); diff --git a/include/otbTilesAnalysisImageFilter.txx b/include/otbTilesAnalysisImageFilter.txx index 9ca8d4f869ee9dd0b731fdaf26f2d8adcdef3d65..13094f7663e4deef02351d8bc362e721cfeec835 100644 --- a/include/otbTilesAnalysisImageFilter.txx +++ b/include/otbTilesAnalysisImageFilter.txx @@ -39,9 +39,9 @@ namespace otb */ template <class TImageIn, class TImageOut, class TFunction> TilesAnalysisImageFilter< TImageIn, TImageOut, TFunction >::TilesAnalysisImageFilter() - : m_SizeTiles(50), m_Margin(7), m_UseCache(false), m_MaxMemoryCacheInMB(0), m_MaxShiftInRange(0.), - m_MaxShiftInAzimut(0.), m_UseMasterGeo(false), m_NbTiles(0), m_NbTilesCol(0), - m_IndLFirstTile(0), m_IndCFirstTile(0) + : m_SizeTiles(50), m_Margin(7), m_UseCache(false), m_MaxMemoryCacheInMB(0), m_NbTiles(0), m_NbTilesCol(0), + m_IndLFirstTile(0), m_IndCFirstTile(0), m_MaxShiftInRange(0.), m_MaxShiftInAzimut(0.), + m_UseMasterGeo(false) { m_ProcessedTilesIndex.clear(); m_ProcessedTiles.clear(); diff --git a/python_src/SAR_MultiSlc.py b/python_src/SAR_MultiSlc.py index a111fa0b0efe2ceedd114c636befd9034b7e76db..13e2f5eb8a46b6f13e4b6cdfccd95bda3b348d1d 100644 --- a/python_src/SAR_MultiSlc.py +++ b/python_src/SAR_MultiSlc.py @@ -124,13 +124,41 @@ if __name__ == "__main__": light_version = dict_Global['parameter']['clean'] light_version = func_utils.str2bool(light_version) + + func_utils.check_ifExist(dict_Global['in']['Input_Path']) + if master_ext[0] == "h5" : # Cosmo case master_Image = func_utils.get_imgFromDir(dict_Global['in']['Master_Image'], dict_Global['in']['Input_Path']) + + if not master_Image : + print(master_Image_base + " not found into given input path " + \ + dict_Global['in']['Input_Path']) + print("Please check your input path") + quit() + else : + correct = func_utils.check_image_pattern(master_Image_base, mode="Cosmo") + if not correct : + print("Master image " + master_Image_base + " does not respect naming conventions for Cosmo") + quit() + master_date = master_Image_base.split("_")[8][:8] pol = master_Image_base.split("_")[5] else : #S1 SM case master_Image = func_utils.get_imgFromSAFE(dict_Global['in']['Master_Image'], dict_Global['in']['Input_Path']) + + if not master_Image : + print(master_Image_base + " not found into given input path " + \ + dict_Global['in']['Input_Path']) + print("Please check your input path") + quit() + else : + correct = func_utils.check_image_pattern(master_Image_base, mode="S1SM") + if not correct : + print("Master image " + master_Image_base + " does not respect naming conventions for S1SM") + quit() + + master_date = master_Image_base.split("-")[4].split("t")[0] pol = master_Image_base.split("-")[3] manifest = master_Image.split("measurement")[0]+"/manifest.safe" @@ -193,7 +221,7 @@ if __name__ == "__main__": if "Spacingxy" in dict_PostProcessing['parameter']: spacingxy = str(dict_PostProcessing['parameter']['Spacingxy']) - ortho_interferogram = "no" + ortho_interferogram = "false" if 'Activate_Ortho' in dict_PostProcessing['parameter']: ortho_interferogram = dict_PostProcessing['parameter']['Activate_Ortho'] if roi: @@ -222,13 +250,13 @@ if __name__ == "__main__": geoGrid_threshold = 0.3 # ====== Check if interferogram is activated for ortho interferogram - if ortho_interferogram == "yes" and version_interferogram == "no": + if func_utils.str2bool(ortho_interferogram) and not func_utils.str2bool(version_interferogram): func_utils.log(logging.CRITICAL, "Error, Impossible to have ortho interferogram without interferogram\n" "If Ortho is required, please activate interferogram estimation in your json file") quit() # ====== Check if interferogram is activated for filtering - if func_utils.str2bool(activateFiltering) and version_interferogram == "no": + if func_utils.str2bool(activateFiltering) and not func_utils.str2bool(version_interferogram): func_utils.log(logging.CRITICAL, "Error, Impossible to have filering without interferogram\n" "If Filtering is required, please activate interferogram estimation in your json file") quit() @@ -342,11 +370,27 @@ if __name__ == "__main__": # Get the elements from os.dirs # ============================= - # ====== Get the list of GTiff corresponding to dates - tiff_list = func_utils.get_AllTiff(pol=pol, ext=master_ext[0], searchDir=dict_Global["in"]["Input_Path"]) + # ====== Get the list of GTiff corresponding to dates and patterns + tiff_list, throw_warning = func_utils.get_AllTiff(pol=pol, ext=master_ext[0], searchDir=dict_Global["in"]["Input_Path"]) + + # Throw a warning + if throw_warning : + func_utils.log(logging.WARNING, "WARNING : At least one of selected images into your input path does not match the expected pattern"+ "\n") + + tiff_dates = func_utils.get_Tiff_WithDates(start_time, end_time, exclude, tiff_list, master_ext[0]) - counter = 0 + tiff_dates = func_utils.avoidDuplicates(tiff_dates) + + if len(tiff_dates)-1 <= 0 : + func_utils.log(logging.CRITICAL, "ERROR : None secondary images found, please check your input path and your selection (dates, exclude ...)"+ "\n") + quit() + + if throw_warning : + # Indicate reference and all secondary images + func_utils.printOnStd("Reference and Secondary images : ") + func_utils.printOnStd(tiff_dates) + counter = 0 # ====== For loop processing for i in (i for i in tiff_dates if i != master_Image_base): total_slaves = len(tiff_dates)-1 @@ -623,7 +667,7 @@ if __name__ == "__main__": list_of_Grids, list_of_Interferogram = DInSar.gridToInterferogram(dem, master_Image, master_Image_base, slave_Image, slave_Image_base, master_data_dir, output_dir, param, 'Others', output_dir) interferogram_path = "" - if version_interferogram == "yes": + if func_utils.str2bool(version_interferogram): interferogram_path = list_of_Interferogram[0] grid_path = list_of_Grids[0] @@ -670,7 +714,6 @@ if __name__ == "__main__": InterferoB123 = "" Interfero_Ortho = "" - Interfero_Ortho = "" if not master_ext[0] == "h5": InterferoB123 = mib[:14]+"M"+mib[14:30]+mib[47:53]+"S"+sib[ @@ -691,7 +734,7 @@ if __name__ == "__main__": ### ROI, Ortho and band_extract ### - if ortho_interferogram == "yes": + if func_utils.str2bool(ortho_interferogram): interf_ortho = "interferogram_ortho.tif" diapOTBApp.orthorectification(interferogram_path, spacingxy, hgts_path, geoid_path, os.path.join(output_dir, interf_ortho)) if not roi: @@ -701,17 +744,21 @@ if __name__ == "__main__": interf_roi = "interferogram_roi.tif" func_utils.extract_roi(os.path.join(output_dir, interf_ortho), os.path.join(output_dir, interf_roi), roi) func_utils.extract_band123(os.path.join(output_dir, interf_roi), os.path.join(output_dir, Interfero_roi)) - if version_interferogram == "yes" and ortho_interferogram == "no" and roi is None: + if func_utils.str2bool(version_interferogram) and not func_utils.str2bool(ortho_interferogram) and roi is None: func_utils.extract_band123(interferogram_path, os.path.join(output_dir, InterferoB123)) # ==================================== # # Removing # # files # # ============================== # - if version_interferogram == "yes": + if func_utils.str2bool(version_interferogram): func_utils.silentremove(os.path.dirname(interferogram_path), os.path.basename(interferogram_path)) - func_utils.silentremove(os.path.dirname(interferogram_path), os.path.basename(interferogram_path).split(".")[0]+".geom") - if ortho_interferogram == "yes": + + os.rename(os.path.join(os.path.dirname(interferogram_path), + os.path.basename(interferogram_path).split(".")[0]+".geom"), + os.path.join(output_dir, InterferoB123.split(".")[0]+".geom")) + + 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") diff --git a/python_src/SAR_MultiSlc_IW.py b/python_src/SAR_MultiSlc_IW.py index c5460fc3b040c32630cf53880351ed7167311c8c..6333fe00334ee5a33be0869394cf8fa641dd5810 100644 --- a/python_src/SAR_MultiSlc_IW.py +++ b/python_src/SAR_MultiSlc_IW.py @@ -112,7 +112,22 @@ if __name__ == "__main__": start_time = int(dict_Global['in']['Start_Date']) end_time = int(dict_Global['in']['End_Date']) master_Image_base = dict_Global['in']['Master_Image'] + + func_utils.check_ifExist(dict_Global['in']['Input_Path']) + master_Image = func_utils.get_imgFromSAFE(dict_Global['in']['Master_Image'], dict_Global['in']['Input_Path']) + + if not master_Image : + print(master_Image_base + " not found into given input path " + \ + dict_Global['in']['Input_Path']) + print("Please check your input path") + quit() + else : + correct = func_utils.check_image_pattern(master_Image_base, mode="S1IW") + if not correct : + print("Master image " + master_Image_base + " does not respect naming conventions for S1IW") + quit() + master_date = master_Image_base.split("-")[4].split("t")[0] pol = master_Image_base.split("-")[3] iw = master_Image_base.split("-")[1] @@ -149,7 +164,7 @@ if __name__ == "__main__": # ====== Ground # ====== DIn_SAR - version_interferogram = "yes" + version_interferogram = "true" if "Activate_Interferogram" in dict_DInSAR['parameter']: version_interferogram = dict_DInSAR['parameter']['Activate_Interferogram'] @@ -183,7 +198,7 @@ if __name__ == "__main__": if "Spacingxy" in dict_PostProcessing['parameter']: spacingxy = str(dict_PostProcessing['parameter']['Spacingxy']) - ortho_interferogram = None + ortho_interferogram = "false" if 'Activate_Ortho' in dict_PostProcessing['parameter']: ortho_interferogram = dict_PostProcessing['parameter']['Activate_Ortho'] if roi: @@ -208,13 +223,13 @@ if __name__ == "__main__": # ====== Check if interferogram is activated for ortho interferogram - if ortho_interferogram == "yes" and version_interferogram == "no": + if func_utils.str2bool(ortho_interferogram) and not func_utils.str2bool(version_interferogram): func_utils.log(logging.CRITICAL, "Error, Impossible to have ortho interferogram without interferogram\n" "If Ortho is required, please activate interferogram estimation in your json file") quit() # ====== Check if interferogram is activated for filtering - if func_utils.str2bool(activateFiltering) and version_interferogram == "no": + if func_utils.str2bool(activateFiltering) and not func_utils.str2bool(version_interferogram) : func_utils.log(logging.CRITICAL, "Error, Impossible to have filering without interferogram\n" "If Filtering is required, please activate interferogram estimation in your json file") quit() @@ -315,10 +330,28 @@ if __name__ == "__main__": # Get the elements from os.dirs # ============================ - tiff_list = func_utils.get_AllTiff(pol, iw, searchDir=dict_Global["in"]["Input_Path"]) + # ====== Get the list of GTiff corresponding to dates and patterns + tiff_list, throw_warning = func_utils.get_AllTiff(pol, iw, searchDir=dict_Global["in"]["Input_Path"]) + + # Throw a warning + if throw_warning : + func_utils.log(logging.WARNING, "WARNING : At least one of selected images into your input path does not match the expected pattern"+ "\n") + tiff_dates = func_utils.get_Tiff_WithDates(start_time, end_time, exclude, tiff_list) - counter = 0 + tiff_dates = func_utils.avoidDuplicates(tiff_dates) + + + if len(tiff_dates)-1 <= 0 : + func_utils.log(logging.CRITICAL, "ERROR : None secondary images found, please check your input path and your selection (dates, exclude ...)"+ "\n") + quit() + + if throw_warning : + # Indicate reference and all secondary images + func_utils.printOnStd("Reference and Secondary images : ") + func_utils.printOnStd(tiff_dates) + + counter = 0 for i in (i for i in tiff_dates if i != master_Image_base): total_slaves = len(tiff_dates)-1 slave_Image_base = i @@ -616,7 +649,7 @@ if __name__ == "__main__": mib = master_Image_base sib = slave_Image_base - if version_interferogram == "yes": + 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[ @@ -628,30 +661,28 @@ if __name__ == "__main__": # B === Extraction of band 1,2,3 ds = gdal.Open(os.path.join(output_dir, Interferogram_Multiband), gdal.GA_ReadOnly) ds = gdal.Translate(os.path.join(output_dir, Interferogram_), ds, bandList = ["1","2","3"]) - os.rename(os.path.join(output_dir, - Interferogram_Multiband.split(".")[0]+".geom"), os.path.join(output_dir, Interferogram_.split(".")[0]+".geom")) - - - - # Phase Filtering (if required) - if func_utils.str2bool(activateFiltering): - # Default paramater - step = 16 - sizetiles = 64 - - paramPost = {} - paramPost['ml_filt_interf_range'] = ml_interf_filt_range - paramPost['ml_filt_interf_azimut'] = ml_interf_filt_azimut - paramPost['filt_alpha'] = interf_filt_alpha - paramPost['interf_Name'] = Con_Interf - - Post_Processing.filtering(master_Image, master_Image_base, slave_Image, - slave_Image_base, Master_temp_dir, temp_dir, paramPost, - "S1_IW", output_dir) - + + # Phase Filtering (if required) + if func_utils.str2bool(activateFiltering): + # Default paramater + step = 16 + sizetiles = 64 + + paramPost = {} + paramPost['ml_filt_interf_range'] = ml_interf_filt_range + paramPost['ml_filt_interf_azimut'] = ml_interf_filt_azimut + paramPost['filt_alpha'] = interf_filt_alpha + paramPost['interf_Name'] = Con_Interf + + Post_Processing.filtering(master_Image, master_Image_base, slave_Image, + slave_Image_base, Master_temp_dir, temp_dir, paramPost, + "S1_IW", output_dir) + + os.rename(os.path.join(output_dir, Interferogram_Multiband.split(".")[0]+".geom"), + os.path.join(output_dir, Interferogram_.split(".")[0]+".geom")) # C === Ortho Interferogram - if version_interferogram == "yes" and ortho_interferogram == "yes": + 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[ @@ -669,9 +700,9 @@ if __name__ == "__main__": # ================================ # func_utils.silentremove(output_dir, CoRe_ML.split(".")[0]+".geom") func_utils.silentremove(output_dir, dop_file) - if version_interferogram == "yes": + if func_utils.str2bool(version_interferogram): func_utils.silentremove(output_dir, Interferogram_Multiband) - if version_interferogram == "yes" and ortho_interferogram == "yes": + 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) diff --git a/python_src/diapOTB.py b/python_src/diapOTB.py index b97e8c36b87b0a27c0a2e3376274141a70861a69..4f13ec38fb771db798b0282bd2176f2ed2c81df5 100644 --- a/python_src/diapOTB.py +++ b/python_src/diapOTB.py @@ -125,7 +125,9 @@ if __name__ == "__main__": ml_interf_azimut = int(dict_DInSAR['parameter']['Interferogram_mlazi']) # Post_Processing - activateOrtho = dict_PostProcessing['parameter']['Activate_Ortho'] + activateOrtho = "false" + if "Activate_Ortho" in dict_PostProcessing['parameter'] : + dict_PostProcessing['parameter']['Activate_Ortho'] spacingxy = 0.00001 if "spacingxy" in dict_PostProcessing['parameter'] : diff --git a/python_src/diapOTB_S1IW.py b/python_src/diapOTB_S1IW.py index b77c1b454681d6bee1cabfd64ced4680bd1d2965..a0b4d7d0b5359b8aff11111dad810e142bdd92fc 100644 --- a/python_src/diapOTB_S1IW.py +++ b/python_src/diapOTB_S1IW.py @@ -112,7 +112,9 @@ if __name__ == "__main__": # Post_Processing - activateOrtho = dict_PostProcessing['parameter']['Activate_Ortho'] + activateOrtho = "false" + if "Activate_Ortho" in dict_PostProcessing['parameter'] : + dict_PostProcessing['parameter']['Activate_Ortho'] spacingxy = 0.00001 if "spacingxy" in dict_PostProcessing['parameter'] : diff --git a/python_src/ex_config/ex_config_MultiSlc_CosmoS1SM.json b/python_src/ex_config/ex_config_MultiSlc_CosmoS1SM.json index b52fd0be1cc95cd4a7e6549693d9ac91f2fcd34f..2d6d713282d3e68230b19c108a01037cb27954cc 100644 --- a/python_src/ex_config/ex_config_MultiSlc_CosmoS1SM.json +++ b/python_src/ex_config/ex_config_MultiSlc_CosmoS1SM.json @@ -57,7 +57,7 @@ "Activate_Interferogram": "yes" } }, - "Post_Proccessing": + "Post_Processing": { "parameter": { diff --git a/python_src/ex_config/ex_config_MultiSlc_IW.json b/python_src/ex_config/ex_config_MultiSlc_IW.json index ccf1a9a95ba59b2be01d97b2dc3c37f690aed0f5..d3b49b9c617936612d094d6f3b5552b7ed443d34 100644 --- a/python_src/ex_config/ex_config_MultiSlc_IW.json +++ b/python_src/ex_config/ex_config_MultiSlc_IW.json @@ -48,7 +48,7 @@ "ESD_iter": 2 } }, - "Post_Proccessing": + "Post_Processing": { "parameter": { diff --git a/python_src/ex_config/ex_config_diapOTB_Cosmo.json b/python_src/ex_config/ex_config_diapOTB_Cosmo.json index 24c300e4539810fbb7e88461b040c90a5d423303..c269e69b6896466c1bbb1ad4a4794a55a7b7a33d 100644 --- a/python_src/ex_config/ex_config_diapOTB_Cosmo.json +++ b/python_src/ex_config/ex_config_diapOTB_Cosmo.json @@ -45,10 +45,10 @@ "GridStep_azimut": 150, "Grid_Threshold": 0.3, "Grid_Gap": 3000, - "Interferogram_gain": 0.1, + "Interferogram_gain": 0.1 } }, - "Post_Proccessing": + "Post_Processing": { "parameter": { diff --git a/python_src/ex_config/ex_config_diapOTB_S1IW.json b/python_src/ex_config/ex_config_diapOTB_S1IW.json index 373537865c574d308e665a57448b120bcd4b1a03..e049d0c4968e67440d69366f3d97bb9775bf320a 100644 --- a/python_src/ex_config/ex_config_diapOTB_S1IW.json +++ b/python_src/ex_config/ex_config_diapOTB_S1IW.json @@ -41,7 +41,7 @@ "ESD_iter": 2 } }, - "Post_Proccessing": + "Post_Processing": { "parameter": { diff --git a/python_src/ex_config/ex_config_diapOTB_S1SM.json b/python_src/ex_config/ex_config_diapOTB_S1SM.json index 16e6ed72c2c077d3f67536eac9c07a67273ff02a..6f049d5d5cfabd125b1522fb5543df3ed08638e7 100644 --- a/python_src/ex_config/ex_config_diapOTB_S1SM.json +++ b/python_src/ex_config/ex_config_diapOTB_S1SM.json @@ -48,7 +48,7 @@ "Interferogram_gain": 0.1 } }, - "Post_Proccessing": + "Post_Processing": { "parameter": { diff --git a/python_src/utils/func_utils.py b/python_src/utils/func_utils.py index c42e55272835ebb9a378ff36c9745ae2543806af..6b721a8f81b7499b29dd5c0da363388d1dfa60a2 100644 --- a/python_src/utils/func_utils.py +++ b/python_src/utils/func_utils.py @@ -249,6 +249,58 @@ def get_imgFromDir(arg, searchDir="."): img = str("".join(img)) return img +def check_image_pattern(img, mode="S1SM") : + """ + Check pattern for current image. Must be cohetrent according to the sensor and mode + """ + + correct_pattern = False + + + if mode == "S1SM" : + # Mode S1 SM : mmm-bb-ttt-pp-yyyymmddthhmmss-yyyymmddthhmmss* + # mmm : Mission identifier (s1a or s1b) + # bb : Mode/Beam (s1-s6 for SM) + # 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 ... + pattern = "".join(["s1.", "-", '\w{1}', '\d', "-slc-", '\w{2}', "-", '\d{8}', "t", '\d{6}', "-", '\d{8}', "t", '\d{6}']) + + if re.match(pattern, img) : + correct_pattern = True + + elif mode == "Cosmo": + # Mode Cosmo : CSKS<i>_*_<YYYYMMDDhhmmss>_<YYYYMMDDhhmmss> + # i : Identifier of the satellite (1, 2, 3 or 4) + # YYYYMMDDhhmmss : Product start/stop date and times + # * : Others representations such as identifier for orbit direction or look side + pattern = "".join(["CSKS", '\d']) + + if re.match(pattern, img) : + pattern_dates = "".join(['\d{14}', "_", '\d{14}']) + dates = re.findall(pattern_dates, img) + + if len(dates) == 1 : + correct_pattern = True + + else : + # Mode S1 IW : mmm-bb-ttt-pp-yyyymmddthhmmss-yyyymmddthhmmss* + # mmm : Mission identifier (s1A or s1B) + # bb : Mode/Beam (iw1-iw3 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 ... + pattern = "".join(["s1.", "-", '\w{2}', '\d', "-slc-", '\w{2}', "-", '\d{8}', "t", '\d{6}', "-", '\d{8}', "t", '\d{6}']) + + if re.match(pattern, img) : + correct_pattern = True + + return correct_pattern + def image_envelope(inTIF, outSHP): """ @@ -292,30 +344,69 @@ def check_srtm_coverage(inSHP_Geometry, SRTM): def get_AllTiff(pol, iw="", ext="", searchDir="."): """ - Get all tiff from an input directory + Get all tiff from an input directory (check on pattern) """ TiffList = [] + throw_warning = False + # Mode S1 IW if not iw == "" : for root, dirs, files in os.walk(searchDir): - for i in (i for i in files): # if i != inTIF): - if i.endswith(".tiff") and pol == i.split("-")[3]: - if iw == i.split("-")[1]: - TiffList.append(i) + for i in (i for i in files): + + # Selection with extension (.tiff) + if i.endswith(".tiff") : + + # Check pattern + correct = check_image_pattern(i, "S1IW") + + if correct : + # Selection with polarisation and subwath + if pol == i.split("-")[3]: + if iw == i.split("-")[1]: + TiffList.append(i) + else : + throw_warning = True + else : + # Mode Cosmo if ext == "h5": for root, dirs, files in os.walk(searchDir): - for i in (i for i in files): # if i != inTIF): - if i.endswith(".h5") and pol == i.split("_")[5]: - TiffList.append(i) - + for i in (i for i in files): + + # Selection with extension (.h5) + if i.endswith(".h5") : + + # Check pattern + correct = check_image_pattern(i, "Cosmo") + + if correct : + # Selection with polarisation + if pol == i.split("_")[5]: + TiffList.append(i) + else : + throw_warning = True + + # Mode S1 SM if not ext == "h5": for root, dirs, files in os.walk(searchDir): - for i in (i for i in files): # if i != inTIF): - if i.endswith(".tiff") and pol == i.split("-")[3]: - TiffList.append(i) + for i in (i for i in files): + + # Selection with extension (.tiff) + if i.endswith(".tiff") : + + # Check pattern + correct = check_image_pattern(i, "S1SM") + + if correct : + # Selection with polarisation + if pol == i.split("-")[3]: + TiffList.append(i) + else : + throw_warning = True + - return TiffList + return TiffList, throw_warning def get_AllFilesWithExt(searchDir, ext) : """ @@ -530,6 +621,14 @@ def str2bool(v): """ return v.lower() in ("yes", "true", "t", "1") + +def avoidDuplicates(inlist): + """ + Remove duplicates into an input list. + """ + outlist = list(dict.fromkeys(inlist)) + return outlist + def check_ifExist(fileOrPathOrImg): """ Check if a file, path or image exists. If not quit the program. @@ -539,6 +638,14 @@ def check_ifExist(fileOrPathOrImg): quit() +def check_ifDir(inDir): + """ + Check if the input path exists and is a directory + """ + if not os.path.isdir(inDir): + print(inDir + " does not exists or is not a directory") + quit() + def check_burstIndex(burst_index): """ Check if the burst_index as string input is correctly sent diff --git a/python_src/utils/generateConfigFile.py b/python_src/utils/generateConfigFile.py new file mode 100644 index 0000000000000000000000000000000000000000..064b0f0e401afaa91428a692a125672dae7215e3 --- /dev/null +++ b/python_src/utils/generateConfigFile.py @@ -0,0 +1,373 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" + generateConfigFile.py + ===================== + + Python script to generate configuration file (json format) with default parameters and user's paths + +""" + +import os +import sys +import re +import json +import readline, glob + +import func_utils + +# Util fct for autocompletion +def complete(text, state): + return (glob.glob(text+'*')+[None])[state] + +# Print with colors +def prRed(skk): print("\033[91m {}\033[00m" .format(skk)) +def prGreen(skk): print("\033[92m {}\033[00m" .format(skk)) +def prYellow(skk): print("\033[93m {}\033[00m" .format(skk)) +def prLightPurple(skk): print("\033[94m {}\033[00m" .format(skk)) +def prPurple(skk): print("\033[95m {}\033[00m" .format(skk)) +def prCyan(skk): print("\033[96m {}\033[00m" .format(skk)) +def prLightGray(skk): print("\033[97m {}\033[00m" .format(skk)) +def prBlack(skk): print("\033[98m {}\033[00m" .format(skk)) + +# Input with colors +def genericInput(skk, color) : + try: + return input(color .format(skk)) + except KeyboardInterrupt : + prRed("Generation Aborted, Ctrl-C detected") + sys.exit(1) + except : + prRed("Generation Aborted") + sys.exit(1) + +def inRed(skk): return genericInput(skk, "\033[91m {}\033[00m") +def inGreen(skk): return genericInput(skk, "\033[92m {}\033[00m") +def inYellow(skk): return genericInput(skk, "\033[93m {}\033[00m") +def inLightPurple(skk): return genericInput(skk, "\033[94m {}\033[00m") +def inPurple(skk): return genericInput(skk, "\033[95m {}\033[00m") +def inCyan(skk): return genericInput(skk, "\033[96m {}\033[00m") +def inLightGray(skk): return genericInput(skk, "\033[97m {}\033[00m") +def inBlack(skk): return genericInput(skk, "\033[98m {}\033[00m") + + +# Questions to user for SAR_MultiSlc* chains +def askForMultiSlc(dataConfig) : + # Select sensor if SAR_MultiSlc + sensor = "S1IW" + if (response == "SAR_MultiSlc") : + sensor = inLightPurple("Please, select the wanted sensor S1SM " \ + "(for Sentinel-1 StripMap mode) or Cosmo " \ + "(for Cosmo-Skymed Spotligth and StriMap mode) : " ) + + if sensor not in ["S1SM", "Cosmo"] : + prRed("Unknown sensor, please choose between S1SM or Cosmo") + quit() + + # SRTM_Shapefile + SRTM_Shapefile = os.path.realpath(inPurple("Please, enter your path to srtm shp : " )) + func_utils.check_ifExist(SRTM_Shapefile) + + # SRTM_Path + SRTM_Path = os.path.realpath(inPurple("Please, enter your path to srtm hgt files : " )) + func_utils.check_ifDir(SRTM_Path) + + # Input/Output Paths + Input_Path = os.path.realpath(inPurple("Please, enter your path to input images : " )) + func_utils.check_ifDir(Input_Path) + + Output_Path = os.path.realpath(inPurple("Where would you like to store the output results : " )) + #func_utils.check_ifDir(os.path.dirname(Output_Path)) + func_utils.check_ifDir(Output_Path) + + # reference image (must be into Input_Path) + reference_image = inPurple("Which image is your reference : " ) + func_utils.check_ifExist(reference_image) + reference_image = os.path.basename(reference_image) + + if not func_utils.get_imgFromDir(reference_image, Input_Path) : + prRed(reference_image + " not found into given input path " + \ + "Input_Path") + prRed("Please check your input path") + quit() + else : + correct = func_utils.check_image_pattern(reference_image, mode=sensor) + if not correct : + prRed("Reference image " + reference_image + " does not respect naming conventions for the " \ + "selected sensor") + quit() + + # Geoid file + res_geoid = inPurple("Would you like to add a geoid file (yes/no) : ") + Geoid = None + + if res_geoid == "yes" : + Geoid = os.path.realpath(inLightPurple("Please, enter your path to your geoid file : ")) + func_utils.check_ifExist(Geoid) + else : + Geoid = os.getenv('OTB_GEOID_FILE') + + # Start/End date for image selection + res_date = inLightPurple("Would you like to specify a start and end date for image selection (yes/no) : ") + + # Dummy dates to select by default all images into Input_Path + start_date = "19000101" + end_date = "29000101" + pattern = "".join(['\d{8}']) + if res_date == "yes" : + start_date = inPurple("Please, indicate a start date with YYYYMMDD format : ") + if not re.match(pattern, start_date) : + prRed("start_date " + start_date + " does not respect the expected format YYYYMMDD") + quit() + + end_date = inPurple("Please, indicate a end date with YYYYMMDD format : ") + if not re.match(pattern, end_date) : + prRed("end_date " + end_date + " does not respect the expected format YYYYMMDD") + quit() + + # Indicate to user, all selected images with given dates, polarisation and input_path + ext = "tiff" + pol = "" + iw = "" + if sensor == "Cosmo" : + ext = "h5" + pol = reference_image.split("_")[5] + else : + pol = reference_image.split("-")[3] + + if sensor == "S1IW" : + iw = reference_image.split("-")[1] + ext = "" + + exclude = "-9999" + tiff_list, throw_warning = func_utils.get_AllTiff(pol=pol, ext=ext, iw=iw, searchDir=Input_Path) + tiff_dates = func_utils.get_Tiff_WithDates(int(start_date), int(end_date), exclude, tiff_list, ext) + + # Avoid duplicates + tiff_dates = func_utils.avoidDuplicates(tiff_dates) + tiff_dates.remove(reference_image) + + prYellow("For your information, the selected images for processings will be : ") + prYellow("As reference : " + reference_image) + prYellow("As secondaries : " + str(tiff_dates)) + + # Ask to continue if selection OK + res_continue = inLightPurple("Do you agree to continue with this selection (yes/no) : ") + + if res_continue != "yes" : + prRed("Previous selection does not fullfill your expectations, you can relaunch this script with new inputs") + quit() + + # EOF file + EOF_Path = None + if sensor != "Cosmo" : + res_eof = inLightPurple("Would you like to indicate fine orbits (yes/no) : ") + + if res_eof == "yes" : + EOF_Path = os.path.realpath(inPurple("Please, enter your path to .EOF files : " )) + func_utils.check_ifDir(EOF_Path) + + + # Fill with user's response our generic fields for SAR_MultiSlc* chains + dataConfig['Global']['in']['SRTM_Shapefile'] = SRTM_Shapefile + dataConfig['Global']['in']['SRTM_Path'] = SRTM_Path + dataConfig['Global']['in']['Input_Path'] = Input_Path + dataConfig['Global']['in']['Master_Image'] = reference_image + dataConfig['Global']['in']['Start_Date'] = start_date + dataConfig['Global']['in']['End_Date'] = end_date + if Geoid : + dataConfig['Global']['in']['Geoid'] = Geoid + else : + del dataConfig['Global']['in']['Geoid'] + if EOF_Path : + dataConfig['Global']['in']['EOF_Path'] = EOF_Path + + dataConfig['Global']['out']['Output_Path'] = Output_Path + + +# Questions to user for diapOTB* chains +def askForDiapOTB(dataConfig) : + # Select sensor if diapOTB + sensor = "S1IW" + if (response == "diapOTB") : + sensor = inLightPurple("Please, select the wanted sensor S1SM " \ + "(for Sentinel-1 StripMap mode) or Cosmo " \ + "(for Cosmo-Skymed Spotligth and StriMap mode) : " ) + + if sensor not in ["S1SM", "Cosmo"] : + prRed("Unknown sensor, please choose between S1SM or Cosmo") + quit() + + + # reference image (path to image) + reference_image = os.path.realpath(inPurple("Which image is your reference : " )) + func_utils.check_ifExist(reference_image) + reference_image_base = os.path.basename(reference_image) + + correct = func_utils.check_image_pattern(reference_image_base, mode=sensor) + if not correct : + prRed("Reference image " + reference_image_base + " does not respect naming conventions for the " \ + "selected sensor") + quit() + + # reference image (path to image) + secondary_image = os.path.realpath(inPurple("Which image is secondary : " )) + func_utils.check_ifExist(secondary_image) + secondary_image_base = os.path.basename(secondary_image) + + correct = func_utils.check_image_pattern(secondary_image_base, mode=sensor) + if not correct : + prRed("Reference image " + secondary_image_base + " does not respect naming conventions for the " \ + "selected sensor") + quit() + + + # DEM Path + DEM_Path = os.path.realpath(inPurple("Please, enter your path to your DEM : ")) + func_utils.check_ifExist(DEM_Path) + + # Output Path + Output_Path = os.path.realpath(inPurple("Where would you like to store the output results : " )) + func_utils.check_ifDir(os.path.dirname(Output_Path)) + + # EOF file + EOF_Path = None + if sensor != "Cosmo" : + res_eof = inLightPurple("Would you like to indicate fine orbits (yes/no) : ") + + if res_eof == "yes" : + EOF_Path = os.path.realpath(inPurple("Please, enter your path to .EOF files : " )) + func_utils.check_ifDir(EOF_Path) + + + # Fill with user's response our generic fields for SAR_MultiSlc* chains + dataConfig['Global']['in']['Master_Image_Path'] = reference_image + dataConfig['Global']['in']['Slave_Image_Path'] = secondary_image + dataConfig['Global']['in']['DEM_Path'] = DEM_Path + if EOF_Path : + dataConfig['Global']['in']['EOF_Path'] = EOF_Path + + dataConfig['Global']['out']['output_dir'] = Output_Path + + + +################### +###### Main ####### +################### +if __name__ == "__main__": + + ######### Introduction prints ######### + prCyan("Welcome to DiapOTB remote module !") + prCyan("You can generate configuration files for the four available processing chains : diapOTB," \ + "diapOTB_S1IW, SAR_MultiSlc and SAR_MultiSlc_IW") + + ######### Load the example for prepare the configuration file according to user's choice ######### + # First choice for user : the selected chain + response = inLightGray("Please, choose your processing chain (diapOTB, diapOTB_S1IW, SAR_MultiSlc and " \ + "SAR_MultiSlc_IW) : ") + + if response not in ['diapOTB', 'diapOTB_S1IW', 'SAR_MultiSlc', 'SAR_MultiSlc_IW'] : + prRed("Wrong chain, please choose between available chains") + quit() + + + # Load examples according to the selected chain => Init a dictionnary with default parameters + current_path = os.path.dirname(os.path.realpath(__file__)) + ex_config_path = os.path.join(current_path, "../ex_config") + + dataConfig = {} + if response == "diapOTB" : + + ex_confile = os.path.join(ex_config_path, "ex_config_diapOTB_Cosmo.json") + dataConfig = func_utils.load_configfile(ex_confile, "S1_SM") + + elif response == "diapOTB_S1IW" : + + ex_confile = os.path.join(ex_config_path, "ex_config_diapOTB_S1IW.json") + dataConfig = func_utils.load_configfile(ex_confile, "S1_IW") + + elif response == "SAR_MultiSlc" : + + ex_confile = os.path.join(ex_config_path, "ex_config_MultiSlc_CosmoS1SM.json") + dataConfig = func_utils.load_configfile(ex_confile, "multi_S1") + + elif response == "SAR_MultiSlc_IW" : + + ex_confile = os.path.join(ex_config_path, "ex_config_MultiSlc_IW.json") + dataConfig = func_utils.load_configfile(ex_confile, "multi_SW") + + + + ########## Prepare for questions : with autocompletion ######### + readline.set_completer_delims(' \t\n;') + readline.parse_and_bind("tab: complete") + readline.set_completer(complete) + + ########## Ask to user for generic fields ######### + # SAR_MultiSlc* chains + if (response == "SAR_MultiSlc" or response == "SAR_MultiSlc_IW") : + try: + askForMultiSlc(dataConfig) + except : + prRed("Generation Aborted") + sys.exit(1) + + if (response == "diapOTB" or response == "diapOTB_S1IW") : + try : + askForDiapOTB(dataConfig) + except : + prRed("Generation Aborted") + sys.exit(1) + + # Dump dataConfig with the new fields and the default parameters + res_json = os.path.realpath(inLightGray("Where do you want store your configuration file : ")) + + # if directory + if os.path.isdir(res_json) : + res_json_name = inLightGray("Please, enter a name for your configuration " \ + "file (with .json extension) : ") + + if os.path.exists(os.path.join(res_json, res_json_name)) : + res_json_overwrite = inLightGray("Would you like to overwrite the file " + + res_json_name + " (yes/no) : ") + + if res_json_overwrite == "yes" : + with open(os.path.join(res_json, res_json_name), 'w') as f: + json.dump(dataConfig, f, indent=2, sort_keys=False) + else : + prRed("Generation Aborted") + quit() + + else : + with open(os.path.join(res_json, res_json_name), 'w') as f: + json.dump(dataConfig, f, indent=2, sort_keys=False) + + # If file (or wrong path) + else : + if os.path.isdir(os.path.dirname(res_json)) : + + if os.path.exists(res_json) : + res_json_overwrite = inLightGray("Would you like to overwrite the file " + + res_json + " (yes/no) : ") + + if res_json_overwrite == "yes": + with open(res_json, 'w') as f: + json.dump(dataConfig, f, indent=2, sort_keys=False) + else : + prRed("Generation Aborted") + quit() + else : + with open(res_json, 'w') as f: + json.dump(dataConfig, f, indent=2, sort_keys=False) + + else : + prRed("Wrong path for the configuration file, Generation Aborted") + + + ######### Conclusion prints ######### + prGreen("The configuration file was generated !") + prCyan("You can modify the parameters in it and launch the processing chain with this file as only argument") + prCyan("You can find further information on https://gitlab.orfeo-toolbox.org/remote_modules/diapotb/-/wikis/") + +