Skip to content

Commit

Permalink
DIALS 3.1.1
Browse files Browse the repository at this point in the history
- Don't crash handling FormatSMVADSC images with floating-point pedestal values (cctbx#216)
- Allow importing filenames with special format characters like % (cctbx#214)
  • Loading branch information
ndevenish authored Sep 1, 2020
2 parents 979ede8 + f6aec9f commit 4526053
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 8 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
DIALS 3.1.1 (2020-09-01)
========================

Bugfixes
--------

- Don't crash handling FormatSMVADSC images with floating-point pedestal values (#216)
- Allow importing filenames with special format characters like % (#214)


DIALS 3.1 (2020-08-17)
======================

Expand Down
4 changes: 2 additions & 2 deletions format/FormatSMVADSC.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def _adsc_trusted_range(self, pedestal=None):
pedestal that is present"""

if pedestal is None:
pedestal = int(self._header_dictionary.get("IMAGE_PEDESTAL", 0))
pedestal = float(self._header_dictionary.get("IMAGE_PEDESTAL", 0))

overload = 65535 - pedestal
underload = -1 - pedestal
Expand Down Expand Up @@ -178,7 +178,7 @@ def _detector(self):
self._adsc_trusted_range(),
[],
gain=self._adsc_module_gain(),
pedestal=int(self._header_dictionary.get("IMAGE_PEDESTAL", 0)),
pedestal=float(self._header_dictionary.get("IMAGE_PEDESTAL", 0)),
)

def _beam(self):
Expand Down
2 changes: 1 addition & 1 deletion format/FormatSMVRigakuSaturnNoTS.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def _detector(self):
pixel_size,
image_size,
(underload, overload),
pedestal=int(self._header_dictionary.get("IMAGE_PEDESTAL"), 0),
pedestal=float(self._header_dictionary.get("IMAGE_PEDESTAL"), 0),
)

def _beam(self):
Expand Down
30 changes: 25 additions & 5 deletions imageset.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,11 @@ def from_template(
# Get the template format
pfx = template.split("#")[0]
sfx = template.split("#")[-1]
template_format = "%s%%0%dd%s" % (pfx, template.count("#"), sfx)
template_format = "%s%%0%dd%s" % (
pfx.replace("%", "%%"),
template.count("#"),
sfx.replace("%", "%%"),
)

# Get the template image range
if image_range is None:
Expand Down Expand Up @@ -450,7 +454,11 @@ def _create_imageset(filelist, check_headers):
if count > 0:
pfx = template.split("#")[0]
sfx = template.split("#")[-1]
template_format = "%s%%0%dd%s" % (pfx, template.count("#"), sfx)
template_format = "%s%%0%dd%s" % (
pfx.replace("%", "%%"),
template.count("#"),
sfx.replace("%", "%%"),
)
filenames = [template_format % index for index in indices]
else:
filenames = [template]
Expand All @@ -475,7 +483,11 @@ def _create_sequence(filelist, check_headers):
if count > 0:
pfx = template.split("#")[0]
sfx = template.split("#")[-1]
template_format = "%s%%0%dd%s" % (pfx, template.count("#"), sfx)
template_format = "%s%%0%dd%s" % (
pfx.replace("%", "%%"),
template.count("#"),
sfx.replace("%", "%%"),
)
filenames = [template_format % index for index in indices]
else:
filenames = [template]
Expand All @@ -489,7 +501,11 @@ def _create_sequence(filelist, check_headers):
# Get the template format
pfx = template.split("#")[0]
sfx = template.split("#")[-1]
template_format = "%s%%0%dd%s" % (pfx, template.count("#"), sfx)
template_format = "%s%%0%dd%s" % (
pfx.replace("%", "%%"),
template.count("#"),
sfx.replace("%", "%%"),
)

# Set the image range
array_range = range(min(indices) - 1, max(indices))
Expand Down Expand Up @@ -559,7 +575,11 @@ def make_sequence(
if count > 0:
pfx = template.split("#")[0]
sfx = template.split("#")[-1]
template_format = "%s%%0%dd%s" % (pfx, template.count("#"), sfx)
template_format = "%s%%0%dd%s" % (
pfx.replace("%", "%%"),
template.count("#"),
sfx.replace("%", "%%"),
)
filenames = [template_format % index for index in indices]
else:
template_format = None
Expand Down
20 changes: 20 additions & 0 deletions tests/format/test_FormatSMVADSC.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import os

import dxtbx


def test_noninteger_pedestal(dials_regression, tmpdir):
filename = os.path.join(
dials_regression, "image_examples/APS_14BMC/q315_1_001.img",
)
# Read this file in as data
with open(filename, "rb") as f:
data = f.read()

# Write out with an inserted header item of a noninteger pedestal
test_file = tmpdir / "test_pedestal_001.img"
with test_file.open("wb") as f:
f.write(data.replace(b"DIM=2;\n", b"DIM=2;\nIMAGE_PEDESTAL=42.0;\n"))

# Make sure this loads
dxtbx.load(test_file)
24 changes: 24 additions & 0 deletions tests/test_imageset.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,30 @@ def test_imagesetfactory(centroid_files, dials_data):
assert len(sequence) == 4


def test_make_sequence_with_percent_character(dials_data, tmp_path):
images = [
dials_data("centroid_test_data").join(f"centroid_{i:04}.cbf")
for i in range(1, 10)
]
directory = tmp_path / "test%"
directory.mkdir()
for image in images:
(directory / image.basename).symlink_to(image)
template = str(directory / "centroid_####.cbf")
sequence = ImageSetFactory.make_sequence(template, list(range(1, 10)))
assert len(sequence) == 9

sequences = ImageSetFactory.new(
[str(directory / image.basename) for image in images]
)
assert len(sequences) == 1
assert len(sequences[0]) == 9

sequences = ImageSetFactory.from_template(template)
assert len(sequences) == 1
assert len(sequences[0]) == 9


def test_pickle_imageset(centroid_files):
sequence = ImageSetFactory.new(centroid_files)[0]

Expand Down

0 comments on commit 4526053

Please sign in to comment.