Commit 864fec3d authored by Aurore Dupuis's avatar Aurore Dupuis
Browse files

Merge branch '90-error-management-improvement' into 'develop'

Resolve "Error management improvement"

Closes #90

See merge request !94
parents 70d625bc 9f58687f
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
......@@ -26,50 +26,13 @@ import json
from logging.handlers import RotatingFileHandler
from s2snow.fsc_config import FscConfig, LisConfigurationException, UnknownProductException
from s2snow.lis_constant import INPUT_PARAMETER_ERROR, UNKNOWN_PRODUCT_EXCEPTION, CONFIGURATION_ERROR, TMP_DIR, LOG_FILE
from s2snow.lis_constant import INPUT_PARAMETER_ERROR, UNKNOWN_PRODUCT_EXCEPTION, CONFIGURATION_ERROR, TMP_DIR, \
LOG_FILE, OUTPUT_UNDEFINED
from s2snow.parser import create_fsc_argument_parser
from s2snow.snow_detector import detect_snow
def main(config_file, input_dir, output_dir, dem, tcd, water_mask, h2_chain_version=None, product_counter=None):
# Check configuration file
if not os.path.exists(config_file):
logging.error("Configuration file does not exist.")
return INPUT_PARAMETER_ERROR
# Load json_file from json files
with open(config_file) as json_data_file:
data = json.load(json_data_file)
logging.info("Reading configuration = " + config_file)
try:
config = FscConfig(data, input_dir, dem, tcd, water_mask)
except LisConfigurationException:
return CONFIGURATION_ERROR
except UnknownProductException:
return UNKNOWN_PRODUCT_EXCEPTION
except IOError:
return INPUT_PARAMETER_ERROR
if not os.path.exists(output_dir):
logging.warning("Output directory product does not exist.")
logging.info("Create directory " + output_dir + "...")
os.makedirs(output_dir)
# Run the snow detector
try:
logging.info("Launch snow detection.")
detect_snow(config, output_dir, h2_chain_version, product_counter)
except Exception as e:
logging.error(e)
return -1
return 0
if __name__ == "__main__":
args_parser = create_fsc_argument_parser()
args = args_parser.parse_args(sys.argv[1:])
def main(args):
if args.json_config_file is not None:
with open(args.json_config_file) as json_config_file:
global_config = json.load(json_config_file)
......@@ -97,12 +60,12 @@ if __name__ == "__main__":
output_dir = args.output_dir
if output_dir is None:
raise LisConfigurationException("Output directory is not defined.")
sys.exit(OUTPUT_UNDEFINED)
if not os.path.exists(output_dir):
os.makedirs(output_dir)
# Create tmp dir
# Create tmp dir
os.makedirs(output_dir + "/" + TMP_DIR, exist_ok=True)
tmp_dir = os.path.join(output_dir, TMP_DIR)
log_file = os.path.join(tmp_dir, LOG_FILE)
......@@ -112,7 +75,7 @@ if __name__ == "__main__":
if args.log_level is not None:
log_level = args.log_level
if log_level is None:
log_level="INFO"
log_level = "INFO"
level = logging.getLevelName(log_level)
logger.setLevel(level)
......@@ -157,4 +120,46 @@ if __name__ == "__main__":
logging.info("product counter: %s", args.product_counter)
product_counter = args.product_counter
main(config_file, input_dir, output_dir, dem, tcd, water_mask, h2_chain_version, product_counter)
let_it_snow_fsc(config_file, input_dir, output_dir, dem, tcd, water_mask, h2_chain_version, product_counter)
def let_it_snow_fsc(config_file, input_dir, output_dir, dem, tcd, water_mask, h2_chain_version=None,
product_counter=None):
# Check configuration file
if not os.path.exists(config_file):
logging.error("Configuration file does not exist.")
sys.exit(INPUT_PARAMETER_ERROR)
# Load json_file from json files
with open(config_file) as json_data_file:
data = json.load(json_data_file)
logging.info("Reading configuration = " + config_file)
try:
config = FscConfig(data, input_dir, dem, tcd, water_mask)
except LisConfigurationException:
sys.exit(CONFIGURATION_ERROR)
except UnknownProductException:
sys.exit(UNKNOWN_PRODUCT_EXCEPTION)
except IOError:
sys.exit(INPUT_PARAMETER_ERROR)
if not os.path.exists(output_dir):
logging.warning("Output directory product does not exist.")
logging.info("Create directory " + output_dir + "...")
os.makedirs(output_dir)
# Run the snow detector
try:
logging.info("Launch snow detection.")
detect_snow(config, output_dir, h2_chain_version, product_counter)
except Exception as e:
logging.error(e)
sys.exit(1)
sys.exit(0)
if __name__ == "__main__":
args_parser = create_fsc_argument_parser()
args = args_parser.parse_args(sys.argv[1:])
main(args)
......@@ -30,58 +30,11 @@ from s2snow.lis_exception import LisConfigurationException, NoSnowProductFound,
from s2snow.snow_synthesis import compute_snow_synthesis
from s2snow.synthesis_config import SynthesisConfig
from s2snow.lis_constant import INPUT_PARAMETER_ERROR, CONFIGURATION_ERROR, TMP_DIR, LOG_FILE, NO_SNOW_PRODUCT_FOUND, \
NO_ZIP_FOUND, NO_PRODUCT_MATCHING_SYNTHESIS, UNKNOWN_PLATFORM
NO_ZIP_FOUND, NO_PRODUCT_MATCHING_SYNTHESIS, UNKNOWN_PLATFORM, OUTPUT_UNDEFINED
from s2snow.parser import create_synthesis_argument_parser
def main(config_file, tile_id, input_products_list, densification_products_list, output_dir, date_start, date_stop, date_margin,
h2_chain_version=None, product_counter=None):
# Check configuration file
if not os.path.exists(config_file):
logging.error("Configuration file does not exist.")
return INPUT_PARAMETER_ERROR
# Load json_file from json files
with open(config_file) as json_data_file:
data = json.load(json_data_file)
logging.info("Reading configuration = " + config_file)
try:
config = SynthesisConfig(data, tile_id, input_products_list, date_start, date_stop, date_margin=date_margin,
densification_products_list=densification_products_list)
except LisConfigurationException:
return CONFIGURATION_ERROR
except IOError:
return INPUT_PARAMETER_ERROR
# Run the snow detector
try:
logging.info("Launch snow synthesis computation.")
compute_snow_synthesis(config, output_dir, h2_chain_version, product_counter)
except UnknownPlatform as e:
logging.error(e)
return UNKNOWN_PLATFORM
except NoProductMatchingSynthesis as e:
logging.error(e)
return NO_PRODUCT_MATCHING_SYNTHESIS
except NoSnowProductFound as e:
logging.error(e)
return NO_SNOW_PRODUCT_FOUND
except NoZipFound as e:
logging.error(e)
return NO_ZIP_FOUND
except Exception as e:
logging.error(e)
return -1
return 0
if __name__ == "__main__":
args_parser = create_synthesis_argument_parser()
args = args_parser.parse_args(sys.argv[1:])
def main(args):
if args.json_config_file is not None:
with open(args.json_config_file) as json_config_file:
global_config = json.load(json_config_file)
......@@ -99,7 +52,7 @@ if __name__ == "__main__":
else:
tile_id = None
input_products_list = None
densification_products_list= None
densification_products_list = None
output_dir = None
config_file = None
date_start = None
......@@ -113,7 +66,7 @@ if __name__ == "__main__":
output_dir = args.output_dir
if output_dir is None:
raise LisConfigurationException("Output directory is not defined.")
sys.exit(OUTPUT_UNDEFINED)
if not os.path.exists(output_dir):
os.makedirs(output_dir)
......@@ -135,8 +88,9 @@ if __name__ == "__main__":
# file handler
file_handler = RotatingFileHandler(log_file, 'a', 1000000, 1)
formatter = logging.Formatter(fmt='%(asctime)s.%(msecs)03d %(levelname)s:%(filename)s:line=%(lineno)s:%(funcName)s:%(message)s',
datefmt='%Y-%m-%dT%H:%M:%S')
formatter = logging.Formatter(
fmt='%(asctime)s.%(msecs)03d %(levelname)s:%(filename)s:line=%(lineno)s:%(funcName)s:%(message)s',
datefmt='%Y-%m-%dT%H:%M:%S')
file_handler.setLevel(level)
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)
......@@ -148,7 +102,6 @@ if __name__ == "__main__":
logger.addHandler(stream_handler)
logging.debug("Debug level activated.")
logging.info("output directory : %s", output_dir)
if args.tile_id is not None:
......@@ -179,4 +132,54 @@ if __name__ == "__main__":
logging.info("product counter: %s", args.product_counter)
product_counter = args.product_counter
main(config_file, tile_id, input_products_list, densification_products_list, output_dir, date_start, date_stop, date_margin, h2_chain_version, product_counter)
let_it_snow_synthesis(config_file, tile_id, input_products_list, densification_products_list, output_dir,
date_start, date_stop, date_margin, h2_chain_version, product_counter)
def let_it_snow_synthesis(config_file, tile_id, input_products_list, densification_products_list, output_dir,
date_start, date_stop, date_margin,
h2_chain_version=None, product_counter=None):
# Check configuration file
if not os.path.exists(config_file):
logging.error("Configuration file does not exist.")
sys.exit(INPUT_PARAMETER_ERROR)
# Load json_file from json files
with open(config_file) as json_data_file:
data = json.load(json_data_file)
logging.info("Reading configuration = " + config_file)
try:
config = SynthesisConfig(data, tile_id, input_products_list, date_start, date_stop, date_margin=date_margin,
densification_products_list=densification_products_list)
except LisConfigurationException:
sys.exit(CONFIGURATION_ERROR)
except IOError:
sys.exit(INPUT_PARAMETER_ERROR)
# Run the snow detector
try:
logging.info("Launch snow synthesis computation.")
compute_snow_synthesis(config, output_dir, h2_chain_version, product_counter)
except UnknownPlatform as e:
logging.error(e)
sys.exit(UNKNOWN_PLATFORM)
except NoProductMatchingSynthesis as e:
logging.error(e)
sys.exit(NO_PRODUCT_MATCHING_SYNTHESIS)
except NoSnowProductFound as e:
logging.error(e)
sys.exit(NO_SNOW_PRODUCT_FOUND)
except NoZipFound as e:
logging.error(e)
sys.exit(NO_ZIP_FOUND)
except Exception as e:
logging.error(e)
sys.exit(-1)
sys.exit(0)
if __name__ == "__main__":
args_parser = create_synthesis_argument_parser()
args = args_parser.parse_args(sys.argv[1:])
main(args)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment