POWGEN data reduction#

Introduction#

This notebook gives a concise overview of how to use the ESSDiffraction package with Sciline. It uses a simple reduction workflow for the SNS POWGEN experiment.

We begin with relevant imports. We will be using tutorial data downloaded with pooch. If you get an error about a missing module pooch, you can install it with !pip install pooch:

[1]:
import scipp as sc
import scippneutron as scn
import scippneutron.io

from ess import powder
from ess.snspowder import powgen
import ess.snspowder.powgen.data  # noqa: F401
from ess.powder.types import *

Create and configure the workflow#

We begin by creating the Powgen workflow object which is a skeleton for reducing Powgen data, with pre-configured steps.

[2]:
workflow = powgen.PowgenWorkflow()

We then need to set the missing parameters which are specific to each experiment (the keys are types defined in essdiffraction.powder.types):

[3]:
workflow[Filename[SampleRun]] = powgen.data.powgen_tutorial_sample_file()
workflow[Filename[VanadiumRun]] = powgen.data.powgen_tutorial_vanadium_file()
workflow[CalibrationFilename] = powgen.data.powgen_tutorial_calibration_file()
# The upper bounds mode is not yet implemented.
workflow[UncertaintyBroadcastMode] = UncertaintyBroadcastMode.drop
# Edges for binning in d-spacing
workflow[DspacingBins] = sc.linspace("dspacing", 0.0, 2.3434, 201, unit="angstrom")
# Mask in time-of-flight to crop to valid range
workflow[TofMask] = lambda x: (x < sc.scalar(0.0, unit="us")) | (
    x > sc.scalar(16666.67, unit="us")
)
workflow[TwoThetaMask] = None
workflow[WavelengthMask] = None
# No pixel masks
workflow = powder.with_pixel_mask_filenames(workflow, [])
Downloading file 'PG3_4844_event.zip' from 'https://public.esss.dk/groups/scipp/ess/powgen/1/PG3_4844_event.zip' to '/home/runner/.cache/ess/powgen/1'.
Unzipping contents of '/home/runner/.cache/ess/powgen/1/PG3_4844_event.zip' to '/home/runner/.cache/ess/powgen/1/PG3_4844_event.zip.unzip'
Downloading file 'PG3_4866_event.zip' from 'https://public.esss.dk/groups/scipp/ess/powgen/1/PG3_4866_event.zip' to '/home/runner/.cache/ess/powgen/1'.
Unzipping contents of '/home/runner/.cache/ess/powgen/1/PG3_4866_event.zip' to '/home/runner/.cache/ess/powgen/1/PG3_4866_event.zip.unzip'
Downloading file 'PG3_FERNS_d4832_2011_08_24_spectrum.h5' from 'https://public.esss.dk/groups/scipp/ess/powgen/1/PG3_FERNS_d4832_2011_08_24_spectrum.h5' to '/home/runner/.cache/ess/powgen/1'.

Use the workflow#

Compute final result#

We can get the graph for computing the final intensity as a function of d-spacing:

[4]:
IofDspacing in workflow.get(IofDspacing).keys()
[4]:
True
[5]:
workflow.visualize(IofDspacing, graph_attr={"rankdir": "LR"})
[5]:
../../_images/user-guide_sns-instruments_POWGEN_data_reduction_8_0.svg

Now we compute the result:

[6]:
result = workflow.compute(IofDspacing)
result
[6]:
Show/Hide data repr Show/Hide attributes
scipp.DataArray (427.42 MB)
    • dspacing: 200
    • dspacing
      (dspacing [bin-edge])
      float64
      Å
      0.0, 0.012, ..., 2.332, 2.343
      Values:
      array([0. , 0.011717, 0.023434, 0.035151, 0.046868, 0.058585, 0.070302, 0.082019, 0.093736, 0.105453, 0.11717 , 0.128887, 0.140604, 0.152321, 0.164038, 0.175755, 0.187472, 0.199189, 0.210906, 0.222623, 0.23434 , 0.246057, 0.257774, 0.269491, 0.281208, 0.292925, 0.304642, 0.316359, 0.328076, 0.339793, 0.35151 , 0.363227, 0.374944, 0.386661, 0.398378, 0.410095, 0.421812, 0.433529, 0.445246, 0.456963, 0.46868 , 0.480397, 0.492114, 0.503831, 0.515548, 0.527265, 0.538982, 0.550699, 0.562416, 0.574133, 0.58585 , 0.597567, 0.609284, 0.621001, 0.632718, 0.644435, 0.656152, 0.667869, 0.679586, 0.691303, 0.70302 , 0.714737, 0.726454, 0.738171, 0.749888, 0.761605, 0.773322, 0.785039, 0.796756, 0.808473, 0.82019 , 0.831907, 0.843624, 0.855341, 0.867058, 0.878775, 0.890492, 0.902209, 0.913926, 0.925643, 0.93736 , 0.949077, 0.960794, 0.972511, 0.984228, 0.995945, 1.007662, 1.019379, 1.031096, 1.042813, 1.05453 , 1.066247, 1.077964, 1.089681, 1.101398, 1.113115, 1.124832, 1.136549, 1.148266, 1.159983, 1.1717 , 1.183417, 1.195134, 1.206851, 1.218568, 1.230285, 1.242002, 1.253719, 1.265436, 1.277153, 1.28887 , 1.300587, 1.312304, 1.324021, 1.335738, 1.347455, 1.359172, 1.370889, 1.382606, 1.394323, 1.40604 , 1.417757, 1.429474, 1.441191, 1.452908, 1.464625, 1.476342, 1.488059, 1.499776, 1.511493, 1.52321 , 1.534927, 1.546644, 1.558361, 1.570078, 1.581795, 1.593512, 1.605229, 1.616946, 1.628663, 1.64038 , 1.652097, 1.663814, 1.675531, 1.687248, 1.698965, 1.710682, 1.722399, 1.734116, 1.745833, 1.75755 , 1.769267, 1.780984, 1.792701, 1.804418, 1.816135, 1.827852, 1.839569, 1.851286, 1.863003, 1.87472 , 1.886437, 1.898154, 1.909871, 1.921588, 1.933305, 1.945022, 1.956739, 1.968456, 1.980173, 1.99189 , 2.003607, 2.015324, 2.027041, 2.038758, 2.050475, 2.062192, 2.073909, 2.085626, 2.097343, 2.10906 , 2.120777, 2.132494, 2.144211, 2.155928, 2.167645, 2.179362, 2.191079, 2.202796, 2.214513, 2.22623 , 2.237947, 2.249664, 2.261381, 2.273098, 2.284815, 2.296532, 2.308249, 2.319966, 2.331683, 2.3434 ])
    • sample_position
      ()
      vector3
      m
      [0. 0. 0.]
      Values:
      array([0., 0., 0.])
    • source_position
      ()
      vector3
      m
      [ 0. 0. -60.]
      Values:
      array([ 0., 0., -60.])
    • (dspacing)
      DataArrayView
      binned data [len=36800, len=34844, ..., len=3, len=3]
      dim='event',
      content=DataArray(
                dims=(event: 17926980),
                data=float64[dimensionless],
                coords={'dspacing':float64[Å]},
                masks={'tof':bool})
[7]:
dspacing_histogram = result.hist()
dspacing_histogram.plot()
[7]:
../../_images/user-guide_sns-instruments_POWGEN_data_reduction_11_0.svg

Save reduced data to file#

We ultimately need to write the reduced data to a file. This could be done with the result we computed above. But we can use the workflow to provide additional parameters (in this case only the file name) as shown below. See also the File output docs of Sciline.

For simplicity we write a simply xye file with 3 columns: \(d\)-spacing, intensity, standard deviation of intensity.

[8]:
def save_xye(
    reduced_data: IofDspacing,
    out_filename: OutFilename,
) -> None:
    data = reduced_data.hist()
    data.coords["dspacing"] = sc.midpoints(data.coords["dspacing"])
    scn.io.save_xye(out_filename, data, coord="dspacing")

Insert a new parameter to set the file name. This could have been done at the top where the other parameters are defined.

[9]:
workflow[OutFilename] = "reduced.xye"

And use the workflow to write the file. Note that this recomputes the result!

[10]:
workflow.bind_and_call(save_xye)

Compute intermediate results#

For inspection and debugging purposes, we can also compute intermediate results. To avoid repeated computation (including costly loading of files), we can request multiple results at once, including the final result, if desired. For example:

[11]:
results = workflow.compute(
    (
        DetectorData[SampleRun],
        MaskedData[SampleRun],
        FilteredData[SampleRun],
        FilteredData[VanadiumRun],
    )
)
[12]:
results[DetectorData[SampleRun]]
[12]:
Show/Hide data repr Show/Hide attributes
scipp.DataArray (274.59 MB)
    • bank: 23
    • column: 154
    • row: 7
    • gd_prtn_chrg
      ()
      float64
      µAh
      1171.953902925
      Values:
      array(1171.95390292)
    • position
      (bank, column, row)
      vector3
      m
      [ 1.17451004 -1.01106149 -2.03796699], [ 1.18147634 -0.95946649 -2.05334117], ..., [1.81428985 0.09565841 3.84338287], [1.81375055 0.1499371 3.84269584]
      Values:
      array([[[[ 1.17451004, -1.01106149, -2.03796699], [ 1.18147634, -0.95946649, -2.05334117], [ 1.18844265, -0.90787149, -2.06871534], ..., [ 1.20237525, -0.80468148, -2.09946369], [ 1.20934156, -0.75308648, -2.11483787], [ 1.21630786, -0.70149148, -2.13021204]], [[ 1.17907562, -1.01107051, -2.03592852], [ 1.18604193, -0.95947551, -2.05130269], [ 1.19300823, -0.90788051, -2.06667687], ..., [ 1.20694084, -0.8046905 , -2.09742522], [ 1.21390714, -0.7530955 , -2.11279939], [ 1.22087344, -0.7015005 , -2.12817357]], [[ 1.18364121, -1.01107953, -2.03389005], [ 1.19060751, -0.95948453, -2.04926422], [ 1.19757381, -0.90788953, -2.06463839], ..., [ 1.21150642, -0.80469952, -2.09538674], [ 1.21847272, -0.75310452, -2.11076092], [ 1.22543903, -0.70150952, -2.12613509]], ..., [[ 1.86391297, -1.01242348, -1.73015741], [ 1.87087928, -0.96082848, -1.74553158], [ 1.87784558, -0.90923348, -1.76090576], ..., [ 1.89177819, -0.80604347, -1.79165411], [ 1.89874449, -0.75444847, -1.80702828], [ 1.90571079, -0.70285347, -1.82240245]], [[ 1.86847856, -1.0124325 , -1.72811893], [ 1.87544486, -0.9608375 , -1.74349311], [ 1.88241116, -0.9092425 , -1.75886728], ..., [ 1.89634377, -0.80605249, -1.78961563], [ 1.90331007, -0.75445749, -1.80498981], [ 1.91027638, -0.70286249, -1.82036398]], [[ 1.87304414, -1.01244152, -1.72608046], [ 1.88001044, -0.96084652, -1.74145463], [ 1.88697675, -0.90925152, -1.75682881], ..., [ 1.90090935, -0.80606151, -1.78757716], [ 1.90787566, -0.75446651, -1.80295133], [ 1.91484196, -0.70287151, -1.81832551]]], [[[ 1.22655272, -0.59102375, -2.15540417], [ 1.23017156, -0.53743647, -2.16329377], [ 1.23379041, -0.48384919, -2.17118338], ..., [ 1.24102811, -0.37667462, -2.18696258], [ 1.24464695, -0.32308734, -2.19485218], [ 1.2482658 , -0.26950005, -2.20274178]], [[ 1.23111763, -0.59103168, -2.15336419], [ 1.23473648, -0.5374444 , -2.16125379], [ 1.23835532, -0.48385712, -2.1691434 ], ..., [ 1.24559302, -0.37668255, -2.1849226 ], [ 1.24921187, -0.32309527, -2.1928122 ], [ 1.25283071, -0.26950799, -2.2007018 ]], [[ 1.23568254, -0.59103962, -2.15132421], [ 1.23930139, -0.53745233, -2.15921381], [ 1.24292024, -0.48386505, -2.16710342], ..., [ 1.25015793, -0.37669048, -2.18288262], [ 1.25377678, -0.3231032 , -2.19077222], [ 1.25739562, -0.26951592, -2.19866182]], ..., [[ 1.91585438, -0.59222158, -1.84736718], [ 1.91947322, -0.5386343 , -1.85525678], [ 1.92309207, -0.48504702, -1.86314638], ..., [ 1.93032976, -0.37787245, -1.87892558], [ 1.93394861, -0.32428517, -1.88681519], [ 1.93756746, -0.27069788, -1.89470479]], [[ 1.92041929, -0.59222951, -1.8453272 ], [ 1.92403813, -0.53864223, -1.8532168 ], [ 1.92765698, -0.48505495, -1.8611064 ], ..., [ 1.93489468, -0.37788038, -1.8768856 ], [ 1.93851352, -0.3242931 , -1.88477521], [ 1.94213237, -0.27070582, -1.89266481]], [[ 1.9249842 , -0.59223745, -1.84328722], [ 1.92860305, -0.53865016, -1.85117682], [ 1.93222189, -0.48506288, -1.85906642], ..., [ 1.93945959, -0.37788831, -1.87484562], [ 1.94307844, -0.32430103, -1.88273523], [ 1.94669728, -0.27071375, -1.89062483]]], [[[ 1.25081825, -0.15856081, -2.20904249], [ 1.25078313, -0.10427517, -2.20895781], [ 1.25074801, -0.04998954, -2.20887313], ..., [ 1.25067777, 0.05858174, -2.20870378], [ 1.25064266, 0.11286738, -2.2086191 ], [ 1.25060754, 0.16715301, -2.20853442]], [[ 1.25538131, -0.15856105, -2.20699836], [ 1.25534619, -0.10427541, -2.20691368], [ 1.25531107, -0.04998977, -2.206829 ], ..., [ 1.25524083, 0.0585815 , -2.20665964], [ 1.25520572, 0.11286714, -2.20657496], [ 1.2551706 , 0.16715278, -2.20649029]], [[ 1.25994437, -0.15856128, -2.20495422], [ 1.25990925, -0.10427565, -2.20486955], [ 1.25987413, -0.04999001, -2.20478487], ..., [ 1.25980389, 0.05858127, -2.20461551], [ 1.25976878, 0.1128669 , -2.20453083], [ 1.25973366, 0.16715254, -2.20444615]], ..., [[ 1.93984034, -0.15859654, -1.90037835], [ 1.93980522, -0.1043109 , -1.90029367], [ 1.93977011, -0.05002527, -1.90020899], ..., [ 1.93969987, 0.05854601, -1.90003963], [ 1.93966475, 0.11283165, -1.89995495], [ 1.93962963, 0.16711728, -1.89987028]], [[ 1.9444034 , -0.15859678, -1.89833421], [ 1.94436828, -0.10431114, -1.89824954], [ 1.94433317, -0.0500255 , -1.89816486], ..., [ 1.94426293, 0.05854577, -1.8979955 ], [ 1.94422781, 0.11283141, -1.89791082], [ 1.94419269, 0.16711705, -1.89782614]], [[ 1.94896646, -0.15859701, -1.89629008], [ 1.94893134, -0.10431138, -1.8962054 ], [ 1.94889623, -0.05002574, -1.89612072], ..., [ 1.94882599, 0.05854554, -1.89595137], [ 1.94879087, 0.11283117, -1.89586669], [ 1.94875575, 0.16711681, -1.89578201]]], ..., [[[ 3.06103735, -0.16850854, 1.88373044], [ 3.06025048, -0.11422854, 1.88377341], [ 3.05946361, -0.05994855, 1.88381637], ..., [ 3.05788987, 0.04861144, 1.8839023 ], [ 3.057103 , 0.10289144, 1.88394527], [ 3.05631612, 0.15717143, 1.88398823]], [[ 3.05935143, -0.1685367 , 1.88843755], [ 3.05856455, -0.11425671, 1.88848051], [ 3.05777768, -0.05997671, 1.88852348], ..., [ 3.05620394, 0.04858328, 1.88860941], [ 3.05541707, 0.10286327, 1.88865237], [ 3.0546302 , 0.15714326, 1.88869534]], [[ 3.0576655 , -0.16856487, 1.89314466], [ 3.05687863, -0.11428487, 1.89318762], [ 3.05609176, -0.06000488, 1.89323059], ..., [ 3.05451801, 0.04855511, 1.89331651], [ 3.05373114, 0.1028351 , 1.89335948], [ 3.05294427, 0.1571151 , 1.89340244]], ..., [[ 2.80646223, -0.1727616 , 2.59450356], [ 2.80567536, -0.1184816 , 2.59454652], [ 2.80488849, -0.06420161, 2.59458949], ..., [ 2.80331474, 0.04435838, 2.59467541], [ 2.80252787, 0.09863837, 2.59471838], [ 2.801741 , 0.15291837, 2.59476134]], [[ 2.8047763 , -0.17278976, 2.59921066], [ 2.80398943, -0.11850977, 2.59925363], [ 2.80320256, -0.06422978, 2.59929659], ..., [ 2.80162882, 0.04433021, 2.59938252], [ 2.80084195, 0.09861021, 2.59942549], [ 2.80005507, 0.1528902 , 2.59946845]], [[ 2.80309038, -0.17281793, 2.60391777], [ 2.8023035 , -0.11853794, 2.60396073], [ 2.80151663, -0.06425794, 2.6040037 ], ..., [ 2.79994289, 0.04430205, 2.60408963], [ 2.79915602, 0.09858204, 2.60413259], [ 2.79836915, 0.15286204, 2.60417556]]], [[[ 2.77462737, -0.17232497, 2.61231542], [ 2.77491036, -0.11804396, 2.6129721 ], [ 2.77519334, -0.06376296, 2.61362878], ..., [ 2.77575932, 0.04479905, 2.61494214], [ 2.77604231, 0.09908006, 2.61559882], [ 2.7763253 , 0.15336106, 2.6162555 ]], [[ 2.77200569, -0.1723628 , 2.61657281], [ 2.77228868, -0.1180818 , 2.61722949], [ 2.77257167, -0.06380079, 2.61788617], ..., [ 2.77313765, 0.04476122, 2.61919953], [ 2.77342063, 0.09904222, 2.61985621], [ 2.77370362, 0.15332323, 2.62051289]], [[ 2.76938402, -0.17240064, 2.62083021], [ 2.76966701, -0.11811964, 2.62148689], [ 2.76995 , -0.06383863, 2.62214357], ..., [ 2.77051597, 0.04472338, 2.62345693], [ 2.77079896, 0.09900438, 2.62411361], [ 2.77108195, 0.15328539, 2.62477029]], ..., [[ 2.37875455, -0.17803839, 3.25518171], [ 2.37903754, -0.12375738, 3.25583839], [ 2.37932053, -0.06947638, 3.25649507], ..., [ 2.3798865 , 0.03908563, 3.25780843], [ 2.38016949, 0.09336664, 3.25846511], [ 2.38045248, 0.14764764, 3.25912179]], [[ 2.37613288, -0.17807623, 3.25943911], [ 2.37641587, -0.12379522, 3.26009579], [ 2.37669885, -0.06951422, 3.26075247], ..., [ 2.37726483, 0.03904779, 3.26206583], [ 2.37754782, 0.0933288 , 3.26272251], [ 2.37783081, 0.1476098 , 3.26337919]], [[ 2.3735112 , -0.17811406, 3.2636965 ], [ 2.37379419, -0.12383306, 3.26435318], [ 2.37407718, -0.06955205, 3.26500986], ..., [ 2.37464316, 0.03900996, 3.26632322], [ 2.37492614, 0.09329096, 3.2669799 ], [ 2.37520913, 0.14757197, 3.26763658]]], [[[ 2.34351345, -0.1775281 , 3.29184866], [ 2.34297415, -0.12324941, 3.29116163], [ 2.34243485, -0.06897072, 3.2904746 ], ..., [ 2.34135626, 0.03958665, 3.28910054], [ 2.34081696, 0.09386534, 3.28841351], [ 2.34027766, 0.14814403, 3.28772648]], [[ 2.34007209, -0.17751638, 3.29547591], [ 2.33953279, -0.12323769, 3.29478888], [ 2.3389935 , -0.068959 , 3.29410185], ..., [ 2.3379149 , 0.03959837, 3.29272779], [ 2.33737561, 0.09387706, 3.29204076], [ 2.33683631, 0.14815575, 3.29135374]], [[ 2.33663074, -0.17750466, 3.29910316], [ 2.33609144, -0.12322597, 3.29841613], [ 2.33555214, -0.06894728, 3.2977291 ], ..., [ 2.33447355, 0.03961009, 3.29635504], [ 2.33393425, 0.09388878, 3.29566801], [ 2.33339496, 0.14816747, 3.29498099]], ..., [[ 1.82386904, -0.17575847, 3.83956351], [ 1.82332975, -0.12147978, 3.83887649], [ 1.82279045, -0.06720109, 3.83818946], ..., [ 1.82171186, 0.04135628, 3.8368154 ], [ 1.82117256, 0.09563497, 3.83612837], [ 1.82063326, 0.14991366, 3.83544134]], [[ 1.82042769, -0.17574675, 3.84319076], [ 1.81988839, -0.12146806, 3.84250374], [ 1.8193491 , -0.06718937, 3.84181671], ..., [ 1.8182705 , 0.041368 , 3.84044265], [ 1.81773121, 0.09564669, 3.83975562], [ 1.81719191, 0.14992538, 3.83906859]], [[ 1.81698634, -0.17573503, 3.84681802], [ 1.81644704, -0.12145634, 3.84613099], [ 1.81590774, -0.06717765, 3.84544396], ..., [ 1.81482915, 0.04137972, 3.8440699 ], [ 1.81428985, 0.09565841, 3.84338287], [ 1.81375055, 0.1499371 , 3.84269584]]]])
    • sample_position
      ()
      vector3
      m
      [0. 0. 0.]
      Values:
      array([0., 0., 0.])
    • source_position
      ()
      vector3
      m
      [ 0. 0. -60.]
      Values:
      array([ 0., 0., -60.])
    • spectrum
      (bank, column, row)
      int32
      1, 2, ..., 24793, 24794
      Values:
      array([[[ 1, 2, 3, ..., 5, 6, 7], [ 8, 9, 10, ..., 12, 13, 14], [ 15, 16, 17, ..., 19, 20, 21], ..., [ 1058, 1059, 1060, ..., 1062, 1063, 1064], [ 1065, 1066, 1067, ..., 1069, 1070, 1071], [ 1072, 1073, 1074, ..., 1076, 1077, 1078]], [[ 1079, 1080, 1081, ..., 1083, 1084, 1085], [ 1086, 1087, 1088, ..., 1090, 1091, 1092], [ 1093, 1094, 1095, ..., 1097, 1098, 1099], ..., [ 2136, 2137, 2138, ..., 2140, 2141, 2142], [ 2143, 2144, 2145, ..., 2147, 2148, 2149], [ 2150, 2151, 2152, ..., 2154, 2155, 2156]], [[ 2157, 2158, 2159, ..., 2161, 2162, 2163], [ 2164, 2165, 2166, ..., 2168, 2169, 2170], [ 2171, 2172, 2173, ..., 2175, 2176, 2177], ..., [ 3214, 3215, 3216, ..., 3218, 3219, 3220], [ 3221, 3222, 3223, ..., 3225, 3226, 3227], [ 3228, 3229, 3230, ..., 3232, 3233, 3234]], ..., [[21561, 21562, 21563, ..., 21565, 21566, 21567], [21568, 21569, 21570, ..., 21572, 21573, 21574], [21575, 21576, 21577, ..., 21579, 21580, 21581], ..., [22618, 22619, 22620, ..., 22622, 22623, 22624], [22625, 22626, 22627, ..., 22629, 22630, 22631], [22632, 22633, 22634, ..., 22636, 22637, 22638]], [[22639, 22640, 22641, ..., 22643, 22644, 22645], [22646, 22647, 22648, ..., 22650, 22651, 22652], [22653, 22654, 22655, ..., 22657, 22658, 22659], ..., [23696, 23697, 23698, ..., 23700, 23701, 23702], [23703, 23704, 23705, ..., 23707, 23708, 23709], [23710, 23711, 23712, ..., 23714, 23715, 23716]], [[23717, 23718, 23719, ..., 23721, 23722, 23723], [23724, 23725, 23726, ..., 23728, 23729, 23730], [23731, 23732, 23733, ..., 23735, 23736, 23737], ..., [24774, 24775, 24776, ..., 24778, 24779, 24780], [24781, 24782, 24783, ..., 24785, 24786, 24787], [24788, 24789, 24790, ..., 24792, 24793, 24794]]], dtype=int32)
    • (bank, column, row)
      DataArrayView
      binned data [len=0, len=0, ..., len=0, len=0]
      dim='event',
      content=DataArray(
                dims=(event: 17926980),
                data=float32[counts],
                coords={'tof':float64[µs]})
[13]:
results[MaskedData[SampleRun]].bins.concat().hist(wavelength=300).plot()
[13]:
../../_images/user-guide_sns-instruments_POWGEN_data_reduction_21_0.svg
[14]:
tof_data = sc.DataGroup(
    sample=results[FilteredData[SampleRun]].bins.concat(),
    vanadium=results[FilteredData[VanadiumRun]].bins.concat(),
)
tof_data.hist(tof=100).plot()
[14]:
../../_images/user-guide_sns-instruments_POWGEN_data_reduction_22_0.svg

Group by scattering angle#

The above workflow focuses the data by merging all instrument pixels to produce a 1d d-spacing curve. If instead we want to group into \(2\theta\) bins, we can alter the workflow parameters by adding some binning in \(2\theta\):

[15]:
workflow[TwoThetaBins] = sc.linspace(
    dim="two_theta", unit="deg", start=25.0, stop=90.0, num=17
).to(unit="rad")

We then have to request a final result that depends on both d-spacing and \(2\theta\):

[16]:
workflow.visualize(IofDspacingTwoTheta, graph_attr={"rankdir": "LR"})
[16]:
../../_images/user-guide_sns-instruments_POWGEN_data_reduction_26_0.svg

Compute and plot the result:

[17]:
grouped_dspacing = workflow.compute(IofDspacingTwoTheta)
grouped_dspacing
[17]:
Show/Hide data repr Show/Hide attributes
scipp.DataArray (169.05 MB)
    • two_theta: 16
    • dspacing: 200
    • dspacing
      (dspacing [bin-edge])
      float64
      Å
      0.0, 0.012, ..., 2.332, 2.343
      Values:
      array([0. , 0.011717, 0.023434, 0.035151, 0.046868, 0.058585, 0.070302, 0.082019, 0.093736, 0.105453, 0.11717 , 0.128887, 0.140604, 0.152321, 0.164038, 0.175755, 0.187472, 0.199189, 0.210906, 0.222623, 0.23434 , 0.246057, 0.257774, 0.269491, 0.281208, 0.292925, 0.304642, 0.316359, 0.328076, 0.339793, 0.35151 , 0.363227, 0.374944, 0.386661, 0.398378, 0.410095, 0.421812, 0.433529, 0.445246, 0.456963, 0.46868 , 0.480397, 0.492114, 0.503831, 0.515548, 0.527265, 0.538982, 0.550699, 0.562416, 0.574133, 0.58585 , 0.597567, 0.609284, 0.621001, 0.632718, 0.644435, 0.656152, 0.667869, 0.679586, 0.691303, 0.70302 , 0.714737, 0.726454, 0.738171, 0.749888, 0.761605, 0.773322, 0.785039, 0.796756, 0.808473, 0.82019 , 0.831907, 0.843624, 0.855341, 0.867058, 0.878775, 0.890492, 0.902209, 0.913926, 0.925643, 0.93736 , 0.949077, 0.960794, 0.972511, 0.984228, 0.995945, 1.007662, 1.019379, 1.031096, 1.042813, 1.05453 , 1.066247, 1.077964, 1.089681, 1.101398, 1.113115, 1.124832, 1.136549, 1.148266, 1.159983, 1.1717 , 1.183417, 1.195134, 1.206851, 1.218568, 1.230285, 1.242002, 1.253719, 1.265436, 1.277153, 1.28887 , 1.300587, 1.312304, 1.324021, 1.335738, 1.347455, 1.359172, 1.370889, 1.382606, 1.394323, 1.40604 , 1.417757, 1.429474, 1.441191, 1.452908, 1.464625, 1.476342, 1.488059, 1.499776, 1.511493, 1.52321 , 1.534927, 1.546644, 1.558361, 1.570078, 1.581795, 1.593512, 1.605229, 1.616946, 1.628663, 1.64038 , 1.652097, 1.663814, 1.675531, 1.687248, 1.698965, 1.710682, 1.722399, 1.734116, 1.745833, 1.75755 , 1.769267, 1.780984, 1.792701, 1.804418, 1.816135, 1.827852, 1.839569, 1.851286, 1.863003, 1.87472 , 1.886437, 1.898154, 1.909871, 1.921588, 1.933305, 1.945022, 1.956739, 1.968456, 1.980173, 1.99189 , 2.003607, 2.015324, 2.027041, 2.038758, 2.050475, 2.062192, 2.073909, 2.085626, 2.097343, 2.10906 , 2.120777, 2.132494, 2.144211, 2.155928, 2.167645, 2.179362, 2.191079, 2.202796, 2.214513, 2.22623 , 2.237947, 2.249664, 2.261381, 2.273098, 2.284815, 2.296532, 2.308249, 2.319966, 2.331683, 2.3434 ])
    • sample_position
      ()
      vector3
      m
      [0. 0. 0.]
      Values:
      array([0., 0., 0.])
    • source_position
      ()
      vector3
      m
      [ 0. 0. -60.]
      Values:
      array([ 0., 0., -60.])
    • two_theta
      (two_theta [bin-edge])
      float64
      rad
      0.436, 0.507, ..., 1.500, 1.571
      Values:
      array([0.43633231, 0.50723631, 0.57814031, 0.64904432, 0.71994832, 0.79085232, 0.86175632, 0.93266032, 1.00356432, 1.07446832, 1.14537232, 1.21627632, 1.28718032, 1.35808432, 1.42898833, 1.49989233, 1.57079633])
    • (two_theta, dspacing)
      DataArrayView
      binned data [len=112, len=125, ..., len=0, len=0]
      dim='event',
      content=DataArray(
                dims=(event: 7088376),
                data=float64[dimensionless],
                coords={'dspacing':float64[Å]},
                masks={'tof':bool})
[18]:
angle = sc.midpoints(grouped_dspacing.coords["two_theta"])
sc.plot(
    {
        f"{angle[group].value:.3f} {angle[group].unit}": grouped_dspacing[
            "two_theta", group
        ].hist()
        for group in range(2, 6)
    }
)
[18]:
../../_images/user-guide_sns-instruments_POWGEN_data_reduction_29_0.svg

Or we can view it as a 2D plot, which should display powder peaks as vertical bright lines:

[19]:
grouped_dspacing.hist().plot()
[19]:
../../_images/user-guide_sns-instruments_POWGEN_data_reduction_31_0.svg