{
"nbformat": 4,
"nbformat_minor": 5,
"metadata": {
"jupytext": {
"main_language": "python",
"notebook_metadata_filter": "-all",
"cell_metadata_filter": "-all",
"text_representation": {
"extension": ".py",
"format_name": "percent"
}
}
},
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"tags": [
"hide-in-docs"
],
"execution": {
"iopub.status.busy": "2026-11-12T16:10:24.281875Z",
"iopub.execute_input": "2026-11-12T16:10:24.281999Z",
"iopub.status.idle": "2026-11-12T16:10:24.284768Z",
"shell.execute_reply": "2026-11-12T16:10:24.284520Z"
}
},
"outputs": [],
"source": "# Check whether easydiffraction is installed; install it if needed.\n# Required for remote environments such as Google Colab.\nimport importlib.util\n\nif importlib.util.find_spec('easydiffraction') is None:\n %pip install easydiffraction==2026.11.13 --extra-index-url https://download.easydiffraction.org/pypi/simple/\n",
"id": "0"
},
{
"id": "1",
"cell_type": "markdown",
"source": "# CeO₂ on PEARL",
"metadata": {}
},
{
"cell_type": "markdown",
"metadata": {},
"source": "
",
"id": "2"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "Fit the CeO₂ standard to time-of-flight neutron powder data from PEARL at ISIS: the calibration\nand the profile, with a polynomial background.\n\nThe project is the catalogue case `pd-neut-tof_ceo2-pearl`, the one the command line and the\napp's Examples open.",
"id": "3"
},
{
"id": "4",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:24.285703Z",
"iopub.execute_input": "2026-11-12T16:10:24.285845Z",
"shell.execute_reply": "2026-11-12T16:10:24.294517Z",
"iopub.status.idle": "2026-11-12T16:10:24.294799Z"
}
},
"execution_count": 2,
"source": "import easydiffraction as edi",
"outputs": []
},
{
"id": "5",
"cell_type": "markdown",
"source": "## Load the project",
"metadata": {}
},
{
"id": "6",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:24.295779Z",
"iopub.execute_input": "2026-11-12T16:10:24.295932Z",
"shell.execute_reply": "2026-11-12T16:10:24.509494Z",
"iopub.status.idle": "2026-11-12T16:10:24.509927Z"
}
},
"execution_count": 3,
"source": "project_path = edi.download_data('pd-neut-tof_ceo2-pearl', destination='data')\nproject = edi.Project.load(project_path)\nstructure = project.structures['ceo2']\nexperiment = project.experiments['pearl']",
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": "Data 'pd-neut-tof_ceo2-pearl' is at data/pd-neut-tof_ceo2-pearl-672773a1ed12/pd-neut-tof_ceo2-pearl\n"
}
]
},
{
"id": "7",
"cell_type": "markdown",
"source": "The project marks what its fit frees. The fit below frees it in stages, so start with all of it\nfixed.",
"metadata": {}
},
{
"id": "8",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:24.511034Z",
"iopub.execute_input": "2026-11-12T16:10:24.511164Z",
"shell.execute_reply": "2026-11-12T16:10:24.529038Z",
"iopub.status.idle": "2026-11-12T16:10:24.529435Z"
}
},
"execution_count": 4,
"source": "for parameter in project.free_parameters:\n parameter.free = False",
"outputs": []
},
{
"id": "9",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:24.530439Z",
"iopub.execute_input": "2026-11-12T16:10:24.530561Z",
"iopub.status.idle": "2026-11-12T16:10:24.568182Z",
"shell.execute_reply": "2026-11-12T16:10:24.567764Z"
}
},
"execution_count": 5,
"source": "project.display.pattern('pearl')",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<384,654 characters>, height=480)",
"text/html": ""
}
}
]
},
{
"id": "10",
"cell_type": "markdown",
"source": "## Perform the analysis\n\nThe fit goes in stages, freeing one group of parameters at a time.",
"metadata": {}
},
{
"id": "11",
"cell_type": "markdown",
"source": "### Scale and time-of-flight calibration\n\nCeO₂ is the calibration standard, so its cell stays fixed and the DIFC terms put the peaks in\nplace.",
"metadata": {}
},
{
"id": "12",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:24.571475Z",
"iopub.execute_input": "2026-11-12T16:10:24.571605Z",
"shell.execute_reply": "2026-11-12T16:10:24.577257Z",
"iopub.status.idle": "2026-11-12T16:10:24.577633Z"
}
},
"execution_count": 6,
"source": "experiment.linked_structures['ceo2'].scale.free = True\nexperiment.instrument.calib_d_to_tof_offset.free = True\nexperiment.instrument.calib_d_to_tof_linear.free = True\nexperiment.instrument.calib_d_to_tof_quadratic.free = True",
"outputs": []
},
{
"id": "13",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:24.578653Z",
"iopub.execute_input": "2026-11-12T16:10:24.578778Z",
"iopub.status.idle": "2026-11-12T16:10:24.597000Z",
"shell.execute_reply": "2026-11-12T16:10:24.596646Z"
}
},
"execution_count": 7,
"source": "project.display.parameters.free()",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<80,829 characters>, height=208)",
"text/html": ""
}
}
]
},
{
"id": "14",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:24.598103Z",
"iopub.execute_input": "2026-11-12T16:10:24.598223Z",
"iopub.status.idle": "2026-11-12T16:10:24.698828Z",
"shell.execute_reply": "2026-11-12T16:10:24.698433Z"
}
},
"execution_count": 8,
"source": "project.analysis.fit()\nproject.display.fit.results()",
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": "edi fit: project pd-neut-tof_ceo2-pearl, 2237 pts fitted / 2524 loaded, 4 free\n iter time (s) Rwp (%) reduced χ² change\n 14.21 27.74\n 1 0.047 13.03 23.34 15.8% ↓\n done · converged · 1 iters · reduced χ² 23.34 · Rwp 13.03 % · 0.06 s\n"
},
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<85,822 characters>, height=376)",
"text/html": ""
}
}
]
},
{
"id": "15",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:24.700162Z",
"iopub.execute_input": "2026-11-12T16:10:24.700289Z",
"iopub.status.idle": "2026-11-12T16:10:24.731558Z",
"shell.execute_reply": "2026-11-12T16:10:24.731137Z"
}
},
"execution_count": 9,
"source": "project.display.pattern('pearl')",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<385,755 characters>, height=480)",
"text/html": ""
}
}
]
},
{
"id": "16",
"cell_type": "markdown",
"source": "### Background\n\nThe six polynomial terms follow the level between the peaks.",
"metadata": {}
},
{
"id": "17",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:24.735150Z",
"iopub.execute_input": "2026-11-12T16:10:24.735280Z",
"shell.execute_reply": "2026-11-12T16:10:24.742578Z",
"iopub.status.idle": "2026-11-12T16:10:24.742901Z"
}
},
"execution_count": 10,
"source": "for term in experiment.background_terms:\n term.coef.free = True",
"outputs": []
},
{
"id": "18",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:24.743905Z",
"iopub.execute_input": "2026-11-12T16:10:24.744028Z",
"iopub.status.idle": "2026-11-12T16:10:24.855376Z",
"shell.execute_reply": "2026-11-12T16:10:24.854971Z"
}
},
"execution_count": 11,
"source": "project.analysis.fit()\nproject.display.fit.results()",
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": "edi fit: project pd-neut-tof_ceo2-pearl, 2237 pts fitted / 2524 loaded, 10 free\n iter time (s) Rwp (%) reduced χ² change\n 13.03 23.41\n 1 0.058 6.73 6.24 73.4% ↓\n done · converged · 1 iters · reduced χ² 6.24 · Rwp 6.73 % · 0.07 s\n"
},
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<92,629 characters>, height=376)",
"text/html": ""
}
}
]
},
{
"id": "19",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:24.856527Z",
"iopub.execute_input": "2026-11-12T16:10:24.856644Z",
"iopub.status.idle": "2026-11-12T16:10:24.887241Z",
"shell.execute_reply": "2026-11-12T16:10:24.886803Z"
}
},
"execution_count": 12,
"source": "project.display.pattern('pearl')",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<407,395 characters>, height=480)",
"text/html": ""
}
}
]
},
{
"id": "20",
"cell_type": "markdown",
"source": "### Gaussian widths\n\nThe Gaussian terms that grow with d spacing.",
"metadata": {}
},
{
"id": "21",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:24.891008Z",
"iopub.execute_input": "2026-11-12T16:10:24.891132Z",
"iopub.status.idle": "2026-11-12T16:10:24.895211Z",
"shell.execute_reply": "2026-11-12T16:10:24.894835Z"
}
},
"execution_count": 13,
"source": "experiment.peak.broad_gauss_sigma_1.free = True\nexperiment.peak.broad_gauss_sigma_2.free = True",
"outputs": []
},
{
"id": "22",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:24.896188Z",
"iopub.execute_input": "2026-11-12T16:10:24.896302Z",
"iopub.status.idle": "2026-11-12T16:10:24.998030Z",
"shell.execute_reply": "2026-11-12T16:10:24.997595Z"
}
},
"execution_count": 14,
"source": "project.analysis.fit()\nproject.display.fit.results()",
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": "edi fit: project pd-neut-tof_ceo2-pearl, 2237 pts fitted / 2524 loaded, 12 free\n iter time (s) Rwp (%) reduced χ² change\n 6.73 6.24\n 1 0.052 6.27 5.43 13.0% ↓\n done · converged · 1 iters · reduced χ² 5.43 · Rwp 6.27 % · 0.06 s\n"
},
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<96,918 characters>, height=376)",
"text/html": ""
}
}
]
},
{
"id": "23",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:24.999257Z",
"iopub.execute_input": "2026-11-12T16:10:24.999378Z",
"iopub.status.idle": "2026-11-12T16:10:25.030086Z",
"shell.execute_reply": "2026-11-12T16:10:25.029662Z"
}
},
"execution_count": 15,
"source": "project.display.pattern('pearl')",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<407,412 characters>, height=480)",
"text/html": ""
}
}
]
},
{
"id": "24",
"cell_type": "markdown",
"source": "### Lorentzian width\n\nThe Lorentzian term that grows with d spacing.",
"metadata": {}
},
{
"id": "25",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:25.033637Z",
"iopub.execute_input": "2026-11-12T16:10:25.033759Z",
"iopub.status.idle": "2026-11-12T16:10:25.036748Z",
"shell.execute_reply": "2026-11-12T16:10:25.036447Z"
}
},
"execution_count": 16,
"source": "experiment.peak.broad_lorentz_gamma_1.free = True",
"outputs": []
},
{
"id": "26",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:25.037688Z",
"iopub.execute_input": "2026-11-12T16:10:25.037791Z",
"iopub.status.idle": "2026-11-12T16:10:25.139694Z",
"shell.execute_reply": "2026-11-12T16:10:25.139287Z"
}
},
"execution_count": 17,
"source": "project.analysis.fit()\nproject.display.fit.results()",
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": "edi fit: project pd-neut-tof_ceo2-pearl, 2237 pts fitted / 2524 loaded, 13 free\n iter time (s) Rwp (%) reduced χ² change\n 6.27 5.43\n 1 0.053 6.19 5.30 2.5% ↓\n done · converged · 1 iters · reduced χ² 5.30 · Rwp 6.19 % · 0.06 s\n"
},
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<98,318 characters>, height=376)",
"text/html": ""
}
}
]
},
{
"id": "27",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:25.140839Z",
"iopub.execute_input": "2026-11-12T16:10:25.140964Z",
"iopub.status.idle": "2026-11-12T16:10:25.170902Z",
"shell.execute_reply": "2026-11-12T16:10:25.170465Z"
}
},
"execution_count": 18,
"source": "project.display.pattern('pearl')",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<407,283 characters>, height=480)",
"text/html": ""
}
}
]
},
{
"id": "28",
"cell_type": "markdown",
"source": "### Rise and decay\n\nThe back-to-back exponentials that shape each time-of-flight peak.",
"metadata": {}
},
{
"id": "29",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:25.174303Z",
"iopub.execute_input": "2026-11-12T16:10:25.174426Z",
"shell.execute_reply": "2026-11-12T16:10:25.179155Z",
"iopub.status.idle": "2026-11-12T16:10:25.179533Z"
}
},
"execution_count": 19,
"source": "experiment.peak.rise_alpha_1.free = True\nexperiment.peak.decay_beta_0.free = True\nexperiment.peak.decay_beta_1.free = True",
"outputs": []
},
{
"id": "30",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:25.180487Z",
"iopub.execute_input": "2026-11-12T16:10:25.180604Z",
"shell.execute_reply": "2026-11-12T16:10:25.279261Z",
"iopub.status.idle": "2026-11-12T16:10:25.279642Z"
}
},
"execution_count": 20,
"source": "project.analysis.fit()\nproject.display.fit.results()",
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": "edi fit: project pd-neut-tof_ceo2-pearl, 2237 pts fitted / 2524 loaded, 16 free\n iter time (s) Rwp (%) reduced χ² change\n 6.19 5.30\n 1 0.050 5.67 4.44 16.3% ↓\n done · converged · 1 iters · reduced χ² 4.44 · Rwp 5.67 % · 0.06 s\n"
},
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<101,949 characters>, height=376)",
"text/html": ""
}
}
]
},
{
"id": "31",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:25.280749Z",
"iopub.execute_input": "2026-11-12T16:10:25.280885Z",
"iopub.status.idle": "2026-11-12T16:10:25.311348Z",
"shell.execute_reply": "2026-11-12T16:10:25.310915Z"
}
},
"execution_count": 21,
"source": "project.display.pattern('pearl')",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<407,121 characters>, height=480)",
"text/html": ""
}
}
]
},
{
"id": "32",
"cell_type": "markdown",
"source": "### Displacements",
"metadata": {}
},
{
"id": "33",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:25.314761Z",
"iopub.execute_input": "2026-11-12T16:10:25.314905Z",
"shell.execute_reply": "2026-11-12T16:10:25.318651Z",
"iopub.status.idle": "2026-11-12T16:10:25.319041Z"
}
},
"execution_count": 22,
"source": "structure.atom_sites['Ce'].adp_iso.free = True\nstructure.atom_sites['O'].adp_iso.free = True",
"outputs": []
},
{
"id": "34",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:25.320040Z",
"iopub.execute_input": "2026-11-12T16:10:25.320168Z",
"iopub.status.idle": "2026-11-12T16:10:25.424661Z",
"shell.execute_reply": "2026-11-12T16:10:25.424273Z"
}
},
"execution_count": 23,
"source": "project.analysis.fit()\nproject.display.fit.results()",
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": "edi fit: project pd-neut-tof_ceo2-pearl, 2237 pts fitted / 2524 loaded, 18 free\n iter time (s) Rwp (%) reduced χ² change\n 5.67 4.44\n 1 0.054 5.29 3.88 12.7% ↓\n done · converged · 1 iters · reduced χ² 3.88 · Rwp 5.29 % · 0.06 s\n"
},
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<104,651 characters>, height=376)",
"text/html": ""
}
}
]
},
{
"id": "35",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:25.425782Z",
"iopub.execute_input": "2026-11-12T16:10:25.425920Z",
"iopub.status.idle": "2026-11-12T16:10:25.456208Z",
"shell.execute_reply": "2026-11-12T16:10:25.455828Z"
}
},
"execution_count": 24,
"source": "project.display.pattern('pearl')",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<407,345 characters>, height=480)",
"text/html": ""
}
}
]
},
{
"id": "36",
"cell_type": "markdown",
"source": "### Absorption\n\nAbsorption weakens the intensities with time of flight, as the displacements do, so it comes\nafter them, on its own.",
"metadata": {}
},
{
"id": "37",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:25.460011Z",
"iopub.execute_input": "2026-11-12T16:10:25.460147Z",
"iopub.status.idle": "2026-11-12T16:10:25.463215Z",
"shell.execute_reply": "2026-11-12T16:10:25.462835Z"
}
},
"execution_count": 25,
"source": "experiment.absorption.abscor1.free = True",
"outputs": []
},
{
"id": "38",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:25.464228Z",
"iopub.execute_input": "2026-11-12T16:10:25.464341Z",
"iopub.status.idle": "2026-11-12T16:10:25.560487Z",
"shell.execute_reply": "2026-11-12T16:10:25.560076Z"
}
},
"execution_count": 26,
"source": "project.analysis.fit()\nproject.display.fit.results()",
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": "edi fit: project pd-neut-tof_ceo2-pearl, 2237 pts fitted / 2524 loaded, 19 free\n iter time (s) Rwp (%) reduced χ² change\n 5.29 3.88\n 1 0.046 5.29 3.88 \n done · converged · 1 iters · reduced χ² 3.88 · Rwp 5.29 % · 0.05 s\n"
},
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<105,050 characters>, height=376)",
"text/html": ""
}
}
]
},
{
"id": "39",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:25.561767Z",
"iopub.execute_input": "2026-11-12T16:10:25.561904Z",
"iopub.status.idle": "2026-11-12T16:10:25.592140Z",
"shell.execute_reply": "2026-11-12T16:10:25.591712Z"
}
},
"execution_count": 27,
"source": "project.display.pattern('pearl')",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<407,321 characters>, height=480)",
"text/html": ""
}
}
]
},
{
"id": "40",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:25.595561Z",
"iopub.execute_input": "2026-11-12T16:10:25.595687Z",
"shell.execute_reply": "2026-11-12T16:10:25.614422Z",
"iopub.status.idle": "2026-11-12T16:10:25.614837Z"
}
},
"execution_count": 28,
"source": "project.display.fit.correlations()",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<79,788 characters>, height=560)",
"text/html": ""
}
}
]
},
{
"id": "41",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:25.615859Z",
"iopub.execute_input": "2026-11-12T16:10:25.615981Z",
"iopub.status.idle": "2026-11-12T16:10:25.637858Z",
"shell.execute_reply": "2026-11-12T16:10:25.637505Z"
}
},
"execution_count": 29,
"source": "project.display.structure('ceo2')",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<206,157 characters>, height=660)",
"text/html": ""
}
}
]
},
{
"id": "42",
"cell_type": "markdown",
"source": "## Save the project",
"metadata": {}
},
{
"id": "43",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:25.639671Z",
"iopub.execute_input": "2026-11-12T16:10:25.639795Z",
"shell.execute_reply": "2026-11-12T16:10:25.806431Z",
"iopub.status.idle": "2026-11-12T16:10:25.806839Z"
}
},
"execution_count": 30,
"source": "project.save_as('pd-neut-tof_ceo2-pearl')\nproject.report.save_html('pd-neut-tof_ceo2-pearl.html')",
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": "Saving project to 'pd-neut-tof_ceo2-pearl'\nSaving report to 'pd-neut-tof_ceo2-pearl.html'\n"
}
]
}
]
}