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

Vamas sub-reader: enhance data extraction, add IRREGULAR parsing #10

Merged
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
e281e8c
add writing of CPS data to vms reader
lukaspie Feb 20, 2024
a23f8fe
make vms comments a list
lukaspie Feb 26, 2024
82c3cd2
change default value of casa comments
lukaspie Feb 26, 2024
319569d
Merge branch 'main' into 9-xps-vamas-sub-reader-add-regular-parsing-e…
lukaspie Feb 26, 2024
11b304b
Merge branch 'main' into 9-xps-vamas-sub-reader-add-regular-parsing-e…
lukaspie Mar 5, 2024
c7834b7
change notation in mapper output
lukaspie Mar 6, 2024
2cb268b
use XPS dataclass template
lukaspie Mar 6, 2024
f64127b
add data model for CasaXPS peak fitting
lukaspie Mar 6, 2024
785c82a
parsing of units and casa processing
lukaspie Mar 6, 2024
49a590d
fix casa data model
lukaspie Mar 6, 2024
a16fcb1
add handling of Casa header
lukaspie Mar 6, 2024
1ebfd68
add parsing of header comments
lukaspie Mar 7, 2024
2ebd168
enable parsing of irregular vms files
lukaspie Mar 8, 2024
8d4e029
improve static typing
lukaspie Mar 8, 2024
3bc72a9
small fix to irregular parsing
lukaspie Mar 8, 2024
e1cbf32
remove unneeded comments
lukaspie Mar 8, 2024
9c3b7db
fix static typing
lukaspie Mar 14, 2024
af4cfe2
add vms test data
lukaspie Mar 15, 2024
15002a0
add regular and irregular vms test data
lukaspie Mar 15, 2024
acf6581
reset test_reader
lukaspie Mar 15, 2024
3ac7f2a
make units top-level constant
lukaspie Mar 15, 2024
9f28b4c
add writing of CPS data to vms reader
lukaspie Feb 20, 2024
9c13c4c
make vms comments a list
lukaspie Feb 26, 2024
7337615
change default value of casa comments
lukaspie Feb 26, 2024
4066cd6
change notation in mapper output
lukaspie Mar 6, 2024
99b8182
use XPS dataclass template
lukaspie Mar 6, 2024
8cc9154
add data model for CasaXPS peak fitting
lukaspie Mar 6, 2024
e058dc6
parsing of units and casa processing
lukaspie Mar 6, 2024
138ea71
fix casa data model
lukaspie Mar 6, 2024
5d7ddd7
add handling of Casa header
lukaspie Mar 6, 2024
3b1fe5b
add parsing of header comments
lukaspie Mar 7, 2024
4dc9413
enable parsing of irregular vms files
lukaspie Mar 8, 2024
2cb9dc9
improve static typing
lukaspie Mar 8, 2024
dc153d5
small fix to irregular parsing
lukaspie Mar 8, 2024
1d2559a
remove unneeded comments
lukaspie Mar 8, 2024
3380ad4
fix static typing
lukaspie Mar 14, 2024
2d825f0
rebase to main
lukaspie Mar 15, 2024
dc578b0
add regular and irregular vms test data
lukaspie Mar 15, 2024
142bd77
reset test_reader
lukaspie Mar 15, 2024
4c26b37
make units top-level constant
lukaspie Mar 15, 2024
07d25d0
avoid unneeded double checking for existence of keyword
lukaspie Mar 15, 2024
eb363e6
avoid unneeded double checking for existence of keyword
lukaspie Mar 15, 2024
105b18e
typo fix in config file
lukaspie Mar 15, 2024
2728461
change some static typing
lukaspie Mar 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pynxtools_xps/config/config_vms.json
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,4 @@
"@energy_indices":"None",
"@energy_depends":"None"
}
}
}
52 changes: 48 additions & 4 deletions pynxtools_xps/reader_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,44 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
import re
from abc import ABC, abstractmethod
from typing import Any, Dict, List, Union
from pathlib import Path
from scipy.interpolate import interp1d
import numpy as np

from dataclasses import dataclass


@dataclass
class XpsDataclass:
"""Generic class to hold a data model and a type validation method."""

def validate_types(self):
ret = True
for field_name, field_def in self.__dataclass_fields__.items():
actual_type = type(getattr(self, field_name))
if actual_type != field_def.type:
print(f"\t{field_name}: '{actual_type}' instead of '{field_def.type}'")
ret = False
return ret

def __post_init__(self):
if not self.validate_types():
raise ValueError("Wrong types")

def dict(self):
return self.__dict__.copy()


class XPSMapper(ABC):
"""Abstract base class from mapping from a parser to NXmpes template"""

def __init__(self):
self.file = None
self.raw_data: list = []
self._xps_dict: dict = {}
self.file: Union[str, Path] = ""
self.raw_data: List[str] = []
self._xps_dict: Dict[str, Any] = {}
self._root_path = "/ENTRY[entry]"

self.parser = None
Expand Down Expand Up @@ -77,6 +103,24 @@ def construct_data(self):
"""


def to_snake_case(str_value):
"""Convert a string to snake_case."""
if " " in str_value:
return "_".join(word.lower() for word in str_value.split())
return convert_pascal_to_snake(str_value)


def convert_pascal_to_snake(str_value):
"""Convert pascal case text to snake case."""
pattern = re.compile(r"(?<!^)(?=[A-Z])")
return pattern.sub("_", str_value).lower()


def convert_snake_to_pascal(str_value):
"""Convert snakecase text to pascal case."""
return str_value.replace("_", " ").title().replace(" ", "")


def safe_arange_with_edges(start, stop, step):
"""
In order to avoid float point errors in the division by step.
Expand All @@ -102,7 +146,7 @@ def safe_arange_with_edges(start, stop, step):

def check_uniform_step_width(lst):
"""
Check to see if a non-uniform step width is used in an lst
Check to see if a non-uniform step width is used in an list.

Parameters
----------
Expand Down
4 changes: 2 additions & 2 deletions pynxtools_xps/sle/sle_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ def _update_xps_dict_with_spectrum(self, spectrum, key_map):

"""
# pylint: disable=too-many-locals,duplicate-code
group_parent = f'{self._root_path}/RegionGroup_{spectrum["group_name"]}'
region_parent = f'{group_parent}/regions/RegionData_{spectrum["spectrum_type"]}'
group_parent = f'{self._root_path}/Group_{spectrum["group_name"]}'
region_parent = f'{group_parent}/regions/Region_{spectrum["spectrum_type"]}'
instrument_parent = f"{region_parent}/instrument"
analyser_parent = f"{instrument_parent}/analyser"

Expand Down
4 changes: 2 additions & 2 deletions pynxtools_xps/txt/txt_scienta.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ def _update_xps_dict_with_spectrum(self, spectrum, key_map):

"""
# pylint: disable=too-many-locals,duplicate-code
group_parent = f'{self._root_path}/RegionGroup_{spectrum["spectrum_type"]}'
region_parent = f'{group_parent}/regions/RegionData_{spectrum["region_name"]}'
group_parent = f'{self._root_path}/Region_{spectrum["spectrum_type"]}'
region_parent = f'{group_parent}/regions/Region_{spectrum["region_name"]}'
file_parent = f"{region_parent}/file_info"
instrument_parent = f"{region_parent}/instrument"
analyser_parent = f"{instrument_parent}/analyser"
Expand Down
4 changes: 2 additions & 2 deletions pynxtools_xps/txt/txt_vamas_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ def _update_xps_dict_with_spectrum(self, spectrum, key_map):

"""
# pylint: disable=too-many-locals,duplicate-code
group_parent = f'{self._root_path}/RegionGroup_{spectrum["group_name"]}'
region_parent = f'{group_parent}/regions/RegionData_{spectrum["spectrum_type"]}'
group_parent = f'{self._root_path}/Group_{spectrum["group_name"]}'
region_parent = f'{group_parent}/regions/Region_{spectrum["spectrum_type"]}'
file_parent = f"{region_parent}/file_info"
instrument_parent = f"{region_parent}/instrument"
analyser_parent = f"{instrument_parent}/analyser"
Expand Down
Loading
Loading