parent
137f20cc20
commit
c10efeb9cc
@ -51,9 +51,11 @@ IMAGE_PLOT_H = int(IMAGE_H * 2) + 27
|
|||||||
|
|
||||||
def create():
|
def create():
|
||||||
det_data = {}
|
det_data = {}
|
||||||
|
cami_meta = {}
|
||||||
roi_selection = {}
|
roi_selection = {}
|
||||||
|
|
||||||
def proposal_textinput_callback(_attr, _old, new):
|
def proposal_textinput_callback(_attr, _old, new):
|
||||||
|
nonlocal cami_meta
|
||||||
proposal = new.strip()
|
proposal = new.strip()
|
||||||
for zebra_proposals_path in pyzebra.ZEBRA_PROPOSALS_PATHS:
|
for zebra_proposals_path in pyzebra.ZEBRA_PROPOSALS_PATHS:
|
||||||
proposal_path = os.path.join(zebra_proposals_path, proposal)
|
proposal_path = os.path.join(zebra_proposals_path, proposal)
|
||||||
@ -69,13 +71,16 @@ def create():
|
|||||||
file_list.append((os.path.join(proposal_path, file), file))
|
file_list.append((os.path.join(proposal_path, file), file))
|
||||||
file_select.options = file_list
|
file_select.options = file_list
|
||||||
|
|
||||||
|
cami_meta = {}
|
||||||
|
|
||||||
proposal_textinput = TextInput(title="Proposal number:", width=210)
|
proposal_textinput = TextInput(title="Proposal number:", width=210)
|
||||||
proposal_textinput.on_change("value", proposal_textinput_callback)
|
proposal_textinput.on_change("value", proposal_textinput_callback)
|
||||||
|
|
||||||
def upload_button_callback(_attr, _old, new):
|
def upload_button_callback(_attr, _old, new):
|
||||||
|
nonlocal cami_meta
|
||||||
with io.StringIO(base64.b64decode(new).decode()) as file:
|
with io.StringIO(base64.b64decode(new).decode()) as file:
|
||||||
h5meta_list = pyzebra.parse_h5meta(file)
|
cami_meta = pyzebra.parse_h5meta(file)
|
||||||
file_list = h5meta_list["filelist"]
|
file_list = cami_meta["filelist"]
|
||||||
file_select.options = [(entry, os.path.basename(entry)) for entry in file_list]
|
file_select.options = [(entry, os.path.basename(entry)) for entry in file_list]
|
||||||
|
|
||||||
upload_div = Div(text="or upload .cami file:", margin=(5, 5, 0, 5))
|
upload_div = Div(text="or upload .cami file:", margin=(5, 5, 0, 5))
|
||||||
@ -182,6 +187,9 @@ def create():
|
|||||||
|
|
||||||
det_data = pyzebra.read_detector_data(new[0])
|
det_data = pyzebra.read_detector_data(new[0])
|
||||||
|
|
||||||
|
if cami_meta and "crystal" in cami_meta:
|
||||||
|
det_data["ub"] = cami_meta["crystal"]["UB"]
|
||||||
|
|
||||||
index_spinner.value = 0
|
index_spinner.value = 0
|
||||||
index_spinner.high = det_data["data"].shape[0] - 1
|
index_spinner.high = det_data["data"].shape[0] - 1
|
||||||
index_slider.end = det_data["data"].shape[0] - 1
|
index_slider.end = det_data["data"].shape[0] - 1
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
import h5py
|
import h5py
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
|
META_MATRIX = ("UB")
|
||||||
|
META_STR = ("name")
|
||||||
|
|
||||||
def read_h5meta(filepath):
|
def read_h5meta(filepath):
|
||||||
"""Open and parse content of a h5meta file.
|
"""Open and parse content of a h5meta file.
|
||||||
|
|
||||||
@ -23,13 +27,30 @@ def parse_h5meta(file):
|
|||||||
line = line.strip()
|
line = line.strip()
|
||||||
if line.startswith("#begin "):
|
if line.startswith("#begin "):
|
||||||
section = line[len("#begin ") :]
|
section = line[len("#begin ") :]
|
||||||
content[section] = []
|
if section in ("detector parameters", "crystal"):
|
||||||
|
content[section] = {}
|
||||||
|
else:
|
||||||
|
content[section] = []
|
||||||
|
|
||||||
elif line.startswith("#end"):
|
elif line.startswith("#end"):
|
||||||
section = None
|
section = None
|
||||||
|
|
||||||
elif section:
|
elif section:
|
||||||
content[section].append(line)
|
if section in ("detector parameters", "crystal"):
|
||||||
|
if "=" in line:
|
||||||
|
variable, value = line.split("=", 1)
|
||||||
|
variable = variable.strip()
|
||||||
|
value = value.strip()
|
||||||
|
|
||||||
|
if variable in META_STR:
|
||||||
|
content[section][variable] = value
|
||||||
|
elif variable in META_MATRIX:
|
||||||
|
ub_matrix = np.array(value.split(",")[:9], dtype=np.float).reshape(3, 3)
|
||||||
|
content[section][variable] = ub_matrix
|
||||||
|
else: # default is a single float number
|
||||||
|
content[section][variable] = float(value)
|
||||||
|
else:
|
||||||
|
content[section].append(line)
|
||||||
|
|
||||||
return content
|
return content
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user