Skip to content
Snippets Groups Projects
Commit 5748fa1e authored by Aurore Dupuis's avatar Aurore Dupuis
Browse files

Merge branch '100-configuration-in-output' into 'develop'

Resolve "Add configuration file in the outpout directory"

Closes #100

See merge request !96
parents 115bff35 7dc8de24
No related branches found
No related tags found
1 merge request!96Resolve "Add configuration file in the outpout directory"
......@@ -136,6 +136,9 @@ def let_it_snow_fsc(config_file, input_dir, output_dir, dem, tcd, water_mask, h2
logging.info("Reading configuration = " + config_file)
try:
config = FscConfig(data, input_dir, dem, tcd, water_mask)
config.dump_configuration(output_dir, config_file, input_dir,
logging.getLevelName(logging.getLogger().getEffectiveLevel()), h2_chain_version,
product_counter)
except LisConfigurationException:
sys.exit(CONFIGURATION_ERROR)
except UnknownProductException:
......
......@@ -151,6 +151,9 @@ def let_it_snow_synthesis(config_file, tile_id, input_products_list, densificati
try:
config = SynthesisConfig(data, tile_id, input_products_list, date_start, date_stop, date_margin=date_margin,
densification_products_list=densification_products_list)
config.dump_configuration(output_dir, config_file,
logging.getLevelName(logging.getLogger().getEffectiveLevel()), h2_chain_version,
product_counter)
except LisConfigurationException:
sys.exit(CONFIGURATION_ERROR)
except IOError:
......
......@@ -19,6 +19,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
import json
import logging
import os
import zipfile
......@@ -560,6 +561,22 @@ class FscConfig:
logging.debug("fscOg_Eq : " + str(self.fscOg_Eq))
logging.debug("fscToc_Eq : " + str(self.fscToc_Eq))
def dump_configuration(self, dump_path, config_file, input_dir, log, chain_version, product_counter):
# Get the fields as a dictionary
conf_keys = ["dem", "tcd", "water_mask"]
key_translation = {"tcd": "tcd_file", "water_mask": "water_mask_path"}
full_data = vars(self)
data = {key: full_data[key_translation.get(key, key)] for key in conf_keys}
data["output_dir"] = dump_path
data["input_dir"] = input_dir
data["log"] = log
data["config_file"] = config_file
data["chain_version"] = chain_version
data["product_counter"] = product_counter
file_path = os.path.join(dump_path, 'fsc_config.json')
with open(file_path, 'w', encoding='utf-8') as f:
json.dump(data, f, ensure_ascii=False, indent=4)
def retrieve_mission(self, absoluteFilename):
mission_key = None
if '.SAFE' in absoluteFilename:
......
......@@ -19,11 +19,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
import json
import logging
import os
from datetime import datetime
from datetime import timedelta
from s2snow.lis_exception import LisConfigurationException
from s2snow.utils import JSONCustomEncoder
class SynthesisConfig:
......@@ -90,3 +93,18 @@ class SynthesisConfig:
logging.debug("output_dates_filename : " + str(self.output_dates_filename))
logging.debug("nb_threads : " + str(self.nb_threads))
logging.debug("ram : " + str(self.ram))
def dump_configuration(self, dump_path, config_file, log_level, chain_version, product_counter):
# Get the fields as a dictionary
conf_keys = ["tile_id", "input_products_list", "date_start", "date_stop", "date_margin",
"densification_products_list"]
full_data = vars(self)
data = {key: full_data[key] for key in conf_keys}
data["output_dir"] = dump_path
data["config_file"] = config_file
data["log_level"] = log_level
data["chain_version"] = chain_version
data["product_counter"] = product_counter
file_path = os.path.join(dump_path, 'synthesis_config.json')
with open(file_path, 'w', encoding='utf-8') as f:
json.dump(data, f, cls=JSONCustomEncoder, ensure_ascii=False, indent=4)
......@@ -21,12 +21,14 @@
#
import glob
import json
import logging
import os
import os.path as op
import subprocess
import uuid
from datetime import datetime
from datetime import timedelta
from distutils import spawn
import numpy as np
......@@ -227,3 +229,12 @@ def compute_percent(image_path, value, no_data=-10000):
return (float(count_pix) / float(tot_pix)) * 100
else:
return 0
class JSONCustomEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, datetime):
return datetime_to_str(o)
elif isinstance(o, timedelta):
return o.days
return super().default(o)
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