Skip to content

Commit

Permalink
added Bi phonon data from CTAX
Browse files Browse the repository at this point in the history
  • Loading branch information
Bing Li committed Dec 9, 2024
1 parent 1b0febe commit bc37643
Show file tree
Hide file tree
Showing 1,513 changed files with 62,630 additions and 82 deletions.
25 changes: 22 additions & 3 deletions scripts/rez_HB1A.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
import matplotlib.pyplot as plt

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 = "./test_data/IPTS9879_HB1A_exp978/hb1a.json"
tas = CN(SPICE_CONVENTION=True)
tas.load_instrument_params_from_json(instrument_config_json_path)

ei = 14.450292
ef = ei
R0 = False

sample_json_path = "./test_data/IPTS9879_HB1A_exp978/si.json"
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)
# ----------------------- load data ----------------------------

tavi = TAVI()

path_to_spice_folder = "./test_data/exp978/"
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' -----------------
Expand All @@ -21,7 +40,7 @@


p1 = Plot2D()
p1.add_contour(si_111_1, cmap="turbo", vmin=0, vmax=1.2e4)
p1.add_contour(si_111_1, cmap="turbo", vmin=0, vmax=2.5e4)
p1.title = sg1.name
p1.ylim = [0.97, 1.03]
p1.xlim = [0.97, 1.03]
Expand All @@ -44,7 +63,7 @@


p2 = Plot2D()
p2.add_contour(si_111_2, cmap="turbo", vmin=0, vmax=1300)
p2.add_contour(si_111_2, cmap="turbo", vmin=0, vmax=3500)
p2.title = sg2.name
# p2.ylim = [0.97, 1.03]
# p2.xlim = [0.97, 1.03]
Expand Down
83 changes: 33 additions & 50 deletions src/tavi/data/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,53 +106,31 @@ def add_background(
prefix = f"b{self._num_backgrounds}_"
self._background_models.append(Fit1D._add_model(model, prefix, nan_policy=self.nan_policy))

@staticmethod
def _get_param_names(models) -> list[list[str]]:
params = []
for model in models:
params.append(model.param_names)
return params

@property
def signal_param_names(self):
"""Get parameter names of all signals"""
return Fit1D._get_param_names(self._signal_models)

@property
def background_param_names(self):
"""Get parameter names of all backgrounds"""
return Fit1D._get_param_names(self._background_models)
# @staticmethod
# def _get_param_names(models) -> list[list[str]]:
# params = []
# for model in models:
# params.append(model.param_names)
# return params

# @property
# def signal_param_names(self):
# """Get parameter names of all signals"""
# return Fit1D._get_param_names(self._signal_models)

# @property
# def background_param_names(self):
# """Get parameter names of all backgrounds"""
# return Fit1D._get_param_names(self._background_models)

# TODO
@property
def params(self) -> dict[str, dict]:
def params(self) -> Parameters:
"""Get fitting parameters as a dictionary with the model prefix being the key"""

all_pars = self.guess() if self._parameters is None else self._parameters
params_names = Fit1D._get_param_names(self._signal_models + self._background_models)

params_dict = {}
for names in params_names:
if len(names) < 1:
raise ValueError(f"Should have at least 1 parameter in {names}.")
prefix, _ = names[0].split("_")
param_dict = {}
for param_name in names:
param = all_pars[param_name]
param_dict.update(
{
"name": param.name,
"value": param.value,
"vary": param.vary,
"min": param.min,
"max": param.max,
"expr": param.expr,
}
)

params_dict.update({prefix: param_dict})

return params_dict
if self._parameters is None:
self._parameters = self.guess()

return self._parameters

def guess(self) -> Parameters:
"""Guess fitting parameters' values
Expand All @@ -173,13 +151,18 @@ def model(self):
compposite_model = np.sum(self._signal_models + self._background_models)
return compposite_model

def x_to_plot(self, num_of_pts: Optional[int] = 100):
if num_of_pts is None:
x_to_plot = self.x
elif isinstance(num_of_pts, int):
x_to_plot = np.linspace(self.x.min(), self.x.max(), num=num_of_pts)
else:
raise ValueError(f"num_of_points={num_of_pts} needs to be an integer.")
def x_to_plot(
self,
min: Optional[float] = None,
max: Optional[float] = None,
num_of_pts: int = 100,
):
if min is None:
min = self.x.min()
if max is None:
max = self.x.max()
x_to_plot = np.linspace(min, max, num=num_of_pts)

return x_to_plot

def eval(self, pars: Parameters, x: np.ndarray) -> np.ndarray:
Expand Down
2 changes: 2 additions & 0 deletions src/tavi/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def _add_fit_from_fitting(self, fit_data: Fit1D, num_of_pts: Optional[int] = 100
for key, val in kwargs.items():
data.fmt.update({key: val})

# TODO
def add_fit(
self, fit_data: Union[tuple[np.ndarray, np.ndarray], Fit1D], num_of_pts: Optional[int] = 100, **kwargs
):
Expand All @@ -98,6 +99,7 @@ def add_fit(
else:
raise ValueError(f"Invalid input fit_data={fit_data}")

# TODO
def add_fit_components(self, fit_data: Fit1D, num_of_pts: Optional[int] = 100, **kwargs):
if isinstance(fit_data, Fit1D) and (result := fit_data.result) is not None:
x = fit_data.x_to_plot(num_of_pts)
Expand Down
14 changes: 14 additions & 0 deletions test_data/Bi_CTAX/exp25/Calibration/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<title>Index of /user_data/cg4c/exp25/Calibration</title>
</head>
<body>
<h1>Index of /user_data/cg4c/exp25/Calibration</h1>
<table>
<tr><th valign="top"><img src="http://neutron.ornl.gov/icons/blank.gif" alt="[ICO]"></th><th><a href="index.html@C=N;O=D">Name</a></th><th><a href="index.html@C=M;O=A">Last modified</a></th><th><a href="index.html@C=S;O=A">Size</a></th><th><a href="index.html@C=D;O=A">Description</a></th></tr>
<tr><th colspan="5"><hr></th></tr>
<tr><td valign="top"><img src="http://neutron.ornl.gov/icons/back.gif" alt="[PARENTDIR]"></td><td><a href="../index.html">Parent Directory</a> </td><td>&nbsp;</td><td align="right"> - </td><td>&nbsp;</td></tr>
<tr><th colspan="5"><hr></th></tr>
</table>
</body></html>
14 changes: 14 additions & 0 deletions test_data/Bi_CTAX/exp25/Calibration/index.html@C=D;O=A
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<title>Index of /user_data/cg4c/exp25/Calibration</title>
</head>
<body>
<h1>Index of /user_data/cg4c/exp25/Calibration</h1>
<table>
<tr><th valign="top"><img src="http://neutron.ornl.gov/icons/blank.gif" alt="[ICO]"></th><th><a href="index.html@C=N;O=A">Name</a></th><th><a href="index.html@C=M;O=A">Last modified</a></th><th><a href="index.html@C=S;O=A">Size</a></th><th><a href="index.html@C=D;O=D">Description</a></th></tr>
<tr><th colspan="5"><hr></th></tr>
<tr><td valign="top"><img src="http://neutron.ornl.gov/icons/back.gif" alt="[PARENTDIR]"></td><td><a href="../index.html">Parent Directory</a> </td><td>&nbsp;</td><td align="right"> - </td><td>&nbsp;</td></tr>
<tr><th colspan="5"><hr></th></tr>
</table>
</body></html>
14 changes: 14 additions & 0 deletions test_data/Bi_CTAX/exp25/Calibration/index.html@C=D;O=D
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<title>Index of /user_data/cg4c/exp25/Calibration</title>
</head>
<body>
<h1>Index of /user_data/cg4c/exp25/Calibration</h1>
<table>
<tr><th valign="top"><img src="http://neutron.ornl.gov/icons/blank.gif" alt="[ICO]"></th><th><a href="index.html@C=N;O=A">Name</a></th><th><a href="index.html@C=M;O=A">Last modified</a></th><th><a href="index.html@C=S;O=A">Size</a></th><th><a href="index.html@C=D;O=A">Description</a></th></tr>
<tr><th colspan="5"><hr></th></tr>
<tr><td valign="top"><img src="http://neutron.ornl.gov/icons/back.gif" alt="[PARENTDIR]"></td><td><a href="../index.html">Parent Directory</a> </td><td>&nbsp;</td><td align="right"> - </td><td>&nbsp;</td></tr>
<tr><th colspan="5"><hr></th></tr>
</table>
</body></html>
14 changes: 14 additions & 0 deletions test_data/Bi_CTAX/exp25/Calibration/index.html@C=M;O=A
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<title>Index of /user_data/cg4c/exp25/Calibration</title>
</head>
<body>
<h1>Index of /user_data/cg4c/exp25/Calibration</h1>
<table>
<tr><th valign="top"><img src="http://neutron.ornl.gov/icons/blank.gif" alt="[ICO]"></th><th><a href="index.html@C=N;O=A">Name</a></th><th><a href="index.html@C=M;O=D">Last modified</a></th><th><a href="index.html@C=S;O=A">Size</a></th><th><a href="index.html@C=D;O=A">Description</a></th></tr>
<tr><th colspan="5"><hr></th></tr>
<tr><td valign="top"><img src="http://neutron.ornl.gov/icons/back.gif" alt="[PARENTDIR]"></td><td><a href="../index.html">Parent Directory</a> </td><td>&nbsp;</td><td align="right"> - </td><td>&nbsp;</td></tr>
<tr><th colspan="5"><hr></th></tr>
</table>
</body></html>
14 changes: 14 additions & 0 deletions test_data/Bi_CTAX/exp25/Calibration/index.html@C=M;O=D
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<title>Index of /user_data/cg4c/exp25/Calibration</title>
</head>
<body>
<h1>Index of /user_data/cg4c/exp25/Calibration</h1>
<table>
<tr><th valign="top"><img src="http://neutron.ornl.gov/icons/blank.gif" alt="[ICO]"></th><th><a href="index.html@C=N;O=A">Name</a></th><th><a href="index.html@C=M;O=A">Last modified</a></th><th><a href="index.html@C=S;O=A">Size</a></th><th><a href="index.html@C=D;O=A">Description</a></th></tr>
<tr><th colspan="5"><hr></th></tr>
<tr><td valign="top"><img src="http://neutron.ornl.gov/icons/back.gif" alt="[PARENTDIR]"></td><td><a href="../index.html">Parent Directory</a> </td><td>&nbsp;</td><td align="right"> - </td><td>&nbsp;</td></tr>
<tr><th colspan="5"><hr></th></tr>
</table>
</body></html>
14 changes: 14 additions & 0 deletions test_data/Bi_CTAX/exp25/Calibration/index.html@C=N;O=A
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<title>Index of /user_data/cg4c/exp25/Calibration</title>
</head>
<body>
<h1>Index of /user_data/cg4c/exp25/Calibration</h1>
<table>
<tr><th valign="top"><img src="http://neutron.ornl.gov/icons/blank.gif" alt="[ICO]"></th><th><a href="index.html@C=N;O=D">Name</a></th><th><a href="index.html@C=M;O=A">Last modified</a></th><th><a href="index.html@C=S;O=A">Size</a></th><th><a href="index.html@C=D;O=A">Description</a></th></tr>
<tr><th colspan="5"><hr></th></tr>
<tr><td valign="top"><img src="http://neutron.ornl.gov/icons/back.gif" alt="[PARENTDIR]"></td><td><a href="../index.html">Parent Directory</a> </td><td>&nbsp;</td><td align="right"> - </td><td>&nbsp;</td></tr>
<tr><th colspan="5"><hr></th></tr>
</table>
</body></html>
14 changes: 14 additions & 0 deletions test_data/Bi_CTAX/exp25/Calibration/index.html@C=N;O=D
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<title>Index of /user_data/cg4c/exp25/Calibration</title>
</head>
<body>
<h1>Index of /user_data/cg4c/exp25/Calibration</h1>
<table>
<tr><th valign="top"><img src="http://neutron.ornl.gov/icons/blank.gif" alt="[ICO]"></th><th><a href="index.html@C=N;O=A">Name</a></th><th><a href="index.html@C=M;O=A">Last modified</a></th><th><a href="index.html@C=S;O=A">Size</a></th><th><a href="index.html@C=D;O=A">Description</a></th></tr>
<tr><th colspan="5"><hr></th></tr>
<tr><td valign="top"><img src="http://neutron.ornl.gov/icons/back.gif" alt="[PARENTDIR]"></td><td><a href="../index.html">Parent Directory</a> </td><td>&nbsp;</td><td align="right"> - </td><td>&nbsp;</td></tr>
<tr><th colspan="5"><hr></th></tr>
</table>
</body></html>
14 changes: 14 additions & 0 deletions test_data/Bi_CTAX/exp25/Calibration/index.html@C=S;O=A
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<title>Index of /user_data/cg4c/exp25/Calibration</title>
</head>
<body>
<h1>Index of /user_data/cg4c/exp25/Calibration</h1>
<table>
<tr><th valign="top"><img src="http://neutron.ornl.gov/icons/blank.gif" alt="[ICO]"></th><th><a href="index.html@C=N;O=A">Name</a></th><th><a href="index.html@C=M;O=A">Last modified</a></th><th><a href="index.html@C=S;O=D">Size</a></th><th><a href="index.html@C=D;O=A">Description</a></th></tr>
<tr><th colspan="5"><hr></th></tr>
<tr><td valign="top"><img src="http://neutron.ornl.gov/icons/back.gif" alt="[PARENTDIR]"></td><td><a href="../index.html">Parent Directory</a> </td><td>&nbsp;</td><td align="right"> - </td><td>&nbsp;</td></tr>
<tr><th colspan="5"><hr></th></tr>
</table>
</body></html>
14 changes: 14 additions & 0 deletions test_data/Bi_CTAX/exp25/Calibration/index.html@C=S;O=D
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<title>Index of /user_data/cg4c/exp25/Calibration</title>
</head>
<body>
<h1>Index of /user_data/cg4c/exp25/Calibration</h1>
<table>
<tr><th valign="top"><img src="http://neutron.ornl.gov/icons/blank.gif" alt="[ICO]"></th><th><a href="index.html@C=N;O=A">Name</a></th><th><a href="index.html@C=M;O=A">Last modified</a></th><th><a href="index.html@C=S;O=A">Size</a></th><th><a href="index.html@C=D;O=A">Description</a></th></tr>
<tr><th colspan="5"><hr></th></tr>
<tr><td valign="top"><img src="http://neutron.ornl.gov/icons/back.gif" alt="[PARENTDIR]"></td><td><a href="../index.html">Parent Directory</a> </td><td>&nbsp;</td><td align="right"> - </td><td>&nbsp;</td></tr>
<tr><th colspan="5"><hr></th></tr>
</table>
</body></html>
File renamed without changes.
Loading

0 comments on commit bc37643

Please sign in to comment.