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] = odin.nexus_name("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/4/ymir_lego_odin.hdf' to '/home/runner/.cache/ess/odin'.
[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 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)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.004, 1.017, ..., 0.948, 0.953σ = 0.124, 0.114, ..., 0.760, 0.768
Values:
array([[[1.00378 , 1.01724381, 1.00154961, ..., 1.0122421 , 0.9978275 , 1.00638398], [1.01086006, 0.99006795, 1.01560947, ..., 1.00564787, 1.01059932, 1.00366538], [1.00056449, 1.02087742, 0.98608721, ..., 1.01754924, 1.01051488, 1.00959286], ..., [0.79150464, 0.77957189, 0.76760133, ..., 1.01538973, 0.99804237, 0.98753239], [0.80031267, 0.77428678, 0.73908402, ..., 1.0407593 , 1.05690807, 0.93790641], [0.79357392, 0.72821654, 0.79468056, ..., 1.03274866, 1.01655323, 0.995492 ]], [[1.03896217, 1.02908565, 1.0108203 , ..., 1.00367537, 1.00412598, 1.00705077], [1.02184996, 1.01079881, 1.03603524, ..., 1.02184961, 1.02548159, 1.01216207], [1.00802808, 1.02624925, 0.99449874, ..., 1.03800243, 1.01689345, 1.01087458], ..., [0.7492774 , 0.73991925, 0.74307598, ..., 0.87263132, 0.97805053, 0.96761415], [0.8053644 , 0.73351948, 0.75839 , ..., 0.97161826, 0.97344562, 0.93120865], [0.76833375, 0.73281318, 0.76821262, ..., 0.95849548, 0.93045325, 0.93499069]], [[1.05428685, 1.04533293, 1.02405839, ..., 1.0099455 , 1.01482759, 1.01906321], [1.03866902, 1.01823435, 1.04142271, ..., 1.02451498, 1.0392219 , 1.0217475 ], [1.02587545, 1.03481808, 0.99851072, ..., 1.01978074, 1.02767675, 1.02845992], ..., [0.78563718, 0.72959102, 0.74771811, ..., 0.95313261, 0.95770465, 0.93418634], [0.76417537, 0.72278859, 0.74839559, ..., 0.93959638, 0.91474338, 0.87354192], [0.80357199, 0.73739119, 0.77301177, ..., 0.95093725, 0.96286442, 0.96771264]], ..., [[1.1213915 , 1.07332085, 1.0431176 , ..., 0.98376307, 0.98071337, 1.00672849], [1.05842762, 1.05063748, 1.07895369, ..., 1.00665182, 1.0153708 , 1.00216646], [1.02607611, 1.03459162, 1.01062682, ..., 1.03884328, 0.99898891, 0.98214157], ..., [0.86016148, 0.87434731, 0.84655827, ..., 0.91066035, 0.96568632, 0.88987923], [0.83666383, 0.81026656, 0.84691991, ..., 0.98503398, 0.96134748, 0.89407832], [0.85977774, 0.83567469, 0.8633638 , ..., 0.95927193, 0.94443435, 0.94911592]], [[1.10573183, 1.05630515, 1.02290619, ..., 0.95860968, 0.95070946, 0.97917786], [1.04595509, 1.0349257 , 1.05762326, ..., 0.99857424, 0.99271286, 0.98927903], [1.00947924, 1.02128722, 0.99871098, ..., 1.01739861, 0.99049233, 0.96548795], ..., [0.84910017, 0.83374631, 0.85018009, ..., 0.89894965, 0.97924262, 0.91719028], [0.85615761, 0.81488159, 0.82156471, ..., 0.94743438, 0.91082203, 0.91997835], [0.81883681, 0.81050645, 0.82115689, ..., 0.93363644, 0.9975757 , 0.92371477]], [[1.12243308, 1.06027779, 1.02279201, ..., 0.96921826, 0.95985835, 0.98073833], [1.06024047, 1.03224797, 1.0647975 , ..., 0.98057066, 0.99664036, 0.98449971], [1.02816881, 1.02302763, 0.99603479, ..., 1.02598174, 0.9964818 , 0.97418947], ..., [0.88261812, 0.88019094, 0.79432106, ..., 0.99993193, 0.96890683, 0.93266078], [0.79783513, 0.84726966, 0.88183461, ..., 1.00003605, 0.95158909, 0.93500291], [0.8960002 , 0.81273057, 0.8857898 , ..., 0.98954308, 0.94794074, 0.95271382]]], shape=(36, 256, 256))
Variances (σ²):
array([[[0.01542391, 0.01305792, 0.01120013, ..., 0.01479976, 0.01365563, 0.01448088], [0.01394227, 0.01288809, 0.01293288, ..., 0.016124 , 0.0159634 , 0.01343396], [0.01365086, 0.01294853, 0.01254833, ..., 0.01530932, 0.01400496, 0.0125991 ], ..., [0.58302722, 0.51391519, 0.4947674 , ..., 0.57261822, 0.61832352, 0.60122908], [0.56103611, 0.53538519, 0.47082462, ..., 0.59872348, 0.63648642, 0.51951596], [0.54225705, 0.46271478, 0.5892087 , ..., 0.68231688, 0.63652927, 0.62800525]], [[0.01637881, 0.01334288, 0.01139877, ..., 0.01462188, 0.01382857, 0.01452721], [0.01422748, 0.01337402, 0.01340458, ..., 0.01659301, 0.01639109, 0.01365292], [0.01385038, 0.01308918, 0.01275458, ..., 0.01586045, 0.01418232, 0.01265124], ..., [0.55085643, 0.48721259, 0.47969071, ..., 0.4700495 , 0.60384594, 0.5871656 ], [0.5681412 , 0.50681004, 0.48726465, ..., 0.54635462, 0.56976806, 0.51679425], [0.52523086, 0.4685747 , 0.56978673, ..., 0.6184374 , 0.56693627, 0.57952432]], [[0.01682225, 0.0137296 , 0.01167644, ..., 0.01480514, 0.01410457, 0.01484806], [0.01465503, 0.01356696, 0.01354846, ..., 0.01670014, 0.0167937 , 0.01389839], [0.0142954 , 0.01330052, 0.0128665 , ..., 0.0154293 , 0.01446438, 0.01304976], ..., [0.58419382, 0.48253824, 0.48570285, ..., 0.5293873 , 0.58941626, 0.562681 ], [0.53772358, 0.5017 , 0.482763 , ..., 0.52453103, 0.52686488, 0.47805238], [0.55600669, 0.47444752, 0.57692808, ..., 0.61451889, 0.59575886, 0.60917887]], ..., [[0.01866572, 0.01434441, 0.01203387, ..., 0.01414745, 0.01329986, 0.01452339], [0.01510974, 0.01428795, 0.01437551, ..., 0.01619013, 0.01612756, 0.01343149], [0.01427667, 0.01327452, 0.01310992, ..., 0.01588616, 0.01377149, 0.01205787], ..., [0.64788713, 0.5935161 , 0.55883988, ..., 0.4967144 , 0.5938713 , 0.52639835], [0.59500607, 0.56781684, 0.55522872, ..., 0.55694044, 0.5605242 , 0.49042313], [0.60059769, 0.54561669, 0.65467693, ..., 0.61943976, 0.57852261, 0.59146179]], [[0.01815366, 0.01390494, 0.01159343, ..., 0.01349405, 0.01257725, 0.01380818], [0.01475109, 0.01387231, 0.01383957, ..., 0.0159046 , 0.01546659, 0.01308827], [0.01383264, 0.01293531, 0.01279838, ..., 0.01527626, 0.01351837, 0.01166856], ..., [0.63133117, 0.55405622, 0.55626035, ..., 0.48402147, 0.6001847 , 0.54239305], [0.60600872, 0.56571713, 0.52964275, ..., 0.52392364, 0.51725675, 0.50440442], [0.56016319, 0.52047347, 0.60963943, ..., 0.59236188, 0.61787664, 0.56563057]], [[0.0186436 , 0.01400578, 0.01160011, ..., 0.01375455, 0.01278991, 0.01385765], [0.01510988, 0.01382199, 0.01401236, ..., 0.01544837, 0.01558274, 0.0129946 ], [0.01428252, 0.01298336, 0.01275094, ..., 0.01550653, 0.01366744, 0.01185526], ..., [0.66404118, 0.59405273, 0.51344959, ..., 0.55945966, 0.59260813, 0.55552241], [0.55756787, 0.59446731, 0.57957324, ..., 0.5650617 , 0.54920248, 0.51630438], [0.62796884, 0.52333386, 0.67095712, ..., 0.64180486, 0.57743434, 0.59044158]]], 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]: