Skip to content

Commit

Permalink
fixed CN class
Browse files Browse the repository at this point in the history
  • Loading branch information
Bing Li committed Sep 11, 2024
1 parent b70a41e commit 7fa37ca
Show file tree
Hide file tree
Showing 200 changed files with 8,453 additions and 398 deletions.
136 changes: 99 additions & 37 deletions scripts/MnTe_contour.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import matplotlib.pyplot as plt
import matplotlib.pylab as plt

from tavi.data.spice_to_nexus import convert_spice_to_nexus
from tavi.data.tavi import TAVI
from tavi.plotter import Plot1DManager, Plot2DManager
from tavi.instrument.resolution.cooper_nathans import CN
from tavi.plotter import Plot2DManager
from tavi.sample.xtal import Xtal

spice_folder = "./test_data/exp813"
nexus_folder = "./test_data/IPTS34735_HB3_exp0813"
if True:
if False:
convert_spice_to_nexus(spice_folder, nexus_folder)

tavi = TAVI()
Expand All @@ -17,20 +19,75 @@
dataset = tavi.data["IPTS34735_HB3_exp0813"]

# -------------- H0L const Q scans ------------
scan_nums = [37, 39, 40, 44, 45, 46, 47, 48, 49, 50, 51, 52]
scan_nums = [37, 39, 40] + list(range(44, 64))
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.5), norm_channel="mcu", norm_val=1)
contour1 = sg1.generate_contour(rebin_steps=(0.025, 0.25), norm_channel="mcu", norm_val=1)

plt2d1 = Plot2DManager()
plt2d1.zlim = [0, 1]
plt2d1.ylim = [0, 45]
plt2d1.zlim = [0, 1.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 = hb3.cooper_nathans(
ei=35 + 14.7,
ef=14.7,
hkl=(1.3, 0, 1.3),
projection=None,
r0=R0,
)
rez.plot()
# -------------------------------------
rez = hb3.cooper_nathans(
ei=35 + 14.7,
ef=14.7,
hkl=(1.3, 0, 1.3),
r0=R0,
)
rez.plot()
# --------------------------------------
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,
)
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 = [2, 45, 5] # start, stop, step

ef = 14.7

plt2d1.rez_plot(hb3, projection, q1, q2, q3, en, ef, R0)

plt.show()

# -----------------
# s1 = dataset["scan0045"]
Expand All @@ -46,39 +103,44 @@
# 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)

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)
# 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)

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)
# 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)

p1 = Plot1DManager()
p1.plot_curve(*curve1)
# 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.plot_curve(*curve3)
p1.plot_curve(*curve2)
p1.plot_curve(*curve4)
# p1 = Plot1DManager()
# p1.plot_curve(*curve1)

# p1.plot_curve(*curve3)
# p1.plot_curve(*curve2)
# p1.plot_curve(*curve4)

plt.show()
# -----------------
# 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()
21 changes: 11 additions & 10 deletions scripts/example_cooper_nathans.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
import numpy as np

from tavi.instrument.resolution.cooper_nathans import CN
from tavi.sample.xtal import Xtal

np.set_printoptions(floatmode="fixed", precision=4)


def test_copper_nathans_localQ(tas_params):
tas, ei, ef, hkl, _, R0 = tas_params
tas, ei, ef, hkl, _, r0 = tas_params

rez = tas.cooper_nathans(ei=ei, ef=ef, hkl=hkl, projection=None, R0=R0)
rez = tas.cooper_nathans(ei=ei, ef=ef, hkl=hkl, projection=None, r0=r0)
rez.plot()


Expand All @@ -35,9 +36,9 @@ def test_cooper_nathans_compare_3():
sample_json_path = "./test_data/test_samples/sample_test.json"

tas.load_instrument_params_from_json(instrument_config_json_path)
tas.load_sample_from_json(sample_json_path)
tas.mount_sample(Xtal.from_json(sample_json_path))

if tas.sample.ub_matrix is None:
if tas.sample.ub_mat is None:
peak_list = [(0, 0, 2), (0, 2, 0)]
angles_list = [
(-51.530388, -45.220125, -0.000500, -2.501000),
Expand All @@ -50,9 +51,9 @@ def test_cooper_nathans_compare_3():
hkl = (0, 0, 2)
# projection = ((1, 0, 0), (-1, 2, 0), (0, 0, 1))
projection = ((0, 0, 1), (0, -1, 0), (2, -1, 0))
R0 = False
r0 = False

tas_params = (tas, ei, ef, hkl, projection, R0)
tas_params = (tas, ei, ef, hkl, projection, r0)

test_copper_nathans_localQ(tas_params)
test_copper_nathans_hkl(tas_params)
Expand All @@ -66,12 +67,12 @@ def test_cooper_nathans_CTAX():
sample_json_path = "./test_data/test_samples/nitio3.json"

tas.load_instrument_params_from_json(instrument_config_json_path)
tas.load_sample_from_json(sample_json_path)
tas.mount_sample(sample_json_path)

# ----------- reset UB -----------------------------------
# print(f"u={tas.sample.u}")
# print(f"v={tas.sample.v}")
# tas.sample.ub_matrix = tas.sample.uv_to_ub_matrix(u=[1, 1, 0], v=[0, 0, 1])
# tas.sample.ub_mat = tas.sample.uv_to_ub_matrix(u=[1, 1, 0], v=[0, 0, 1])
# print(f"u={tas.sample.u}")
# print(f"v={tas.sample.v}")
# ----------------------------------------------------------
Expand All @@ -81,9 +82,9 @@ def test_cooper_nathans_CTAX():
hkl = (0, 0, 3)

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

tas_params = (tas, ei, ef, hkl, projection, R0)
tas_params = (tas, ei, ef, hkl, projection, r0)

test_copper_nathans_localQ(tas_params)
test_copper_nathans_hkl(tas_params)
Expand Down
1 change: 1 addition & 0 deletions src/tavi/data/spice_to_nexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ def _nenux_entry(nxentry, das_logs):
"""Entry containing scan info"""

nxentry.attrs["NX_class"] = "NXentry"
# nxentry.attrs["NX_class"] = "NXroot"
nxentry.attrs["EX_required"] = "true"

# Valid enumeration values for root['/entry']['definition'] are: NXtas
Expand Down
2 changes: 1 addition & 1 deletion src/tavi/instrument/goni.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def stacking_order_yxy(r_mat):
def set_limit(
self,
motor_name: Literal["omega", "sgl", "sgu", "chi", "phi"],
motor_range: tuple[float] = (-180, 180),
motor_range: tuple[float, float] = (-180, 180),
):
"set goiometer motor limt"
setattr(self, motor_name + "_limit", motor_range)
Expand Down
76 changes: 76 additions & 0 deletions src/tavi/instrument/instrument_params/hb3_mnte.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"source": {
"shape": "rectangular",
"width": 15.0,
"height": 15.0
},
"guide": {
"in_use": false,
"div_h": 0.0,
"div_v": 0.0
},
"monochromator": {
"type": "PG002",
"mosaic_h": 30,
"mosaic_v": 30,
"sense": -1,
"shape": "rectangular",
"width": 7.62,
"height": 10.16,
"depth": 0.25,
"curved_h": false,
"curvh": 0.0,
"optimally_curved_h": false,
"curved_v": false,
"curvv": 0.4,
"optimally_curved_v": false
},
"monitor": {
"shape": "rectangular",
"width": 5,
"height": 12
},
"goniometer": {
"sense": 1,
"type": "Y-ZX"
},
"analyzer": {
"type": "Pg002",
"d_spacing": 3.35416,
"mosaic_h": 40,
"mosaic_v": 40,
"sense": -1,
"shape": "rectangular",
"width": 7.62,
"height": 7,
"depth": 0.2,
"curved_h": false,
"curvh": 0.0,
"optimally_curved_h": false,
"curved_v": true,
"curvv": 163.2,
"optimally_curved_v": false
},
"detector": {
"shape": "rectangular",
"width": 4,
"height": 12.0
},
"distances": {
"src_mono": 650.0,
"mono_sample": 190.0,
"sample_ana": 106.0,
"ana_det": 60.0,
"mono_monitor": 86.0
},
"collimators": {
"h_pre_mono": 48,
"h_pre_sample": 40,
"h_post_sample": 40,
"h_post_ana": 120,
"v_pre_mono": 120,
"v_pre_sample": 120,
"v_post_sample": 120,
"v_post_ana": 120
}
}
Loading

0 comments on commit 7fa37ca

Please sign in to comment.