Skip to content

Commit

Permalink
setting up resolution bench marking on HB1A using La2Ni7 data
Browse files Browse the repository at this point in the history
  • Loading branch information
Bing Li committed Jan 2, 2025
1 parent 281e2f9 commit e833a03
Show file tree
Hide file tree
Showing 20 changed files with 434 additions and 270 deletions.
300 changes: 300 additions & 0 deletions notebooks/La2Ni7_HB1A_resolution.ipynb

Large diffs are not rendered by default.

27 changes: 0 additions & 27 deletions notebooks/example.ipynb

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
53 changes: 0 additions & 53 deletions scripts/test_fit_group.py

This file was deleted.

78 changes: 0 additions & 78 deletions scripts/test_plotter.py

This file was deleted.

102 changes: 0 additions & 102 deletions scripts/test_scan.py

This file was deleted.

9 changes: 6 additions & 3 deletions src/tavi/data/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,15 @@ def x_to_plot(
def eval(self, pars: Parameters, x: np.ndarray) -> np.ndarray:
return self.model.eval(pars, x=x)

def fit(self, pars: Parameters) -> ModelResult:
def fit(self, pars: Parameters, USE_ERRORBAR=True) -> ModelResult:

result = self.model.fit(self.y, pars, x=self.x, weights=self.err)
if USE_ERRORBAR:
result = self.model.fit(self.y, pars, x=self.x, weights=self.err)
else:
result = self.model.fit(self.y, pars, x=self.x)
if result.success:
self.result = result
self._parameters = result.params
return result
else:
return None
raise ValueError("Fitting failed")
18 changes: 17 additions & 1 deletion src/tavi/data/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,18 @@ def validate_rebin_params(rebin_params: float | int | tuple) -> tuple:
raise ValueError(f"Unrecogonized rebin parameters {rebin_params}")
return rebin_params

def _get_del_q(self):
"""Calculate del_q for aeither a s1 scan or a th2th scan"""
qs = self.data["q"]
q_diff = np.max(qs) - np.min(qs)
mid_idx = int((len(qs) - 1) / 2)
if q_diff > 0.0001: # q changing, must be a th2th scan
return qs - qs[mid_idx]
else: # q not changing, must be a s1 scan
q_abs = np.mean(qs)
s1s = self.data["s1"]
return np.deg2rad(s1s - s1s[mid_idx]) * q_abs

def get_data(
self,
axes: tuple[Optional[str], Optional[str]] = (None, None),
Expand All @@ -205,7 +217,11 @@ def get_data(
x_str = self.scan_info.def_x if x_str is None else x_str
y_str = self.scan_info.def_y if y_str is None else y_str

scan_data_1d = ScanData1D(x=self.data[x_str], y=self.data[y_str])
if x_str == "del_q":
scan_data_1d = ScanData1D(x=self._get_del_q(), y=self.data[y_str])
else:
scan_data_1d = ScanData1D(x=self.data[x_str], y=self.data[y_str])

label = "scan " + str(self.scan_info.scan_num)
title = f"{label}: {self.scan_info.scan_title}"

Expand Down
33 changes: 33 additions & 0 deletions test_data/IPTS9879_HB1A_exp978/La2Ni7.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"type": "xtal",
"a": 5.055640,
"b": 5.055640,
"c": 24.597968,
"alpha": 90,
"beta": 90,
"gamma": 120,
"shape": "cylindrical",
"mosaic_h": 0,
"mosaic_v": 0,
"ub_matrix": [
-0.007780,
-0.010850,
0.040605,
-0.194566,
-0.200455,
-0.001928,
0.119371,
-0.108931,
-0.000496
],
"plane_normal": [
0.013441,
0.025785,
0.999577
],
"in_plane_ref": [
0.998800,
-0.047426,
-0.012208
]
}
12 changes: 6 additions & 6 deletions test_data/IPTS9879_HB1A_exp978/hb1a_2.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"type": "PG002",
"mosaic_h": 30,
"mosaic_v": 30,
"sense": 1,
"sense": "+",
"shape": "rectangular",
"width": 10.0,
"height": 18.0,
Expand All @@ -27,14 +27,14 @@
},
"monitor": {},
"goniometer": {
"sense": -1,
"sense": "-",
"type": "Y-ZX"
},
"analyzer": {
"type": "Pg002",
"mosaic_h": 30,
"mosaic_v": 30,
"sense": 1,
"sense": "+",
"shape": "rectangular",
"width": 15.0,
"height": 15.6,
Expand All @@ -61,9 +61,9 @@
},
"collimators": {
"h_pre_mono": 40,
"h_pre_sample": 20,
"h_post_sample": 20,
"h_post_ana": 20,
"h_pre_sample": 40,
"h_post_sample": 40,
"h_post_ana": 80,
"v_pre_mono": 600,
"v_pre_sample": 600,
"v_post_sample": 600,
Expand Down
Loading

0 comments on commit e833a03

Please sign in to comment.