@@ -83,8 +83,7 @@ class SleMapperSpecs(XPSMapper):
83
83
84
84
def __init__ (self ):
85
85
self .parsers = [
86
- SleProdigyParserV1 ,
87
- SleProdigyParserV4 ,
86
+ SleProdigyParser ,
88
87
]
89
88
90
89
self .versions_map = {}
@@ -425,20 +424,52 @@ def _update_xps_dict_with_spectrum(
425
424
POSSIBLE_DATE_FORMATS : List [str ] = ["%Y-%b-%d %H:%M:%S.%f" ]
426
425
427
426
428
- class SleProdigyParser ( ABC ) :
427
+ class SleProdigyParser :
429
428
"""
430
429
Generic parser without reading capabilities,
431
430
to be used as template for implementing parsers for different versions.
432
431
"""
433
432
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
+
434
455
def __init__ (self ):
435
456
self .con = ""
436
457
self .spectra : List [Dict [str , Any ]] = []
437
458
self .xml : ET .Element = None
438
459
self .sum_channels : bool = False
439
460
self .remove_align : bool = True
440
461
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
+ }
442
473
443
474
def initiate_file_connection (self , filepath : str ):
444
475
"""Set the sqllite connection of the file to be opened."""
@@ -468,17 +499,17 @@ def parse_file(
468
499
Flat list of dictionaries containing one spectrum each.
469
500
470
501
"""
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 )
476
504
477
505
# initiate connection to sql file
478
506
self .initiate_file_connection (filepath )
479
507
480
508
# read and parse sle file
481
509
self ._get_xml_schedule ()
510
+ self ._get_xml_schedule ()
511
+ self ._get_xml_schedule ()
512
+
482
513
self .spectra = flatten_xml (self .xml )
483
514
self ._attach_node_ids ()
484
515
self ._remove_empty_nodes ()
@@ -501,12 +532,32 @@ def parse_file(
501
532
502
533
return self .spectra
503
534
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 ):
506
544
cur = self .con .cursor ()
507
- query = ' SELECT Value FROM Configuration WHERE Key="Schedule"'
545
+ query = f" SELECT Value FROM Configuration WHERE Key={ key } "
508
546
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
510
561
511
562
def _append_scan_data (self ):
512
563
"""
@@ -1342,11 +1393,6 @@ def _check_encoding(self):
1342
1393
cur .execute (query )
1343
1394
data , chunksize = cur .fetchall ()[0 ]
1344
1395
1345
- encodings_map : Dict [str , List [str , float ]] = {
1346
- "double" : ["d" , 8 ],
1347
- "float" : ["f" , 4 ],
1348
- }
1349
-
1350
1396
if data / chunksize == 4 :
1351
1397
self .encoding = encodings_map ["float" ]
1352
1398
elif data / chunksize == 8 :
@@ -1445,32 +1491,3 @@ def get_sle_version(self) -> str:
1445
1491
cur .execute (query )
1446
1492
version = cur .fetchall ()[0 ][0 ]
1447
1493
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
- ]
0 commit comments