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] = 'orca_detector'
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/2/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/2/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/2/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
- dim_1: 256
- dim_2: 256
- position(dim_1, dim_2)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(dim_2)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(dim_1)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, dim_1, dim_2)float64𝟙1.010, 1.023, ..., 0.961, 0.966σ = 0.125, 0.115, ..., 0.769, 0.778
Values:
array([[[1.01004422, 1.0234801 , 1.00767668, ..., 1.01859779, 1.00409662, 1.01274979], [1.01712147, 0.99618973, 1.02186165, ..., 1.01203152, 1.01701625, 1.0099162 ], [1.00674745, 1.02711681, 0.99218058, ..., 1.02399009, 1.01686532, 1.01587181], ..., [0.8024722 , 0.79000108, 0.77782372, ..., 1.0269968 , 1.00992376, 0.99939682], [0.81106115, 0.78484828, 0.74918073, ..., 1.05246387, 1.06894212, 0.94897847], [0.80429418, 0.73826875, 0.80566598, ..., 1.04515265, 1.02841706, 1.00727495]], [[1.03521427, 1.02533839, 1.00716407, ..., 1.00004642, 1.00051087, 1.00345346], [1.01816611, 1.00714891, 1.03229012, ..., 1.01817191, 1.02180331, 1.00847997], [1.00437421, 1.02250014, 0.99090421, ..., 1.03428951, 1.01323509, 1.00721545], ..., [0.74738211, 0.73792211, 0.74099917, ..., 0.87021796, 0.97545597, 0.96514815], [0.80320413, 0.73155072, 0.75635755, ..., 0.96889876, 0.97081894, 0.92863327], [0.76635929, 0.73086515, 0.76623021, ..., 0.95605848, 0.92786653, 0.93241549]], [[1.04402099, 1.0351179 , 1.01407537, ..., 1.00010425, 1.00495394, 1.00917711], [1.02855699, 1.00831527, 1.03127329, ..., 1.0145493 , 1.02912551, 1.01176807], [1.01586801, 1.02469357, 0.9887804 , ..., 1.00988293, 1.01768081, 1.01843299], ..., [0.7789132 , 0.72322334, 0.74111865, ..., 0.94472269, 0.94936311, 0.92614733], [0.75751635, 0.71649441, 0.74187469, ..., 0.93127245, 0.90673433, 0.86583701], [0.79665647, 0.73098394, 0.76635756, ..., 0.94276257, 0.9543569 , 0.9591872 ]], ..., [[1.11407959, 1.06631405, 1.03635224, ..., 0.97726853, 0.97426502, 1.00013497], [1.05153766, 1.04379913, 1.07194134, ..., 1.00000175, 1.00868336, 0.99555532], [1.01936725, 1.02781816, 1.00403556, ..., 1.03203616, 0.99242583, 0.97568789], ..., [0.85234787, 0.86650925, 0.83881813, ..., 0.90275679, 0.95742552, 0.88213993], [0.82893375, 0.80268582, 0.83928886, ..., 0.97671525, 0.95318245, 0.88627648], [0.85206887, 0.82811514, 0.8554662 , ..., 0.95104492, 0.93617381, 0.94083546]], [[1.11720223, 1.06720285, 1.03346905, ..., 0.96860945, 0.96063386, 0.98942849], [1.05679938, 1.04564437, 1.06856162, ..., 1.00902009, 1.00310775, 0.99954944], [1.01993417, 1.03181667, 1.00905853, ..., 1.02804068, 1.00082557, 0.97552365], ..., [0.8615082 , 0.84567153, 0.86217737, ..., 0.91136839, 0.99279689, 0.93012591], [0.8684309 , 0.8266908 , 0.83333062, ..., 0.96033563, 0.92347475, 0.93261453], [0.8307524 , 0.82217421, 0.83322686, ..., 0.94687885, 1.01120009, 0.936568 ]], [[1.13232932, 1.06955525, 1.03174236, ..., 0.97786349, 0.96842275, 0.98952282], [1.06957744, 1.0413305 , 1.07413959, ..., 0.98936952, 1.00558027, 0.99322223], [1.03721589, 1.03197658, 1.00480773, ..., 1.0351567 , 1.00536218, 0.98282294], ..., [0.89581316, 0.89293328, 0.80613757, ..., 1.013449 , 0.98248267, 0.94595112], [0.80996474, 0.8598511 , 0.89454246, ..., 1.01349052, 0.9647929 , 0.94789535], [0.90908867, 0.8248192 , 0.89900108, ..., 1.00357423, 0.9611884 , 0.96605757]]], shape=(36, 256, 256))
Variances (σ²):
array([[[0.01560841, 0.01321212, 0.01133241, ..., 0.01497743, 0.01381966, 0.01465622], [0.01410848, 0.01304118, 0.0130864 , ..., 0.01631906, 0.01615692, 0.01359392], [0.01381286, 0.01310102, 0.01269722, ..., 0.01549489, 0.01417347, 0.01274938], ..., [0.59547558, 0.52438342, 0.50465066, ..., 0.58413576, 0.6311945 , 0.61389539], [0.57265338, 0.5464191 , 0.48032141, ..., 0.61067921, 0.64949743, 0.5299149 ], [0.55360289, 0.47206461, 0.6017344 , ..., 0.69692681, 0.64952364, 0.64089628]], [[0.01626564, 0.01324921, 0.01131917, ..., 0.0145208 , 0.01373339, 0.01442833], [0.01412897, 0.01328113, 0.01331132, ..., 0.0164793 , 0.01627923, 0.01355765], [0.01375382, 0.01299689, 0.01266586, ..., 0.01575246, 0.01408485, 0.01256339], ..., [0.54895758, 0.48528265, 0.47766136, ..., 0.46817333, 0.60172211, 0.58527699], [0.56597822, 0.50482308, 0.48537289, ..., 0.54417634, 0.56767521, 0.5147646 ], [0.52337011, 0.46676592, 0.56775842, ..., 0.61646244, 0.56469511, 0.57728228]], [[0.0165009 , 0.01346581, 0.01145252, ..., 0.01452226, 0.01383551, 0.01456593], [0.01437487, 0.01330729, 0.01328898, ..., 0.01638205, 0.01647432, 0.01363194], [0.01402143, 0.01304457, 0.01262011, ..., 0.01513604, 0.0141886 , 0.01280003], ..., [0.57511633, 0.47475201, 0.47774825, ..., 0.52088769, 0.58016228, 0.55400254], [0.52910568, 0.49362551, 0.47501076, ..., 0.51604409, 0.51848629, 0.47032876], [0.54730924, 0.46685052, 0.56786705, ..., 0.60507767, 0.58618456, 0.59944041]], ..., [[0.01843646, 0.01416716, 0.01188589, ..., 0.01397368, 0.01313701, 0.01434646], [0.01492437, 0.01411248, 0.01419876, ..., 0.01599177, 0.01593043, 0.01326577], [0.01410092, 0.0131102 , 0.01294889, ..., 0.01569233, 0.0136029 , 0.01190968], ..., [0.64006494, 0.58619991, 0.55180161, ..., 0.49061433, 0.58669707, 0.52017167], [0.58760343, 0.5607491 , 0.54842982, ..., 0.55009841, 0.55374691, 0.4843979 ], [0.59337018, 0.53896201, 0.64665793, ..., 0.61208323, 0.57130544, 0.58411901]], [[0.01853113, 0.01419196, 0.01183291, ..., 0.01377428, 0.0128387 , 0.01409655], [0.01505714, 0.01415972, 0.01412611, ..., 0.0162364 , 0.0157896 , 0.01335917], [0.01411881, 0.01320176, 0.01306327, ..., 0.0155955 , 0.01379975, 0.01191029], ..., [0.64872386, 0.56888673, 0.57098338, ..., 0.49681115, 0.61642533, 0.55718695], [0.62235633, 0.58092916, 0.54380617, ..., 0.53772794, 0.53106757, 0.51773507], [0.57539572, 0.53441942, 0.62632035, ..., 0.60864142, 0.63435575, 0.58073388]], [[0.01896838, 0.01424726, 0.01180011, ..., 0.0139937 , 0.01301244, 0.01410017], [0.01537213, 0.01406131, 0.01425486, ..., 0.01571847, 0.01585569, 0.01321949], [0.01452953, 0.01320658, 0.01297138, ..., 0.01577835, 0.0139057 , 0.0120606 ], ..., [0.68145337, 0.60909171, 0.52617142, ..., 0.57336613, 0.60771923, 0.56981373], [0.57171808, 0.60961733, 0.59422708, ..., 0.57902305, 0.56299681, 0.52909177], [0.64419998, 0.53653229, 0.68847727, ..., 0.65853479, 0.59191274, 0.60531763]]], 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]: