API Reference
DataProposal
Bases: DataProposalBase
Source code in nx5d/repo/filesystem.py
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 | |
scan_url
property
Returns a URL pattern that contains {scan} or where the scan
info should go.
__init__(repo=None, key=None, url=None, glob=None, scan_class=None, **super_args)
Initializes a filesystem-based proposal walker.
Args:
repo: Repository object (parent)
key: Identifying information for this proposal
url: URL (format) of the proposal folder. Use the
{scan} format key to denote how the scan key
ties into the URL to produce scan URLs. The URL
may or may not have the specific proposal key
already baked into the URL. In any case, replacing
the format key {proposal} for the specified key
parameter will be attempted.
glob: globbing/search pattern for the scans, if different from "*".
scan_class: subclass to use for building scan objects
(typically a subclass of DataScanBase, or compatible).
Source code in nx5d/repo/filesystem.py
DataRepository
Bases: DataRepoBase
Source code in nx5d/repo/filesystem.py
__init__(*args, glob=None, **repo_kwargs)
Initializes an on-disk proposal manager.
| Parameters: |
|
|---|
Source code in nx5d/repo/filesystem.py
FsSpecGlobber
Produces globbing list using fsspec.
Source code in nx5d/repo/filesystem.py
LazyQMap
Bases: QMapper
QMapper subclass which accepts data at initialization time.
The idea is to follow up with a later call to a class
instance (i.e. use the .__call__() operator) to trigger a
Q-space mapping after some processing has been applied.
To do this, LazyQMap stores the data in an internal xarray.Dataset
of its own, the .xdata property.
The raw / authoritative data (i.e. XRD images) is additionally
accessed by the .data property, which behaves like a Python
dict(), while .angles gives access to the desginated angles
(goniometer and detector axes).
The .__init__() method requires at least the experimental setup
to be passed -- see documentation of .__init__() for details.
All of the computed data being lazily evaluated means that any
processing that must take place on the raw (i.e. untransformed)
data can -- and must -- take place before first access to any
of the q... properties. E.g. for intensity normalization, you
could do simething like: qmapper.xdata['img'] *= intensity and
only then proceed to accessing .__call__().
Source code in nx5d/xrd/signal.py
957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 | |
angles
property
dict-based access to all the "angles" fields (mimics old API).
data
property
dict-based access to all the "data" fields (mimics old API).
__call__(data_key, qsize=None, dims=None, _gridderDict=None, _ang2qDict=None)
Executes a Q-space mapping on the data_key array of the internal .xdata.
Args:
data_key: string with the data variable name to execute the mapping on
qsize: Grid size(s) for the resulting Q-space map. Unlike the base class's
`.qmap()` call, this supports only tuples of integers -- no dicts.
dims: Dimension names to control the mapping. This is a tuple of combintations
of "qx", "qy" and "qz".
_gridderDict: update the `.gridderDict` before the mapping (i.e. a dictionary
with extra parameters to pass to the gridder). This is strongly dependent
on the unterlying (xrayutilities) implementation.
_ang2qDict: update the `.ang2qDict` before the mapping (i.e. a dictionary
with extra parameters to pass to the angular converter).
This is strongly dependent on the unterlying (xrayutilities) implementation.
| an `xarray.Dataset` with detector data converted into Q-space, |
|
|---|
Source code in nx5d/xrd/signal.py
__init__(setup=None, **data)
Initializes the Q-mapper with default settings, data, or both.
Args:
setup: This is expected to be an experiment definition dictionary,
largely the same as the parameters of `QMapper.init_experiment()`.
Additionally, this dicttionary also accepts the following keys:
- `detectorTARAngles`: data for the tilt, azimuth and rotation angles.
Only required (and accepted) for angles that are defined as not `None`
in the `detectorTARAxes`. The parameter can be one of:
- A dictionary with angle name(s) as keys, and data array(s)
as values, for each of the directions: tilt, azimuth, and rotation.
Only directions with are marked with something different than `None`
in `detectorTARAxes` are accepted.
- A tuple of strings (keys) for the corresponding angle names, if
the angle data is not supplied separately but is instead included
in the `data` container.
- `goniometerAngles`: similarly to `detectorTARAngles`, this describes the
angles by which the goniometer can be positioned.
Can be one of:
- A dictionary with angle names as keys, and dara arrays as values,
from outer-most to inner-mot angle. *All* goniometer angles
named in `goniometerAxes` must be listed here.
- A tuple with strings, representing data-vars, if angles are
not supplied separatetly but within the `data` parameter itself.
Order is essential, it must be the same as the axis order in
`goniometerAxes`.
**data: This is a series of named parameters, each containing data
of the same length in the first dimension. This data can be either
detector images, angles, or any kind of additional data.
Source code in nx5d/xrd/signal.py
__make_dataset(**dsets)
Creates an xarray.Dataset of data sets within dsets.
The first dimension of all dsets is required to be the same.
This is introduced as the first dimension in the xarray dataset,
with the name "index".
Source code in nx5d/xrd/signal.py
QMapper
Base class for all Xrayutilities based Q-space mapper.
This essentially just initializes the experimental setup for xrayutilities and prepares for accepting "useful" data. The relevant Xrayutilities algorithm wrappers are also implemented here.
This is a fully functional implementation with a clean separation between static setup data (experiment geometry) and measurement data (angles and images). Subclasses may still implement more specific usage APIs.
Example
# Defining an experimental geometry. We put this in a dictionary
# for clarity, but we could just as well pass the parameters to
# QMapper(...) below one by one.
exp_setup = {
'beamDirection': (0, 1, 0),
'beamEnergy': 9600.0,
'imageAxes': ('x-', 'z-'),
'imageCenter': (90, 245),
'imageChannelSize': (0.172, 0.172),
'imageDistance': 720.0,
'imageSize': (195, 487),
'sampleFaceUp': 'z+',
'sampleNormal': (0, 0, 1)
# keys here will be used to find the angles in the xarray.Dataset
'goniometerAxes': {
'phi': 'x+',
'chi': 'y+',
'omega': 'z+'
},
# These last two keys of the detector axes will be ignored,
# because angle spec is None. Yet we still need to define them
# even if the detector doesn't have an Azimuth or Rotation axis.
'detectorTARAxes': {
'twotheta': 'x+',
'a': None,
'r': None
},
}
# We demonstrate the layout of an xarray Dataset suitable for Q-mapping.
# In a real example, instead of generating the data, we'd read it
# (e.g. from a HDF5 file)
raw_data = xarray.Dataset(
data_vars={
'chi': ('index', np.array(...)),
'phi': ('index', np.array(...)),
'omega': ('index', np.array(...)),
'twotheta': ('index', np.array(...)),
'pilatus': (('index', 'x', 'y'), np.array(...)),
},
coords={
'index': np.array(range(N)), # N is the number of images/angles here
'x': np.array(range(195)), # 195 is the image width, see exp_setup above
'y': np.array(range(487)) # 487 is the image height in pixels
})
# Defining the mapper
mapper = QMapper(**exp_setup)
# This is the most simple approach: call .qmap() and let it figure out
# useful defaults (which it will, given the Dataset above).
q_data = mapper.qmap(raw_data)
# Different approach: specify explicitly which image to transform...
q_data = mapper.qmap(raw_data, images="pilatus")
# ...or which angle sets to use...
q_data = mapper.qmap(raw_data, angles=("chi", "phi", "omega", "twotheta"))
# ...or both.
q_data = mapper.qmap(raw_data, angles=("chi", "phi", "omega", "twotheta"),
images="pilatus")
# Control Q-space grid size
q_data = mapper.qmap(raw_data, qsize=(100, 100, 200))
# Or reduce the number of dimensions (i.e. 2D Q-space map)
q_data = mapper.qmap(raw_data, dims=("qx", "qz"))
# Or both at the same time (using a dictionary for qsize instead of a tuple)
q_data = mapper.qmap(raw_data, qsize={"qx": 100, "qz": 200})
This will result e.g. in transforming a raw_data dataset like this:
>>> raw_data
<xarray.Dataset>
Dimensions: (index: 64, x: 195, y: 487)
Coordinates:
* index (index) int64 0 1 2 3 4 5 6 7 8 9 ... 55 56 57 58 59 60 61 62 63
* x (x) int64 0 1 2 3 4 5 6 7 8 ... 187 188 189 190 191 192 193 194
* y (y) int64 0 1 2 3 4 5 6 7 8 ... 479 480 481 482 483 484 485 486
Data variables:
phi (index) float64 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0
chi (index) float64 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0
theta (index) float64 12.0 12.01 12.02 12.03 ... 12.6 12.61 12.62 12.63
twotheta (index) float64 24.0 24.01 24.02 24.03 ... 24.6 24.61 24.62 24.63
pilatus (index, x, y) float64 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0
into something like this (in the default case):
>>> q_data
<xarray.DataArray (qy: 64, qx: 195, qz: 487)>
array([[[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.]]])
Coordinates:
* qy (qy) float64 -0.5787 -0.574 -0.5693 ... -0.293 -0.2883 -0.2836
* qx (qx) float64 -0.2423 -0.2409 -0.2395 ... 0.0337 0.03513 0.03657
* qz (qz) float64 1.72 1.721 1.722 1.723 ... 2.279 2.28 2.281 2.282
Source code in nx5d/xrd/signal.py
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 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 | |
__init__(**experiment_setup)
Initializes the experimental geometry.
The arguments to .__init__() are inspired from the xrayutitlities
Experiment classes, but they're intended to be fairly generic
and represent the actual physics, not a specific coded implementation
of it. They should be the same for all backends, even if different from
xrayutilities.
| Parameters: |
|
|---|
Source code in nx5d/xrd/signal.py
init_experiment(beamEnergy=None, beamDirection=None, goniometerAxes=None, detectorAxes=None, detectorTARAlign=None, imageAxes=None, imageCenter=None, imageChannelSize=None, imageChannelSpan=None, imageDistance=None, imageSize=None, sampleFaceUp=None, sampleNormal=None, roi=None)
Initializes the experiment setup representation.
This is typically an xrayutilities HXRD object or similar,
with specified device and sample geometry. The optional parameter roi
restricts angle-to-Q conversion to solely this region, if it is
specified. This is a good way to save significant amounts of computing
time.
Args:
beamEnergy: the energy of the incoming X-ray beam, in eV.
beamDirection: direction of the X-ray beam.
goniometerAxes: the direction of each of the goniometer axes,
in the [xyz][+-] notation. This is a variable-sized array, as there
can be several axes in any goniometer, and xrayutilities apparently
magically knows what to do.
This can hold an arbitrary number of angles, the only restriction
(according to xrayutilities docs)
being that these must be in from the outer to the inner rotations.
This can either be a simple enumerable (list or tuple), to specify
only the axis orientations; or this can be a dictionary, to also
specify the names in addition to the orientation.
detectorAxes: detector rotation axes, from outer to inner (similarly
to goniometerAxes).
imageAxes: the direction of the image axes (x and y) at zero angles. The positive direction of the axes should coincide with increasing pixel index in the data.
imageCenter: this is the position of the center pixel, either absolute
(integer pixel numbers), or relative to the sensor size (as specified in
imageAxes). If the number is in the range 0.0..1.0, then relative
positioning is assumed.
imageChannelSize: for Q transformation, ultimately the relation between every specific on the detectors and the angle of the incoming beam activating that specific pixel is needed. There are two distinct ways of specifying this: either using the "channel span", i.e. the size, in degrees, of each pixel, in horizontal/vertical direction, or by a distance parameter (from detector to sample) and a pixel size.
`imageChannelSpan` is either a single number or a 2-tuple specifying
how many degrees one channel takes. `imageChannelSize` specifies the
spatial size of a pixel relative to the distance between the sample
and the sensor.
imageChannelSpan: (overrides setup["imageChannelSpan"]),
see imgeChannelSize.
imageDistance: (overrides setup["imageDistance"]),
distance of the detector from the center of rotation.
imageSize: (overrides setup["imageSize"]), width and height of one detector
image.
sampleFaceUp: (overrides setup["sampleFaceUp"]),
direction of the "sample surface facing up", a.k.a.
"sampleor" (sample orientation) in xrayutilities lingo.
This is the orientation of
the sample surface at zero angles. This is either an axis notation
([xyz][+-]) or one of the special words det, respectively sam.
sampleNormal: (overrides setup["sampleNormal"]), not sure
what this is... in xrayutilities.
Returns: the internal representation of the experiment (typically an xrayutilities.Experiment instance, when xrayutilities is used as a backend). The internal representation is also stored within the object.
Source code in nx5d/xrd/signal.py
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 | |
qmap(xdata, images=None, angles=None, qsize=None, dims=None, retain=True, output=None, dask_compute=False)
Performs Q-space mapping on xdata.
The detector image data to map into Q-space (see images and xdata
parameters) must have the image same size as the imageSize parameter
that was passed to .__init__() of no region-of-interest (roi)
was specified. If a roi was specified to .__init__(), then
the image data must be the size of the roi, and the corresponding
pixel index must start with the lower numbers of the corresponding
roi dimension.
| Parameters: |
|
|---|
| an `xarray.Dataset` (or `DataArray`?) with the designated detector |
|
|---|
Source code in nx5d/xrd/signal.py
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 | |
qmap_groupby(data, groupby=None, combine=None, auto_compute=False, concat_params=None, *args, **kwargs)
Invokes the Q-space mapping on every member of a .groupby() result.
Think of this as a fancy xdata.groubpy(...).map(QMapper().qmap()) call.
The split-process-combine pattern of .groupby() is very powerful and
allows to write expressive data analysis code -- which we want. However,
combining results of .qmap() usually lead to unintended results, simply
because every single call comes with its own set of qx, qy and qz
coordinates.
Mostly, these are "the same" in the physical sense, but xarray doesn't
recognize them as the same because of minor numerical variations. To
combine them (and still have some failsafe / restored functionality when
they're actually not the same, just similar), we scale and transform the
coordinate vectors into integers after .qmap() invocation, but before
combining. Then after combination, we re-scale them back to their original
magnitude and transform them to float.
| Parameters: |
|
|---|
Source code in nx5d/xrd/signal.py
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 | |
qmap_single(xdata, *args, **kwargs)
Convenient wrapper for .qmap() to use when data only has a single image.
"Regular" .qmap() will choke, as it is expecting a batch of angular pixel
data, and a batch of angles. On single images, there's only one of each
(each angle, image etc), and there's no 3rd dimension.
The easy thing to do is simply extend xdata by an extra dimension. However,
one thing we also want to do is modify implicit settings for dims to
produce a 2D Q-map (since that's what the user will be expecting).
NOTE: deprecated, try using .groubpy(squeeze=False) instead.