Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CBF origin vectors off by half a pixel #564

Open
phyy-nx opened this issue Oct 20, 2022 · 0 comments
Open

CBF origin vectors off by half a pixel #564

phyy-nx opened this issue Oct 20, 2022 · 0 comments
Assignees

Comments

@phyy-nx
Copy link
Contributor

phyy-nx commented Oct 20, 2022

As discussed in dials/dials#2194 (text modified from this comment):

dxtbx is reading the header wrong for MiniCBF. ImageCIF specifies counting from the center of the pixel, not the corner, as shown in these two references:
http://www.bernstein-plus-sons.com/software/CBF/doc/cif_img_1.8.4.html#_diffrn_detector_element.reference_center_fast
http://www.bernstein-plus-sons.com/software/CBF/doc/cif_img_1.8.4.html#array_structure_list_axis

Compare to the relevant lines from FormatCBFMini, where we aren't subtracting 0.5 from the beam_xy parameter.
https://github.com/cctbx/dxtbx/blob/main/src/dxtbx/format/FormatCBFMini.py#L128
https://github.com/cctbx/dxtbx/blob/main/src/dxtbx/format/FormatCBFMini.py#L170

Likewise, FormatCBFFullPilatus uses imgCIF_H, which calls cbflib's get_pixel_coordinates(0, 0), which according to the docs, returns the center of pixel 0,0. So to go from ImageCIF to dxtbx we need to apply a half pixel correction. So with this diff (and after dials/dials#2194 is merged), the image from dials/dials#2190 displays properly:

diff --git a/src/dxtbx/model/detector.py b/src/dxtbx/model/detector.py
index 399fde70..ceeee2a0 100644
--- a/src/dxtbx/model/detector.py
+++ b/src/dxtbx/model/detector.py
@@ -768,7 +768,7 @@ class DetectorFactory:
             cbf_detector.get_inferred_pixel_size(2),
         )

-        origin = tuple(cbf_detector.get_pixel_coordinates(0, 0))
+        origin = tuple(cbf_detector.get_pixel_coordinates(-0.5, -0.5))
         fast = cbf_detector.get_detector_axis_fast()
         slow = cbf_detector.get_detector_axis_slow()
         size = tuple(reversed(cbf_handle.get_image_size(0)))

Note, this is like the cause of the 0.5 pixel offset problem @nksauter worked through in 2020 (see section 2.3.1).

Also note if we fix all the CBF format classes by subtracting this half pixel offset, we'll need to make a corresponding change to cbf_writer, which writes CBFs following the dxtbx convention instead of the ImageCIF convention. It will need to add a half pixel to the vectors it writes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant