utils
formatting
chapter(title)
Formats a chapter header with bold magenta text, uppercase, and padding.
Source code in src/easydiffraction/utils/formatting.py
11 12 13 14 15 16 17 18 19 |
|
error(title)
Formats an error message with red text.
Source code in src/easydiffraction/utils/formatting.py
43 44 45 |
|
info(title)
Formats an info message with cyan text.
Source code in src/easydiffraction/utils/formatting.py
53 54 55 |
|
paragraph(title)
Formats a subsection header with bold blue text while keeping quoted text unformatted.
Source code in src/easydiffraction/utils/formatting.py
28 29 30 31 32 33 34 35 36 37 38 39 40 |
|
section(title)
Formats a section header with bold green text.
Source code in src/easydiffraction/utils/formatting.py
22 23 24 25 |
|
warning(title)
Formats a warning message with yellow text.
Source code in src/easydiffraction/utils/formatting.py
48 49 50 |
|
utils
General utilities and helpers for easydiffraction.
download_from_repository(file_name, branch=None, destination='data', overwrite=False)
Download a data file from the EasyDiffraction repository on GitHub.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_name
|
str
|
The file name to fetch (e.g., "NaCl.gr"). |
required |
branch
|
str | None
|
Branch to fetch from. If None, uses DATA_REPO_BRANCH. |
None
|
destination
|
str
|
Directory to save the file into (created if missing). |
'data'
|
overwrite
|
bool
|
Whether to overwrite the file if it already exists. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
None
|
None |
Source code in src/easydiffraction/utils/utils.py
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 |
|
fetch_tutorial_list()
Return a list of available tutorial notebook filenames from the GitHub release
that matches the installed version of easydiffraction
, if possible. If the
version-specific release is unavailable, falls back to the latest release.
This function does not fetch or display the tutorials themselves; it only lists the notebook filenames (e.g., '01-intro.ipynb', ...) found inside the 'tutorials.zip' asset of the appropriate GitHub release.
Returns:
Type | Description |
---|---|
list[str]
|
list[str]: A sorted list of tutorial notebook filenames (without directories) |
list[str]
|
extracted from the corresponding release's tutorials.zip, or an empty list |
list[str]
|
if unavailable. |
Source code in src/easydiffraction/utils/utils.py
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 |
|
fetch_tutorials()
Download and extract the tutorials ZIP archive from the GitHub release matching the
installed version of easydiffraction
, if available. If the version-specific release
is unavailable, falls back to the latest release.
The archive is extracted into the current working directory and then removed.
Returns:
Type | Description |
---|---|
None
|
None |
Source code in src/easydiffraction/utils/utils.py
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 |
|
get_value_from_xye_header(file_path, key)
Extracts a floating point value from the first line of the file, corresponding to the given key.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
str
|
Path to the input file. |
required |
key
|
str
|
The key to extract ('DIFC' or 'two_theta'). |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
The extracted value. |
Raises:
Type | Description |
---|---|
ValueError
|
If the key is not found. |
Source code in src/easydiffraction/utils/utils.py
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 |
|
is_colab()
Determines if the current environment is Google Colab.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if running in Google Colab PyCharm, False otherwise. |
Source code in src/easydiffraction/utils/utils.py
388 389 390 391 392 393 394 395 396 397 398 |
|
is_github_ci()
Determines if the current process is running in GitHub Actions CI.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the environment variable |
bool
|
(Always "true" on GitHub Actions), False otherwise. |
Source code in src/easydiffraction/utils/utils.py
401 402 403 404 405 406 407 408 409 |
|
is_notebook()
Determines if the current environment is a Jupyter Notebook.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if running inside a Jupyter Notebook, False otherwise. |
Source code in src/easydiffraction/utils/utils.py
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
|
is_pycharm()
Determines if the current environment is PyCharm.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if running inside PyCharm, False otherwise. |
Source code in src/easydiffraction/utils/utils.py
378 379 380 381 382 383 384 385 |
|
list_tutorials()
List available tutorial notebooks.
Returns:
Type | Description |
---|---|
None |
Source code in src/easydiffraction/utils/utils.py
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 |
|
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
|
str | None: The raw version string (may include local part, e.g., '1.2.3+abc123'), |
str | None
|
or None if the package is not installed. |
Source code in src/easydiffraction/utils/utils.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
|
render_cif(cif_text, paragraph_title)
Display the CIF text as a formatted table in Jupyter Notebook or terminal.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cif_text
|
The CIF text to display. |
required | |
paragraph_title
|
The title to print above the table. |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Source code in src/easydiffraction/utils/utils.py
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 |
|
render_table(columns_data, columns_alignment, columns_headers=None, show_index=False, display_handle=None)
Renders a table either as an HTML (in Jupyter Notebook) or ASCII (in terminal), with aligned columns.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
columns_data
|
list
|
List of lists, where each inner list represents a row of data. |
required |
columns_alignment
|
list
|
Corresponding text alignment for each column (e.g., 'left', 'center', 'right'). |
required |
columns_headers
|
list
|
List of column headers. |
None
|
show_index
|
bool
|
Whether to show the index column. |
False
|
display_handle
|
Optional display handle for updating in Jupyter. |
None
|
Returns:
Type | Description |
---|---|
None |
Source code in src/easydiffraction/utils/utils.py
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 |
|
show_version()
Print the installed version of the easydiffraction package.
Returns:
Type | Description |
---|---|
None
|
None |
Source code in src/easydiffraction/utils/utils.py
338 339 340 341 342 343 344 345 346 347 348 349 |
|
stripped_package_version(package_name)
Get the installed version of the specified package, stripped of any local version part.
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
|
str | None: The public version string, or None if the package is not installed. |
Source code in src/easydiffraction/utils/utils.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
|
tof_to_d(tof, offset, linear, quad, quad_eps=1e-20)
Convert time-of-flight (TOF) to d-spacing using a 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
|
np.ndarray: d-spacing values (Å), NaN where invalid. |
Raises:
Type | Description |
---|---|
TypeError
|
If |
Source code in src/easydiffraction/utils/utils.py
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 |
|
twotheta_to_d(twotheta, wavelength)
Convert 2-theta to d-spacing using Bragg's law.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
twotheta
|
float or ndarray
|
2-theta angle in degrees. |
required |
wavelength
|
float
|
Wavelength in Å. |
required |
Returns:
Name | Type | Description |
---|---|---|
d |
float or ndarray
|
d-spacing in Å. |
Source code in src/easydiffraction/utils/utils.py
621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 |
|