2
2
from typing import Optional
3
3
4
4
5
+ def _add_dataset_entry (
6
+ entry_dict : dict ,
7
+ key : str ,
8
+ daslogs : dict ,
9
+ daslogs_key : Optional [str ] = None ,
10
+ ** kwargs ,
11
+ ):
12
+ key = key if daslogs_key is None else daslogs_key
13
+ try :
14
+ val = daslogs [key ]
15
+ entry_dict .update ({key : {"dataset" : val }})
16
+ if not kwargs :
17
+ return entry_dict
18
+ attr_dict = {}
19
+ for k , v in kwargs .items ():
20
+ attr_dict .update ({k : v })
21
+ entry_dict [key ].update ({"attrs" : attr_dict })
22
+ return entry_dict
23
+
24
+ except KeyError :
25
+ print (f"Variable { key } cannot be found in DAS logs." )
26
+ return entry_dict
27
+
28
+
5
29
def nxsource (spicelogs , instrument_config_params ):
6
30
source = {
7
31
"attrs" : {"NX_class" : "NXsource" , "EX_required" : "true" },
@@ -21,49 +45,74 @@ def nxsource(spicelogs, instrument_config_params):
21
45
22
46
23
47
def nxmono (spicelogs , instrument_config_params ):
24
- metadata = spicelogs ["attrs" ]
25
48
26
- try :
27
- mono = {
28
- "attrs" : {"NX_class" : "NXcrystal" , "EX_required" : "true" },
29
- "ei" : {
30
- "dataset" : spicelogs ["ei" ],
31
- "attrs" : {"type" : "NX_FLOAT" , "EX_required" : "true" , "units" : "meV" },
32
- },
33
- "type" : {"dataset" : metadata ["monochromator" ], "attrs" : {"type" : "NX_CHAR" }},
34
- "sense" : {"dataset" : metadata ["sense" ][0 ], "attrs" : {"type" : "NX_CHAR" }},
35
- "m1" : {
36
- "dataset" : spicelogs ["m1" ],
37
- "attrs" : {"type" : "NX_FLOAT" , "units" : "degrees" },
38
- },
39
- "m2" : {
40
- "dataset" : spicelogs ["m2" ],
41
- "attrs" : {"type" : "NX_FLOAT" , "units" : "degrees" },
42
- },
43
- "mfocus" : {"dataset" : spicelogs ["mfocus" ], "attrs" : {"type" : "NX_FLOAT" }},
44
- "marc" : {"dataset" : spicelogs ["marc" ], "attrs" : {"type" : "NX_FLOAT" }},
45
- "mtrans" : {"dataset" : spicelogs ["mtrans" ], "attrs" : {"type" : "NX_FLOAT" }},
46
- "focal_length" : {"dataset" : spicelogs ["focal_length" ], "attrs" : {"type" : "NX_FLOAT" }},
47
- }
48
- except KeyError :
49
- pass
49
+ mono = {"attrs" : {"NX_class" : "NXcrystal" , "EX_required" : "true" }}
50
+ mono = _add_dataset_entry (mono , key = "ei" , daslogs = spicelogs , type = "NX_FLOAT" , EX_required = "true" , unit = "meV" )
51
+ mono .update ({"type" : {"dataset" : spicelogs ["attrs" ]["monochromator" ], "attrs" : {"type" : "NX_CHAR" }}})
52
+ mono .update ({"sense" : {"dataset" : spicelogs ["attrs" ]["sense" ][0 ], "attrs" : {"type" : "NX_CHAR" }}})
53
+ mono = _add_dataset_entry (mono , key = "m1" , daslogs = spicelogs , type = "NX_FLOAT" , unit = "degrees" )
54
+ mono = _add_dataset_entry (mono , key = "m2" , daslogs = spicelogs , type = "NX_FLOAT" , unit = "degrees" )
55
+ mono = _add_dataset_entry (mono , key = "mfocus" , daslogs = spicelogs , type = "NX_FLOAT" )
56
+ mono = _add_dataset_entry (mono , key = "marc" , daslogs = spicelogs , type = "NX_FLOAT" )
57
+ mono = _add_dataset_entry (mono , key = "mtrans" , daslogs = spicelogs , type = "NX_FLOAT" )
58
+ mono = _add_dataset_entry (mono , key = "focal_length" , daslogs = spicelogs , type = "NX_FLOAT" )
59
+
50
60
return mono
51
61
52
62
53
63
def nxcoll (spicelogs , instrument_config_params ):
54
- return {}
64
+ pass
55
65
56
66
57
67
def nxana (spicelogs , instrument_config_params ):
58
- return {}
68
+ ana = {"attrs" : {"NX_class" : "NXcrystal" , "EX_required" : "true" }}
69
+ ana = _add_dataset_entry (ana , key = "ef" , daslogs = spicelogs , type = "NX_FLOAT" , EX_required = "true" , unit = "meV" )
70
+ ana .update ({"type" : {"dataset" : spicelogs ["attrs" ]["analyzer" ], "attrs" : {"type" : "NX_CHAR" }}})
71
+ ana .update ({"sense" : {"dataset" : spicelogs ["attrs" ]["sense" ][2 ], "attrs" : {"type" : "NX_CHAR" }}})
72
+ ana = _add_dataset_entry (ana , key = "a1" , daslogs = spicelogs , type = "NX_FLOAT" , unit = "degrees" )
73
+ ana = _add_dataset_entry (ana , key = "a2" , daslogs = spicelogs , type = "NX_FLOAT" , unit = "degrees" )
74
+ ana = _add_dataset_entry (ana , key = "afocus" , daslogs = spicelogs , type = "NX_FLOAT" )
75
+ for i in range (8 ):
76
+ ana = _add_dataset_entry (ana , key = f"qm{ i + 1 } " , daslogs = spicelogs , type = "NX_FLOAT" )
77
+ ana = _add_dataset_entry (ana , key = f"xm{ i + 1 } " , daslogs = spicelogs , type = "NX_FLOAT" )
78
+ return ana
59
79
60
80
61
81
def nxdet (spicelogs , instrument_config_params ):
62
- return {}
82
+ det = {"attrs" : {"NX_class" : "NXdetector" , "EX_required" : "true" }}
83
+ det = _add_dataset_entry (det , key = "detector" , daslogs = spicelogs , type = "NX_INT" , EX_required = "true" , unit = "counts" )
84
+ # polar_angle
85
+ return det
63
86
64
87
65
88
def nxmonitor (spicelogs , instrument_config_params ):
66
- return {}
89
+ monitor = {"attrs" : {"NX_class" : "NXmonitor" , "EX_required" : "true" }}
90
+ preset_type = spicelogs ["attrs" ]["preset_type" ]
91
+ match preset_type :
92
+ case "countfile" : # polarization data
93
+ print ("Countfile preset type is not supported." )
94
+
95
+ case "normal" :
96
+ preset_channel = spicelogs ["attrs" ]["preset_channel" ]
97
+ monitor .update ({"mode" : {"dataset" : preset_channel , "attrs" : {"type" : "NX_CHAR" , "EX_required" : "true" }}})
98
+ monitor .update (
99
+ {
100
+ "preset" : {
101
+ "dataset" : spicelogs ["attrs" ]["preset_value" ],
102
+ "attrs" : {"type" : "NX_FLOAT" , "EX_required" : "true" },
103
+ }
104
+ }
105
+ )
106
+ monitor = _add_dataset_entry (monitor , key = "time" , daslogs = spicelogs , type = "NX_FLOAT" , units = "seconds" )
107
+ monitor = _add_dataset_entry (monitor , key = "monitor" , daslogs = spicelogs , type = "NX_INT" , units = "counts" )
108
+ monitor = _add_dataset_entry (monitor , key = "mcu" , daslogs = spicelogs , type = "NX_FLOAT" )
109
+ monitor_data_dict = monitor [preset_channel ]
110
+ monitor .update ({"data" : monitor_data_dict })
111
+
112
+ case _:
113
+ print (f"Unrecogonized preset type { preset_type } ." )
114
+
115
+ return monitor
67
116
68
117
69
118
def nxsample (spicelogs , sample_config_params ):
0 commit comments