Skip to content

Commit 703cfd8

Browse files
author
Bing Li
committed
included ub conf into spice logs
1 parent 9107c60 commit 703cfd8

15 files changed

+61
-1919
lines changed

src/tavi/data/nxdict.py

+19-11
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from pathlib import Path
66
from typing import Optional
77

8+
import h5py
89
import numpy as np
910

1011
from tavi.data.spice_reader import _create_spicelogs, read_spice_datafile
@@ -109,13 +110,21 @@ def add_attribute(self, key: str, attr):
109110

110111
def _formatted_spicelogs(spicelogs: dict) -> NXentry:
111112
"""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+
113119
metadata = spicelogs.pop("metadata")
120+
formatted_spicelogs = NXentry(ub_conf=formatted_ub_conf, NX_class="NXcollection", EX_required="false")
121+
114122
for attr_key, attr_entry in metadata.items():
115123
formatted_spicelogs.add_attribute(attr_key, attr_entry)
116124

117125
for entry_key, entry_data in spicelogs.items():
118126
formatted_spicelogs.add_dataset(key=entry_key, ds=NXdataset(ds=entry_data))
127+
119128
return formatted_spicelogs
120129

121130

@@ -280,6 +289,13 @@ def spice_scan_to_nxdict(
280289
EX_required="true",
281290
)
282291
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"))
283299

284300
# Motor angles
285301
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(
289305
nxsample.add_dataset(key="stu", ds=NXdataset(ds=spicelogs.get("stu"), type="NX_FLOAT", units="degrees"))
290306
nxsample.add_dataset(key="stl", ds=NXdataset(ds=spicelogs.get("stl"), type="NX_FLOAT", units="degrees"))
291307

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-
300308
# ---------------------------------------- sample environment ---------------------------------------------
301309

302310
# TODO all sample environment variable names needed!
@@ -381,14 +389,14 @@ def spice_data_to_nxdict(
381389
for path_to_scan_file in scan_list:
382390
*_, file_name = path_to_scan_file.split("/")
383391
*_, scan_dat = file_name.split("_")
384-
scan_num, _ = scan_dat.split(".")
392+
scan_name, _ = scan_dat.split(".")
385393

386394
nxentry = spice_scan_to_nxdict(
387395
path_to_scan_file,
388396
path_to_instrument_json,
389397
path_to_sample_json,
390398
)
391399
nxentry["attrs"].update({"dataset_name": dataset_name})
392-
nexus_dict.update({scan_num: nxentry})
400+
nexus_dict.update({scan_name: nxentry})
393401

394402
return nexus_dict

src/tavi/data/nxdict_backup.py

-150
This file was deleted.

src/tavi/data/nxdict_backup2.py

-143
This file was deleted.

src/tavi/data/nxentry.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ def to_nexus(self, path_to_nexus: str, name="scan") -> None:
217217
scan_grp = nexus_file.require_group(name + "/")
218218
NexusEntry._write_recursively(self, scan_grp)
219219
# create soft link for data
220-
def_y = nexus_file["scan0034"]["data"].attrs["signal"]
221-
def_x = nexus_file["scan0034"]["data"].attrs["axes"]
220+
def_y = nexus_file[name]["data"].attrs["signal"]
221+
def_x = nexus_file[name]["data"].attrs["axes"]
222222
path_y = _find_val_path(def_y, nexus_file)
223223
path_x = _find_val_path(def_x, nexus_file)
224224

0 commit comments

Comments
 (0)