From 540c850883f1f1ef44f46e39320249aaccd13376 Mon Sep 17 00:00:00 2001 From: Rubel Date: Tue, 21 Nov 2023 21:08:14 +0100 Subject: [PATCH] ci. --- pynxtools/dataconverter/readers/sts/helper.py | 2 +- pynxtools/dataconverter/readers/sts/reader.py | 23 +++++++++---------- pynxtools/dataconverter/readers/xrd/reader.py | 9 ++++---- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/pynxtools/dataconverter/readers/sts/helper.py b/pynxtools/dataconverter/readers/sts/helper.py index 3fa8ffc20..6ad99ca8a 100644 --- a/pynxtools/dataconverter/readers/sts/helper.py +++ b/pynxtools/dataconverter/readers/sts/helper.py @@ -101,7 +101,7 @@ def overwrite_fields(template, data_dict, path_to_data = data_path[unit] unit = transform_to_intended_dt(data_dict[path_to_data] if path_to_data in data_dict else None) - template[new_temp_key + "/@units"] = + template[new_temp_key + "/@units"] = unit def nested_path_to_slash_separated_path(nested_dict: dict, diff --git a/pynxtools/dataconverter/readers/sts/reader.py b/pynxtools/dataconverter/readers/sts/reader.py index 9929c1759..e6698b834 100644 --- a/pynxtools/dataconverter/readers/sts/reader.py +++ b/pynxtools/dataconverter/readers/sts/reader.py @@ -195,32 +195,31 @@ def read(self, fl_obj: object if ext in ['sxm', 'dat']: data_file = file - if ext == 'json': - with open(file, mode="r", encoding="utf-8") as fl_obj: - config_dict = json.load(fl_obj) if ext in ['yaml', 'yml']: - with open(file, mode="r", encoding="utf-8") as fl_obj: + with open(file, encoding="utf-8", mode="r") as fl_obj: eln_dict = flatten_and_replace( FlattenSettings( yaml.safe_load(fl_obj), - CONVERT_DICT, - REPLACE_NESTED + replace_nested=REPLACE_NESTED, + convert_dict=CONVERT_DICT, ) ) + if ext == 'json': + with open(file, mode="r", encoding="utf-8") as fl_obj: + config_dict = json.load(fl_obj) # Get callable object that has parser inside parser = Spm().get_appropriate_parser(eln_dict) parser(template, data_file, config_dict, eln_dict) for key, val in template.items(): - - if val is None: - del template[key] - else: + if val is not None: filled_template[key] = val + else: + del template[key] + if not filled_template.keys(): - raise ValueError("Reader could not read anything! Check for input files and the" - " corresponding extention.") + raise ValueError("Reader could not read anything! Check for input files") return filled_template diff --git a/pynxtools/dataconverter/readers/xrd/reader.py b/pynxtools/dataconverter/readers/xrd/reader.py index c27d81963..bcc67575c 100644 --- a/pynxtools/dataconverter/readers/xrd/reader.py +++ b/pynxtools/dataconverter/readers/xrd/reader.py @@ -91,10 +91,10 @@ def get_template_from_xrd_reader(nxdl_name, file_paths): Parameters ---------- - nxdl_name : str_ + nxdl_name : str Name of nxdl definition - file_paths : str - _description_ + file_paths : Tuple[str] + Tuple of path of files. Returns ------- @@ -141,8 +141,7 @@ def read(self, eln_dict = flatten_and_replace( FlattenSettings( yaml.safe_load(fl_obj), - CONVERT_DICT, - REPLACE_NESTED + CONVERT_DICT, REPLACE_NESTED ) ) elif ext in XRD_FILE_EXTENSIONS: