Skip to content

Commit

Permalink
Merge pull request #107 from FAIRmat-NFDI/processing-order
Browse files Browse the repository at this point in the history
Process yaml and json files last
  • Loading branch information
lukaspie authored Jan 14, 2025
2 parents aa65867 + d94b673 commit 51cb445
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.8.0
rev: v0.9.1
hooks:
# Run the linter.
- id: ruff
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies = [
[project.optional-dependencies]
dev = [
"mypy",
"ruff>=0.6.0",
"ruff>=0.9.0",
"pytest",
"pytest-cov",
"pytest-timeout",
Expand Down
8 changes: 7 additions & 1 deletion src/pynxtools_xps/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class XPSReader(MultiFormatReader):
)

__vndr_err_msg__ = (
"Need an XPS data file from one of the following vendors: " f"{__vendors__}"
f"Need an XPS data file from one of the following vendors: {__vendors__}"
)

def __init__(self, *args, **kwargs):
Expand All @@ -176,6 +176,12 @@ def __init__(self, *args, **kwargs):
for ext in XPSReader.__prmt_file_ext__:
self.extensions[ext] = self.handle_data_file

self.processing_order = XPSReader.__prmt_file_ext__ + [
".yml",
".yaml",
".json",
]

def set_config_file(self, file_path: str) -> Dict[str, Any]:
if self.config_file is not None:
logger.info(
Expand Down
4 changes: 2 additions & 2 deletions src/pynxtools_xps/reader_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,12 @@ def construct_data_key(spectrum: Dict[str, Any]) -> str:
"""
if "loop_no" in spectrum:
cycle_key = f'cycle{spectrum["loop_no"]}'
cycle_key = f"cycle{spectrum['loop_no']}"
else:
cycle_key = "cycle0"

if "scan_no" in spectrum:
scan_key = f'scan{spectrum["scan_no"]}'
scan_key = f"scan{spectrum['scan_no']}"
else:
scan_key = "scan0"

Expand Down
6 changes: 3 additions & 3 deletions src/pynxtools_xps/specs/sle/sle_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ def _update_xps_dict_with_spectrum(
if units is not None:
self._xps_dict[f"{root}/{mpes_key}/@units"] = units

self._xps_dict[f'{path_map["electronanalyser"]}/name'] = spectrum["devices"][0]
self._xps_dict[f'{path_map["source"]}/name'] = spectrum["devices"][1]
self._xps_dict[f"{path_map['electronanalyser']}/name"] = spectrum["devices"][0]
self._xps_dict[f"{path_map['source']}/name"] = spectrum["devices"][1]

# Create keys for writing to data
scan_key = construct_data_key(spectrum)
Expand Down Expand Up @@ -298,7 +298,7 @@ def _update_xps_dict_with_spectrum(
# TODO: fix this hotfix so that all data can be written

# Add energy axis to energy_calibration
calib_energy_key = f'{path_map["process/energy_calibration"]}/energy'
calib_energy_key = f"{path_map['process/energy_calibration']}/energy"
self._xps_dict[calib_energy_key] = energy

self._xps_dict["data"][entry][scan_key.split("_")[0]] = xr.DataArray(
Expand Down
6 changes: 2 additions & 4 deletions src/pynxtools_xps/specs/xml/xml_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,7 @@ def struct_fc_name_sc_value(self, element_, first_child, parent_path, skip_child
for unit in units:
if f"_[{unit}]" in section_nm_reslvr:
section_nm_reslvr, _ = section_nm_reslvr.split("_")
self.metadata_dict[f"{parent_path}/" f"{section_nm_reslvr}/@units"] = (
unit
)
self.metadata_dict[f"{parent_path}/{section_nm_reslvr}/@units"] = unit

parent_path, self.tail_part_frm_struct = self.check_last_part_repetition(
parent_path, self.tail_part_frm_struct, section_nm_reslvr
Expand Down Expand Up @@ -513,7 +511,7 @@ def last_element_parser(self, element_: EmtT.Element, parent_path: str) -> None:

if child_num == 0:
if "name" in elmt_attr.keys():
section_nm_reslvr = f'{elmt_attr["name"]}'
section_nm_reslvr = f"{elmt_attr['name']}"
value = self.restructure_value(element_.text, element_.tag)

parent_path, self.tail_part_frm_othr = self.check_last_part_repetition(
Expand Down
18 changes: 9 additions & 9 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,16 @@ def test_extract_unit(
):
result_value, result_unit = extract_unit(key, value, unit_missing)

assert isinstance(
result_value, type(expected_value)
), f"Expected type {type(expected_value)} but got type {type(result_value)}"
assert isinstance(result_value, type(expected_value)), (
f"Expected type {type(expected_value)} but got type {type(result_value)}"
)

assert (
result_value == expected_value
), f"Expected {expected_value} but got {result_value}"
assert (
result_unit == expected_unit
), f"Expected {expected_unit} but got {result_unit}"
assert result_value == expected_value, (
f"Expected {expected_value} but got {result_value}"
)
assert result_unit == expected_unit, (
f"Expected {expected_unit} but got {result_unit}"
)


@pytest.mark.parametrize(
Expand Down

0 comments on commit 51cb445

Please sign in to comment.