5
5
from pathlib import Path
6
6
from typing import Optional
7
7
8
+ import h5py
8
9
import numpy as np
9
10
10
11
from tavi .data .spice_reader import _create_spicelogs , read_spice_datafile
@@ -109,13 +110,21 @@ def add_attribute(self, key: str, attr):
109
110
110
111
def _formatted_spicelogs (spicelogs : dict ) -> NXentry :
111
112
"""Format SPICE logs into NeXus dict"""
112
- formatted_spicelogs = NXentry (NX_class = "NXcollection" , EX_required = "false" )
113
+ ub_conf = spicelogs .pop ("ub_conf" )
114
+ ub_file_path = ub_conf .pop ("file_path" )
115
+ formatted_ub_conf = NXentry (file_path = ub_file_path , NX_class = "NXcollection" , EX_required = "false" )
116
+ for entry_key , entry_data in ub_conf .items ():
117
+ formatted_ub_conf .add_dataset (key = entry_key , ds = NXdataset (ds = entry_data ))
118
+
113
119
metadata = spicelogs .pop ("metadata" )
120
+ formatted_spicelogs = NXentry (ub_conf = formatted_ub_conf , NX_class = "NXcollection" , EX_required = "false" )
121
+
114
122
for attr_key , attr_entry in metadata .items ():
115
123
formatted_spicelogs .add_attribute (attr_key , attr_entry )
116
124
117
125
for entry_key , entry_data in spicelogs .items ():
118
126
formatted_spicelogs .add_dataset (key = entry_key , ds = NXdataset (ds = entry_data ))
127
+
119
128
return formatted_spicelogs
120
129
121
130
@@ -280,6 +289,13 @@ def spice_scan_to_nxdict(
280
289
EX_required = "true" ,
281
290
)
282
291
nxsample .add_dataset (key = "Pt." , ds = NXdataset (ds = spicelogs .get ("Pt." ), type = "NX_INT" ))
292
+ # UB info
293
+ nxsample .add_dataset (
294
+ key = "orientation_matrix" ,
295
+ ds = NXdataset (ds = metadata .get ("ubmatrix" ), type = "NX_FLOAT" , EX_required = "true" , units = "NX_DIMENSIONLESS" ),
296
+ )
297
+ # nxsample.add_dataset(key="ub_conf", ds=NXdataset(ds=metadata["ubconf"].split(".")[0], type="NX_CHAR"))
298
+ nxsample .add_dataset (key = "plane_normal" , ds = NXdataset (ds = metadata .get ("plane_normal" ), type = "NX_FLOAT" ))
283
299
284
300
# Motor angles
285
301
nxsample .add_dataset (key = "s1" , ds = NXdataset (ds = spicelogs .get ("s1" ), type = "NX_FLOAT" , units = "degrees" ))
@@ -289,14 +305,6 @@ def spice_scan_to_nxdict(
289
305
nxsample .add_dataset (key = "stu" , ds = NXdataset (ds = spicelogs .get ("stu" ), type = "NX_FLOAT" , units = "degrees" ))
290
306
nxsample .add_dataset (key = "stl" , ds = NXdataset (ds = spicelogs .get ("stl" ), type = "NX_FLOAT" , units = "degrees" ))
291
307
292
- # UB info
293
- nxsample .add_dataset (
294
- key = "orientation_matrix" ,
295
- ds = NXdataset (ds = metadata .get ("ubmatrix" ), type = "NX_FLOAT" , EX_required = "true" , units = "NX_DIMENSIONLESS" ),
296
- )
297
- nxsample .add_dataset (key = "ub_conf" , ds = NXdataset (ds = metadata ["ubconf" ].split ("." )[0 ], type = "NX_CHAR" ))
298
- nxsample .add_dataset (key = "plane_normal" , ds = NXdataset (ds = metadata .get ("plane_normal" ), type = "NX_FLOAT" ))
299
-
300
308
# ---------------------------------------- sample environment ---------------------------------------------
301
309
302
310
# TODO all sample environment variable names needed!
@@ -381,14 +389,14 @@ def spice_data_to_nxdict(
381
389
for path_to_scan_file in scan_list :
382
390
* _ , file_name = path_to_scan_file .split ("/" )
383
391
* _ , scan_dat = file_name .split ("_" )
384
- scan_num , _ = scan_dat .split ("." )
392
+ scan_name , _ = scan_dat .split ("." )
385
393
386
394
nxentry = spice_scan_to_nxdict (
387
395
path_to_scan_file ,
388
396
path_to_instrument_json ,
389
397
path_to_sample_json ,
390
398
)
391
399
nxentry ["attrs" ].update ({"dataset_name" : dataset_name })
392
- nexus_dict .update ({scan_num : nxentry })
400
+ nexus_dict .update ({scan_name : nxentry })
393
401
394
402
return nexus_dict
0 commit comments