From 0f50c4b6b214945344a6b19824550691912648b9 Mon Sep 17 00:00:00 2001 From: James Beilsten-Edmands <30625594+jbeilstenedmands@users.noreply.github.com> Date: Mon, 29 Jan 2024 16:28:37 +0000 Subject: [PATCH] Validate input --- src/dials/command_line/export_bitmaps.py | 4 ++++ src/dials/util/export_bitmaps.py | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/src/dials/command_line/export_bitmaps.py b/src/dials/command_line/export_bitmaps.py index 10c2be26dd..a38886da66 100644 --- a/src/dials/command_line/export_bitmaps.py +++ b/src/dials/command_line/export_bitmaps.py @@ -173,6 +173,10 @@ def imageset_as_bitmaps(imageset, params): if params.imageset_index: selected_images = [] for idx in params.imageset_index: + if idx > len(images): + sys.exit( + f"Bad value for imageset_index: {idx}. The imageset has length {len(images)}; allowable values for imageset_index are the range 1 to {len(images)} inclusive." + ) selected_images.append(images[idx - 1]) images = selected_images diff --git a/src/dials/util/export_bitmaps.py b/src/dials/util/export_bitmaps.py index 7facbddfa3..bb1d689266 100644 --- a/src/dials/util/export_bitmaps.py +++ b/src/dials/util/export_bitmaps.py @@ -87,7 +87,12 @@ def imageset_as_flex_image( start = 1 # If the user specified an image range index, only export those + n_images = len(imageset) for i_image in images: + if (i_image < start) or (i_image >= start + n_images): + raise ValueError( + f"Image {i_image} outside of scan range {start},{start+n_images-1}" + ) image = imageset.get_raw_data(i_image - start) mask = imageset.get_mask(i_image - start)