utils
enums
General-purpose enumerations shared across the library.
VerbosityEnum
Bases: str, Enum
Console output verbosity level.
Controls how much information is printed during operations such as data loading, fitting, and saving.
Members
FULL Multi-line output with headers, tables, and details. SHORT Single-line status messages per action. SILENT No console output.
Source code in src/easydiffraction/utils/enums.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | |
default()
classmethod
Return the default verbosity (FULL).
Source code in src/easydiffraction/utils/enums.py
27 28 29 30 | |
environment
can_update_ipython_display()
Return True if IPython HTML display utilities are available.
This indicates we can safely construct IPython.display.HTML and
update a display handle.
Source code in src/easydiffraction/utils/environment.py
146 147 148 149 150 151 152 153 154 155 156 157 158 | |
can_use_ipython_display(handle)
Return True if we can update the given IPython DisplayHandle.
Combines type checking of the handle with availability of IPython HTML utilities.
Source code in src/easydiffraction/utils/environment.py
161 162 163 164 165 166 167 168 169 170 171 | |
in_colab()
Check whether the current environment is Google Colab.
Returns:
| Type | Description |
|---|---|
bool
|
True if running in Google Colab, False otherwise. |
Source code in src/easydiffraction/utils/environment.py
48 49 50 51 52 53 54 55 56 57 58 59 60 | |
in_github_ci()
Return True when running under GitHub Actions CI.
Returns:
| Type | Description |
|---|---|
bool
|
True if env var |
Source code in src/easydiffraction/utils/environment.py
104 105 106 107 108 109 110 111 112 113 | |
in_jupyter()
Return True when running inside a Jupyter Notebook.
Returns:
| Type | Description |
|---|---|
bool
|
True if inside a Jupyter Notebook, False otherwise. |
Source code in src/easydiffraction/utils/environment.py
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 | |
in_pycharm()
Check whether the current environment is PyCharm.
Returns:
| Type | Description |
|---|---|
bool
|
True if running inside PyCharm, False otherwise. |
Source code in src/easydiffraction/utils/environment.py
36 37 38 39 40 41 42 43 44 45 | |
in_pytest()
Determine whether the code is running inside a pytest session.
Returns:
| Type | Description |
|---|---|
bool
|
True if pytest is loaded, False otherwise. |
Source code in src/easydiffraction/utils/environment.py
11 12 13 14 15 16 17 18 19 20 | |
in_warp()
Determine whether the terminal is the Warp terminal emulator.
Returns:
| Type | Description |
|---|---|
bool
|
True if the TERM_PROGRAM environment variable equals
|
Source code in src/easydiffraction/utils/environment.py
23 24 25 26 27 28 29 30 31 32 33 | |
is_ipython_display_handle(obj)
Return True if obj is an IPython DisplayHandle instance.
Tries to import IPython.display.DisplayHandle and uses
isinstance when available. Falls back to a conservative module
name heuristic if IPython is missing. Any errors result in
False.
Source code in src/easydiffraction/utils/environment.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
logging
Project-wide logging utilities built on top of Rich.
Provides a shared Rich console, a compact/verbose logger with consistent formatting, Jupyter traceback handling, and a small printing façade tailored to the configured console.
ConsoleManager
Central provider for shared Rich Console instance.
Source code in src/easydiffraction/utils/logging.py
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 | |
get()
classmethod
Return a shared Rich Console instance.
Source code in src/easydiffraction/utils/logging.py
137 138 139 140 141 142 143 144 145 | |
ConsolePrinter
Printer utility for the shared console with left padding.
Source code in src/easydiffraction/utils/logging.py
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 | |
chapter(title)
classmethod
Format a chapter header in bold magenta, uppercase.
Source code in src/easydiffraction/utils/logging.py
695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 | |
paragraph(title)
classmethod
Print a bold blue paragraph heading.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str
|
Heading text; substrings enclosed in single quotes are rendered without the bold-blue style. |
required |
Source code in src/easydiffraction/utils/logging.py
662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 | |
print(*objects, **kwargs)
classmethod
Print objects to the console with left padding.
- Renderables (Rich types like Text, Table, Panel, etc.) are kept as-is. - Non-renderables (ints, floats, Path, etc.) are converted to str().
Source code in src/easydiffraction/utils/logging.py
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 | |
section(title)
classmethod
Format a section header with bold green text.
Source code in src/easydiffraction/utils/logging.py
685 686 687 688 689 690 691 692 693 | |
ExceptionHookManager
Handles installation and restoration of exception hooks.
Source code in src/easydiffraction/utils/logging.py
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 | |
install_compact_hook(logger)
staticmethod
Install a compact exception hook that logs message-only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logger
|
Logger
|
Logger used to emit the error message. |
required |
Source code in src/easydiffraction/utils/logging.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |
install_jupyter_traceback_suppressor(logger)
staticmethod
Install a Jupyter/IPython exception handler for tracebacks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logger
|
Logger
|
Logger used to emit error messages. |
required |
Source code in src/easydiffraction/utils/logging.py
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 | |
install_verbose_hook(logger)
staticmethod
Install a verbose exception hook that prints rich tracebacks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logger
|
Logger
|
Logger used to emit the exception information. |
required |
Source code in src/easydiffraction/utils/logging.py
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 | |
restore_original_hook()
staticmethod
Restore the original sys.excepthook if it was overridden.
Source code in src/easydiffraction/utils/logging.py
301 302 303 304 305 | |
IconifiedRichHandler
Bases: RichHandler
RichHandler using icons (compact) or names (verbose).
Source code in src/easydiffraction/utils/logging.py
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 | |
get_level_text(record)
Return an icon or level name for the log record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
record
|
LogRecord
|
The log record being rendered. |
required |
Returns:
| Type | Description |
|---|---|
Text
|
A Rich Text object with the level indicator. |
Source code in src/easydiffraction/utils/logging.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
render_message(record, message)
Render the log message body as a Rich Text object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
record
|
LogRecord
|
The log record being rendered. |
required |
message
|
str
|
Pre-formatted log message string. |
required |
Returns:
| Type | Description |
|---|---|
Text
|
A Rich Text object with the rendered message. |
Source code in src/easydiffraction/utils/logging.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
Logger
Centralized logging with Rich formatting and two modes.
Environment variables: ED_LOG_MODE: set default mode ('verbose' or 'compact') ED_LOG_LEVEL: set default level ('DEBUG', 'INFO', etc.)
Source code in src/easydiffraction/utils/logging.py
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 | |
Level
Bases: IntEnum
Mirror stdlib logging levels.
Source code in src/easydiffraction/utils/logging.py
387 388 389 390 391 392 393 394 395 396 397 398 399 | |
default()
classmethod
Return the default log level (WARNING).
Source code in src/easydiffraction/utils/logging.py
396 397 398 399 | |
Mode
Bases: Enum
Output modes (see :class:Logger).
Source code in src/easydiffraction/utils/logging.py
376 377 378 379 380 381 382 383 384 385 | |
default()
classmethod
Return the default output mode (compact).
Source code in src/easydiffraction/utils/logging.py
382 383 384 385 | |
Reaction
Bases: Enum
Reaction to errors (see :class:Logger).
Source code in src/easydiffraction/utils/logging.py
401 402 403 404 405 406 407 408 409 410 | |
default()
classmethod
Return the default error reaction (RAISE).
Source code in src/easydiffraction/utils/logging.py
407 408 409 410 | |
configure(*, mode=None, level=None, reaction=None, rich_tracebacks=None)
classmethod
Configure logger.
mode: default COMPACT in Jupyter else VERBOSE level: minimum log level rich_tracebacks: override automatic choice
Environment variables: ED_LOG_MODE: set default mode ('verbose' or 'compact') ED_LOG_LEVEL: set default level ('DEBUG', 'INFO', etc.)
Source code in src/easydiffraction/utils/logging.py
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 | |
critical(*messages, exc_type=RuntimeError)
classmethod
Log one or more messages at CRITICAL level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*messages
|
str
|
Message parts joined with a space before logging. |
()
|
exc_type
|
type[BaseException]
|
Exception type to raise in VERBOSE/COMPACT mode. |
RuntimeError
|
Source code in src/easydiffraction/utils/logging.py
610 611 612 613 614 615 616 617 618 619 620 621 622 | |
debug(*messages)
classmethod
Log one or more messages at DEBUG level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*messages
|
str
|
Message parts joined with a space before logging. |
()
|
Source code in src/easydiffraction/utils/logging.py
558 559 560 561 562 563 564 565 566 567 568 | |
error(*messages, exc_type=AttributeError)
classmethod
Log one or more messages at ERROR level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*messages
|
str
|
Message parts joined with a space before logging. |
()
|
exc_type
|
type[BaseException]
|
Exception type to raise in VERBOSE/COMPACT mode. |
AttributeError
|
Source code in src/easydiffraction/utils/logging.py
596 597 598 599 600 601 602 603 604 605 606 607 608 | |
handle(*messages, level=Level.ERROR, exc_type=AttributeError)
classmethod
Route a log message (see class docs for policy).
Source code in src/easydiffraction/utils/logging.py
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 | |
info(*messages)
classmethod
Log one or more messages at INFO level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*messages
|
str
|
Message parts joined with a space before logging. |
()
|
Source code in src/easydiffraction/utils/logging.py
570 571 572 573 574 575 576 577 578 579 580 | |
mode()
classmethod
Return the currently active output mode.
Returns:
| Type | Description |
|---|---|
Mode
|
The current Logger.Mode value. |
Source code in src/easydiffraction/utils/logging.py
506 507 508 509 510 511 512 513 514 515 516 | |
set_level(level)
classmethod
Set the minimum log level and reconfigure the logger.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level
|
Level
|
The desired minimum log level. |
required |
Source code in src/easydiffraction/utils/logging.py
494 495 496 497 498 499 500 501 502 503 504 | |
set_mode(mode)
classmethod
Set the output mode and reconfigure the logger.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
Mode
|
The desired output mode (VERBOSE or COMPACT). |
required |
Source code in src/easydiffraction/utils/logging.py
482 483 484 485 486 487 488 489 490 491 492 | |
warning(*messages, exc_type=None)
classmethod
Log one or more messages at WARNING level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*messages
|
str
|
Message parts joined with a space before logging. |
()
|
exc_type
|
type[BaseException] | None
|
If provided, raise this exception type instead of logging. |
None
|
Source code in src/easydiffraction/utils/logging.py
582 583 584 585 586 587 588 589 590 591 592 593 594 | |
LoggerConfig
Facade for logger configuration, delegates to helpers.
Source code in src/easydiffraction/utils/logging.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 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 | |
configure(logger, *, mode, level, rich_tracebacks)
staticmethod
Configure the logger with RichHandler and exception hooks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logger
|
Logger
|
Logger instance to configure. |
required |
mode
|
'Logger.Mode'
|
Output mode (compact or verbose). |
required |
level
|
'Logger.Level'
|
Minimum log level to emit. |
required |
rich_tracebacks
|
bool
|
Whether to enable Rich tracebacks. |
required |
Source code in src/easydiffraction/utils/logging.py
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 | |
setup_handlers(logger, *, level, rich_tracebacks, mode='compact')
staticmethod
Install Rich handler and optional Jupyter traceback support.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logger
|
Logger
|
Logger instance to attach handlers to. |
required |
level
|
int
|
Minimum log level to emit. |
required |
rich_tracebacks
|
bool
|
Whether to enable Rich tracebacks. |
required |
mode
|
str
|
Output mode name ("compact" or "verbose"). |
'compact'
|
Source code in src/easydiffraction/utils/logging.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 198 199 200 201 | |
utils
download_all_tutorials(destination='tutorials', overwrite=False)
Download all available tutorial notebooks.
Example: paths = download_all_tutorials(destination="tutorials")
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
destination
|
str
|
Directory to save the files into (created if missing). |
'tutorials'
|
overwrite
|
bool
|
Whether to overwrite files if they already exist. |
False
|
Returns:
| Type | Description |
|---|---|
list[str]
|
List of full paths to the downloaded files. |
Source code in src/easydiffraction/utils/utils.py
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 | |
download_data(id, destination='data', overwrite=False)
Download a dataset by numeric ID using the remote diffraction index.
Example: path = download_data(id=12, destination="data")
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
int | str
|
Numeric dataset id (e.g. 12). |
required |
destination
|
str
|
Directory to save the file into (created if missing). |
'data'
|
overwrite
|
bool
|
Whether to overwrite the file if it already exists. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
Full path to the downloaded file as string. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the id is not found in the index. |
Source code in src/easydiffraction/utils/utils.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 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 | |
download_tutorial(id, destination='tutorials', overwrite=False)
Download a tutorial notebook by numeric ID.
Example: path = download_tutorial(id=1, destination="tutorials")
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
int | str
|
Numeric tutorial id (e.g. 1). |
required |
destination
|
str
|
Directory to save the file into (created if missing). |
'tutorials'
|
overwrite
|
bool
|
Whether to overwrite the file if it already exists. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
Full path to the downloaded file as string. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the id is not found in the index. |
Source code in src/easydiffraction/utils/utils.py
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 | |
list_tutorials()
Display a table of available tutorial notebooks.
Shows tutorial ID, filename and title for all tutorials available for the current version of easydiffraction.
Source code in src/easydiffraction/utils/utils.py
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 | |
package_version(package_name)
Get the installed version string of the specified package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package_name
|
str
|
The name of the package to query. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The raw version string (may include local part, e.g., '1.2.3+abc123'), or None if the package is not installed. |
Source code in src/easydiffraction/utils/utils.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |
render_cif(cif_text)
Display CIF text as a formatted table in Jupyter or terminal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cif_text
|
str
|
The CIF text to display. |
required |
Source code in src/easydiffraction/utils/utils.py
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 | |
render_table(columns_data, columns_alignment, columns_headers=None, display_handle=None)
Render tabular data to the active display backend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
columns_data
|
object
|
A list of rows, where each row is a list of cell values. |
required |
columns_alignment
|
object
|
A list of alignment strings (e.g. |
required |
columns_headers
|
object
|
Optional list of column header strings. |
None
|
display_handle
|
object
|
Optional display handle for in-place updates (e.g. in Jupyter or a terminal Live context). |
None
|
Source code in src/easydiffraction/utils/utils.py
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 | |
show_version()
Print the installed version of the easydiffraction package.
Source code in src/easydiffraction/utils/utils.py
495 496 497 498 | |
sin_theta_over_lambda_to_d_spacing(sin_theta_over_lambda)
Convert sin(theta)/lambda to d-spacing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sin_theta_over_lambda
|
object
|
sin(theta)/lambda in 1/Å (float or np.ndarray). |
required |
Returns:
| Type | Description |
|---|---|
object
|
d-spacing in Å (float or np.ndarray). |
Source code in src/easydiffraction/utils/utils.py
676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 | |
str_to_ufloat(s, default=None)
Parse a CIF-style numeric string into a ufloat.
Examples of supported input: - "3.566" → ufloat(3.566, nan) - "3.566(2)" → ufloat(3.566, 0.002) - None → ufloat(default, nan)
Behavior: - If the input string contains a value with parentheses
(e.g. "3.566(2)"), the number in parentheses is interpreted as an
estimated standard deviation (esd) in the last digit(s). - If the
input string has no parentheses, an uncertainty of NaN is assigned
to indicate "no esd provided". - If parsing fails, the function
falls back to the given default value with uncertainty NaN.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s
|
Optional[str]
|
Numeric string in CIF format (e.g. "3.566", "3.566(2)") or None. |
required |
default
|
Optional[float]
|
Default value to use if |
None
|
Returns:
| Type | Description |
|---|---|
UFloat
|
An |
Source code in src/easydiffraction/utils/utils.py
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 | |
stripped_package_version(package_name)
Get installed package version, stripped of local version parts.
Returns only the public version segment (e.g., '1.2.3' or '1.2.3.post4'), omitting any local segment (e.g., '+d136').
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package_name
|
str
|
The name of the package to query. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The public version string, or None if the package is not installed. |
Source code in src/easydiffraction/utils/utils.py
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 | |
tof_to_d(tof, offset, linear, quad, quad_eps=1e-20)
Convert time-of-flight to d-spacing using quadratic calibration.
Model: TOF = offset + linear * d + quad * d²
The function: - Uses a linear fallback when the quadratic term is
effectively zero. - Solves the quadratic for d and selects the
smallest positive, finite root. - Returns NaN where no valid
solution exists. - Expects tof as a NumPy array; output matches
its shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tof
|
ndarray
|
Time-of-flight values (µs). Must be a NumPy array. |
required |
offset
|
float
|
Calibration offset (µs). |
required |
linear
|
float
|
Linear calibration coefficient (µs/Å). |
required |
quad
|
float
|
Quadratic calibration coefficient (µs/Ų). |
required |
quad_eps
|
float
|
Threshold to treat |
1e-20
|
Returns:
| Type | Description |
|---|---|
ndarray
|
d-spacing values (Å), NaN where invalid. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Source code in src/easydiffraction/utils/utils.py
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 | |
twotheta_to_d(twotheta, wavelength)
Convert 2-theta to d-spacing using Bragg's law.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
twotheta
|
object
|
2-theta angle in degrees (float or np.ndarray). |
required |
wavelength
|
float
|
Wavelength in Å. |
required |
Returns:
| Type | Description |
|---|---|
object
|
d-spacing in Å (float or np.ndarray). |
Source code in src/easydiffraction/utils/utils.py
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 | |