Skip to content

Commit

Permalink
add handling of Casa header
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaspie committed Mar 6, 2024
1 parent 49a590d commit a16fcb1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
33 changes: 29 additions & 4 deletions pynxtools_xps/vms/vamas.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,10 @@ def build_list(self):
temp_group_name = ""
spectra = []

header_dict = {to_snake_case(k): v for (k, v) in self.header.dict().items()}
del header_dict["comment_lines"]
header_dict.update(self.handle_header_comments(self.header.comment_lines))

for spectrum_id, block in enumerate(self.blocks):
group_name = block.sample_id
# This set of conditions detects if the group name has changed.
Expand Down Expand Up @@ -669,9 +673,7 @@ def build_list(self):
"sample_rotation_angle": block.sample_rotation,
"n_values": int(block.num_ord_values / block.no_variables),
}

comment_dict = self.handle_block_comments(block.comment_lines)
settings.update(comment_dict)
settings.update(header_dict)

# Convert the native time format to the datetime string
# in the ISO 8601 format
Expand Down Expand Up @@ -719,8 +721,31 @@ def build_list(self):

return spectra

def handle_header_comments(self, comment_list):
"""Handle comments (incl. Casa info) for the header."""
comments = {}

if "Casa Info Follows" in comment_list[0]:
comments["casa_version"] = (
comment_list[0].split("Casa Info Follows CasaXPS Version")[1].strip()
)
non_casa_comments = comment_list[1:]
else:
non_casa_comments = comment_list

for line in non_casa_comments:
for sep in ("=", ":"):
try:
key, value = [part.strip(" ") for part in line.split(sep, 1)]
comments[to_snake_case(key)] = value
except ValueError:
if "SpecsLab Prodigy" in line:
comments["prodigy_version"] = line.split("Version")[1].strip()

return comments

def handle_block_comments(self, comment_list):
"""Handle comments (incl. Casa fitting for each block."""
"""Handle comments (incl. Casa fitting) for each block."""
comments = {}

if "Casa Info Follows" in comment_list[0]:
Expand Down
6 changes: 4 additions & 2 deletions pynxtools_xps/vms/vamas_data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@

from dataclasses import dataclass, field

from pynxtools_xps.reader_utils import XpsDataclass


@dataclass
class VamasHeader:
class VamasHeader(XpsDataclass):
"""An object to store the Vamas header information."""

format_id: str = (
Expand Down Expand Up @@ -51,7 +53,7 @@ class VamasHeader:


@dataclass
class VamasBlock:
class VamasBlock(XpsDataclass):
"""An object to store a block of spectrum data and meta-data."""

block_id: str = ""
Expand Down

0 comments on commit a16fcb1

Please sign in to comment.