|
1 | 1 | # %% [markdown]
|
2 |
| -# # Joint Fit (Advanced Usage) |
| 2 | +# # Joint Fit (Advanced) |
3 | 3 | #
|
4 |
| -# This example demonstrates a more flexible and advanced usage of the |
5 |
| -# EasyDiffraction library by explicitly creating and configuring some objects. |
6 |
| -# It is more suitable for users comfortable with Python programming and those |
7 |
| -# interested in custom workflows. |
| 4 | +# This example demonstrates a flexible and advanced use of the |
| 5 | +# EasyDiffraction library by explicitly creating and configuring objects. |
| 6 | +# It is intended for users who are comfortable with Python programming and are |
| 7 | +# interested in creating custom workflows. |
8 | 8 |
|
9 | 9 | # %% [markdown]
|
10 |
| -# ## Import EasyDiffraction |
| 10 | +# ## Import Library |
11 | 11 |
|
12 | 12 | # %%
|
13 | 13 | from easydiffraction import (
|
|
20 | 20 | # %% [markdown]
|
21 | 21 | # ## Define Sample Model
|
22 | 22 | #
|
23 |
| -# This section covers how to add sample models and modify their parameters. |
| 23 | +# This section explains how to add sample models and modify their parameters. |
24 | 24 | #
|
25 |
| -# ### Create sample model object |
| 25 | +# ### Create Sample Model |
26 | 26 |
|
27 | 27 | # %%
|
28 | 28 | model = SampleModel('pbso4')
|
29 | 29 |
|
30 | 30 | # %% [markdown]
|
31 |
| -# ### Define space group |
| 31 | +# ### Set Space Group |
32 | 32 |
|
33 | 33 | # %%
|
34 | 34 | model.space_group.name_h_m = 'P n m a'
|
35 | 35 |
|
36 | 36 | # %% [markdown]
|
37 |
| -# ### Define unit cell |
| 37 | +# ### Set Unit Cell |
38 | 38 |
|
39 | 39 | # %%
|
40 | 40 | model.cell.length_a = 8.47
|
41 | 41 | model.cell.length_b = 5.39
|
42 | 42 | model.cell.length_c = 6.95
|
43 | 43 |
|
44 | 44 | # %% [markdown]
|
45 |
| -# ### Define atom sites |
| 45 | +# ### Set Atom Sites |
46 | 46 |
|
47 | 47 | # %%
|
48 | 48 | model.atom_sites.add('Pb', 'Pb', 0.1876, 0.25, 0.167, b_iso=1.37)
|
|
55 | 55 | # %% [markdown]
|
56 | 56 | # ## Define Experiments
|
57 | 57 | #
|
58 |
| -# This section teaches how to add experiments, configure their parameters, and |
59 |
| -# link to them the sample models defined in the previous step. |
| 58 | +# This section explains how to add experiments, configure their parameters, and |
| 59 | +# link the sample models defined in the previous step. |
60 | 60 | #
|
61 | 61 | # ### Experiment 1: npd
|
62 | 62 | #
|
63 |
| -# #### Download measured data |
| 63 | +# #### Download Data |
64 | 64 |
|
65 | 65 | # %%
|
66 | 66 | download_from_repository('d1a_pbso4.dat',
|
67 | 67 | branch='docs',
|
68 | 68 | destination='data')
|
69 | 69 |
|
70 | 70 | # %% [markdown]
|
71 |
| -# #### Create experiment object |
| 71 | +# #### Create Experiment |
72 | 72 |
|
73 | 73 | # %%
|
74 | 74 | expt1 = Experiment('npd',
|
75 | 75 | radiation_probe='neutron',
|
76 | 76 | data_path='data/d1a_pbso4.dat')
|
77 | 77 |
|
78 | 78 | # %% [markdown]
|
79 |
| -# #### Define instrument |
| 79 | +# #### Set Instrument |
80 | 80 |
|
81 | 81 | # %%
|
82 | 82 | expt1.instrument.setup_wavelength = 1.91
|
83 | 83 | expt1.instrument.calib_twotheta_offset = -0.1406
|
84 | 84 |
|
85 | 85 | # %% [markdown]
|
86 |
| -# #### Define peak profile |
| 86 | +# #### Set Peak Profile |
87 | 87 |
|
88 | 88 | # %%
|
89 | 89 | expt1.peak.broad_gauss_u = 0.139
|
|
93 | 93 | expt1.peak.broad_lorentz_y = 0.088
|
94 | 94 |
|
95 | 95 | # %% [markdown]
|
96 |
| -# #### Define background |
| 96 | +# #### Set Background |
97 | 97 |
|
98 | 98 | # %% [markdown]
|
99 |
| -# Select desired background type |
| 99 | +# Select Background Type |
100 | 100 |
|
101 | 101 | # %%
|
102 | 102 | expt1.background_type = 'line-segment'
|
103 | 103 |
|
104 | 104 | # %% [markdown]
|
105 |
| -# Add background points |
| 105 | +# Add Background Points |
106 | 106 |
|
107 | 107 | # %%
|
108 | 108 | for x, y in [
|
|
118 | 118 | expt1.background.add(x, y)
|
119 | 119 |
|
120 | 120 | # %% [markdown]
|
121 |
| -# #### Define linked phases |
| 121 | +# #### Set Linked Phases |
122 | 122 |
|
123 | 123 | # %%
|
124 | 124 | expt1.linked_phases.add('pbso4', scale=1.5)
|
125 | 125 |
|
126 | 126 | # %% [markdown]
|
127 | 127 | # ### Experiment 2: xrd
|
128 | 128 | #
|
129 |
| -# #### Download measured data |
| 129 | +# #### Download Data |
130 | 130 |
|
131 | 131 | # %%
|
132 | 132 | download_from_repository('lab_pbso4.dat',
|
133 | 133 | branch='docs',
|
134 | 134 | destination='data')
|
135 | 135 |
|
136 | 136 | # %% [markdown]
|
137 |
| -# #### Create experiment object |
| 137 | +# #### Create Experiment |
138 | 138 |
|
139 | 139 | # %%
|
140 | 140 | expt2 = Experiment('xrd',
|
141 | 141 | radiation_probe='xray',
|
142 | 142 | data_path='data/lab_pbso4.dat')
|
143 | 143 |
|
144 | 144 | # %% [markdown]
|
145 |
| -# #### Define instrument |
| 145 | +# #### Set Instrument |
146 | 146 |
|
147 | 147 | # %%
|
148 | 148 | expt2.instrument.setup_wavelength = 1.540567
|
149 | 149 | expt2.instrument.calib_twotheta_offset = -0.05181
|
150 | 150 |
|
151 | 151 | # %% [markdown]
|
152 |
| -# #### Define peak profile |
| 152 | +# #### Set Peak Profile |
153 | 153 |
|
154 | 154 | # %%
|
155 | 155 | expt2.peak.broad_gauss_u = 0.304138
|
|
159 | 159 | expt2.peak.broad_lorentz_y = 0.057691
|
160 | 160 |
|
161 | 161 | # %% [markdown]
|
162 |
| -# #### Define background |
| 162 | +# #### Set Background |
163 | 163 |
|
164 | 164 | # %% [markdown]
|
165 |
| -# Select desired background type |
| 165 | +# Select Background Type |
166 | 166 |
|
167 | 167 | # %%
|
168 | 168 | expt2.background_type = 'chebyshev polynomial'
|
169 | 169 |
|
170 | 170 | # %% [markdown]
|
171 |
| -# Add background points |
| 171 | +# Add Background Points |
172 | 172 |
|
173 | 173 | # %%
|
174 | 174 | for x, y in [
|
|
182 | 182 | expt2.background.add(x, y)
|
183 | 183 |
|
184 | 184 | # %% [markdown]
|
185 |
| -# #### Define linked phases |
| 185 | +# #### Set Linked Phases |
186 | 186 |
|
187 | 187 | # %%
|
188 | 188 | expt2.linked_phases.add('pbso4', scale=0.001)
|
189 | 189 |
|
190 | 190 | # %% [markdown]
|
191 | 191 | # ## Define Project
|
192 | 192 | #
|
193 |
| -# The project object is used to manage the sample model, experiments, and |
194 |
| -# analysis |
| 193 | +# The project object manages the sample model, experiments, and |
| 194 | +# analysis. |
195 | 195 | #
|
196 |
| -# ### Create project object |
| 196 | +# ### Create Project |
197 | 197 |
|
198 | 198 | # %%
|
199 | 199 | project = Project()
|
200 | 200 |
|
201 | 201 | # %% [markdown]
|
202 |
| -# ### Add sample model |
| 202 | +# ### Add Sample Model |
203 | 203 |
|
204 | 204 | # %%
|
205 | 205 | project.sample_models.add(model)
|
206 | 206 |
|
207 | 207 | # %% [markdown]
|
208 |
| -# ### Add experiments |
| 208 | +# ### Add Experiments |
209 | 209 |
|
210 | 210 | # %%
|
211 | 211 | project.experiments.add(expt1)
|
|
214 | 214 | # %% [markdown]
|
215 | 215 | # ## Analysis
|
216 | 216 | #
|
217 |
| -# This section will guide you through the analysis process, including setting |
218 |
| -# up calculators and fitting models. |
| 217 | +# This section explains the analysis process, including how to set |
| 218 | +# up calculators and fit models. |
219 | 219 | #
|
220 |
| -# ### Set calculation engine |
| 220 | +# ### Set Calculator |
221 | 221 |
|
222 | 222 | # %%
|
223 | 223 | project.analysis.current_calculator = 'cryspy'
|
224 | 224 |
|
225 | 225 | # %% [markdown]
|
226 |
| -# ### Set fit mode |
| 226 | +# ### Set Fit Mode |
227 | 227 |
|
228 | 228 | # %%
|
229 | 229 | project.analysis.fit_mode = 'joint'
|
230 | 230 |
|
231 | 231 | # %% [markdown]
|
232 |
| -# ### Set fitting engine |
| 232 | +# ### Set Minimizer |
233 | 233 |
|
234 | 234 | # %%
|
235 | 235 | project.analysis.current_minimizer = 'lmfit (leastsq)'
|
236 | 236 |
|
237 | 237 | # %% [markdown]
|
238 |
| -# ### Set fitting parameters |
| 238 | +# ### Set Fitting Parameters |
239 | 239 | #
|
240 |
| -# Set sample model parameters to be fitted |
| 240 | +# Set sample model parameters to be refined |
241 | 241 |
|
242 | 242 | # %%
|
243 | 243 | model.cell.length_a.free = True
|
244 | 244 | model.cell.length_b.free = True
|
245 | 245 | model.cell.length_c.free = True
|
246 | 246 |
|
247 | 247 | # %% [markdown]
|
248 |
| -# Set experimental parameters to be fitted |
| 248 | +# Set experiment parameters to be refined |
249 | 249 |
|
250 | 250 | # %%
|
251 | 251 | expt1.linked_phases['pbso4'].scale.free = True
|
|
271 | 271 | term.coef.free = True
|
272 | 272 |
|
273 | 273 | # %% [markdown]
|
274 |
| -# ### Perform Fit |
| 274 | +# ### Run Fit |
275 | 275 |
|
276 | 276 | # %%
|
277 | 277 | project.analysis.fit()
|
278 | 278 |
|
279 | 279 | # %% [markdown]
|
280 |
| -# ### Show fitting results |
| 280 | +# ### Show Results |
281 | 281 |
|
282 | 282 | # %%
|
283 | 283 | project.plot_meas_vs_calc(expt_name='npd',
|
|
0 commit comments