TBL: Orca image normalization workflow#
This notebook shows how to use the workflow to compute normalized images recorded by the Orca detector on the TBL instrument.
[1]:
import ess.tbl.data # noqa: F401
from ess import tbl
from ess.imaging.types import *
import scipp as sc
import plopp as pp
%matplotlib widget
Workflow setup#
[2]:
wf = tbl.OrcaNormalizedImagesWorkflow()
wf[Filename[SampleRun]] = tbl.data.tbl_lego_sample_run()
wf[Filename[DarkBackgroundRun]] = tbl.data.tbl_lego_dark_run()
wf[Filename[OpenBeamRun]] = tbl.data.tbl_lego_openbeam_run()
wf[NeXusDetectorName] = tbl.nexus_name('orca')
wf[MaskingRules] = {} # No masks to begin with
wf[UncertaintyBroadcastMode] = UncertaintyBroadcastMode.upper_bound
Downloading file 'ymir_lego_sample_run.hdf' from 'https://public.esss.dk/groups/scipp/ess/tbl/5/ymir_lego_sample_run.hdf' to '/home/runner/.cache/ess/tbl'.
Downloading file 'ymir_lego_dark_run.hdf' from 'https://public.esss.dk/groups/scipp/ess/tbl/5/ymir_lego_dark_run.hdf' to '/home/runner/.cache/ess/tbl'.
Downloading file 'ymir_lego_openbeam_run.hdf' from 'https://public.esss.dk/groups/scipp/ess/tbl/5/ymir_lego_openbeam_run.hdf' to '/home/runner/.cache/ess/tbl'.
[3]:
wf.visualize(NormalizedImage, compact=True, graph_attr={"rankdir": "LR"})
[3]:
Run the workflow#
We compute the final normalized image:
[4]:
image = wf.compute(NormalizedImage)
image
[4]:
scipp.DataArray (37.51 MB)
- time: 36
- y_pixel_offset: 256
- x_pixel_offset: 256
- position(y_pixel_offset, x_pixel_offset)vector3m[-0.1 -0.1 0. ], [-0.09921569 -0.1 0. ], ..., [0.09921569 0.1 0. ], [0.1 0.1 0. ]
Values:
array([[[-0.1 , -0.1 , 0. ], [-0.09921569, -0.1 , 0. ], [-0.09843137, -0.1 , 0. ], ..., [ 0.09843137, -0.1 , 0. ], [ 0.09921569, -0.1 , 0. ], [ 0.1 , -0.1 , 0. ]], [[-0.1 , -0.09921569, 0. ], [-0.09921569, -0.09921569, 0. ], [-0.09843137, -0.09921569, 0. ], ..., [ 0.09843137, -0.09921569, 0. ], [ 0.09921569, -0.09921569, 0. ], [ 0.1 , -0.09921569, 0. ]], [[-0.1 , -0.09843137, 0. ], [-0.09921569, -0.09843137, 0. ], [-0.09843137, -0.09843137, 0. ], ..., [ 0.09843137, -0.09843137, 0. ], [ 0.09921569, -0.09843137, 0. ], [ 0.1 , -0.09843137, 0. ]], ..., [[-0.1 , 0.09843137, 0. ], [-0.09921569, 0.09843137, 0. ], [-0.09843137, 0.09843137, 0. ], ..., [ 0.09843137, 0.09843137, 0. ], [ 0.09921569, 0.09843137, 0. ], [ 0.1 , 0.09843137, 0. ]], [[-0.1 , 0.09921569, 0. ], [-0.09921569, 0.09921569, 0. ], [-0.09843137, 0.09921569, 0. ], ..., [ 0.09843137, 0.09921569, 0. ], [ 0.09921569, 0.09921569, 0. ], [ 0.1 , 0.09921569, 0. ]], [[-0.1 , 0.1 , 0. ], [-0.09921569, 0.1 , 0. ], [-0.09843137, 0.1 , 0. ], ..., [ 0.09843137, 0.1 , 0. ], [ 0.09921569, 0.1 , 0. ], [ 0.1 , 0.1 , 0. ]]], shape=(256, 256, 3)) - time(time)datetime64ns2024-08-14T14:16:57.997255602, 2024-08-14T14:17:46.682255224, ..., 2024-08-14T14:44:41.925222722, 2024-08-14T14:45:30.825154517
Values:
array(['2024-08-14T14:16:57.997255602', '2024-08-14T14:17:46.682255224', '2024-08-14T14:18:35.853205911', '2024-08-14T14:19:24.975128719', '2024-08-14T14:20:13.955183413', '2024-08-14T14:21:02.993115782', '2024-08-14T14:21:51.865167018', '2024-08-14T14:22:40.700159043', '2024-08-14T14:23:30.120165136', '2024-08-14T14:24:19.211202454', '2024-08-14T14:25:07.781151541', '2024-08-14T14:25:56.672195037', '2024-08-14T14:26:45.768113531', '2024-08-14T14:27:34.491207424', '2024-08-14T14:28:23.784141401', '2024-08-14T14:29:12.714194238', '2024-08-14T14:30:01.238209345', '2024-08-14T14:30:50.167144757', '2024-08-14T14:31:38.958162332', '2024-08-14T14:32:27.831177947', '2024-08-14T14:33:16.678124259', '2024-08-14T14:34:05.873147398', '2024-08-14T14:34:54.972148922', '2024-08-14T14:35:43.545102329', '2024-08-14T14:36:32.141243180', '2024-08-14T14:37:21.510179315', '2024-08-14T14:38:10.617163791', '2024-08-14T14:39:00.045194764', '2024-08-14T14:39:48.289190220', '2024-08-14T14:40:36.650186469', '2024-08-14T14:41:25.774189010', '2024-08-14T14:42:15.149107963', '2024-08-14T14:43:03.915278596', '2024-08-14T14:43:53.077218381', '2024-08-14T14:44:41.925222722', '2024-08-14T14:45:30.825154517'], dtype='datetime64[ns]') - x_pixel_offset(x_pixel_offset)float64m-0.1, -0.099, ..., 0.099, 0.1
Values:
array([-0.1 , -0.09921569, -0.09843137, -0.09764706, -0.09686275, -0.09607843, -0.09529412, -0.0945098 , -0.09372549, -0.09294118, -0.09215686, -0.09137255, -0.09058824, -0.08980392, -0.08901961, -0.08823529, -0.08745098, -0.08666667, -0.08588235, -0.08509804, -0.08431373, -0.08352941, -0.0827451 , -0.08196078, -0.08117647, -0.08039216, -0.07960784, -0.07882353, -0.07803922, -0.0772549 , -0.07647059, -0.07568627, -0.07490196, -0.07411765, -0.07333333, -0.07254902, -0.07176471, -0.07098039, -0.07019608, -0.06941176, -0.06862745, -0.06784314, -0.06705882, -0.06627451, -0.0654902 , -0.06470588, -0.06392157, -0.06313725, -0.06235294, -0.06156863, -0.06078431, -0.06 , -0.05921569, -0.05843137, -0.05764706, -0.05686275, -0.05607843, -0.05529412, -0.0545098 , -0.05372549, -0.05294118, -0.05215686, -0.05137255, -0.05058824, -0.04980392, -0.04901961, -0.04823529, -0.04745098, -0.04666667, -0.04588235, -0.04509804, -0.04431373, -0.04352941, -0.0427451 , -0.04196078, -0.04117647, -0.04039216, -0.03960784, -0.03882353, -0.03803922, -0.0372549 , -0.03647059, -0.03568627, -0.03490196, -0.03411765, -0.03333333, -0.03254902, -0.03176471, -0.03098039, -0.03019608, -0.02941176, -0.02862745, -0.02784314, -0.02705882, -0.02627451, -0.0254902 , -0.02470588, -0.02392157, -0.02313725, -0.02235294, -0.02156863, -0.02078431, -0.02 , -0.01921569, -0.01843137, -0.01764706, -0.01686275, -0.01607843, -0.01529412, -0.0145098 , -0.01372549, -0.01294118, -0.01215686, -0.01137255, -0.01058824, -0.00980392, -0.00901961, -0.00823529, -0.00745098, -0.00666667, -0.00588235, -0.00509804, -0.00431373, -0.00352941, -0.0027451 , -0.00196078, -0.00117647, -0.00039216, 0.00039216, 0.00117647, 0.00196078, 0.0027451 , 0.00352941, 0.00431373, 0.00509804, 0.00588235, 0.00666667, 0.00745098, 0.00823529, 0.00901961, 0.00980392, 0.01058824, 0.01137255, 0.01215686, 0.01294118, 0.01372549, 0.0145098 , 0.01529412, 0.01607843, 0.01686275, 0.01764706, 0.01843137, 0.01921569, 0.02 , 0.02078431, 0.02156863, 0.02235294, 0.02313725, 0.02392157, 0.02470588, 0.0254902 , 0.02627451, 0.02705882, 0.02784314, 0.02862745, 0.02941176, 0.03019608, 0.03098039, 0.03176471, 0.03254902, 0.03333333, 0.03411765, 0.03490196, 0.03568627, 0.03647059, 0.0372549 , 0.03803922, 0.03882353, 0.03960784, 0.04039216, 0.04117647, 0.04196078, 0.0427451 , 0.04352941, 0.04431373, 0.04509804, 0.04588235, 0.04666667, 0.04745098, 0.04823529, 0.04901961, 0.04980392, 0.05058824, 0.05137255, 0.05215686, 0.05294118, 0.05372549, 0.0545098 , 0.05529412, 0.05607843, 0.05686275, 0.05764706, 0.05843137, 0.05921569, 0.06 , 0.06078431, 0.06156863, 0.06235294, 0.06313725, 0.06392157, 0.06470588, 0.0654902 , 0.06627451, 0.06705882, 0.06784314, 0.06862745, 0.06941176, 0.07019608, 0.07098039, 0.07176471, 0.07254902, 0.07333333, 0.07411765, 0.07490196, 0.07568627, 0.07647059, 0.0772549 , 0.07803922, 0.07882353, 0.07960784, 0.08039216, 0.08117647, 0.08196078, 0.0827451 , 0.08352941, 0.08431373, 0.08509804, 0.08588235, 0.08666667, 0.08745098, 0.08823529, 0.08901961, 0.08980392, 0.09058824, 0.09137255, 0.09215686, 0.09294118, 0.09372549, 0.0945098 , 0.09529412, 0.09607843, 0.09686275, 0.09764706, 0.09843137, 0.09921569, 0.1 ]) - y_pixel_offset(y_pixel_offset)float64m-0.1, -0.099, ..., 0.099, 0.1
Values:
array([-0.1 , -0.09921569, -0.09843137, -0.09764706, -0.09686275, -0.09607843, -0.09529412, -0.0945098 , -0.09372549, -0.09294118, -0.09215686, -0.09137255, -0.09058824, -0.08980392, -0.08901961, -0.08823529, -0.08745098, -0.08666667, -0.08588235, -0.08509804, -0.08431373, -0.08352941, -0.0827451 , -0.08196078, -0.08117647, -0.08039216, -0.07960784, -0.07882353, -0.07803922, -0.0772549 , -0.07647059, -0.07568627, -0.07490196, -0.07411765, -0.07333333, -0.07254902, -0.07176471, -0.07098039, -0.07019608, -0.06941176, -0.06862745, -0.06784314, -0.06705882, -0.06627451, -0.0654902 , -0.06470588, -0.06392157, -0.06313725, -0.06235294, -0.06156863, -0.06078431, -0.06 , -0.05921569, -0.05843137, -0.05764706, -0.05686275, -0.05607843, -0.05529412, -0.0545098 , -0.05372549, -0.05294118, -0.05215686, -0.05137255, -0.05058824, -0.04980392, -0.04901961, -0.04823529, -0.04745098, -0.04666667, -0.04588235, -0.04509804, -0.04431373, -0.04352941, -0.0427451 , -0.04196078, -0.04117647, -0.04039216, -0.03960784, -0.03882353, -0.03803922, -0.0372549 , -0.03647059, -0.03568627, -0.03490196, -0.03411765, -0.03333333, -0.03254902, -0.03176471, -0.03098039, -0.03019608, -0.02941176, -0.02862745, -0.02784314, -0.02705882, -0.02627451, -0.0254902 , -0.02470588, -0.02392157, -0.02313725, -0.02235294, -0.02156863, -0.02078431, -0.02 , -0.01921569, -0.01843137, -0.01764706, -0.01686275, -0.01607843, -0.01529412, -0.0145098 , -0.01372549, -0.01294118, -0.01215686, -0.01137255, -0.01058824, -0.00980392, -0.00901961, -0.00823529, -0.00745098, -0.00666667, -0.00588235, -0.00509804, -0.00431373, -0.00352941, -0.0027451 , -0.00196078, -0.00117647, -0.00039216, 0.00039216, 0.00117647, 0.00196078, 0.0027451 , 0.00352941, 0.00431373, 0.00509804, 0.00588235, 0.00666667, 0.00745098, 0.00823529, 0.00901961, 0.00980392, 0.01058824, 0.01137255, 0.01215686, 0.01294118, 0.01372549, 0.0145098 , 0.01529412, 0.01607843, 0.01686275, 0.01764706, 0.01843137, 0.01921569, 0.02 , 0.02078431, 0.02156863, 0.02235294, 0.02313725, 0.02392157, 0.02470588, 0.0254902 , 0.02627451, 0.02705882, 0.02784314, 0.02862745, 0.02941176, 0.03019608, 0.03098039, 0.03176471, 0.03254902, 0.03333333, 0.03411765, 0.03490196, 0.03568627, 0.03647059, 0.0372549 , 0.03803922, 0.03882353, 0.03960784, 0.04039216, 0.04117647, 0.04196078, 0.0427451 , 0.04352941, 0.04431373, 0.04509804, 0.04588235, 0.04666667, 0.04745098, 0.04823529, 0.04901961, 0.04980392, 0.05058824, 0.05137255, 0.05215686, 0.05294118, 0.05372549, 0.0545098 , 0.05529412, 0.05607843, 0.05686275, 0.05764706, 0.05843137, 0.05921569, 0.06 , 0.06078431, 0.06156863, 0.06235294, 0.06313725, 0.06392157, 0.06470588, 0.0654902 , 0.06627451, 0.06705882, 0.06784314, 0.06862745, 0.06941176, 0.07019608, 0.07098039, 0.07176471, 0.07254902, 0.07333333, 0.07411765, 0.07490196, 0.07568627, 0.07647059, 0.0772549 , 0.07803922, 0.07882353, 0.07960784, 0.08039216, 0.08117647, 0.08196078, 0.0827451 , 0.08352941, 0.08431373, 0.08509804, 0.08588235, 0.08666667, 0.08745098, 0.08823529, 0.08901961, 0.08980392, 0.09058824, 0.09137255, 0.09215686, 0.09294118, 0.09372549, 0.0945098 , 0.09529412, 0.09607843, 0.09686275, 0.09764706, 0.09843137, 0.09921569, 0.1 ])
- (time, y_pixel_offset, x_pixel_offset)float64𝟙1.008, 1.022, ..., 0.952, 0.957σ = 0.125, 0.115, ..., 0.763, 0.771
Values:
array([[[1.00827594, 1.02177345, 1.00602353, ..., 1.01672476, 1.00226682, 1.01092133], [1.01537256, 0.99451361, 1.02015293, ..., 1.01009754, 1.01510089, 1.00812932], [1.00501827, 1.02540049, 0.99051709, ..., 1.02209743, 1.01503207, 1.01411484], ..., [0.79508201, 0.78304803, 0.77089695, ..., 1.01983449, 1.00243618, 0.99212301], [0.80379617, 0.77768024, 0.74235994, ..., 1.04533586, 1.06161391, 0.94197701], [0.7972558 , 0.73156695, 0.79835965, ..., 1.03739156, 1.02086018, 0.99970991]], [[1.03543859, 1.02556886, 1.00738011, ..., 1.00022111, 1.00069063, 1.00366494], [1.01836921, 1.00738201, 1.03251604, ..., 1.01832898, 1.02197863, 1.00869786], [1.00458165, 1.02271946, 0.99113913, ..., 1.03447255, 1.01343579, 1.00744625], ..., [0.74676652, 0.73739518, 0.74041904, ..., 0.86958385, 0.9746592 , 0.96449532], [0.80253209, 0.73096169, 0.75578288, ..., 0.96824432, 0.97011859, 0.92792216], [0.76585042, 0.73041646, 0.76572208, ..., 0.95526063, 0.92707408, 0.93159522]], [[1.03993825, 1.03107934, 1.01010911, ..., 0.99615023, 1.00098609, 1.00522356], [1.02451768, 1.00438765, 1.02724368, ..., 1.0105169 , 1.02505316, 1.00781027], [1.01188557, 1.02068522, 0.98493433, ..., 1.00589247, 1.01368139, 1.01446281], ..., [0.77497624, 0.71964713, 0.73740555, ..., 0.94006557, 0.94459848, 0.92162783], [0.7536803 , 0.71288323, 0.73817584, ..., 0.92673332, 0.90227008, 0.86153405], [0.7927623 , 0.72744368, 0.7626056 , ..., 0.93801077, 0.94953105, 0.95431232]], ..., [[1.11405234, 1.06626853, 1.03627832, ..., 0.97727545, 0.97426578, 1.00016919], [1.05148485, 1.04377306, 1.07188652, ..., 1.00000949, 1.00870074, 0.99557649], [1.0193326 , 1.02777097, 1.00402594, ..., 1.03203485, 0.99244211, 0.97571375], ..., [0.85456661, 0.86860769, 0.8408624 , ..., 0.90460883, 0.95929306, 0.88420447], [0.83108357, 0.80488642, 0.84133802, ..., 0.97850765, 0.95503051, 0.88810401], [0.85428733, 0.83030615, 0.85784198, ..., 0.95300959, 0.93802709, 0.94267708]], [[1.11241683, 1.06266365, 1.02907813, ..., 0.96435667, 0.95642864, 0.98512672], [1.05226298, 1.04119426, 1.06401169, ..., 1.00455704, 0.99869005, 0.99522889], [1.01555425, 1.02741213, 1.00476232, ..., 1.02354012, 0.99647185, 0.97132505], ..., [0.85426824, 0.83877025, 0.85516202, ..., 0.90429299, 0.98508777, 0.92289116], [0.86122539, 0.81972956, 0.82649334, ..., 0.95308483, 0.91630443, 0.92541232], [0.82391902, 0.81550548, 0.82624529, ..., 0.93929656, 1.00336482, 0.92907544]], [[1.12717123, 1.06472584, 1.02709726, ..., 0.97326065, 0.9638814 , 0.98490731], [1.0647002 , 1.03661702, 1.06928662, ..., 0.9846567 , 1.00082292, 0.98862471], [1.03248052, 1.02729662, 1.00025269, ..., 1.03030323, 1.00067947, 0.97830184], ..., [0.88637984, 0.88388892, 0.79752674, ..., 1.00405137, 0.97292271, 0.93675594], [0.80110227, 0.85076467, 0.88551602, ..., 1.00417585, 0.95558079, 0.93882 ], [0.89992637, 0.81626036, 0.8896624 , ..., 0.99373674, 0.95171277, 0.95650503]]], shape=(36, 256, 256))
Variances (σ²):
array([[[0.0155625 , 0.01317443, 0.01130043, ..., 0.01493091, 0.01377734, 0.01461206], [0.01406704, 0.01300424, 0.01304891, ..., 0.01626673, 0.01610589, 0.01355365], [0.0137726 , 0.01306337, 0.01266147, ..., 0.01544655, 0.0141305 , 0.0127123 ], ..., [0.58834149, 0.51850861, 0.49895368, ..., 0.57759295, 0.62374285, 0.60695157], [0.56587669, 0.54005237, 0.47499713, ..., 0.60396109, 0.6421625 , 0.52397322], [0.54738873, 0.46703697, 0.59476836, ..., 0.68849299, 0.64178332, 0.6331911 ]], [[0.01626802, 0.01325179, 0.01132133, ..., 0.01452119, 0.01373404, 0.01442999], [0.01413073, 0.0132839 , 0.01331373, ..., 0.01647859, 0.01627925, 0.01355955], [0.01375578, 0.01299914, 0.0126687 , ..., 0.01575283, 0.01408609, 0.01256566], ..., [0.54719905, 0.4838943 , 0.47620069, ..., 0.46673624, 0.59963072, 0.58349978], [0.56409825, 0.50324993, 0.48390938, ..., 0.54253287, 0.56587635, 0.51309268], [0.5219226 , 0.46556917, 0.56618229, ..., 0.61429331, 0.56270121, 0.57519502]], [[0.0163676 , 0.01335769, 0.01136052, ..., 0.01440323, 0.01372237, 0.01444781], [0.01425844, 0.01320063, 0.01318211, ..., 0.01624663, 0.01633884, 0.01352174], [0.01390811, 0.01293955, 0.01251915, ..., 0.01501196, 0.01407316, 0.01269706], ..., [0.56847713, 0.46947453, 0.47233232, ..., 0.5149295 , 0.57336158, 0.54775752], [0.52300745, 0.48801305, 0.46965785, ..., 0.51023662, 0.51259117, 0.46494804], [0.54123572, 0.46178717, 0.56158296, ..., 0.59794801, 0.57924272, 0.59229048]], ..., [[0.01842234, 0.01415648, 0.01187661, ..., 0.01396127, 0.01312549, 0.01433505], [0.01491218, 0.01410202, 0.01418787, ..., 0.01597691, 0.01591632, 0.01325536], [0.01408957, 0.01309992, 0.01293937, ..., 0.01567867, 0.01359164, 0.01190064], ..., [0.63952337, 0.58574955, 0.55126028, ..., 0.49009594, 0.58600016, 0.51980122], [0.58703777, 0.56026279, 0.54792055, ..., 0.54955025, 0.55317849, 0.4838358 ], [0.59305288, 0.5386993 , 0.64643495, ..., 0.61140159, 0.57057201, 0.58333316]], [[0.01837397, 0.0140728 , 0.01173378, ..., 0.01365613, 0.01272896, 0.01397676], [0.01492956, 0.01404103, 0.01400733, ..., 0.01609548, 0.01565335, 0.0132461 ], [0.01399957, 0.01309077, 0.0129541 , ..., 0.01546131, 0.01368214, 0.01181016], ..., [0.63907688, 0.56075364, 0.56271091, ..., 0.48975377, 0.60733552, 0.54926023], [0.61314208, 0.57242843, 0.53600352, ..., 0.53015872, 0.52349913, 0.51032081], [0.56723248, 0.52698151, 0.61731612, ..., 0.59958842, 0.6249228 , 0.57208766]], [[0.01880148, 0.01412349, 0.011698 , ..., 0.01386933, 0.01289728, 0.01397601], [0.01523728, 0.0139394 , 0.01413082, ..., 0.01557712, 0.01571376, 0.01310365], [0.0144025 , 0.01309178, 0.01285932, ..., 0.0156375 , 0.01378289, 0.01195564], ..., [0.66975347, 0.59905495, 0.51752594, ..., 0.56403093, 0.59749597, 0.56051833], [0.56209 , 0.59933877, 0.58440751, ..., 0.56971323, 0.55381614, 0.52046694], [0.63359675, 0.52795757, 0.67695015, ..., 0.64728142, 0.58190761, 0.5950154 ]]], shape=(36, 256, 256))
[5]:
pp.slicer(image, autoscale=False)
[5]:
Adding masks#
If we want to mask some part of the image, we update the masking rules. For example, here we mask the upper part of the image:
[6]:
wf[MaskingRules] = {'y_pixel_offset': lambda x: x > sc.scalar(0.082, unit='m')}
pp.slicer(wf.compute(NormalizedImage), autoscale=False)
[6]:
Intermediate results#
We can also inspect intermediate results, which is useful for debugging:
[7]:
results = wf.compute([
RawDetector[SampleRun],
CorrectedDetector[SampleRun],
BackgroundSubtractedDetector[SampleRun]
])
fig = pp.tiled(2, 2, hspace=0.3, wspace=0.3)
fig[0, 0] = results[RawDetector[SampleRun]]['time', 0].plot(title='Raw data')
fig[0, 1] = results[CorrectedDetector[SampleRun]]['time', 0].plot(title='Masks applied')
fig[1, 0] = results[BackgroundSubtractedDetector[SampleRun]]['time', 0].plot(title='Background subtracted')
fig[1, 1] = image['time', 0].plot(title='Final image')
fig
[7]: