How to use the fabio.openimage.openimage function in fabio

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 / 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 edna-site / edna / execPlugins / plugins / EDPluginGroupEDF-v1.0 / plugins / EDPluginExportAsciiPowderv1_0.py View on Github external
def readArrayFromFile(self, _filename):
        """
        Populate self.inputArray for a given filename and extracts as well 
        self.fPixelSize
        self.fDistance
        self.fRadOffset
        self.wavelength ...
        """

        image = openimage(_filename)
        self.inputArray = image.data
        self.dHeader = image.header
        if "Offset_1" in self.dHeader:
            offset, unit = self.dHeader["Offset_1"].split(None, 1)
            if unit.lower() != "pixel":
                EDVerbose.WARNING("I got a strange unit for offset: %s, I expected pixel." % self.dHeader["Offset_1"])
            try:
                self.fRadOffset = float(offset)
            except ValueError:
                strErrorMessage = "EDPluginExportAsciiPowderv1_0.process: Unable to recognize this offset and convert it to float: %s" % self.dHeader["Offset_1"]
                EDVerbose.ERROR(strErrorMessage)
                self.addErrorMessage(strErrorMessage)
                self.setFailure()
                raise ValueError, strErrorMessage

        if "Offset_2" in self.dHeader:
github silx-kit / fabio / fabio / file_series.py View on Github external
def first_image(self):
        """
        First image in a sequence

        :return: fabioimage

        """
        return openimage(self.first())
github silx-kit / fabio / fabio / fabioimage.py View on Github external
def getframe(self, num):
        """ returns the file numbered 'num' in the series as a fabioimage """
        if self.nframes == 1:
            # single image per file
            from .openimage import openimage
            return openimage(fabioutils.jump_filename(self.filename, num))
        raise Exception("getframe out of range")