Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
10bcabd7f9 | |||
bee8263184 | |||
98a76ebf63 | |||
12ba0b291b | |||
a719f10f4f | |||
aaff6032c8 | |||
3fb3fe573b | |||
1687337f26 | |||
53ceac21aa | |||
741a09819c | |||
3c619713d5 | |||
3d5a4ed6aa |
@ -5,4 +5,4 @@ from pyzebra.h5 import *
|
|||||||
from pyzebra.utils import *
|
from pyzebra.utils import *
|
||||||
from pyzebra.xtal import *
|
from pyzebra.xtal import *
|
||||||
|
|
||||||
__version__ = "0.6.2"
|
__version__ = "0.6.5"
|
||||||
|
@ -178,7 +178,7 @@ def create():
|
|||||||
|
|
||||||
new_data1 = []
|
new_data1 = []
|
||||||
new_data2 = []
|
new_data2 = []
|
||||||
for ind, f_str, f_name in enumerate(zip(upload_button.value, upload_button.filename)):
|
for ind, (f_str, f_name) in enumerate(zip(upload_button.value, upload_button.filename)):
|
||||||
with io.StringIO(base64.b64decode(f_str).decode()) as file:
|
with io.StringIO(base64.b64decode(f_str).decode()) as file:
|
||||||
base, ext = os.path.splitext(f_name)
|
base, ext = os.path.splitext(f_name)
|
||||||
try:
|
try:
|
||||||
|
@ -141,22 +141,29 @@ def create():
|
|||||||
|
|
||||||
scan_table_source.data.update(frame=frame, x_pos=x_pos, y_pos=y_pos)
|
scan_table_source.data.update(frame=frame, x_pos=x_pos, y_pos=y_pos)
|
||||||
|
|
||||||
|
def _file_open():
|
||||||
|
new_data = []
|
||||||
|
for f_name in file_select.value:
|
||||||
|
try:
|
||||||
|
new_data.append(pyzebra.read_detector_data(f_name))
|
||||||
|
except KeyError:
|
||||||
|
print("Could not read data from the file.")
|
||||||
|
return
|
||||||
|
|
||||||
|
zebra_data.extend(new_data)
|
||||||
|
|
||||||
|
_init_datatable()
|
||||||
|
|
||||||
def file_open_button_callback():
|
def file_open_button_callback():
|
||||||
nonlocal zebra_data
|
nonlocal zebra_data
|
||||||
zebra_data = []
|
zebra_data = []
|
||||||
for f_name in file_select.value:
|
_file_open()
|
||||||
zebra_data.append(pyzebra.read_detector_data(f_name))
|
|
||||||
|
|
||||||
_init_datatable()
|
|
||||||
|
|
||||||
file_open_button = Button(label="Open New", width=100)
|
file_open_button = Button(label="Open New", width=100)
|
||||||
file_open_button.on_click(file_open_button_callback)
|
file_open_button.on_click(file_open_button_callback)
|
||||||
|
|
||||||
def file_append_button_callback():
|
def file_append_button_callback():
|
||||||
for f_name in file_select.value:
|
_file_open()
|
||||||
zebra_data.append(pyzebra.read_detector_data(f_name))
|
|
||||||
|
|
||||||
_init_datatable()
|
|
||||||
|
|
||||||
file_append_button = Button(label="Append", width=100)
|
file_append_button = Button(label="Append", width=100)
|
||||||
file_append_button.on_click(file_append_button_callback)
|
file_append_button.on_click(file_append_button_callback)
|
||||||
|
@ -107,13 +107,23 @@ def create():
|
|||||||
upload_cami_button = FileInput(accept=".cami", width=200)
|
upload_cami_button = FileInput(accept=".cami", width=200)
|
||||||
upload_cami_button.on_change("value", upload_cami_button_callback)
|
upload_cami_button.on_change("value", upload_cami_button_callback)
|
||||||
|
|
||||||
def _open_file(file, cami_meta):
|
def _file_open(file, cami_meta):
|
||||||
nonlocal det_data
|
nonlocal det_data
|
||||||
det_data = pyzebra.read_detector_data(file, cami_meta)
|
try:
|
||||||
|
det_data = pyzebra.read_detector_data(file, cami_meta)
|
||||||
|
except KeyError:
|
||||||
|
print("Could not read data from the file.")
|
||||||
|
return
|
||||||
|
|
||||||
|
last_im_index = det_data["data"].shape[0] - 1
|
||||||
|
|
||||||
index_spinner.value = 0
|
index_spinner.value = 0
|
||||||
index_spinner.high = det_data["data"].shape[0] - 1
|
index_spinner.high = last_im_index
|
||||||
index_slider.end = det_data["data"].shape[0] - 1
|
if last_im_index == 0:
|
||||||
|
index_slider.disabled = True
|
||||||
|
else:
|
||||||
|
index_slider.disabled = False
|
||||||
|
index_slider.end = last_im_index
|
||||||
|
|
||||||
zebra_mode = det_data["zebra_mode"]
|
zebra_mode = det_data["zebra_mode"]
|
||||||
if zebra_mode == "nb":
|
if zebra_mode == "nb":
|
||||||
@ -125,7 +135,7 @@ def create():
|
|||||||
update_overview_plot()
|
update_overview_plot()
|
||||||
|
|
||||||
def upload_hdf_button_callback(_attr, _old, new):
|
def upload_hdf_button_callback(_attr, _old, new):
|
||||||
_open_file(io.BytesIO(base64.b64decode(new)), None)
|
_file_open(io.BytesIO(base64.b64decode(new)), None)
|
||||||
|
|
||||||
upload_hdf_div = Div(text="or upload .hdf file:", margin=(5, 5, 0, 5))
|
upload_hdf_div = Div(text="or upload .hdf file:", margin=(5, 5, 0, 5))
|
||||||
upload_hdf_button = FileInput(accept=".hdf", width=200)
|
upload_hdf_button = FileInput(accept=".hdf", width=200)
|
||||||
@ -136,9 +146,9 @@ def create():
|
|||||||
return
|
return
|
||||||
|
|
||||||
if data_source.value == "proposal number":
|
if data_source.value == "proposal number":
|
||||||
_open_file(file_select.value[0], None)
|
_file_open(file_select.value[0], None)
|
||||||
else:
|
else:
|
||||||
_open_file(file_select.value[0], cami_meta)
|
_file_open(file_select.value[0], cami_meta)
|
||||||
|
|
||||||
file_open_button = Button(label="Open New", width=100)
|
file_open_button = Button(label="Open New", width=100)
|
||||||
file_open_button.on_click(file_open_button_callback)
|
file_open_button.on_click(file_open_button_callback)
|
||||||
@ -249,7 +259,7 @@ def create():
|
|||||||
|
|
||||||
var = det_data[scan_motor]
|
var = det_data[scan_motor]
|
||||||
var_start = var[0]
|
var_start = var[0]
|
||||||
var_end = var[-1] + (var[-1] - var[0]) / (n_im - 1)
|
var_end = var[-1] + (var[-1] - var[0]) / (n_im - 1) if n_im != 1 else var_start + 1
|
||||||
|
|
||||||
scanning_motor_range.start = var_start
|
scanning_motor_range.start = var_start
|
||||||
scanning_motor_range.end = var_end
|
scanning_motor_range.end = var_end
|
||||||
|
@ -27,6 +27,7 @@ from bokeh.models import (
|
|||||||
Legend,
|
Legend,
|
||||||
Line,
|
Line,
|
||||||
LinearAxis,
|
LinearAxis,
|
||||||
|
LinearColorMapper,
|
||||||
MultiLine,
|
MultiLine,
|
||||||
MultiSelect,
|
MultiSelect,
|
||||||
NumberEditor,
|
NumberEditor,
|
||||||
@ -34,6 +35,7 @@ from bokeh.models import (
|
|||||||
PanTool,
|
PanTool,
|
||||||
Plot,
|
Plot,
|
||||||
RadioGroup,
|
RadioGroup,
|
||||||
|
Range1d,
|
||||||
ResetTool,
|
ResetTool,
|
||||||
Scatter,
|
Scatter,
|
||||||
Select,
|
Select,
|
||||||
@ -46,8 +48,7 @@ from bokeh.models import (
|
|||||||
WheelZoomTool,
|
WheelZoomTool,
|
||||||
Whisker,
|
Whisker,
|
||||||
)
|
)
|
||||||
from bokeh.palettes import Category10, Turbo256
|
from bokeh.palettes import Category10, Plasma256
|
||||||
from bokeh.transform import linear_cmap
|
|
||||||
from scipy import interpolate
|
from scipy import interpolate
|
||||||
|
|
||||||
import pyzebra
|
import pyzebra
|
||||||
@ -337,24 +338,31 @@ def create():
|
|||||||
|
|
||||||
ov_plot_mline_source.data.update(xs=xs, ys=ys, param=param, color=color_palette(len(xs)))
|
ov_plot_mline_source.data.update(xs=xs, ys=ys, param=param, color=color_palette(len(xs)))
|
||||||
|
|
||||||
if y:
|
ov_param_plot_scatter_source.data.update(x=x, y=y)
|
||||||
mapper["transform"].low = np.min([np.min(y) for y in ys])
|
|
||||||
mapper["transform"].high = np.max([np.max(y) for y in ys])
|
|
||||||
ov_param_plot_scatter_source.data.update(x=x, y=y, param=par)
|
|
||||||
|
|
||||||
try:
|
if y:
|
||||||
interp_f = interpolate.interp2d(x, y, par)
|
|
||||||
x1, x2 = min(x), max(x)
|
x1, x2 = min(x), max(x)
|
||||||
y1, y2 = min(y), max(y)
|
y1, y2 = min(y), max(y)
|
||||||
image = interp_f(
|
grid_x, grid_y = np.meshgrid(
|
||||||
np.linspace(x1, x2, ov_param_plot.inner_width // 10),
|
np.linspace(x1, x2, ov_param_plot.inner_width),
|
||||||
np.linspace(y1, y2, ov_param_plot.inner_height // 10),
|
np.linspace(y1, y2, ov_param_plot.inner_height),
|
||||||
assume_sorted=True,
|
|
||||||
)
|
)
|
||||||
|
image = interpolate.griddata((x, y), par, (grid_x, grid_y))
|
||||||
ov_param_plot_image_source.data.update(
|
ov_param_plot_image_source.data.update(
|
||||||
image=[image], x=[x1], y=[y1], dw=[x2 - x1], dh=[y2 - y1]
|
image=[image], x=[x1], y=[y1], dw=[x2 - x1], dh=[y2 - y1]
|
||||||
)
|
)
|
||||||
except Exception:
|
|
||||||
|
x_range = ov_param_plot.x_range
|
||||||
|
x_range.start, x_range.end = x1, x2
|
||||||
|
x_range.reset_start, x_range.reset_end = x1, x2
|
||||||
|
x_range.bounds = (x1, x2)
|
||||||
|
|
||||||
|
y_range = ov_param_plot.y_range
|
||||||
|
y_range.start, y_range.end = y1, y2
|
||||||
|
y_range.reset_start, y_range.reset_end = y1, y2
|
||||||
|
y_range.bounds = (y1, y2)
|
||||||
|
|
||||||
|
else:
|
||||||
ov_param_plot_image_source.data.update(image=[], x=[], y=[], dw=[], dh=[])
|
ov_param_plot_image_source.data.update(image=[], x=[], y=[], dw=[], dh=[])
|
||||||
|
|
||||||
def _update_param_plot():
|
def _update_param_plot():
|
||||||
@ -448,9 +456,7 @@ def create():
|
|||||||
ov_plot.toolbar.logo = None
|
ov_plot.toolbar.logo = None
|
||||||
|
|
||||||
# Overview perams plot
|
# Overview perams plot
|
||||||
ov_param_plot = Plot(
|
ov_param_plot = Plot(x_range=Range1d(), y_range=Range1d(), plot_height=450, plot_width=700)
|
||||||
x_range=DataRange1d(), y_range=DataRange1d(), plot_height=450, plot_width=700
|
|
||||||
)
|
|
||||||
|
|
||||||
ov_param_plot.add_layout(LinearAxis(axis_label="Param"), place="left")
|
ov_param_plot.add_layout(LinearAxis(axis_label="Param"), place="left")
|
||||||
ov_param_plot.add_layout(LinearAxis(axis_label="Scan motor"), place="below")
|
ov_param_plot.add_layout(LinearAxis(axis_label="Scan motor"), place="below")
|
||||||
@ -458,16 +464,16 @@ def create():
|
|||||||
ov_param_plot.add_layout(Grid(dimension=0, ticker=BasicTicker()))
|
ov_param_plot.add_layout(Grid(dimension=0, ticker=BasicTicker()))
|
||||||
ov_param_plot.add_layout(Grid(dimension=1, ticker=BasicTicker()))
|
ov_param_plot.add_layout(Grid(dimension=1, ticker=BasicTicker()))
|
||||||
|
|
||||||
|
color_mapper = LinearColorMapper(palette=Plasma256)
|
||||||
ov_param_plot_image_source = ColumnDataSource(dict(image=[], x=[], y=[], dw=[], dh=[]))
|
ov_param_plot_image_source = ColumnDataSource(dict(image=[], x=[], y=[], dw=[], dh=[]))
|
||||||
ov_param_plot.add_glyph(
|
ov_param_plot.add_glyph(
|
||||||
ov_param_plot_image_source, Image(image="image", x="x", y="y", dw="dw", dh="dh")
|
ov_param_plot_image_source,
|
||||||
|
Image(image="image", x="x", y="y", dw="dw", dh="dh", color_mapper=color_mapper),
|
||||||
)
|
)
|
||||||
|
|
||||||
ov_param_plot_scatter_source = ColumnDataSource(dict(x=[], y=[], param=[]))
|
ov_param_plot_scatter_source = ColumnDataSource(dict(x=[], y=[]))
|
||||||
mapper = linear_cmap(field_name="param", palette=Turbo256, low=0, high=50)
|
|
||||||
ov_param_plot.add_glyph(
|
ov_param_plot.add_glyph(
|
||||||
ov_param_plot_scatter_source,
|
ov_param_plot_scatter_source, Scatter(x="x", y="y", marker="dot", size=15),
|
||||||
Scatter(x="x", y="y", line_color=mapper, fill_color=mapper, size=10),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
ov_param_plot.add_tools(PanTool(), WheelZoomTool(), ResetTool())
|
ov_param_plot.add_tools(PanTool(), WheelZoomTool(), ResetTool())
|
||||||
|
@ -170,7 +170,7 @@ def parse_1D(fileobj, data_type):
|
|||||||
while len(counts) < s["n_points"]:
|
while len(counts) < s["n_points"]:
|
||||||
counts.extend(map(float, next(fileobj).split()))
|
counts.extend(map(float, next(fileobj).split()))
|
||||||
s["counts"] = np.array(counts)
|
s["counts"] = np.array(counts)
|
||||||
s["counts_err"] = np.sqrt(s["counts"])
|
s["counts_err"] = np.sqrt(np.maximum(s["counts"], 1))
|
||||||
|
|
||||||
if s["h"].is_integer() and s["k"].is_integer() and s["l"].is_integer():
|
if s["h"].is_integer() and s["k"].is_integer() and s["l"].is_integer():
|
||||||
s["h"], s["k"], s["l"] = map(int, (s["h"], s["k"], s["l"]))
|
s["h"], s["k"], s["l"] = map(int, (s["h"], s["k"], s["l"]))
|
||||||
@ -208,7 +208,7 @@ def parse_1D(fileobj, data_type):
|
|||||||
for name in col_names:
|
for name in col_names:
|
||||||
s[name] = np.array(s[name])
|
s[name] = np.array(s[name])
|
||||||
|
|
||||||
s["counts_err"] = np.sqrt(s["counts"])
|
s["counts_err"] = np.sqrt(np.maximum(s["counts"], 1))
|
||||||
|
|
||||||
s["scan_motors"] = []
|
s["scan_motors"] = []
|
||||||
for motor, step in zip(motors, steps):
|
for motor, step in zip(motors, steps):
|
||||||
|
@ -220,8 +220,7 @@ def fit_scan(scan, model_dict, fit_from=None, fit_to=None):
|
|||||||
else:
|
else:
|
||||||
model += _model
|
model += _model
|
||||||
|
|
||||||
weights = [1 / y_err if y_err != 0 else 1 for y_err in y_err]
|
scan["fit"] = model.fit(y_fit, x=x_fit, weights=1 / y_err)
|
||||||
scan["fit"] = model.fit(y_fit, x=x_fit, weights=weights)
|
|
||||||
|
|
||||||
|
|
||||||
def get_area(scan, area_method, lorentz):
|
def get_area(scan, area_method, lorentz):
|
||||||
|
@ -103,12 +103,16 @@ def read_detector_data(filepath, cami_meta=None):
|
|||||||
det_data["name"] = h5f["/entry1/sample/name"][0].decode()
|
det_data["name"] = h5f["/entry1/sample/name"][0].decode()
|
||||||
det_data["cell"] = h5f["/entry1/sample/cell"][:]
|
det_data["cell"] = h5f["/entry1/sample/cell"][:]
|
||||||
|
|
||||||
for var in ("omega", "gamma", "nu", "chi", "phi"):
|
if n == 1:
|
||||||
if abs(det_data[var][0] - det_data[var][-1]) > 0.1:
|
# a default motor for a single frame file
|
||||||
det_data["scan_motor"] = var
|
det_data["scan_motor"] = "omega"
|
||||||
break
|
|
||||||
else:
|
else:
|
||||||
raise ValueError("No angles that vary")
|
for var in ("omega", "gamma", "nu", "chi", "phi"):
|
||||||
|
if abs(det_data[var][0] - det_data[var][-1]) > 0.1:
|
||||||
|
det_data["scan_motor"] = var
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
raise ValueError("No angles that vary")
|
||||||
|
|
||||||
# optional parameters
|
# optional parameters
|
||||||
if "/entry1/sample/magnetic_field" in h5f:
|
if "/entry1/sample/magnetic_field" in h5f:
|
||||||
@ -132,7 +136,7 @@ def read_detector_data(filepath, cami_meta=None):
|
|||||||
|
|
||||||
if "detector parameters" in cami_meta:
|
if "detector parameters" in cami_meta:
|
||||||
cami_meta_detparam = cami_meta["detector parameters"]
|
cami_meta_detparam = cami_meta["detector parameters"]
|
||||||
if "dist1" in cami_meta_detparam:
|
if "dist2" in cami_meta_detparam:
|
||||||
det_data["ddist"] = cami_meta_detparam["dist1"]
|
det_data["ddist"] = cami_meta_detparam["dist2"]
|
||||||
|
|
||||||
return det_data
|
return det_data
|
||||||
|
Reference in New Issue
Block a user