class RowMetaData(): """ This class is a wrapper for MetaData in row mode. Where only one object is used. """ def __init__(self, filename=None): self._md = MetaData() self._md.setColumnFormat(False) self._id = self._md.addObject() if filename: self.read(filename) def setValue(self, label, value): self._md.setValue(label, value, self._id) def getValue(self, label): return self._md.getValue(label, self._id) def write(self, filename, mode=MD_APPEND): self._md.write(filename, mode) def read(self, filename): self._md.read(filename) self._md.setColumnFormat(False) self._id = self._md.firstObject() def containsLabel(self, label): return self._md.containsLabel(label) def __str__(self): return str(self._md)
def produceAlignedImagesStep(self, volumeIsCTFCorrected, fn, images): from numpy import array, dot fnOut = 'classes_aligned@' + fn MDin = MetaData(images) MDout = MetaData() n = 1 hasCTF = MDin.containsLabel(xmippLib.MDL_CTF_MODEL) for i in MDin: fnImg = MDin.getValue(xmippLib.MDL_IMAGE, i) fnImgRef = MDin.getValue(xmippLib.MDL_IMAGE_REF, i) maxCC = MDin.getValue(xmippLib.MDL_MAXCC, i) rot = MDin.getValue(xmippLib.MDL_ANGLE_ROT, i) tilt = MDin.getValue(xmippLib.MDL_ANGLE_TILT, i) psi = -1. * MDin.getValue(xmippLib.MDL_ANGLE_PSI, i) flip = MDin.getValue(xmippLib.MDL_FLIP, i) if flip: psi = -psi eulerMatrix = Euler_angles2matrix(0., 0., psi) x = MDin.getValue(xmippLib.MDL_SHIFT_X, i) y = MDin.getValue(xmippLib.MDL_SHIFT_Y, i) shift = array([x, y, 0]) shiftOut = dot(eulerMatrix, shift) [x, y, z] = shiftOut if flip: x = -x id = MDout.addObject() MDout.setValue(xmippLib.MDL_IMAGE, fnImg, id) MDout.setValue(xmippLib.MDL_IMAGE_REF, fnImgRef, id) MDout.setValue(xmippLib.MDL_IMAGE1, "%05d@%s" % (n, self._getExtraPath("diff.stk")), id) if hasCTF: fnCTF = MDin.getValue(xmippLib.MDL_CTF_MODEL, i) MDout.setValue(xmippLib.MDL_CTF_MODEL, fnCTF, id) MDout.setValue(xmippLib.MDL_MAXCC, maxCC, id) MDout.setValue(xmippLib.MDL_ANGLE_ROT, rot, id) MDout.setValue(xmippLib.MDL_ANGLE_TILT, tilt, id) MDout.setValue(xmippLib.MDL_ANGLE_PSI, psi, id) MDout.setValue(xmippLib.MDL_SHIFT_X, x, id) MDout.setValue(xmippLib.MDL_SHIFT_Y, y, id) MDout.setValue(xmippLib.MDL_FLIP, flip, id) MDout.setValue(xmippLib.MDL_ENABLED, 1, id) n += 1 MDout.write(fnOut, xmippLib.MD_APPEND) # Actually create the differences img = Image() imgRef = Image() if hasCTF and volumeIsCTFCorrected: Ts = MDin.getValue(xmippLib.MDL_SAMPLINGRATE, MDin.firstObject()) for i in MDout: img.readApplyGeo(MDout, i) imgRef.read(MDout.getValue(xmippLib.MDL_IMAGE_REF, i)) if hasCTF and volumeIsCTFCorrected: fnCTF = MDout.getValue(xmippLib.MDL_CTF_MODEL, i) applyCTF(imgRef, fnCTF, Ts) img.convert2DataType(DT_DOUBLE) imgDiff = img - imgRef imgDiff.write(MDout.getValue(xmippLib.MDL_IMAGE1, i))