Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update SLE reader to newest data version and other measurement configurations #31

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dependencies = [
"numpy>=1.21.2",
"pint>=0.17",
"pynxtools>=0.7.0",
"scipy",
]

[project.entry-points."pynxtools.reader"]
Expand Down
1 change: 1 addition & 0 deletions src/pynxtools_xps/config/config_phi.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"experiment_facility":"@eln",
"experiment_laboratory":"@eln",
"method":"@attrs:region/technique",
"method/@long_name":"@attrs:region/technique_long_name",
"program_name":"@attrs:file_info/software_version",
"acquisition_filename":"@attrs:file_info/acquisition_filename"
},
Expand Down
3 changes: 2 additions & 1 deletion src/pynxtools_xps/config/config_scienta.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"title":"@eln",
"start_time":"@attrs:time_stamp",
"end_time":"@eln",
"method":"X-ray photoelectron spectroscopy (XPS)",
"method":"XPS",
"method/@long_name":"X-ray photoelectron spectroscopy",
"experiment_institution":"@eln",
"experiment_facility":"@eln",
"experiment_laboratory":"@eln",
Expand Down
1 change: 1 addition & 0 deletions src/pynxtools_xps/config/config_specs_sle.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"duration":null,
"duration/@units":"s",
"method":"@attrs:region/analysis_method",
"method/@long_name":"@attrs:region/analysis_method_long_name",
"program_name":"@eln"
},
"/ENTRY/USER[user]":{
Expand Down
1 change: 1 addition & 0 deletions src/pynxtools_xps/config/config_specs_xml.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"experiment_laboratory":"@eln",
"entry_identifier":"@eln",
"method":"@attrs:region/analysis_method",
"method/@long_name":"@attrs:region/analysis_method_long_name",
"program_name":"@eln"
},
"/ENTRY/USER[user]":{
Expand Down
1 change: 1 addition & 0 deletions src/pynxtools_xps/config/config_specs_xy.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"start_time":"@attrs:time_stamp",
"end_time":"@eln",
"method":"@attrs:region/analysis_method",
"method/@long_name":"@attrs:region/analysis_method_long_name",
"experiment_institution":"@eln",
"experiment_facility":"@eln",
"experiment_laboratory":"@eln",
Expand Down
1 change: 1 addition & 0 deletions src/pynxtools_xps/config/config_txt_vamas_export.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"duration":"@eln",
"duration/@units":"@eln",
"method":"@eln",
"method/@long_name":"@eln:method/long_name",
"program_name":"@eln"
},
"/ENTRY/USER[user]":{
Expand Down
3 changes: 1 addition & 2 deletions src/pynxtools_xps/kratos/metadata_kratos.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,9 @@ def map_values(self, key: str, value, field_type):
Value of correct type and internal structure.

"""

if key in self.value_function_map:
map_fn = self.value_function_map[key]
if key == "date_created":
if "date" in key:
value = map_fn(value, POSSIBLE_DATE_FORMATS)
else:
value = map_fn(value)
Expand Down
30 changes: 21 additions & 9 deletions src/pynxtools_xps/reader_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def data_dict(self) -> dict:

def parse_file(self, file, **kwargs):
"""
Parse the file using the Scienta TXT parser.
Parse the file using the selected parser.

"""
self.file = file
Expand Down Expand Up @@ -116,14 +116,23 @@ def convert_snake_to_pascal(str_value: str):


def convert_pascal_to_snake(str_value: str):
"""Convert pascal case text to snake case."""
# Convert CamelCase to snake_case
snake_case = re.sub(r"(?<!^)(?=[A-Z])", "_", str_value)

# Convert whitespace to underscores and remove extra underscores
snake_case_cleaned = re.sub(r"\s+", "_", snake_case).replace("__", "_")
"""Convert PascalCase text to snake_case, preserving bracketed content."""

def replace_non_bracketed(match):
content = match.group(0)
snake_case = re.sub(r"(?<!^)(?=[A-Z])", "_", content)
return re.sub(r"\s+", "_", snake_case).replace("__", "_")

pattern = r"(\[.*?\]|[^[]+)"
parts = re.sub(
pattern,
lambda m: m.group(0)
if m.group(0).startswith("[")
else replace_non_bracketed(m),
str_value,
)

return snake_case_cleaned.lower()
return parts.lower()


def safe_arange_with_edges(start: float, stop: float, step: float):
Expand Down Expand Up @@ -488,7 +497,7 @@ def split_value_and_unit(

Parameters
----------
value : str
value_str: str
The input string to be split.

Returns
Expand Down Expand Up @@ -540,6 +549,9 @@ def extract_unit(
- If no unit is found in both `value_str` and `unit_missing`,
returns an empty string for the unit.
"""
if not value_str:
return "", ""

value, unit = split_value_and_unit(value_str)

if not unit:
Expand Down
Loading
Loading