analysis
analysis
Analysis
Source code in src/easydiffraction/analysis/analysis.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 |
|
calculate_pattern(expt_name)
Calculate the diffraction pattern for a given experiment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expt_name
|
str
|
The name of the experiment. |
required |
Returns:
Type | Description |
---|---|
Optional[ndarray]
|
The calculated pattern as a pandas DataFrame. |
Source code in src/easydiffraction/analysis/analysis.py
355 356 357 358 359 360 361 362 363 364 365 366 367 368 |
|
calculation
DiffractionCalculator
Invokes calculation engines for pattern generation.
Source code in src/easydiffraction/analysis/calculation.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
|
__init__(engine='cryspy')
Initialize the DiffractionCalculator with a specified backend engine.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
engine
|
str
|
Type of the calculation engine to use. Supported types: 'crysfml', 'cryspy', 'pdffit'. Default is 'cryspy'. |
'cryspy'
|
Source code in src/easydiffraction/analysis/calculation.py
22 23 24 25 26 27 28 29 30 31 32 |
|
calculate_pattern(sample_models, experiment)
Calculate diffraction pattern based on sample models and experiment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample_models
|
SampleModels
|
Collection of sample models. |
required |
experiment
|
Experiment
|
A single experiment object. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
Diffraction pattern calculated by the backend calculator. |
Source code in src/easydiffraction/analysis/calculation.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
|
calculate_structure_factors(sample_models, experiments)
Calculate HKL intensities (structure factors) for sample models and experiments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample_models
|
SampleModels
|
Collection of sample models. |
required |
experiments
|
Experiments
|
Collection of experiments. |
required |
Returns:
Type | Description |
---|---|
Optional[List[Any]]
|
HKL intensities calculated by the backend calculator. |
Source code in src/easydiffraction/analysis/calculation.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
|
set_calculator(engine)
Switch to a different calculator engine at runtime.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
engine
|
str
|
New calculation engine type to use. |
required |
Source code in src/easydiffraction/analysis/calculation.py
34 35 36 37 38 39 40 41 |
|
calculators
calculator_base
CalculatorBase
Bases: ABC
Base API for diffraction calculation engines.
Source code in src/easydiffraction/analysis/calculators/calculator_base.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
|
calculate_pattern(sample_models, experiment, called_by_minimizer=False)
Calculate the diffraction pattern for multiple sample models and a single experiment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample_models
|
SampleModels
|
Collection of sample models. |
required |
experiment
|
Experiment
|
The experiment object. |
required |
called_by_minimizer
|
bool
|
Whether the calculation is called by a minimizer. |
False
|
Returns:
Type | Description |
---|---|
ndarray
|
The calculated diffraction pattern as a NumPy array. |
Source code in src/easydiffraction/analysis/calculators/calculator_base.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
calculate_structure_factors(sample_model, experiment)
abstractmethod
Calculate structure factors for a single sample model and experiment.
Source code in src/easydiffraction/analysis/calculators/calculator_base.py
32 33 34 35 36 37 38 39 40 41 |
|
calculator_crysfml
CrysfmlCalculator
Bases: CalculatorBase
Wrapper for Crysfml library.
Source code in src/easydiffraction/analysis/calculators/calculator_crysfml.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
|
calculate_structure_factors(sample_models, experiments)
Call Crysfml to calculate structure factors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample_models
|
SampleModels
|
The sample models to calculate structure factors for. |
required |
experiments
|
Experiments
|
The experiments associated with the sample models. |
required |
Source code in src/easydiffraction/analysis/calculators/calculator_crysfml.py
38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
calculator_cryspy
CryspyCalculator
Bases: CalculatorBase
Cryspy-based diffraction calculator. Converts EasyDiffraction models into Cryspy objects and computes patterns.
Source code in src/easydiffraction/analysis/calculators/calculator_cryspy.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 |
|
calculate_structure_factors(sample_model, experiment)
Raises a NotImplementedError as HKL calculation is not implemented.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample_model
|
SampleModel
|
The sample model to calculate structure factors for. |
required |
experiment
|
Experiment
|
The experiment associated with the sample models. |
required |
Source code in src/easydiffraction/analysis/calculators/calculator_cryspy.py
46 47 48 49 50 51 52 53 54 55 56 57 58 |
|
calculator_pdffit
PdffitCalculator
Bases: CalculatorBase
Wrapper for Pdffit library.
Source code in src/easydiffraction/analysis/calculators/calculator_pdffit.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|
collections
joint_fit_experiments
JointFitExperiments
Bases: Collection
Collection manager for experiments that are fitted together
in a joint
fit.
Source code in src/easydiffraction/analysis/collections/joint_fit_experiments.py
43 44 45 46 47 48 49 50 51 52 53 54 55 |
|
minimization
DiffractionMinimizer
Handles the fitting workflow using a pluggable minimizer.
Source code in src/easydiffraction/analysis/minimization.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
|
fit(sample_models, experiments, calculator, weights=None)
Run the fitting process.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample_models
|
SampleModels
|
Collection of sample models. |
required |
experiments
|
Experiments
|
Collection of experiments. |
required |
calculator
|
Any
|
The calculator to use for pattern generation. |
required |
weights
|
Optional[array]
|
Optional weights for joint fitting. |
None
|
Source code in src/easydiffraction/analysis/minimization.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
|
minimizers
fitting_progress_tracker
FittingProgressTracker
Tracks and reports the reduced chi-square during the optimization process.
Source code in src/easydiffraction/analysis/minimizers/fitting_progress_tracker.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
|
track(residuals, parameters)
Track chi-square progress during the optimization process.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
residuals
|
ndarray
|
Array of residuals between measured and calculated data. |
required |
parameters
|
list
|
List of free parameters being fitted. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Residuals unchanged, for optimizer consumption. |
Source code in src/easydiffraction/analysis/minimizers/fitting_progress_tracker.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
|
minimizer_base
MinimizerBase
Bases: ABC
Abstract base class for minimizer implementations. Provides shared logic and structure for concrete minimizers.
Source code in src/easydiffraction/analysis/minimizers/minimizer_base.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
|
minimizer_dfols
DfolsMinimizer
Bases: MinimizerBase
Minimizer using the DFO-LS package (Derivative-Free Optimization for Least-Squares).
Source code in src/easydiffraction/analysis/minimizers/minimizer_dfols.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
|
minimizer_factory
MinimizerFactory
Source code in src/easydiffraction/analysis/minimizers/minimizer_factory.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
|
create_minimizer(selection)
classmethod
Create a minimizer instance based on the selection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
selection
|
str
|
The name of the minimizer to create. |
required |
Returns:
Type | Description |
---|---|
MinimizerBase
|
An instance of the selected minimizer. |
Raises:
Type | Description |
---|---|
ValueError
|
If the selection is not a valid minimizer. |
Source code in src/easydiffraction/analysis/minimizers/minimizer_factory.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
|
list_available_minimizers()
classmethod
List all available minimizers.
Returns:
Type | Description |
---|---|
List[str]
|
A list of minimizer names. |
Source code in src/easydiffraction/analysis/minimizers/minimizer_factory.py
46 47 48 49 50 51 52 53 54 |
|
register_minimizer(name, minimizer_cls, method=None, description='No description provided.')
classmethod
Register a new minimizer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the minimizer. |
required |
minimizer_cls
|
Type[MinimizerBase]
|
The class of the minimizer. |
required |
method
|
Optional[str]
|
The method used by the minimizer (optional). |
None
|
description
|
str
|
A description of the minimizer. |
'No description provided.'
|
Source code in src/easydiffraction/analysis/minimizers/minimizer_factory.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
|
show_available_minimizers()
classmethod
Display a table of available minimizers and their descriptions.
Source code in src/easydiffraction/analysis/minimizers/minimizer_factory.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
|
minimizer_lmfit
LmfitMinimizer
Bases: MinimizerBase
Minimizer using the lmfit package.
Source code in src/easydiffraction/analysis/minimizers/minimizer_lmfit.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
|
reliability_factors
calculate_r_factor(y_obs, y_calc)
Calculate the R-factor (reliability factor) between observed and calculated data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
y_obs
|
ndarray
|
Observed data points. |
required |
y_calc
|
ndarray
|
Calculated data points. |
required |
Returns:
Type | Description |
---|---|
float
|
R-factor value. |
Source code in src/easydiffraction/analysis/reliability_factors.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
calculate_r_factor_squared(y_obs, y_calc)
Calculate the R-factor squared between observed and calculated data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
y_obs
|
ndarray
|
Observed data points. |
required |
y_calc
|
ndarray
|
Calculated data points. |
required |
Returns:
Type | Description |
---|---|
float
|
R-factor squared value. |
Source code in src/easydiffraction/analysis/reliability_factors.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
calculate_rb_factor(y_obs, y_calc)
Calculate the Bragg R-factor between observed and calculated data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
y_obs
|
ndarray
|
Observed data points. |
required |
y_calc
|
ndarray
|
Calculated data points. |
required |
Returns:
Type | Description |
---|---|
float
|
Bragg R-factor value. |
Source code in src/easydiffraction/analysis/reliability_factors.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
|
calculate_reduced_chi_square(residuals, num_parameters)
Calculate the reduced chi-square statistic.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
residuals
|
ndarray
|
Residuals between observed and calculated data. |
required |
num_parameters
|
int
|
Number of free parameters used in the model. |
required |
Returns:
Type | Description |
---|---|
float
|
Reduced chi-square value. |
Source code in src/easydiffraction/analysis/reliability_factors.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
calculate_weighted_r_factor(y_obs, y_calc, weights)
Calculate the weighted R-factor between observed and calculated data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
y_obs
|
ndarray
|
Observed data points. |
required |
y_calc
|
ndarray
|
Calculated data points. |
required |
weights
|
ndarray
|
Weights for each data point. |
required |
Returns:
Type | Description |
---|---|
float
|
Weighted R-factor value. |
Source code in src/easydiffraction/analysis/reliability_factors.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
|
get_reliability_inputs(sample_models, experiments, calculator)
Collect observed and calculated data points for reliability calculations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample_models
|
SampleModels
|
Collection of sample models. |
required |
experiments
|
Experiments
|
Collection of experiments. |
required |
calculator
|
CalculatorBase
|
The calculator to use for pattern generation. |
required |
Returns:
Type | Description |
---|---|
Tuple[ndarray, ndarray, Optional[ndarray]]
|
Tuple containing arrays of (observed values, calculated values, error values) |
Source code in src/easydiffraction/analysis/reliability_factors.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
|