{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "10c07820",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:56:02.500307Z",
"iopub.status.busy": "2026-01-06T13:56:02.499876Z",
"iopub.status.idle": "2026-01-06T13:56:02.511744Z",
"shell.execute_reply": "2026-01-06T13:56:02.510223Z"
},
"tags": [
"hide-in-docs"
]
},
"outputs": [],
"source": [
"# Check if the easydiffraction library is installed.\n",
"# If not, install it with the 'visualization' extras.\n",
"# Needed when running remotely (e.g. Colab) where the lib is absent.\n",
"import builtins\n",
"import importlib.util\n",
"\n",
"if (hasattr(builtins, '__IPYTHON__') and\n",
" importlib.util.find_spec('easydiffraction') is None):\n",
" !pip install 'easydiffraction[visualization]==0.10.1'"
]
},
{
"cell_type": "markdown",
"id": "0",
"metadata": {},
"source": [
"# Structure Refinement: Si, SEPD\n",
"\n",
"This example demonstrates a Rietveld refinement of Si crystal\n",
"structure using time-of-flight neutron powder diffraction data from\n",
"SEPD at Argonne."
]
},
{
"cell_type": "markdown",
"id": "1",
"metadata": {},
"source": [
"## Import Library"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "2",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:56:02.516269Z",
"iopub.status.busy": "2026-01-06T13:56:02.515824Z",
"iopub.status.idle": "2026-01-06T13:56:06.089776Z",
"shell.execute_reply": "2026-01-06T13:56:06.087301Z"
}
},
"outputs": [],
"source": [
"from easydiffraction import ExperimentFactory\n",
"from easydiffraction import Project\n",
"from easydiffraction import SampleModelFactory\n",
"from easydiffraction import download_data"
]
},
{
"cell_type": "markdown",
"id": "3",
"metadata": {},
"source": [
"## Define Sample Model\n",
"\n",
"This section shows how to add sample models and modify their\n",
"parameters.\n",
"\n",
"#### Create Sample Model"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "4",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:56:06.105153Z",
"iopub.status.busy": "2026-01-06T13:56:06.104245Z",
"iopub.status.idle": "2026-01-06T13:56:06.124996Z",
"shell.execute_reply": "2026-01-06T13:56:06.119308Z"
}
},
"outputs": [],
"source": [
"model = SampleModelFactory.create(name='si')"
]
},
{
"cell_type": "markdown",
"id": "5",
"metadata": {},
"source": [
"#### Set Space Group"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "6",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:56:06.131124Z",
"iopub.status.busy": "2026-01-06T13:56:06.130929Z",
"iopub.status.idle": "2026-01-06T13:56:06.137174Z",
"shell.execute_reply": "2026-01-06T13:56:06.135004Z"
}
},
"outputs": [],
"source": [
"model.space_group.name_h_m = 'F d -3 m'\n",
"model.space_group.it_coordinate_system_code = '2'"
]
},
{
"cell_type": "markdown",
"id": "7",
"metadata": {},
"source": [
"#### Set Unit Cell"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "8",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:56:06.141249Z",
"iopub.status.busy": "2026-01-06T13:56:06.141071Z",
"iopub.status.idle": "2026-01-06T13:56:06.145298Z",
"shell.execute_reply": "2026-01-06T13:56:06.144453Z"
}
},
"outputs": [],
"source": [
"model.cell.length_a = 5.431"
]
},
{
"cell_type": "markdown",
"id": "9",
"metadata": {},
"source": [
"#### Set Atom Sites"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "10",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:56:06.148482Z",
"iopub.status.busy": "2026-01-06T13:56:06.148090Z",
"iopub.status.idle": "2026-01-06T13:56:06.154617Z",
"shell.execute_reply": "2026-01-06T13:56:06.153893Z"
}
},
"outputs": [],
"source": [
"model.atom_sites.add(\n",
" label='Si',\n",
" type_symbol='Si',\n",
" fract_x=0.125,\n",
" fract_y=0.125,\n",
" fract_z=0.125,\n",
" b_iso=0.5,\n",
")"
]
},
{
"cell_type": "markdown",
"id": "11",
"metadata": {},
"source": [
"## Define Experiment\n",
"\n",
"This section shows how to add experiments, configure their\n",
"parameters, and link the sample models defined in the previous step.\n",
"\n",
"#### Download Measured Data"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "12",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:56:06.157678Z",
"iopub.status.busy": "2026-01-06T13:56:06.156527Z",
"iopub.status.idle": "2026-01-06T13:56:06.247191Z",
"shell.execute_reply": "2026-01-06T13:56:06.246659Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;34mGetting data\u001b[0m\u001b[1;34m...\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Data #\u001b[1;36m7\u001b[0m: Si, SEPD \u001b[1m(\u001b[0mArgonne\u001b[1m)\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"✅ Data #\u001b[1;36m7\u001b[0m downloaded to \u001b[32m'data/ed-7.xye'\u001b[0m\n"
]
}
],
"source": [
"data_path = download_data(id=7, destination='data')"
]
},
{
"cell_type": "markdown",
"id": "13",
"metadata": {},
"source": [
"#### Create Experiment"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "14",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:56:06.252943Z",
"iopub.status.busy": "2026-01-06T13:56:06.252681Z",
"iopub.status.idle": "2026-01-06T13:56:07.429732Z",
"shell.execute_reply": "2026-01-06T13:56:07.429225Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;34mData loaded successfully\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Experiment 🔬 \u001b[32m'sepd'\u001b[0m. Number of data points: \u001b[1;36m5600\u001b[0m\n"
]
}
],
"source": [
"expt = ExperimentFactory.create(name='sepd', data_path=data_path, beam_mode='time-of-flight')"
]
},
{
"cell_type": "markdown",
"id": "15",
"metadata": {},
"source": [
"#### Set Instrument"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "16",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:56:07.432845Z",
"iopub.status.busy": "2026-01-06T13:56:07.432306Z",
"iopub.status.idle": "2026-01-06T13:56:07.438473Z",
"shell.execute_reply": "2026-01-06T13:56:07.437461Z"
}
},
"outputs": [],
"source": [
"expt.instrument.setup_twotheta_bank = 144.845\n",
"expt.instrument.calib_d_to_tof_offset = 0.0\n",
"expt.instrument.calib_d_to_tof_linear = 7476.91\n",
"expt.instrument.calib_d_to_tof_quad = -1.54"
]
},
{
"cell_type": "markdown",
"id": "17",
"metadata": {},
"source": [
"#### Set Peak Profile"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "18",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:56:07.442584Z",
"iopub.status.busy": "2026-01-06T13:56:07.441982Z",
"iopub.status.idle": "2026-01-06T13:56:07.451331Z",
"shell.execute_reply": "2026-01-06T13:56:07.449038Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;34mPeak profile type for experiment \u001b[0m\u001b[32m'sepd'\u001b[0m\u001b[1;34m changed to\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"pseudo-voigt * ikeda-carpenter\n"
]
}
],
"source": [
"expt.peak_profile_type = 'pseudo-voigt * ikeda-carpenter'\n",
"expt.peak.broad_gauss_sigma_0 = 3.0\n",
"expt.peak.broad_gauss_sigma_1 = 40.0\n",
"expt.peak.broad_gauss_sigma_2 = 2.0\n",
"expt.peak.broad_mix_beta_0 = 0.04221\n",
"expt.peak.broad_mix_beta_1 = 0.00946"
]
},
{
"cell_type": "markdown",
"id": "19",
"metadata": {},
"source": [
"#### Set Peak Asymmetry"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "20",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:56:07.454397Z",
"iopub.status.busy": "2026-01-06T13:56:07.454183Z",
"iopub.status.idle": "2026-01-06T13:56:07.458548Z",
"shell.execute_reply": "2026-01-06T13:56:07.457501Z"
}
},
"outputs": [],
"source": [
"expt.peak.asym_alpha_0 = 0.0\n",
"expt.peak.asym_alpha_1 = 0.5971"
]
},
{
"cell_type": "markdown",
"id": "21",
"metadata": {},
"source": [
"#### Set Background"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "22",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:56:07.462385Z",
"iopub.status.busy": "2026-01-06T13:56:07.462181Z",
"iopub.status.idle": "2026-01-06T13:56:07.482493Z",
"shell.execute_reply": "2026-01-06T13:56:07.478435Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;34mBackground type for experiment \u001b[0m\u001b[32m'sepd'\u001b[0m\u001b[1;34m changed to\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"line-segment\n"
]
}
],
"source": [
"expt.background_type = 'line-segment'\n",
"for x in range(0, 35000, 5000):\n",
" expt.background.add(id=str(x), x=x, y=200)"
]
},
{
"cell_type": "markdown",
"id": "23",
"metadata": {},
"source": [
"#### Set Linked Phases"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "24",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:56:07.487702Z",
"iopub.status.busy": "2026-01-06T13:56:07.487467Z",
"iopub.status.idle": "2026-01-06T13:56:07.493215Z",
"shell.execute_reply": "2026-01-06T13:56:07.491608Z"
}
},
"outputs": [],
"source": [
"expt.linked_phases.add(id='si', scale=10.0)"
]
},
{
"cell_type": "markdown",
"id": "25",
"metadata": {},
"source": [
"## Define Project\n",
"\n",
"The project object is used to manage the sample model, experiment, and\n",
"analysis.\n",
"\n",
"#### Create Project"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "26",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:56:07.497317Z",
"iopub.status.busy": "2026-01-06T13:56:07.497126Z",
"iopub.status.idle": "2026-01-06T13:56:07.700995Z",
"shell.execute_reply": "2026-01-06T13:56:07.700538Z"
}
},
"outputs": [],
"source": [
"project = Project()"
]
},
{
"cell_type": "markdown",
"id": "27",
"metadata": {},
"source": [
"#### Add Sample Model"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "28",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:56:07.703170Z",
"iopub.status.busy": "2026-01-06T13:56:07.703023Z",
"iopub.status.idle": "2026-01-06T13:56:07.710036Z",
"shell.execute_reply": "2026-01-06T13:56:07.707488Z"
}
},
"outputs": [],
"source": [
"project.sample_models.add(sample_model=model)"
]
},
{
"cell_type": "markdown",
"id": "29",
"metadata": {},
"source": [
"#### Add Experiment"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "30",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:56:07.715566Z",
"iopub.status.busy": "2026-01-06T13:56:07.714589Z",
"iopub.status.idle": "2026-01-06T13:56:07.720979Z",
"shell.execute_reply": "2026-01-06T13:56:07.719761Z"
}
},
"outputs": [],
"source": [
"project.experiments.add(experiment=expt)"
]
},
{
"cell_type": "markdown",
"id": "31",
"metadata": {},
"source": [
"## Perform Analysis\n",
"\n",
"This section shows the analysis process, including how to set up\n",
"calculation and fitting engines.\n",
"\n",
"#### Set Calculator"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "32",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:56:07.722683Z",
"iopub.status.busy": "2026-01-06T13:56:07.722577Z",
"iopub.status.idle": "2026-01-06T13:56:07.727751Z",
"shell.execute_reply": "2026-01-06T13:56:07.727036Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;34mCurrent calculator changed to\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"cryspy\n"
]
}
],
"source": [
"project.analysis.current_calculator = 'cryspy'"
]
},
{
"cell_type": "markdown",
"id": "33",
"metadata": {},
"source": [
"#### Set Minimizer"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "34",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:56:07.734512Z",
"iopub.status.busy": "2026-01-06T13:56:07.732681Z",
"iopub.status.idle": "2026-01-06T13:56:07.744482Z",
"shell.execute_reply": "2026-01-06T13:56:07.742694Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;34mCurrent minimizer changed to\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"lmfit \u001b[1m(\u001b[0mleastsq\u001b[1m)\u001b[0m\n"
]
}
],
"source": [
"project.analysis.current_minimizer = 'lmfit (leastsq)'"
]
},
{
"cell_type": "markdown",
"id": "35",
"metadata": {},
"source": [
"#### Plot Measured vs Calculated"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "36",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:56:07.747771Z",
"iopub.status.busy": "2026-01-06T13:56:07.746920Z",
"iopub.status.idle": "2026-01-06T13:56:09.306826Z",
"shell.execute_reply": "2026-01-06T13:56:09.306417Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.plot_meas_vs_calc(expt_name='sepd', show_residual=True)\n",
"project.plot_meas_vs_calc(expt_name='sepd', x_min=23200, x_max=23700, show_residual=True)"
]
},
{
"cell_type": "markdown",
"id": "37",
"metadata": {},
"source": [
"### Perform Fit 1/5\n",
"\n",
"Set parameters to be refined."
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "38",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:56:09.308691Z",
"iopub.status.busy": "2026-01-06T13:56:09.308540Z",
"iopub.status.idle": "2026-01-06T13:56:09.311321Z",
"shell.execute_reply": "2026-01-06T13:56:09.310773Z"
}
},
"outputs": [],
"source": [
"model.cell.length_a.free = True\n",
"\n",
"expt.linked_phases['si'].scale.free = True\n",
"expt.instrument.calib_d_to_tof_offset.free = True"
]
},
{
"cell_type": "markdown",
"id": "39",
"metadata": {},
"source": [
"Show free parameters after selection."
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "40",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:56:09.313542Z",
"iopub.status.busy": "2026-01-06T13:56:09.313395Z",
"iopub.status.idle": "2026-01-06T13:56:09.724344Z",
"shell.execute_reply": "2026-01-06T13:56:09.723034Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;34mFree parameters for both sample models \u001b[0m\u001b[1;34m(\u001b[0m\u001b[1;34m🧩 data blocks\u001b[0m\u001b[1;34m)\u001b[0m\u001b[1;34m and experiments \u001b[0m\u001b[1;34m(\u001b[0m\u001b[1;34m🔬 data blocks\u001b[0m\u001b[1;34m)\u001b[0m\n"
]
},
{
"data": {
"application/javascript": [
"\n",
" (function() {\n",
" var isDark = false;\n",
"\n",
" // Check JupyterLab theme\n",
" if (document.body.classList.contains('jp-mod-dark') || \n",
" document.body.classList.contains('theme-dark') ||\n",
" document.body.classList.contains('vscode-dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check theme attribute\n",
" var themeAttr = document.body.getAttribute('data-jp-theme-name');\n",
" if (themeAttr && themeAttr.includes('dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check computed background color\n",
" var notebookEl = document.querySelector('.jp-Notebook') || \n",
" document.querySelector('.notebook_app') ||\n",
" document.body;\n",
" if (notebookEl) {\n",
" var bgColor = window.getComputedStyle(notebookEl).backgroundColor;\n",
" var rgb = bgColor.match(/\\d+/g);\n",
" if (rgb && rgb.length >= 3) {\n",
" var brightness = (parseInt(rgb[0]) + parseInt(rgb[1]) + parseInt(rgb[2])) / 3;\n",
" if (brightness < 128) {\n",
" isDark = true;\n",
" }\n",
" }\n",
" }\n",
"\n",
" // Store result\n",
" if (typeof IPython !== 'undefined' && IPython.notebook && IPython.notebook.kernel) {\n",
" IPython.notebook.kernel.execute('_jupyter_dark_detect_result = ' + isDark);\n",
" }\n",
" })();\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" if (typeof IPython !== 'undefined' && IPython.notebook) {\n",
" IPython.notebook.kernel.execute(\"_jupyter_dark_detect_result = \" + \n",
" (document.body.classList.contains('theme-dark') || \n",
" document.body.classList.contains('jp-mod-dark') ||\n",
" (document.body.getAttribute('data-jp-theme-name') && \n",
" document.body.getAttribute('data-jp-theme-name').includes('dark'))));\n",
" }\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
"\n",
" \n",
" \n",
" | | \n",
" datablock | \n",
" category | \n",
" entry | \n",
" parameter | \n",
" value | \n",
" uncertainty | \n",
" min | \n",
" max | \n",
" units | \n",
"
\n",
" \n",
" \n",
" \n",
" | 1 | \n",
" si | \n",
" cell | \n",
" | \n",
" length_a | \n",
" 5.43100 | \n",
" | \n",
" -inf | \n",
" inf | \n",
" Å | \n",
"
\n",
" \n",
" | 2 | \n",
" sepd | \n",
" linked_phases | \n",
" si | \n",
" scale | \n",
" 10.00000 | \n",
" | \n",
" -inf | \n",
" inf | \n",
" | \n",
"
\n",
" \n",
" | 3 | \n",
" sepd | \n",
" instrument | \n",
" | \n",
" d_to_tof_offset | \n",
" 0.00000 | \n",
" | \n",
" -inf | \n",
" inf | \n",
" µs | \n",
"
\n",
" \n",
"
\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.analysis.show_free_params()"
]
},
{
"cell_type": "markdown",
"id": "41",
"metadata": {},
"source": [
"#### Run Fitting"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "42",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:56:09.731715Z",
"iopub.status.busy": "2026-01-06T13:56:09.730843Z",
"iopub.status.idle": "2026-01-06T13:56:23.145737Z",
"shell.execute_reply": "2026-01-06T13:56:23.145036Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;34mUsing experiment 🔬 \u001b[0m\u001b[32m'sepd'\u001b[0m\u001b[1;34m for \u001b[0m\u001b[32m'single'\u001b[0m\u001b[1;34m fitting\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"🚀 Starting fit process with \u001b[32m'lmfit \u001b[0m\u001b[32m(\u001b[0m\u001b[32mleastsq\u001b[0m\u001b[32m)\u001b[0m\u001b[32m'\u001b[0m\u001b[33m...\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"📈 Goodness-of-fit \u001b[1m(\u001b[0mreduced χ²\u001b[1m)\u001b[0m change:\n"
]
},
{
"data": {
"text/html": [
"\n",
"\n",
" \n",
" \n",
" | | \n",
" iteration | \n",
" χ² | \n",
" improvement [%] | \n",
"
\n",
" \n",
" \n",
" \n",
" | 1 | \n",
" 1 | \n",
" 113.06 | \n",
" | \n",
"
\n",
" \n",
" | 2 | \n",
" 7 | \n",
" 72.20 | \n",
" 36.1% ↓ | \n",
"
\n",
" \n",
" | 3 | \n",
" 11 | \n",
" 66.76 | \n",
" 7.5% ↓ | \n",
"
\n",
" \n",
" | 4 | \n",
" 30 | \n",
" 66.72 | \n",
" | \n",
"
\n",
" \n",
"
\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" (function() {\n",
" var isDark = false;\n",
"\n",
" // Check JupyterLab theme\n",
" if (document.body.classList.contains('jp-mod-dark') || \n",
" document.body.classList.contains('theme-dark') ||\n",
" document.body.classList.contains('vscode-dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check theme attribute\n",
" var themeAttr = document.body.getAttribute('data-jp-theme-name');\n",
" if (themeAttr && themeAttr.includes('dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check computed background color\n",
" var notebookEl = document.querySelector('.jp-Notebook') || \n",
" document.querySelector('.notebook_app') ||\n",
" document.body;\n",
" if (notebookEl) {\n",
" var bgColor = window.getComputedStyle(notebookEl).backgroundColor;\n",
" var rgb = bgColor.match(/\\d+/g);\n",
" if (rgb && rgb.length >= 3) {\n",
" var brightness = (parseInt(rgb[0]) + parseInt(rgb[1]) + parseInt(rgb[2])) / 3;\n",
" if (brightness < 128) {\n",
" isDark = true;\n",
" }\n",
" }\n",
" }\n",
"\n",
" // Store result\n",
" if (typeof IPython !== 'undefined' && IPython.notebook && IPython.notebook.kernel) {\n",
" IPython.notebook.kernel.execute('_jupyter_dark_detect_result = ' + isDark);\n",
" }\n",
" })();\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" if (typeof IPython !== 'undefined' && IPython.notebook) {\n",
" IPython.notebook.kernel.execute(\"_jupyter_dark_detect_result = \" + \n",
" (document.body.classList.contains('theme-dark') || \n",
" document.body.classList.contains('jp-mod-dark') ||\n",
" (document.body.getAttribute('data-jp-theme-name') && \n",
" document.body.getAttribute('data-jp-theme-name').includes('dark'))));\n",
" }\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" (function() {\n",
" var isDark = false;\n",
"\n",
" // Check JupyterLab theme\n",
" if (document.body.classList.contains('jp-mod-dark') || \n",
" document.body.classList.contains('theme-dark') ||\n",
" document.body.classList.contains('vscode-dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check theme attribute\n",
" var themeAttr = document.body.getAttribute('data-jp-theme-name');\n",
" if (themeAttr && themeAttr.includes('dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check computed background color\n",
" var notebookEl = document.querySelector('.jp-Notebook') || \n",
" document.querySelector('.notebook_app') ||\n",
" document.body;\n",
" if (notebookEl) {\n",
" var bgColor = window.getComputedStyle(notebookEl).backgroundColor;\n",
" var rgb = bgColor.match(/\\d+/g);\n",
" if (rgb && rgb.length >= 3) {\n",
" var brightness = (parseInt(rgb[0]) + parseInt(rgb[1]) + parseInt(rgb[2])) / 3;\n",
" if (brightness < 128) {\n",
" isDark = true;\n",
" }\n",
" }\n",
" }\n",
"\n",
" // Store result\n",
" if (typeof IPython !== 'undefined' && IPython.notebook && IPython.notebook.kernel) {\n",
" IPython.notebook.kernel.execute('_jupyter_dark_detect_result = ' + isDark);\n",
" }\n",
" })();\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" if (typeof IPython !== 'undefined' && IPython.notebook) {\n",
" IPython.notebook.kernel.execute(\"_jupyter_dark_detect_result = \" + \n",
" (document.body.classList.contains('theme-dark') || \n",
" document.body.classList.contains('jp-mod-dark') ||\n",
" (document.body.getAttribute('data-jp-theme-name') && \n",
" document.body.getAttribute('data-jp-theme-name').includes('dark'))));\n",
" }\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" (function() {\n",
" var isDark = false;\n",
"\n",
" // Check JupyterLab theme\n",
" if (document.body.classList.contains('jp-mod-dark') || \n",
" document.body.classList.contains('theme-dark') ||\n",
" document.body.classList.contains('vscode-dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check theme attribute\n",
" var themeAttr = document.body.getAttribute('data-jp-theme-name');\n",
" if (themeAttr && themeAttr.includes('dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check computed background color\n",
" var notebookEl = document.querySelector('.jp-Notebook') || \n",
" document.querySelector('.notebook_app') ||\n",
" document.body;\n",
" if (notebookEl) {\n",
" var bgColor = window.getComputedStyle(notebookEl).backgroundColor;\n",
" var rgb = bgColor.match(/\\d+/g);\n",
" if (rgb && rgb.length >= 3) {\n",
" var brightness = (parseInt(rgb[0]) + parseInt(rgb[1]) + parseInt(rgb[2])) / 3;\n",
" if (brightness < 128) {\n",
" isDark = true;\n",
" }\n",
" }\n",
" }\n",
"\n",
" // Store result\n",
" if (typeof IPython !== 'undefined' && IPython.notebook && IPython.notebook.kernel) {\n",
" IPython.notebook.kernel.execute('_jupyter_dark_detect_result = ' + isDark);\n",
" }\n",
" })();\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" if (typeof IPython !== 'undefined' && IPython.notebook) {\n",
" IPython.notebook.kernel.execute(\"_jupyter_dark_detect_result = \" + \n",
" (document.body.classList.contains('theme-dark') || \n",
" document.body.classList.contains('jp-mod-dark') ||\n",
" (document.body.getAttribute('data-jp-theme-name') && \n",
" document.body.getAttribute('data-jp-theme-name').includes('dark'))));\n",
" }\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" (function() {\n",
" var isDark = false;\n",
"\n",
" // Check JupyterLab theme\n",
" if (document.body.classList.contains('jp-mod-dark') || \n",
" document.body.classList.contains('theme-dark') ||\n",
" document.body.classList.contains('vscode-dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check theme attribute\n",
" var themeAttr = document.body.getAttribute('data-jp-theme-name');\n",
" if (themeAttr && themeAttr.includes('dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check computed background color\n",
" var notebookEl = document.querySelector('.jp-Notebook') || \n",
" document.querySelector('.notebook_app') ||\n",
" document.body;\n",
" if (notebookEl) {\n",
" var bgColor = window.getComputedStyle(notebookEl).backgroundColor;\n",
" var rgb = bgColor.match(/\\d+/g);\n",
" if (rgb && rgb.length >= 3) {\n",
" var brightness = (parseInt(rgb[0]) + parseInt(rgb[1]) + parseInt(rgb[2])) / 3;\n",
" if (brightness < 128) {\n",
" isDark = true;\n",
" }\n",
" }\n",
" }\n",
"\n",
" // Store result\n",
" if (typeof IPython !== 'undefined' && IPython.notebook && IPython.notebook.kernel) {\n",
" IPython.notebook.kernel.execute('_jupyter_dark_detect_result = ' + isDark);\n",
" }\n",
" })();\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" if (typeof IPython !== 'undefined' && IPython.notebook) {\n",
" IPython.notebook.kernel.execute(\"_jupyter_dark_detect_result = \" + \n",
" (document.body.classList.contains('theme-dark') || \n",
" document.body.classList.contains('jp-mod-dark') ||\n",
" (document.body.getAttribute('data-jp-theme-name') && \n",
" document.body.getAttribute('data-jp-theme-name').includes('dark'))));\n",
" }\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" (function() {\n",
" var isDark = false;\n",
"\n",
" // Check JupyterLab theme\n",
" if (document.body.classList.contains('jp-mod-dark') || \n",
" document.body.classList.contains('theme-dark') ||\n",
" document.body.classList.contains('vscode-dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check theme attribute\n",
" var themeAttr = document.body.getAttribute('data-jp-theme-name');\n",
" if (themeAttr && themeAttr.includes('dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check computed background color\n",
" var notebookEl = document.querySelector('.jp-Notebook') || \n",
" document.querySelector('.notebook_app') ||\n",
" document.body;\n",
" if (notebookEl) {\n",
" var bgColor = window.getComputedStyle(notebookEl).backgroundColor;\n",
" var rgb = bgColor.match(/\\d+/g);\n",
" if (rgb && rgb.length >= 3) {\n",
" var brightness = (parseInt(rgb[0]) + parseInt(rgb[1]) + parseInt(rgb[2])) / 3;\n",
" if (brightness < 128) {\n",
" isDark = true;\n",
" }\n",
" }\n",
" }\n",
"\n",
" // Store result\n",
" if (typeof IPython !== 'undefined' && IPython.notebook && IPython.notebook.kernel) {\n",
" IPython.notebook.kernel.execute('_jupyter_dark_detect_result = ' + isDark);\n",
" }\n",
" })();\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" if (typeof IPython !== 'undefined' && IPython.notebook) {\n",
" IPython.notebook.kernel.execute(\"_jupyter_dark_detect_result = \" + \n",
" (document.body.classList.contains('theme-dark') || \n",
" document.body.classList.contains('jp-mod-dark') ||\n",
" (document.body.getAttribute('data-jp-theme-name') && \n",
" document.body.getAttribute('data-jp-theme-name').includes('dark'))));\n",
" }\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"🏆 Best goodness-of-fit \u001b[1m(\u001b[0mreduced χ²\u001b[1m)\u001b[0m is \u001b[1;36m66.72\u001b[0m at iteration \u001b[1;36m26\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"✅ Fitting complete.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;34mFit results\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"✅ Success: \u001b[3;92mTrue\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"⏱️ Fitting time: \u001b[1;36m11.47\u001b[0m seconds\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"📏 Goodness-of-fit \u001b[1m(\u001b[0mreduced χ²\u001b[1m)\u001b[0m: \u001b[1;36m66.72\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"📏 R-factor \u001b[1m(\u001b[0mRf\u001b[1m)\u001b[0m: \u001b[1;36m23.05\u001b[0m%\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"📏 R-factor squared \u001b[1m(\u001b[0mRf²\u001b[1m)\u001b[0m: \u001b[1;36m12.56\u001b[0m%\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"📏 Weighted R-factor \u001b[1m(\u001b[0mwR\u001b[1m)\u001b[0m: \u001b[1;36m12.54\u001b[0m%\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"📈 Fitted parameters:\n"
]
},
{
"data": {
"application/javascript": [
"\n",
" (function() {\n",
" var isDark = false;\n",
"\n",
" // Check JupyterLab theme\n",
" if (document.body.classList.contains('jp-mod-dark') || \n",
" document.body.classList.contains('theme-dark') ||\n",
" document.body.classList.contains('vscode-dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check theme attribute\n",
" var themeAttr = document.body.getAttribute('data-jp-theme-name');\n",
" if (themeAttr && themeAttr.includes('dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check computed background color\n",
" var notebookEl = document.querySelector('.jp-Notebook') || \n",
" document.querySelector('.notebook_app') ||\n",
" document.body;\n",
" if (notebookEl) {\n",
" var bgColor = window.getComputedStyle(notebookEl).backgroundColor;\n",
" var rgb = bgColor.match(/\\d+/g);\n",
" if (rgb && rgb.length >= 3) {\n",
" var brightness = (parseInt(rgb[0]) + parseInt(rgb[1]) + parseInt(rgb[2])) / 3;\n",
" if (brightness < 128) {\n",
" isDark = true;\n",
" }\n",
" }\n",
" }\n",
"\n",
" // Store result\n",
" if (typeof IPython !== 'undefined' && IPython.notebook && IPython.notebook.kernel) {\n",
" IPython.notebook.kernel.execute('_jupyter_dark_detect_result = ' + isDark);\n",
" }\n",
" })();\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" if (typeof IPython !== 'undefined' && IPython.notebook) {\n",
" IPython.notebook.kernel.execute(\"_jupyter_dark_detect_result = \" + \n",
" (document.body.classList.contains('theme-dark') || \n",
" document.body.classList.contains('jp-mod-dark') ||\n",
" (document.body.getAttribute('data-jp-theme-name') && \n",
" document.body.getAttribute('data-jp-theme-name').includes('dark'))));\n",
" }\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
"\n",
" \n",
" \n",
" | | \n",
" datablock | \n",
" category | \n",
" entry | \n",
" parameter | \n",
" start | \n",
" fitted | \n",
" uncertainty | \n",
" units | \n",
" change | \n",
"
\n",
" \n",
" \n",
" \n",
" | 1 | \n",
" si | \n",
" cell | \n",
" | \n",
" length_a | \n",
" 5.4310 | \n",
" 5.4314 | \n",
" 0.0002 | \n",
" Å | \n",
" 0.01 % ↑ | \n",
"
\n",
" \n",
" | 2 | \n",
" sepd | \n",
" linked_phases | \n",
" si | \n",
" scale | \n",
" 10.0000 | \n",
" 13.3619 | \n",
" 0.1153 | \n",
" | \n",
" 33.62 % ↑ | \n",
"
\n",
" \n",
" | 3 | \n",
" sepd | \n",
" instrument | \n",
" | \n",
" d_to_tof_offset | \n",
" 0.0000 | \n",
" -9.2543 | \n",
" 0.2503 | \n",
" µs | \n",
" N/A | \n",
"
\n",
" \n",
"
\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.analysis.fit()\n",
"project.analysis.show_fit_results()"
]
},
{
"cell_type": "markdown",
"id": "43",
"metadata": {},
"source": [
"#### Plot Measured vs Calculated"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "44",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:56:23.149826Z",
"iopub.status.busy": "2026-01-06T13:56:23.149617Z",
"iopub.status.idle": "2026-01-06T13:56:23.835777Z",
"shell.execute_reply": "2026-01-06T13:56:23.835003Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.plot_meas_vs_calc(expt_name='sepd', show_residual=True)"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "45",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:56:23.837928Z",
"iopub.status.busy": "2026-01-06T13:56:23.837796Z",
"iopub.status.idle": "2026-01-06T13:56:24.505307Z",
"shell.execute_reply": "2026-01-06T13:56:24.504363Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.plot_meas_vs_calc(expt_name='sepd', x_min=23200, x_max=23700, show_residual=True)"
]
},
{
"cell_type": "markdown",
"id": "46",
"metadata": {},
"source": [
"### Perform Fit 2/5\n",
"\n",
"Set more parameters to be refined."
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "47",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:56:24.508657Z",
"iopub.status.busy": "2026-01-06T13:56:24.508440Z",
"iopub.status.idle": "2026-01-06T13:56:24.511783Z",
"shell.execute_reply": "2026-01-06T13:56:24.511220Z"
}
},
"outputs": [],
"source": [
"for point in expt.background:\n",
" point.y.free = True"
]
},
{
"cell_type": "markdown",
"id": "48",
"metadata": {},
"source": [
"Show free parameters after selection."
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "49",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:56:24.513719Z",
"iopub.status.busy": "2026-01-06T13:56:24.513420Z",
"iopub.status.idle": "2026-01-06T13:56:24.895341Z",
"shell.execute_reply": "2026-01-06T13:56:24.894116Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;34mFree parameters for both sample models \u001b[0m\u001b[1;34m(\u001b[0m\u001b[1;34m🧩 data blocks\u001b[0m\u001b[1;34m)\u001b[0m\u001b[1;34m and experiments \u001b[0m\u001b[1;34m(\u001b[0m\u001b[1;34m🔬 data blocks\u001b[0m\u001b[1;34m)\u001b[0m\n"
]
},
{
"data": {
"application/javascript": [
"\n",
" (function() {\n",
" var isDark = false;\n",
"\n",
" // Check JupyterLab theme\n",
" if (document.body.classList.contains('jp-mod-dark') || \n",
" document.body.classList.contains('theme-dark') ||\n",
" document.body.classList.contains('vscode-dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check theme attribute\n",
" var themeAttr = document.body.getAttribute('data-jp-theme-name');\n",
" if (themeAttr && themeAttr.includes('dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check computed background color\n",
" var notebookEl = document.querySelector('.jp-Notebook') || \n",
" document.querySelector('.notebook_app') ||\n",
" document.body;\n",
" if (notebookEl) {\n",
" var bgColor = window.getComputedStyle(notebookEl).backgroundColor;\n",
" var rgb = bgColor.match(/\\d+/g);\n",
" if (rgb && rgb.length >= 3) {\n",
" var brightness = (parseInt(rgb[0]) + parseInt(rgb[1]) + parseInt(rgb[2])) / 3;\n",
" if (brightness < 128) {\n",
" isDark = true;\n",
" }\n",
" }\n",
" }\n",
"\n",
" // Store result\n",
" if (typeof IPython !== 'undefined' && IPython.notebook && IPython.notebook.kernel) {\n",
" IPython.notebook.kernel.execute('_jupyter_dark_detect_result = ' + isDark);\n",
" }\n",
" })();\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" if (typeof IPython !== 'undefined' && IPython.notebook) {\n",
" IPython.notebook.kernel.execute(\"_jupyter_dark_detect_result = \" + \n",
" (document.body.classList.contains('theme-dark') || \n",
" document.body.classList.contains('jp-mod-dark') ||\n",
" (document.body.getAttribute('data-jp-theme-name') && \n",
" document.body.getAttribute('data-jp-theme-name').includes('dark'))));\n",
" }\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
"\n",
" \n",
" \n",
" | | \n",
" datablock | \n",
" category | \n",
" entry | \n",
" parameter | \n",
" value | \n",
" uncertainty | \n",
" min | \n",
" max | \n",
" units | \n",
"
\n",
" \n",
" \n",
" \n",
" | 1 | \n",
" si | \n",
" cell | \n",
" | \n",
" length_a | \n",
" 5.43135 | \n",
" 0.00018 | \n",
" -inf | \n",
" inf | \n",
" Å | \n",
"
\n",
" \n",
" | 2 | \n",
" sepd | \n",
" linked_phases | \n",
" si | \n",
" scale | \n",
" 13.36187 | \n",
" 0.11531 | \n",
" -inf | \n",
" inf | \n",
" | \n",
"
\n",
" \n",
" | 3 | \n",
" sepd | \n",
" instrument | \n",
" | \n",
" d_to_tof_offset | \n",
" -9.25432 | \n",
" 0.25033 | \n",
" -inf | \n",
" inf | \n",
" µs | \n",
"
\n",
" \n",
" | 4 | \n",
" sepd | \n",
" background | \n",
" 0 | \n",
" y | \n",
" 200.00000 | \n",
" | \n",
" -inf | \n",
" inf | \n",
" | \n",
"
\n",
" \n",
" | 5 | \n",
" sepd | \n",
" background | \n",
" 5000 | \n",
" y | \n",
" 200.00000 | \n",
" | \n",
" -inf | \n",
" inf | \n",
" | \n",
"
\n",
" \n",
" | 6 | \n",
" sepd | \n",
" background | \n",
" 10000 | \n",
" y | \n",
" 200.00000 | \n",
" | \n",
" -inf | \n",
" inf | \n",
" | \n",
"
\n",
" \n",
" | 7 | \n",
" sepd | \n",
" background | \n",
" 15000 | \n",
" y | \n",
" 200.00000 | \n",
" | \n",
" -inf | \n",
" inf | \n",
" | \n",
"
\n",
" \n",
" | 8 | \n",
" sepd | \n",
" background | \n",
" 20000 | \n",
" y | \n",
" 200.00000 | \n",
" | \n",
" -inf | \n",
" inf | \n",
" | \n",
"
\n",
" \n",
" | 9 | \n",
" sepd | \n",
" background | \n",
" 25000 | \n",
" y | \n",
" 200.00000 | \n",
" | \n",
" -inf | \n",
" inf | \n",
" | \n",
"
\n",
" \n",
" | 10 | \n",
" sepd | \n",
" background | \n",
" 30000 | \n",
" y | \n",
" 200.00000 | \n",
" | \n",
" -inf | \n",
" inf | \n",
" | \n",
"
\n",
" \n",
"
\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.analysis.show_free_params()"
]
},
{
"cell_type": "markdown",
"id": "50",
"metadata": {},
"source": [
"#### Run Fitting"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "51",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:56:24.899150Z",
"iopub.status.busy": "2026-01-06T13:56:24.898610Z",
"iopub.status.idle": "2026-01-06T13:56:42.871701Z",
"shell.execute_reply": "2026-01-06T13:56:42.870325Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;34mUsing experiment 🔬 \u001b[0m\u001b[32m'sepd'\u001b[0m\u001b[1;34m for \u001b[0m\u001b[32m'single'\u001b[0m\u001b[1;34m fitting\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"🚀 Starting fit process with \u001b[32m'lmfit \u001b[0m\u001b[32m(\u001b[0m\u001b[32mleastsq\u001b[0m\u001b[32m)\u001b[0m\u001b[32m'\u001b[0m\u001b[33m...\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"📈 Goodness-of-fit \u001b[1m(\u001b[0mreduced χ²\u001b[1m)\u001b[0m change:\n"
]
},
{
"data": {
"text/html": [
"\n",
"\n",
" \n",
" \n",
" | | \n",
" iteration | \n",
" χ² | \n",
" improvement [%] | \n",
"
\n",
" \n",
" \n",
" \n",
" | 1 | \n",
" 1 | \n",
" 66.80 | \n",
" | \n",
"
\n",
" \n",
" | 2 | \n",
" 14 | \n",
" 3.38 | \n",
" 94.9% ↓ | \n",
"
\n",
" \n",
" | 3 | \n",
" 48 | \n",
" 3.38 | \n",
" | \n",
"
\n",
" \n",
"
\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" (function() {\n",
" var isDark = false;\n",
"\n",
" // Check JupyterLab theme\n",
" if (document.body.classList.contains('jp-mod-dark') || \n",
" document.body.classList.contains('theme-dark') ||\n",
" document.body.classList.contains('vscode-dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check theme attribute\n",
" var themeAttr = document.body.getAttribute('data-jp-theme-name');\n",
" if (themeAttr && themeAttr.includes('dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check computed background color\n",
" var notebookEl = document.querySelector('.jp-Notebook') || \n",
" document.querySelector('.notebook_app') ||\n",
" document.body;\n",
" if (notebookEl) {\n",
" var bgColor = window.getComputedStyle(notebookEl).backgroundColor;\n",
" var rgb = bgColor.match(/\\d+/g);\n",
" if (rgb && rgb.length >= 3) {\n",
" var brightness = (parseInt(rgb[0]) + parseInt(rgb[1]) + parseInt(rgb[2])) / 3;\n",
" if (brightness < 128) {\n",
" isDark = true;\n",
" }\n",
" }\n",
" }\n",
"\n",
" // Store result\n",
" if (typeof IPython !== 'undefined' && IPython.notebook && IPython.notebook.kernel) {\n",
" IPython.notebook.kernel.execute('_jupyter_dark_detect_result = ' + isDark);\n",
" }\n",
" })();\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" if (typeof IPython !== 'undefined' && IPython.notebook) {\n",
" IPython.notebook.kernel.execute(\"_jupyter_dark_detect_result = \" + \n",
" (document.body.classList.contains('theme-dark') || \n",
" document.body.classList.contains('jp-mod-dark') ||\n",
" (document.body.getAttribute('data-jp-theme-name') && \n",
" document.body.getAttribute('data-jp-theme-name').includes('dark'))));\n",
" }\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" (function() {\n",
" var isDark = false;\n",
"\n",
" // Check JupyterLab theme\n",
" if (document.body.classList.contains('jp-mod-dark') || \n",
" document.body.classList.contains('theme-dark') ||\n",
" document.body.classList.contains('vscode-dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check theme attribute\n",
" var themeAttr = document.body.getAttribute('data-jp-theme-name');\n",
" if (themeAttr && themeAttr.includes('dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check computed background color\n",
" var notebookEl = document.querySelector('.jp-Notebook') || \n",
" document.querySelector('.notebook_app') ||\n",
" document.body;\n",
" if (notebookEl) {\n",
" var bgColor = window.getComputedStyle(notebookEl).backgroundColor;\n",
" var rgb = bgColor.match(/\\d+/g);\n",
" if (rgb && rgb.length >= 3) {\n",
" var brightness = (parseInt(rgb[0]) + parseInt(rgb[1]) + parseInt(rgb[2])) / 3;\n",
" if (brightness < 128) {\n",
" isDark = true;\n",
" }\n",
" }\n",
" }\n",
"\n",
" // Store result\n",
" if (typeof IPython !== 'undefined' && IPython.notebook && IPython.notebook.kernel) {\n",
" IPython.notebook.kernel.execute('_jupyter_dark_detect_result = ' + isDark);\n",
" }\n",
" })();\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" if (typeof IPython !== 'undefined' && IPython.notebook) {\n",
" IPython.notebook.kernel.execute(\"_jupyter_dark_detect_result = \" + \n",
" (document.body.classList.contains('theme-dark') || \n",
" document.body.classList.contains('jp-mod-dark') ||\n",
" (document.body.getAttribute('data-jp-theme-name') && \n",
" document.body.getAttribute('data-jp-theme-name').includes('dark'))));\n",
" }\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" (function() {\n",
" var isDark = false;\n",
"\n",
" // Check JupyterLab theme\n",
" if (document.body.classList.contains('jp-mod-dark') || \n",
" document.body.classList.contains('theme-dark') ||\n",
" document.body.classList.contains('vscode-dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check theme attribute\n",
" var themeAttr = document.body.getAttribute('data-jp-theme-name');\n",
" if (themeAttr && themeAttr.includes('dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check computed background color\n",
" var notebookEl = document.querySelector('.jp-Notebook') || \n",
" document.querySelector('.notebook_app') ||\n",
" document.body;\n",
" if (notebookEl) {\n",
" var bgColor = window.getComputedStyle(notebookEl).backgroundColor;\n",
" var rgb = bgColor.match(/\\d+/g);\n",
" if (rgb && rgb.length >= 3) {\n",
" var brightness = (parseInt(rgb[0]) + parseInt(rgb[1]) + parseInt(rgb[2])) / 3;\n",
" if (brightness < 128) {\n",
" isDark = true;\n",
" }\n",
" }\n",
" }\n",
"\n",
" // Store result\n",
" if (typeof IPython !== 'undefined' && IPython.notebook && IPython.notebook.kernel) {\n",
" IPython.notebook.kernel.execute('_jupyter_dark_detect_result = ' + isDark);\n",
" }\n",
" })();\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" if (typeof IPython !== 'undefined' && IPython.notebook) {\n",
" IPython.notebook.kernel.execute(\"_jupyter_dark_detect_result = \" + \n",
" (document.body.classList.contains('theme-dark') || \n",
" document.body.classList.contains('jp-mod-dark') ||\n",
" (document.body.getAttribute('data-jp-theme-name') && \n",
" document.body.getAttribute('data-jp-theme-name').includes('dark'))));\n",
" }\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" (function() {\n",
" var isDark = false;\n",
"\n",
" // Check JupyterLab theme\n",
" if (document.body.classList.contains('jp-mod-dark') || \n",
" document.body.classList.contains('theme-dark') ||\n",
" document.body.classList.contains('vscode-dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check theme attribute\n",
" var themeAttr = document.body.getAttribute('data-jp-theme-name');\n",
" if (themeAttr && themeAttr.includes('dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check computed background color\n",
" var notebookEl = document.querySelector('.jp-Notebook') || \n",
" document.querySelector('.notebook_app') ||\n",
" document.body;\n",
" if (notebookEl) {\n",
" var bgColor = window.getComputedStyle(notebookEl).backgroundColor;\n",
" var rgb = bgColor.match(/\\d+/g);\n",
" if (rgb && rgb.length >= 3) {\n",
" var brightness = (parseInt(rgb[0]) + parseInt(rgb[1]) + parseInt(rgb[2])) / 3;\n",
" if (brightness < 128) {\n",
" isDark = true;\n",
" }\n",
" }\n",
" }\n",
"\n",
" // Store result\n",
" if (typeof IPython !== 'undefined' && IPython.notebook && IPython.notebook.kernel) {\n",
" IPython.notebook.kernel.execute('_jupyter_dark_detect_result = ' + isDark);\n",
" }\n",
" })();\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" if (typeof IPython !== 'undefined' && IPython.notebook) {\n",
" IPython.notebook.kernel.execute(\"_jupyter_dark_detect_result = \" + \n",
" (document.body.classList.contains('theme-dark') || \n",
" document.body.classList.contains('jp-mod-dark') ||\n",
" (document.body.getAttribute('data-jp-theme-name') && \n",
" document.body.getAttribute('data-jp-theme-name').includes('dark'))));\n",
" }\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"🏆 Best goodness-of-fit \u001b[1m(\u001b[0mreduced χ²\u001b[1m)\u001b[0m is \u001b[1;36m3.38\u001b[0m at iteration \u001b[1;36m47\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"✅ Fitting complete.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;34mFit results\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"✅ Success: \u001b[3;92mTrue\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"⏱️ Fitting time: \u001b[1;36m16.14\u001b[0m seconds\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"📏 Goodness-of-fit \u001b[1m(\u001b[0mreduced χ²\u001b[1m)\u001b[0m: \u001b[1;36m3.38\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"📏 R-factor \u001b[1m(\u001b[0mRf\u001b[1m)\u001b[0m: \u001b[1;36m9.29\u001b[0m%\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"📏 R-factor squared \u001b[1m(\u001b[0mRf²\u001b[1m)\u001b[0m: \u001b[1;36m6.35\u001b[0m%\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"📏 Weighted R-factor \u001b[1m(\u001b[0mwR\u001b[1m)\u001b[0m: \u001b[1;36m5.99\u001b[0m%\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"📈 Fitted parameters:\n"
]
},
{
"data": {
"application/javascript": [
"\n",
" (function() {\n",
" var isDark = false;\n",
"\n",
" // Check JupyterLab theme\n",
" if (document.body.classList.contains('jp-mod-dark') || \n",
" document.body.classList.contains('theme-dark') ||\n",
" document.body.classList.contains('vscode-dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check theme attribute\n",
" var themeAttr = document.body.getAttribute('data-jp-theme-name');\n",
" if (themeAttr && themeAttr.includes('dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check computed background color\n",
" var notebookEl = document.querySelector('.jp-Notebook') || \n",
" document.querySelector('.notebook_app') ||\n",
" document.body;\n",
" if (notebookEl) {\n",
" var bgColor = window.getComputedStyle(notebookEl).backgroundColor;\n",
" var rgb = bgColor.match(/\\d+/g);\n",
" if (rgb && rgb.length >= 3) {\n",
" var brightness = (parseInt(rgb[0]) + parseInt(rgb[1]) + parseInt(rgb[2])) / 3;\n",
" if (brightness < 128) {\n",
" isDark = true;\n",
" }\n",
" }\n",
" }\n",
"\n",
" // Store result\n",
" if (typeof IPython !== 'undefined' && IPython.notebook && IPython.notebook.kernel) {\n",
" IPython.notebook.kernel.execute('_jupyter_dark_detect_result = ' + isDark);\n",
" }\n",
" })();\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" if (typeof IPython !== 'undefined' && IPython.notebook) {\n",
" IPython.notebook.kernel.execute(\"_jupyter_dark_detect_result = \" + \n",
" (document.body.classList.contains('theme-dark') || \n",
" document.body.classList.contains('jp-mod-dark') ||\n",
" (document.body.getAttribute('data-jp-theme-name') && \n",
" document.body.getAttribute('data-jp-theme-name').includes('dark'))));\n",
" }\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
"\n",
" \n",
" \n",
" | | \n",
" datablock | \n",
" category | \n",
" entry | \n",
" parameter | \n",
" start | \n",
" fitted | \n",
" uncertainty | \n",
" units | \n",
" change | \n",
"
\n",
" \n",
" \n",
" \n",
" | 1 | \n",
" si | \n",
" cell | \n",
" | \n",
" length_a | \n",
" 5.4314 | \n",
" 5.4314 | \n",
" 0.0000 | \n",
" Å | \n",
" 0.00 % ↑ | \n",
"
\n",
" \n",
" | 2 | \n",
" sepd | \n",
" linked_phases | \n",
" si | \n",
" scale | \n",
" 13.3619 | \n",
" 14.6317 | \n",
" 0.0265 | \n",
" | \n",
" 9.50 % ↑ | \n",
"
\n",
" \n",
" | 3 | \n",
" sepd | \n",
" instrument | \n",
" | \n",
" d_to_tof_offset | \n",
" -9.2543 | \n",
" -9.2534 | \n",
" 0.0515 | \n",
" µs | \n",
" 0.01 % ↓ | \n",
"
\n",
" \n",
" | 4 | \n",
" sepd | \n",
" background | \n",
" 0 | \n",
" y | \n",
" 200.0000 | \n",
" 268.6002 | \n",
" 0.9745 | \n",
" | \n",
" 34.30 % ↑ | \n",
"
\n",
" \n",
" | 5 | \n",
" sepd | \n",
" background | \n",
" 5000 | \n",
" y | \n",
" 200.0000 | \n",
" 144.7589 | \n",
" 0.4071 | \n",
" | \n",
" 27.62 % ↓ | \n",
"
\n",
" \n",
" | 6 | \n",
" sepd | \n",
" background | \n",
" 10000 | \n",
" y | \n",
" 200.0000 | \n",
" 120.0247 | \n",
" 0.4282 | \n",
" | \n",
" 39.99 % ↓ | \n",
"
\n",
" \n",
" | 7 | \n",
" sepd | \n",
" background | \n",
" 15000 | \n",
" y | \n",
" 200.0000 | \n",
" 135.8494 | \n",
" 0.8169 | \n",
" | \n",
" 32.08 % ↓ | \n",
"
\n",
" \n",
" | 8 | \n",
" sepd | \n",
" background | \n",
" 20000 | \n",
" y | \n",
" 200.0000 | \n",
" 132.6887 | \n",
" 1.4317 | \n",
" | \n",
" 33.66 % ↓ | \n",
"
\n",
" \n",
" | 9 | \n",
" sepd | \n",
" background | \n",
" 25000 | \n",
" y | \n",
" 200.0000 | \n",
" 175.1775 | \n",
" 2.8755 | \n",
" | \n",
" 12.41 % ↓ | \n",
"
\n",
" \n",
" | 10 | \n",
" sepd | \n",
" background | \n",
" 30000 | \n",
" y | \n",
" 200.0000 | \n",
" 180.4556 | \n",
" 5.8525 | \n",
" | \n",
" 9.77 % ↓ | \n",
"
\n",
" \n",
"
\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.analysis.fit()\n",
"project.analysis.show_fit_results()"
]
},
{
"cell_type": "markdown",
"id": "52",
"metadata": {},
"source": [
"#### Plot Measured vs Calculated"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "53",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:56:42.877085Z",
"iopub.status.busy": "2026-01-06T13:56:42.876813Z",
"iopub.status.idle": "2026-01-06T13:56:43.782578Z",
"shell.execute_reply": "2026-01-06T13:56:43.782032Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.plot_meas_vs_calc(expt_name='sepd', show_residual=True)"
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "54",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:56:43.784306Z",
"iopub.status.busy": "2026-01-06T13:56:43.784174Z",
"iopub.status.idle": "2026-01-06T13:56:44.742569Z",
"shell.execute_reply": "2026-01-06T13:56:44.741878Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.plot_meas_vs_calc(expt_name='sepd', x_min=23200, x_max=23700, show_residual=True)"
]
},
{
"cell_type": "markdown",
"id": "55",
"metadata": {},
"source": [
"### Perform Fit 3/5\n",
"\n",
"Fix background points."
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "56",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:56:44.744617Z",
"iopub.status.busy": "2026-01-06T13:56:44.744490Z",
"iopub.status.idle": "2026-01-06T13:56:44.747069Z",
"shell.execute_reply": "2026-01-06T13:56:44.746633Z"
}
},
"outputs": [],
"source": [
"for point in expt.background:\n",
" point.y.free = False"
]
},
{
"cell_type": "markdown",
"id": "57",
"metadata": {},
"source": [
"Set more parameters to be refined."
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "58",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:56:44.748708Z",
"iopub.status.busy": "2026-01-06T13:56:44.748565Z",
"iopub.status.idle": "2026-01-06T13:56:44.751555Z",
"shell.execute_reply": "2026-01-06T13:56:44.750742Z"
}
},
"outputs": [],
"source": [
"expt.peak.broad_gauss_sigma_0.free = True\n",
"expt.peak.broad_gauss_sigma_1.free = True\n",
"expt.peak.broad_gauss_sigma_2.free = True"
]
},
{
"cell_type": "markdown",
"id": "59",
"metadata": {},
"source": [
"Show free parameters after selection."
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "60",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:56:44.754146Z",
"iopub.status.busy": "2026-01-06T13:56:44.753999Z",
"iopub.status.idle": "2026-01-06T13:56:45.066444Z",
"shell.execute_reply": "2026-01-06T13:56:45.066003Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;34mFree parameters for both sample models \u001b[0m\u001b[1;34m(\u001b[0m\u001b[1;34m🧩 data blocks\u001b[0m\u001b[1;34m)\u001b[0m\u001b[1;34m and experiments \u001b[0m\u001b[1;34m(\u001b[0m\u001b[1;34m🔬 data blocks\u001b[0m\u001b[1;34m)\u001b[0m\n"
]
},
{
"data": {
"application/javascript": [
"\n",
" (function() {\n",
" var isDark = false;\n",
"\n",
" // Check JupyterLab theme\n",
" if (document.body.classList.contains('jp-mod-dark') || \n",
" document.body.classList.contains('theme-dark') ||\n",
" document.body.classList.contains('vscode-dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check theme attribute\n",
" var themeAttr = document.body.getAttribute('data-jp-theme-name');\n",
" if (themeAttr && themeAttr.includes('dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check computed background color\n",
" var notebookEl = document.querySelector('.jp-Notebook') || \n",
" document.querySelector('.notebook_app') ||\n",
" document.body;\n",
" if (notebookEl) {\n",
" var bgColor = window.getComputedStyle(notebookEl).backgroundColor;\n",
" var rgb = bgColor.match(/\\d+/g);\n",
" if (rgb && rgb.length >= 3) {\n",
" var brightness = (parseInt(rgb[0]) + parseInt(rgb[1]) + parseInt(rgb[2])) / 3;\n",
" if (brightness < 128) {\n",
" isDark = true;\n",
" }\n",
" }\n",
" }\n",
"\n",
" // Store result\n",
" if (typeof IPython !== 'undefined' && IPython.notebook && IPython.notebook.kernel) {\n",
" IPython.notebook.kernel.execute('_jupyter_dark_detect_result = ' + isDark);\n",
" }\n",
" })();\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" if (typeof IPython !== 'undefined' && IPython.notebook) {\n",
" IPython.notebook.kernel.execute(\"_jupyter_dark_detect_result = \" + \n",
" (document.body.classList.contains('theme-dark') || \n",
" document.body.classList.contains('jp-mod-dark') ||\n",
" (document.body.getAttribute('data-jp-theme-name') && \n",
" document.body.getAttribute('data-jp-theme-name').includes('dark'))));\n",
" }\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
"\n",
" \n",
" \n",
" | | \n",
" datablock | \n",
" category | \n",
" entry | \n",
" parameter | \n",
" value | \n",
" uncertainty | \n",
" min | \n",
" max | \n",
" units | \n",
"
\n",
" \n",
" \n",
" \n",
" | 1 | \n",
" si | \n",
" cell | \n",
" | \n",
" length_a | \n",
" 5.43137 | \n",
" 0.00004 | \n",
" -inf | \n",
" inf | \n",
" Å | \n",
"
\n",
" \n",
" | 2 | \n",
" sepd | \n",
" linked_phases | \n",
" si | \n",
" scale | \n",
" 14.63167 | \n",
" 0.02651 | \n",
" -inf | \n",
" inf | \n",
" | \n",
"
\n",
" \n",
" | 3 | \n",
" sepd | \n",
" peak | \n",
" | \n",
" gauss_sigma_0 | \n",
" 3.00000 | \n",
" | \n",
" -inf | \n",
" inf | \n",
" µs² | \n",
"
\n",
" \n",
" | 4 | \n",
" sepd | \n",
" peak | \n",
" | \n",
" gauss_sigma_1 | \n",
" 40.00000 | \n",
" | \n",
" -inf | \n",
" inf | \n",
" µs/Å | \n",
"
\n",
" \n",
" | 5 | \n",
" sepd | \n",
" peak | \n",
" | \n",
" gauss_sigma_2 | \n",
" 2.00000 | \n",
" | \n",
" -inf | \n",
" inf | \n",
" µs²/Ų | \n",
"
\n",
" \n",
" | 6 | \n",
" sepd | \n",
" instrument | \n",
" | \n",
" d_to_tof_offset | \n",
" -9.25336 | \n",
" 0.05153 | \n",
" -inf | \n",
" inf | \n",
" µs | \n",
"
\n",
" \n",
"
\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.analysis.show_free_params()"
]
},
{
"cell_type": "markdown",
"id": "61",
"metadata": {},
"source": [
"#### Run Fitting"
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "62",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:56:45.068493Z",
"iopub.status.busy": "2026-01-06T13:56:45.068333Z",
"iopub.status.idle": "2026-01-06T13:57:02.694717Z",
"shell.execute_reply": "2026-01-06T13:57:02.693642Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;34mUsing experiment 🔬 \u001b[0m\u001b[32m'sepd'\u001b[0m\u001b[1;34m for \u001b[0m\u001b[32m'single'\u001b[0m\u001b[1;34m fitting\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"🚀 Starting fit process with \u001b[32m'lmfit \u001b[0m\u001b[32m(\u001b[0m\u001b[32mleastsq\u001b[0m\u001b[32m)\u001b[0m\u001b[32m'\u001b[0m\u001b[33m...\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"📈 Goodness-of-fit \u001b[1m(\u001b[0mreduced χ²\u001b[1m)\u001b[0m change:\n"
]
},
{
"data": {
"text/html": [
"\n",
"\n",
" \n",
" \n",
" | | \n",
" iteration | \n",
" χ² | \n",
" improvement [%] | \n",
"
\n",
" \n",
" \n",
" \n",
" | 1 | \n",
" 1 | \n",
" 3.38 | \n",
" | \n",
"
\n",
" \n",
" | 2 | \n",
" 10 | \n",
" 3.21 | \n",
" 5.0% ↓ | \n",
"
\n",
" \n",
" | 3 | \n",
" 39 | \n",
" 3.21 | \n",
" | \n",
"
\n",
" \n",
"
\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" (function() {\n",
" var isDark = false;\n",
"\n",
" // Check JupyterLab theme\n",
" if (document.body.classList.contains('jp-mod-dark') || \n",
" document.body.classList.contains('theme-dark') ||\n",
" document.body.classList.contains('vscode-dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check theme attribute\n",
" var themeAttr = document.body.getAttribute('data-jp-theme-name');\n",
" if (themeAttr && themeAttr.includes('dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check computed background color\n",
" var notebookEl = document.querySelector('.jp-Notebook') || \n",
" document.querySelector('.notebook_app') ||\n",
" document.body;\n",
" if (notebookEl) {\n",
" var bgColor = window.getComputedStyle(notebookEl).backgroundColor;\n",
" var rgb = bgColor.match(/\\d+/g);\n",
" if (rgb && rgb.length >= 3) {\n",
" var brightness = (parseInt(rgb[0]) + parseInt(rgb[1]) + parseInt(rgb[2])) / 3;\n",
" if (brightness < 128) {\n",
" isDark = true;\n",
" }\n",
" }\n",
" }\n",
"\n",
" // Store result\n",
" if (typeof IPython !== 'undefined' && IPython.notebook && IPython.notebook.kernel) {\n",
" IPython.notebook.kernel.execute('_jupyter_dark_detect_result = ' + isDark);\n",
" }\n",
" })();\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" if (typeof IPython !== 'undefined' && IPython.notebook) {\n",
" IPython.notebook.kernel.execute(\"_jupyter_dark_detect_result = \" + \n",
" (document.body.classList.contains('theme-dark') || \n",
" document.body.classList.contains('jp-mod-dark') ||\n",
" (document.body.getAttribute('data-jp-theme-name') && \n",
" document.body.getAttribute('data-jp-theme-name').includes('dark'))));\n",
" }\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" (function() {\n",
" var isDark = false;\n",
"\n",
" // Check JupyterLab theme\n",
" if (document.body.classList.contains('jp-mod-dark') || \n",
" document.body.classList.contains('theme-dark') ||\n",
" document.body.classList.contains('vscode-dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check theme attribute\n",
" var themeAttr = document.body.getAttribute('data-jp-theme-name');\n",
" if (themeAttr && themeAttr.includes('dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check computed background color\n",
" var notebookEl = document.querySelector('.jp-Notebook') || \n",
" document.querySelector('.notebook_app') ||\n",
" document.body;\n",
" if (notebookEl) {\n",
" var bgColor = window.getComputedStyle(notebookEl).backgroundColor;\n",
" var rgb = bgColor.match(/\\d+/g);\n",
" if (rgb && rgb.length >= 3) {\n",
" var brightness = (parseInt(rgb[0]) + parseInt(rgb[1]) + parseInt(rgb[2])) / 3;\n",
" if (brightness < 128) {\n",
" isDark = true;\n",
" }\n",
" }\n",
" }\n",
"\n",
" // Store result\n",
" if (typeof IPython !== 'undefined' && IPython.notebook && IPython.notebook.kernel) {\n",
" IPython.notebook.kernel.execute('_jupyter_dark_detect_result = ' + isDark);\n",
" }\n",
" })();\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" if (typeof IPython !== 'undefined' && IPython.notebook) {\n",
" IPython.notebook.kernel.execute(\"_jupyter_dark_detect_result = \" + \n",
" (document.body.classList.contains('theme-dark') || \n",
" document.body.classList.contains('jp-mod-dark') ||\n",
" (document.body.getAttribute('data-jp-theme-name') && \n",
" document.body.getAttribute('data-jp-theme-name').includes('dark'))));\n",
" }\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" (function() {\n",
" var isDark = false;\n",
"\n",
" // Check JupyterLab theme\n",
" if (document.body.classList.contains('jp-mod-dark') || \n",
" document.body.classList.contains('theme-dark') ||\n",
" document.body.classList.contains('vscode-dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check theme attribute\n",
" var themeAttr = document.body.getAttribute('data-jp-theme-name');\n",
" if (themeAttr && themeAttr.includes('dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check computed background color\n",
" var notebookEl = document.querySelector('.jp-Notebook') || \n",
" document.querySelector('.notebook_app') ||\n",
" document.body;\n",
" if (notebookEl) {\n",
" var bgColor = window.getComputedStyle(notebookEl).backgroundColor;\n",
" var rgb = bgColor.match(/\\d+/g);\n",
" if (rgb && rgb.length >= 3) {\n",
" var brightness = (parseInt(rgb[0]) + parseInt(rgb[1]) + parseInt(rgb[2])) / 3;\n",
" if (brightness < 128) {\n",
" isDark = true;\n",
" }\n",
" }\n",
" }\n",
"\n",
" // Store result\n",
" if (typeof IPython !== 'undefined' && IPython.notebook && IPython.notebook.kernel) {\n",
" IPython.notebook.kernel.execute('_jupyter_dark_detect_result = ' + isDark);\n",
" }\n",
" })();\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" if (typeof IPython !== 'undefined' && IPython.notebook) {\n",
" IPython.notebook.kernel.execute(\"_jupyter_dark_detect_result = \" + \n",
" (document.body.classList.contains('theme-dark') || \n",
" document.body.classList.contains('jp-mod-dark') ||\n",
" (document.body.getAttribute('data-jp-theme-name') && \n",
" document.body.getAttribute('data-jp-theme-name').includes('dark'))));\n",
" }\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" (function() {\n",
" var isDark = false;\n",
"\n",
" // Check JupyterLab theme\n",
" if (document.body.classList.contains('jp-mod-dark') || \n",
" document.body.classList.contains('theme-dark') ||\n",
" document.body.classList.contains('vscode-dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check theme attribute\n",
" var themeAttr = document.body.getAttribute('data-jp-theme-name');\n",
" if (themeAttr && themeAttr.includes('dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check computed background color\n",
" var notebookEl = document.querySelector('.jp-Notebook') || \n",
" document.querySelector('.notebook_app') ||\n",
" document.body;\n",
" if (notebookEl) {\n",
" var bgColor = window.getComputedStyle(notebookEl).backgroundColor;\n",
" var rgb = bgColor.match(/\\d+/g);\n",
" if (rgb && rgb.length >= 3) {\n",
" var brightness = (parseInt(rgb[0]) + parseInt(rgb[1]) + parseInt(rgb[2])) / 3;\n",
" if (brightness < 128) {\n",
" isDark = true;\n",
" }\n",
" }\n",
" }\n",
"\n",
" // Store result\n",
" if (typeof IPython !== 'undefined' && IPython.notebook && IPython.notebook.kernel) {\n",
" IPython.notebook.kernel.execute('_jupyter_dark_detect_result = ' + isDark);\n",
" }\n",
" })();\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" if (typeof IPython !== 'undefined' && IPython.notebook) {\n",
" IPython.notebook.kernel.execute(\"_jupyter_dark_detect_result = \" + \n",
" (document.body.classList.contains('theme-dark') || \n",
" document.body.classList.contains('jp-mod-dark') ||\n",
" (document.body.getAttribute('data-jp-theme-name') && \n",
" document.body.getAttribute('data-jp-theme-name').includes('dark'))));\n",
" }\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"🏆 Best goodness-of-fit \u001b[1m(\u001b[0mreduced χ²\u001b[1m)\u001b[0m is \u001b[1;36m3.21\u001b[0m at iteration \u001b[1;36m38\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"✅ Fitting complete.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;34mFit results\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"✅ Success: \u001b[3;92mTrue\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"⏱️ Fitting time: \u001b[1;36m15.71\u001b[0m seconds\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"📏 Goodness-of-fit \u001b[1m(\u001b[0mreduced χ²\u001b[1m)\u001b[0m: \u001b[1;36m3.21\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"📏 R-factor \u001b[1m(\u001b[0mRf\u001b[1m)\u001b[0m: \u001b[1;36m9.00\u001b[0m%\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"📏 R-factor squared \u001b[1m(\u001b[0mRf²\u001b[1m)\u001b[0m: \u001b[1;36m5.49\u001b[0m%\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"📏 Weighted R-factor \u001b[1m(\u001b[0mwR\u001b[1m)\u001b[0m: \u001b[1;36m4.81\u001b[0m%\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"📈 Fitted parameters:\n"
]
},
{
"data": {
"application/javascript": [
"\n",
" (function() {\n",
" var isDark = false;\n",
"\n",
" // Check JupyterLab theme\n",
" if (document.body.classList.contains('jp-mod-dark') || \n",
" document.body.classList.contains('theme-dark') ||\n",
" document.body.classList.contains('vscode-dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check theme attribute\n",
" var themeAttr = document.body.getAttribute('data-jp-theme-name');\n",
" if (themeAttr && themeAttr.includes('dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check computed background color\n",
" var notebookEl = document.querySelector('.jp-Notebook') || \n",
" document.querySelector('.notebook_app') ||\n",
" document.body;\n",
" if (notebookEl) {\n",
" var bgColor = window.getComputedStyle(notebookEl).backgroundColor;\n",
" var rgb = bgColor.match(/\\d+/g);\n",
" if (rgb && rgb.length >= 3) {\n",
" var brightness = (parseInt(rgb[0]) + parseInt(rgb[1]) + parseInt(rgb[2])) / 3;\n",
" if (brightness < 128) {\n",
" isDark = true;\n",
" }\n",
" }\n",
" }\n",
"\n",
" // Store result\n",
" if (typeof IPython !== 'undefined' && IPython.notebook && IPython.notebook.kernel) {\n",
" IPython.notebook.kernel.execute('_jupyter_dark_detect_result = ' + isDark);\n",
" }\n",
" })();\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" if (typeof IPython !== 'undefined' && IPython.notebook) {\n",
" IPython.notebook.kernel.execute(\"_jupyter_dark_detect_result = \" + \n",
" (document.body.classList.contains('theme-dark') || \n",
" document.body.classList.contains('jp-mod-dark') ||\n",
" (document.body.getAttribute('data-jp-theme-name') && \n",
" document.body.getAttribute('data-jp-theme-name').includes('dark'))));\n",
" }\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
"\n",
" \n",
" \n",
" | | \n",
" datablock | \n",
" category | \n",
" entry | \n",
" parameter | \n",
" start | \n",
" fitted | \n",
" uncertainty | \n",
" units | \n",
" change | \n",
"
\n",
" \n",
" \n",
" \n",
" | 1 | \n",
" si | \n",
" cell | \n",
" | \n",
" length_a | \n",
" 5.4314 | \n",
" 5.4314 | \n",
" 0.0000 | \n",
" Å | \n",
" 0.00 % ↑ | \n",
"
\n",
" \n",
" | 2 | \n",
" sepd | \n",
" linked_phases | \n",
" si | \n",
" scale | \n",
" 14.6317 | \n",
" 14.7057 | \n",
" 0.0257 | \n",
" | \n",
" 0.51 % ↑ | \n",
"
\n",
" \n",
" | 3 | \n",
" sepd | \n",
" peak | \n",
" | \n",
" gauss_sigma_0 | \n",
" 3.0000 | \n",
" 5.7727 | \n",
" 0.4206 | \n",
" µs² | \n",
" 92.42 % ↑ | \n",
"
\n",
" \n",
" | 4 | \n",
" sepd | \n",
" peak | \n",
" | \n",
" gauss_sigma_1 | \n",
" 40.0000 | \n",
" 44.2827 | \n",
" 0.7966 | \n",
" µs/Å | \n",
" 10.71 % ↑ | \n",
"
\n",
" \n",
" | 5 | \n",
" sepd | \n",
" peak | \n",
" | \n",
" gauss_sigma_2 | \n",
" 2.0000 | \n",
" 1.2962 | \n",
" 0.1680 | \n",
" µs²/Ų | \n",
" 35.19 % ↓ | \n",
"
\n",
" \n",
" | 6 | \n",
" sepd | \n",
" instrument | \n",
" | \n",
" d_to_tof_offset | \n",
" -9.2534 | \n",
" -9.2506 | \n",
" 0.0546 | \n",
" µs | \n",
" 0.03 % ↓ | \n",
"
\n",
" \n",
"
\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.analysis.fit()\n",
"project.analysis.show_fit_results()"
]
},
{
"cell_type": "markdown",
"id": "63",
"metadata": {},
"source": [
"#### Plot Measured vs Calculated"
]
},
{
"cell_type": "code",
"execution_count": 34,
"id": "64",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:57:02.701455Z",
"iopub.status.busy": "2026-01-06T13:57:02.701082Z",
"iopub.status.idle": "2026-01-06T13:57:03.683274Z",
"shell.execute_reply": "2026-01-06T13:57:03.670109Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.plot_meas_vs_calc(expt_name='sepd', show_residual=True)"
]
},
{
"cell_type": "code",
"execution_count": 35,
"id": "65",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:57:03.708364Z",
"iopub.status.busy": "2026-01-06T13:57:03.703140Z",
"iopub.status.idle": "2026-01-06T13:57:04.584760Z",
"shell.execute_reply": "2026-01-06T13:57:04.583231Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.plot_meas_vs_calc(expt_name='sepd', x_min=23200, x_max=23700, show_residual=True)"
]
},
{
"cell_type": "markdown",
"id": "66",
"metadata": {},
"source": [
"### Perform Fit 4/5\n",
"\n",
"Set more parameters to be refined."
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "67",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:57:04.589124Z",
"iopub.status.busy": "2026-01-06T13:57:04.588598Z",
"iopub.status.idle": "2026-01-06T13:57:04.594698Z",
"shell.execute_reply": "2026-01-06T13:57:04.592697Z"
}
},
"outputs": [],
"source": [
"model.atom_sites['Si'].b_iso.free = True"
]
},
{
"cell_type": "markdown",
"id": "68",
"metadata": {},
"source": [
"Show free parameters after selection."
]
},
{
"cell_type": "code",
"execution_count": 37,
"id": "69",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:57:04.598709Z",
"iopub.status.busy": "2026-01-06T13:57:04.598420Z",
"iopub.status.idle": "2026-01-06T13:57:04.911521Z",
"shell.execute_reply": "2026-01-06T13:57:04.910470Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;34mFree parameters for both sample models \u001b[0m\u001b[1;34m(\u001b[0m\u001b[1;34m🧩 data blocks\u001b[0m\u001b[1;34m)\u001b[0m\u001b[1;34m and experiments \u001b[0m\u001b[1;34m(\u001b[0m\u001b[1;34m🔬 data blocks\u001b[0m\u001b[1;34m)\u001b[0m\n"
]
},
{
"data": {
"application/javascript": [
"\n",
" (function() {\n",
" var isDark = false;\n",
"\n",
" // Check JupyterLab theme\n",
" if (document.body.classList.contains('jp-mod-dark') || \n",
" document.body.classList.contains('theme-dark') ||\n",
" document.body.classList.contains('vscode-dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check theme attribute\n",
" var themeAttr = document.body.getAttribute('data-jp-theme-name');\n",
" if (themeAttr && themeAttr.includes('dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check computed background color\n",
" var notebookEl = document.querySelector('.jp-Notebook') || \n",
" document.querySelector('.notebook_app') ||\n",
" document.body;\n",
" if (notebookEl) {\n",
" var bgColor = window.getComputedStyle(notebookEl).backgroundColor;\n",
" var rgb = bgColor.match(/\\d+/g);\n",
" if (rgb && rgb.length >= 3) {\n",
" var brightness = (parseInt(rgb[0]) + parseInt(rgb[1]) + parseInt(rgb[2])) / 3;\n",
" if (brightness < 128) {\n",
" isDark = true;\n",
" }\n",
" }\n",
" }\n",
"\n",
" // Store result\n",
" if (typeof IPython !== 'undefined' && IPython.notebook && IPython.notebook.kernel) {\n",
" IPython.notebook.kernel.execute('_jupyter_dark_detect_result = ' + isDark);\n",
" }\n",
" })();\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" if (typeof IPython !== 'undefined' && IPython.notebook) {\n",
" IPython.notebook.kernel.execute(\"_jupyter_dark_detect_result = \" + \n",
" (document.body.classList.contains('theme-dark') || \n",
" document.body.classList.contains('jp-mod-dark') ||\n",
" (document.body.getAttribute('data-jp-theme-name') && \n",
" document.body.getAttribute('data-jp-theme-name').includes('dark'))));\n",
" }\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
"\n",
" \n",
" \n",
" | | \n",
" datablock | \n",
" category | \n",
" entry | \n",
" parameter | \n",
" value | \n",
" uncertainty | \n",
" min | \n",
" max | \n",
" units | \n",
"
\n",
" \n",
" \n",
" \n",
" | 1 | \n",
" si | \n",
" cell | \n",
" | \n",
" length_a | \n",
" 5.43143 | \n",
" 0.00004 | \n",
" -inf | \n",
" inf | \n",
" Å | \n",
"
\n",
" \n",
" | 2 | \n",
" si | \n",
" atom_site | \n",
" Si | \n",
" b_iso | \n",
" 0.50000 | \n",
" | \n",
" -inf | \n",
" inf | \n",
" Ų | \n",
"
\n",
" \n",
" | 3 | \n",
" sepd | \n",
" linked_phases | \n",
" si | \n",
" scale | \n",
" 14.70568 | \n",
" 0.02567 | \n",
" -inf | \n",
" inf | \n",
" | \n",
"
\n",
" \n",
" | 4 | \n",
" sepd | \n",
" peak | \n",
" | \n",
" gauss_sigma_0 | \n",
" 5.77274 | \n",
" 0.42055 | \n",
" -inf | \n",
" inf | \n",
" µs² | \n",
"
\n",
" \n",
" | 5 | \n",
" sepd | \n",
" peak | \n",
" | \n",
" gauss_sigma_1 | \n",
" 44.28265 | \n",
" 0.79664 | \n",
" -inf | \n",
" inf | \n",
" µs/Å | \n",
"
\n",
" \n",
" | 6 | \n",
" sepd | \n",
" peak | \n",
" | \n",
" gauss_sigma_2 | \n",
" 1.29621 | \n",
" 0.16795 | \n",
" -inf | \n",
" inf | \n",
" µs²/Ų | \n",
"
\n",
" \n",
" | 7 | \n",
" sepd | \n",
" instrument | \n",
" | \n",
" d_to_tof_offset | \n",
" -9.25065 | \n",
" 0.05458 | \n",
" -inf | \n",
" inf | \n",
" µs | \n",
"
\n",
" \n",
"
\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.analysis.show_free_params()"
]
},
{
"cell_type": "markdown",
"id": "70",
"metadata": {},
"source": [
"#### Run Fitting"
]
},
{
"cell_type": "code",
"execution_count": 38,
"id": "71",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:57:04.916314Z",
"iopub.status.busy": "2026-01-06T13:57:04.915394Z",
"iopub.status.idle": "2026-01-06T13:57:23.473420Z",
"shell.execute_reply": "2026-01-06T13:57:23.472437Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;34mUsing experiment 🔬 \u001b[0m\u001b[32m'sepd'\u001b[0m\u001b[1;34m for \u001b[0m\u001b[32m'single'\u001b[0m\u001b[1;34m fitting\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"🚀 Starting fit process with \u001b[32m'lmfit \u001b[0m\u001b[32m(\u001b[0m\u001b[32mleastsq\u001b[0m\u001b[32m)\u001b[0m\u001b[32m'\u001b[0m\u001b[33m...\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"📈 Goodness-of-fit \u001b[1m(\u001b[0mreduced χ²\u001b[1m)\u001b[0m change:\n"
]
},
{
"data": {
"text/html": [
"\n",
"\n",
" \n",
" \n",
" | | \n",
" iteration | \n",
" χ² | \n",
" improvement [%] | \n",
"
\n",
" \n",
" \n",
" \n",
" | 1 | \n",
" 1 | \n",
" 3.21 | \n",
" | \n",
"
\n",
" \n",
" | 2 | \n",
" 44 | \n",
" 3.19 | \n",
" | \n",
"
\n",
" \n",
"
\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" (function() {\n",
" var isDark = false;\n",
"\n",
" // Check JupyterLab theme\n",
" if (document.body.classList.contains('jp-mod-dark') || \n",
" document.body.classList.contains('theme-dark') ||\n",
" document.body.classList.contains('vscode-dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check theme attribute\n",
" var themeAttr = document.body.getAttribute('data-jp-theme-name');\n",
" if (themeAttr && themeAttr.includes('dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check computed background color\n",
" var notebookEl = document.querySelector('.jp-Notebook') || \n",
" document.querySelector('.notebook_app') ||\n",
" document.body;\n",
" if (notebookEl) {\n",
" var bgColor = window.getComputedStyle(notebookEl).backgroundColor;\n",
" var rgb = bgColor.match(/\\d+/g);\n",
" if (rgb && rgb.length >= 3) {\n",
" var brightness = (parseInt(rgb[0]) + parseInt(rgb[1]) + parseInt(rgb[2])) / 3;\n",
" if (brightness < 128) {\n",
" isDark = true;\n",
" }\n",
" }\n",
" }\n",
"\n",
" // Store result\n",
" if (typeof IPython !== 'undefined' && IPython.notebook && IPython.notebook.kernel) {\n",
" IPython.notebook.kernel.execute('_jupyter_dark_detect_result = ' + isDark);\n",
" }\n",
" })();\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" if (typeof IPython !== 'undefined' && IPython.notebook) {\n",
" IPython.notebook.kernel.execute(\"_jupyter_dark_detect_result = \" + \n",
" (document.body.classList.contains('theme-dark') || \n",
" document.body.classList.contains('jp-mod-dark') ||\n",
" (document.body.getAttribute('data-jp-theme-name') && \n",
" document.body.getAttribute('data-jp-theme-name').includes('dark'))));\n",
" }\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" (function() {\n",
" var isDark = false;\n",
"\n",
" // Check JupyterLab theme\n",
" if (document.body.classList.contains('jp-mod-dark') || \n",
" document.body.classList.contains('theme-dark') ||\n",
" document.body.classList.contains('vscode-dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check theme attribute\n",
" var themeAttr = document.body.getAttribute('data-jp-theme-name');\n",
" if (themeAttr && themeAttr.includes('dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check computed background color\n",
" var notebookEl = document.querySelector('.jp-Notebook') || \n",
" document.querySelector('.notebook_app') ||\n",
" document.body;\n",
" if (notebookEl) {\n",
" var bgColor = window.getComputedStyle(notebookEl).backgroundColor;\n",
" var rgb = bgColor.match(/\\d+/g);\n",
" if (rgb && rgb.length >= 3) {\n",
" var brightness = (parseInt(rgb[0]) + parseInt(rgb[1]) + parseInt(rgb[2])) / 3;\n",
" if (brightness < 128) {\n",
" isDark = true;\n",
" }\n",
" }\n",
" }\n",
"\n",
" // Store result\n",
" if (typeof IPython !== 'undefined' && IPython.notebook && IPython.notebook.kernel) {\n",
" IPython.notebook.kernel.execute('_jupyter_dark_detect_result = ' + isDark);\n",
" }\n",
" })();\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" if (typeof IPython !== 'undefined' && IPython.notebook) {\n",
" IPython.notebook.kernel.execute(\"_jupyter_dark_detect_result = \" + \n",
" (document.body.classList.contains('theme-dark') || \n",
" document.body.classList.contains('jp-mod-dark') ||\n",
" (document.body.getAttribute('data-jp-theme-name') && \n",
" document.body.getAttribute('data-jp-theme-name').includes('dark'))));\n",
" }\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" (function() {\n",
" var isDark = false;\n",
"\n",
" // Check JupyterLab theme\n",
" if (document.body.classList.contains('jp-mod-dark') || \n",
" document.body.classList.contains('theme-dark') ||\n",
" document.body.classList.contains('vscode-dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check theme attribute\n",
" var themeAttr = document.body.getAttribute('data-jp-theme-name');\n",
" if (themeAttr && themeAttr.includes('dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check computed background color\n",
" var notebookEl = document.querySelector('.jp-Notebook') || \n",
" document.querySelector('.notebook_app') ||\n",
" document.body;\n",
" if (notebookEl) {\n",
" var bgColor = window.getComputedStyle(notebookEl).backgroundColor;\n",
" var rgb = bgColor.match(/\\d+/g);\n",
" if (rgb && rgb.length >= 3) {\n",
" var brightness = (parseInt(rgb[0]) + parseInt(rgb[1]) + parseInt(rgb[2])) / 3;\n",
" if (brightness < 128) {\n",
" isDark = true;\n",
" }\n",
" }\n",
" }\n",
"\n",
" // Store result\n",
" if (typeof IPython !== 'undefined' && IPython.notebook && IPython.notebook.kernel) {\n",
" IPython.notebook.kernel.execute('_jupyter_dark_detect_result = ' + isDark);\n",
" }\n",
" })();\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" if (typeof IPython !== 'undefined' && IPython.notebook) {\n",
" IPython.notebook.kernel.execute(\"_jupyter_dark_detect_result = \" + \n",
" (document.body.classList.contains('theme-dark') || \n",
" document.body.classList.contains('jp-mod-dark') ||\n",
" (document.body.getAttribute('data-jp-theme-name') && \n",
" document.body.getAttribute('data-jp-theme-name').includes('dark'))));\n",
" }\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"🏆 Best goodness-of-fit \u001b[1m(\u001b[0mreduced χ²\u001b[1m)\u001b[0m is \u001b[1;36m3.19\u001b[0m at iteration \u001b[1;36m43\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"✅ Fitting complete.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;34mFit results\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"✅ Success: \u001b[3;92mTrue\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"⏱️ Fitting time: \u001b[1;36m16.78\u001b[0m seconds\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"📏 Goodness-of-fit \u001b[1m(\u001b[0mreduced χ²\u001b[1m)\u001b[0m: \u001b[1;36m3.19\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"📏 R-factor \u001b[1m(\u001b[0mRf\u001b[1m)\u001b[0m: \u001b[1;36m9.01\u001b[0m%\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"📏 R-factor squared \u001b[1m(\u001b[0mRf²\u001b[1m)\u001b[0m: \u001b[1;36m5.28\u001b[0m%\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"📏 Weighted R-factor \u001b[1m(\u001b[0mwR\u001b[1m)\u001b[0m: \u001b[1;36m4.34\u001b[0m%\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"📈 Fitted parameters:\n"
]
},
{
"data": {
"application/javascript": [
"\n",
" (function() {\n",
" var isDark = false;\n",
"\n",
" // Check JupyterLab theme\n",
" if (document.body.classList.contains('jp-mod-dark') || \n",
" document.body.classList.contains('theme-dark') ||\n",
" document.body.classList.contains('vscode-dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check theme attribute\n",
" var themeAttr = document.body.getAttribute('data-jp-theme-name');\n",
" if (themeAttr && themeAttr.includes('dark')) {\n",
" isDark = true;\n",
" }\n",
"\n",
" // Check computed background color\n",
" var notebookEl = document.querySelector('.jp-Notebook') || \n",
" document.querySelector('.notebook_app') ||\n",
" document.body;\n",
" if (notebookEl) {\n",
" var bgColor = window.getComputedStyle(notebookEl).backgroundColor;\n",
" var rgb = bgColor.match(/\\d+/g);\n",
" if (rgb && rgb.length >= 3) {\n",
" var brightness = (parseInt(rgb[0]) + parseInt(rgb[1]) + parseInt(rgb[2])) / 3;\n",
" if (brightness < 128) {\n",
" isDark = true;\n",
" }\n",
" }\n",
" }\n",
"\n",
" // Store result\n",
" if (typeof IPython !== 'undefined' && IPython.notebook && IPython.notebook.kernel) {\n",
" IPython.notebook.kernel.execute('_jupyter_dark_detect_result = ' + isDark);\n",
" }\n",
" })();\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
" if (typeof IPython !== 'undefined' && IPython.notebook) {\n",
" IPython.notebook.kernel.execute(\"_jupyter_dark_detect_result = \" + \n",
" (document.body.classList.contains('theme-dark') || \n",
" document.body.classList.contains('jp-mod-dark') ||\n",
" (document.body.getAttribute('data-jp-theme-name') && \n",
" document.body.getAttribute('data-jp-theme-name').includes('dark'))));\n",
" }\n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
"\n",
" \n",
" \n",
" | | \n",
" datablock | \n",
" category | \n",
" entry | \n",
" parameter | \n",
" start | \n",
" fitted | \n",
" uncertainty | \n",
" units | \n",
" change | \n",
"
\n",
" \n",
" \n",
" \n",
" | 1 | \n",
" si | \n",
" cell | \n",
" | \n",
" length_a | \n",
" 5.4314 | \n",
" 5.4314 | \n",
" 0.0000 | \n",
" Å | \n",
" 0.00 % ↑ | \n",
"
\n",
" \n",
" | 2 | \n",
" si | \n",
" atom_site | \n",
" Si | \n",
" b_iso | \n",
" 0.5000 | \n",
" 0.5201 | \n",
" 0.0034 | \n",
" Ų | \n",
" 4.02 % ↑ | \n",
"
\n",
" \n",
" | 3 | \n",
" sepd | \n",
" linked_phases | \n",
" si | \n",
" scale | \n",
" 14.7057 | \n",
" 14.8594 | \n",
" 0.0366 | \n",
" | \n",
" 1.05 % ↑ | \n",
"
\n",
" \n",
" | 4 | \n",
" sepd | \n",
" peak | \n",
" | \n",
" gauss_sigma_0 | \n",
" 5.7727 | \n",
" 4.8233 | \n",
" 0.4394 | \n",
" µs² | \n",
" 16.45 % ↓ | \n",
"
\n",
" \n",
" | 5 | \n",
" sepd | \n",
" peak | \n",
" | \n",
" gauss_sigma_1 | \n",
" 44.2827 | \n",
" 45.2122 | \n",
" 0.8016 | \n",
" µs/Å | \n",
" 2.10 % ↑ | \n",
"
\n",
" \n",
" | 6 | \n",
" sepd | \n",
" peak | \n",
" | \n",
" gauss_sigma_2 | \n",
" 1.2962 | \n",
" 1.1931 | \n",
" 0.1667 | \n",
" µs²/Ų | \n",
" 7.95 % ↓ | \n",
"
\n",
" \n",
" | 7 | \n",
" sepd | \n",
" instrument | \n",
" | \n",
" d_to_tof_offset | \n",
" -9.2506 | \n",
" -9.2823 | \n",
" 0.0548 | \n",
" µs | \n",
" 0.34 % ↑ | \n",
"
\n",
" \n",
"
\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.analysis.fit()\n",
"project.analysis.show_fit_results()"
]
},
{
"cell_type": "markdown",
"id": "72",
"metadata": {},
"source": [
"#### Plot Measured vs Calculated"
]
},
{
"cell_type": "code",
"execution_count": 39,
"id": "73",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:57:23.477194Z",
"iopub.status.busy": "2026-01-06T13:57:23.476938Z",
"iopub.status.idle": "2026-01-06T13:57:24.435291Z",
"shell.execute_reply": "2026-01-06T13:57:24.434608Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.plot_meas_vs_calc(expt_name='sepd', show_residual=True)"
]
},
{
"cell_type": "code",
"execution_count": 40,
"id": "74",
"metadata": {
"execution": {
"iopub.execute_input": "2026-01-06T13:57:24.439733Z",
"iopub.status.busy": "2026-01-06T13:57:24.439555Z",
"iopub.status.idle": "2026-01-06T13:57:25.555577Z",
"shell.execute_reply": "2026-01-06T13:57:25.555187Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.plot_meas_vs_calc(expt_name='sepd', x_min=23200, x_max=23700, show_residual=True)"
]
}
],
"metadata": {
"jupytext": {
"cell_metadata_filter": "-all",
"main_language": "python",
"notebook_metadata_filter": "-all"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.13.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}