Commit 0d2c1172 authored by payno's avatar payno
Browse files

[app][ows-to-script] add parameters update from command line option

parent 11fae07a
Pipeline #40725 passed with stages
in 6 minutes and 43 seconds
......@@ -35,7 +35,9 @@ def _convert(scheme, output_file, overwrite):
file_.write(_dump_info_generation())
workflow = Workflow.ProcessableWorkflow(scheme)
converter = Workflow.Converter(workflow=workflow, output_file=output_file)
converter = Workflow.Converter(
workflow=workflow, output_file=output_file, with_opts=True
)
converter.process()
# set up workflow
......@@ -198,6 +200,44 @@ if __name__ == '__main__':
default=None,
help="Provide scan title name to consider",
)
# handle larch settings
parser.add_argument(
"--set-autobk-params",
dest="set_autobk_params",
default=None,
help="set autobk settings",
)
parser.add_argument(
"--set-mback-params",
dest="set_mback_params",
default=None,
help="set mback settings",
)
parser.add_argument(
"--set-mback-norm-params",
dest="set_mback_norm_params",
default=None,
help="set mback norm settings",
)
parser.add_argument(
"--set-pre-edge-params",
dest="set_pre_edge_params",
default=None,
help="set pre-edge settings",
)
parser.add_argument(
"--set-xftf-params",
dest="set_xftf_params",
default=None,
help="set xftf settings",
)
# handle noise settings
parser.add_argument(
"--set-noise--params",
dest="set_noise_params",
default=None,
help="set noise settings",
)
options = parser.parse_args(sys.argv[1:])
input_information = InputInformation(
......@@ -220,7 +260,7 @@ if __name__ == '__main__':
input_information.mu_ref = get_url(options.input_mu_ref)
xas_obj = get_xas_obj(input_information)
main(input_data=xas_obj, channel="xas_obj")
main(input_data=xas_obj, channel="xas_obj", options=options)
"""
......
......@@ -31,6 +31,7 @@ __date__ = "07/08/2019"
from .progress import Progress
from est.core.types import XASObject
from ..utils import extract_properties_from_dict
import logging
from collections import namedtuple
from typing import Iterable
......@@ -334,3 +335,10 @@ class Process(object):
def addCallback(self, callback):
self._callbacks.append(callback)
def update_properties(self, properties):
if properties is None:
return
if isinstance(properties, str):
properties = extract_properties_from_dict(properties)
self._settings.update(properties)
......@@ -74,3 +74,30 @@ def DownloadDataset(dataset, output_folder, timeout, unpack=False):
if unpack is True:
shutil.unpack_archive(archive_folder, extract_dir=output_folder, format="bztar")
os.remove(archive_folder)
def extract_properties_from_dict(my_str) -> dict:
"""
Convert parameters provided from a string to a dictionary.
expected syntax is param1:value1,param2:value2
would return { param1: value1, param2: value2 }
try to cast each value to a number (float).
"""
params = {}
param_list = my_str.split(",")
failures = []
for param in param_list:
try:
param_name, param_value = param.split(":")
except Exception as e:
logger.info("Fail to cast some parameters: {}".format(e))
failures.append(param)
else:
try:
param_value = float(param_value)
except Exception:
pass
params[param_name] = param_value
if len(failures) > 0:
logger.warning("Fail to convert some parameters : {}".format(failures))
return params
settings_updater = {
# larch processing
"est.core.process.larch.autobk.Larch_autobk": "set_autobk_params",
"est.core.process.larch.mback.Larch_mback": "set_mback_params",
"est.core.process.larch.mback_norm.Larch_mback_norm": "set_mback_norm_params",
"est.core.process.larch.pre_edge.Larch_pre_edge": "set_pre_edge_params",
"est.core.process.larch.xftf.Larch_xftf": "set_xftf_params",
# utils
"est.core.process.noise.NoiseProcess": "set_noise_params",
}
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