From e67380cbc45042cf99437202914d66f184aeff91 Mon Sep 17 00:00:00 2001 From: Rubel Date: Fri, 1 Dec 2023 13:27:24 +0100 Subject: [PATCH] Fixing error mentioned by sandor. --- pynxtools/dataconverter/helpers.py | 8 ++++++-- pynxtools/dataconverter/readers/xrd/config.py | 2 +- pynxtools/dataconverter/readers/xrd/xrd_helper.py | 2 +- pynxtools/definitions | 2 +- tests/dataconverter/test_helpers.py | 1 + 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/pynxtools/dataconverter/helpers.py b/pynxtools/dataconverter/helpers.py index 0778bcf8b..821dd6306 100644 --- a/pynxtools/dataconverter/helpers.py +++ b/pynxtools/dataconverter/helpers.py @@ -652,7 +652,7 @@ def extract_atom_types(formula, mode='hill'): return atom_types - +# pylint: disable=too-many-branches def transform_to_intended_dt(str_value: Any) -> Optional[Any]: """Transform string to the intended data type, if not then return str_value. @@ -702,7 +702,11 @@ def transform_to_intended_dt(str_value: Any) -> Optional[Any]: parts = str_value.split(sym) modified_parts = [] for part in parts: - modified_parts.append(transform_to_intended_dt(part)) + part = transform_to_intended_dt(part) + if (isinstance(part, int) or isinstance(part, float)): + modified_parts.append(part) + else: + return str_value return transform_to_intended_dt(modified_parts) return str_value diff --git a/pynxtools/dataconverter/readers/xrd/config.py b/pynxtools/dataconverter/readers/xrd/config.py index fc5513419..9c48120af 100644 --- a/pynxtools/dataconverter/readers/xrd/config.py +++ b/pynxtools/dataconverter/readers/xrd/config.py @@ -85,7 +85,7 @@ "@units": ""} }, "/ENTRY[entry]/INSTRUMENT[instrument]/SOURCE[source]/xray_tube_current": {"xrdml_1.5": {"value": "/xrdMeasurements/xrdMeasurement/incidentBeamPath/xRayTube/current", - "@units": ""} + "@units": "/xrdMeasurements/xrdMeasurement/incidentBeamPath/xRayTube/current/unit"} }, "/ENTRY[entry]/INSTRUMENT[instrument]/SOURCE[source]/source_peak_wavelength": {"xrdml_1.5": {"value": "", "@units": ""} diff --git a/pynxtools/dataconverter/readers/xrd/xrd_helper.py b/pynxtools/dataconverter/readers/xrd/xrd_helper.py index f5bfaaf1a..40874be50 100644 --- a/pynxtools/dataconverter/readers/xrd/xrd_helper.py +++ b/pynxtools/dataconverter/readers/xrd/xrd_helper.py @@ -42,7 +42,7 @@ def check_unit(unit: str): """ if unit is None: return unit - unit_map = {'Angstrom': 'angstrom', + unit_map = {'Angstrom': '\u212B', } correct_unit = unit_map.get(unit, None) if correct_unit is None: diff --git a/pynxtools/definitions b/pynxtools/definitions index f82576cdf..30ee95fdc 160000 --- a/pynxtools/definitions +++ b/pynxtools/definitions @@ -1 +1 @@ -Subproject commit f82576cdf6a9b313b5eeb569dd4f168a7b8cd0fa +Subproject commit 30ee95fdc641177e99ea566dc9c2323a9da3a710 diff --git a/tests/dataconverter/test_helpers.py b/tests/dataconverter/test_helpers.py index fa4e13e40..48be2c1e4 100644 --- a/tests/dataconverter/test_helpers.py +++ b/tests/dataconverter/test_helpers.py @@ -87,6 +87,7 @@ def listify_template(data_dict: Template): ('test', 'test'), (['59', '3.00005', '498E-36'], np.array([59.0, 3.00005, 4.98e-34])), ('23 34 444 5000', np.array([23., 34., 444., 5000.])), + ('xrd experiment','xrd experiment'), (None, None), ]) def test_transform_to_intended_dt(input_data, expected_output):