Skip to content

Commit

Permalink
included ub conf into spice logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Bing Li committed Oct 3, 2024
1 parent 9107c60 commit 703cfd8
Show file tree
Hide file tree
Showing 15 changed files with 61 additions and 1,919 deletions.
30 changes: 19 additions & 11 deletions src/tavi/data/nxdict.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pathlib import Path
from typing import Optional

import h5py
import numpy as np

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

def _formatted_spicelogs(spicelogs: dict) -> NXentry:
"""Format SPICE logs into NeXus dict"""
formatted_spicelogs = NXentry(NX_class="NXcollection", EX_required="false")
ub_conf = spicelogs.pop("ub_conf")
ub_file_path = ub_conf.pop("file_path")
formatted_ub_conf = NXentry(file_path=ub_file_path, NX_class="NXcollection", EX_required="false")
for entry_key, entry_data in ub_conf.items():
formatted_ub_conf.add_dataset(key=entry_key, ds=NXdataset(ds=entry_data))

metadata = spicelogs.pop("metadata")
formatted_spicelogs = NXentry(ub_conf=formatted_ub_conf, NX_class="NXcollection", EX_required="false")

for attr_key, attr_entry in metadata.items():
formatted_spicelogs.add_attribute(attr_key, attr_entry)

for entry_key, entry_data in spicelogs.items():
formatted_spicelogs.add_dataset(key=entry_key, ds=NXdataset(ds=entry_data))

return formatted_spicelogs


Expand Down Expand Up @@ -280,6 +289,13 @@ def spice_scan_to_nxdict(
EX_required="true",
)
nxsample.add_dataset(key="Pt.", ds=NXdataset(ds=spicelogs.get("Pt."), type="NX_INT"))
# UB info
nxsample.add_dataset(
key="orientation_matrix",
ds=NXdataset(ds=metadata.get("ubmatrix"), type="NX_FLOAT", EX_required="true", units="NX_DIMENSIONLESS"),
)
# nxsample.add_dataset(key="ub_conf", ds=NXdataset(ds=metadata["ubconf"].split(".")[0], type="NX_CHAR"))
nxsample.add_dataset(key="plane_normal", ds=NXdataset(ds=metadata.get("plane_normal"), type="NX_FLOAT"))

# Motor angles
nxsample.add_dataset(key="s1", ds=NXdataset(ds=spicelogs.get("s1"), type="NX_FLOAT", units="degrees"))
Expand All @@ -289,14 +305,6 @@ def spice_scan_to_nxdict(
nxsample.add_dataset(key="stu", ds=NXdataset(ds=spicelogs.get("stu"), type="NX_FLOAT", units="degrees"))
nxsample.add_dataset(key="stl", ds=NXdataset(ds=spicelogs.get("stl"), type="NX_FLOAT", units="degrees"))

# UB info
nxsample.add_dataset(
key="orientation_matrix",
ds=NXdataset(ds=metadata.get("ubmatrix"), type="NX_FLOAT", EX_required="true", units="NX_DIMENSIONLESS"),
)
nxsample.add_dataset(key="ub_conf", ds=NXdataset(ds=metadata["ubconf"].split(".")[0], type="NX_CHAR"))
nxsample.add_dataset(key="plane_normal", ds=NXdataset(ds=metadata.get("plane_normal"), type="NX_FLOAT"))

# ---------------------------------------- sample environment ---------------------------------------------

# TODO all sample environment variable names needed!
Expand Down Expand Up @@ -381,14 +389,14 @@ def spice_data_to_nxdict(
for path_to_scan_file in scan_list:
*_, file_name = path_to_scan_file.split("/")
*_, scan_dat = file_name.split("_")
scan_num, _ = scan_dat.split(".")
scan_name, _ = scan_dat.split(".")

nxentry = spice_scan_to_nxdict(
path_to_scan_file,
path_to_instrument_json,
path_to_sample_json,
)
nxentry["attrs"].update({"dataset_name": dataset_name})
nexus_dict.update({scan_num: nxentry})
nexus_dict.update({scan_name: nxentry})

return nexus_dict
150 changes: 0 additions & 150 deletions src/tavi/data/nxdict_backup.py

This file was deleted.

143 changes: 0 additions & 143 deletions src/tavi/data/nxdict_backup2.py

This file was deleted.

4 changes: 2 additions & 2 deletions src/tavi/data/nxentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ def to_nexus(self, path_to_nexus: str, name="scan") -> None:
scan_grp = nexus_file.require_group(name + "/")
NexusEntry._write_recursively(self, scan_grp)
# create soft link for data
def_y = nexus_file["scan0034"]["data"].attrs["signal"]
def_x = nexus_file["scan0034"]["data"].attrs["axes"]
def_y = nexus_file[name]["data"].attrs["signal"]
def_x = nexus_file[name]["data"].attrs["axes"]
path_y = _find_val_path(def_y, nexus_file)
path_x = _find_val_path(def_x, nexus_file)

Expand Down
Loading

0 comments on commit 703cfd8

Please sign in to comment.