Ejemplo n.º 1
0
    def test_guess_binning(self):

        #Mar 345 2300 pixels with 150 micron size
        mar = detector_factory("mar345")
        shape = 2300, 2300
        mar.guess_binning(shape)
        self.assertEqual(shape, mar.mask.shape,
                         "Mar345 detector has right mask shape")
        self.assertEqual(mar.pixel1, 150e-6,
                         "Mar345 detector has pixel size 150µ")

        mar = detector_factory("mar345")
        shape = 3450, 3450
        mar.guess_binning(shape)
        self.assertEqual(shape, mar.mask.shape,
                         "Mar345 detector has right mask shape")
        self.assertEqual(mar.pixel1, 100e-6,
                         "Mar345 detector has pixel size 100µ")

        mar = detector_factory("mar165")
        shape = 1364, 1364
        mar.guess_binning(shape)
        self.assertEqual(shape, mar.mask.shape,
                         "Mar165 detector has right mask shape")
        self.assertEqual(mar.pixel1, 118.616e-6,
                         "Mar166 detector has pixel size 118.616µ")
        self.assertEqual(mar.binning, (3, 3), "Mar165 has 3x3 binning")

        mar = detector_factory("RayonixLx170")
        shape = 192, 384
        mar.guess_binning(shape)
        self.assertEqual(mar.binning, (10, 10),
                         "RayonixLx170 has 10x10 binning")
Ejemplo n.º 2
0
    def test_guess_binning(self):

        # Mar 345 2300 pixels with 150 micron size
        mar = detector_factory("mar345")
        shape = 2300, 2300
        mar.guess_binning(shape)
        self.assertEqual(shape, mar.mask.shape, "Mar345 detector has right mask shape")
        self.assertEqual(mar.pixel1, 150e-6, "Mar345 detector has pixel size 150µ")

        mar = detector_factory("mar345")
        shape = 3450, 3450
        mar.guess_binning(shape)
        self.assertEqual(shape, mar.mask.shape, "Mar345 detector has right mask shape")
        self.assertEqual(mar.pixel1, 100e-6, "Mar345 detector has pixel size 100µ")

        mar = detector_factory("mar165")
        shape = 1364, 1364
        mar.guess_binning(shape)
        self.assertEqual(shape, mar.mask.shape, "Mar165 detector has right mask shape")
        self.assertEqual(mar.pixel1, 118.616e-6, "Mar166 detector has pixel size 118.616µ")
        self.assertEqual(mar.binning, (3, 3), "Mar165 has 3x3 binning")

        mar = detector_factory("RayonixLx170")
        shape = 192, 384
        mar.guess_binning(shape)
        self.assertEqual(mar.binning, (10, 10), "RayonixLx170 has 10x10 binning")

        p = detector_factory("Perkin")
        self.assertEqual(p.pixel1, 200e-6, "raw detector has good pixel size")
        self.assertEqual(p.binning, (2, 2), "raw detector has good pixel binning")
        p.guess_binning((4096, 4096))
        self.assertEqual(p.pixel1, 100e-6, "unbinned detector has good pixel size")
        self.assertEqual(p.binning, (1, 1), "unbinned detector has good pixel binning")
Ejemplo n.º 3
0
    def test_nexus_detector(self):
        tmpdir = tempfile.mkdtemp()
        known_fail = []
        if io.h5py is None:
            logger.warning("H5py not present, skipping test_detector.TestDetector.test_nexus_detector")
            return
        for det_name in ALL_DETECTORS:

            fname = os.path.join(tmpdir, det_name + ".h5")
            if os.path.exists(fname):  # already tested with another alias
                continue
            det = detector_factory(det_name)
            logger.info("%s --> nxs" % det_name)
            if (det.pixel1 is None) or (det.shape is None):
                continue
            if (det.shape[0] > 1900) or (det.shape[1] > 1900):
                continue

            det.save(fname)
            new_det = detector_factory(fname)
            for what in ("pixel1", "pixel2", "name", "max_shape", "shape", "binning"):
                if "__len__" in dir(det.__getattribute__(what)):
                    self.assertEqual(det.__getattribute__(what), new_det.__getattribute__(what), "%s is the same for %s" % (what, fname))
                else:
                    self.assertAlmostEqual(det.__getattribute__(what), new_det.__getattribute__(what), 4, "%s is the same for %s" % (what, fname))
            if (det.mask is not None) or (new_det.mask is not None):
                self.assert_(numpy.allclose(det.mask, new_det.mask), "%s mask is not the same" % det_name)

            if det.shape[0] > 2000:
                continue
            try:
                r = det.calc_cartesian_positions()
                o = new_det.calc_cartesian_positions()
            except MemoryError:
                logger.warning("Test nexus_detector failed due to short memory on detector %s" % det_name)
                continue
            self.assertEqual(len(o), len(r), "data have same dimension")
            err1 = abs(r[0] - o[0]).max()
            err2 = abs(r[1] - o[1]).max()
            if det.name in known_fail:
                continue
            if err1 > 1e-6:
                logger.error("%s precision on pixel position 1 is better than 1µm, got %e" % (det_name, err1))
            if err2 > 1e-6:
                logger.error("%s precision on pixel position 1 is better than 1µm, got %e" % (det_name, err2))

            # self.assert_(err1 < 1e-6, "%s precision on pixel position 1 is better than 1µm, got %e" % (det_name, err1))
            # self.assert_(err2 < 1e-6, "%s precision on pixel position 2 is better than 1µm, got %e" % (det_name, err2))
            if not det.IS_FLAT:
                err = abs(r[2] - o[2]).max()
                self.assert_(err < 1e-6, "%s precision on pixel position 3 is better than 1µm, got %e" % (det_name, err))

        # check Pilatus with displacement maps
        # check spline
        # check SPD sisplacement

        shutil.rmtree(tmpdir)
Ejemplo n.º 4
0
    def test_nexus_detector(self):
        tmpdir = tempfile.mkdtemp()
        known_fail = []  #TODO: fix broken detectors
        #        print(tmpdir)
        for det_name in ALL_DETECTORS:
            fname = os.path.join(tmpdir, det_name + ".h5")
            if os.path.exists(fname):  #already tested with another alias
                continue
#            print fname
            det = detector_factory(det_name)
            if (det.pixel1 is None) or (det.shape is None):
                continue


#            print(det)

            det.save(fname)
            new_det = detector_factory(fname)
            #            print new_det
            for what in ("pixel1", "pixel2", "name", "max_shape", "shape",
                         "binning"):
                if "__len__" in dir(det.__getattribute__(what)):
                    self.assertEqual(det.__getattribute__(what),
                                     new_det.__getattribute__(what),
                                     "%s is the same for %s" % (what, fname))
                else:
                    self.assertAlmostEqual(
                        det.__getattribute__(what),
                        new_det.__getattribute__(what), 4,
                        "%s is the same for %s" % (what, fname))
            if det.shape[0] > 2000:
                continue
            r1, r2 = det.calc_cartesian_positions()
            o1, o2 = new_det.calc_cartesian_positions()
            err1 = abs(r1 - o1).max()
            err2 = abs(r2 - o2).max()
            if det.name not in known_fail:
                self.assert_(
                    err1 < 1e-6,
                    "%s precision on pixel position 1 is better than 1µm, got %e"
                    % (det_name, err2))
                self.assert_(
                    err2 < 1e-6,
                    "%s precision on pixel position 2 is better than 1µm, got %e"
                    % (det_name, err2))
            if (det.mask is not None) or (new_det.mask is not None):
                self.assert_(numpy.allclose(det.mask, new_det.mask),
                             "%s mask is not the same" % det_name)

        #check Pilatus with displacement maps
        #check spline
        #check SPD sisplacement

        shutil.rmtree(tmpdir)
Ejemplo n.º 5
0
 def test_non_flat(self):
     """
     tests specific to non flat detectors to ensure consistency
     """
     a = detector_factory("Aarhus")
     # to limit the memory footprint, devide size by 100
     a.binning = (10, 10)
     t0 = time.time()
     n = a.get_pixel_corners(use_cython=False)
     t1 = time.time()
     a._pixel_corners = None
     c = a.get_pixel_corners(use_cython=True)
     t2 = time.time()
     logger.info("Aarhus.get_pixel_corners timing Numpy: %.3fs Cython: %.3fs" % (t1 - t0, t2 - t1))
     self.assert_(abs(n - c).max() < 1e-6, "get_pixel_corners cython == numpy")
     # test pixel center coordinates
     t0 = time.time()
     n1, n2, n3 = a.calc_cartesian_positions(use_cython=False)
     t1 = time.time()
     c1, c2, c3 = a.calc_cartesian_positions(use_cython=True)
     t2 = time.time()
     logger.info("Aarhus.calc_cartesian_positions timing Numpy: %.3fs Cython: %.3fs" % (t1 - t0, t2 - t1))
     self.assert_(abs(n1 - c1).max() < 1e-6, "cartesian coord1 cython == numpy")
     self.assert_(abs(n2 - c2).max() < 1e-6, "cartesian coord2 cython == numpy")
     self.assert_(abs(n3 - c3).max() < 1e-6, "cartesian coord3 cython == numpy")
Ejemplo n.º 6
0
    def test_detector_imxpad_s140(self):
        """
        The masked image has a masked ring around 1.5deg with value
        -10 without mask the pixels should be at -10 ; with mask they
        are at 0
        """
        imxpad = detector_factory("imxpad_s140")

        # check that the cartesian coordinates is cached
        self.assertEqual(hasattr(imxpad, '_pixel_edges'), True)
        self.assertEqual(imxpad._pixel_edges, None)
        y, x = imxpad.calc_cartesian_positions()
        self.assertEqual(imxpad._pixel_edges is None, False)

        # now check that the cached values are identical for each
        # method call
        y1, x1 = imxpad.calc_cartesian_positions()
        self.assertEqual(numpy.all(numpy.equal(y1, y)), True)
        self.assertEqual(numpy.all(numpy.equal(x1, x)), True)

        # check that a few pixel positions are ok.
        self.assertAlmostEqual(y[0, 0], 2.5 * 130e-6 / 2.)
        self.assertAlmostEqual(y[3, 0], y[2, 0] + 130e-6)
        self.assertAlmostEqual(y[119, 0], y[118, 0] + 130e-6 * 3.5 / 2.)

        self.assertAlmostEqual(x[0, 0], 2.5 * 130e-6 / 2.)
        self.assertAlmostEqual(x[0, 3], x[0, 2] + 130e-6)
        self.assertAlmostEqual(x[0, 79], x[0, 78] + 130e-6 * 3.5 / 2.)
Ejemplo n.º 7
0
 def test_non_flat(self):
     """
     tests specific to non flat detectors to ensure consistency
     """
     a = detector_factory("Aarhus")
     t0 = time.time()
     n = a.get_pixel_corners(use_cython=False)
     t1 = time.time()
     a._pixel_corners = None
     c = a.get_pixel_corners(use_cython=True)
     t2 = time.time()
     logger.info(
         "Aarhus.get_pixel_corners timing Numpy: %.3fs Cython: %.3fs" %
         (t1 - t0, t2 - t1))
     self.assert_(
         abs(n - c).max() < 1e-6, "get_pixel_corners cython == numpy")
     # test pixel center coordinates
     t0 = time.time()
     n1, n2, n3 = a.calc_cartesian_positions(use_cython=False)
     t1 = time.time()
     c1, c2, c3 = a.calc_cartesian_positions(use_cython=True)
     t2 = time.time()
     logger.info(
         "Aarhus.calc_cartesian_positions timing Numpy: %.3fs Cython: %.3fs"
         % (t1 - t0, t2 - t1))
     self.assert_(
         abs(n1 - c1).max() < 1e-6, "cartesian coord1 cython == numpy")
     self.assert_(
         abs(n2 - c2).max() < 1e-6, "cartesian coord2 cython == numpy")
     self.assert_(
         abs(n3 - c3).max() < 1e-6, "cartesian coord3 cython == numpy")
Ejemplo n.º 8
0
    def test_detector_imxpad_s140(self):
        """
        The masked image has a masked ring around 1.5deg with value
        -10 without mask the pixels should be at -10 ; with mask they
        are at 0
        """
        imxpad = detector_factory("imxpad_s140")

        # check that the cartesian coordinates is cached
        self.assertEqual(hasattr(imxpad, '_pixel_edges'), True)
        self.assertEqual(imxpad._pixel_edges, None)
        y, x, z = imxpad.calc_cartesian_positions()
        self.assertEqual(imxpad._pixel_edges is None, False)

        # now check that the cached values are identical for each
        # method call
        y1, x1, z1 = imxpad.calc_cartesian_positions()
        self.assertEqual(numpy.all(numpy.equal(y1, y)), True)
        self.assertEqual(numpy.all(numpy.equal(x1, x)), True)
        self.assertEqual(z, None)
        self.assertEqual(z1, None)
        # check that a few pixel positions are ok.
        self.assertAlmostEqual(y[0, 0], 2.5 * 130e-6 / 2.)
        self.assertAlmostEqual(y[3, 0], y[2, 0] + 130e-6)
        self.assertAlmostEqual(y[119, 0], y[118, 0] + 130e-6 * 3.5 / 2.)

        self.assertAlmostEqual(x[0, 0], 2.5 * 130e-6 / 2.)
        self.assertAlmostEqual(x[0, 3], x[0, 2] + 130e-6)
        self.assertAlmostEqual(x[0, 79], x[0, 78] + 130e-6 * 3.5 / 2.)
Ejemplo n.º 9
0
    def test_detector_imxpad_s140(self):
        """
        The masked image has a masked ring around 1.5deg with value
        -10 without mask the pixels should be at -10 ; with mask they
        are at 0
        """
        imxpad = detector_factory("imxpad_s140")

        # check that the cartesian coordinates is cached
        self.assertEqual(hasattr(imxpad, 'COORDINATES'), False)
        y, x = imxpad.calc_cartesian_positions()
        self.assertEqual(hasattr(imxpad, 'COORDINATES'), True)

        # now check that the cached values are identical for each
        # method call
        y1, x1 = imxpad.calc_cartesian_positions()
        self.assertEqual(numpy.all(numpy.equal(y1, y)), True)
        self.assertEqual(numpy.all(numpy.equal(x1, x)), True)

        # check that a few pixel positiopns are ok.
        self.assertAlmostEqual(y[0], 130e-6 / 2.)
        self.assertAlmostEqual(y[1], y[0] + 130e-6)
        self.assertAlmostEqual(y[119], y[118] + 130e-6 * 3.5 / 2.)

        self.assertAlmostEqual(x[0], 130e-6 / 2.)
        self.assertAlmostEqual(x[1], x[0] + 130e-6)
        self.assertAlmostEqual(x[79], x[78] + 130e-6 * 3.5 / 2.)
Ejemplo n.º 10
0
    def test_nexus_detector(self):
        tmpdir = tempfile.mkdtemp()
        known_fail = []
        if io.h5py is None:
            logger.warning("H5py not present, skipping test_detector.TestDetector.test_nexus_detector")
            return
        for det_name in ALL_DETECTORS:
            fname = os.path.join(tmpdir, det_name + ".h5")
            if os.path.exists(fname):  # already tested with another alias
                continue
            det = detector_factory(det_name)
            if (det.pixel1 is None) or (det.shape is None):
                continue
            det.save(fname)
            new_det = detector_factory(fname)
            for what in ("pixel1", "pixel2", "name", "max_shape", "shape", "binning"):
                if "__len__" in dir(det.__getattribute__(what)):
                    self.assertEqual(det.__getattribute__(what), new_det.__getattribute__(what), "%s is the same for %s" % (what, fname))
                else:
                    self.assertAlmostEqual(det.__getattribute__(what), new_det.__getattribute__(what), 4, "%s is the same for %s" % (what, fname))
            if (det.mask is not None) or (new_det.mask is not None):
                self.assert_(numpy.allclose(det.mask, new_det.mask), "%s mask is not the same" % det_name)

            if det.shape[0] > 2000:
                continue
            try:
                r = det.calc_cartesian_positions()
                o = new_det.calc_cartesian_positions()
            except MemoryError:
                logger.warning("Test nexus_detector failed due to short memory on detector %s" % det_name)
                continue
            self.assertEqual(len(o), len(r), "data have same dimension")
            err1 = abs(r[0] - o[0]).max()
            err2 = abs(r[1] - o[1]).max()
            if det.name in known_fail:
                continue
            self.assert_(err1 < 1e-6, "%s precision on pixel position 1 is better than 1µm, got %e" % (det_name, err2))
            self.assert_(err2 < 1e-6, "%s precision on pixel position 2 is better than 1µm, got %e" % (det_name, err2))
            if not det.IS_FLAT:
                err = abs(r[2] - o[2]).max()
                self.assert_(err < 1e-6, "%s precision on pixel position 3 is better than 1µm, got %e" % (det_name, err))

        # check Pilatus with displacement maps
        # check spline
        # check SPD sisplacement

        shutil.rmtree(tmpdir)
Ejemplo n.º 11
0
 def test_Xpad_flat(self):
     d = detector_factory("Xpad S540 flat")
     cy = d.calc_cartesian_positions(use_cython=True)
     np = d.calc_cartesian_positions(use_cython=False)
     self.assert_(numpy.allclose(cy[0], np[0]),
                  "max_delta1=" % abs(cy[0] - np[0]).max())
     self.assert_(numpy.allclose(cy[1], np[1]),
                  "max_delta2=" % abs(cy[1] - np[1]).max())
Ejemplo n.º 12
0
    def test_nexus_detector(self):
        tmpdir = tempfile.mkdtemp()
        known_fail = [] #TODO: fix broken detectors
#        print(tmpdir)
        for det_name in ALL_DETECTORS:
            fname = os.path.join(tmpdir, det_name + ".h5")
            if os.path.exists(fname): #already tested with another alias
                continue
#            print fname
            det = detector_factory(det_name)
            if (det.pixel1 is None) or (det.shape is None):
                continue
#            print(det)

            det.save(fname)
            new_det = detector_factory(fname)
#            print new_det
            for what in ("pixel1", "pixel2", "name", "max_shape", "shape", "binning"):
                if "__len__" in dir(det.__getattribute__(what)):
                    self.assertEqual(det.__getattribute__(what), new_det.__getattribute__(what), "%s is the same for %s" % (what, fname))
                else:
                    self.assertAlmostEqual(det.__getattribute__(what), new_det.__getattribute__(what), 4, "%s is the same for %s" % (what, fname))
            if det.shape[0] > 2000:
                continue
            r1, r2 = det.calc_cartesian_positions()
            o1, o2 = new_det.calc_cartesian_positions()
            err1 = abs(r1 - o1).max()
            err2 = abs(r2 - o2).max()
            if det.name not in known_fail:
                self.assert_(err1 < 1e-6, "%s precision on pixel position 1 is better than 1µm, got %e" % (det_name,err2))
                self.assert_(err2 < 1e-6, "%s precision on pixel position 2 is better than 1µm, got %e" % (det_name, err2))
            if (det.mask is not None) or (new_det.mask is not None):
                self.assert_(numpy.allclose(det.mask, new_det.mask), "%s mask is not the same" % det_name)
            
        #check Pilatus with displacement maps
        #check spline
        #check SPD sisplacement

        shutil.rmtree(tmpdir)
Ejemplo n.º 13
0
    def test_Detector_pickle(self):
        det = self.ai.detector
        dets = dumps(det)
        self.assertTrue(dets, "pickle works")
        rest = loads(dets)
        self.assertTrue(rest, "unpickle works")
        self.assertEqual(rest.shape, self.ai.detector.MAX_SHAPE)

        # test the binning
        mar = detector_factory("RayonixMx225")
        mar.guess_binning((2048, 2048))
        self.assertEqual(mar.binning, (3, 3), "binning OK")
        mars = dumps(mar)
        marr = loads(mars)
        self.assertEqual(mar.binning, marr.binning, "restored binning OK")
Ejemplo n.º 14
0
    def test_detector_rayonix_sx165(self):
        """
        rayonix detectors have different pixel size depending on the binning.
        Check that the set_binning method works for the sx_165

        #personal communication of M. Blum:

     self.desired_pixelsizes[4096]        = 39.500
     self.desired_pixelsizes[2048]        = 79.000
     self.desired_pixelsizes[1364]        = 118.616
     self.desired_pixelsizes[1024]        = 158.000
     self.desired_pixelsizes[512]        = 316.000

        """
        sx165 = detector_factory("rayonixsx165")

        # check the default pixels size and the default binning
        self.assertAlmostEqual(sx165.pixel1, 395e-7)
        self.assertAlmostEqual(sx165.pixel2, 395e-7)
        self.assertEqual(sx165.binning, (1, 1))

        # check binning 1
        sx165.binning = 1
        self.assertAlmostEqual(sx165.pixel1, 395e-7)
        self.assertAlmostEqual(sx165.pixel2, 395e-7)
        self.assertEqual(sx165.binning, (1, 1))

        # check binning 2
        sx165.binning = 2
        self.assertAlmostEqual(sx165.pixel1, 79e-6)
        self.assertAlmostEqual(sx165.pixel2, 79e-6)
        self.assertEqual(sx165.binning, (2, 2))

        # check binning 4
        sx165.binning = 4
        self.assertAlmostEqual(sx165.pixel1, 158e-6)
        self.assertAlmostEqual(sx165.pixel2, 158e-6)
        self.assertEqual(sx165.binning, (4, 4))

        # check binning 8
        sx165.binning = 8
        self.assertAlmostEqual(sx165.pixel1, 316e-6)
        self.assertAlmostEqual(sx165.pixel2, 316e-6)
        self.assertEqual(sx165.binning, (8, 8))

        # check a non standard binning
        sx165.binning = 10
        self.assertAlmostEqual(sx165.pixel1, sx165.pixel2)
Ejemplo n.º 15
0
    def __init__(self,
                 detector,
                 image,
                 pitch,
                 beamcenter,
                 detectordistance,
                 mask=None,
                 invert=False):
        """
        @param detector: instance of Detector or its name
        @param image: 2d array representing the image  
        @param mask:
        @param pitch: floating number in millimeter, representing distance between holes
        @param beamcenter: 2d array for the position of the beam, (y,x)-coordinate in Px
        @param detectordistance: floating number in meter representing distance between detector and scatterin object
        @param invert: set to true if the image of the grid has regular dark spots (instead of bright points) 
        """
        if isinstance(detector, detectors.Detector):
            self.detector = detector
        else:
            self.detector = detectors.detector_factory(detector)

        if isinstance(image, numpy.ndarray):
            self.image = image
        else:
            self.image = fabio.open(image).data

        if mask is not None:
            if isinstance(mask, numpy.ndarray):
                self.mask = mask
            else:
                self.mask = fabio.open(mask).data.astype(bool)
            if self.detector.mask is not None:
                self.mask = numpy.logical_or(self.detector.mask, self.mask)
        else:
            self.mask = numpy.zeros_like(self.image, bool)
        if invert:
            self.image = self.image.max() - self.image

        self.pitch = pitch
        self.detectordistance = detectordistance
        self.beamcenter = beamcenter
        self.coordinates = []
        self.good_peaks = []
        self.mean_vec = []
        self.module_translation = []
        self.grid_angle = []
        self.grid = []
Ejemplo n.º 16
0
    def test_detector_rayonix_sx165(self):
        """
        rayonix detectors have different pixel size depending on the binning.
        Check that the set_binning method works for the sx_165

        #personal communication of M. Blum:

     self.desired_pixelsizes[4096]        = 39.500
     self.desired_pixelsizes[2048]        = 79.000
     self.desired_pixelsizes[1364]        = 118.616
     self.desired_pixelsizes[1024]        = 158.000
     self.desired_pixelsizes[512]        = 316.000

        """
        sx165 = detector_factory("rayonixsx165")

        # check the default pixels size and the default binning
        self.assertAlmostEqual(sx165.pixel1, 395e-7)
        self.assertAlmostEqual(sx165.pixel2, 395e-7)
        self.assertEqual(sx165.binning, (1, 1))

        # check binning 1
        sx165.binning = 1
        self.assertAlmostEqual(sx165.pixel1, 395e-7)
        self.assertAlmostEqual(sx165.pixel2, 395e-7)
        self.assertEqual(sx165.binning, (1, 1))

        # check binning 2
        sx165.binning = 2
        self.assertAlmostEqual(sx165.pixel1, 79e-6)
        self.assertAlmostEqual(sx165.pixel2, 79e-6)
        self.assertEqual(sx165.binning, (2, 2))

        # check binning 4
        sx165.binning = 4
        self.assertAlmostEqual(sx165.pixel1, 158e-6)
        self.assertAlmostEqual(sx165.pixel2, 158e-6)
        self.assertEqual(sx165.binning, (4, 4))

        # check binning 8
        sx165.binning = 8
        self.assertAlmostEqual(sx165.pixel1, 316e-6)
        self.assertAlmostEqual(sx165.pixel2, 316e-6)
        self.assertEqual(sx165.binning, (8, 8))

        # check a non standard binning
        sx165.binning = 10
        self.assertAlmostEqual(sx165.pixel1, sx165.pixel2)
Ejemplo n.º 17
0
def image_test_rings():
    rings = 10
    mod = 50
    detector = detector_factory("Titan")
    sigma = detector.pixel1 * 4
    shape = detector.max_shape
    ai = AzimuthalIntegrator(detector=detector)
    ai.setFit2D(1000, 1000, 1000)
    r = ai.rArray(shape)
    r_max = r.max()
    chi = ai.chiArray(shape)
    img = numpy.zeros(shape)
    modulation = (1 + numpy.sin(5 * r + chi * mod))
    for radius in numpy.linspace(0, r_max, rings):
        img += numpy.exp(-(r - radius)**2 / (2 * (sigma * sigma)))
    return img * modulation
Ejemplo n.º 18
0
def image_test_rings():
    rings = 10
    mod = 50
    detector = detector_factory("Titan")
    sigma = detector.pixel1 * 4
    shape = detector.max_shape
    ai = AzimuthalIntegrator(detector=detector)
    ai.setFit2D(1000, 1000, 1000)
    r = ai.rArray(shape)
    r_max = r.max()
    chi = ai.chiArray(shape)
    img = numpy.zeros(shape)
    modulation = (1 + numpy.sin(5 * r + chi * mod))
    for radius in numpy.linspace(0, r_max, rings):
        img += numpy.exp(-(r - radius) ** 2 / (2 * (sigma * sigma)))
    return img * modulation
Ejemplo n.º 19
0
    def __init__(self, detector, image, pitch, beamcenter, detectordistance, mask=None, invert=False): 
        """
        @param detector: instance of Detector or its name
        @param image: 2d array representing the image  
        @param mask:
        @param pitch: floating number in millimeter, representing distance between holes
        @param beamcenter: 2d array for the position of the beam, (y,x)-coordinate in Px
        @param detectordistance: floating number in meter representing distance between detector and scatterin object
        @param invert: set to true if the image of the grid has regular dark spots (instead of bright points) 
        """
        if isinstance(detector, detectors.Detector):
            self.detector = detector
        else:
            self.detector = detectors.detector_factory(detector)

        if isinstance(image, numpy.ndarray):
            self.image = image
        else:
            self.image = fabio.open(image).data

        if mask is not None:
            if isinstance(mask, numpy.ndarray):
                self.mask = mask
            else:
                self.mask = fabio.open(mask).data.astype(bool)
            if self.detector.mask is not None:
                self.mask = numpy.logical_or(self.detector.mask, self.mask)
        else:
            self.mask = numpy.zeros_like(self.image, bool)
        if invert:
            self.image = self.image.max() - self.image
        
        
        self.pitch = pitch
        self.detectordistance = detectordistance
        self.beamcenter = beamcenter
        self.coordinates=[]
        self.good_peaks=[]
        self.mean_vec = []
        self.module_translation = []
        self.grid_angle =[]
        self.grid =[]
Ejemplo n.º 20
0
    def __init__(self, detector="detector", shape=None):
        """
        @param detector: detector instance or detector name
        """
        if type(detector) in types.StringTypes:
            self.detector = detectors.detector_factory(detector)
        else:  # we assume it is a Detector instance
            self.detector = detector
        if "max_shape" in dir(self.detector):
            self.shape = self.detector.max_shape
        else:
            self.shape = shape
        self.shape = tuple([int(i) for i in self.shape])
        self._sem = threading.Semaphore()

        self.lut_size = None
        self.pos = None
        self.LUT = None
        self.delta0 = self.delta1 = None  # max size of an pixel on a regular grid ...
        self.integrator = None
Ejemplo n.º 21
0
    def __init__(self, detector="detector", shape=None):
        """
        @param detector: detector instance or detector name
        """
        if type(detector) in types.StringTypes:
            self.detector = detectors.detector_factory(detector)
        else:  # we assume it is a Detector instance
            self.detector = detector
        if "max_shape" in dir(self.detector):
            self.shape = self.detector.max_shape
        else:
            self.shape = shape
        self.shape = tuple([int(i) for i in self.shape])
        self._sem = threading.Semaphore()

        self.lut_size = None
        self.pos = None
        self.LUT = None
        self.delta0 = self.delta1 = None  # max size of an pixel on a regular grid ...
        self.integrator = None
Ejemplo n.º 22
0
def image_test_rings():
    "Creating a test image containing gaussian spots on several rings"
    rings = 10
    mod = 50
    detector = detector_factory("Titan")
    sigma = detector.pixel1 * 4
    shape = detector.max_shape
    ai = AzimuthalIntegrator(detector=detector)
    ai.setFit2D(1000, 1000, 1000)
    r = ai.rArray(shape)
    r_max = r.max()
    chi = ai.chiArray(shape)
    img = numpy.zeros(shape)
    modulation = (1 + numpy.sin(5 * r + chi * mod))
    for radius in numpy.linspace(0, r_max, rings):
        img += numpy.exp(-(r - radius) ** 2 / (2 * (sigma * sigma)))

    img *= modulation
    img = add_noise(img, 0.0)
    return img
Ejemplo n.º 23
0
def image_test_rings():
    "Creating a test image containing gaussian spots on several rings"
    rings = 10
    mod = 50
    detector = detector_factory("Titan")
    sigma = detector.pixel1 * 4
    shape = detector.max_shape
    ai = AzimuthalIntegrator(detector=detector)
    ai.setFit2D(1000, 1000, 1000)
    r = ai.rArray(shape)
    r_max = r.max()
    chi = ai.chiArray(shape)
    img = numpy.zeros(shape)
    modulation = (1 + numpy.sin(5 * r + chi * mod))
    for radius in numpy.linspace(0, r_max, rings):
        img += numpy.exp(-(r - radius)**2 / (2 * (sigma * sigma)))

    img *= modulation
    img = add_noise(img, 0.0)
    return img
Ejemplo n.º 24
0
    def __init__(self, detector, module):
        """
        @param detector: instance of Detector or its name
        @param module: Intenger number starting with 0 and row by row
        """
        if isinstance(detector, detectors.Detector):
            self.detector = detector
        else:
            self.detector = detectors.detector_factory(detector)

        self.module = module
        self.module_size = self.detector.MODULE_SIZE
        self.module_gap = self.detector.MODULE_GAP
        self.max_shape = self.detector.MAX_SHAPE
        self.amount = []
        self.center_of_module = []
        self.amount_x = []
        self.amount_y = []
        self.module_area = []
        self.mask = []
        self.mask_grid = []
Ejemplo n.º 25
0
 def __init__(self, detector, module):
     """
     @param detector: instance of Detector or its name
     @param module: Intenger number starting with 0 and row by row
     """
     if isinstance(detector, detectors.Detector):
         self.detector = detector
     else:
         self.detector = detectors.detector_factory(detector)
         
         
     self.module = module
     self.module_size = self.detector.MODULE_SIZE
     self.module_gap = self.detector.MODULE_GAP
     self.max_shape = self.detector.MAX_SHAPE
     self.amount = []
     self.center_of_module = []
     self.amount_x = []
     self.amount_y = []
     self.module_area = []
     self.mask = []
     self.mask_grid = []
Ejemplo n.º 26
0
    def __init__(self, detector="detector", shape=None, method="LUT", device=None, workgroup=8):
        """
        @param detector: detector instance or detector name
        @param shape: shape of the output image
        @param method: "lut" or "csr", the former is faster
        @param device: Name of the device: None for OpenMP, "cpu" or "gpu" or the id of the OpenCL device a 2-tuple of integer
        @param workgroup: workgroup size for CSR on OpenCL
        """
        if type(detector) in types.StringTypes:
            self.detector = detectors.detector_factory(detector)
        else:  # we assume it is a Detector instance
            self.detector = detector
        if "shape" in dir(self.detector):
            self.shape = self.detector.shape
            if shape is not None and self.shape != shape:
                logger.warning("unconsistency in detector geometry, got %s and expected %s" % (shape, self.shape))
                self.shape = shape
        else:
            self.shape = shape
        self.shape = tuple([int(i) for i in self.shape])
        self._sem = threading.Semaphore()

        self.bin_size = None
        self.max_size = None
        self.pos = None
        self.lut = None
        self.delta0 = self.delta1 = None  # max size of an pixel on a regular grid ...
        self.integrator = None
        if not method:
            self.method = "lut"
        else:
            self.method = method.lower()
        self.device = device
        if not workgroup:
            self.workgroup = 8
        else:
            self.workgroup = int(workgroup)
Ejemplo n.º 27
0
 def test_Xpad_flat(self):
     d = detector_factory("Xpad S540 flat")
     cy = d.calc_cartesian_positions(use_cython=True)
     np = d.calc_cartesian_positions(use_cython=False)
     self.assert_(numpy.allclose(cy[0], np[0]), "max_delta1=" % abs(cy[0] - np[0]).max())
     self.assert_(numpy.allclose(cy[1], np[1]), "max_delta2=" % abs(cy[1] - np[1]).max())