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(".")
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'
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()
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()
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'
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'
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", "")