Skip to content
Snippets Groups Projects
Commit 6db3382e authored by Gaëlle USSEGLIO's avatar Gaëlle USSEGLIO
Browse files

UPDATE : add python Diapason chain and environment scripts

parent b699bfe2
No related branches found
No related tags found
No related merge requests found
/build/*
/scripts/diapOTBEnv.sh
/data/*.omd
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = "POC-THALES"
__version__ = "0.1"
__status__ = "Developpement"
__date__ = "27/10/2017"
__last_modified__ = "27/10/2017"
# Imports
import logging
import ConfigParser
import os
import argparse
import otbApplication as otb
logger = logging.getLogger(__name__)
# ConfigParser functions
# Get a map of sections
def ConfigSectionMap(config, section):
dict1 = {}
options = config.options(section)
for option in options:
try:
dict1[option] = config.get(section, option)
if dict1[option] == -1:
DebugPrint("skip: %s" % option)
except:
print("exception on %s!" % option)
dict1[option] = None
return dict1
# Check the configuration file
def ConfigCheck(config):
configOk = True
# List for configuration
listOfSections = ["Global", "MultiLook", "Doppler0"]
globalList = ["Master_Image_Path", "Slave_Image_Path", "output_dir"]
MLList = ["range", "azimut", "gain"]
Doppler0List = ["doppler_file"]
dictOfSections = {'Global': globalList, 'MultiLook': MLList, 'Doppler0' : Doppler0List}
# For each elt of listOfSections
for section in listOfSections :
# Check if section exists into config
if config.has_section(section) :
# For each elt of lists of dictOfSections
for option in dictOfSections[section] :
# Check if option exists into section of config
if not config.has_option(section, option) :
print option + " is missing for the section " + section + " of the configuration file"
configOk = False
else :
print section + " is missing into the configuration file"
configOk = False
return configOk
# Main
if __name__ == "__main__":
# Check arguments
parser = argparse.ArgumentParser()
parser.add_argument("configfile", help="input conguration file for the application DiapOTB")
args = parser.parse_args()
print args.configfile
# Read the configuration file
Config = ConfigParser.ConfigParser()
Config.read(args.configfile)
configOk = ConfigCheck(Config)
# If some values are missing, quit the application
if not configOk :
quit()
# Get elements from configuration file
master_Image = ConfigSectionMap(Config, "Global")['master_image_path']
slave_Image = ConfigSectionMap(Config, "Global")['slave_image_path']
output_dir = ConfigSectionMap(Config, "Global")['output_dir']
ml_range = int(ConfigSectionMap(Config, "MultiLook")['range'])
ml_azimut = int(ConfigSectionMap(Config, "MultiLook")['azimut'])
ml_gain = float(ConfigSectionMap(Config, "MultiLook")['gain'])
dop_file = ConfigSectionMap(Config, "Doppler0")['doppler_file']
# Check if images exist
if not os.path.exists(master_Image) :
print master_Image + " does not exists"
quit()
if not os.path.exists(slave_Image) :
print slave_Image + " does not exists"
quit()
if not os.path.exists(output_dir):
print "The output directory does not exist and will be created"
os.makedirs(output_dir)
else :
print "The output directory exists. Some files can be overwritten"
master_Image_base = os.path.basename(master_Image)
slave_Image_base = os.path.basename(slave_Image)
####################### Doppler Application ##########################
# Master
dopFile = open(os.path.join(output_dir, dop_file), "w")
dopFile.write("Doppler for master image : " + os.path.basename(master_Image_base)+ "\n")
dopFile.close()
appDoppler0Master = otb.Registry.CreateApplication("SARDoppler0")
appDoppler0Master.SetParameterString("in", master_Image)
appDoppler0Master.SetParameterString("outfile", os.path.join(output_dir, dop_file))
appDoppler0Master.SetParameterInt("ram", 4000)
appDoppler0Master.ExecuteAndWriteOutput()
# Slave
dopFile = open(os.path.join(output_dir, dop_file), "a")
dopFile.write("Doppler for slave image : " + os.path.basename(slave_Image_base) + "\n")
dopFile.close()
appDoppler0Slave = otb.Registry.CreateApplication("SARDoppler0")
appDoppler0Slave.SetParameterString("in", slave_Image)
appDoppler0Slave.SetParameterString("outfile", os.path.join(output_dir, dop_file))
appDoppler0Master.SetParameterInt("ram", 4000)
appDoppler0Slave.ExecuteAndWriteOutput()
###################### MultiLook Application #########################
# Master
master_Image_ML = os.path.splitext(master_Image_base)[0] + "_ml.tif"
appMultiLookMaster = otb.Registry.CreateApplication("SARMultiLook")
appMultiLookMaster.SetParameterString("in", master_Image)
appMultiLookMaster.SetParameterString("out", os.path.join(output_dir, master_Image_ML))
appMultiLookMaster.SetParameterInt("mlran",ml_range)
appMultiLookMaster.SetParameterInt("mlazi",ml_azimut)
appMultiLookMaster.SetParameterFloat("mlgain", ml_gain)
appDoppler0Master.SetParameterInt("ram", 4000)
appMultiLookMaster.ExecuteAndWriteOutput()
# Slave
slave_Image_ML = os.path.splitext(slave_Image_base)[0] + "_ml.tif"
appMultiLookSlave = otb.Registry.CreateApplication("SARMultiLook")
appMultiLookSlave.SetParameterString("in", slave_Image)
appMultiLookSlave.SetParameterString("out", os.path.join(output_dir, slave_Image_ML))
appMultiLookSlave.SetParameterInt("mlran",ml_range)
appMultiLookSlave.SetParameterInt("mlazi",ml_azimut)
appMultiLookSlave.SetParameterFloat("mlgain", ml_gain)
appDoppler0Master.SetParameterInt("ram", 4000)
appMultiLookSlave.ExecuteAndWriteOutput()
[Global]
Master_Image_Path = image_1.tif
Slave_Image_Path = image_2.tif
output_dir = ./output_diapOTB
[MultiLook]
range = 3
azimut = 3
gain = 0.1
[Doppler0]
doppler_file = dop0.txt
#!/bin/bash
# Directory of teh current script
dir_script=$(dirname $0)
# Subtitute the varaible install_directory with the argument
sed 's@${install_directory}@'"$1"'@' $dir_script/template_diapOTBEnv.sh > $dir_script/diapOTBEnv.sh
#!/bin/bash
export OTB_APPLICATION_PATH=${install_directory}/lib:$OTB_APPLICATION_PATH
export LD_LIBRARY_PATH=${install_directory}/lib/:$LD_LIBRARY_PATH
export PYTHONPATH=${install_directory}/python_src/:$PYTHONPATH
export DIAPOTB_INSTALL=${install_directory}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment