Skip to content

Commit

Permalink
Updated MnTe scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
bingli621 committed Nov 4, 2024
1 parent d3637b4 commit d41c23e
Show file tree
Hide file tree
Showing 17 changed files with 121 additions and 227 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion scripts/HoV6Sn6_contour.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
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.plotter import Plot2DManager

spice_folder = "./test_data/exp1031/"
nexus_file_name = "./test_data/nexus_exp1031.h5"
Expand Down
199 changes: 63 additions & 136 deletions scripts/MnTe_contour.py
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()
32 changes: 32 additions & 0 deletions scripts/MnTe_lines.py
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()
75 changes: 0 additions & 75 deletions scripts/MnTe_new.py

This file was deleted.

9 changes: 9 additions & 0 deletions scripts/rez_loader.jl
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")
8 changes: 4 additions & 4 deletions scripts/scans_rez.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
qk_list = scan.data["qk"]
ql_list = scan.data["ql"]

projection = ((1, 1, 0), (0, 0, 1), (1, -1, 0))
# projection = ((1, 1, 0), (0, 0, 1), (1, -1, 0))
R0 = True

rez_mat_list = []
Expand All @@ -40,7 +40,7 @@
ei=ei_list[i],
ef=ef_list[i],
hkl=(qh_list[i], qk_list[i], ql_list[i]),
projection=projection,
# projection=projection,
R0=R0,
)
rez_mat_list.append(rez.mat)
Expand All @@ -56,11 +56,11 @@
err=NXdataset(ds=scan_data.err),
rez_mat=NXdataset(ds=rez_mat_list),
rez_r0=NXdataset(ds=rez_r0_list),
projection=NXdataset(ds=projection),
# projection=NXdataset(ds=projection),
)

tavi.processed_data.update(NexusEntry._dict_to_nexus_entry({scan.name: rez_entry}))


file_path = "./test_data/tavi_rez.h5"
file_path = "./test_data/tavi_rez_HKLE.h5"
tavi.save(file_path)
2 changes: 1 addition & 1 deletion scripts/test_fit_group.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import matplotlib.pyplot as plt

from tavi.data.plotter import Plot1DManager, Plot2DManager
from tavi.data.tavi import TAVI
from tavi.plotter import Plot1DManager, Plot2DManager


def test_fit_group(tavi):
Expand Down
2 changes: 1 addition & 1 deletion scripts/test_plotter.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import matplotlib.pylab as plt

from tavi.data.plotter import Plot1DManager, Plot2DManager
from tavi.data.tavi import TAVI
from tavi.instrument.resolution.cooper_nathans import CN
from tavi.plotter import Plot1DManager, Plot2DManager

# from tavi.instrument.instrument_params.python_dicts.cg4c import cg4c_config_params
# from tests.test_data_folder.test_samples.python_samples.nitio3 import nitio3
Expand Down
Loading

0 comments on commit d41c23e

Please sign in to comment.