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/3/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/3/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/3/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.010, 1.024, ..., 0.948, 0.953σ = 0.125, 0.115, ..., 0.760, 0.769
Values:
array([[[1.01013506, 1.02362298, 1.0079153 , ..., 1.01861753, 1.00414488, 1.01276708], [1.01729493, 0.99631987, 1.02202647, ..., 1.01199991, 1.01700921, 1.00999952], [1.00688026, 1.02731683, 0.99229456, ..., 1.02396406, 1.0169041 , 1.0159626 ], ..., [0.79658308, 0.78451274, 0.77236867, ..., 1.02179666, 1.00433541, 0.99402899], [0.80539523, 0.77919388, 0.74371668, ..., 1.04724947, 1.06363227, 0.94380926], [0.79862172, 0.7328272 , 0.79974081, ..., 1.0394582 , 1.02274494, 1.00170001]], [[1.03134055, 1.02147547, 1.00342976, ..., 0.99628012, 0.9967599 , 0.99967464], [1.01438875, 1.00336733, 1.02842204, ..., 1.01433863, 1.01797051, 1.00471694], [1.00061456, 1.01869719, 0.98716777, ..., 1.03036025, 1.00942529, 1.00343714], ..., [0.74384371, 0.73449628, 0.73753664, ..., 0.86621152, 0.97085089, 0.96075213], [0.79947195, 0.72814319, 0.75277944, ..., 0.96439947, 0.96633439, 0.92434304], [0.76271992, 0.72743763, 0.76260482, ..., 0.95162075, 0.92340712, 0.92804414]], [[1.05192343, 1.0429273 , 1.02178782, ..., 1.00764863, 1.01255262, 1.01679035], [1.03637625, 1.01593509, 1.03907496, ..., 1.0222033 , 1.03690413, 1.01943663], [1.02355647, 1.03247428, 0.9962365 , ..., 1.01746742, 1.02536443, 1.02613205], ..., [0.78394226, 0.72796037, 0.74595264, ..., 0.95097581, 0.95553328, 0.93232138], [0.76247713, 0.72117292, 0.74667113, ..., 0.93740143, 0.9127209 , 0.87155121], [0.80179428, 0.73573839, 0.77130687, ..., 0.94896168, 0.96047659, 0.96545213]], ..., [[1.12649721, 1.07814331, 1.04789266, ..., 0.98820994, 0.98517857, 1.01132367], [1.06328322, 1.05540374, 1.08385244, ..., 1.01122028, 1.02000548, 1.0067092 ], [1.03072846, 1.03927795, 1.0151917 , ..., 1.0435452 , 1.00352895, 0.98659179], ..., [0.86415084, 0.87833412, 0.85031088, ..., 0.91478723, 0.97005828, 0.8941507 ], [0.84048952, 0.81396092, 0.85072266, ..., 0.9894253 , 0.96575427, 0.89811561], [0.86371783, 0.83947979, 0.86732618, ..., 0.96379812, 0.94850788, 0.95334724]], [[1.10908822, 1.05944823, 1.02603635, ..., 0.96148814, 0.95359528, 0.9821613 ], [1.04916611, 1.03805014, 1.06082016, ..., 1.00159065, 0.99573759, 0.99226208], [1.01252441, 1.02436344, 1.00170648, ..., 1.02045953, 0.99349062, 0.96839754], ..., [0.85174955, 0.83628271, 0.8526587 , ..., 0.90165927, 0.98218991, 0.9202006 ], [0.85877313, 0.81736035, 0.82400691, ..., 0.95022042, 0.91361493, 0.92273651], [0.8213466 , 0.81296695, 0.82367934, ..., 0.93662458, 1.0003649 , 0.92643118]], [[1.12313459, 1.0608771 , 1.02345637, ..., 0.96979239, 0.96045825, 0.98136247], [1.0609396 , 1.03287618, 1.06544948, ..., 0.98116911, 0.99727467, 0.9850953 ], [1.02879205, 1.0236432 , 0.99662145, ..., 1.02659547, 0.99709627, 0.9747771 ], ..., [0.88324439, 0.88074696, 0.79472238, ..., 1.00053569, 0.96948757, 0.93347319], [0.7983493 , 0.84780463, 0.88233048, ..., 1.00056646, 0.95221316, 0.93555242], [0.89658667, 0.81323877, 0.88637556, ..., 0.99032451, 0.94830675, 0.95321925]]], shape=(36, 256, 256))
Variances (σ²):
array([[[0.01562 , 0.01322205, 0.01134318, ..., 0.01498673, 0.01382925, 0.01466539], [0.0141207 , 0.01305143, 0.01309691, ..., 0.01632841, 0.01616682, 0.0136041 ], [0.01382378, 0.01311243, 0.01270677, ..., 0.01550294, 0.01418272, 0.0127586 ], ..., [0.59058479, 0.52045923, 0.50088594, ..., 0.57986247, 0.62613746, 0.60933056], [0.56820151, 0.54220219, 0.47672569, ..., 0.60616142, 0.64464183, 0.52606329], [0.54919835, 0.4685978 , 0.59676287, ..., 0.69134444, 0.64415227, 0.63580809]], [[0.01613957, 0.01314611, 0.01123292, ..., 0.01440715, 0.01362658, 0.01431541], [0.01402082, 0.01317814, 0.01320838, ..., 0.01635005, 0.01615214, 0.01345284], [0.01364746, 0.01289727, 0.01256719, ..., 0.01562776, 0.01397488, 0.01246579], ..., [0.54294117, 0.48010505, 0.47252338, ..., 0.46315535, 0.59498095, 0.57902123], [0.55987457, 0.4994162 , 0.48006149, ..., 0.53822171, 0.56149934, 0.50918988], [0.51760279, 0.46173055, 0.56152257, ..., 0.60970934, 0.55825612, 0.57089858]], [[0.0167471 , 0.01366631, 0.01162495, ..., 0.01473782, 0.01404157, 0.01478214], [0.01459077, 0.01350582, 0.01348753, ..., 0.01662493, 0.01671916, 0.01383563], [0.0142309 , 0.01324037, 0.01280792, ..., 0.01535936, 0.01439947, 0.01299078], ..., [0.58172617, 0.48039153, 0.4833688 , ..., 0.52699002, 0.58673917, 0.56058173], [0.53535132, 0.49946763, 0.48052084, ..., 0.52204107, 0.52456037, 0.47586531], [0.55357045, 0.47232825, 0.57441071, ..., 0.61207911, 0.59267124, 0.60628583]], ..., [[0.0188363 , 0.01447343, 0.01214454, ..., 0.0142756 , 0.01342139, 0.01465651], [0.01524907, 0.01441795, 0.01450644, ..., 0.01633749, 0.0162754 , 0.01355357], [0.01440648, 0.01339508, 0.01322857, ..., 0.01603027, 0.01389705, 0.01216741], ..., [0.65397189, 0.59895244, 0.56374924, ..., 0.50122273, 0.59925312, 0.53159743], [0.60047821, 0.57301677, 0.56020008, ..., 0.56187028, 0.56570023, 0.49485088], [0.60613947, 0.55060352, 0.66073115, ..., 0.62541341, 0.5833909 , 0.59669811]], [[0.01826424, 0.01398764, 0.01166472, ..., 0.01357516, 0.01265386, 0.01389268], [0.01484217, 0.01395627, 0.01392345, ..., 0.0160009 , 0.01556124, 0.01316736], [0.01391627, 0.01301338, 0.01287523, ..., 0.0153683 , 0.01360044, 0.01173902], ..., [0.63533648, 0.55744278, 0.55945215, ..., 0.48694002, 0.60379515, 0.54610064], [0.60973615, 0.56917439, 0.53277199, ..., 0.52696617, 0.52045653, 0.50742145], [0.56362446, 0.52364468, 0.61341875, ..., 0.59626772, 0.62118864, 0.56891583]], [[0.01866713, 0.01402144, 0.01161542, ..., 0.01377081, 0.01280605, 0.01387552], [0.0151302 , 0.01383888, 0.01402961, ..., 0.0154673 , 0.01560284, 0.01301037], [0.01429989, 0.01299902, 0.01276593, ..., 0.01552508, 0.0136844 , 0.01186959], ..., [0.66504773, 0.59481499, 0.51391958, ..., 0.56013088, 0.59331112, 0.5566361 ], [0.55830327, 0.59522938, 0.58019739, ..., 0.56561324, 0.54994777, 0.51689912], [0.62881755, 0.52399491, 0.67187741, ..., 0.64293969, 0.57774736, 0.59101913]]], 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]: