Exemple #1
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
Exemple #2
0
 def __setXmippImage(label):
     attr = '_xmipp_' + emlib.label2Str(label)
     if not hasattr(particle, attr):
         img = Image()
         setattr(particle, attr, img)
         img.setSamplingRate(particle.getSamplingRate())
     else:
         img = getattr(particle, attr)
     img.setLocation(xmippToLocation(row.getValue(label)))
Exemple #3
0
    def calculateDeviationsStep(self, it):
        """ Calculate both angles and shifts devitations for all iterations
        """

        SL = emlib.SymList()
        mdIter = emlib.MetaData()
        #for it in self.allIters():
        mdIter.clear()
        SL.readSymmetryFile(self._symmetry[it])
        md1 = emlib.MetaData(self.docFileInputAngles[it])
        md2 = emlib.MetaData(self.docFileInputAngles[it - 1])
        #ignore disabled,
        md1.removeDisabled()
        md2.removeDisabled()

        #first metadata file may not have shiftx and shifty
        if not md2.containsLabel(emlib.MDL_SHIFT_X):
            md2.addLabel(emlib.MDL_SHIFT_X)
            md2.addLabel(emlib.MDL_SHIFT_Y)
            md2.fillConstant(emlib.MDL_SHIFT_X, 0.)
            md2.fillConstant(emlib.MDL_SHIFT_Y, 0.)
        oldLabels = [
            emlib.MDL_ANGLE_ROT, emlib.MDL_ANGLE_TILT, emlib.MDL_ANGLE_PSI,
            emlib.MDL_SHIFT_X, emlib.MDL_SHIFT_Y
        ]
        newLabels = [
            emlib.MDL_ANGLE_ROT2, emlib.MDL_ANGLE_TILT2, emlib.MDL_ANGLE_PSI2,
            emlib.MDL_SHIFT_X2, emlib.MDL_SHIFT_Y2
        ]
        md2.renameColumn(oldLabels, newLabels)
        md2.addLabel(emlib.MDL_SHIFT_X_DIFF)
        md2.addLabel(emlib.MDL_SHIFT_Y_DIFF)
        md2.addLabel(emlib.MDL_SHIFT_DIFF)
        mdIter.join1(md1, md2, emlib.MDL_IMAGE, emlib.INNER_JOIN)
        SL.computeDistance(mdIter, False, False, False)
        emlib.activateMathExtensions()
        #operate in sqlite
        shiftXLabel = emlib.label2Str(emlib.MDL_SHIFT_X)
        shiftX2Label = emlib.label2Str(emlib.MDL_SHIFT_X2)
        shiftXDiff = emlib.label2Str(emlib.MDL_SHIFT_X_DIFF)
        shiftYLabel = emlib.label2Str(emlib.MDL_SHIFT_Y)
        shiftY2Label = emlib.label2Str(emlib.MDL_SHIFT_Y2)
        shiftYDiff = emlib.label2Str(emlib.MDL_SHIFT_Y_DIFF)
        shiftDiff = emlib.label2Str(emlib.MDL_SHIFT_DIFF)
        #timeStr = str(dtBegin)
        operateString = shiftXDiff + "=" + shiftXLabel + "-" + shiftX2Label
        operateString += "," + shiftYDiff + "=" + shiftYLabel + "-" + shiftY2Label
        mdIter.operate(operateString)
        operateString  =  shiftDiff+"=sqrt(" \
                          +shiftXDiff+"*"+shiftXDiff+"+" \
                          +shiftYDiff+"*"+shiftYDiff+");"
        mdIter.operate(operateString)
        iterFile = self._mdDevitationsFn(it)
        mdIter.write(iterFile, emlib.MD_APPEND)

        self._setLastIter(it)
    def test_CTF(self):
        """ Test the conversion of a SetOfParticles to Xmipp metadata. """
        mdCtf = emlib.MetaData(self.dataset.getFile('ctfGold'))
        objId = mdCtf.firstObject()
        rowCtf = rowFromMd(mdCtf, objId)
        ctf = rowToCtfModel(rowCtf)

        ALL_CTF_LABELS = [
            emlib.MDL_CTF_CA,
            emlib.MDL_CTF_ENERGY_LOSS,
            emlib.MDL_CTF_LENS_STABILITY,
            emlib.MDL_CTF_CONVERGENCE_CONE,
            emlib.MDL_CTF_LONGITUDINAL_DISPLACEMENT,
            emlib.MDL_CTF_TRANSVERSAL_DISPLACEMENT,
            emlib.MDL_CTF_K,
            emlib.MDL_CTF_BG_GAUSSIAN_K,
            emlib.MDL_CTF_BG_GAUSSIAN_SIGMAU,
            emlib.MDL_CTF_BG_GAUSSIAN_SIGMAV,
            emlib.MDL_CTF_BG_GAUSSIAN_CU,
            emlib.MDL_CTF_BG_GAUSSIAN_CV,
            emlib.MDL_CTF_BG_SQRT_K,
            emlib.MDL_CTF_BG_SQRT_U,
            emlib.MDL_CTF_BG_SQRT_V,
            emlib.MDL_CTF_BG_SQRT_ANGLE,
            emlib.MDL_CTF_BG_BASELINE,
            emlib.MDL_CTF_BG_GAUSSIAN2_K,
            emlib.MDL_CTF_BG_GAUSSIAN2_SIGMAU,
            emlib.MDL_CTF_BG_GAUSSIAN2_SIGMAV,
            emlib.MDL_CTF_BG_GAUSSIAN2_CU,
            emlib.MDL_CTF_BG_GAUSSIAN2_CV,
            emlib.MDL_CTF_BG_GAUSSIAN2_ANGLE,
            #emlib.MDL_CTF_CRIT_FITTINGSCORE,
            emlib.MDL_CTF_CRIT_FITTINGCORR13,
            emlib.MDL_CTF_DOWNSAMPLE_PERFORMED,
            emlib.MDL_CTF_CRIT_PSDVARIANCE,
            emlib.MDL_CTF_CRIT_PSDPCA1VARIANCE,
            emlib.MDL_CTF_CRIT_PSDPCARUNSTEST,
            emlib.MDL_CTF_CRIT_FIRSTZEROAVG,
            emlib.MDL_CTF_CRIT_DAMPING,
            emlib.MDL_CTF_CRIT_FIRSTZERORATIO,
            emlib.MDL_CTF_CRIT_PSDCORRELATION90,
            emlib.MDL_CTF_CRIT_PSDRADIALINTEGRAL,
            emlib.MDL_CTF_CRIT_NORMALITY,
        ]

        for label in ALL_CTF_LABELS:
            attrName = '_xmipp_%s' % emlib.label2Str(label)
            self.assertAlmostEquals(mdCtf.getValue(label, objId),
                                    ctf.getAttributeValue(attrName))
Exemple #5
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()))
                break
        if imgPath:
            self._imgPreview = self._getImagePreview(imgPath)
            self._imgInfo = self._getImageString(imgPath)
        return msg
Exemple #6
0
def findRow(md, label, value):
    """ Query the metadata for a row with label=value.
    Params:
        md: metadata to query.
        label: label to check value
        value: value for equal condition
    Returns:
        Row object of the row found.
        None if no row is found with label=value
    """
    mdQuery = emlib.MetaData()  # store result
    mdQuery.importObjects(md, emlib.MDValueEQ(label, value))
    n = mdQuery.size()

    if n == 0:
        row = None
    elif n == 1:
        row = emlib.metadata.Row()
        row.readFromMd(mdQuery, mdQuery.firstObject())
    else:
        raise Exception("findRow: more than one row found matching the query "
                        "%s = %s" % (emlib.label2Str(label), value))

    return row