Exemplo n.º 1
0
    def _start(self):
        # Read the file structure
        temp_file = "tmp_master_%s.nxs" % uuid.uuid1().hex
        fixer = EigerNXmxFixer(self._image_file, temp_file)
        reader = NXmxReader(handle=fixer.handle)

        # Only support 1 set of models at the moment
        assert len(reader.entries) == 1, "Currently only supports 1 NXmx entry"
        assert len(reader.entries[0].data) == 1, "Currently only supports 1 NXdata"
        assert (
            len(reader.entries[0].instruments) == 1
        ), "Currently only supports 1 NXinstrument"
        assert len(reader.entries[0].samples) == 1, "Currently only supports 1 NXsample"
        assert (
            len(reader.entries[0].instruments[0].detectors) == 1
        ), "Currently only supports 1 NXdetector"
        assert (
            len(reader.entries[0].instruments[0].detectors[0].modules) == 1
        ), "Currently only supports 1 NXdetector_module"
        assert (
            len(reader.entries[0].samples[0].beams) == 1
            or len(reader.entries[0].instruments[0].beams) == 1
        ), "Currently only supports 1 NXbeam"

        # Get the NXmx model objects
        entry = reader.entries[0]
        self.instrument = instrument = entry.instruments[0]
        detector = instrument.detectors[0]
        sample = entry.samples[0]
        beam = sample.beams[0] if sample.beams else instrument.beams[0]

        # Use data from original master file
        data = NXdata(fixer.handle_orig[entry.data[0].handle.name])
        self._raw_data = DataFactory(data, cached_information=fixer.data_factory_cache)

        # Construct the models
        self._beam_factory = BeamFactory(beam)
        self._beam_factory.load_model(0)
        self._detector_model = DetectorFactory(
            detector, self._beam_factory.model, shape=self._raw_data.shape()
        ).model

        # Override the minimum trusted value - for Eiger should be -1
        for panel in self._detector_model:
            trusted = panel.get_trusted_range()
            panel.set_trusted_range((-1, trusted[1]))

        self._goniometer_model = GoniometerFactory(sample).model
        self._scan_model = generate_scan_model(sample, detector)

        # update model for masking Eiger detectors
        for f0, f1, s0, s1 in determine_eiger_mask(self._detector_model):
            self._detector_model[0].add_mask(f0 - 1, s0 - 1, f1, s1)
Exemplo n.º 2
0
    def _start(self):

        # Read the file structure
        import uuid

        temp_file = "tmp_master_%s.nxs" % uuid.uuid1().hex
        fixer = EigerNXmxFixer(self._image_file, temp_file)
        reader = NXmxReader(handle=fixer.handle)

        # Only support 1 set of models at the moment
        assert len(reader.entries) == 1, "Currently only supports 1 NXmx entry"
        assert len(reader.entries[0].data) == 1, "Currently only supports 1 NXdata"
        assert (
            len(reader.entries[0].instruments) == 1
        ), "Currently only supports 1 NXinstrument"
        assert len(reader.entries[0].samples) == 1, "Currently only supports 1 NXsample"
        assert (
            len(reader.entries[0].instruments[0].detectors) == 1
        ), "Currently only supports 1 NXdetector"
        assert (
            len(reader.entries[0].instruments[0].detectors[0].modules) == 1
        ), "Currently only supports 1 NXdetector_module"
        assert (
            len(reader.entries[0].samples[0].beams) == 1
        ), "Currently only supports 1 NXbeam"

        # Get the NXmx model objects
        entry = reader.entries[0]
        self.instrument = instrument = entry.instruments[0]
        detector = instrument.detectors[0]
        sample = entry.samples[0]
        beam = sample.beams[0]

        # Use data from original master file
        data = NXdata(fixer.handle_orig[entry.data[0].handle.name])

        # Construct the models
        self._beam_model = BeamFactory(beam).model
        self._detector_model = DetectorFactory(detector, self._beam_model).model
        self._goniometer_model = GoniometerFactory(sample).model
        self._scan_model = ScanFactory(sample, detector).model
        self._raw_data = DataFactory(data).model

        # update model for masking Eiger detectors
        from dxtbx.format.FormatPilatusHelpers import determine_eiger_mask

        for f0, f1, s0, s1 in determine_eiger_mask(self._detector_model):
            self._detector_model[0].add_mask(f0 - 1, s0 - 1, f1, s1)
    def _start(self):

        # Read the file structure
        import uuid
        temp_file = "tmp_master_%s.nxs" % uuid.uuid1().hex
        fixer = EigerNXmxFixer(self._image_file, temp_file)
        reader = NXmxReader(handle=fixer.handle)

        # Only support 1 set of models at the moment
        assert len(reader.entries) == 1, \
          "Currently only supports 1 NXmx entry"
        assert len(reader.entries[0].data) == 1, \
          "Currently only supports 1 NXdata"
        assert len(reader.entries[0].instruments) == 1, \
          "Currently only supports 1 NXinstrument"
        assert len(reader.entries[0].samples) == 1, \
          "Currently only supports 1 NXsample"
        assert len(reader.entries[0].instruments[0].detectors) == 1, \
          "Currently only supports 1 NXdetector"
        assert len(reader.entries[0].instruments[0].detectors[0].modules) == 1, \
          "Currently only supports 1 NXdetector_module"
        assert len(reader.entries[0].samples[0].beams) == 1, \
          "Currently only supports 1 NXbeam"

        # Get the NXmx model objects
        entry = reader.entries[0]
        instrument = entry.instruments[0]
        detector = instrument.detectors[0]
        sample = entry.samples[0]
        beam = sample.beams[0]

        # Use data from original master file
        data = NXdata(fixer.handle_orig[entry.data[0].handle.name])

        # Construct the models
        self._beam_model = BeamFactory(beam).model
        self._detector_model = DetectorFactory(detector,
                                               self._beam_model).model
        self._goniometer_model = GoniometerFactory(sample).model
        self._scan_model = ScanFactory(sample, detector).model
        self._raw_data = DataFactory(data).model
        self._mask = MaskFactory([detector]).mask
Exemplo n.º 4
0
 def _setup_gonio_and_scan(self, sample, detector):
     """ Set up rotation-specific models """
     self._goniometer_model = GoniometerFactory(sample).model
     self._scan_model = ScanFactory(sample, detector).model
Exemplo n.º 5
0
def tst_dxtbx_eiger():
    print "Testing eiger hdf5 geometry recognition.."

    try:
        # due to https://github.com/cctbx/cctbx_project/issues/282
        import dxtbx.format.FormatHDFEigerNearlyNexus
    except ImportError:
        print "  FormatHDFEigerNearlyNexus does not exist. This implies h5-recorded geometry can be no longer extracted using dxtbx. I hope it works. OK"
        return True

    try:
        import h5py
        import uuid
        from dxtbx.format.nexus import NXmxReader
        from dxtbx.format.FormatHDFEigerNearlyNexus import EigerNXmxFixer
        from dxtbx.format.nexus import BeamFactory
        from dxtbx.format.nexus import DetectorFactory
        from dxtbx.format.nexus import GoniometerFactory
        import numpy

        tmpfd, tmpf = tempfile.mkstemp()
        os.close(tmpfd)

        h = h5py.File(tmpf, "w")
        h.create_group("/entry/instrument/detector/")
        h["/entry/instrument/detector/description"] = "Dectris Eiger"
        h["/entry/"].attrs["NX_class"] = "NXentry"
        g = h.create_group(
            "entry/instrument/detector/detectorSpecific/detectorModule_000")
        g["countrate_correction_count_cutoff"] = 10
        g = h.create_group("/entry/instrument/beam")
        g["incident_wavelength"] = 1.
        g["incident_wavelength"].attrs["units"] = "angstrom"
        h["/entry/instrument"].attrs["NX_class"] = "NXinstrument"
        h["/entry/instrument/beam"].attrs["NX_class"] = "NXbeam"
        g = h.create_group("/entry/data")
        g.create_dataset("data_000001", (1, 3269, 3110), dtype=numpy.uint16)
        h["/entry/data"].attrs["NX_class"] = "NXdata"
        g = h.create_group("/entry/instrument/detector/geometry/orientation")
        g["value"] = (-1, 0, 0, 0, -1, 0)
        g = h.create_group("/entry/instrument/detector/geometry/translation")
        g["distances"] = (0.11737501, 0.11992501, -0.18)
        h["/entry/instrument/detector"].attrs["NX_class"] = "NXdetector"
        h["/entry/instrument/detector/x_pixel_size"] = h[
            "/entry/instrument/detector/y_pixel_size"] = 7.5e-5
        h["/entry/instrument/detector/sensor_material"] = "Si"
        h["/entry/instrument/detector/sensor_thickness"] = 4.5e-4
        h["/entry/instrument/detector/sensor_thickness"].attrs["units"] = "m"
        h["/entry/instrument/detector/count_time"] = 0.99998

        g = h.create_group("/entry/sample/goniometer")
        g["omega_range_average"] = 1.
        h["/entry/sample"].attrs["NX_class"] = "NXsample"

        h.close()

        temp_file = "tmp_master_%s.nxs" % uuid.uuid1().hex
        fixer = EigerNXmxFixer(tmpf, temp_file)
        reader = NXmxReader(handle=fixer.handle)

        entry = reader.entries[0]
        instrument = entry.instruments[0]
        detector = instrument.detectors[0]
        sample = entry.samples[0]
        beam = sample.beams[0]
        beam_model = BeamFactory(beam).model
        detector_model = DetectorFactory(detector, beam_model).model
        goniometer_model = GoniometerFactory(sample).model

        _test = detector_model[0].get_fast_axis(
        ) + detector_model[0].get_slow_axis() + beam_model.get_direction(
        ) + goniometer_model.get_rotation_axis()
        os.remove(tmpf)

        if _test == (1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, -1.0, 1.0, 0.0,
                     0.0):
            print "  OK"
            return True
        elif _test == (1.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0,
                       0.0):
            print "  OK"
            return True
        else:
            print "  vectors=", _test
    except:
        print traceback.format_exc()

    print "  NG! You are using old cctbx. Use latest cctbx or environment of DIALS v1.6 or PHENIX 1.12 or newer."
    return False