Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
10bcabd7f9 | |||
bee8263184 | |||
98a76ebf63 | |||
12ba0b291b | |||
a719f10f4f | |||
aaff6032c8 | |||
3fb3fe573b | |||
1687337f26 | |||
53ceac21aa | |||
741a09819c | |||
3c619713d5 | |||
3d5a4ed6aa | |||
b2129805dc | |||
92765b5665 |
@ -5,4 +5,4 @@ from pyzebra.h5 import *
|
||||
from pyzebra.utils import *
|
||||
from pyzebra.xtal import *
|
||||
|
||||
__version__ = "0.6.1"
|
||||
__version__ = "0.6.5"
|
||||
|
@ -178,7 +178,7 @@ def create():
|
||||
|
||||
new_data1 = []
|
||||
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:
|
||||
base, ext = os.path.splitext(f_name)
|
||||
try:
|
||||
|
@ -141,22 +141,29 @@ def create():
|
||||
|
||||
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():
|
||||
nonlocal zebra_data
|
||||
zebra_data = []
|
||||
for f_name in file_select.value:
|
||||
zebra_data.append(pyzebra.read_detector_data(f_name))
|
||||
|
||||
_init_datatable()
|
||||
_file_open()
|
||||
|
||||
file_open_button = Button(label="Open New", width=100)
|
||||
file_open_button.on_click(file_open_button_callback)
|
||||
|
||||
def file_append_button_callback():
|
||||
for f_name in file_select.value:
|
||||
zebra_data.append(pyzebra.read_detector_data(f_name))
|
||||
|
||||
_init_datatable()
|
||||
_file_open()
|
||||
|
||||
file_append_button = Button(label="Append", width=100)
|
||||
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.on_change("value", upload_cami_button_callback)
|
||||
|
||||
def _open_file(file, cami_meta):
|
||||
def _file_open(file, cami_meta):
|
||||
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.high = det_data["data"].shape[0] - 1
|
||||
index_slider.end = det_data["data"].shape[0] - 1
|
||||
index_spinner.high = last_im_index
|
||||
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"]
|
||||
if zebra_mode == "nb":
|
||||
@ -125,7 +135,7 @@ def create():
|
||||
update_overview_plot()
|
||||
|
||||
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_button = FileInput(accept=".hdf", width=200)
|
||||
@ -136,9 +146,9 @@ def create():
|
||||
return
|
||||
|
||||
if data_source.value == "proposal number":
|
||||
_open_file(file_select.value[0], None)
|
||||
_file_open(file_select.value[0], None)
|
||||
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.on_click(file_open_button_callback)
|
||||
@ -249,7 +259,7 @@ def create():
|
||||
|
||||
var = det_data[scan_motor]
|
||||
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.end = var_end
|
||||
|
@ -27,6 +27,7 @@ from bokeh.models import (
|
||||
Legend,
|
||||
Line,
|
||||
LinearAxis,
|
||||
LinearColorMapper,
|
||||
MultiLine,
|
||||
MultiSelect,
|
||||
NumberEditor,
|
||||
@ -34,6 +35,7 @@ from bokeh.models import (
|
||||
PanTool,
|
||||
Plot,
|
||||
RadioGroup,
|
||||
Range1d,
|
||||
ResetTool,
|
||||
Scatter,
|
||||
Select,
|
||||
@ -46,8 +48,7 @@ from bokeh.models import (
|
||||
WheelZoomTool,
|
||||
Whisker,
|
||||
)
|
||||
from bokeh.palettes import Category10, Turbo256
|
||||
from bokeh.transform import linear_cmap
|
||||
from bokeh.palettes import Category10, Plasma256
|
||||
from scipy import interpolate
|
||||
|
||||
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)))
|
||||
|
||||
if 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)
|
||||
ov_param_plot_scatter_source.data.update(x=x, y=y)
|
||||
|
||||
try:
|
||||
interp_f = interpolate.interp2d(x, y, par)
|
||||
if y:
|
||||
x1, x2 = min(x), max(x)
|
||||
y1, y2 = min(y), max(y)
|
||||
image = interp_f(
|
||||
np.linspace(x1, x2, ov_param_plot.inner_width // 10),
|
||||
np.linspace(y1, y2, ov_param_plot.inner_height // 10),
|
||||
assume_sorted=True,
|
||||
grid_x, grid_y = np.meshgrid(
|
||||
np.linspace(x1, x2, ov_param_plot.inner_width),
|
||||
np.linspace(y1, y2, ov_param_plot.inner_height),
|
||||
)
|
||||
image = interpolate.griddata((x, y), par, (grid_x, grid_y))
|
||||
ov_param_plot_image_source.data.update(
|
||||
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=[])
|
||||
|
||||
def _update_param_plot():
|
||||
@ -448,9 +456,7 @@ def create():
|
||||
ov_plot.toolbar.logo = None
|
||||
|
||||
# Overview perams plot
|
||||
ov_param_plot = Plot(
|
||||
x_range=DataRange1d(), y_range=DataRange1d(), plot_height=450, plot_width=700
|
||||
)
|
||||
ov_param_plot = Plot(x_range=Range1d(), y_range=Range1d(), 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="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=1, ticker=BasicTicker()))
|
||||
|
||||
color_mapper = LinearColorMapper(palette=Plasma256)
|
||||
ov_param_plot_image_source = ColumnDataSource(dict(image=[], x=[], y=[], dw=[], dh=[]))
|
||||
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=[]))
|
||||
mapper = linear_cmap(field_name="param", palette=Turbo256, low=0, high=50)
|
||||
ov_param_plot_scatter_source = ColumnDataSource(dict(x=[], y=[]))
|
||||
ov_param_plot.add_glyph(
|
||||
ov_param_plot_scatter_source,
|
||||
Scatter(x="x", y="y", line_color=mapper, fill_color=mapper, size=10),
|
||||
ov_param_plot_scatter_source, Scatter(x="x", y="y", marker="dot", size=15),
|
||||
)
|
||||
|
||||
ov_param_plot.add_tools(PanTool(), WheelZoomTool(), ResetTool())
|
||||
|
@ -170,7 +170,7 @@ def parse_1D(fileobj, data_type):
|
||||
while len(counts) < s["n_points"]:
|
||||
counts.extend(map(float, next(fileobj).split()))
|
||||
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():
|
||||
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:
|
||||
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"] = []
|
||||
for motor, step in zip(motors, steps):
|
||||
|
@ -131,7 +131,7 @@ def merge_scans(scan_into, scan_from):
|
||||
|
||||
scan_into[scan_motor] = pos_tmp
|
||||
scan_into["counts"] = val_tmp / num_tmp
|
||||
scan_into["counts_err"] = np.sqrt(err_tmp)
|
||||
scan_into["counts_err"] = np.sqrt(err_tmp) / num_tmp
|
||||
|
||||
scan_from["export"] = False
|
||||
|
||||
@ -220,8 +220,7 @@ def fit_scan(scan, model_dict, fit_from=None, fit_to=None):
|
||||
else:
|
||||
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=weights)
|
||||
scan["fit"] = model.fit(y_fit, x=x_fit, weights=1 / y_err)
|
||||
|
||||
|
||||
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["cell"] = h5f["/entry1/sample/cell"][:]
|
||||
|
||||
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
|
||||
if n == 1:
|
||||
# a default motor for a single frame file
|
||||
det_data["scan_motor"] = "omega"
|
||||
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
|
||||
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:
|
||||
cami_meta_detparam = cami_meta["detector parameters"]
|
||||
if "dist1" in cami_meta_detparam:
|
||||
det_data["ddist"] = cami_meta_detparam["dist1"]
|
||||
if "dist2" in cami_meta_detparam:
|
||||
det_data["ddist"] = cami_meta_detparam["dist2"]
|
||||
|
||||
return det_data
|
||||
|
Reference in New Issue
Block a user