Skip to content

Commit f84bda4

Browse files
committed
Updates NCAF tutorial
1 parent b7e6295 commit f84bda4

File tree

3 files changed

+110
-145
lines changed

3 files changed

+110
-145
lines changed

.github/workflows/building-deploying-docs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ jobs:
124124
- name: Build site with MkDocs
125125
run: |
126126
export JUPYTER_PLATFORM_DIRS=1
127+
export PYTHONWARNINGS="ignore::RuntimeWarning"
127128
export PYTHONPATH=$(pwd)/src:$PYTHONPATH
128129
mkdocs build
129130

src/easydiffraction/core/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
DEFAULT_PEAK_PROFILE_TYPE = {
88
"bragg": {
99
"constant wavelength": "pseudo-voigt",
10-
"time-of-flight": "pseudo-voigt"
10+
"time-of-flight": "pseudo-voigt * ikeda-carpenter"
1111
},
1212
"total": {
1313
"constant wavelength": "gaussian-damped-sinc",

tutorials/cryst-struct_pd-neut-tof_NCAF-WISH.py

Lines changed: 108 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# structure using time-of-flight neutron powder diffraction data from WISH at
66
# ISIS.
77
#
8-
# Temporarily, only a single dataset from detector banks 5 & 6 is used here.
8+
# Two datasets from detector banks 5_6 and 4_7 are used for joint fitting.
99

1010
# %% [markdown]
1111
# ## Import Library
@@ -45,12 +45,12 @@
4545
# ### Set Atom Sites
4646

4747
# %%
48-
model.atom_sites.add('Ca', 'Ca', 0.4661, 0.0, 0.25, wyckoff_letter="b", b_iso=0.9)
49-
model.atom_sites.add('Al', 'Al', 0.25171, 0.25171, 0.25171, wyckoff_letter="a", b_iso=0.66)
50-
model.atom_sites.add('Na', 'Na', 0.08481, 0.08481, 0.08481, wyckoff_letter="a", b_iso=1.9)
51-
model.atom_sites.add('F1', 'F', 0.1375, 0.3053, 0.1195, wyckoff_letter="c", b_iso=0.9)
52-
model.atom_sites.add('F2', 'F', 0.3626, 0.3634, 0.1867, wyckoff_letter="c", b_iso=1.28)
53-
model.atom_sites.add('F3', 'F', 0.4612, 0.4612, 0.4612, wyckoff_letter="a", b_iso=0.79)
48+
model.atom_sites.add('Ca', 'Ca', 0.4665, 0.0, 0.25, wyckoff_letter="b", b_iso=0.92)
49+
model.atom_sites.add('Al', 'Al', 0.2520, 0.2520, 0.2520, wyckoff_letter="a", b_iso=0.73)
50+
model.atom_sites.add('Na', 'Na', 0.0852, 0.0852, 0.0852, wyckoff_letter="a", b_iso=2.08)
51+
model.atom_sites.add('F1', 'F', 0.1376, 0.3055, 0.1196, wyckoff_letter="c", b_iso=0.90)
52+
model.atom_sites.add('F2', 'F', 0.3623, 0.3631, 0.1870, wyckoff_letter="c", b_iso=1.37)
53+
model.atom_sites.add('F3', 'F', 0.4611, 0.4611, 0.4611, wyckoff_letter="a", b_iso=0.88)
5454

5555
# %% [markdown]
5656
# ## Define Experiment
@@ -61,50 +61,61 @@
6161
# ### Download Measured Data
6262

6363
# %%
64-
download_from_repository('wish_ncaf.xye',
65-
branch='docs',
66-
destination='data')
64+
download_from_repository('wish_ncaf_5_6.xye', branch='docs', destination='data')
65+
66+
# %%
67+
download_from_repository('wish_ncaf_4_7.xye', branch='docs', destination='data')
6768

6869
# %% [markdown]
6970
# ### Create Experiment
7071

7172
# %%
72-
expt = Experiment('wish',
73-
beam_mode='time-of-flight',
74-
data_path='data/wish_ncaf.xye')
73+
expt56 = Experiment('wish_5_6', beam_mode='time-of-flight', data_path='data/wish_ncaf_5_6.xye')
74+
75+
# %%
76+
expt47 = Experiment('wish_4_7', beam_mode='time-of-flight', data_path='data/wish_ncaf_4_7.xye')
7577

7678
# %% [markdown]
7779
# ### Set Instrument
7880

7981
# %%
80-
expt.instrument.setup_twotheta_bank = 152.827
81-
expt.instrument.calib_d_to_tof_offset = 0.0
82-
expt.instrument.calib_d_to_tof_linear = 20770
83-
expt.instrument.calib_d_to_tof_quad = -1.08308
82+
expt56.instrument.setup_twotheta_bank = 152.827
83+
expt56.instrument.calib_d_to_tof_offset = -13.0
84+
expt56.instrument.calib_d_to_tof_linear = 20752.1
85+
expt56.instrument.calib_d_to_tof_quad = -1.08308
86+
87+
# %%
88+
expt47.instrument.setup_twotheta_bank = 121.660
89+
expt47.instrument.calib_d_to_tof_offset = -15.0
90+
expt47.instrument.calib_d_to_tof_linear = 18640.7
91+
expt47.instrument.calib_d_to_tof_quad = -0.47488
8492

8593
# %% [markdown]
8694
# ### Set Peak Profile
8795

8896
# %%
89-
expt.peak_profile_type = 'pseudo-voigt * ikeda-carpenter'
90-
expt.peak.broad_gauss_sigma_0 = 0.0
91-
expt.peak.broad_gauss_sigma_1 = 0.0
92-
expt.peak.broad_gauss_sigma_2 = 5.0
93-
expt.peak.broad_mix_beta_0 = 0.01
94-
expt.peak.broad_mix_beta_1 = 0.01
95-
96-
# %% [markdown]
97-
# ### Set Peak Asymmetry
97+
expt56.peak.broad_gauss_sigma_0 = 0.0
98+
expt56.peak.broad_gauss_sigma_1 = 0.0
99+
expt56.peak.broad_gauss_sigma_2 = 15.0
100+
expt56.peak.broad_mix_beta_0 = 0.01
101+
expt56.peak.broad_mix_beta_1 = 0.01
102+
expt56.peak.asym_alpha_0 = -0.01
103+
expt56.peak.asym_alpha_1 = 0.10
98104

99105
# %%
100-
expt.peak.asym_alpha_0 = 0.0
101-
expt.peak.asym_alpha_1 = 0.1
106+
expt47.peak.broad_gauss_sigma_0 = 0.0
107+
expt47.peak.broad_gauss_sigma_1 = 30.0
108+
expt47.peak.broad_gauss_sigma_2 = 20.0
109+
expt47.peak.broad_mix_beta_0 = 0.01
110+
expt47.peak.broad_mix_beta_1 = 0.01
111+
expt47.peak.asym_alpha_0 = -0.01
112+
expt47.peak.asym_alpha_1 = 0.10
102113

103114
# %% [markdown]
104115
# ### Set Background
105116

106117
# %%
107-
expt.background_type = 'line-segment'
118+
expt56.background_type = 'line-segment'
108119
for x, y in [
109120
(9162, 465),
110121
(11136, 593),
@@ -135,13 +146,49 @@
135146
(91958, 268),
136147
(102712, 262)
137148
]:
138-
expt.background.add(x, y)
149+
expt56.background.add(x, y)
150+
151+
# %%
152+
expt47.background_type = 'line-segment'
153+
for x, y in [
154+
(9090, 488),
155+
(10672, 566),
156+
(12287, 494),
157+
(14037, 559),
158+
(15451, 529),
159+
(16764, 445),
160+
(18076, 460),
161+
(19456, 413),
162+
(20466, 511),
163+
(21880, 396),
164+
(23798, 391),
165+
(25447, 385),
166+
(28073, 349),
167+
(30058, 332),
168+
(32583, 309),
169+
(34804, 355),
170+
(37160, 318),
171+
(40324, 290),
172+
(46895, 260),
173+
(50631, 256),
174+
(54602, 246),
175+
(58439, 264),
176+
(66520, 250),
177+
(75002, 258),
178+
(83649, 257),
179+
(92770, 255),
180+
(101524, 260)
181+
]:
182+
expt47.background.add(x, y)
139183

140184
# %% [markdown]
141185
# ### Set Linked Phases
142186

143187
# %%
144-
expt.linked_phases.add('ncaf', scale=0.5)
188+
expt56.linked_phases.add('ncaf', scale=1.0)
189+
190+
# %%
191+
expt47.linked_phases.add('ncaf', scale=2.0)
145192

146193
# %% [markdown]
147194
# ## Define Project
@@ -170,7 +217,8 @@
170217
# ### Add Experiment
171218

172219
# %%
173-
project.experiments.add(expt)
220+
project.experiments.add(expt56)
221+
project.experiments.add(expt47)
174222

175223
# %% [markdown]
176224
# ## Analysis
@@ -190,93 +238,24 @@
190238
project.analysis.current_minimizer = 'lmfit (leastsq)'
191239

192240
# %% [markdown]
193-
# ### Plot Measured vs Calculated
241+
# ### Set Fit Mode
194242

195243
# %%
196-
project.plot_meas_vs_calc(expt_name='wish',
197-
show_residual=True)
198-
199-
# %%
200-
project.plot_meas_vs_calc(expt_name='wish',
201-
x_min=37000, x_max=40000,
202-
show_residual=True)
203-
204-
# %% [markdown]
205-
# ### Perform Fit 1/5
206-
#
207-
# Set parameters to be refined.
208-
209-
# %%
210-
model.cell.length_a.free = True
211-
212-
expt.instrument.calib_d_to_tof_offset.free = True
213-
expt.linked_phases['ncaf'].scale.free = True
214-
215-
# %% [markdown]
216-
# Show free parameters after selection.
217-
218-
# %%
219-
project.analysis.show_free_params()
220-
221-
# %% [markdown]
222-
# #### Run Fit
223-
224-
# %%
225-
project.analysis.fit()
244+
project.analysis.fit_mode = 'joint'
226245

227246
# %% [markdown]
228247
# ### Plot Measured vs Calculated
229248

230249
# %%
231-
project.plot_meas_vs_calc(expt_name='wish',
232-
show_residual=True)
250+
project.plot_meas_vs_calc(expt_name='wish_5_6', show_residual=True)
233251

234252
# %%
235-
project.plot_meas_vs_calc(expt_name='wish',
236-
x_min=37000, x_max=40000,
237-
show_residual=True)
253+
project.plot_meas_vs_calc(expt_name='wish_4_7', show_residual=True)
238254

239255
# %% [markdown]
240-
# ### Perform Fit 2/5
256+
# ### Perform Fit
241257
#
242-
# Set more parameters to be refined.
243-
244-
# %%
245-
expt.peak.broad_gauss_sigma_2.free = True
246-
expt.peak.broad_mix_beta_0.free = True
247-
expt.peak.broad_mix_beta_1.free = True
248-
expt.peak.asym_alpha_0.free = True
249-
expt.peak.asym_alpha_1.free = True
250-
251-
# %% [markdown]
252-
# Show free parameters after selection.
253-
254-
# %%
255-
project.analysis.show_free_params()
256-
257-
# %% [markdown]
258-
# #### Run Fit
259-
260-
# %%
261-
project.analysis.fit()
262-
263-
# %% [markdown]
264-
# #### Plot Measured vs Calculated
265-
266-
# %%
267-
project.plot_meas_vs_calc(expt_name='wish',
268-
show_residual=True)
269-
270-
# %%
271-
project.plot_meas_vs_calc(expt_name='wish',
272-
x_min=37000, x_max=40000,
273-
show_residual=True)
274-
275-
276-
# %% [markdown]
277-
# ### Perform Fit 3/5
278-
#
279-
# Set more parameters to be refined.
258+
# Set parameters to be refined.
280259

281260
# %%
282261
model.atom_sites['Ca'].fract_x.free = True
@@ -290,45 +269,33 @@
290269
model.atom_sites['F2'].fract_z.free = True
291270
model.atom_sites['F3'].fract_x.free = True
292271

293-
# %% [markdown]
294-
# Show free parameters after selection.
295-
296-
# %%
297-
project.analysis.show_free_params()
298-
299-
# %% [markdown]
300-
# #### Run Fit
301-
302-
# %%
303-
project.analysis.fit()
304-
305-
# %% [markdown]
306-
# #### Plot Measured vs Calculated
307-
308-
# %%
309-
project.plot_meas_vs_calc(expt_name='wish',
310-
show_residual=True)
311-
312-
# %%
313-
project.plot_meas_vs_calc(expt_name='wish',
314-
x_min=37000, x_max=40000,
315-
show_residual=True)
316-
317-
# %% [markdown]
318-
# ### Perform Fit 4/5
319-
#
320-
# Set more parameters to be refined.
321-
322-
# %%
323-
expt.instrument.calib_d_to_tof_linear.free = True
324-
325272
model.atom_sites['Ca'].b_iso.free = True
326273
model.atom_sites['Al'].b_iso.free = True
327274
model.atom_sites['Na'].b_iso.free = True
328275
model.atom_sites['F1'].b_iso.free = True
329276
model.atom_sites['F2'].b_iso.free = True
330277
model.atom_sites['F3'].b_iso.free = True
331278

279+
# %%
280+
expt56.linked_phases['ncaf'].scale.free = True
281+
expt56.instrument.calib_d_to_tof_offset.free = True
282+
expt56.instrument.calib_d_to_tof_linear.free = True
283+
expt56.peak.broad_gauss_sigma_2.free = True
284+
expt56.peak.broad_mix_beta_0.free = True
285+
expt56.peak.broad_mix_beta_1.free = True
286+
expt56.peak.asym_alpha_0.free = True
287+
expt56.peak.asym_alpha_1.free = True
288+
289+
expt47.linked_phases['ncaf'].scale.free = True
290+
expt47.instrument.calib_d_to_tof_linear.free = True
291+
expt47.instrument.calib_d_to_tof_offset.free = True
292+
expt47.peak.broad_gauss_sigma_1.free = True
293+
expt47.peak.broad_gauss_sigma_2.free = True
294+
expt47.peak.broad_mix_beta_0.free = True
295+
expt47.peak.broad_mix_beta_1.free = True
296+
expt47.peak.asym_alpha_0.free = True
297+
expt47.peak.asym_alpha_1.free = True
298+
332299
# %% [markdown]
333300
# Show free parameters after selection.
334301

@@ -345,13 +312,10 @@
345312
# #### Plot Measured vs Calculated
346313

347314
# %%
348-
project.plot_meas_vs_calc(expt_name='wish',
349-
show_residual=True)
315+
project.plot_meas_vs_calc(expt_name='wish_5_6', show_residual=True)
350316

351317
# %%
352-
project.plot_meas_vs_calc(expt_name='wish',
353-
x_min=37000, x_max=40000,
354-
show_residual=True)
318+
project.plot_meas_vs_calc(expt_name='wish_4_7', show_residual=True)
355319

356320
# %% [markdown]
357321
# ## Summary

0 commit comments

Comments
 (0)