def tst_scan(self): from dxtbx.model import Scan, ScanFactory from scitbx.array_family import flex s1 = Scan((1, 3), (1.0, 0.2), flex.double([0.1, 0.1, 0.1]), flex.double([0.1, 0.2, 0.3])) d = s1.to_dict() s2 = ScanFactory.from_dict(d) assert (d['image_range'] == (1, 3)) assert (d['oscillation'] == (1.0, 0.2)) assert (d['exposure_time'] == [0.1, 0.1, 0.1]) assert (d['epochs'] == [0.1, 0.2, 0.3]) assert (s1 == s2) # Test with a template and partial dictionary d2 = {'exposure_time': [0.2, 0.2, 0.2]} s3 = ScanFactory.from_dict(d2, d) assert (s3.get_image_range() == (1, 3)) assert (s3.get_oscillation() == (1.0, 0.2)) assert (list(s3.get_exposure_times()) == [0.2, 0.2, 0.2]) assert (list(s3.get_epochs()) == [0.1, 0.2, 0.3]) assert (s2 != s3) # Test with a partial epoch d3 = {'image_range': (1, 10), 'epochs': [0.1, 0.2]} s4 = ScanFactory.from_dict(d3, d) assert (abs(s4.get_epochs()[2] - 0.3) < 1e-7) assert (abs(s4.get_epochs()[9] - 1.0) < 1e-7) print 'OK'
def _make_input_for_exclude_tests(exclude_images=True): """Generate input data, that upon exclusion should leave only the first reflection.""" if exclude_images: exclude_images = [["0:360:720"], ["1:360:720"]] expt1 = Experiment(scan=Scan(image_range=(0, 720), oscillation=(0.0, 1.0))) expt2 = Experiment(scan=Scan(image_range=(0, 720), oscillation=(0.0, -1.0))) refls1 = flex.reflection_table() refls2 = flex.reflection_table() refls1["xyzobs.mm.value"] = flex.vec3_double([ (0.0, 0.0, 10.0 * math.pi / 180.0), (0.0, 0.0, 370.0 * math.pi / 180.0) ]) refls1["xyzobs.px.value"] = flex.vec3_double([(0.0, 0.0, 10.0), (0.0, 0.0, 370.0)]) refls1["i"] = flex.int([0, 1]) refls2["xyzobs.mm.value"] = flex.vec3_double([ (0.0, 0.0, -10.0 * math.pi / 180.0), (0.0, 0.0, -370.0 * math.pi / 180.0) ]) refls2["xyzobs.px.value"] = flex.vec3_double([(0.0, 0.0, 10.0), (0.0, 0.0, 370.0)]) refls2["i"] = flex.int([0, 1]) expts = ExperimentList([expt1, expt2]) tables = [refls1, refls2] expts, tables = assign_unique_identifiers(expts, tables) return exclude_images, expts, tables
def test_swap(): scan1 = Scan((1, 20), (0.0, 1.0)) scan2 = Scan((40, 60), (10.0, 2.0)) scan1.swap(scan2) assert scan2.get_image_range() == (1, 20) assert scan1.get_image_range() == (40, 60) assert scan2.get_oscillation() == (0.0, 1.0) assert scan1.get_oscillation() == (10.0, 2.0)
def test_scan(): from dxtbx.model import Scan from scitbx.array_family import flex s1 = Scan(image_range=(1, 20), oscillation=(5.0, 0.1), exposure_times=flex.double(range(20)), epochs=flex.double(range(20, 40))) d = s1.to_dict() s2 = Scan.from_dict(d) assert s1 == s2
def test_experiment_is_still(): experiment = Experiment() assert experiment.is_still() experiment.goniometer = Goniometer() assert experiment.is_still() experiment.scan = Scan() assert experiment.is_still() experiment.scan = Scan((1, 1000), (0, 0.05)) assert not experiment.is_still() # Specifically test the bug from dxtbx#4 triggered by ending on 0° experiment.scan = Scan((1, 1800), (-90, 0.05)) assert not experiment.is_still()
def test_scan_360_append(): scan1 = Scan((1, 360), (0.0, 1.0)) scan2 = Scan((361, 720), (0.0, 1.0)) scan = scan1 + scan2 eps = 1e-7 assert(scan.get_num_images() == 720) assert(abs(scan.get_oscillation()[0] - 0.0) < eps) assert(abs(scan.get_oscillation()[1] - 1.0) < eps) assert(scan.get_image_range() == (1, 720)) assert(scan.get_batch_range() == (1, 720)) scan1 = Scan((1, 360), (0.0, 1.0)) scan2 = Scan((361, 720), (360.0, 1.0)) scan = scan1 + scan2 eps = 1e-7 assert(scan.get_num_images() == 720) assert(abs(scan.get_oscillation()[0] - 0.0) < eps) assert(abs(scan.get_oscillation()[1] - 1.0) < eps) assert(scan.get_image_range() == (1, 720)) assert(scan.get_batch_range() == (1, 720)) from libtbx.test_utils import Exception_expected scan2.set_batch_offset(10) try: scan = scan1 + scan2 except Exception: pass else: raise Exception_expected
def tst_equality(self): from dxtbx.model import Beam, Detector, Goniometer, Scan from dxtbx.model import Crystal # Create a load of models b1 = Beam() d1 = Detector() g1 = Goniometer() s1 = Scan() c1 = Crystal((1, 0, 0), (0, 1, 0), (0, 0, 1), space_group_symbol="P1") # Create a load of models that look the same but aren't b2 = Beam() d2 = Detector() g2 = Goniometer() s2 = Scan() c2 = Crystal((1, 0, 0), (0, 1, 0), (0, 0, 1), space_group_symbol="P1") # Create an experiment e1 = Experiment(beam=b1, detector=d1, goniometer=g1, scan=s1, crystal=c1, imageset=None) # Create an experiment e2 = Experiment(beam=b1, detector=d1, goniometer=g1, scan=s1, crystal=c1, imageset=None) # Create an experiment e3 = Experiment(beam=b2, detector=d2, goniometer=g2, scan=s2, crystal=c2, imageset=None) # Check e1 equals e2 but not e3 assert (e1 == e2) assert (e1 != e3) assert (e2 != e3) # Test passed print 'OK'
def test_scan_360_append(): scan1 = Scan((1, 360), (0.0, 1.0)) scan2 = Scan((361, 720), (0.0, 1.0)) scan = scan1 + scan2 eps = 1e-7 assert scan.get_num_images() == 720 assert abs(scan.get_oscillation()[0] - 0.0) < eps assert abs(scan.get_oscillation()[1] - 1.0) < eps assert scan.get_image_range() == (1, 720) assert scan.get_batch_range() == (1, 720) scan1 = Scan((1, 360), (0.0, 1.0)) scan2 = Scan((361, 720), (360.0, 1.0)) scan = scan1 + scan2 eps = 1e-7 assert scan.get_num_images() == 720 assert abs(scan.get_oscillation()[0] - 0.0) < eps assert abs(scan.get_oscillation()[1] - 1.0) < eps assert scan.get_image_range() == (1, 720) assert scan.get_batch_range() == (1, 720) scan2.set_batch_offset(10) with pytest.raises(RuntimeError): scan = scan1 + scan2
class ScanFactory(object): ''' A class to create a scan model from NXmx stuff ''' def __init__(self, obj, detector_obj): from dxtbx.model import Scan from scitbx.array_family import flex # Get the image and oscillation range phi = obj.handle.file[obj.handle['depends_on'][()]] image_range = (1, len(phi)) if len(phi) > 1: oscillation = (float(phi[0]), float(phi[1]-phi[0])) is_sweep = True else: oscillation = (float(phi[0]), 0.0) is_sweep = False # Get the exposure time num_images = len(phi) if "frame_time" in detector_obj.handle: frame_time = float(detector_obj.handle['frame_time'][()]) exposure_time = flex.double(num_images, frame_time) epochs = flex.double(num_images) for i in range(1, len(epochs)): epochs[i] = epochs[i-1] + exposure_time[i-1] else: exposure_time = flex.double(num_images, 0) epochs = flex.double(num_images, 0) if is_sweep is True: # Construct the model self.model = Scan( image_range, oscillation, exposure_time, epochs) else: self.model = [] for i, image in enumerate(range(image_range[0], image_range[1]+1)): self.model.append(Scan( (image, image), oscillation, exposure_time[i:i+1], epochs[i:i+1]))
def __call__(self): from dxtbx.model import Scan from scitbx.array_family import flex s1 = Scan( image_range=(1, 20), oscillation=(5.0, 0.1), exposure_times=flex.double(range(20)), epochs=flex.double(range(20,40))) d = s1.to_dict() s2 = Scan.from_dict(d) assert(s1 == s2) print 'OK'
def test_experimentlist_factory_from_datablock(): from dxtbx.model import Beam, Detector, Goniometer, Scan from dxtbx.datablock import DataBlockFactory from dxtbx.model import Crystal from dxtbx.format.Format import Format filenames = ["filename_%01d.cbf" % (i+1) for i in range(0, 2)] imageset = Format.get_imageset( filenames, beam = Beam(), detector = Detector(), goniometer = Goniometer(), scan = Scan((1,2), (0,1)), as_sweep=True) crystal = Crystal((1, 0, 0), (0, 1, 0), (0, 0, 1), space_group_symbol="P1") datablock = DataBlockFactory.from_imageset(imageset) experiments = ExperimentListFactory.from_datablock_and_crystal( datablock, crystal) assert len(experiments) == 1 assert experiments[0].imageset is not None assert experiments[0].beam is not None assert experiments[0].detector is not None assert experiments[0].goniometer is not None assert experiments[0].scan is not None assert experiments[0].crystal is not None
def generated_single_exp(): """Generate an experiment object.""" experiments = ExperimentList() exp_dict = { "__id__": "crystal", "real_space_a": [1.0, 0.0, 0.0], "real_space_b": [0.0, 1.0, 0.0], "real_space_c": [0.0, 0.0, 2.0], "space_group_hall_symbol": " C 2y", } crystal = Crystal.from_dict(exp_dict) scan = Scan(image_range=[0, 60], oscillation=[0.0, 1.0]) beam = Beam(s0=(0.0, 0.0, 1.01)) goniometer = Goniometer((1.0, 0.0, 0.0)) detector = Detector() experiments.append( Experiment( beam=beam, scan=scan, goniometer=goniometer, detector=detector, crystal=crystal, )) experiments[0].identifier = "0" return experiments
def tst_from_sweep(self): from dxtbx.model import Beam, Detector, Goniometer, Scan from dxtbx.model import Crystal from dxtbx.format.Format import Format filenames = ["filename_%01d.cbf" % (i + 1) for i in range(0, 2)] imageset = Format.get_imageset(filenames, beam=Beam(), detector=Detector(), goniometer=Goniometer(), scan=Scan((1, 2), (0, 1)), as_sweep=True) crystal = Crystal((1, 0, 0), (0, 1, 0), (0, 0, 1), space_group_symbol="P1") experiments = ExperimentListFactory.from_imageset_and_crystal( imageset, crystal) assert (len(experiments) == 1) assert (experiments[0].imageset is not None) assert (experiments[0].beam is not None) assert (experiments[0].detector is not None) assert (experiments[0].goniometer is not None) assert (experiments[0].scan is not None) assert (experiments[0].crystal is not None) print 'OK'
def test_experimentlist_factory_from_datablock(): filenames = ["filename_%01d.cbf" % (i + 1) for i in range(0, 2)] imageset = Format.get_imageset( filenames, beam=Beam(), detector=Detector(), goniometer=Goniometer(), scan=Scan((1, 2), (0, 1)), as_sequence=True, ) crystal = Crystal((1, 0, 0), (0, 1, 0), (0, 0, 1), space_group_symbol="P1") datablock = DataBlockFactory.from_imageset(imageset) assert datablock[0].format_class() experiments = ExperimentListFactory.from_datablock_and_crystal( datablock, crystal) assert len(experiments) == 1 assert experiments[0].imageset assert experiments[0].beam assert experiments[0].detector is not None assert experiments[0].goniometer assert experiments[0].scan assert experiments[0].crystal
def generated_exp(n=1, space_group="P 2", assign_ids=False, id_=None): """Generate an experiment list with two experiments.""" experiments = ExperimentList() exp_dict = { "__id__": "crystal", "real_space_a": [15.0, 0.0, 0.0], "real_space_b": [0.0, 10.0, 0.0], "real_space_c": [0.0, 0.0, 20.0], "space_group_hall_symbol": space_group, } crystal = Crystal.from_dict(exp_dict) scan = Scan(image_range=[0, 90], oscillation=[0.0, 1.0]) beam = Beam(s0=(0.0, 0.0, 1.01)) if assign_ids: experiments.append( Experiment(identifier="0", beam=beam, scan=scan, crystal=crystal) ) elif id_: experiments.append( Experiment(identifier=str(id_), beam=beam, scan=scan, crystal=crystal) ) else: experiments.append(Experiment(beam=beam, scan=scan, crystal=crystal)) if n > 1: for i in range(1, n): if assign_ids: experiments.append( Experiment(identifier=str(i), beam=beam, scan=scan, crystal=crystal) ) else: experiments.append(Experiment(beam=beam, scan=scan, crystal=crystal)) return experiments
def from_dict(d, t=None): ''' Convert the dictionary to a scan model Params: d The dictionary of parameters t The template dictionary to use Returns: The scan model ''' from dxtbx.model import Scan from scitbx.array_family import flex # import dependency # If None, return None if d == None: if t == None: return None else: return from_dict(t, None) elif t != None: d = dict(t.items() + d.items()) if not isinstance(d['exposure_time'], list): d['exposure_time'] = [d['exposure_time']] # Create the model from the dictionary return Scan.from_dict(d)
def tst_from_null_sweep(self): from dxtbx.format.Format import Format from dxtbx.imageset import ImageSweep from dxtbx.model import Beam, Detector, Goniometer, Scan filenames = ["template_%2d.cbf" % (i+1) for i in range(0, 10)] sweep = Format.get_imageset( filenames, beam = Beam((0, 0, 1)), detector = Detector(), goniometer = Goniometer((1, 0, 0)), scan = Scan((1, 10), (0, 0.1))) # Create the datablock datablock = DataBlockFactory.from_imageset(sweep) assert(len(datablock) == 1) datablock = datablock[0] sweeps = datablock.extract_sweeps() assert(len(sweeps) == 1) assert(sweeps[0].get_beam() == sweep.get_beam()) assert(sweeps[0].get_detector() == sweep.get_detector()) assert(sweeps[0].get_goniometer() == sweep.get_goniometer()) assert(sweeps[0].get_scan() == sweep.get_scan()) print 'OK'
def generate_test_input(): (reflections, ms) = load_data("test_dataset_mu0p2_smalldetector_P4_rot0.pickle") # json.dump(datablock, open(datablock_json, 'w')) experiments = ExperimentList() exp_dict = { "__id__": "crystal", "real_space_a": [20.0, 0.0, 0.0], "real_space_b": [0.0, 20.0, 0.0], "real_space_c": [0.0, 0.0, 15.0], "space_group_hall_symbol": " P 4", } experiments.crystal = Crystal.from_dict(exp_dict) experiments.scan = Scan(image_range=[0, 360], oscillation=[0.0, 1.0]) experiments.beam = Beam(s0=(0.0, 0.0, 1.01)) experiments.goniometer = Goniometer((1.0, 0.0, 0.0)) phil_scope = phil.parse( """ include scope dials_scratch.jbe.scaling_code.scaling_options.phil_scope """, process_includes=True, ) optionparser = OptionParser(phil=phil_scope, check_format=False) parameters, _ = optionparser.parse_args(args=None, quick_parse=True, show_diff_phil=False) parameters.__inject__("scaling_method", "aimless") parameters.scaling_options.__inject__("multi_mode", False) return (reflections, experiments, parameters)
def test_experimentlist_dumper_dump_empty_sweep(tmpdir): tmpdir.chdir() from dxtbx.model import Beam, Detector, Goniometer, Scan from dxtbx.model import Crystal from dxtbx.format.Format import Format filenames = ["filename_%01d.cbf" % (i+1) for i in range(0, 2)] imageset = Format.get_imageset( filenames, beam = Beam((1, 0, 0)), detector = Detector(), goniometer = Goniometer(), scan = Scan((1,2), (0.0, 1.0)), as_sweep=True) crystal = Crystal((1, 0, 0), (0, 1, 0), (0, 0, 1), space_group_symbol="P1") experiments = ExperimentListFactory.from_imageset_and_crystal( imageset, crystal) dump = ExperimentListDumper(experiments) filename = 'temp.json' dump.as_json(filename) experiments2 = ExperimentListFactory.from_json_file(filename, check_format=False) check(experiments, experiments2)
def tst_from_null_sweep(self): from dxtbx.datablock import DataBlockFactory from dxtbx.imageset import NullReader, ImageSweep, SweepFileList from dxtbx.model import Beam, Detector, Goniometer, Scan sweep = ImageSweep( NullReader(SweepFileList("template_%2d.cbf", (0, 10)))) sweep.set_beam(Beam((0, 0, 1))) sweep.set_detector(Detector()) sweep.set_goniometer(Goniometer((1, 0, 0))) sweep.set_scan(Scan((1, 10), (0, 0.1))) # Create the datablock datablock = DataBlockFactory.from_imageset(sweep) assert (len(datablock) == 1) datablock = datablock[0] sweeps = datablock.extract_sweeps() assert (len(sweeps) == 1) assert (sweeps[0].get_beam() == sweep.get_beam()) assert (sweeps[0].get_detector() == sweep.get_detector()) assert (sweeps[0].get_goniometer() == sweep.get_goniometer()) assert (sweeps[0].get_scan() == sweep.get_scan()) print 'OK'
def tst_from_datablock(self): from dxtbx.imageset import ImageSweep, NullReader, SweepFileList from dxtbx.model import Beam, Detector, Goniometer, Scan from dxtbx.datablock import DataBlockFactory from dxtbx.model.crystal import crystal_model imageset = ImageSweep(NullReader(SweepFileList("filename%01d.cbf", (0, 2)))) imageset.set_beam(Beam()) imageset.set_detector(Detector()) imageset.set_goniometer(Goniometer()) imageset.set_scan(Scan((1, 2), (0, 1))) crystal = crystal_model((1, 0, 0), (0, 1, 0), (0, 0, 1), space_group_symbol=0) datablock = DataBlockFactory.from_imageset(imageset) experiments = ExperimentListFactory.from_datablock_and_crystal( datablock, crystal) assert(len(experiments) == 1) assert(experiments[0].imageset is not None) assert(experiments[0].beam is not None) assert(experiments[0].detector is not None) assert(experiments[0].goniometer is not None) assert(experiments[0].scan is not None) assert(experiments[0].crystal is not None) print 'OK'
def tst_dump_empty_sweep(self): from dxtbx.imageset import ImageSweep, NullReader, SweepFileList from dxtbx.model import Beam, Detector, Goniometer, Scan from dxtbx.model.crystal import crystal_model from uuid import uuid4 imageset = ImageSweep(NullReader(SweepFileList("filename%01d.cbf", (0, 3)))) imageset.set_beam(Beam((1, 0, 0))) imageset.set_detector(Detector()) imageset.set_goniometer(Goniometer()) imageset.set_scan(Scan((1, 3), (0.0, 1.0))) crystal = crystal_model((1, 0, 0), (0, 1, 0), (0, 0, 1), space_group_symbol=1) experiments = ExperimentListFactory.from_imageset_and_crystal( imageset, crystal) dump = ExperimentListDumper(experiments) filename = 'temp%s.json' % uuid4().hex dump.as_json(filename) experiments2 = ExperimentListFactory.from_json_file(filename, check_format=False) self.check(experiments, experiments2) print 'OK'
def test_set_batch_offsets(): """Test for namesake function""" scan = Scan(image_range=[1, 200], oscillation=[0.0, 1.0]) exp1 = Experiment(scan=scan) exp2 = Experiment() set_batch_offsets([exp2, exp1], [0, 101]) assert exp1.scan.get_batch_offset() == 101
def tst_contains(self): from dxtbx.model import Beam, Detector, Goniometer, Scan # Check all the models are found for e in self.el: assert(e.beam in self.el) assert(e.detector in self.el) assert(e.goniometer in self.el) assert(e.scan in self.el) # Create some more models b = Beam() d = Detector() g = Goniometer() s = Scan() # Check that models not in are not found assert(b not in self.el) assert(d not in self.el) assert(g not in self.el) assert(s not in self.el) # Test passed print 'OK'
def generated_exp(n=1): """Generate an experiment list with two experiments.""" experiments = ExperimentList() exp_dict = { "__id__": "crystal", "real_space_a": [1.0, 0.0, 0.0], "real_space_b": [0.0, 1.0, 0.0], "real_space_c": [0.0, 0.0, 2.0], "space_group_hall_symbol": " C 2y", } crystal = Crystal.from_dict(exp_dict) scan = Scan(image_range=[0, 90], oscillation=[0.0, 1.0]) beam = Beam(s0=(0.0, 0.0, 1.01)) goniometer = Goniometer((1.0, 0.0, 0.0)) detector = Detector() experiments.append( Experiment( beam=beam, scan=scan, goniometer=goniometer, detector=detector, crystal=crystal, )) if n > 1: for _ in range(n - 1): experiments.append( Experiment( beam=beam, scan=scan, goniometer=goniometer, detector=detector, crystal=crystal, )) return experiments
def test_valid_image_ranges(): scan = Scan((1, 100), (0.0, 1.0)) scan.set_valid_image_ranges("0", [(1,80)]) scan.set_valid_image_ranges("1", [(1,50)]) assert list(scan.get_valid_image_ranges("0")) == [(1, 80)] assert list(scan.get_valid_image_ranges("1")) == [(1, 50)] scan.set_valid_image_ranges("0", [(1,50), (80, 100)]) assert list(scan.get_valid_image_ranges("0")) == [(1, 50), (80, 100)] assert list(scan.get_valid_image_ranges("2")) == []
def convert_stills_to_sweep(self, imageset): from dxtbx.model import Scan assert self.params.geometry.scan.oscillation is not None for i in range(len(imageset)): self.override_beam( imageset.get_beam(index=i), self.params.geometry.beam) self.override_detector( imageset.get_detector(index=i), self.params.geometry.detector) self.override_goniometer( imageset.get_goniometer(index=i), self.params.geometry.goniometer) beam = imageset.get_beam(index=0) detector = imageset.get_detector(index=0) goniometer = imageset.get_goniometer(index=0) for i in range(1, len(imageset)): assert beam.is_similar_to( imageset.get_beam(index=i), wavelength_tolerance = self.params.input.tolerance.beam.wavelength, direction_tolerance = self.params.input.tolerance.beam.direction, polarization_normal_tolerance = self.params.input.tolerance.beam.polarization_normal, polarization_fraction_tolerance = self.params.input.tolerance.beam.polarization_fraction) assert detector.is_similar_to( imageset.get_detector(index=i), fast_axis_tolerance = self.params.input.tolerance.detector.fast_axis, slow_axis_tolerance = self.params.input.tolerance.detector.slow_axis, origin_tolerance = self.params.input.tolerance.detector.origin) assert goniometer.is_similar_to( imageset.get_goniometer(index=i), rotation_axis_tolerance = self.params.input.tolerance.goniometer.rotation_axis, fixed_rotation_tolerance = self.params.input.tolerance.goniometer.fixed_rotation, setting_rotation_tolerance = self.params.input.tolerance.goniometer.setting_rotation) assert beam is not None assert detector is not None assert goniometer is not None if self.params.geometry.scan.image_range is not None: image_range = self.params.geometry.scan.image_range else: image_range = (1, len(imageset)) oscillation = self.params.geometry.scan.oscillation scan = Scan(image_range=image_range, oscillation=oscillation) from dxtbx.sweep_filenames import template_regex from dxtbx.imageset import ImageSetFactory indices = list(range(image_range[0], image_range[1]+1)) template = template_regex(imageset.get_path(0))[0] if template is None: paths = [imageset.get_path(i) for i in range(len(imageset))] assert len(set(paths)) == 1 template = paths[0] new_sweep = ImageSetFactory.make_sweep( template = template, indices = indices, format_class = imageset.reader().get_format_class(), beam = beam, detector = detector, goniometer = goniometer, scan = scan) return new_sweep
def test_calculate_batch_offsets(): """Test offset calculation. Offset is next number ending in 01 bigger than previous batch numbers which is not consecutive""" scan = Scan(image_range=[1, 200], oscillation=[0.0, 1.0]) exp1 = Experiment(scan=scan) exp2 = Experiment() offsets = calculate_batch_offsets([exp1, exp2]) assert offsets == [0, 301]
def test_get_image_ranges(): """Test for namesake function""" scan = Scan(image_range=[1, 200], oscillation=[0.0, 1.0]) exp1 = Experiment(scan=scan) exp2 = Experiment() experiments = [exp1, exp2] image_ranges = get_image_ranges(experiments) assert image_ranges == [(1, 200), (0, 0)]
def tst_swap(): scan1 = Scan((1, 20), (0.0, 1.0)) scan2 = Scan((40, 60), (10.0, 2.0)) scan1.swap(scan2) assert(scan2.get_image_range() == (1, 20)) assert(scan1.get_image_range() == (40, 60)) assert(scan2.get_oscillation() == (0.0, 1.0)) assert(scan1.get_oscillation() == (10.0, 2.0)) print 'OK'
def test_slice_experiments(): image_range = (0, 1000) oscillation = (0, 0.1) scan = Scan(image_range, oscillation) experiments = ExperimentList([Experiment(scan=scan)]) sliced_image_range = [(1, 5)] sliced_experiments = slice_experiments(experiments, sliced_image_range) assert sliced_experiments[0].scan.get_image_range() == sliced_image_range[0] copy.deepcopy(sliced_experiments)
def test_get_batch_ranges(): """Test for namesake function""" scan = Scan(image_range=[1, 200], oscillation=[0.0, 1.0]) exp1 = Experiment(scan=scan) exp2 = Experiment(scan=scan) batch_offsets = [0, 300] experiments = [exp1, exp2] batch_ranges = get_batch_ranges(experiments, batch_offsets) assert batch_ranges == [(1, 200), (301, 500)]
def load_models(obj): try: beam = Beam.from_dict(blist[obj['beam']]) except Exception: beam = None try: dobj = dlist[obj['detector']] detector = Detector.from_dict(dobj) except Exception: detector = None try: from dxtbx.serialize import goniometer gonio = goniometer.from_dict(glist[obj['goniometer']]) except Exception: gonio = None try: scan = Scan.from_dict(slist[obj['scan']]) except Exception: scan = None return beam, detector, gonio, scan
def load_models(obj): try: beam = Beam.from_dict(blist[obj['beam']]) except Exception: beam = None try: dobj = dlist[obj['detector']] if 'hierarchy' in dobj: detector = HierarchicalDetector.from_dict(dobj) else: detector = Detector.from_dict(dobj) except Exception: detector = None try: gonio = Goniometer.from_dict(glist[obj['goniometer']]) except Exception: gonio = None try: scan = Scan.from_dict(slist[obj['scan']]) except Exception: scan = None return beam, detector, gonio, scan
def _scan_from_dict(obj): ''' Get the scan from a dictionary. ''' from dxtbx.model import Scan return Scan.from_dict(obj)