diff --git a/json_schemas/schema_S1IW.json b/json_schemas/schema_S1IW.json index 137e8464d1ce473cb576edb57676936f2ac4f407..f8c9911633b55dd57fd265cb7f215c337b57ecab 100644 --- a/json_schemas/schema_S1IW.json +++ b/json_schemas/schema_S1IW.json @@ -21,7 +21,8 @@ "additionalProperties": false, "properties": {"Master_Image_Path": {"type": "string"}, "Slave_Image_Path": {"type": "string"}, - "DEM_Path": {"type": "string"}} + "DEM_Path": {"type": "string"}, + "EOF_Path": {"type": "string"}} }, "out": { diff --git a/json_schemas/schema_S1SM.json b/json_schemas/schema_S1SM.json index c18077fa860a20ad7c1ce91edd95c7ebec70575e..c69614c415fceb224b544bceb16f0b746a5cd17e 100644 --- a/json_schemas/schema_S1SM.json +++ b/json_schemas/schema_S1SM.json @@ -22,7 +22,8 @@ "additionalProperties": false, "properties": {"Master_Image_Path": {"type": "string"}, "Slave_Image_Path": {"type": "string"}, - "DEM_Path": {"type": "string"}} + "DEM_Path": {"type": "string"}, + "EOF_Path": {"type": "string"}} }, "out": { diff --git a/python_src/diapOTB.py b/python_src/diapOTB.py index cb207b18fe9d43cb670f6883f3049ec0c09f17b2..b97e8c36b87b0a27c0a2e3376274141a70861a69 100644 --- a/python_src/diapOTB.py +++ b/python_src/diapOTB.py @@ -47,6 +47,7 @@ from processings import DInSar from processings import Metadata_Correction from processings import Post_Processing +import utils.DiapOTB_applications as diapOTBApp from utils import func_utils # Main @@ -75,8 +76,12 @@ if __name__ == "__main__": master_Image = dict_Global['in']['Master_Image_Path'] slave_Image = dict_Global['in']['Slave_Image_Path'] dem = dict_Global['in']['DEM_Path'] - output_dir = dict_Global['out']['output_dir'] + eof_Path = None + if 'EOF_Path' in dict_Global['in']: + eof_Path = dict_Global['in']['EOF_Path'] + output_dir = dict_Global['out']['output_dir'] + satellite = "default" mode = "default" @@ -162,6 +167,13 @@ if __name__ == "__main__": print("The output directory exists. Some files can be overwritten") + # Check eof path + if eof_Path : + if not os.path.exists(eof_Path) : + func_utils.log(logging.CRITICAL, "Error, {path} does not exist. Check its path.".format(path=eof_Path)) + quit() + + # Init file handler (all normaly print on std is redirected into info.log) # To use previous print on std, use printOnStd func_utils.init_fileLog(output_dir) @@ -296,6 +308,67 @@ if __name__ == "__main__": func_utils.printOnStd("\n Beginning of DiapOTB processing (S1 SM or Cosmo mode) \n") func_utils.log(logging.INFO, "############ Beginning of DiapOTB processing (S1 SM or Cosmo mode) ##############") + + # Find eof files for each image if not cosmo + # Then, create the "fine" geom (with precise orbits) + # Eventually, assign an extended filename if EOF file correspond to the image + if satellite != "cosmo" : + if eof_Path : + list_ofEOF = func_utils.get_AllFilesWithExt(eof_Path, ".EOF") + + + # master + start_master = dictKWLMaster['support_data.first_line_time'] + end_master = dictKWLMaster['support_data.last_line_time'] + + # Get a eof file + eof_file = func_utils.select_EofWithDate(start_master, end_master, list_ofEOF) + + if (eof_file) : + # Create the new geom file into dedicated repository + extendedGeom_Path = os.path.join(output_dir, "extended_geom") + if not os.path.exists(extendedGeom_Path): + os.makedirs(extendedGeom_Path) + + # Call SARMetadataCorrection + diapOTBApp.metadataCorrection(mode="orbits", insar=master_Image, indem=None, + infineorbits=os.path.join(eof_Path, eof_file), + outPath=os.path.join(extendedGeom_Path, + "extended_master.geom")) + + + # Assign new geom file with extended filename + master_Image += "?geom=" + os.path.join(extendedGeom_Path, + "extended_master.geom") + + + # slave + dictKWLSlave = func_utils.getImageKWL(slave_Image) + start_slave = dictKWLSlave['support_data.first_line_time'] + end_slave = dictKWLSlave['support_data.last_line_time'] + + # Get a eof file + eof_file = func_utils.select_EofWithDate(start_slave, end_slave, list_ofEOF) + + if (eof_file) : + # Create the new geom file into dedicated repository + extendedGeom_Path = os.path.join(output_dir, "extended_geom") + if not os.path.exists(extendedGeom_Path): + os.makedirs(extendedGeom_Path) + + # Call SARMetadataCorrection + diapOTBApp.metadataCorrection(mode="orbits", insar=slave_Image, indem=None, + infineorbits=os.path.join(eof_Path, eof_file), + outPath=os.path.join(extendedGeom_Path, + "extended_slave.geom")) + + # Assign new geom file with extended filename + slave_Image += "?geom=" + os.path.join(extendedGeom_Path, + "extended_slave.geom") + + + + ####################### Pre Processing Chain ########################## # Master func_utils.printOnStd("\n Master Pre_Processing chain \n") diff --git a/python_src/diapOTB_S1IW.py b/python_src/diapOTB_S1IW.py index 29655d8413b84b8337afa8f25423bcef95db5d9d..b77c1b454681d6bee1cabfd64ced4680bd1d2965 100644 --- a/python_src/diapOTB_S1IW.py +++ b/python_src/diapOTB_S1IW.py @@ -46,6 +46,7 @@ from processings import Ground from processings import DInSar from processings import Post_Processing +import utils.DiapOTB_applications as diapOTBApp from utils import func_utils # Main @@ -74,6 +75,10 @@ if __name__ == "__main__": master_Image = dict_Global['in']['Master_Image_Path'] slave_Image = dict_Global['in']['Slave_Image_Path'] dem = dict_Global['in']['DEM_Path'] + eof_Path = None + if 'EOF_Path' in dict_Global['in']: + eof_Path = dict_Global['in']['EOF_Path'] + output_dir = dict_Global['out']['output_dir'] # Pre_Processing @@ -150,6 +155,12 @@ if __name__ == "__main__": else : print("The output directory exists. Some files can be overwritten") + # Check eof path + if eof_Path : + if not os.path.exists(eof_Path) : + func_utils.log(logging.CRITICAL, "Error, {path} does not exist. Check its path.".format(path=eof_Path)) + quit() + # Init file handler (all normaly print on std is redirected into info.log) # To use previous print on std, use printOnStd @@ -257,6 +268,65 @@ if __name__ == "__main__": func_utils.printOnStd("\n Beginning of DiapOTB processing (S1 IW mode) \n") func_utils.log(logging.INFO, "############ Beginning of DiapOTB processing (S1 IW mode) ##############") + + # Find eof files for each image if not cosmo + # Then, create the "fine" geom (with precise orbits) + # Eventually, assign an extended filename if EOF file correspond to the image + if eof_Path : + list_ofEOF = func_utils.get_AllFilesWithExt(eof_Path, ".EOF") + + + # master + start_master = dictKWLMaster['support_data.first_line_time'] + end_master = dictKWLMaster['support_data.last_line_time'] + + # Get a eof file + eof_file = func_utils.select_EofWithDate(start_master, end_master, list_ofEOF) + + if (eof_file) : + # Create the new geom file into dedicated repository + extendedGeom_Path = os.path.join(output_dir, "extended_geom") + if not os.path.exists(extendedGeom_Path): + os.makedirs(extendedGeom_Path) + + # Call SARMetadataCorrection + diapOTBApp.metadataCorrection(mode="orbits", insar=master_Image, indem=None, + infineorbits=os.path.join(eof_Path, eof_file), + outPath=os.path.join(extendedGeom_Path, + "extended_master.geom")) + + + # Assign new geom file with extended filename + master_Image += "?geom=" + os.path.join(extendedGeom_Path, + "extended_master.geom") + + + # slave + dictKWLSlave = func_utils.getImageKWL(slave_Image) + start_slave = dictKWLSlave['support_data.first_line_time'] + end_slave = dictKWLSlave['support_data.last_line_time'] + + # Get a eof file + eof_file = func_utils.select_EofWithDate(start_slave, end_slave, list_ofEOF) + + if (eof_file) : + # Create the new geom file into dedicated repository + extendedGeom_Path = os.path.join(output_dir, "extended_geom") + if not os.path.exists(extendedGeom_Path): + os.makedirs(extendedGeom_Path) + + # Call SARMetadataCorrection + diapOTBApp.metadataCorrection(mode="orbits", insar=slave_Image, indem=None, + infineorbits=os.path.join(eof_Path, eof_file), + outPath=os.path.join(extendedGeom_Path, + "extended_slave.geom")) + + # Assign new geom file with extended filename + slave_Image += "?geom=" + os.path.join(extendedGeom_Path, + "extended_slave.geom") + + + ####################### Pre Processing Chain ########################## # Master diff --git a/python_src/utils/DiapOTB_applications.py b/python_src/utils/DiapOTB_applications.py index 1cb94c504032511eafe7f569aaf8138a8ca0f9b5..ae7ab0c6400fe933dc1d028b2eb7f649b848c2a7 100644 --- a/python_src/utils/DiapOTB_applications.py +++ b/python_src/utils/DiapOTB_applications.py @@ -654,6 +654,52 @@ def topographicPhase(ingrid, insarslave, incartmeanmaster, gridsteprange, gridst appTopoPhase.ExecuteAndWriteOutput() +def metadataCorrection(mode, insar, indem, infineorbits, + outPath, ram="4000"): + """ + Launch SARMetadataCorrection application (from DiapOTB). + + This application correct some metadata such as gcp or orbit states. + Two kinds of uses are possible according to the input mode : + _ GCPs correction thanks to input DEM + _ Fine orbits correction (with input EOF file) + + + :param mode: String to indicate selected mode (gcp or orbits). + :param insar: Input SAR image. + :param indem: Input DEM to extract height data. + :param infineorbits: Input file to get precise orbits. + :param outPath: Output geom file. + + :type mode: string + :type insar: string + :type idem: string + :type infineorbits: string + :type outPath: string + + :return: None + """ + appMetatadataCorrection = otb.Registry.CreateApplication("SARMetadataCorrection") + + # Check mode (must be gcp or orbits) + if mode != "gcp" and mode != "orbits" : + print("Wrong selected modes for SARMetadataCorrection application") + return 1 + + + appMetatadataCorrection.SetParameterString("mode", mode) # Check if really string + appMetatadataCorrection.SetParameterString("insar", insar) + + if mode == "gcp" : + appMetatadataCorrection.SetParameterString("indem", indem) + else : + appMetatadataCorrection.SetParameterString("infineorbits", infineorbits) + + appMetatadataCorrection.SetParameterString("outkwl", outPath) + appMetatadataCorrection.SetParameterString("ram", ram) + appMetatadataCorrection.ExecuteAndWriteOutput() + + def phaseFiltering(withComplex, inForFiltering, mlran, mlazi, step, sizetiles, alpha, outPath, ram="4000"): """ diff --git a/python_src/utils/func_utils.py b/python_src/utils/func_utils.py index fa6d0e6e2237d9c34fd824300418d584f33ee939..c42e55272835ebb9a378ff36c9745ae2543806af 100644 --- a/python_src/utils/func_utils.py +++ b/python_src/utils/func_utils.py @@ -39,6 +39,7 @@ import argparse import re import xml.etree.ElementTree as ET import datetime +import time import gdal import ogr @@ -201,7 +202,7 @@ def getImageKWL(Img): keyword = ReadImageInfo.GetParameterString("keyword") keywordlist = ReadImageInfo.GetParameterString("keyword").split("\n") keywordlist = filter(None, keywordlist) - dictKWL = { i.split(':')[0] : re.sub(r"[\n\t\s]*", "", i.split(':')[1]) for i in keywordlist } + dictKWL = { i.split(':')[0] : re.sub(r"[\n\t\s]*", "", "".join(i.split(':')[1:])) for i in keywordlist } return dictKWL @@ -354,6 +355,42 @@ def get_Tiff_WithDates(start, end, exclude, TiffList, ext=""): date_list.append(i) return date_list +def select_EofWithDate(start, end, eofList) : + """ + Select into the input list, the file that correspond to dates + """ + time_start = time.mktime(time.strptime(start, + "%Y-%m-%dT%H%M%S.%f")) + + time_end = time.mktime(time.strptime(end, + "%Y-%m-%dT%H%M%S.%f")) + + + for i_eof in eofList: + # Without extension + i_eof = i_eof.split(".EOF")[0] + + start_eofDate = i_eof.split('_')[-2] + start_eofDate = start_eofDate.split("V")[1] + end_eofDate = i_eof.split('_')[-1] + + # Save date format + time_start_eofDate = time.mktime(time.strptime(start_eofDate, + "%Y%m%dT%H%M%S")) + + time_end_eofDate = time.mktime(time.strptime(end_eofDate, + "%Y%m%dT%H%M%S")) + + + # Compare dates and return eof file if eof file contains the current image dates + if time_start >= time_start_eofDate and time_end <= time_end_eofDate : + return i_eof + ".EOF" + + + # if none of files contains wanted dates : return None + return None + + def get_relative_orbit(manifest): """ Get from manifest file, the orbit number