parent
4dae756b3e
commit
c2be907113
@ -207,10 +207,11 @@ def create():
|
|||||||
scan_motor = scan["scan_motor"]
|
scan_motor = scan["scan_motor"]
|
||||||
|
|
||||||
y = scan["counts"]
|
y = scan["counts"]
|
||||||
|
y_err = scan["counts_err"]
|
||||||
x = scan[scan_motor]
|
x = scan[scan_motor]
|
||||||
|
|
||||||
plot.axis[0].axis_label = scan_motor
|
plot.axis[0].axis_label = scan_motor
|
||||||
plot_scatter_source.data.update(x=x, y=y, y_upper=y + np.sqrt(y), y_lower=y - np.sqrt(y))
|
plot_scatter_source.data.update(x=x, y=y, y_upper=y + y_err, y_lower=y - y_err)
|
||||||
|
|
||||||
fit = scan.get("fit")
|
fit = scan.get("fit")
|
||||||
if fit is not None:
|
if fit is not None:
|
||||||
|
@ -235,10 +235,11 @@ def create():
|
|||||||
scan_motor = scan["scan_motor"]
|
scan_motor = scan["scan_motor"]
|
||||||
|
|
||||||
y = scan["counts"]
|
y = scan["counts"]
|
||||||
|
y_err = scan["counts_err"]
|
||||||
x = scan[scan_motor]
|
x = scan[scan_motor]
|
||||||
|
|
||||||
plot.axis[0].axis_label = scan_motor
|
plot.axis[0].axis_label = scan_motor
|
||||||
plot_scatter_source.data.update(x=x, y=y, y_upper=y + np.sqrt(y), y_lower=y - np.sqrt(y))
|
plot_scatter_source.data.update(x=x, y=y, y_upper=y + y_err, y_lower=y - y_err)
|
||||||
|
|
||||||
fit = scan.get("fit")
|
fit = scan.get("fit")
|
||||||
if fit is not None:
|
if fit is not None:
|
||||||
|
@ -169,6 +169,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"])
|
||||||
|
|
||||||
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"]))
|
||||||
@ -204,6 +205,8 @@ 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["scan_motors"] = []
|
s["scan_motors"] = []
|
||||||
for motor, step in zip(motors, steps):
|
for motor, step in zip(motors, steps):
|
||||||
if step == 0:
|
if step == 0:
|
||||||
|
@ -29,6 +29,7 @@ def normalize_dataset(dataset, monitor=100_000):
|
|||||||
for scan in dataset:
|
for scan in dataset:
|
||||||
monitor_ratio = monitor / scan["monitor"]
|
monitor_ratio = monitor / scan["monitor"]
|
||||||
scan["counts"] *= monitor_ratio
|
scan["counts"] *= monitor_ratio
|
||||||
|
scan["counts_err"] *= monitor_ratio
|
||||||
scan["monitor"] = monitor
|
scan["monitor"] = monitor
|
||||||
|
|
||||||
|
|
||||||
@ -83,6 +84,7 @@ def merge_scans(scan_into, scan_from):
|
|||||||
if "init_omega" not in scan_into:
|
if "init_omega" not in scan_into:
|
||||||
scan_into["init_omega"] = scan_into["omega"]
|
scan_into["init_omega"] = scan_into["omega"]
|
||||||
scan_into["init_counts"] = scan_into["counts"]
|
scan_into["init_counts"] = scan_into["counts"]
|
||||||
|
scan_into["init_counts_err"] = scan_into["counts_err"]
|
||||||
|
|
||||||
if "merged_scans" not in scan_into:
|
if "merged_scans" not in scan_into:
|
||||||
scan_into["merged_scans"] = []
|
scan_into["merged_scans"] = []
|
||||||
@ -93,15 +95,20 @@ def merge_scans(scan_into, scan_from):
|
|||||||
and np.max(np.abs(scan_into["omega"] - scan_from["omega"])) < 0.0005
|
and np.max(np.abs(scan_into["omega"] - scan_from["omega"])) < 0.0005
|
||||||
):
|
):
|
||||||
scan_into["counts"] = (scan_into["counts"] + scan_from["counts"]) / 2
|
scan_into["counts"] = (scan_into["counts"] + scan_from["counts"]) / 2
|
||||||
|
scan_into["counts_err"] = np.sqrt(
|
||||||
|
scan_into["counts_err"] ** 2 + scan_from["counts_err"] ** 2
|
||||||
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
omega = np.concatenate((scan_into["omega"], scan_from["omega"]))
|
omega = np.concatenate((scan_into["omega"], scan_from["omega"]))
|
||||||
counts = np.concatenate((scan_into["counts"], scan_from["counts"]))
|
counts = np.concatenate((scan_into["counts"], scan_from["counts"]))
|
||||||
|
counts_err = np.concatenate((scan_into["counts_err"], scan_from["counts_err"]))
|
||||||
|
|
||||||
index = np.argsort(omega)
|
index = np.argsort(omega)
|
||||||
|
|
||||||
scan_into["omega"] = omega[index]
|
scan_into["omega"] = omega[index]
|
||||||
scan_into["counts"] = counts[index]
|
scan_into["counts"] = counts[index]
|
||||||
|
scan_into["counts_err"] = counts_err[index]
|
||||||
|
|
||||||
scan_from["active"] = False
|
scan_from["active"] = False
|
||||||
|
|
||||||
@ -114,8 +121,10 @@ def restore_scan(scan):
|
|||||||
if "init_omega" in scan:
|
if "init_omega" in scan:
|
||||||
scan["omega"] = scan["init_omega"]
|
scan["omega"] = scan["init_omega"]
|
||||||
scan["counts"] = scan["init_counts"]
|
scan["counts"] = scan["init_counts"]
|
||||||
|
scan["counts_err"] = scan["init_counts_err"]
|
||||||
del scan["init_omega"]
|
del scan["init_omega"]
|
||||||
del scan["init_counts"]
|
del scan["init_counts"]
|
||||||
|
del scan["init_counts_err"]
|
||||||
|
|
||||||
if "merged_scans" in scan:
|
if "merged_scans" in scan:
|
||||||
for merged_scan in scan["merged_scans"]:
|
for merged_scan in scan["merged_scans"]:
|
||||||
@ -130,11 +139,13 @@ def fit_scan(scan, model_dict, fit_from=None, fit_to=None):
|
|||||||
fit_to = np.inf
|
fit_to = np.inf
|
||||||
|
|
||||||
y_fit = scan["counts"]
|
y_fit = scan["counts"]
|
||||||
|
y_err = scan["counts_err"]
|
||||||
x_fit = scan[scan["scan_motor"]]
|
x_fit = scan[scan["scan_motor"]]
|
||||||
|
|
||||||
# apply fitting range
|
# apply fitting range
|
||||||
fit_ind = (fit_from <= x_fit) & (x_fit <= fit_to)
|
fit_ind = (fit_from <= x_fit) & (x_fit <= fit_to)
|
||||||
y_fit = y_fit[fit_ind]
|
y_fit = y_fit[fit_ind]
|
||||||
|
y_err = y_err[fit_ind]
|
||||||
x_fit = x_fit[fit_ind]
|
x_fit = x_fit[fit_ind]
|
||||||
|
|
||||||
model = None
|
model = None
|
||||||
@ -182,7 +193,7 @@ def fit_scan(scan, model_dict, fit_from=None, fit_to=None):
|
|||||||
else:
|
else:
|
||||||
model += _model
|
model += _model
|
||||||
|
|
||||||
weights = [1 / np.sqrt(val) if val != 0 else 1 for val in y_fit]
|
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=weights)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user