Skip to content

Commit

Permalink
updated Ellipsoid class to return None when the (Q,E) point cannot be…
Browse files Browse the repository at this point in the history
… reached
  • Loading branch information
Bing Li committed Nov 14, 2024
1 parent 7c8b1d8 commit 226b933
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 5 deletions.
Binary file modified .DS_Store
Binary file not shown.
57 changes: 57 additions & 0 deletions scripts/rez_dispH.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.axisartist import Axes

from tavi.data.nxdict import NXdataset, NXentry
from tavi.data.nxentry import NexusEntry
from tavi.data.tavi import TAVI
from tavi.instrument.resolution.cooper_nathans import CN
from tavi.plotter import Plot2D
from tavi.sample.xtal import Xtal

instrument_config_json_path = "./src/tavi/instrument/instrument_params/cg4c.json"
tas = CN(SPICE_CONVENTION=False)
tas.load_instrument_params_from_json(instrument_config_json_path)

sample_json_path = "./test_data/test_samples/nitio3.json"
sample = Xtal.from_json(sample_json_path)
tas.mount_sample(sample)


tavi = TAVI()

# calculate resolution ellipses
R0 = False
hkl_list = [(qh, 0, 0) for qh in np.arange(1, 2.01, 0.1)]
ef = 4.8
ei_list = [e + ef for e in np.arange(0, 5.1, 0.2)]

# genreate plot
p = Plot2D()

for i, hkl in enumerate(hkl_list, 1):
rez_list = tas.cooper_nathans(hkl_list=hkl, ei=ei_list, ef=ef, R0=R0)
sz = len(rez_list)
rez_entry = NXentry(
hkl=NXdataset(ds=[rez.hkl for rez in rez_list]),
en=NXdataset(ds=[rez.en for rez in rez_list]),
rez_mat=NXdataset(ds=[rez.mat for rez in rez_list]),
rez_r0=NXdataset(ds=[rez.r0 for rez in rez_list]),
)
tavi.processed_data.update(NexusEntry._dict_to_nexus_entry({f"scan{i:04}": rez_entry}))

for rez in rez_list:
e_co = rez.get_ellipse(axes=(0, 3), PROJECTION=False)
e_inco = rez.get_ellipse(axes=(0, 3), PROJECTION=True)
if e_co is not None:
p.add_reso(e_co, c="k", linestyle="solid")
if e_inco is not None:
p.add_reso(e_inco, c="k", linestyle="dashed")

tavi.save("./test_data/rez_dispH.h5")


fig = plt.figure()
ax = fig.add_subplot(111, axes_class=Axes)
im = p.plot(ax)
plt.show()
2 changes: 1 addition & 1 deletion scripts/scans_rez.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
rez = tas.cooper_nathans(
ei=ei_list[i],
ef=ef_list[i],
hkl=(qh_list[i], qk_list[i], ql_list[i]),
hkl_list=(qh_list[i], qk_list[i], ql_list[i]),
# projection=projection,
R0=R0,
)
Expand Down
10 changes: 7 additions & 3 deletions src/tavi/instrument/resolution/cooper_nathans.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,10 @@ def cooper_nathans(
except TypeError:
rez.STATUS = False
print(f"Cannot close triangle for ei={ei}, ef={ef}, hkl={np.round(hkl,3)}.")
return rez

rez._set_labels()
rez_list.append(rez)
continue

# phi = <ki to q>, always has the oppositie sign of s2
phi = get_angle_from_triangle(ki, q_mod, kf) * self.goniometer.sense * (-1)
Expand Down Expand Up @@ -256,7 +259,9 @@ def cooper_nathans(
motor_angles = self.calculate_motor_angles(peak=hkl, ei=ei, ef=ef)
if motor_angles is None:
rez.STATUS = False
return rez
rez._set_labels()
rez_list.append(rez)
continue

r_mat = self.goniometer.r_mat(motor_angles)
ub_mat = self.sample.ub_mat
Expand Down Expand Up @@ -287,7 +292,6 @@ def cooper_nathans(
rez.STATUS = True

rez._set_labels()

rez_list.append(rez)

if len(rez_list) == 1:
Expand Down
4 changes: 3 additions & 1 deletion src/tavi/instrument/resolution/ellipsoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def get_ellipse(
axes: tuple[int, int] = (0, 1),
PROJECTION: bool = False,
ORIGIN: bool = True,
) -> ResoEllipse:
) -> Optional[ResoEllipse]:
"""Gnerate a 2D ellipse by either making a cut or projection
Arguments:
Expand All @@ -203,6 +203,8 @@ def get_ellipse(
ORIGIN: shift the center if True
"""
if not self.STATUS:
return None
x_axis, y_axis = axes
qe_list = np.concatenate((self.q, self.en), axis=None)
# axes = np.sort(axes)
Expand Down
Binary file added test_data/rez_dispH.h5
Binary file not shown.
Binary file added test_data/tavi_rez_HKLE.h5
Binary file not shown.

0 comments on commit 226b933

Please sign in to comment.