Skip to content

Commit 7f4f336

Browse files
Add parameter correlations table/plot (#146)
* Reorganize tmp/ directory * Implement parameter correlations table/plot * Enhance correlation heatmap with threshold and precision parameters for labels * Refine documentation and examples * Refactor example notebooks to improve clarity * Temporarily lower minimum coverage percentage requirement from 75 to 70 * Remove show_diagonal and triangle from plot_param_correlations * Fix PlotterBase.plot_correlation_heatmap lint errors * Fix future annotations, dead code, and **kwargs in display * Clean up
1 parent 745b51e commit 7f4f336

58 files changed

Lines changed: 1394 additions & 200 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/architecture/sequential_fitting_design.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,7 @@ propagation, diffrn callback, precondition validation.
11201120
**Implemented:** `Plotter.plot_param_series()` resolves CSV vs snapshots
11211121
automatically via the project reference.
11221122
`Plotter._plot_param_series_from_csv()` reads CSV via pandas.
1123-
`Plotter._plot_param_series_from_snapshots()` preserves backward
1123+
`Plotter.plot_param_series_from_snapshots()` preserves backward
11241124
compatibility for `fit()` single-mode (no CSV yet). Axis labels derived
11251125
from live descriptor objects.
11261126

docs/docs/tutorials/ed-1.ipynb

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{
44
"cell_type": "code",
55
"execution_count": null,
6-
"id": "b1e6b328",
6+
"id": "ab0fa7f5",
77
"metadata": {
88
"tags": [
99
"hide-in-docs"
@@ -26,23 +26,20 @@
2626
"source": [
2727
"# Structure Refinement: LBCO, HRPT\n",
2828
"\n",
29-
"This minimalistic example is designed to show how Rietveld refinement\n",
30-
"can be performed when both the crystal structure and experiment\n",
31-
"parameters are defined using CIF files.\n",
29+
"This basic example is designed to show how Rietveld refinement can be\n",
30+
"performed when both the crystal structure and experiment parameters\n",
31+
"are defined using CIF files.\n",
3232
"\n",
3333
"For this example, constant-wavelength neutron powder diffraction data\n",
3434
"for La0.5Ba0.5CoO3 from HRPT at PSI is used.\n",
3535
"\n",
36-
"It does not contain any advanced features or options, and includes no\n",
37-
"comments or explanations—these can be found in the other tutorials.\n",
38-
"Default values are used for all parameters if not specified. Only\n",
39-
"essential and self-explanatory code is provided.\n",
40-
"\n",
4136
"The example is intended for users who are already familiar with the\n",
42-
"EasyDiffraction library and want to quickly get started with a simple\n",
43-
"refinement. It is also useful for those who want to see what a\n",
44-
"refinement might look like in code. For a more detailed explanation of\n",
45-
"the code, please refer to the other tutorials."
37+
"EasyDiffraction library and want to quickly get started with a basic\n",
38+
"refinement.\n",
39+
"\n",
40+
"It is also useful for those who want to see how constraints can be\n",
41+
"applied to highly correlated parameters. For a more detailed\n",
42+
"explanation of the code, please refer to the other tutorials."
4643
]
4744
},
4845
{
@@ -147,7 +144,7 @@
147144
"id": "11",
148145
"metadata": {},
149146
"source": [
150-
"## Step 4: Perform Analysis (cryspy)"
147+
"## Step 4: Perform Analysis (no constraints)"
151148
]
152149
},
153150
{
@@ -157,18 +154,9 @@
157154
"metadata": {},
158155
"outputs": [],
159156
"source": [
160-
"# Define aliases and constraints for refinement. This is necessary to\n",
161-
"# properly refine the isotropic displacement parameters of La and Ba,\n",
162-
"# which are correlated due to their shared Wyckoff position.\n",
163-
"project.analysis.aliases.create(\n",
164-
" label='biso_La',\n",
165-
" param=project.structures['lbco'].atom_sites['La'].b_iso,\n",
166-
")\n",
167-
"project.analysis.aliases.create(\n",
168-
" label='biso_Ba',\n",
169-
" param=project.structures['lbco'].atom_sites['Ba'].b_iso,\n",
170-
")\n",
171-
"project.analysis.constraints.create(expression='biso_Ba = biso_La')"
157+
"# Start refinement. All parameters, which have standard uncertainties\n",
158+
"# in the input CIF files, are refined by default.\n",
159+
"project.analysis.fit()"
172160
]
173161
},
174162
{
@@ -178,9 +166,8 @@
178166
"metadata": {},
179167
"outputs": [],
180168
"source": [
181-
"# Start refinement. All parameters, which have standard uncertainties\n",
182-
"# in the input CIF files, are refined by default.\n",
183-
"project.analysis.fit()"
169+
"# Show fit results summary\n",
170+
"project.analysis.display.fit_results()"
184171
]
185172
},
186173
{
@@ -190,19 +177,16 @@
190177
"metadata": {},
191178
"outputs": [],
192179
"source": [
193-
"# Show fit results summary\n",
194-
"project.analysis.display.fit_results()"
180+
"# Show parameter correlations\n",
181+
"project.plotter.plot_param_correlations()"
195182
]
196183
},
197184
{
198-
"cell_type": "code",
199-
"execution_count": null,
185+
"cell_type": "markdown",
200186
"id": "15",
201187
"metadata": {},
202-
"outputs": [],
203188
"source": [
204-
"# Show defined experiment names\n",
205-
"project.experiments.show_names()"
189+
"## Step 5: Perform Analysis (with constraints)"
206190
]
207191
},
208192
{
@@ -212,16 +196,34 @@
212196
"metadata": {},
213197
"outputs": [],
214198
"source": [
215-
"# Plot measured vs. calculated diffraction patterns\n",
216-
"project.plotter.plot_meas_vs_calc(expt_name='hrpt', show_residual=True)"
199+
"# As can be seen from the parameter-correlation plot, the isotropic\n",
200+
"# displacement parameters of La and Ba are highly correlated. Because\n",
201+
"# La and Ba share the same mixed-occupancy site, their contributions to\n",
202+
"# the neutron diffraction pattern are difficult to separate, especially\n",
203+
"# since their coherent scattering lengths are not very different.\n",
204+
"# Therefore, it is necessary to constrain them to be equal. First we\n",
205+
"# define aliases and then use them to create a constraint.\n",
206+
"project.analysis.aliases.create(\n",
207+
" label='biso_La',\n",
208+
" param=project.structures['lbco'].atom_sites['La'].b_iso,\n",
209+
")\n",
210+
"project.analysis.aliases.create(\n",
211+
" label='biso_Ba',\n",
212+
" param=project.structures['lbco'].atom_sites['Ba'].b_iso,\n",
213+
")\n",
214+
"project.analysis.constraints.create(expression='biso_Ba = biso_La')"
217215
]
218216
},
219217
{
220-
"cell_type": "markdown",
218+
"cell_type": "code",
219+
"execution_count": null,
221220
"id": "17",
222221
"metadata": {},
222+
"outputs": [],
223223
"source": [
224-
"## Step 5: Perform Analysis (crysfml)"
224+
"# Start refinement. All parameters, which have standard uncertainties\n",
225+
"# in the input CIF files, are refined by default.\n",
226+
"project.analysis.fit()"
225227
]
226228
},
227229
{
@@ -231,9 +233,8 @@
231233
"metadata": {},
232234
"outputs": [],
233235
"source": [
234-
"# Change calculation engine from 'cryspy' to 'crysfml'\n",
235-
"project.experiments['hrpt'].show_supported_calculator_types()\n",
236-
"project.experiments['hrpt'].calculator_type = 'crysfml'"
236+
"# Show fit results summary\n",
237+
"project.analysis.display.fit_results()"
237238
]
238239
},
239240
{
@@ -243,8 +244,8 @@
243244
"metadata": {},
244245
"outputs": [],
245246
"source": [
246-
"# Start refinement\n",
247-
"project.analysis.fit()"
247+
"# Show parameter correlations\n",
248+
"project.plotter.plot_param_correlations()"
248249
]
249250
},
250251
{
@@ -254,8 +255,8 @@
254255
"metadata": {},
255256
"outputs": [],
256257
"source": [
257-
"# Show fit results summary\n",
258-
"project.analysis.display.fit_results()"
258+
"# Show defined experiment names\n",
259+
"project.experiments.show_names()"
259260
]
260261
},
261262
{

docs/docs/tutorials/ed-1.py

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
# %% [markdown]
22
# # Structure Refinement: LBCO, HRPT
33
#
4-
# This minimalistic example is designed to show how Rietveld refinement
5-
# can be performed when both the crystal structure and experiment
6-
# parameters are defined using CIF files.
4+
# This basic example is designed to show how Rietveld refinement can be
5+
# performed when both the crystal structure and experiment parameters
6+
# are defined using CIF files.
77
#
88
# For this example, constant-wavelength neutron powder diffraction data
99
# for La0.5Ba0.5CoO3 from HRPT at PSI is used.
1010
#
11-
# It does not contain any advanced features or options, and includes no
12-
# comments or explanations—these can be found in the other tutorials.
13-
# Default values are used for all parameters if not specified. Only
14-
# essential and self-explanatory code is provided.
15-
#
1611
# The example is intended for users who are already familiar with the
17-
# EasyDiffraction library and want to quickly get started with a simple
18-
# refinement. It is also useful for those who want to see what a
19-
# refinement might look like in code. For a more detailed explanation of
20-
# the code, please refer to the other tutorials.
12+
# EasyDiffraction library and want to quickly get started with a basic
13+
# refinement.
14+
#
15+
# It is also useful for those who want to see how constraints can be
16+
# applied to highly correlated parameters. For a more detailed
17+
# explanation of the code, please refer to the other tutorials.
2118

2219
# %% [markdown]
2320
# ## Import Library
@@ -55,12 +52,32 @@
5552
project.experiments.add_from_cif_path(expt_path)
5653

5754
# %% [markdown]
58-
# ## Step 4: Perform Analysis (cryspy)
55+
# ## Step 4: Perform Analysis (no constraints)
56+
57+
# %%
58+
# Start refinement. All parameters, which have standard uncertainties
59+
# in the input CIF files, are refined by default.
60+
project.analysis.fit()
61+
62+
# %%
63+
# Show fit results summary
64+
project.analysis.display.fit_results()
65+
66+
# %%
67+
# Show parameter correlations
68+
project.plotter.plot_param_correlations()
69+
70+
# %% [markdown]
71+
# ## Step 5: Perform Analysis (with constraints)
5972

6073
# %%
61-
# Define aliases and constraints for refinement. This is necessary to
62-
# properly refine the isotropic displacement parameters of La and Ba,
63-
# which are correlated due to their shared Wyckoff position.
74+
# As can be seen from the parameter-correlation plot, the isotropic
75+
# displacement parameters of La and Ba are highly correlated. Because
76+
# La and Ba share the same mixed-occupancy site, their contributions to
77+
# the neutron diffraction pattern are difficult to separate, especially
78+
# since their coherent scattering lengths are not very different.
79+
# Therefore, it is necessary to constrain them to be equal. First we
80+
# define aliases and then use them to create a constraint.
6481
project.analysis.aliases.create(
6582
label='biso_La',
6683
param=project.structures['lbco'].atom_sites['La'].b_iso,
@@ -81,28 +98,12 @@
8198
project.analysis.display.fit_results()
8299

83100
# %%
84-
# Show defined experiment names
85-
project.experiments.show_names()
86-
87-
# %%
88-
# Plot measured vs. calculated diffraction patterns
89-
project.plotter.plot_meas_vs_calc(expt_name='hrpt', show_residual=True)
90-
91-
# %% [markdown]
92-
# ## Step 5: Perform Analysis (crysfml)
93-
94-
# %%
95-
# Change calculation engine from 'cryspy' to 'crysfml'
96-
project.experiments['hrpt'].show_supported_calculator_types()
97-
project.experiments['hrpt'].calculator_type = 'crysfml'
98-
99-
# %%
100-
# Start refinement
101-
project.analysis.fit()
101+
# Show parameter correlations
102+
project.plotter.plot_param_correlations()
102103

103104
# %%
104-
# Show fit results summary
105-
project.analysis.display.fit_results()
105+
# Show defined experiment names
106+
project.experiments.show_names()
106107

107108
# %%
108109
# Plot measured vs. calculated diffraction patterns

docs/docs/tutorials/ed-10.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{
44
"cell_type": "code",
55
"execution_count": null,
6-
"id": "307e00fa",
6+
"id": "dc88a9ac",
77
"metadata": {
88
"tags": [
99
"hide-in-docs"

docs/docs/tutorials/ed-11.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{
44
"cell_type": "code",
55
"execution_count": null,
6-
"id": "2ab104e6",
6+
"id": "9736040b",
77
"metadata": {
88
"tags": [
99
"hide-in-docs"

docs/docs/tutorials/ed-12.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{
44
"cell_type": "code",
55
"execution_count": null,
6-
"id": "f188a46a",
6+
"id": "44960a4c",
77
"metadata": {
88
"tags": [
99
"hide-in-docs"

docs/docs/tutorials/ed-13.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{
44
"cell_type": "code",
55
"execution_count": null,
6-
"id": "be0cfa00",
6+
"id": "1ac207fe",
77
"metadata": {
88
"tags": [
99
"hide-in-docs"
@@ -2647,7 +2647,7 @@
26472647
],
26482648
"metadata": {
26492649
"jupytext": {
2650-
"cell_metadata_filter": "title,tags,-all",
2650+
"cell_metadata_filter": "tags,title,-all",
26512651
"main_language": "python",
26522652
"notebook_metadata_filter": "-all"
26532653
}

docs/docs/tutorials/ed-14.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{
44
"cell_type": "code",
55
"execution_count": null,
6-
"id": "f6f4b6a6",
6+
"id": "86c9f966",
77
"metadata": {
88
"tags": [
99
"hide-in-docs"

docs/docs/tutorials/ed-15.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{
44
"cell_type": "code",
55
"execution_count": null,
6-
"id": "ceaaff89",
6+
"id": "c631fd19",
77
"metadata": {
88
"tags": [
99
"hide-in-docs"

docs/docs/tutorials/ed-16.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{
44
"cell_type": "code",
55
"execution_count": null,
6-
"id": "c342992c",
6+
"id": "d0fcc613",
77
"metadata": {
88
"tags": [
99
"hide-in-docs"

0 commit comments

Comments
 (0)