Skip to content

Commit

Permalink
Deprecate SequenceDiff pseudoclass
Browse files Browse the repository at this point in the history
[skip ci] [ci skip]
  • Loading branch information
Anthchirp committed Feb 12, 2021
1 parent 218a0bc commit 8b92256
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 36 deletions.
46 changes: 13 additions & 33 deletions datablock.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import operator
import os.path
import pickle
import warnings

import libtbx
from scitbx import matrix
Expand Down Expand Up @@ -1820,38 +1821,17 @@ def mod_2pi(x):

class SequenceDiff:
def __init__(self, tolerance):

if tolerance is None:
self.b_diff = BeamDiff()
self.d_diff = DetectorDiff()
self.g_diff = GoniometerDiff()
self.s_diff = ScanDiff()
else:
self.b_diff = BeamDiff(
wavelength_tolerance=tolerance.beam.wavelength,
direction_tolerance=tolerance.beam.direction,
polarization_normal_tolerance=tolerance.beam.polarization_normal,
polarization_fraction_tolerance=tolerance.beam.polarization_fraction,
)

self.d_diff = DetectorDiff(
fast_axis_tolerance=tolerance.detector.fast_axis,
slow_axis_tolerance=tolerance.detector.slow_axis,
origin_tolerance=tolerance.detector.origin,
)

self.g_diff = GoniometerDiff(
rotation_axis_tolerance=tolerance.goniometer.rotation_axis,
fixed_rotation_tolerance=tolerance.goniometer.fixed_rotation,
setting_rotation_tolerance=tolerance.goniometer.setting_rotation,
)

self.s_diff = ScanDiff(scan_tolerance=tolerance.scan.oscillation)
warnings.warn(
"dxtbx.datablock.SequenceDiff is deprecated. "
"Use dxtbx.model.experiment_list.sequence_diff instead",
DeprecationWarning,
stacklevel=2,
)
self._tolerance = tolerance

def __call__(self, sequence1, sequence2):
text = []
text.extend(self.b_diff(sequence1.get_beam(), sequence2.get_beam()))
text.extend(self.d_diff(sequence1.get_detector(), sequence2.get_detector()))
text.extend(self.g_diff(sequence1.get_goniometer(), sequence2.get_goniometer()))
text.extend(self.s_diff(sequence1.get_scan(), sequence2.get_scan()))
return text
import dxtbx.model.experiment_list # do not float this import (circular)

return dxtbx.model.experiment_list.sequence_diff(
sequence1, sequence2, tolerance=self._tolerance
).split("\n")
5 changes: 2 additions & 3 deletions format/test_cbf_mini_as_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
DataBlockFactory,
DetectorComparison,
GoniometerComparison,
SequenceDiff,
)
from dxtbx.format.FormatCBFMini import FormatCBFMini
from dxtbx.model.experiment_list import sequence_diff


@pytest.mark.parametrize(
Expand Down Expand Up @@ -43,8 +43,7 @@ def test_cbf_writer(image_file, dials_regression, run_in_tmpdir):
d_u_o = pytest.importorskip("dials.util.options")
tolerance = d_u_o.tolerance_phil_scope.extract().tolerance

diff = SequenceDiff(tolerance)
print("\n".join(diff(imageset, imageset2)))
print(sequence_diff(imageset, imageset2, tolerance=tolerance))

assert BeamComparison()(imageset.get_beam(), imageset2.get_beam())
assert DetectorComparison(origin_tolerance=tolerance.detector.origin)(
Expand Down
37 changes: 37 additions & 0 deletions model/experiment_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@

from dxtbx.datablock import (
BeamComparison,
BeamDiff,
DataBlockFactory,
DataBlockTemplateImporter,
DetectorComparison,
DetectorDiff,
GoniometerComparison,
GoniometerDiff,
ScanDiff,
SequenceDiff,
)
from dxtbx.format.FormatMultiImage import FormatMultiImage
Expand Down Expand Up @@ -758,3 +762,36 @@ def __init__(self, templates, **kwargs):
self.experiments.extend(
ExperimentListFactory.from_datablock_and_crystal(db, None)
)


def sequence_diff(sequence1, sequence2, tolerance=None):
if tolerance:
b_diff = BeamDiff(
wavelength_tolerance=tolerance.beam.wavelength,
direction_tolerance=tolerance.beam.direction,
polarization_normal_tolerance=tolerance.beam.polarization_normal,
polarization_fraction_tolerance=tolerance.beam.polarization_fraction,
)
d_diff = DetectorDiff(
fast_axis_tolerance=tolerance.detector.fast_axis,
slow_axis_tolerance=tolerance.detector.slow_axis,
origin_tolerance=tolerance.detector.origin,
)
g_diff = GoniometerDiff(
rotation_axis_tolerance=tolerance.goniometer.rotation_axis,
fixed_rotation_tolerance=tolerance.goniometer.fixed_rotation,
setting_rotation_tolerance=tolerance.goniometer.setting_rotation,
)
s_diff = ScanDiff(scan_tolerance=tolerance.scan.oscillation)
else:
b_diff = BeamDiff()
d_diff = DetectorDiff()
g_diff = GoniometerDiff()
s_diff = ScanDiff()

return "\n".join(
b_diff(sequence1.get_beam(), sequence2.get_beam())
+ d_diff(sequence1.get_detector(), sequence2.get_detector())
+ g_diff(sequence1.get_goniometer(), sequence2.get_goniometer())
+ s_diff(sequence1.get_scan(), sequence2.get_scan())
)

0 comments on commit 8b92256

Please sign in to comment.