diff --git a/app/run_snow_annual_map.py b/app/run_snow_annual_map.py index 841efd90ca70d8460a6d86e0772fe505344a97f1..12195b4a247ff93089807ff2d6f0a458ae7f0201 100644 --- a/app/run_snow_annual_map.py +++ b/app/run_snow_annual_map.py @@ -56,34 +56,42 @@ def main(argv): """ main script of snow extraction procedure""" json_file = argv[1] - # Set logging level and format. - logging.basicConfig(stream=sys.stdout, level=logging.INFO, \ - format='%(asctime)s - %(filename)s:%(lineno)s - %(levelname)s - %(message)s') - logging.info("Start run_snow_annual_map.py") - logging.info("Input args = {}".format(json_file)) - - logging.info("Load parameters") # ---------------------------------------------------------------------------------------- # Set parameters # ---------------------------------------------------------------------------------------- with open(json_file) as json_data_file: params = json.load(json_data_file) + output_dir = params.get("path_out") + if not os.path.exists(output_dir): + logging.info("Create directory {} ...".format(output_dir)) + os.makedirs(output_dir) + + log = params.get("log", True) + stdout_file = op.join(output_dir, "stdout.log") + stderr_file = op.join(output_dir, "stderr.log") + if log: + sys.stdout = open(params.get("log_stdout", stdout_file), 'w') + sys.stderr = open(params.get("log_stderr", stderr_file), 'w') + + # Set logging level and format. mode = params.get("mode", "RUNTIME") if mode == "DEBUG": logging.basicConfig(stream=sys.stdout, level=logging.DEBUG, \ format='%(asctime)s - %(filename)s:%(lineno)s - %(levelname)s - %(message)s') logging.debug("Debug is enabled") + else: + logging.basicConfig(stream=sys.stdout, level=logging.INFO, \ + format='%(asctime)s - %(filename)s:%(lineno)s - %(levelname)s - %(message)s') + + logging.info("Start run_snow_annual_map.py") + logging.info("Input args = {}".format(json_file)) tile_id = params.get("tile_id") date_start = str_to_datetime(params.get("date_start"), "%d/%m/%Y") date_stop = str_to_datetime(params.get("date_stop"), "%d/%m/%Y") date_margin = timedelta(days=params.get("date_margin", 0)) logging.debug("Date margin: {}".format(date_margin)) - output_dir = params.get("path_out") - if not os.path.exists(output_dir): - logging.info("Create directory {} ...".format(output_dir)) - os.makedirs(output_dir) processing_id = str(tile_id + "_" + datetime_to_str(date_start) + "_" + datetime_to_str(date_stop)) path_out = op.join(output_dir, processing_id) @@ -116,10 +124,6 @@ def main(argv): densification_path_list = [] - log = params.get("log", True) - if log: - sys.stdout = open(params.get("log_stdout", op.join(path_out, "stdout.log")), 'w') - sys.stderr = open(params.get("log_stderr", op.join(path_out, "stderr.log")), 'w') # ---------------------------------------------------------------------------------------- # Search snow products @@ -214,6 +218,9 @@ def main(argv): shutil.copy2(nobs_output_file, path_out) shutil.copy2(smod_file, path_out) shutil.copy2(sod_file, path_out) + if log: + shutil.copy2(stdout_file, path_out) + shutil.copy2(stderr_file, path_out) os.remove(input_dates_file_path) os.remove(output_dates_file_path) @@ -224,6 +231,9 @@ def main(argv): os.remove(nobs_output_file) os.remove(smod_file) os.remove(sod_file) + if log: + os.remove(stdout_file) + os.remove(stderr_file) logging.info("End run_snow_annual_map.py") diff --git a/python/s2snow/version.py b/python/s2snow/version.py index b88c6a67ac958388d617041c2d9e42e7d0491385..0d2111f59cfb9ee5e87975dc58fefa4052fd51dd 100644 --- a/python/s2snow/version.py +++ b/python/s2snow/version.py @@ -20,4 +20,4 @@ # limitations under the License. # -VERSION = "1.6.3" +VERSION = "1.6.5"