コード例 #1
0
    def test_scaleStack(self):
        particles = self.dataset.getFile("particles/BPV_1386.stk")
        outFn = join('/tmp', 'scaled.mrc')
        ih = emlib.image.ImageHandler()
        DT = emlib.DT_FLOAT

        # Scaled with a higher dimension using finalDimension parameter
        EXPECTED_SIZE = (256, 256, 131, 1)
        ih.scale2DStack(particles, outFn, finalDimension=EXPECTED_SIZE[0])

        self.assertTrue(os.path.exists(outFn))
        self.assertTrue(pwutils.getFileSize(outFn) > 0)
        self.assertEqual(ih.getDimensions(outFn), EXPECTED_SIZE)
        self.assertEqual(ih.getDataType(outFn), DT)

        # Scaled with a lower dimension using finalDimension parameter
        EXPECTED_SIZE = (64, 64, 131, 1)
        ih.scale2DStack(particles, outFn, finalDimension=EXPECTED_SIZE[0])

        self.assertTrue(os.path.exists(outFn))
        self.assertTrue(pwutils.getFileSize(outFn) > 0)
        self.assertEqual(ih.getDimensions(outFn), EXPECTED_SIZE)
        self.assertEqual(ih.getDataType(outFn), DT)

        # Scaled with a higher dimension using scaleFactor parameter
        scaleFactor = 1.5
        EXPECTED_SIZE = (210, 210, 131, 1)
        ih.scale2DStack(particles, outFn, scaleFactor=scaleFactor)

        self.assertTrue(os.path.exists(outFn))
        self.assertTrue(pwutils.getFileSize(outFn) > 0)
        self.assertEqual(ih.getDimensions(outFn), EXPECTED_SIZE)
        self.assertEqual(ih.getDataType(outFn), DT)
コード例 #2
0
    def test_convertMovie(self):
        """Check movie conversion"""
        movFn = self.dsFormat.getFile('qbeta/qbeta.mrc') + ":mrcs"

        ih = emlib.image.ImageHandler()
        # Check that we can read the dimensions of the dm4 file:
        EXPECTED_SIZE = (4096, 4096, 1, 7)
        EXPECTED_DT = emlib.DT_USHORT

        self.assertEqual(ih.getDimensions(movFn), EXPECTED_SIZE)
        self.assertEqual(ih.getDataType(movFn), EXPECTED_DT)

        outFn = join('/tmp/qbeta_converted.mrcs')

        ih.convertStack(movFn, outFn, 2, 6)

        self.assertTrue(os.path.exists(outFn))
        self.assertTrue(pwutils.getFileSize(outFn) > 0)
        self.assertEqual(ih.getDimensions(outFn), (4096, 4096, 1, 5))
        self.assertEqual(ih.getDataType(outFn), EXPECTED_DT)

        if pwutils.envVarOn(SCIPION_DEBUG_NOCLEAN):
            print("Not cleaning output movie: ", outFn)
        else:
            pwutils.cleanPath(outFn)
コード例 #3
0
    def test_readDM4(self):
        """ Check we can read dm4 files (using EMAN)
        """
        micFn = self.dsFormat.getFile('SuperRef_c3-adp-se-xyz-0228_001.dm4')

        ih = emlib.image.ImageHandler()
        # Check that we can read the dimensions of the dm4 file:
        EXPECTED_SIZE = (7676, 7420, 1, 1)
        self.assertEqual(ih.getDimensions(micFn), EXPECTED_SIZE)

        # We could even convert to an mrc file:
        outSuffix = pwutils.replaceBaseExt(micFn, 'mrc')

        outFn = join('/tmp', outSuffix)
        print("Converting: \n%s -> %s" % (micFn, outFn))

        ih.convert(micFn, outFn)

        self.assertTrue(os.path.exists(outFn))
        self.assertTrue(pwutils.getFileSize(outFn) > 0)
        # Check dimensions are still the same:
        self.assertEqual(ih.getDimensions(outFn), EXPECTED_SIZE)

        # Clean up tmp files
        pwutils.cleanPath(outFn)
コード例 #4
0
    def _getMdString(self, filename, block=None):
        md = emlib.MetaData()
        if block:
            md.read(block + '@' + filename)
        else:
            md.read(filename, 1)
        labels = md.getActiveLabels()
        msg = "Metadata items: *%d*\n" % md.getParsedLines()
        msg += "Metadata labels: " + ''.join(
            ["\n   - %s" % emlib.label2Str(l) for l in labels])

        imgPath = None
        for label in labels:
            if emlib.labelIsImage(label):
                imgPath = self._getImgPath(
                    filename, md.getValue(label, md.firstObject()))
                if imgPath is None or not os.path.exists(imgPath):
                    imgPath = None
                break

        # If there is an image and is not too big
        if imgPath and pwutils.getFileSize(imgPath) < (
                pwem.Config.MAX_PREVIEW_FILE_SIZE * 1024 * 1024):

            self._imgPreview = self._getImagePreview(imgPath)
            self._imgInfo = self._getImageString(imgPath)
        return msg
コード例 #5
0
    def test_createEmptyImage(self):
        outFn = join('/tmp', 'empty.mrc')
        SIZE = (128, 128, 1, 1)
        ih = emlib.image.ImageHandler()
        DT = emlib.DT_FLOAT
        ih.createEmptyImage(outFn, SIZE[0], SIZE[1], dataType=DT)

        self.assertTrue(pwutils.getFileSize(outFn) > 0)
        self.assertEqual(ih.getDimensions(outFn), SIZE)
        self.assertEqual(ih.getDataType(outFn), DT)
コード例 #6
0
    def test_truncateMask(self):
        ih = emlib.image.ImageHandler()

        maskFn = self.dataset.getFile('masks/mask.vol')
        outFn = join('/tmp', 'mask.vol')

        ih.truncateMask(maskFn, outFn, newDim=128)
        EXPECTED_SIZE = (128, 128, 128, 1)

        self.assertTrue(os.path.exists(outFn))
        self.assertTrue(pwutils.getFileSize(outFn) > 0)
        self.assertEqual(ih.getDimensions(outFn), EXPECTED_SIZE)

        pwutils.cleanPath(outFn)
コード例 #7
0
    def test_convertMicrographs(self):
        """ Convert micrograhs to different formats.
         EMAN2 required for .img
        """
        micFn = self.dataset.getFile('micrographs/BPV_1386.mrc')
        outSuffix = pwutils.replaceBaseExt(micFn, 'img')
        ih = emlib.image.ImageHandler()

        outFn = join('/tmp', outSuffix)
        print("Converting: \n%s -> %s" % (micFn, outFn))

        ih.convert(micFn, outFn)

        self.assertTrue(os.path.exists(outFn))
        self.assertTrue(pwutils.getFileSize(outFn) > 0)

        pwutils.cleanPath(outFn)
        pwutils.cleanPath(outFn.replace('.img', '.hed'))
コード例 #8
0
    def _getImagePreview(self, filename):

        # If file size if big
        if pwutils.getFileSize(filename) > (pwem.Config.MAX_PREVIEW_FILE_SIZE *
                                            1024 * 1024):
            return

        dim = 128

        if isStandardImage(filename):
            self.tkImg = gui.getImage(os.path.abspath(filename),
                                      tkImage=True,
                                      maxheight=dim)
        else:
            fn = self._index + filename
            self.tkImg = getTkImage(self._image, fn, dim)

        return self.tkImg
コード例 #9
0
    def test_readCompressedTIF(self):
        """ Check we can read tif files
        """
        micFn = self.dsFormat.getFile('c3-adp-se-xyz-0228_200.tif')

        ih = emlib.image.ImageHandler()
        # Check that we can read the dimensions of the dm4 file:
        EXPECTED_SIZE = (7676, 7420, 1, 38)
        self.assertEqual(ih.getDimensions(micFn), EXPECTED_SIZE)

        # We could even convert to an mrc file:
        outSuffix = pwutils.replaceBaseExt(micFn, 'mrc')

        outFn = join('/tmp', outSuffix)
        print("Converting: \n%s -> %s" % ((1, micFn), outFn))

        ih.convert((1, micFn), outFn)

        self.assertTrue(os.path.exists(outFn))
        self.assertTrue(pwutils.getFileSize(outFn) > 0)
        self.assertEqual(ih.getDimensions(outFn), (7676, 7420, 1, 1))

        # Clean up tmp files
        pwutils.cleanPath(outFn)
コード例 #10
0
    def size(self):
        s = 0
        for f in self.files:
            s += pwutils.getFileSize(f)

        return s