{
"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:26.880307Z",
"iopub.execute_input": "2026-11-12T16:10:26.880421Z",
"iopub.status.idle": "2026-11-12T16:10:26.883403Z",
"shell.execute_reply": "2026-11-12T16:10:26.883154Z"
}
},
"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": "# Ferrite and austenite on BEER",
"metadata": {}
},
{
"cell_type": "markdown",
"metadata": {},
"source": "
",
"id": "2"
},
{
"cell_type": "markdown",
"metadata": {},
"source": "Calibrate the BEER instrument at ESS with two McStas-simulated banks of a ferrite and austenite\nduplex steel, fitted together: each bank has its own zero and resolution.\n\nThe project is the catalogue case `pd-neut-tof_ferrite-austenite-beer`, the one the command line\nand the app's Examples open. Austenite's displacement follows ferrite's, and each phase's scale\nin bank n2 follows bank s2, from the start.",
"id": "3"
},
{
"id": "4",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:26.884378Z",
"iopub.execute_input": "2026-11-12T16:10:26.884495Z",
"shell.execute_reply": "2026-11-12T16:10:26.893037Z",
"iopub.status.idle": "2026-11-12T16:10:26.893335Z"
}
},
"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:26.894301Z",
"iopub.execute_input": "2026-11-12T16:10:26.894410Z",
"iopub.status.idle": "2026-11-12T16:10:27.157833Z",
"shell.execute_reply": "2026-11-12T16:10:27.157464Z"
}
},
"execution_count": 3,
"source": "project_path = edi.download_data('pd-neut-tof_ferrite-austenite-beer', destination='data')\nproject = edi.Project.load(project_path)\nferrite = project.structures['ferrite']\naustenite = project.structures['austenite']\nbank_s2 = project.experiments['expt_s2']\nbank_n2 = project.experiments['expt_n2']\nproject.display.constraints()",
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": "Data 'pd-neut-tof_ferrite-austenite-beer' is at data/pd-neut-tof_ferrite-austenite-beer-764611d2acc1/pd-neut-tof_ferrite-austenite-beer\n"
},
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<85,205 characters>, height=348)",
"text/html": ""
}
}
]
},
{
"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:27.158990Z",
"iopub.execute_input": "2026-11-12T16:10:27.159117Z",
"shell.execute_reply": "2026-11-12T16:10:27.324842Z",
"iopub.status.idle": "2026-11-12T16:10:27.325324Z"
}
},
"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:27.326781Z",
"iopub.execute_input": "2026-11-12T16:10:27.326947Z",
"iopub.status.idle": "2026-11-12T16:10:27.377760Z",
"shell.execute_reply": "2026-11-12T16:10:27.377358Z"
}
},
"execution_count": 5,
"source": "project.display.pattern('expt_s2')",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<485,376 characters>, height=480)",
"text/html": ""
}
}
]
},
{
"id": "10",
"cell_type": "markdown",
"source": "## Perform the analysis\n\nThe cells stay fixed: this is a calibration, and the two phases are the standards.",
"metadata": {}
},
{
"id": "11",
"cell_type": "markdown",
"source": "### Scales and time-of-flight calibration\n\nBoth phases' scales and each bank's DIFC offset put the peaks in place and at the right height.",
"metadata": {}
},
{
"id": "12",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:27.382277Z",
"iopub.execute_input": "2026-11-12T16:10:27.382429Z",
"shell.execute_reply": "2026-11-12T16:10:27.394112Z",
"iopub.status.idle": "2026-11-12T16:10:27.394441Z"
}
},
"execution_count": 6,
"source": "bank_s2.linked_structures['ferrite'].scale.free = True\nbank_s2.linked_structures['austenite'].scale.free = True\nbank_s2.instrument.calib_d_to_tof_offset.free = True\nbank_n2.instrument.calib_d_to_tof_offset.free = True",
"outputs": []
},
{
"id": "13",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:27.395562Z",
"iopub.execute_input": "2026-11-12T16:10:27.395693Z",
"iopub.status.idle": "2026-11-12T16:10:27.428232Z",
"shell.execute_reply": "2026-11-12T16:10:27.427802Z"
}
},
"execution_count": 7,
"source": "project.display.parameters.free()",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<86,632 characters>, height=208)",
"text/html": ""
}
}
]
},
{
"id": "14",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:27.429428Z",
"iopub.execute_input": "2026-11-12T16:10:27.429548Z",
"iopub.status.idle": "2026-11-12T16:10:27.510879Z",
"shell.execute_reply": "2026-11-12T16:10:27.510448Z"
}
},
"execution_count": 8,
"source": "project.analysis.fit()\nproject.display.fit.results()",
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": "edi fit: joint project pd-neut-tof_ferrite-austenite-beer, 2 banks (expt_n2, expt_s2), 5642 pts fitted / 5998 loaded, 4 free\n iter time (s) Rwp (%) reduced χ² change\n 41.43 229.76\n 1 0.010 23.83 76.04 66.9% ↓\n 2 0.012 23.83 76.04 \n done · converged · 2 iters · reduced χ² 76.04 · Rwp 23.83 % · 0.01 s\n"
},
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<91,077 characters>, height=376)",
"text/html": ""
}
}
]
},
{
"id": "15",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:27.512090Z",
"iopub.execute_input": "2026-11-12T16:10:27.512225Z",
"iopub.status.idle": "2026-11-12T16:10:27.561154Z",
"shell.execute_reply": "2026-11-12T16:10:27.560697Z"
}
},
"execution_count": 9,
"source": "project.display.pattern('expt_s2')",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<485,748 characters>, height=480)",
"text/html": ""
}
}
]
},
{
"id": "16",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:27.565329Z",
"iopub.execute_input": "2026-11-12T16:10:27.565480Z",
"iopub.status.idle": "2026-11-12T16:10:27.616102Z",
"shell.execute_reply": "2026-11-12T16:10:27.615569Z"
}
},
"execution_count": 10,
"source": "project.display.pattern('expt_n2')",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<486,125 characters>, height=480)",
"text/html": ""
}
}
]
},
{
"id": "17",
"cell_type": "markdown",
"source": "### Background\n\nEach bank's background points; the last, past the end of the data, stays fixed.",
"metadata": {}
},
{
"id": "18",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:27.620218Z",
"iopub.execute_input": "2026-11-12T16:10:27.620348Z",
"shell.execute_reply": "2026-11-12T16:10:27.768634Z",
"iopub.status.idle": "2026-11-12T16:10:27.768994Z"
}
},
"execution_count": 11,
"source": "for point in bank_s2.background:\n point.intensity.free = True\nfor point in bank_n2.background:\n point.intensity.free = True\nbank_s2.background[30].intensity.free = False\nbank_n2.background[30].intensity.free = False",
"outputs": []
},
{
"id": "19",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:27.770434Z",
"iopub.execute_input": "2026-11-12T16:10:27.770587Z",
"shell.execute_reply": "2026-11-12T16:10:27.967592Z",
"iopub.status.idle": "2026-11-12T16:10:27.967964Z"
}
},
"execution_count": 12,
"source": "project.analysis.fit()\nproject.display.fit.results()",
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": "edi fit: joint project pd-neut-tof_ferrite-austenite-beer, 2 banks (expt_n2, expt_s2), 5642 pts fitted / 5998 loaded, 64 free\n iter time (s) Rwp (%) reduced χ² change\n 23.83 76.86\n 1 0.107 18.05 44.10 42.6% ↓\n done · converged · 1 iters · reduced χ² 44.10 · Rwp 18.05 % · 0.12 s\n"
},
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<174,472 characters>, height=376)",
"text/html": ""
}
}
]
},
{
"id": "20",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:27.969057Z",
"iopub.execute_input": "2026-11-12T16:10:27.969174Z",
"iopub.status.idle": "2026-11-12T16:10:28.022005Z",
"shell.execute_reply": "2026-11-12T16:10:28.021509Z"
}
},
"execution_count": 13,
"source": "project.display.pattern('expt_s2')",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<548,453 characters>, height=480)",
"text/html": ""
}
}
]
},
{
"id": "21",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:28.027481Z",
"iopub.execute_input": "2026-11-12T16:10:28.027620Z",
"iopub.status.idle": "2026-11-12T16:10:28.081231Z",
"shell.execute_reply": "2026-11-12T16:10:28.080777Z"
}
},
"execution_count": 14,
"source": "project.display.pattern('expt_n2')",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<547,832 characters>, height=480)",
"text/html": ""
}
}
]
},
{
"id": "22",
"cell_type": "markdown",
"source": "### Peak widths\n\nEach bank's widths.",
"metadata": {}
},
{
"id": "23",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:28.085844Z",
"iopub.execute_input": "2026-11-12T16:10:28.085988Z",
"iopub.status.idle": "2026-11-12T16:10:28.109525Z",
"shell.execute_reply": "2026-11-12T16:10:28.109118Z"
}
},
"execution_count": 15,
"source": "bank_s2.peak.broad_gauss_sigma_0.free = True\nbank_s2.peak.broad_gauss_sigma_1.free = True\nbank_s2.peak.broad_gauss_sigma_2.free = True\nbank_s2.peak.broad_lorentz_gamma_0.free = True\nbank_n2.peak.broad_gauss_sigma_0.free = True\nbank_n2.peak.broad_gauss_sigma_1.free = True\nbank_n2.peak.broad_gauss_sigma_2.free = True\nbank_n2.peak.broad_lorentz_gamma_0.free = True",
"outputs": []
},
{
"id": "24",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:28.110697Z",
"iopub.execute_input": "2026-11-12T16:10:28.110842Z",
"iopub.status.idle": "2026-11-12T16:10:28.326034Z",
"shell.execute_reply": "2026-11-12T16:10:28.325589Z"
}
},
"execution_count": 16,
"source": "project.analysis.fit()\nproject.display.fit.results()",
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": "edi fit: joint project pd-neut-tof_ferrite-austenite-beer, 2 banks (expt_n2, expt_s2), 5642 pts fitted / 5998 loaded, 72 free\n iter time (s) Rwp (%) reduced χ² change\n 18.05 44.16\n 1 0.120 16.38 36.35 17.7% ↓\n done · converged · 1 iters · reduced χ² 36.35 · Rwp 16.38 % · 0.13 s\n"
},
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<185,924 characters>, height=376)",
"text/html": ""
}
}
]
},
{
"id": "25",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:28.328074Z",
"iopub.execute_input": "2026-11-12T16:10:28.328198Z",
"iopub.status.idle": "2026-11-12T16:10:28.380640Z",
"shell.execute_reply": "2026-11-12T16:10:28.380208Z"
}
},
"execution_count": 17,
"source": "project.display.pattern('expt_s2')",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<548,203 characters>, height=480)",
"text/html": ""
}
}
]
},
{
"id": "26",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:28.385686Z",
"iopub.execute_input": "2026-11-12T16:10:28.385846Z",
"iopub.status.idle": "2026-11-12T16:10:28.439839Z",
"shell.execute_reply": "2026-11-12T16:10:28.439422Z"
}
},
"execution_count": 18,
"source": "project.display.pattern('expt_n2')",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<548,113 characters>, height=480)",
"text/html": ""
}
}
]
},
{
"id": "27",
"cell_type": "markdown",
"source": "### Displacement\n\nLast, ferrite's displacement; austenite's follows it.",
"metadata": {}
},
{
"id": "28",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:28.445199Z",
"iopub.execute_input": "2026-11-12T16:10:28.445341Z",
"shell.execute_reply": "2026-11-12T16:10:28.450350Z",
"iopub.status.idle": "2026-11-12T16:10:28.450707Z"
}
},
"execution_count": 19,
"source": "ferrite.atom_sites['Fe'].adp_iso.free = True",
"outputs": []
},
{
"id": "29",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:28.451676Z",
"iopub.execute_input": "2026-11-12T16:10:28.451790Z",
"iopub.status.idle": "2026-11-12T16:10:28.681630Z",
"shell.execute_reply": "2026-11-12T16:10:28.681249Z"
}
},
"execution_count": 20,
"source": "project.analysis.fit()\nproject.display.fit.results()",
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": "edi fit: joint project pd-neut-tof_ferrite-austenite-beer, 2 banks (expt_n2, expt_s2), 5642 pts fitted / 5998 loaded, 73 free\n iter time (s) Rwp (%) reduced χ² change\n 16.38 36.36\n 1 0.088 7.13 6.89 81.0% ↓\n 2 0.134 7.13 6.89 \n done · converged · 2 iters · reduced χ² 6.89 · Rwp 7.13 % · 0.15 s\n"
},
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<187,241 characters>, height=376)",
"text/html": ""
}
}
]
},
{
"id": "30",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:28.683929Z",
"iopub.execute_input": "2026-11-12T16:10:28.684060Z",
"iopub.status.idle": "2026-11-12T16:10:28.737827Z",
"shell.execute_reply": "2026-11-12T16:10:28.737377Z"
}
},
"execution_count": 21,
"source": "project.display.pattern('expt_s2')",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<548,533 characters>, height=480)",
"text/html": ""
}
}
]
},
{
"id": "31",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:28.742841Z",
"iopub.execute_input": "2026-11-12T16:10:28.742972Z",
"iopub.status.idle": "2026-11-12T16:10:28.796636Z",
"shell.execute_reply": "2026-11-12T16:10:28.796255Z"
}
},
"execution_count": 22,
"source": "project.display.pattern('expt_n2')",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<548,330 characters>, height=480)",
"text/html": ""
}
}
]
},
{
"id": "32",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:28.802246Z",
"iopub.execute_input": "2026-11-12T16:10:28.802387Z",
"iopub.status.idle": "2026-11-12T16:10:28.839914Z",
"shell.execute_reply": "2026-11-12T16:10:28.839523Z"
}
},
"execution_count": 23,
"source": "project.display.fit.correlations()",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<85,959 characters>, height=560)",
"text/html": ""
}
}
]
},
{
"id": "33",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:28.841351Z",
"iopub.execute_input": "2026-11-12T16:10:28.841478Z",
"iopub.status.idle": "2026-11-12T16:10:28.881436Z",
"shell.execute_reply": "2026-11-12T16:10:28.881054Z"
}
},
"execution_count": 24,
"source": "project.display.structure('ferrite')",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<153,756 characters>, height=660)",
"text/html": ""
}
}
]
},
{
"id": "34",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:28.882547Z",
"iopub.execute_input": "2026-11-12T16:10:28.882667Z",
"iopub.status.idle": "2026-11-12T16:10:28.922599Z",
"shell.execute_reply": "2026-11-12T16:10:28.922176Z"
}
},
"execution_count": 25,
"source": "project.display.structure('austenite')",
"outputs": [
{
"output_type": "display_data",
"metadata": {},
"data": {
"text/plain": "View(html=<208,387 characters>, height=660)",
"text/html": ""
}
}
]
},
{
"id": "35",
"cell_type": "markdown",
"source": "## Save the project",
"metadata": {}
},
{
"id": "36",
"cell_type": "code",
"metadata": {
"execution": {
"iopub.status.busy": "2026-11-12T16:10:28.924778Z",
"iopub.execute_input": "2026-11-12T16:10:28.924923Z",
"shell.execute_reply": "2026-11-12T16:10:29.399411Z",
"iopub.status.idle": "2026-11-12T16:10:29.399824Z"
}
},
"execution_count": 26,
"source": "project.save_as('pd-neut-tof_ferrite-austenite-beer')\nproject.report.save_html('pd-neut-tof_ferrite-austenite-beer.html')",
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": "Saving project to 'pd-neut-tof_ferrite-austenite-beer'\nSaving report to 'pd-neut-tof_ferrite-austenite-beer.html'\n"
}
]
}
]
}