Skip to content

Commit

Permalink
Add fast_slow_beam_centre = option for setting beam centre (#421)
Browse files Browse the repository at this point in the history
And switch internally to use this for more consistency. This will error if both are set.
  • Loading branch information
dagewa authored Oct 29, 2021
1 parent f7bd120 commit 605c397
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 18 deletions.
1 change: 1 addition & 0 deletions newsfragments/421.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
New ``fast_slow_beam_centre=`` parameter for detector models allows setting the beam centre using fast, slow [panel] value ordering
54 changes: 40 additions & 14 deletions src/dxtbx/model/detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
find_gain_value,
find_undefined_value,
set_detector_distance,
set_fast_slow_beam_centre_mm,
set_mosflm_beam_centre,
set_slow_fast_beam_centre_mm,
)
from dxtbx_model_ext import (
Detector,
Expand Down Expand Up @@ -180,12 +180,19 @@
.help = "The detector distance (used when mosflm_beam_centre is set)"
.short_caption = "Detector distance"
slow_fast_beam_centre = None
fast_slow_beam_centre = None
.type = ints(size_min=2, size_max=3)
.help = "Override the beam centre from the image headers, following "
"the slow/fast pixel convention used by dials.image_viewer."
"The first two values are the slow and fast pixel coordinate."
.help = "Override the beam centre from the image headers."
"The first two values are the fast and slow pixel coordinate."
"If the third is supplied it specifies a panel number."
.short_caption = "Beam centre coordinates (px fast, px slow, [panel id])"
slow_fast_beam_centre = None
.type = ints(size_min=2, size_max=3)
.help = "Alternative to fast_slow_beam_centre in which the coordinates"
"are given in order (px slow, px fast, [panel id]). If"
"fast_slow_beam_centre is set it will take priority over any"
"values set here."
.short_caption = "Beam centre coordinates (px slow, px fast, [panel id])"
}
"""
Expand Down Expand Up @@ -438,21 +445,40 @@ def from_phil(params, reference=None, beam=None):
assert beam is not None
set_mosflm_beam_centre(detector, beam, params.detector.mosflm_beam_centre)

# If the slow fast beam centre is set then update
if params.detector.slow_fast_beam_centre is not None:
fast_slow_beam_centre = None
if (
params.detector.fast_slow_beam_centre
and params.detector.slow_fast_beam_centre
):
raise RuntimeError(
"Can only set one of fast_slow_beam_centre or slow_fast_beam_centre"
)

if params.detector.slow_fast_beam_centre:
fast_slow_beam_centre = list(params.detector.slow_fast_beam_centre)
fast_slow_beam_centre[0], fast_slow_beam_centre[1] = (
fast_slow_beam_centre[1],
fast_slow_beam_centre[0],
)

if params.detector.fast_slow_beam_centre:
fast_slow_beam_centre = params.detector.fast_slow_beam_centre

# If the fast slow beam centre is set then update
if fast_slow_beam_centre is not None:
panel_id = 0
if len(params.detector.slow_fast_beam_centre) > 2:
panel_id = params.detector.slow_fast_beam_centre[2]
if len(fast_slow_beam_centre) > 2:
panel_id = fast_slow_beam_centre[2]
if panel_id >= len(detector):
raise IndexError(f"Detector does not have panel index {panel_id}")
px_size_f, px_size_s = detector[0].get_pixel_size()
slow_fast_beam_centre_mm = (
params.detector.slow_fast_beam_centre[0] * px_size_s,
params.detector.slow_fast_beam_centre[1] * px_size_f,
fast_slow_beam_centre_mm = (
fast_slow_beam_centre[0] * px_size_f,
fast_slow_beam_centre[1] * px_size_s,
)
assert beam is not None
set_slow_fast_beam_centre_mm(
detector, beam, slow_fast_beam_centre_mm, panel_id=panel_id
set_fast_slow_beam_centre_mm(
detector, beam, fast_slow_beam_centre_mm, panel_id=panel_id
)

return detector
Expand Down
17 changes: 13 additions & 4 deletions src/dxtbx/model/detector_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,20 @@ def all():


def set_slow_fast_beam_centre_mm(detector, beam, beam_centre, panel_id=None):
beam_centre[0], beam_centre[1] = beam_centre[1], beam_centre[0]
warnings.warn(
"set_slow_fast_beam_centre_mm is deprecated", DeprecationWarning, stacklevel=2
)
return set_fast_slow_beam_centre_mm(detector, beam, beam_centre, panel_id)


def set_fast_slow_beam_centre_mm(detector, beam, beam_centre, panel_id=None):
"""detector and beam are dxtbx objects,
beam_centre is a tuple of (slow, fast) mm coordinates.
beam_centre is a tuple of (fast, slow) mm coordinates.
supports 2-theta offset detectors, assumes correct centre provided
for 2-theta=0
"""
beam_s, beam_f = beam_centre
beam_f, beam_s = beam_centre

# Ensure panel_id is set
us0 = matrix.col(beam.get_unit_s0())
Expand Down Expand Up @@ -282,11 +290,12 @@ def set_slow_fast_beam_centre_mm(detector, beam, beam_centre, panel_id=None):

def set_mosflm_beam_centre(detector, beam, mosflm_beam_centre):
"""detector and beam are dxtbx objects,
mosflm_beam_centre is a tuple of mm coordinates.
mosflm_beam_centre is a tuple of mm coordinates in order (slow, fast).
supports 2-theta offset detectors, assumes correct centre provided
for 2-theta=0
"""
return set_slow_fast_beam_centre_mm(detector, beam, mosflm_beam_centre)
slow_fast_beam_centre = mosflm_beam_centre[1], mosflm_beam_centre[0]
return set_fast_slow_beam_centre_mm(detector, beam, slow_fast_beam_centre)


def set_detector_distance(detector, distance):
Expand Down

0 comments on commit 605c397

Please sign in to comment.