analysis
Analysis
Bases: AnalysisBase
For analysing two-dimensional data, i.e. intensity as function of energy and Q.
Supports independent fits of each Q value and simultaneous fits of all Q.
Source code in src/easydynamics/analysis/analysis.py
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 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 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 | |
__init__(display_name='MyAnalysis', unique_name=None, experiment=None, sample_model=None, instrument_model=None, extra_parameters=None)
Initialize an Analysis object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
display_name
|
str | None, default='MyAnalysis'
|
Display name of the analysis. |
'MyAnalysis'
|
unique_name
|
str | None, default=None
|
Unique name of the analysis. If None, a unique name is automatically generated. |
None
|
experiment
|
Experiment | None, default=None
|
The Experiment associated with this Analysis. If None, a default Experiment is created. |
None
|
sample_model
|
SampleModel | None, default=None
|
The SampleModel associated with this Analysis. If None, a default SampleModel is created. |
None
|
instrument_model
|
InstrumentModel | None, default=None
|
The InstrumentModel associated with this Analysis. If None, a default InstrumentModel is created. |
None
|
extra_parameters
|
Parameter | list[Parameter] | None, default=None
|
Extra parameters to be included in the analysis for advanced users. If None, no extra parameters are added. |
None
|
Source code in src/easydynamics/analysis/analysis.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 | |
analysis_list
property
writable
Get the Analysis1d objects associated with this Analysis.
Returns:
| Type | Description |
|---|---|
list[Analysis1d]
|
list[Analysis1d]: A list of Analysis1d objects, one for each Q index. |
calculate(Q_index=None, energy=None)
Calculate model data for a specific Q index. If Q_index is None, calculate for all Q indices and return a list of arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None, default=None
|
Index of the Q value to calculate for. If None, calculate for all Q values. |
None
|
energy
|
sc.Variable | None, default=None
|
The energy values to use for calculating the model. If None, uses the energy from the experiment. |
None
|
Returns:
| Type | Description |
|---|---|
list[ndarray] | ndarray
|
list[np.ndarray] | np.ndarray: If Q_index is None, returns a list of numpy arrays, one for each Q index. If Q_index is an integer, returns a single numpy array for that Q index. |
Source code in src/easydynamics/analysis/analysis.py
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 | |
fit(fit_method='independent', Q_index=None)
Fit the model to the experimental data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fit_method
|
str, default="independent"
|
Method to use for fitting. Options are "independent" (fit each Q index independently, one after the other) or "simultaneous" (fit all Q indices simultaneously). Default is "independent". |
'independent'
|
Q_index
|
int | None, default=None
|
If fit_method is "independent", specify which Q index to fit. If None, fit all Q indices independently. Ignored if fit_method is "simultaneous". Default is None. |
None
|
Returns:
| Type | Description |
|---|---|
FitResults | list[FitResults]
|
FitResults | list[FitResults]: a list of FitResults if fitting independently, or a single FitResults object if fitting simultaneously. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If fit_method is not "independent" or "simultaneous" or if there are no Q values available for fitting. |
Source code in src/easydynamics/analysis/analysis.py
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 | |
get_fit_functions()
Get fit functions for all Q indices, which can be used for simultaneous fitting.
Returns:
| Type | Description |
|---|---|
list[callable]
|
list[callable]: A list of fit functions, one for each Q index. |
Source code in src/easydynamics/analysis/analysis.py
524 525 526 527 528 529 530 531 532 | |
parameters_to_dataset()
Creates a scipp dataset with copies of the Parameters in the model.
Ensures unit consistency across Q.
Returns:
| Type | Description |
|---|---|
Dataset
|
sc.Dataset: A dataset where each entry is a parameter, with dimensions "Q" and values corresponding to the parameter values. |
Raises:
| Type | Description |
|---|---|
UnitError
|
If there are inconsistent units for the same parameter across different Q values. |
Source code in src/easydynamics/analysis/analysis.py
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 | |
plot_data_and_model(Q_index=None, plot_components=True, add_background=True, energy=None, **kwargs)
Plot the experimental data and the model prediction. Optionally also plot the individual components of the model.
Uses Plopp for plotting: https://scipp.github.io/plopp/
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None, default=None
|
Index of the Q value to plot. If None, plot all Q values. Default is None. |
None
|
plot_components
|
bool, default=True
|
Whether to plot the individual components. Default is True. |
True
|
add_background
|
bool, default=True
|
Whether to add background components to the sample model components when plotting. Default is True. |
True
|
energy
|
sc.Variable | None, default=None
|
The energy values to use for calculating the model. If None, uses the energy from the experiment. |
None
|
**kwargs
|
dict[str, Any]
|
Additional keyword arguments passed to plopp for customizing the plot. |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If Q_index is out of bounds, or if there is no data to plot, or if there are no Q values available for plotting. |
RuntimeError
|
If not in a Jupyter notebook environment. |
TypeError
|
If plot_components or add_background is not True or False. |
Returns:
| Name | Type | Description |
|---|---|---|
InteractiveFigure |
InteractiveFigure
|
A Plopp InteractiveFigure containing the plot of the data and model. |
Source code in src/easydynamics/analysis/analysis.py
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 | |
plot_parameters(names=None, **kwargs)
Plot fitted parameters as a function of Q.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
names
|
str | list[str] | None, default=None
|
Name(s) of the parameter(s) to plot. If None, plots all parameters. |
None
|
**kwargs
|
dict[str, Any]
|
Additional keyword arguments passed to plopp.slicer for customizing the plot (e.g., title, linestyle, marker, color). |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
InteractiveFigure |
InteractiveFigure
|
A Plopp InteractiveFigure containing the plot of the parameters. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If names is not a string, list of strings, or None. |
ValueError
|
If any of the specified parameter names are not found in the dataset. |
Source code in src/easydynamics/analysis/analysis.py
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 | |
analysis
Analysis
Bases: AnalysisBase
For analysing two-dimensional data, i.e. intensity as function of energy and Q.
Supports independent fits of each Q value and simultaneous fits of all Q.
Source code in src/easydynamics/analysis/analysis.py
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 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 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 | |
__init__(display_name='MyAnalysis', unique_name=None, experiment=None, sample_model=None, instrument_model=None, extra_parameters=None)
Initialize an Analysis object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
display_name
|
str | None, default='MyAnalysis'
|
Display name of the analysis. |
'MyAnalysis'
|
unique_name
|
str | None, default=None
|
Unique name of the analysis. If None, a unique name is automatically generated. |
None
|
experiment
|
Experiment | None, default=None
|
The Experiment associated with this Analysis. If None, a default Experiment is created. |
None
|
sample_model
|
SampleModel | None, default=None
|
The SampleModel associated with this Analysis. If None, a default SampleModel is created. |
None
|
instrument_model
|
InstrumentModel | None, default=None
|
The InstrumentModel associated with this Analysis. If None, a default InstrumentModel is created. |
None
|
extra_parameters
|
Parameter | list[Parameter] | None, default=None
|
Extra parameters to be included in the analysis for advanced users. If None, no extra parameters are added. |
None
|
Source code in src/easydynamics/analysis/analysis.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 | |
analysis_list
property
writable
Get the Analysis1d objects associated with this Analysis.
Returns:
| Type | Description |
|---|---|
list[Analysis1d]
|
list[Analysis1d]: A list of Analysis1d objects, one for each Q index. |
calculate(Q_index=None, energy=None)
Calculate model data for a specific Q index. If Q_index is None, calculate for all Q indices and return a list of arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None, default=None
|
Index of the Q value to calculate for. If None, calculate for all Q values. |
None
|
energy
|
sc.Variable | None, default=None
|
The energy values to use for calculating the model. If None, uses the energy from the experiment. |
None
|
Returns:
| Type | Description |
|---|---|
list[ndarray] | ndarray
|
list[np.ndarray] | np.ndarray: If Q_index is None, returns a list of numpy arrays, one for each Q index. If Q_index is an integer, returns a single numpy array for that Q index. |
Source code in src/easydynamics/analysis/analysis.py
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 | |
fit(fit_method='independent', Q_index=None)
Fit the model to the experimental data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fit_method
|
str, default="independent"
|
Method to use for fitting. Options are "independent" (fit each Q index independently, one after the other) or "simultaneous" (fit all Q indices simultaneously). Default is "independent". |
'independent'
|
Q_index
|
int | None, default=None
|
If fit_method is "independent", specify which Q index to fit. If None, fit all Q indices independently. Ignored if fit_method is "simultaneous". Default is None. |
None
|
Returns:
| Type | Description |
|---|---|
FitResults | list[FitResults]
|
FitResults | list[FitResults]: a list of FitResults if fitting independently, or a single FitResults object if fitting simultaneously. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If fit_method is not "independent" or "simultaneous" or if there are no Q values available for fitting. |
Source code in src/easydynamics/analysis/analysis.py
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 | |
get_fit_functions()
Get fit functions for all Q indices, which can be used for simultaneous fitting.
Returns:
| Type | Description |
|---|---|
list[callable]
|
list[callable]: A list of fit functions, one for each Q index. |
Source code in src/easydynamics/analysis/analysis.py
524 525 526 527 528 529 530 531 532 | |
parameters_to_dataset()
Creates a scipp dataset with copies of the Parameters in the model.
Ensures unit consistency across Q.
Returns:
| Type | Description |
|---|---|
Dataset
|
sc.Dataset: A dataset where each entry is a parameter, with dimensions "Q" and values corresponding to the parameter values. |
Raises:
| Type | Description |
|---|---|
UnitError
|
If there are inconsistent units for the same parameter across different Q values. |
Source code in src/easydynamics/analysis/analysis.py
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 | |
plot_data_and_model(Q_index=None, plot_components=True, add_background=True, energy=None, **kwargs)
Plot the experimental data and the model prediction. Optionally also plot the individual components of the model.
Uses Plopp for plotting: https://scipp.github.io/plopp/
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_index
|
int | None, default=None
|
Index of the Q value to plot. If None, plot all Q values. Default is None. |
None
|
plot_components
|
bool, default=True
|
Whether to plot the individual components. Default is True. |
True
|
add_background
|
bool, default=True
|
Whether to add background components to the sample model components when plotting. Default is True. |
True
|
energy
|
sc.Variable | None, default=None
|
The energy values to use for calculating the model. If None, uses the energy from the experiment. |
None
|
**kwargs
|
dict[str, Any]
|
Additional keyword arguments passed to plopp for customizing the plot. |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If Q_index is out of bounds, or if there is no data to plot, or if there are no Q values available for plotting. |
RuntimeError
|
If not in a Jupyter notebook environment. |
TypeError
|
If plot_components or add_background is not True or False. |
Returns:
| Name | Type | Description |
|---|---|---|
InteractiveFigure |
InteractiveFigure
|
A Plopp InteractiveFigure containing the plot of the data and model. |
Source code in src/easydynamics/analysis/analysis.py
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 | |
plot_parameters(names=None, **kwargs)
Plot fitted parameters as a function of Q.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
names
|
str | list[str] | None, default=None
|
Name(s) of the parameter(s) to plot. If None, plots all parameters. |
None
|
**kwargs
|
dict[str, Any]
|
Additional keyword arguments passed to plopp.slicer for customizing the plot (e.g., title, linestyle, marker, color). |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
InteractiveFigure |
InteractiveFigure
|
A Plopp InteractiveFigure containing the plot of the parameters. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If names is not a string, list of strings, or None. |
ValueError
|
If any of the specified parameter names are not found in the dataset. |
Source code in src/easydynamics/analysis/analysis.py
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 | |
analysis1d
Analysis1d
Bases: AnalysisBase
For analysing one-dimensional data, i.e. intensity as function of energy for a single Q index.
Is used primarily in the Analysis class, but can also be used on its own for simpler analyses.
Source code in src/easydynamics/analysis/analysis1d.py
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 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 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 | |
Q_index
property
writable
Get the Q index associated with this Analysis.
Returns:
| Type | Description |
|---|---|
int | None
|
int | None: The Q index associated with this Analysis. |
__init__(display_name='MyAnalysis', unique_name=None, experiment=None, sample_model=None, instrument_model=None, Q_index=None, extra_parameters=None)
Initialize a Analysis1d.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
display_name
|
str | None, default='MyAnalysis'
|
Display name of the analysis. |
'MyAnalysis'
|
unique_name
|
str | None, default=None
|
Unique name of the analysis. If None, a unique name is automatically generated. |
None
|
experiment
|
Experiment | None, default=None
|
The Experiment associated with this Analysis. If None, a default Experiment is created. |
None
|
sample_model
|
SampleModel | None, default=None
|
The SampleModel associated with this Analysis. If None, a default SampleModel is created. |
None
|
instrument_model
|
InstrumentModel | None, default=None
|
The InstrumentModel associated with this Analysis. If None, a default InstrumentModel is created. |
None
|
Q_index
|
int | None, default=None
|
The Q index to analyze. If None, the analysis will not be able to calculate or fit until a Q index is set. |
None
|
extra_parameters
|
Parameter | list[Parameter] | None, default=None
|
Extra parameters to be included in the analysis for advanced users. If None, no extra parameters are added. |
None
|
Source code in src/easydynamics/analysis/analysis1d.py
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 | |
as_fit_function(x=None, **kwargs)
Return self._calculate as a fit function.
The EasyScience fitter requires x as input, but self._calculate() already uses the correct energy from the experiment. So we ignore the x input and just return the calculated model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
np.ndarray | sc.Variable | None, default=None
|
Ignored. The energy grid is taken from the experiment. |
None
|
**kwargs
|
dict[str, Any]
|
Ignored. Included for compatibility with the EasyScience fitter. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
callable |
callable
|
A function that can be used as a fit function in the EasyScience fitter, which returns the calculated model. |
Source code in src/easydynamics/analysis/analysis1d.py
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 | |
calculate(energy=None)
Calculate the model prediction for the chosen Q index. Makes sure the convolver is up to date before calculating.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
energy
|
sc.Variable | None, default=None
|
Optional energy grid to use for calculation. If None, the energy grid from the experiment is used. |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: The calculated model prediction. |
Source code in src/easydynamics/analysis/analysis1d.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
fit()
Fit the model to the experimental data for the chosen Q index.
The energy grid is fixed for the duration of the fit. Convolution objects are created once and reused during parameter optimization for performance reasons.
Returns:
| Name | Type | Description |
|---|---|---|
FitResults |
FitResults
|
The result of the fit. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no experiment is associated with this Analysis. |
Source code in src/easydynamics/analysis/analysis1d.py
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 | |
get_all_variables()
Get all variables used in the analysis.
Returns:
| Type | Description |
|---|---|
list[DescriptorNumber]
|
list[DescriptorNumber]: A list of all variables. |
Source code in src/easydynamics/analysis/analysis1d.py
217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |
plot_data_and_model(plot_components=True, add_background=True, energy=None, **kwargs)
Plot the experimental data and the model prediction for the chosen Q index. Optionally also plot the individual components of the model.
Uses Plopp for plotting: https://scipp.github.io/plopp/
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plot_components
|
bool, default=True
|
Whether to plot the individual components of the model. |
True
|
add_background
|
bool, default=True
|
Whether to add the background to the model prediction when plotting individual components. |
True
|
energy
|
sc.Variable | None, default=None
|
Optional energy grid to use for plotting. If None, the energy grid from the experiment is used. |
None
|
**kwargs
|
dict[str, Any]
|
Keyword arguments to pass to the plotting function. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
InteractiveFigure |
InteractiveFigure
|
A plot of the data and model. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no data is available to plot. |
Source code in src/easydynamics/analysis/analysis1d.py
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 | |
analysis_base
AnalysisBase
Bases: ModelBase
Base class for analysis in EasyDynamics. This class is not meant to be used directly.
An Analysis consists of an Experiment, a SampleModel, and an InstrumentModel. The Experiment contains the data to be fitted, the SampleModel contains the model for the sample, and the InstrumentModel contains the model for the instrument, including background and resolution
Source code in src/easydynamics/analysis/analysis_base.py
14 15 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 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 | |
Q
property
writable
Get the Q values from the associated Experiment, if available.
Returns:
| Type | Description |
|---|---|
Variable | None
|
sc.Variable | None: The Q values from the associated Experiment, if available, and None if not. |
__init__(display_name='MyAnalysis', unique_name=None, experiment=None, sample_model=None, instrument_model=None, extra_parameters=None)
Initialize the AnalysisBase.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
display_name
|
str | None, default='MyAnalysis'
|
Display name of the analysis. |
'MyAnalysis'
|
unique_name
|
str | None, default=None
|
Unique name of the analysis. If None, a unique name is automatically generated. |
None
|
experiment
|
Experiment | None, default=None
|
The Experiment associated with this Analysis. If None, a default Experiment is created. |
None
|
sample_model
|
SampleModel | None, default=None
|
The SampleModel associated with this Analysis. If None, a default SampleModel is created. |
None
|
instrument_model
|
InstrumentModel | None, default=None
|
The InstrumentModel associated with this Analysis. If None, a default InstrumentModel is created. |
None
|
extra_parameters
|
Parameter | list[Parameter] | None, default=None
|
Extra parameters to be included in the analysis for advanced users. If None, no extra parameters are added. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If experiment is not an Experiment or None or if sample_model is not a SampleModel or None or if instrument_model is not an InstrumentModel or None or if extra_parameters is not a Parameter, a list of Parameters, or None. |
Source code in src/easydynamics/analysis/analysis_base.py
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 | |
__repr__()
Return a string representation of the Analysis.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A string representation of the Analysis. |
Source code in src/easydynamics/analysis/analysis_base.py
341 342 343 344 345 346 347 348 | |
energy
property
writable
Get the energy values from the associated Experiment, if available.
Returns:
| Type | Description |
|---|---|
Variable | None
|
sc.Variable | None: The energy values from the associated |
Variable | None
|
Experiment, if available, and None if not. |
experiment
property
writable
Get the Experiment associated with this Analysis.
Returns:
| Name | Type | Description |
|---|---|---|
Experiment |
Experiment
|
The Experiment associated with this Analysis. |
extra_parameters
property
writable
Get the extra parameters included in this Analysis.
Returns:
| Type | Description |
|---|---|
list[Parameter]
|
list[Parameter]: The extra parameters included in this Analysis. |
instrument_model
property
writable
Get the InstrumentModel associated with this Analysis.
Returns:
| Name | Type | Description |
|---|---|---|
InstrumentModel |
InstrumentModel
|
The InstrumentModel associated with this Analysis. |
sample_model
property
writable
Get the SampleModel associated with this Analysis.
Returns:
| Name | Type | Description |
|---|---|---|
SampleModel |
SampleModel
|
The SampleModel associated with this Analysis. |
temperature
property
writable
Get the temperature from the associated SampleModel, if available.
Returns:
| Type | Description |
|---|---|
Parameter | None
|
Parameter | None: The temperature from the associated SampleModel, |
Parameter | None
|
if available, and None if not. |