Odin: Orca image normalization workflow#

This notebook shows how to use the workflow to compute normalized images recorded by the Orca detector on the ODIN instrument.

[1]:
import ess.odin.data  # noqa: F401
from ess import odin
from ess.imaging.types import *
import scipp as sc
import plopp as pp

%matplotlib widget

Workflow setup#

[2]:
wf = odin.OdinOrcaWorkflow()

wf[Filename[AllRuns]] = odin.data.odin_lego_images()

wf[NeXusDetectorName] = 'histogram_mode_detectors/orca'

wf[MaskingRules] = {}  # No masks to begin with
wf[UncertaintyBroadcastMode] = UncertaintyBroadcastMode.upper_bound
Downloading file 'ymir_lego_odin.hdf' from 'https://public.esss.dk/groups/scipp/ess/odin/2/ymir_lego_odin.hdf' to '/home/runner/.cache/ess/odin'.
[3]:
wf.visualize(NormalizedImage, compact=True, graph_attr={"rankdir": "LR"})
[3]:
../_images/odin_odin-orca-image-normalization_4_0.svg

Run the workflow#

We compute the final normalized image:

[4]:
image = wf.compute(NormalizedImage)
image
[4]:
Show/Hide data repr Show/Hide attributes
scipp.DataArray (37.51 MB)
    • time: 36
    • y_pixel_offset: 256
    • x_pixel_offset: 256
    • position
      (y_pixel_offset, x_pixel_offset)
      vector3
      m
      [-0.1 -0.1 1. ], [-0.09921569 -0.1 1. ], ..., [0.09921569 0.1 1. ], [0.1 0.1 1. ]
      Values:
      array([[[-0.1 , -0.1 , 1. ], [-0.09921569, -0.1 , 1. ], [-0.09843137, -0.1 , 1. ], ..., [ 0.09843137, -0.1 , 1. ], [ 0.09921569, -0.1 , 1. ], [ 0.1 , -0.1 , 1. ]], [[-0.1 , -0.09921569, 1. ], [-0.09921569, -0.09921569, 1. ], [-0.09843137, -0.09921569, 1. ], ..., [ 0.09843137, -0.09921569, 1. ], [ 0.09921569, -0.09921569, 1. ], [ 0.1 , -0.09921569, 1. ]], [[-0.1 , -0.09843137, 1. ], [-0.09921569, -0.09843137, 1. ], [-0.09843137, -0.09843137, 1. ], ..., [ 0.09843137, -0.09843137, 1. ], [ 0.09921569, -0.09843137, 1. ], [ 0.1 , -0.09843137, 1. ]], ..., [[-0.1 , 0.09843137, 1. ], [-0.09921569, 0.09843137, 1. ], [-0.09843137, 0.09843137, 1. ], ..., [ 0.09843137, 0.09843137, 1. ], [ 0.09921569, 0.09843137, 1. ], [ 0.1 , 0.09843137, 1. ]], [[-0.1 , 0.09921569, 1. ], [-0.09921569, 0.09921569, 1. ], [-0.09843137, 0.09921569, 1. ], ..., [ 0.09843137, 0.09921569, 1. ], [ 0.09921569, 0.09921569, 1. ], [ 0.1 , 0.09921569, 1. ]], [[-0.1 , 0.1 , 1. ], [-0.09921569, 0.1 , 1. ], [-0.09843137, 0.1 , 1. ], ..., [ 0.09843137, 0.1 , 1. ], [ 0.09921569, 0.1 , 1. ], [ 0.1 , 0.1 , 1. ]]], shape=(256, 256, 3))
    • time
      (time)
      datetime64
      ns
      2024-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)
      float64
      m
      -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)
      float64
      m
      -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.019, 1.032, ..., 0.961, 0.965
      σ = 0.126, 0.116, ..., 0.770, 0.779
      Values:
      array([[[1.01864338, 1.03228618, 1.01641751, ..., 1.02722369, 1.01261973, 1.02132025], [1.02585895, 1.00474485, 1.03066916, ..., 1.02054464, 1.02557613, 1.0184681 ], [1.01538401, 1.03595063, 1.00069851, ..., 1.03266834, 1.0254901 , 1.02452273], ..., [0.80329133, 0.79105537, 0.77884898, ..., 1.0303825 , 1.0128954 , 1.00228606], [0.81211228, 0.78568408, 0.75005071, ..., 1.0560449 , 1.07256099, 0.95177527], [0.80537185, 0.73897752, 0.80638151, ..., 1.04818057, 1.03150572, 1.01016382]], [[1.03314446, 1.02330305, 1.0051973 , ..., 0.99804836, 0.99852008, 1.00144541], [1.01615845, 1.00515536, 1.03025505, ..., 1.01613343, 1.01975173, 1.00643614], [1.00238728, 1.02046003, 0.98893978, ..., 1.0322419 , 1.01121125, 1.00519492], ..., [0.74514353, 0.73572027, 0.73880265, ..., 0.86770917, 0.97264553, 0.96232161], [0.80080448, 0.72934909, 0.75416624, ..., 0.96606297, 0.96799734, 0.92597572], [0.76407617, 0.72868805, 0.76384826, ..., 0.95325527, 0.92515341, 0.92969181]], [[1.05242266, 1.04346398, 1.02228541, ..., 1.00815275, 1.01305016, 1.01729549], [1.03686344, 1.01645066, 1.03960259, ..., 1.02270918, 1.03739694, 1.01988179], [1.02406528, 1.03294509, 0.99675501, ..., 1.01802865, 1.02587172, 1.02662176], ..., [0.78431301, 0.72824575, 0.7462824 , ..., 0.95140801, 0.95608165, 0.93265629], [0.76277629, 0.72144822, 0.74709495, ..., 0.93782366, 0.91312835, 0.87197982], [0.80219809, 0.7360654 , 0.77158158, ..., 0.94938222, 0.96106867, 0.9659357 ]], ..., [[1.12811841, 1.07973808, 1.04941372, ..., 0.98965755, 0.98661293, 1.01280161], [1.06480866, 1.05695737, 1.08544829, ..., 1.01269612, 1.02147411, 1.00811979], [1.03223505, 1.0407543 , 1.01669934, ..., 1.04512746, 1.00499342, 0.98801426], ..., [0.86539305, 0.87952559, 0.85150693, ..., 0.91608533, 0.97155075, 0.89533426], [0.84162992, 0.81505669, 0.85202619, ..., 0.9908253 , 0.9671169 , 0.89942358], [0.86498595, 0.84066261, 0.86847156, ..., 0.96515484, 0.95000761, 0.95474433]], [[1.11579037, 1.06589303, 1.03224941, ..., 0.96732321, 0.9593739 , 0.98811838], [1.05550141, 1.04435734, 1.06726605, ..., 1.00766365, 1.00175545, 0.99822043], [1.01866595, 1.03053447, 1.00780595, ..., 1.02670513, 0.99951437, 0.9742521 ], ..., [0.8568952 , 0.84126689, 0.85778338, ..., 0.90708971, 0.9882233 , 0.92565457], [0.86389163, 0.8222233 , 0.82906342, ..., 0.95593946, 0.91910997, 0.9283285 ], [0.82633393, 0.81785503, 0.82855869, ..., 0.94225494, 1.00655275, 0.93205403]], [[1.13747404, 1.07446464, 1.03653603, ..., 0.98219931, 0.97273707, 0.99391393], [1.07448016, 1.04609766, 1.07908825, ..., 0.9937162 , 1.01000791, 0.99763454], [1.04195044, 1.03669315, 1.00939196, ..., 1.0397824 , 1.00984689, 0.98722504], ..., [0.8945196 , 0.89191816, 0.80484271, ..., 1.01328951, 0.98196281, 0.94528215], [0.80847564, 0.85854916, 0.89367859, ..., 1.01331656, 0.96434324, 0.94751323], [0.90806006, 0.82359687, 0.89758596, ..., 1.00293682, 0.96055029, 0.96541469]]], shape=(36, 256, 256))

      Variances (σ²):
      array([[[0.01588376, 0.01344661, 0.01153506, ..., 0.01524074, 0.01406334, 0.01491384], [0.01435899, 0.01327287, 0.01331912, ..., 0.01660495, 0.01643983, 0.01383254], [0.01405798, 0.01333326, 0.01292275, ..., 0.0157677 , 0.01442292, 0.01297413], ..., [0.60055365, 0.52912142, 0.50929615, ..., 0.58961347, 0.63689889, 0.61939796], [0.57765726, 0.55121005, 0.48490391, ..., 0.6163465 , 0.65546488, 0.534971 ], [0.55851832, 0.47647043, 0.60663037, ..., 0.70294476, 0.65530917, 0.64659158]], [[0.01619558, 0.013193 , 0.01127224, ..., 0.01445806, 0.01367443, 0.01436588], [0.01406934, 0.01322493, 0.01325528, ..., 0.01640761, 0.01620821, 0.01349829], [0.01369557, 0.01294147, 0.0126122 , ..., 0.01568496, 0.01402407, 0.01250913], ..., [0.54482315, 0.48165894, 0.47411991, ..., 0.46473366, 0.59722207, 0.5808245 ], [0.56168273, 0.5010182 , 0.48185552, ..., 0.54004702, 0.56339662, 0.51098077], [0.51944236, 0.46329412, 0.56327967, ..., 0.61176356, 0.5604292 , 0.57292215]], [[0.01676249, 0.01368018, 0.01163598, ..., 0.01475229, 0.01405504, 0.01479653], [0.01460403, 0.0135193 , 0.01350099, ..., 0.01664104, 0.01673454, 0.01384707], [0.01424475, 0.01325195, 0.0128211 , ..., 0.01537638, 0.01441341, 0.0130028 ], ..., [0.58225748, 0.48072165, 0.48376863, ..., 0.52743951, 0.5874509 , 0.56089998], [0.53571728, 0.49979662, 0.48108968, ..., 0.52248031, 0.52499595, 0.47632506], [0.55412503, 0.47272254, 0.57474287, ..., 0.61257998, 0.59346648, 0.60688751]], ..., [[0.01888997, 0.01451606, 0.01217952, ..., 0.01431718, 0.01346019, 0.01469908], [0.01529237, 0.01446018, 0.01454893, ..., 0.01638486, 0.0163218 , 0.01359095], [0.01444832, 0.01343267, 0.01326773, ..., 0.016079 , 0.01393735, 0.01220217], ..., [0.6558302 , 0.60051053, 0.56530033, ..., 0.50261876, 0.60113782, 0.53292775], [0.60204282, 0.57449371, 0.5619483 , ..., 0.56342668, 0.56726084, 0.49628435], [0.60791702, 0.55212273, 0.66237979, ..., 0.62713228, 0.58530006, 0.59844258]], [[0.01848507, 0.01415813, 0.01180612, ..., 0.01374017, 0.0128074 , 0.01406143], [0.01502148, 0.01412613, 0.01409292, ..., 0.01619519, 0.01574942, 0.01332534], [0.0140853 , 0.01317016, 0.01303235, ..., 0.01555707, 0.01376557, 0.01188104], ..., [0.64301341, 0.56404502, 0.56616075, ..., 0.49279616, 0.61127661, 0.55250992], [0.61695663, 0.57589914, 0.53935929, ..., 0.53329614, 0.52670274, 0.51358074], [0.57048672, 0.52992891, 0.620619 , ..., 0.60341688, 0.62896779, 0.57583729]], [[0.01914623, 0.0143827 , 0.0119139 , ..., 0.01412515, 0.01313528, 0.01423243], [0.01551837, 0.0141952 , 0.01439084, ..., 0.01586508, 0.01600333, 0.01334307], [0.01466771, 0.01333207, 0.01309503, ..., 0.01592656, 0.01403633, 0.01217432], ..., [0.68211088, 0.60992977, 0.52705973, ..., 0.57446826, 0.60871883, 0.57072183], [0.57249535, 0.61033786, 0.59525097, ..., 0.58008381, 0.56401174, 0.53019053], [0.64501013, 0.53739587, 0.68887567, ..., 0.65937374, 0.59282645, 0.606233 ]]], 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(
    [
        FluxNormalizedDetector[SampleRun],
        FluxNormalizedDetector[OpenBeamRun],
        BackgroundSubtractedDetector[SampleRun],
    ]
)

fig = pp.tiled(2, 2, hspace=0.3, wspace=0.3)
fig[0, 0] = results[FluxNormalizedDetector[SampleRun]]['time', 0].plot(
    title='Sample (proton-charge normalized)'
)
fig[0, 1] = results[FluxNormalizedDetector[OpenBeamRun]]['time', 0].plot(
    title='Open beam (proton-charge normalized)'
)
fig[1, 0] = results[BackgroundSubtractedDetector[SampleRun]]['time', 0].plot(
    title='Background subtracted sample'
)
fig[1, 1] = image['time', 0].plot(title='Final image')
fig
[7]: