Esempio n. 1
0
    def test_fake(self):
        """test for fake image generation"""
        with_plot = (logger.getEffectiveLevel() <= logging.DEBUG)
        if with_plot:
            import matplotlib
            import matplotlib.pyplot as plt
            fig = plt.figure()
            ax = fig.add_subplot(1, 1, 1)

        detectors = set(ALL_DETECTORS.values())
        for idx, detector in enumerate(detectors):
            det = detector()
            # Skip generic detectors
            if "MAX_SHAPE" not in dir(det):
                continue
            # skip the big detectors for now
            if max(det.MAX_SHAPE) > 2000:
                continue
            ai = pyFAI.AzimuthalIntegrator(dist=0.01, poni1=0, poni2=0,
                                           detector=det)
            calibrant = ALL_CALIBRANTS["LaB6"]
            calibrant.set_wavelength(1e-10)
            img = calibrant.fake_calibration_image(ai)

            if with_plot:
                ax.cla()
                ax.set_title(det.name)

                ax.imshow(img, interpolation='nearest')
                fig.show()
                six.moves.input("enter> ")
            logger.info("%s min: %s max: %s " % (det.name, img.min(), img.max()))
            self.assert_(img.shape == det.shape, "Image (%s) has the right size" % (det.name,))
            self.assert_(img.sum() > 0, "Image (%s) contains some data" % (det.name,))
            sys.stderr.write(".")
Esempio n. 2
0
 def setup_instrument(self):
     entry = self.experiment_file['entry']
     entry.instrument = NXinstrument()
     entry.instrument.monochromator = NXmonochromator()
     entry.instrument.detector = NXdetector()
     entry['instrument/monochromator/wavelength'] = NXfield(
         0.5, dtype=np.float32)
     entry['instrument/monochromator/wavelength'].attrs[
         'units'] = 'Angstroms'
     entry['instrument/monochromator/energy'] = NXfield(12.398419739640717 /
                                                        0.5,
                                                        dtype=np.float32)
     entry['instrument/monochromator/energy'].attrs['units'] = 'keV'
     entry['instrument/detector/distance'] = NXfield(100.0,
                                                     dtype=np.float32)
     entry['instrument/detector/distance'].attrs['units'] = 'mm'
     self.instrument = GridParameters()
     self.instrument.add('experiment', 'experiment', 'Experiment Name')
     self.instrument.add('wavelength',
                         entry['instrument/monochromator/wavelength'],
                         'Wavelength (Ang)')
     self.instrument.add('distance', entry['instrument/detector/distance'],
                         'Detector Distance (mm)')
     detector_list = sorted(
         list(set([detector().name
                   for detector in ALL_DETECTORS.values()])))
     self.instrument.add('detector', detector_list, 'Detector')
     self.instrument['detector'].value = 'Pilatus CdTe 2M'
     self.instrument.add('positions', [0, 1, 2, 3, 4],
                         'Number of Detector Positions',
                         slot=self.set_entries)
     self.instrument['positions'].value = '0'
Esempio n. 3
0
 def test_detector_instanciate(self):
     """
     this method try to instantiate all the detectors
     """
     for k, v in ALL_DETECTORS.items():
         logger.debug(k)
         v()
Esempio n. 4
0
def get_available_detectors():
    detector_classes = set()
    detector_names = []

    for key, item in ALL_DETECTORS.items():
        detector_classes.add(item)

    for detector in detector_classes:
        if len(detector.aliases) > 0:
            detector_names.append(detector.aliases[0])
        else:
            detector_names.append(detector().__class__.__name__)

    sorted_indices = sorted(range(len(detector_names)),
                            key=detector_names.__getitem__)

    detector_names_sorted = [detector_names[i] for i in sorted_indices]
    detector_classes_sorted = [
        list(detector_classes)[i] for i in sorted_indices
    ]

    base_class_index = detector_names_sorted.index('Detector')
    del detector_names_sorted[base_class_index]
    del detector_classes_sorted[base_class_index]

    return detector_names_sorted, detector_classes_sorted
Esempio n. 5
0
 def test_detector_instanciate(self):
     """
     this method try to instantiate all the detectors
     """
     for k, v in ALL_DETECTORS.items():
         logger.debug(k)
         v()
Esempio n. 6
0
    def test_fake(self):
        """test for fake image generation"""
        with_plot = False
        if with_plot:
            import matplotlib
            matplotlib.use('Agg')

            import matplotlib.pyplot as plt

            from matplotlib.backends.backend_pdf import PdfPages
            from matplotlib import rcParams

            pp = PdfPages('fake.pdf')
            rcParams['font.size'] = 6
            plt.clf()

        detectors = set(ALL_DETECTORS.values())
        for idx, detector in enumerate(detectors):
            det = detector()
            # Skip generic detectors
            if "MAX_SHAPE" not in dir(det):
                continue
            # skip the big detectors for now
            if max(det.MAX_SHAPE) > 2000:
                continue
            ai = pyFAI.AzimuthalIntegrator(dist=0.01,
                                           poni1=0,
                                           poni2=0,
                                           detector=det)
            calibrant = ALL_CALIBRANTS["LaB6"]
            calibrant.set_wavelength(1e-10)
            img = calibrant.fake_calibration_image(ai)

            if with_plot:
                plt.clf
                plt.subplot(3, 4, idx % 12)
                plt.title(det.name)
                plt.imshow(img, interpolation='nearest')

                if idx != 0 and idx % 12 == 0:
                    pp.savefig()
                    plt.clf()
                print(det.name, img.min(), img.max())
            self.assert_(img.shape == det.shape,
                         "Image (%s) has the right size" % (det.name, ))
            self.assert_(img.sum() > 0,
                         "Image (%s) contains some data" % (det.name, ))
            sys.stderr.write(".")

        if with_plot:
            pp.savefig()
            pp.close()
Esempio n. 7
0
def guess_detector_by_shape(shape):
    # for every detector known to pyFAI
    for name, detector in sorted(ALL_DETECTORS.items()):
        # if a shape limit is set
        if hasattr(detector, 'MAX_SHAPE'):
            if detector.MAX_SHAPE == shape:
                return detector()
        if hasattr(detector, 'BINNED_PIXEL_SIZE'):
            for binning in detector.BINNED_PIXEL_SIZE.keys():
                if shape == tuple(np.array(detector.MAX_SHAPE) / binning): # possibly needs to be reversed [::-1]
                    detector = detector()
                    detector.set_binning(binning)
                    return detector
    return None
Esempio n. 8
0
    def test_fake(self):
        """test for fake image generation"""
        with_plot = False
        if with_plot:
            import matplotlib
            matplotlib.use('Agg')

            import matplotlib.pyplot as plt

            from matplotlib.backends.backend_pdf import PdfPages
            from matplotlib import rcParams

            pp = PdfPages('fake.pdf')
            rcParams['font.size'] = 6
            plt.clf()

        detectors = set(ALL_DETECTORS.values())
        for idx, detector in enumerate(detectors):
            det = detector()
            # Skip generic detectors
            if "MAX_SHAPE" not in dir(det):
                continue
            # skip the big detectors for now
            if max(det.MAX_SHAPE) > 2000:
                continue
            ai = pyFAI.AzimuthalIntegrator(dist=0.01, poni1=0, poni2=0,
                                           detector=det)
            calibrant = ALL_CALIBRANTS["LaB6"]
            calibrant.set_wavelength(1e-10)
            img = calibrant.fake_calibration_image(ai)

            if with_plot:
                plt.clf
                plt.subplot(3, 4, idx % 12)
                plt.title(det.name)
                plt.imshow(img, interpolation='nearest')

                if idx != 0 and idx % 12 == 0:
                    pp.savefig()
                    plt.clf()
                print(det.name, img.min(), img.max())
            self.assert_(img.shape == det.shape, "Image (%s) has the right size" % (det.name,))
            self.assert_(img.sum() > 0, "Image (%s) contains some data" % (det.name,))
            sys.stderr.write(".")

        if with_plot:
            pp.savefig()
            pp.close()
Esempio n. 9
0
 def setup_instrument(self):
     default = self.settings['nxrefine']
     entry = self.configuration_file['entry']
     entry['instrument/detector/distance'] = NXfield(default['distance'],
                                                     dtype=float)
     entry['instrument/detector/distance'].attrs['units'] = 'mm'
     self.instrument = GridParameters()
     self.instrument.add('distance', entry['instrument/detector/distance'],
                         'Detector Distance (mm)')
     detector_list = sorted(
         list(set([detector().name
                   for detector in ALL_DETECTORS.values()])))
     self.instrument.add('detector', detector_list, 'Detector')
     self.instrument['detector'].value = 'Pilatus CdTe 2M'
     self.instrument.add('positions', [0, 1, 2, 3, 4, 5, 6, 7, 8],
                         'Number of Detector Positions',
                         slot=self.set_entries)
     self.instrument['positions'].value = '0'
Esempio n. 10
0
 def setup_instrument(self):
     entry = self.experiment_file['entry']
     entry.instrument = NXinstrument()
     entry.instrument.monochromator = NXmonochromator()
     entry.instrument.detector = NXdetector()
     entry['instrument/monochromator/wavelength'] = NXfield(0.5, dtype=np.float32)
     entry['instrument/monochromator/wavelength'].attrs['units'] = 'Angstroms'
     entry['instrument/monochromator/energy'] = NXfield(12.398419739640717/0.5, dtype=np.float32)
     entry['instrument/monochromator/energy'].attrs['units'] = 'keV'
     entry['instrument/detector/distance'] = NXfield(100.0, dtype=np.float32)
     entry['instrument/detector/distance'].attrs['units'] = 'mm'
     self.instrument = GridParameters()
     self.instrument.add('experiment', 'experiment', 'Experiment Name')
     self.instrument.add('wavelength', entry['instrument/monochromator/wavelength'], 'Wavelength (Ang)')
     self.instrument.add('distance', entry['instrument/detector/distance'], 'Detector Distance (mm)')
     detector_list = sorted(list(set([detector().name for detector in ALL_DETECTORS.values()])))
     self.instrument.add('detector', detector_list, 'Detector')
     self.instrument['detector'].value = 'Pilatus CdTe 2M'
     self.instrument.add('positions', [0,1,2,3,4], 'Number of Detector Positions', slot=self.set_entries)
     self.instrument['positions'].value = '0'
Esempio n. 11
0
from pyFAI.detectors import ALL_DETECTORS, Detector
from pyFAI.azimuthalIntegrator import AzimuthalIntegrator
from xicam.plugins.operationplugin import describe_input, describe_output, operation, output_names, display_name, units


def get_name(detector):
    if detector.aliases:
        name = detector.aliases[0]
    else:
        name = detector.__class__.__name__
    return name


# Remove 'detector' and sort by name
_detectors = {get_name(detector): detector
              for detector in ALL_DETECTORS.values()
              if detector is not Detector}
_sorted_detectors = dict(sorted(_detectors.items()))
DetectorEnum = Enum('Detector', _sorted_detectors)


@operation
@output_names()
@units("distance", "mm")
@units("center_x", "mm")
@units("center_y", "mm")
@units("tilt", "degrees")
@units("tilt_plane_rotation", "degrees")
@describe_input("distance", "Distance to detector center")
@describe_input("center_x", "")
@describe_input("center_y", "")
Esempio n. 12
0
 def test_detector_instanciate(self):
     """
     this method try to instanciate all the detectors
     """
     for k, v in ALL_DETECTORS.iteritems():
         v()
Esempio n. 13
0
 def test_detector_instanciate(self):
     """
     this method try to instanciate all the detectors
     """
     for k, v in ALL_DETECTORS.iteritems():
         v()