Skip to content

Commit 4af58c3

Browse files
committed
save current version
1 parent 7750fbd commit 4af58c3

File tree

4 files changed

+71
-60
lines changed

4 files changed

+71
-60
lines changed

src/pynxtools_xps/specs/sle/flatten_xml.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import re
99
import copy
10-
from typing import Tuple, Dict, Any
10+
from typing import Tuple, Dict, Any, List
1111

1212
from lxml import etree as ET
1313

@@ -40,7 +40,7 @@ def extract_devices(elem: ET.Element) -> Dict[str, Any]:
4040

4141

4242
def step_profiling(elem: ET.Element) -> Dict[str, Any]:
43-
settings = {}
43+
settings: Dict[str, Any] = {}
4444

4545
for setting in elem.iter():
4646
print(setting.tag, setting.attrib)
@@ -174,7 +174,7 @@ def _get_spectrum_metadata(spectrum: ET.Element) -> Dict[str, Any]:
174174
}
175175

176176

177-
def flatten_xml(xml: ET.Element) -> Dict[str, Any]:
177+
def flatten_xml(xml: ET.Element) -> List[Dict[str, Any]]:
178178
"""
179179
Flatten the nested XML structure, keeping only the needed metadata.
180180
@@ -208,7 +208,7 @@ def process_element(elem: ET.Element, settings: Dict[str, Any]):
208208

209209
for measurement_type in MEASUREMENT_METHOD_MAP:
210210
for group in xml.iter(measurement_type):
211-
data = {}
211+
data: Dict[str, Any] = {}
212212
data["devices"] = []
213213
data["analysis_method"] = convert_measurement_method(measurement_type)
214214
process_element(group, data)

src/pynxtools_xps/specs/sle/sle_specs.py

Lines changed: 64 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ class SleMapperSpecs(XPSMapper):
8383

8484
def __init__(self):
8585
self.parsers = [
86-
SleProdigyParserV1,
87-
SleProdigyParserV4,
86+
SleProdigyParser,
8887
]
8988

9089
self.versions_map = {}
@@ -425,20 +424,52 @@ def _update_xps_dict_with_spectrum(
425424
POSSIBLE_DATE_FORMATS: List[str] = ["%Y-%b-%d %H:%M:%S.%f"]
426425

427426

428-
class SleProdigyParser(ABC):
427+
class SleProdigyParser:
429428
"""
430429
Generic parser without reading capabilities,
431430
to be used as template for implementing parsers for different versions.
432431
"""
433432

433+
supported_versions = [
434+
"1.2",
435+
"1.8",
436+
"1.9",
437+
"1.10",
438+
"1.11",
439+
"1.12",
440+
"1.13",
441+
"4.63",
442+
"4.64",
443+
"4.65",
444+
"4.66",
445+
"4.67",
446+
"4.68",
447+
"4.69",
448+
"4.70",
449+
"4.71",
450+
"4.72",
451+
"4.73",
452+
"4.100",
453+
]
454+
434455
def __init__(self):
435456
self.con = ""
436457
self.spectra: List[Dict[str, Any]] = []
437458
self.xml: ET.Element = None
438459
self.sum_channels: bool = False
439460
self.remove_align: bool = True
440461

441-
self.encoding: List[str, float] = ["f", 4]
462+
self.encodings_dtype = {
463+
"short": np.int16,
464+
"double": np.float64,
465+
"float": np.float32,
466+
}
467+
self.encoding = np.float32
468+
469+
encodings_map: Dict[str, List[str, float]] = {
470+
"double": ["d", 8],
471+
"float": ["f", 4],
472+
}
442473

443474
def initiate_file_connection(self, filepath: str):
444475
"""Set the sqllite connection of the file to be opened."""
@@ -468,17 +499,17 @@ def parse_file(
468499
Flat list of dictionaries containing one spectrum each.
469500
470501
"""
471-
if "remove_align" in kwargs:
472-
self.remove_align = kwargs["remove_align"]
473-
474-
if "sum_channels" in kwargs:
475-
self.sum_channels = kwargs["sum_channels"]
502+
self.remove_align = kwargs.get("remove_align", True)
503+
self.sum_channels = kwargs.get("sum_channels", False)
476504

477505
# initiate connection to sql file
478506
self.initiate_file_connection(filepath)
479507

480508
# read and parse sle file
481509
self._get_xml_schedule()
510+
self._get_xml_schedule()
511+
self._get_xml_schedule()
512+
482513
self.spectra = flatten_xml(self.xml)
483514
self._attach_node_ids()
484515
self._remove_empty_nodes()
@@ -501,12 +532,32 @@ def parse_file(
501532

502533
return self.spectra
503534

504-
def _get_xml_schedule(self):
505-
"""Parse the schedule into an XML object."""
535+
def _addVersion(self):
536+
self.cursor.execute('SELECT Value FROM Configuration WHERE Key="Version"')
537+
self.version = self.cursor.fetchone()[0]
538+
539+
def _addAppVersion(self):
540+
self.cursor.execute('SELECT Value FROM Configuration WHERE Key="AppVersion"')
541+
self.app_version = self.cursor.fetchone()[0]
542+
543+
def _get_xml_from_key(key: str):
506544
cur = self.con.cursor()
507-
query = 'SELECT Value FROM Configuration WHERE Key="Schedule"'
545+
query = f"SELECT Value FROM Configuration WHERE Key={key}"
508546
cur.execute(query)
509-
self.xml = ET.fromstring(cur.fetchall()[0][0])
547+
return ET.fromstring(self.cursor.fetchone()[0])
548+
549+
def _get_xml_schedule(self):
550+
"""Parse the schedule into an XML object."""
551+
self.xml_schedule = _get_xml_from_key("Schedule")
552+
553+
def _get_xml_context(self):
554+
"""Parse the context into an XML object."""
555+
self.xml_context = _get_xml_from_key("Context")
556+
557+
def _get_xml_metainfo(self):
558+
XML = _get_xml_from_key("MetaInfo")
559+
for i in XML.iter("Parameter"):
560+
self.metainfo[i.attrib["name"].replace(" ", "_")] = i.text
510561

511562
def _append_scan_data(self):
512563
"""
@@ -1342,11 +1393,6 @@ def _check_encoding(self):
13421393
cur.execute(query)
13431394
data, chunksize = cur.fetchall()[0]
13441395

1345-
encodings_map: Dict[str, List[str, float]] = {
1346-
"double": ["d", 8],
1347-
"float": ["f", 4],
1348-
}
1349-
13501396
if data / chunksize == 4:
13511397
self.encoding = encodings_map["float"]
13521398
elif data / chunksize == 8:
@@ -1445,32 +1491,3 @@ def get_sle_version(self) -> str:
14451491
cur.execute(query)
14461492
version = cur.fetchall()[0][0]
14471493
return version
1448-
1449-
1450-
class SleProdigyParserV1(SleProdigyParser):
1451-
"""
1452-
Parser for SLE version 1.
1453-
"""
1454-
1455-
supported_versions = ["1.2", "1.8", "1.9", "1.10", "1.11", "1.12", "1.13"]
1456-
1457-
1458-
class SleProdigyParserV4(SleProdigyParser):
1459-
"""
1460-
Parser for SLE version 4.
1461-
"""
1462-
1463-
supported_versions = [
1464-
"4.63",
1465-
"4.64",
1466-
"4.65",
1467-
"4.66",
1468-
"4.67",
1469-
"4.68",
1470-
"4.69",
1471-
"4.70",
1472-
"4.71",
1473-
"4.72",
1474-
"4.73",
1475-
"4.100",
1476-
]

src/pynxtools_xps/specs/xml/xml_specs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#
2323
import re
2424
import xml.etree.ElementTree as ET
25-
from typing import Tuple, List, Any
25+
from typing import Tuple, List, Any, Dict
2626
import copy
2727
import xarray as xr
2828
import numpy as np
@@ -265,7 +265,7 @@ def parse_file(self, file: str, **kwargs):
265265
----------
266266
"""
267267
root_element = ET.parse(file).getroot()
268-
root_element.attrib[self.child_nm_reslvers] = []
268+
root_element.attrib[self.child_nm_reslvers] = [] # type: ignore[assignment]
269269
child_num = len(root_element)
270270
parent_path = self._root_path
271271
skip_child = -1

src/pynxtools_xps/specs/xy/xy_specs.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -851,10 +851,4 @@ def _parse_datetime(self, date: str) -> str:
851851

852852
possible_time_formats = ["%m/%d/%y %H:%M:%S"]
853853

854-
date_object = datetime.datetime.strptime(date, "%m/%d/%y %H:%M:%S").replace(
855-
tzinfo=tz
856-
)
857-
858-
return date_object.isoformat()
859-
860-
return parse_datetime(date, possible_time_formats, tzinfo)
854+
return parse_datetime(date, possible_time_formats, tz)

0 commit comments

Comments
 (0)