How to use fabio - 10 common examples

To help you get started, we’ve selected a few fabio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github silx-kit / fabio / test / testpnmimage.py View on Github external
def test_read(self):
        """ check we can read pnm images"""
        vals = self.results.split()
        name = vals[0]
        dim1, dim2 = [int(x) for x in vals[1:3]]
        mini, maxi, mean, stddev = [float(x) for x in vals[3:]]
        obj = openimage(self.fn[name])
        self.assertAlmostEqual(mini, obj.getmin(), 4, "getmin")
        self.assertAlmostEqual(maxi, obj.getmax(), 4, "getmax")
        self.assertAlmostEqual(mean, obj.getmean(), 4, "getmean")
        self.assertAlmostEqual(stddev, obj.getstddev(), 4, "getstddev")
        self.assertEqual(dim1, obj.dim1, "dim1")
        self.assertEqual(dim2, obj.dim2, "dim2")
github silx-kit / pyFAI / test / test_mask.py View on Github external
def setUp(self):
        """Download files"""
        self.dataFile = UtilsTest.getimage(self.__class__.dataFile)
        self.poniFile = UtilsTest.getimage(self.__class__.poniFile)
        self.ai = pyFAI.load(self.poniFile)
#        self.ai.mask = None
        self.data = fabio.open(self.dataFile).data
        self.mask = self.data < 0
github silx-kit / pyFAI / test / test_bug_regression.py View on Github external
def test_quantile(self):
        if not os.path.exists(self.exe):
            print("Error with executable: %s" % self.exe)
            print(os.listdir(os.path.dirname(self.exe)))
        p = subprocess.call([sys.executable, self.exe, "--quiet", "-q", "0.2-0.8", "-o", self.outfile] + self.image_files,
                            shell=False, env=self.env)
        if p:
            l = [sys.executable, self.exe, "--quiet", "-q", "0.2-0.8", "-o", self.outfile] + self.image_files
            logger.error(os.linesep + (" ".join(l)))
            env = "Environment:"
            for k, v in self.env.items():
                env += "%s    %s: %s" % (os.linesep, k, v)
            logger.error(env)
        self.assertEqual(p, 0, msg="pyFAI-average return code %i != 0" % p)
        self.assert_(numpy.allclose(fabio.open(self.outfile).data, self.res),
                         "pyFAI-average with quantiles gives good results")
github silx-kit / fabio / test / testedfimage.py View on Github external
def setUp(self):
        self.multiFrameFilename = UtilsTest.getimage("MultiFrame.edf.bz2")[:-4]
        self.Frame0Filename = UtilsTest.getimage("MultiFrame-Frame0.edf.bz2")[:-4]
        self.Frame1Filename = UtilsTest.getimage("MultiFrame-Frame1.edf.bz2")[:-4]
        self.ref = edfimage()
        self.frame0 = edfimage()
        self.frame1 = edfimage()
        try:
            self.ref.read(self.multiFrameFilename)
        except:
            raise RuntimeError("Cannot read image multiFrameFilename image %s" % self.multiFrameFilename)
        try:
            self.frame0.read(self.Frame0Filename)
        except:
            raise RuntimeError("Cannot read image Frame0File image %s" % self.Frame0File)
        try:
            self.frame1.read(self.Frame1Filename)
        except:
            raise RuntimeError("Cannot read image Frame1File image %s" % self.Frame1File)
github silx-kit / fabio / test / testedfimage.py View on Github external
def setUp(self):
        self.multiFrameFilename = UtilsTest.getimage("MultiFrame.edf.bz2")[:-4]
        self.Frame0Filename = UtilsTest.getimage("MultiFrame-Frame0.edf.bz2")[:-4]
        self.Frame1Filename = UtilsTest.getimage("MultiFrame-Frame1.edf.bz2")[:-4]
        self.ref = edfimage()
        self.frame0 = edfimage()
        self.frame1 = edfimage()
        try:
            self.ref.read(self.multiFrameFilename)
        except:
            raise RuntimeError("Cannot read image multiFrameFilename image %s" % self.multiFrameFilename)
        try:
            self.frame0.read(self.Frame0Filename)
        except:
            raise RuntimeError("Cannot read image Frame0File image %s" % self.Frame0File)
        try:
            self.frame1.read(self.Frame1Filename)
        except:
            raise RuntimeError("Cannot read image Frame1File image %s" % self.Frame1File)
github silx-kit / fabio / test / testedfimage.py View on Github external
def setUp(self):
        self.multiFrameFilename = UtilsTest.getimage("MultiFrame.edf.bz2")[:-4]
        self.Frame0Filename = UtilsTest.getimage("MultiFrame-Frame0.edf.bz2")[:-4]
        self.Frame1Filename = UtilsTest.getimage("MultiFrame-Frame1.edf.bz2")[:-4]
        self.ref = edfimage()
        self.frame0 = edfimage()
        self.frame1 = edfimage()
        try:
            self.ref.read(self.multiFrameFilename)
        except:
            raise RuntimeError("Cannot read image multiFrameFilename image %s" % self.multiFrameFilename)
        try:
            self.frame0.read(self.Frame0Filename)
        except:
            raise RuntimeError("Cannot read image Frame0File image %s" % self.Frame0File)
        try:
            self.frame1.read(self.Frame1Filename)
        except:
            raise RuntimeError("Cannot read image Frame1File image %s" % self.Frame1File)
github silx-kit / fabio / test / test_cbfimage.py View on Github external
def test_read(self):
        """ check whole reader"""
        times = []
        times.append(time.time())
        cbf = openimage(self.cbf_filename)
        times.append(time.time())
        edf = openimage(self.edf_filename)
        times.append(time.time())

        self.assertAlmostEqual(0, (cbf.data - edf.data).max())
        logging.info("Reading CBF took %.3fs whereas the same EDF took %.3fs" % (times[1] - times[0], times[2] - times[1]))
github silx-kit / fabio / test / testpnmimage.py View on Github external
def test_write(self):
        pnmfile = os.path.join(UtilsTest.tempdir, "pnmfile.pnm")
        shape = (9, 11)
        size = shape[0] * shape[1]
        data = numpy.random.randint(0, 65000, size=size).reshape(shape)
        pnmimage(data=data).save(pnmfile)
        pnm = openimage(pnmfile)
        self.assert_(numpy.allclose(data, pnm.data), "data are the same")
        os.unlink(pnmfile)
github silx-kit / fabio / test / test_cbfimage.py View on Github external
def test_byte_offset(self):
        """ check byte offset algorythm"""
        cbf = openimage(self.cbf_filename)
        starter = "\x0c\x1a\x04\xd5"
        startPos = cbf.cif["_array_data.data"].find(starter) + 4
        data = cbf.cif["_array_data.data"][ startPos: startPos + int(cbf.header["X-Binary-Size"])]

        startTime = time.time()
        numpyRes = cbfimage.analyseNumpy(data, size=cbf.dim1 * cbf.dim2)
        tNumpy = time.time() - startTime
        logging.info("Timing for Numpy method : %.3fs" % tNumpy)

#        startTime = time.time()
#        weaveRes = cbfimage.analyseWeave(data, size=cbf.dim1 * cbf.dim2)
#        tWeave = time.time() - startTime
#        delta = abs(numpyRes - weaveRes).max()
#        self.assertAlmostEqual(0, delta)
#        logging.info("Timing for Weave method : %.3fs, max delta=%s" % (tWeave, delta))
github silx-kit / pyFAI / test / profileDistortionCSR.py View on Github external
# working with halfccd spline
#    x, y = numpy.ogrid[:2048, :2048]
#    grid = numpy.logical_or(x % 100 == 0, y % 100 == 0).astype(numpy.float32) + numpy.ones((2048, 2048), numpy.float32)
#    det = detectors.FReLoN("frelon.spline")


    print det, det.max_shape
    disLUT = _distortion.Distortion(det)
    print disLUT
    lut = disLUT.calc_LUT_size()
    print disLUT.lut_size
    print lut.mean()

    disLUT.calc_LUT()
    outLUT = disLUT.correct(grid)
    fabio.edfimage.edfimage(data=outLUT.astype("float32")).write("test_correct_LUT.edf")

    print("*"*50)


    print det, det.max_shape
    disCSR = _distortionCSR.Distortion(det,foo=64)
    print disCSR
    lut = disCSR.calc_LUT_size()
    print disCSR.lut_size
    print lut.mean()

    disCSR.calc_LUT()
    outCSR = disCSR.correct(grid)
    fabio.edfimage.edfimage(data=outCSR.astype("float32")).write("test_correct_CSR.edf")

    print("*"*50)