Exemplo n.º 1
0
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
Exemplo n.º 2
0
def generate_test_experiments(n=2):
    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=[1, 10], oscillation=[0.0, 1.0])
    experiments.append(
        Experiment(crystal=crystal,
                   scan=scan,
                   scaling_model=get_scaling_model()))
    experiments[0].identifier = "0"
    if n > 1:
        for i in range(n - 1):
            experiments.append(
                Experiment(crystal=crystal,
                           scan=scan,
                           scaling_model=get_scaling_model()))
            experiments[i + 1].identifier = str(i + 1)
    return experiments
Exemplo n.º 3
0
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 test_experimentlist_dumper_dump_empty_sweep(tmpdir):
    tmpdir.chdir()

    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)

    filename = "temp.json"
    experiments.as_json(filename)
    experiments2 = ExperimentListFactory.from_json_file(filename,
                                                        check_format=False)
    check(experiments, experiments2)
def test_experimentlist_factory_from_sweep():
    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
    assert experiments[0].beam
    assert experiments[0].detector is not None
    assert experiments[0].goniometer
    assert experiments[0].scan
    assert experiments[0].crystal
Exemplo n.º 6
0
def scan():
    image_range = (0, 1000)
    oscillation = (0, 0.1)
    scan = Scan(image_range, oscillation)
    scan.set_batch_offset(100)
    return scan
Exemplo n.º 7
0
    def convert_stills_to_sweep(self, imageset):
        from dxtbx.model import Scan

        assert self.params.geometry.scan.oscillation is not None
        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)):
            b_i = imageset.get_beam(i)
            d_i = imageset.get_detector(i)
            g_i = imageset.get_goniometer(i)
            assert (beam is None and b_i is None) or 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 None
                    and d_i is None) or 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 None
                    and g_i is None) or 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,
                    )
        oscillation = self.params.geometry.scan.oscillation
        from dxtbx.sweep_filenames import template_regex_from_list
        from dxtbx.imageset import ImageSetFactory

        template, indices = template_regex_from_list(imageset.paths())
        image_range = (min(indices), max(indices))
        assert (image_range[1] + 1 - image_range[0]) == len(indices)
        scan = Scan(image_range=image_range, oscillation=oscillation)
        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
Exemplo n.º 8
0
def make_scan_experiment(image_range=(1, 100), expid="0"):
    """Make an experiment with a scan"""
    return Experiment(scan=Scan(image_range, (0.0, 1.0)), identifier=expid)
Exemplo n.º 9
0
def test_scan():
    '''Test pickling the scan data object.'''
    obj1 = Scan((1, 2), (1, 1))
    obj2 = pickle_then_unpickle(obj1)
    assert obj1 == obj2
Exemplo n.º 10
0
def test_experiment():
    d = {
        "__id__":
        "crystal",
        "real_space_a":
        [14.963210089244596, -22.599814679318, 51.02946725220764],
        "real_space_b":
        [-19.963976860932235, -51.503385430151205, -16.955728379753463],
        "real_space_c":
        [135.29560393219694, -34.371677531924206, -54.89475471853507],
        "space_group_hall_symbol":
        " P 4",
        "A_at_scan_points": [[
            0.004481726844090139,
            -0.005980612987053365,
            0.006013325470974739,
            -0.006768741824936281,
            -0.015428970379357122,
            -0.0015280122438480544,
            0.01528745348419002,
            -0.005078101688718203,
            -0.0024394384982453095,
        ]],
    }

    crystal = CrystalFactory.from_dict(d)

    beam_d = {
        "direction": [-2.4882593300783137e-06, -0.0, 0.9999999999969044],
        "transmission": 1.0,
        "polarization_normal": [0.0, 1.0, 0.0],
        "divergence": 0.0,
        "polarization_fraction": 0.999,
        "flux": 0.0,
        "sigma_divergence": 0.0,
        "wavelength": 0.9762499999999994,
    }

    beam = BeamFactory.from_dict(beam_d)
    scan = Scan(image_range=[0, 1], oscillation=[0.0, 0.01])

    detector_dict = {
        "hierarchy": {
            "origin": [0.0, 0.0, 0.0],
            "fast_axis": [1.0, 0.0, 0.0],
            "name": "",
            "raw_image_offset": [0, 0],
            "slow_axis": [0.0, 1.0, 0.0],
            "material": "",
            "mask": [],
            "thickness": 0.0,
            "mu": 0.0,
            "gain": 1.0,
            "trusted_range": [0.0, 0.0],
            "image_size": [0, 0],
            "px_mm_strategy": {
                "type": "SimplePxMmStrategy"
            },
            "identifier": "",
            "type": "",
            "children": [{
                "panel": 0
            }],
            "pixel_size": [0.0, 0.0],
        },
        "panels": [{
            "origin":
            [-210.66631009735772, 205.7063614421482, -263.8386975038205],
            "fast_axis": [
                0.9999973940105483,
                -0.0016357501034268717,
                -0.0015925745544149894,
            ],
            "name":
            "Panel",
            "raw_image_offset": [0, 0],
            "slow_axis": [
                -0.0016426481736367285,
                -0.999989234013669,
                -0.004339765400707805,
            ],
            "material":
            "Si",
            "mask": [
                [488, 1, 494, 2527],
                [982, 1, 988, 2527],
                [1476, 1, 1482, 2527],
                [1970, 1, 1976, 2527],
                [1, 196, 2463, 212],
                [1, 408, 2463, 424],
                [1, 620, 2463, 636],
                [1, 832, 2463, 848],
                [1, 1044, 2463, 1060],
                [1, 1256, 2463, 1272],
                [1, 1468, 2463, 1484],
                [1, 1680, 2463, 1696],
                [1, 1892, 2463, 1908],
                [1, 2104, 2463, 2120],
                [1, 2316, 2463, 2332],
            ],
            "thickness":
            0.32,
            "mu":
            3.9220322752480934,
            "gain":
            1.0,
            "trusted_range": [-1.0, 161977.0],
            "image_size": [2463, 2527],
            "px_mm_strategy": {
                "type": "ParallaxCorrectedPxMmStrategy"
            },
            "identifier":
            "",
            "type":
            "SENSOR_PAD",
            "pixel_size": [0.17200000000000001, 0.17200000000000001],
        }],
    }

    detector = DetectorFactory.from_dict(detector_dict)

    expt = Experiment(beam=beam, crystal=crystal, scan=scan, detector=detector)
    return expt