Skip to content

Commit

Permalink
fix unit.
Browse files Browse the repository at this point in the history
  • Loading branch information
RubelMozumder committed Nov 30, 2023
1 parent 02982d6 commit c76305f
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion pynxtools/dataconverter/readers/xrd/xrd_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ def get_a_value_or_warn(return_value="",
return return_value


def check_unit(unit: str):
"""Handle conflicted unit.
Some units comes with verdor file that do not follow correct format.
"""
if unit is None:
return unit
unit_map = {'Angstrom': 'angstrom',
}
correct_unit = unit_map.get(unit, None)
if correct_unit is None:
return unit
return correct_unit


# pylint: disable=too-many-statements
def feed_xrdml_to_template(template, xrd_dict, eln_dict, file_term, config_dict=None):
"""Fill template with data from xrdml type file.
Expand Down Expand Up @@ -91,11 +105,15 @@ def fill_template_from_config_data(config_dict: dict, template: Template,
# the field does not have any value
if not raw_data_des.get('value', None):
continue
# Note: path is the data path in raw file
for val_atr_key, path in raw_data_des.items():
# data or field val
if val_atr_key == 'value':
template[nx_key] = xrd_dict.get(path, None)
# attr e.g. @units
elif path and val_atr_key == '@units':
template[nx_key + '/' + val_atr_key] = check_unit(
xrd_dict.get(path, None))
# attr e.g. @AXISNAME
elif path and val_atr_key.startswith('@'):
template[nx_key + '/' + val_atr_key] = xrd_dict.get(path, None)
if not isinstance(val, dict) and isinstance(val, str):
Expand Down

0 comments on commit c76305f

Please sign in to comment.