Histogram Mode Detector#
TL;DR - Get normalized sample images averaged along the rotation angle.#
[1]:
from ess.imaging.data import get_ymir_images_path
from ess.imaging.io import FilePath
from ess.imaging.normalize import NormalizedSampleImages
from ess.imaging.workflow import (
YmirImageNormalizationWorkflow,
ImageDetectorName,
RotationMotionSensorName,
)
wf = YmirImageNormalizationWorkflow()
wf[FilePath] = (
get_ymir_images_path()
) # Replace with the path to your images in nexus file.
wf[ImageDetectorName] = 'orca'
wf[RotationMotionSensorName] = 'motion_cabinet_2'
normalized = wf.compute(NormalizedSampleImages)
normalized
Downloading file 'README.md' from 'https://public.esss.dk/groups/scipp/ess/imaging/1/README.md' to '/home/runner/.cache/essimaging/1'.
Downloading file 'small_ymir_images.hdf' from 'https://public.esss.dk/groups/scipp/ess/imaging/1/small_ymir_images.hdf' to '/home/runner/.cache/essimaging/1'.
/home/runner/work/essimaging/essimaging/.tox/docs/lib/python3.10/site-packages/ess/imaging/io.py:105: UserWarning: The unit of the histogram detector data is [None]. It is expected to be [counts]. The loader manually assigned the unit to be [counts].
warnings.warn(
/home/runner/work/essimaging/essimaging/.tox/docs/lib/python3.10/site-packages/ess/imaging/normalize.py:47: UserWarning: Computing average open beam image assuming constant exposure time.
warnings.warn(warning_message, stacklevel=1)
/home/runner/work/essimaging/essimaging/.tox/docs/lib/python3.10/site-packages/ess/imaging/normalize.py:47: UserWarning: Computing average dark current image assuming constant exposure time.
warnings.warn(warning_message, stacklevel=1)
/home/runner/work/essimaging/essimaging/.tox/docs/lib/python3.10/site-packages/ess/imaging/normalize.py:47: UserWarning: Computing average background pixel counts assuming constant exposure time.
warnings.warn(warning_message, stacklevel=1)
/home/runner/work/essimaging/essimaging/.tox/docs/lib/python3.10/site-packages/ess/imaging/normalize.py:47: UserWarning: Computing average sample pixel counts assuming constant exposure time.
warnings.warn(warning_message, stacklevel=1)
/home/runner/work/essimaging/essimaging/.tox/docs/lib/python3.10/site-packages/ess/imaging/normalize.py:47: UserWarning: Computing normalized sample image stack assuming constant exposure time.
warnings.warn(warning_message, stacklevel=1)
[1]:
scipp.DataArray (18.01 MB
)- time: 36
- dim_1: 256
- dim_2: 256
- dim_1(dim_1)int64𝟙0, 1, ..., 254, 255
Values:
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255]) - dim_2(dim_2)int64𝟙0, 1, ..., 254, 255
Values:
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255]) - rotation_angle(time)float64deg1.007, 11.034, ..., 341.951, 351.979
Values:
array([ 1.00731091, 11.03435639, 21.06173445, 31.08968206, 41.11822052, 51.14620862, 61.17432276, 71.20250242, 81.22770456, 91.25705069, 101.28393277, 111.31280002, 121.33981109, 131.36662637, 141.39534187, 151.42282542, 161.45027075, 171.47811035, 181.50597898, 191.53482643, 201.56200906, 211.58970896, 221.61798686, 231.64625132, 241.67332848, 251.70052385, 261.72550702, 271.75563946, 281.78514837, 291.81166234, 301.83935011, 311.86674052, 321.89460518, 331.92353937, 341.95077558, 351.97860336]) - 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]')
- (time, dim_1, dim_2)float64𝟙1.048, 1.062, ..., 0.992, 0.997
Values:
array([[[1.0476282 , 1.06165906, 1.04531464, ..., 1.05644014, 1.0414165 , 1.05037228], [1.05502979, 1.03332636, 1.05998197, ..., 1.04956501, 1.05474718, 1.04747274], [1.04426372, 1.06543977, 1.02916858, ..., 1.06201682, 1.05465958, 1.0536832 ], ..., [0.82613202, 0.81359233, 0.80103089, ..., 1.05969303, 1.04164473, 1.03079426], [0.83522123, 0.80806379, 0.77136373, ..., 1.08613709, 1.10307506, 0.97883198], [0.82829581, 0.76003729, 0.82939737, ..., 1.0779487 , 1.06083292, 1.0388744 ]], [[1.07754557, 1.06728106, 1.04837291, ..., 1.04092882, 1.0414165 , 1.04447528], [1.05981017, 1.04834564, 1.07451759, ..., 1.05978473, 1.06356613, 1.04971428], [1.04545417, 1.06432785, 1.03143697, ..., 1.07656832, 1.05465958, 1.04840317], ..., [0.77715187, 0.76736549, 0.77057344, ..., 0.90499331, 1.01437654, 1.0036681 ], [0.83522123, 0.7607163 , 0.78654806, ..., 1.00762116, 1.00959412, 0.96574599], [0.79692097, 0.76003729, 0.79674393, ..., 0.9941703 , 0.96489196, 0.9696161 ]], [[1.08665086, 1.07740067, 1.05550886, ..., 1.04092882, 1.04598111, 1.05037228], [1.07056602, 1.04950097, 1.07339946, ..., 1.05595233, 1.07112524, 1.05307659], [1.05735868, 1.06655169, 1.02916858, ..., 1.0511032 , 1.05922619, 1.06001924], ..., [0.80980531, 0.75195655, 0.77057344, ..., 0.98234317, 0.98710835, 0.96297885], [0.78758504, 0.7449338 , 0.77136373, ..., 0.96836319, 0.94282202, 0.90031605], [0.82829581, 0.76003729, 0.79674393, ..., 0.98020724, 0.99230366, 0.99731942]], ..., [[1.16209465, 1.11225709, 1.08099439, ..., 1.01945161, 1.01631112, 1.04329588], [1.09685811, 1.08878215, 1.11812444, ..., 1.04317768, 1.05222747, 1.03850657], [1.06331094, 1.07211128, 1.0473157 , ..., 1.07656832, 1.03525147, 1.01777898], ..., [0.8914389 , 0.90604601, 0.87717451, ..., 0.94366824, 1.00074245, 0.9222896 ], [0.86697869, 0.83962878, 0.87765401, ..., 1.02070714, 0.9962397 , 0.92648802], [0.89104549, 0.86601858, 0.89470425, ..., 0.9941703 , 0.97859781, 0.98346776]], [[1.1607939 , 1.10888388, 1.07385844, ..., 1.00632665, 0.99805267, 1.0279637 ], [1.09805321, 1.0864715 , 1.11029757, ..., 1.04828754, 1.04214867, 1.03850657], [1.05973958, 1.07211128, 1.0484499 , ..., 1.06807995, 1.03981808, 1.01355496], ..., [0.8914389 , 0.87522811, 0.89240323, ..., 0.94366824, 1.02801063, 0.96297885], [0.89873615, 0.85541128, 0.86246969, ..., 0.99453517, 0.95617644, 0.96574599], [0.85967065, 0.8508784 , 0.86205081, ..., 0.98020724, 1.04712707, 0.9696161 ]], [[1.17510221, 1.11000828, 1.07080018, ..., 1.0146789 , 1.00489959, 1.02678431], [1.11000416, 1.08069485, 1.11477007, ..., 1.02657064, 1.04340852, 1.03066117], [1.0764059 , 1.07099936, 1.04277892, ..., 1.07414307, 1.04324304, 1.01989099], ..., [0.92409234, 0.92145495, 0.83148833, ..., 1.04680138, 1.01437654, 0.97654193], [0.83522123, 0.88697627, 0.92320699, ..., 1.04687912, 0.9962397 , 0.97883198], [0.93810775, 0.8508784 , 0.92735769, ..., 1.0360595 , 0.99230366, 0.99731942]]], shape=(36, 256, 256))
[2]:
normalized['time', 0].plot(
title=f'Normalized Sample Image at Rotation Angle of {normalized.coords["rotation_angle"].values[0]:.3f}'
)
[2]:
You can use a slicer to browse images along the rotation angle.
%matplotlib widget
from plopp import slicer
slicer(normalized)
If you want to bin the images by linear steps of angles, you can use sc.groupby
like below.
%matplotlib widget
import scipp as sc
from plopp import slicer
slicer(normalized.groupby(
'rotation_angle',
bins=sc.linspace(dim='rotation_angle', start=-0.5, stop=4.5, num=5, unit='deg'),
).mean('rotation_angle'))
IO#
I/O providers can load white beam images and slice them according to the image key.
Note that not like the rotation_angle
, image_key
is not assigned as a coordinate.
Instead, we slice the data according to the image_key
and separate image stacks earlier due to performance limitation of 3-dimensional data binning.
For example, for 400 images of 2_048 x 2_048 pixels couldn’t be done in the regular laptop.
Load the data as a stack of images#
[3]:
from ess.imaging.data import get_ymir_images_path
from ess.imaging.io import (
FilePath,
SampleImageStacksWithLogs,
RawSampleImageStacks,
OpenBeamImageStacks,
DarkCurrentImageStacks,
AllImageStacks,
)
from ess.imaging.workflow import (
YmirImageNormalizationWorkflow,
ImageDetectorName,
RotationMotionSensorName,
)
wf = YmirImageNormalizationWorkflow()
wf[FilePath] = get_ymir_images_path()
wf[ImageDetectorName] = 'orca'
wf[RotationMotionSensorName] = 'motion_cabinet_2'
[4]:
image_stack_types = (
AllImageStacks,
RawSampleImageStacks,
OpenBeamImageStacks,
DarkCurrentImageStacks,
SampleImageStacksWithLogs,
)
wf.visualize(image_stack_types)
[4]:
[5]:
results = wf.compute(image_stack_types)
results[SampleImageStacksWithLogs]
[5]:
scipp.DataArray (9.01 MB
)- time: 36
- dim_1: 256
- dim_2: 256
- dim_1(dim_1)int64𝟙0, 1, ..., 254, 255
Values:
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255]) - dim_2(dim_2)int64𝟙0, 1, ..., 254, 255
Values:
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255]) - rotation_angle(time)float64deg1.007, 11.034, ..., 341.951, 351.979
Values:
array([ 1.00731091, 11.03435639, 21.06173445, 31.08968206, 41.11822052, 51.14620862, 61.17432276, 71.20250242, 81.22770456, 91.25705069, 101.28393277, 111.31280002, 121.33981109, 131.36662637, 141.39534187, 151.42282542, 161.45027075, 171.47811035, 181.50597898, 191.53482643, 201.56200906, 211.58970896, 221.61798686, 231.64625132, 241.67332848, 251.70052385, 261.72550702, 271.75563946, 281.78514837, 291.81166234, 301.83935011, 311.86674052, 321.89460518, 331.92353937, 341.95077558, 351.97860336]) - 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]')
- (time, dim_1, dim_2)int32counts950, 1090, ..., 204, 203
Values:
array([[[ 950, 1090, 1171, ..., 1058, 1087, 1065], [1027, 1039, 1094, ..., 996, 1012, 1108], [1022, 1104, 1054, ..., 1050, 1100, 1174], ..., [ 169, 171, 171, ..., 215, 209, 208], [ 171, 170, 169, ..., 213, 213, 205], [ 171, 169, 170, ..., 211, 209, 206]], [[ 973, 1095, 1174, ..., 1045, 1087, 1060], [1031, 1052, 1107, ..., 1004, 1019, 1110], [1023, 1103, 1056, ..., 1062, 1100, 1169], ..., [ 166, 168, 169, ..., 203, 207, 206], [ 171, 167, 170, ..., 207, 206, 204], [ 169, 169, 168, ..., 205, 202, 201]], [[ 980, 1104, 1181, ..., 1045, 1091, 1065], [1040, 1053, 1106, ..., 1001, 1025, 1113], [1033, 1105, 1054, ..., 1041, 1104, 1180], ..., [ 168, 167, 169, ..., 209, 205, 203], [ 168, 166, 169, ..., 204, 201, 199], [ 171, 169, 168, ..., 204, 204, 203]], ..., [[1038, 1135, 1206, ..., 1027, 1065, 1059], [1062, 1087, 1146, ..., 991, 1010, 1100], [1038, 1110, 1070, ..., 1062, 1083, 1140], ..., [ 173, 177, 176, ..., 206, 206, 200], [ 173, 172, 176, ..., 208, 205, 201], [ 175, 176, 174, ..., 205, 203, 202]], [[1037, 1132, 1199, ..., 1016, 1049, 1046], [1063, 1085, 1139, ..., 995, 1002, 1100], [1035, 1110, 1071, ..., 1055, 1087, 1136], ..., [ 173, 175, 177, ..., 206, 208, 203], [ 175, 173, 175, ..., 206, 202, 204], [ 173, 175, 172, ..., 204, 208, 201]], [[1048, 1133, 1196, ..., 1023, 1055, 1045], [1073, 1080, 1143, ..., 978, 1003, 1093], [1049, 1109, 1066, ..., 1060, 1090, 1142], ..., [ 175, 178, 173, ..., 214, 207, 204], [ 171, 175, 179, ..., 210, 205, 205], [ 178, 175, 176, ..., 208, 204, 203]]], shape=(36, 256, 256), dtype=int32)
Save Individual Frame#
[6]:
from ess.imaging.io import export_image_stacks_as_tiff, ImageKey
from pathlib import Path
from tqdm import tqdm
output_dir = Path("images")
export_image_stacks_as_tiff(
output_dir=output_dir,
image_stacks=results[AllImageStacks],
merge_image_by_key=False,
overwrite=True,
progress_wrapper=tqdm,
image_prefix_map={
ImageKey.SAMPLE: "sample",
ImageKey.DARK_CURRENT: "dc",
ImageKey.OPEN_BEAM: "ob",
},
)
0%| | 0/3 [00:00<?, ?it/s]
100%|██████████| 36/36 [00:00<00:00, 1552.90it/s]
100%|██████████| 5/5 [00:00<00:00, 1426.93it/s]
100%|██████████| 5/5 [00:00<00:00, 1563.06it/s]
100%|██████████| 3/3 [00:00<00:00, 74.35it/s]
[7]:
sorted(output_dir.iterdir())
[7]:
[PosixPath('images/dc_0000.tiff'),
PosixPath('images/dc_0001.tiff'),
PosixPath('images/dc_0002.tiff'),
PosixPath('images/dc_0003.tiff'),
PosixPath('images/dc_0004.tiff'),
PosixPath('images/ob_0000.tiff'),
PosixPath('images/ob_0001.tiff'),
PosixPath('images/ob_0002.tiff'),
PosixPath('images/ob_0003.tiff'),
PosixPath('images/ob_0004.tiff'),
PosixPath('images/sample_0000.tiff'),
PosixPath('images/sample_0001.tiff'),
PosixPath('images/sample_0002.tiff'),
PosixPath('images/sample_0003.tiff'),
PosixPath('images/sample_0004.tiff'),
PosixPath('images/sample_0005.tiff'),
PosixPath('images/sample_0006.tiff'),
PosixPath('images/sample_0007.tiff'),
PosixPath('images/sample_0008.tiff'),
PosixPath('images/sample_0009.tiff'),
PosixPath('images/sample_0010.tiff'),
PosixPath('images/sample_0011.tiff'),
PosixPath('images/sample_0012.tiff'),
PosixPath('images/sample_0013.tiff'),
PosixPath('images/sample_0014.tiff'),
PosixPath('images/sample_0015.tiff'),
PosixPath('images/sample_0016.tiff'),
PosixPath('images/sample_0017.tiff'),
PosixPath('images/sample_0018.tiff'),
PosixPath('images/sample_0019.tiff'),
PosixPath('images/sample_0020.tiff'),
PosixPath('images/sample_0021.tiff'),
PosixPath('images/sample_0022.tiff'),
PosixPath('images/sample_0023.tiff'),
PosixPath('images/sample_0024.tiff'),
PosixPath('images/sample_0025.tiff'),
PosixPath('images/sample_0026.tiff'),
PosixPath('images/sample_0027.tiff'),
PosixPath('images/sample_0028.tiff'),
PosixPath('images/sample_0029.tiff'),
PosixPath('images/sample_0030.tiff'),
PosixPath('images/sample_0031.tiff'),
PosixPath('images/sample_0032.tiff'),
PosixPath('images/sample_0033.tiff'),
PosixPath('images/sample_0034.tiff'),
PosixPath('images/sample_0035.tiff')]
Save All Frames in One File#
[8]:
from ess.imaging.io import export_image_stacks_as_tiff, ImageKey
from tqdm import tqdm
from pathlib import Path
output_dir = Path("images")
export_image_stacks_as_tiff(
output_dir=output_dir,
image_stacks=results[AllImageStacks],
merge_image_by_key=True,
overwrite=True,
progress_wrapper=tqdm,
image_prefix_map={
ImageKey.SAMPLE: "sample",
ImageKey.DARK_CURRENT: "dc",
ImageKey.OPEN_BEAM: "ob",
},
)
100%|██████████| 3/3 [00:00<00:00, 220.72it/s]
[9]:
tuple(output_dir.iterdir())
[9]:
(PosixPath('images/sample_0000_0036.tiff'),
PosixPath('images/ob_0000_0005.tiff'),
PosixPath('images/dc_0000_0005.tiff'))
[10]:
!rm -rf images
Normalization#
See :attr:ess.imaging.normalize.normalize_sample_images for more details.
[11]:
from ess.imaging.normalize import NormalizedSampleImages
wf[OpenBeamImageStacks] = results[OpenBeamImageStacks]
wf[DarkCurrentImageStacks] = results[DarkCurrentImageStacks]
wf[SampleImageStacksWithLogs] = results[SampleImageStacksWithLogs]
wf.visualize(NormalizedSampleImages)
[11]:
[12]:
wf.compute(NormalizedSampleImages)
[12]:
scipp.DataArray (18.01 MB
)- time: 36
- dim_1: 256
- dim_2: 256
- dim_1(dim_1)int64𝟙0, 1, ..., 254, 255
Values:
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255]) - dim_2(dim_2)int64𝟙0, 1, ..., 254, 255
Values:
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255]) - rotation_angle(time)float64deg1.007, 11.034, ..., 341.951, 351.979
Values:
array([ 1.00731091, 11.03435639, 21.06173445, 31.08968206, 41.11822052, 51.14620862, 61.17432276, 71.20250242, 81.22770456, 91.25705069, 101.28393277, 111.31280002, 121.33981109, 131.36662637, 141.39534187, 151.42282542, 161.45027075, 171.47811035, 181.50597898, 191.53482643, 201.56200906, 211.58970896, 221.61798686, 231.64625132, 241.67332848, 251.70052385, 261.72550702, 271.75563946, 281.78514837, 291.81166234, 301.83935011, 311.86674052, 321.89460518, 331.92353937, 341.95077558, 351.97860336]) - 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]')
- (time, dim_1, dim_2)float64𝟙1.048, 1.062, ..., 0.992, 0.997
Values:
array([[[1.0476282 , 1.06165906, 1.04531464, ..., 1.05644014, 1.0414165 , 1.05037228], [1.05502979, 1.03332636, 1.05998197, ..., 1.04956501, 1.05474718, 1.04747274], [1.04426372, 1.06543977, 1.02916858, ..., 1.06201682, 1.05465958, 1.0536832 ], ..., [0.82613202, 0.81359233, 0.80103089, ..., 1.05969303, 1.04164473, 1.03079426], [0.83522123, 0.80806379, 0.77136373, ..., 1.08613709, 1.10307506, 0.97883198], [0.82829581, 0.76003729, 0.82939737, ..., 1.0779487 , 1.06083292, 1.0388744 ]], [[1.07754557, 1.06728106, 1.04837291, ..., 1.04092882, 1.0414165 , 1.04447528], [1.05981017, 1.04834564, 1.07451759, ..., 1.05978473, 1.06356613, 1.04971428], [1.04545417, 1.06432785, 1.03143697, ..., 1.07656832, 1.05465958, 1.04840317], ..., [0.77715187, 0.76736549, 0.77057344, ..., 0.90499331, 1.01437654, 1.0036681 ], [0.83522123, 0.7607163 , 0.78654806, ..., 1.00762116, 1.00959412, 0.96574599], [0.79692097, 0.76003729, 0.79674393, ..., 0.9941703 , 0.96489196, 0.9696161 ]], [[1.08665086, 1.07740067, 1.05550886, ..., 1.04092882, 1.04598111, 1.05037228], [1.07056602, 1.04950097, 1.07339946, ..., 1.05595233, 1.07112524, 1.05307659], [1.05735868, 1.06655169, 1.02916858, ..., 1.0511032 , 1.05922619, 1.06001924], ..., [0.80980531, 0.75195655, 0.77057344, ..., 0.98234317, 0.98710835, 0.96297885], [0.78758504, 0.7449338 , 0.77136373, ..., 0.96836319, 0.94282202, 0.90031605], [0.82829581, 0.76003729, 0.79674393, ..., 0.98020724, 0.99230366, 0.99731942]], ..., [[1.16209465, 1.11225709, 1.08099439, ..., 1.01945161, 1.01631112, 1.04329588], [1.09685811, 1.08878215, 1.11812444, ..., 1.04317768, 1.05222747, 1.03850657], [1.06331094, 1.07211128, 1.0473157 , ..., 1.07656832, 1.03525147, 1.01777898], ..., [0.8914389 , 0.90604601, 0.87717451, ..., 0.94366824, 1.00074245, 0.9222896 ], [0.86697869, 0.83962878, 0.87765401, ..., 1.02070714, 0.9962397 , 0.92648802], [0.89104549, 0.86601858, 0.89470425, ..., 0.9941703 , 0.97859781, 0.98346776]], [[1.1607939 , 1.10888388, 1.07385844, ..., 1.00632665, 0.99805267, 1.0279637 ], [1.09805321, 1.0864715 , 1.11029757, ..., 1.04828754, 1.04214867, 1.03850657], [1.05973958, 1.07211128, 1.0484499 , ..., 1.06807995, 1.03981808, 1.01355496], ..., [0.8914389 , 0.87522811, 0.89240323, ..., 0.94366824, 1.02801063, 0.96297885], [0.89873615, 0.85541128, 0.86246969, ..., 0.99453517, 0.95617644, 0.96574599], [0.85967065, 0.8508784 , 0.86205081, ..., 0.98020724, 1.04712707, 0.9696161 ]], [[1.17510221, 1.11000828, 1.07080018, ..., 1.0146789 , 1.00489959, 1.02678431], [1.11000416, 1.08069485, 1.11477007, ..., 1.02657064, 1.04340852, 1.03066117], [1.0764059 , 1.07099936, 1.04277892, ..., 1.07414307, 1.04324304, 1.01989099], ..., [0.92409234, 0.92145495, 0.83148833, ..., 1.04680138, 1.01437654, 0.97654193], [0.83522123, 0.88697627, 0.92320699, ..., 1.04687912, 0.9962397 , 0.97883198], [0.93810775, 0.8508784 , 0.92735769, ..., 1.0360595 , 0.99230366, 0.99731942]]], shape=(36, 256, 256))