generated from neutrons/python_project_template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
121 additions
and
227 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,148 +1,75 @@ | ||
import matplotlib.pylab as plt | ||
import matplotlib.pyplot as plt | ||
|
||
from tavi.data.plotter import Plot2DManager | ||
from tavi.data.scan_old.spice_to_nexus import convert_spice_to_nexus | ||
from tavi.data.tavi import TAVI | ||
from tavi.instrument.resolution.cooper_nathans import CN | ||
from tavi.sample.xtal import Xtal | ||
|
||
spice_folder = "./test_data/exp813" | ||
nexus_folder = "./test_data/IPTS34735_HB3_exp0813" | ||
if False: | ||
convert_spice_to_nexus(spice_folder, nexus_folder) | ||
from tavi.plotter import Plot2D | ||
|
||
tavi = TAVI() | ||
|
||
tavi_file_name = "./test_data/tavi_test_exp0813.h5" | ||
tavi.new(tavi_file_name) | ||
tavi.load_nexus_data_from_disk(nexus_folder) | ||
dataset = tavi.data["IPTS34735_HB3_exp0813"] | ||
# load two experiments from SPICE the first time | ||
if False: | ||
tavi.load_spice_data_from_disk("./test_data/IPTS-34735/exp813/") | ||
tavi.load_spice_data_from_disk("./test_data/IPTS-34735/exp823/") | ||
tavi.save("./test_data/tavi_MnTe.h5") | ||
|
||
tavi.open_file("./test_data/tavi_MnTe.h5") | ||
|
||
# -------------- H0L const Q scans ------------ | ||
scan_nums = [37, 39, 40] + list(range(44, 64)) + list(range(65, 69)) + list(range(84, 97)) | ||
scan_list1 = [dataset[f"scan{i:04}"] for i in scan_nums] | ||
sg1 = tavi.generate_scan_group( | ||
signals=scan_list1, | ||
signal_axes=("qh", "en", "detector"), | ||
) | ||
contour1 = sg1.generate_contour(rebin_steps=(0.025, 0.25), norm_channel="mcu", norm_val=1) | ||
|
||
plt2d1 = Plot2DManager() | ||
plt2d1.zlim = [0, 0.5] | ||
plt2d1.ylim = [0, 55] | ||
plt2d1.title = "" | ||
plt2d1.plot_contour(*contour1) | ||
# --------------------------------------------------------- | ||
# resolution calculation | ||
# --------------------------------------------------------- | ||
R0 = False | ||
hb3 = CN() | ||
instrument_config_json_path = "./src/tavi/instrument/instrument_params/hb3_mnte.json" | ||
hb3.load_instrument_params_from_json(instrument_config_json_path) | ||
sample_json_path = "./test_data/test_samples/mnte.json" | ||
mnte = Xtal.from_json(sample_json_path) | ||
hb3.mount_sample(mnte) | ||
|
||
# ----------------------------------------------- | ||
# generate rez plot for point (1.3, 0, 1.3) | ||
# ----------------------------------------------- | ||
rez_q = hb3.cooper_nathans( | ||
ei=35 + 14.7, | ||
ef=14.7, | ||
hkl=(1.3, 0, 1.3), | ||
projection=None, | ||
R0=R0, | ||
) | ||
rez_q.plot() | ||
print(rez_q.mat) | ||
# ------------------------------------- | ||
rez_hkl = hb3.cooper_nathans( | ||
ei=35 + 14.7, | ||
ef=14.7, | ||
hkl=(1.3, 0, 1.3), | ||
R0=R0, | ||
) | ||
rez_hkl.plot() | ||
print(rez_hkl.mat) | ||
# -------------------------------------- | ||
projection = ((1, 0, 1), (-1, 2, 0), (-0.2776, 0, 0.9607)) | ||
|
||
rez = hb3.cooper_nathans( | ||
ei=35 + 14.7, | ||
ef=14.7, | ||
hkl=(1.3, 0, 1.3), | ||
projection=projection, | ||
R0=R0, | ||
# scan_list1 = [37, 39, 40] + list(range(44, 64)) + list(range(65, 69)) + list(range(84, 97)) | ||
# sg1 = tavi.combine_scans(scan_list1, name="dispH") | ||
|
||
|
||
# scan_data_2d = sg1.get_data( | ||
# axes=("qh", "en", "detector"), | ||
# norm_to=(1, "mcu"), | ||
# grid=(0.025, 0.3), | ||
# ) | ||
|
||
# p1 = Plot2D() | ||
# p1.add_contour(scan_data_2d, cmap="turbo", vmax=1) | ||
# p1.zlim = [0, 0.5] | ||
# p1.ylim = [0, 50] | ||
# fig, ax = plt.subplots() | ||
# p1.plot(ax) | ||
|
||
|
||
# -------------- (H, 0. 2-H) Ef = 14.7 const Q scans ------------ | ||
|
||
scans = list(range(88, 133)) | ||
|
||
scan_list2 = [("IPTS34735_HB3_exp0823", scan) for scan in scans] | ||
sg2 = tavi.combine_scans(scan_list2, name="dispH (H,0,2-H) Ef=14.7 meV") | ||
scan_data_2 = sg2.get_data( | ||
axes=("qh", "en", "detector"), | ||
norm_to=(1, "mcu"), | ||
grid=(0.025, 0.5), | ||
) | ||
rez.plot() | ||
# ----------------------------------------------- | ||
# generate 2D rez plot | ||
# ----------------------------------------------- | ||
# projection = ((1, 0, 1), (-1, 2, 0), (-1, 0, 1)) | ||
projection = ((1, 0, 1), (-1, 2, 0), (-0.2776, 0, 0.9607)) | ||
q1 = [1, 1.5, 0.1] # start, stop, step | ||
q2 = 0 | ||
q3 = 0 | ||
en = [-1, 45, 5] # start, stop, step | ||
|
||
ef = 14.7 | ||
p2 = Plot2D() | ||
p2.add_contour(scan_data_2, cmap="turbo", vmin=0, vmax=1) | ||
p2.title = sg2.name | ||
p2.ylim = [0, 50] | ||
fig, ax = plt.subplots() | ||
im = p2.plot(ax) | ||
fig.colorbar(im) | ||
|
||
plt2d1.rez_plot(hb3, projection, q1, q2, q3, en, ef, R0) | ||
# -------------- (H, 0. 2-H) Ef = 30.5 meV const Q scans ------------ | ||
|
||
plt.show() | ||
scans = list(range(133, 167)) | ||
|
||
# ----------------- | ||
# s1 = dataset["scan0045"] | ||
# # x, y, xerr, yerr, xlabel, ylabel, title, label | ||
# curve1 = s1.generate_curve(norm_channel="mcu", norm_val=1) | ||
# (x, y, xerr, yerr, xlabel, ylabel, title, label) = curve1 | ||
# label += " H/L=1.15" | ||
# curve1 = (x, y, xerr, yerr, xlabel, ylabel, title, label) | ||
|
||
# s2 = dataset["scan0046"] | ||
# curve2 = s2.generate_curve(norm_channel="mcu", norm_val=1) | ||
# (x, y, xerr, yerr, xlabel, ylabel, title, label) = curve2 | ||
# label += " H/L=1.20" | ||
# curve2 = (x, y, xerr, yerr, xlabel, ylabel, title, label) | ||
|
||
# ----------------- | ||
# s1 = dataset["scan0049"] | ||
# # x, y, xerr, yerr, xlabel, ylabel, title, label | ||
# curve1 = s1.generate_curve(norm_channel="mcu", norm_val=1) | ||
# (x, y, xerr, yerr, xlabel, ylabel, title, label) = curve1 | ||
# label += " H/L=1.3" | ||
# curve1 = (x, y, xerr, yerr, xlabel, ylabel, title, label) | ||
|
||
# s2 = dataset["scan0050"] | ||
# curve2 = s2.generate_curve(norm_channel="mcu", norm_val=1) | ||
# (x, y, xerr, yerr, xlabel, ylabel, title, label) = curve2 | ||
# label += " H/L=1.3" | ||
# curve2 = (x, y, xerr, yerr, xlabel, ylabel, title, label) | ||
|
||
# s3 = dataset["scan0051"] | ||
# # x, y, xerr, yerr, xlabel, ylabel, title, label | ||
# curve3 = s3.generate_curve(norm_channel="mcu", norm_val=1) | ||
# (x, y, xerr, yerr, xlabel, ylabel, title, label) = curve3 | ||
# label += " H/L=1.325" | ||
# curve3 = (x, y, xerr, yerr, xlabel, ylabel, title, label) | ||
|
||
# s4 = dataset["scan0052"] | ||
# curve4 = s4.generate_curve(norm_channel="mcu", norm_val=1) | ||
# (x, y, xerr, yerr, xlabel, ylabel, title, label) = curve4 | ||
# label += " H/L=1.325" | ||
# curve4 = (x, y, xerr, yerr, xlabel, ylabel, title, label) | ||
|
||
# p1 = Plot1DManager() | ||
# p1.plot_curve(*curve1) | ||
|
||
# p1.plot_curve(*curve3) | ||
# p1.plot_curve(*curve2) | ||
# p1.plot_curve(*curve4) | ||
|
||
# ----------------- | ||
# s1 = dataset["scan0062"] | ||
# # x, y, xerr, yerr, xlabel, ylabel, title, label | ||
# curve1 = s1.generate_curve(norm_channel="mcu", norm_val=1) | ||
# p1 = Plot1DManager() | ||
# p1.plot_curve(*curve1) | ||
# plt.show() | ||
scan_list3 = [("IPTS34735_HB3_exp0823", scan) for scan in scans] | ||
sg3 = tavi.combine_scans(scan_list3, name="dispH (H,0,2-H) Ef=30.5 meV") | ||
scan_data_3 = sg3.get_data( | ||
axes=("qh", "en", "detector"), | ||
norm_to=(1, "mcu"), | ||
grid=(0.025, 0.5), | ||
) | ||
|
||
p3 = Plot2D() | ||
p3.add_contour(scan_data_3, cmap="turbo", vmin=0, vmax=1) | ||
p3.title = sg3.name | ||
p3.ylim = [0, 50] | ||
|
||
fig, ax = plt.subplots() | ||
im = p3.plot(ax) | ||
fig.colorbar(im) | ||
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import matplotlib.pyplot as plt | ||
|
||
from tavi.data.tavi import TAVI | ||
from tavi.plotter import Plot1D | ||
|
||
tavi = TAVI() | ||
|
||
# load two experiments from SPICE the first time | ||
if False: | ||
tavi.load_spice_data_from_disk("./test_data/IPTS-34735/exp813/") | ||
tavi.load_spice_data_from_disk("./test_data/IPTS-34735/exp823/") | ||
tavi.save("./test_data/tavi_MnTe.h5") | ||
|
||
tavi.open_file("./test_data/tavi_MnTe.h5") | ||
|
||
|
||
# overplot two curves with different Ei's | ||
# 120,121, 145 | ||
scan1 = [("IPTS34735_HB3_exp0823", scan) for scan in [120, 121]] | ||
sg4 = tavi.combine_scans(scan1, name="Ef=14.7 meV") | ||
l1 = sg4.get_data(norm_to=(1, "mcu")) | ||
|
||
scan2 = tavi.get_scan(("IPTS34735_HB3_exp0823", 145)) | ||
l2 = scan2.get_data(norm_to=(1, "mcu")) | ||
|
||
p4 = Plot1D() | ||
p4.add_scan(l1, fmt="o") | ||
p4.add_scan(l2, fmt="s") | ||
fig, ax = plt.subplots() | ||
p4.plot(ax) | ||
|
||
plt.show() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using HDF5 | ||
filename = "./test_data/tavi_rez.h5" | ||
fid = h5open(filename, "r") | ||
pdata = fid["processed_data"] | ||
scan0042 = pdata["scan0042"] | ||
rez_mat = read(scan0042, "rez_mat") | ||
|
||
scan0001 = fid["data"]["IPTS32124_CG4C_exp0424"]["scan0001"] | ||
read(scan0001["sample"], "unit_cell") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.