Skip to content

Commit

Permalink
added script for HB1A resolution benchmark
Browse files Browse the repository at this point in the history
Bing Li committed Dec 16, 2024
1 parent 234db28 commit 87cd7da
Showing 4 changed files with 171 additions and 8 deletions.
4 changes: 2 additions & 2 deletions scripts/FeSn_film_HB1A.py
Original file line number Diff line number Diff line change
@@ -114,7 +114,7 @@

fig, ax = plt.subplots()
p2.plot(ax)
ax.set_title("scan0060")
ax.set_title("scan0050")

# -----------------------------Fit 2 Q-----------------------------

@@ -141,5 +141,5 @@

fig, ax = plt.subplots()
p2_2.plot(ax)
ax.set_title("scan0060")
ax.set_title("scan0050")
plt.show()
101 changes: 96 additions & 5 deletions scripts/rez_HB1A.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import matplotlib.pyplot as plt

from tavi.data.fit import Fit1D
from tavi.data.tavi import TAVI
from tavi.instrument.resolution.cooper_nathans import CN
from tavi.plotter import Plot2D
from tavi.plotter import Plot1D, Plot2D
from tavi.sample.xtal import Xtal

instrument_config_json_path = "./test_data/IPTS9879_HB1A_exp978/hb1a.json"
@@ -17,17 +18,20 @@
sample = Xtal.from_json(sample_json_path)
tas.mount_sample(sample)

rez1_l = tas.cooper_nathans(hkl_list=(1, 1, 1), ei=ei, ef=ef, R0=R0, projection=((1, 1, 0), (0, 0, 1), (1, -1, 0)))
rez1_l.plot_ellipses()
# rez1_q = tas.cooper_nathans(hkl_list=(0, 0, 0.5), ei=ei, ef=ef, R0=R0, projection=None)
rez1 = tas.cooper_nathans(hkl_list=(1, 1, 1), ei=ei, ef=ef, R0=R0, projection=((1, 1, 0), (0, 0, 1), (1, -1, 0)))
rez1.plot_ellipses()
rez1_hhl = rez1.get_ellipse(axes=(0, 1), PROJECTION=False)
# rez1_q = tas.cooper_nathans(hkl_list=(1, 1, 1), ei=ei, ef=ef, R0=R0, projection=None)
# rez1_q.plot_ellipses()
# ----------------------- load data ----------------------------

tavi = TAVI()

path_to_spice_folder = "./test_data/IPTS9879_HB1A_exp978/exp978/"
tavi.load_spice_data_from_disk(path_to_spice_folder)

# ----------------------------------------------------
# -------------- Si (111) 40'-40'-40'-80' -----------------
# ----------------------------------------------------

scans = list(range(824, 848 + 1))

@@ -41,16 +45,70 @@

p1 = Plot2D()
p1.add_contour(si_111_1, cmap="turbo", vmin=0, vmax=2.5e4)
p1.add_reso(rez1_hhl, c="w")
p1.title = sg1.name
p1.ylim = [0.97, 1.03]
p1.xlim = [0.97, 1.03]


fig, ax = plt.subplots()
im1 = p1.plot(ax)
fig.colorbar(im1)
# ------------------

# si_111_s1s2 = sg1.get_data(
# axes=("s1", "s2", "detector"),
# norm_to=(1, "mcu"),
# grid=(0.1, 0.1),
# )
# p2 = Plot2D()
# p2.add_contour(si_111_s1s2, cmap="turbo", vmin=0, vmax=2.5e4)
# fig, ax = plt.subplots()
# im2 = p2.plot(ax)
# fig.colorbar(im2)

# -----------------------1 D --------------------
scan836 = tavi.get_scan(scan_num=836)
hh1 = scan836.get_data()

hh1_fit = Fit1D(hh1)

hh1_fit.add_signal(model="Gaussian")
pars = hh1_fit.guess()
result = hh1_fit.fit(pars)
print(hh1_fit.result.fit_report())


p4 = Plot1D()
p4.add_scan(hh1, fmt="o")
p4.add_fit(
hh1_fit,
x=hh1_fit.x_to_plot(),
label=f"FWHM={result.params["s1_fwhm"].value:.5f}+/-{result.params["s1_fwhm"].stderr:.5f}",
)

x = hh1_fit.result.params["s1_center"].value
y = result.eval(result.params, x=x) / 2

p4.add_reso_bar(
pos=(x, y),
fwhm=rez1.coh_fwhms(axis=0),
label=f"Resolution FWHM={rez1.coh_fwhms(axis=0):.05f}",
)
p4.title = "Si (HH1) 40'-40'-40'-80'"
fig, ax = plt.subplots()
p4.plot(ax)
# ----------------------------------------------------
# -------------- Si (111) 40'-20'-20'-20' ------------
# ----------------------------------------------------
instrument_config_json_path_2 = "./test_data/IPTS9879_HB1A_exp978/hb1a_2.json"
tas2 = CN(SPICE_CONVENTION=True)
tas2.load_instrument_params_from_json(instrument_config_json_path_2)
tas2.mount_sample(sample)

rez2 = tas2.cooper_nathans(hkl_list=(1, 1, 1), ei=ei, ef=ef, R0=R0, projection=((1, 1, 0), (0, 0, 1), (1, -1, 0)))
rez2.plot_ellipses()
rez2_hhl = rez2.get_ellipse(axes=(0, 1), PROJECTION=False)

scans = list(range(792, 816 + 1))

@@ -64,6 +122,7 @@

p2 = Plot2D()
p2.add_contour(si_111_2, cmap="turbo", vmin=0, vmax=3500)
p2.add_reso(rez2_hhl, c="w")
p2.title = sg2.name
# p2.ylim = [0.97, 1.03]
# p2.xlim = [0.97, 1.03]
@@ -72,4 +131,36 @@
im2 = p2.plot(ax)
fig.colorbar(im2)

# -----------------------1 D --------------------
scan804 = tavi.get_scan(scan_num=804)
hh1_2 = scan804.get_data()

hh1_fit_2 = Fit1D(hh1_2)

hh1_fit_2.add_signal(model="Gaussian")
pars = hh1_fit_2.guess()
result = hh1_fit_2.fit(pars)
print(hh1_fit_2.result.fit_report())


p5 = Plot1D()
p5.add_scan(hh1_2, fmt="o")
p5.add_fit(
hh1_fit_2,
x=hh1_fit.x_to_plot(),
label=f"FWHM={result.params["s1_fwhm"].value:.5f}+/-{result.params["s1_fwhm"].stderr:.5f}",
)

x = hh1_fit_2.result.params["s1_center"].value
y = result.eval(result.params, x=x) / 2

p5.add_reso_bar(
pos=(x, y),
fwhm=rez2.coh_fwhms(axis=0),
label=f"Resolution FWHM={rez2.coh_fwhms(axis=0):.05f}",
)
p5.title = "Si (HH1) 40'-20'-20'-20'"
fig, ax = plt.subplots()
p5.plot(ax)

plt.show()
2 changes: 1 addition & 1 deletion src/tavi/data/tavi.py
Original file line number Diff line number Diff line change
@@ -162,7 +162,7 @@ def get_scan(self, scan_num: Union[tuple[str, int], int]) -> Scan:
def combine_scans(
self,
scan_nums: Union[list[int], list[tuple[str, int]]],
name: Optional[str] = None,
name: str = "",
):
"""Group scans for further processing
72 changes: 72 additions & 0 deletions test_data/IPTS9879_HB1A_exp978/hb1a_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"source": {
"shape": "rectangular",
"width": 0.0,
"height": 0.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": 10.0,
"height": 18.0,
"depth": 0.0,
"curved_h": false,
"curvh": 0.0,
"optimally_curved_h": false,
"curved_v": true,
"curvv": 0.0,
"optimally_curved_v": false
},
"monitor": {},
"goniometer": {
"sense": -1,
"type": "Y-ZX"
},
"analyzer": {
"type": "Pg002",
"mosaic_h": 30,
"mosaic_v": 30,
"sense": 1,
"shape": "rectangular",
"width": 15.0,
"height": 15.6,
"depth": 0.0,
"curved_h": false,
"curvh": 0.0,
"optimally_curved_h": false,
"curved_v": true,
"curvv": 0.0,
"optimally_curved_v": false
},
"detector": {
"shape": "rectangular",
"width": 5.08,
"height": 5.08
},
"distances": {
"src_mono1": 474.5,
"mono1_mono2": 227.6,
"src_mono": 474.5,
"mono_sample": 143.13,
"sample_ana": 74.0,
"ana_det": 50.0
},
"collimators": {
"h_pre_mono": 40,
"h_pre_sample": 20,
"h_post_sample": 20,
"h_post_ana": 20,
"v_pre_mono": 600,
"v_pre_sample": 600,
"v_post_sample": 600,
"v_post_ana": 600
}
}

0 comments on commit 87cd7da

Please sign in to comment.