Skip to content

Commit

Permalink
Improve exclude_images option for handling multi-sweep exclusions (di…
Browse files Browse the repository at this point in the history
  • Loading branch information
jbeilstenedmands committed Feb 4, 2022
1 parent e548cb4 commit ed5cefa
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 29 deletions.
1 change: 1 addition & 0 deletions newsfragments/1996.feature
@@ -0,0 +1 @@
For data reduction programs, allow exclude_images option to take a single multi-sweep command, e.g. exclude_images=0:100:120,1:150:180
24 changes: 16 additions & 8 deletions tests/util/test_exclude_images.py
Expand Up @@ -34,14 +34,22 @@ def make_scanless_experiment(expid="1"):

def test_parse_exclude_images_commands():
"""Test for namesake function"""
commands = [["1:101:200"], ["0:201:300"]]
r1 = flex.reflection_table()
r1.experiment_identifiers()[1] = "1"
r0 = flex.reflection_table()
r0.experiment_identifiers()[0] = "0"
tables = [r0, r1]
ranges = _parse_exclude_images_commands(commands, [], tables)
assert ranges == [("1", (101, 200)), ("0", (201, 300))]
formats = (
[["1:101:200"], ["0:201:300"]], # if given as separate exclude_images=
[["1:101:200,0:201:300"]], # if given as exclude_images="1:101:200,0:201:300"
[
["1:101:200", "0:201:300"]
], # if given as exclude_images="1:101:200 0:201:300"
)
for command in formats:
r1 = flex.reflection_table()
r1.experiment_identifiers()[1] = "1"
r0 = flex.reflection_table()
r0.experiment_identifiers()[0] = "0"
tables = [r0, r1]
ranges = _parse_exclude_images_commands(command, [], tables)
assert ranges == [("1", (101, 200)), ("0", (201, 300))]

experiments = ["1", "2"]
short_command = [["101:200"]]
with pytest.raises(ValueError):
Expand Down
52 changes: 31 additions & 21 deletions util/exclude_images.py
Expand Up @@ -20,6 +20,9 @@
.help = "Input in the format exp:start:end"
"Exclude a range of images (start, stop) from the dataset with"
"experiment identifier exp (inclusive of frames start, stop)."
"Multiple ranges can be given in one go, e.g."
"exclude_images=0:150:200,1:200:250"
"exclude_images='0:150:200 1:200:250'"
.short_caption = "Exclude images"
.expert_level = 1
"""
Expand Down Expand Up @@ -91,28 +94,35 @@ def _parse_exclude_images_commands(commands, experiments, reflections):
"""
ranges_to_remove = []
for com in commands:
vals = com[0].split(":")
if len(vals) == 2:
if len(experiments) > 1:
raise ValueError(
"Exclude images must be in the form experimentnumber:start:stop for multiple experiments"
)
else:
ranges_to_remove.append(
(experiments[0].identifier, (int(vals[0]), int(vals[1])))
)
if len(com) > 1:
sub = com
elif "," in com[0]:
sub = com[0].split(",")
else:
if len(vals) != 3:
raise ValueError(
"Exclude images must be input in the form experimentnumber:start:stop, or start:stop for a single experiment"
)
dataset_id = int(vals[0])
for table in reflections:
if dataset_id in table.experiment_identifiers():
expid = table.experiment_identifiers()[dataset_id]
ranges_to_remove.append((expid, (int(vals[1]), int(vals[2]))))
break

sub = com
for subvals in sub:
vals = subvals.split(":")
if len(vals) == 2:
if len(experiments) > 1:
raise ValueError(
"Exclude images must be in the form experimentnumber:start:stop for multiple experiments"
)
else:
ranges_to_remove.append(
(experiments[0].identifier, (int(vals[0]), int(vals[1])))
)
else:
if len(vals) != 3:
raise ValueError(
"Exclude images must be input in the form experimentnumber:start:stop, or start:stop for a single experiment"
+ "Multiple ranges can be specified by comma or space separated values e.g 0:100:150,1:120:200"
)
dataset_id = int(vals[0])
for table in reflections:
if dataset_id in table.experiment_identifiers():
expid = table.experiment_identifiers()[dataset_id]
ranges_to_remove.append((expid, (int(vals[1]), int(vals[2]))))
break
return ranges_to_remove


Expand Down

0 comments on commit ed5cefa

Please sign in to comment.