Пример #1
0
 def invertStack(self, inputFn, outputFn):
     #get input dim
     (x,y,z,n) = xmipp.getImageSize(inputFn)
     #Create empty output stack for efficiency
     xmipp.createEmptyFile(outputFn,x,y,z,n)
     # handle image formats
     for i in range(1, n+1):
         self.invert((i, inputFn), (i, outputFn))
Пример #2
0
 def invertStack(self, inputFn, outputFn):
     #get input dim
     (x,y,z,n) = xmipp.getImageSize(inputFn)
     #Create empty output stack for efficiency
     xmipp.createEmptyFile(outputFn,x,y,z,n)
     # handle image formats
     for i in range(1, n+1):
         self.invert((i, inputFn), (i, outputFn))
Пример #3
0
    def convertStack(self,
                     inputFn,
                     outputFn,
                     firstImg=None,
                     lastImg=None,
                     inFormat=None,
                     outFormat=None):
        """ Convert an input stack file into another.
        It is possible to only use a subset of frames to be written in the
            output stack.
        If outFormat/inFomat=None then there will be
        inferred from extension.If firstFrame/lastFrame are not None, the output
        stack will be a subset of input stack. If it are none, the conversion is
        over the whole stack. If the input format is ".dm4" or  ".img" only is
        allowed the conversion of the whole stack.
        """
        inputLower = inputFn.lower()
        outputLower = outputFn.lower()
        if outputLower.endswith('.img'):
            if (firstImg and lastImg) is None:
                # FIXME Since now we can not read dm4 format in Scipion natively
                # or writing recent .img format
                # we are opening an Eman2 process to read the dm4 file
                from pyworkflow.em.packages.eman2.convert import convertImage
                convertImage(inputFn, outputFn)
            else:
                ext = os.path.splitext(outputFn)[1]
                raise Exception("if convert from %s, firstImg and lastImg "
                                "must be None" % ext)
        # elif inputLower.endswith('.tif'):
        #     # FIXME: It seems that we have some flip problem with compressed
        #     # tif files, we need to check that
        #     if outputLower.endswith('.mrc'):
        #         self.runJob('tif2mrc', '%s %s' % (inputFn, outputFn))
        #     else:
        #         raise Exception("Conversion from tif to %s is not "
        #                         "implemented yet. " % pwutils.getExt(outputFn))
        else:
            # get input dim
            (x, y, z, n) = xmipp.getImageSize(inputFn)

            location = self._convertToLocation(inputFn)
            self._img.read(location, xmipp.HEADER)

            dataType = self.getSupportedDataType(self._img.getDataType(),
                                                 outputLower)

            if (firstImg and lastImg) is None:
                n = max(z, n)
                firstImg = 1
                lastImg = n
            else:
                n = lastImg - firstImg + 1

            # Create empty output stack file to reserve desired space
            xmipp.createEmptyFile(outputFn, x, y, 1, n, dataType)
            for i, j in izip(range(firstImg, lastImg + 1), range(1, n + 1)):
                self.convert((i, inputFn), (j, outputFn))
Пример #4
0
    def convertInputStep(self, volName):
        # Read volume and convert to DOUBLE
        self.vol = xmipp.Image(volName)
        self.vol.convert2DataType(xmipp.DT_DOUBLE)
        # Mask volume if needed
        if self.refMask.get() is not None:
            maskName = getImageLocation(self.refMask.get())
            self.mask = xmipp.Image(maskName)
            self.mask.convert2DataType(xmipp.DT_DOUBLE)
            self.vol.inplaceMultiply(self.mask)
        padding = 2
        maxFreq = 0.5
        splineDegree = 3
        ###
        self.fourierProjectVol = xmipp.FourierProjector(
            self.vol, padding, maxFreq, splineDegree)
        ###
        partSet = self.inputParticles.get()
        nPart = len(partSet)
        numberOfTasks = min(nPart, max(self.numberOfThreads.get() - 1, 1))
        taskSize = nPart / numberOfTasks
        md = xmipp.MetaData()

        # Convert angles and shifts from volume system of coordinates to
        # projection system of coordinates
        mdCount = 0

        for index, part in enumerate(partSet):
            objId = md.addObject()
            imgRow = XmippMdRow()
            particleToRow(part, imgRow)
            shifts, angles = geometryFromMatrix(
                part.getTransform().getMatrix(), True)

            imgRow.setValue(xmipp.MDL_SHIFT_X, -shifts[0])
            imgRow.setValue(xmipp.MDL_SHIFT_Y, -shifts[1])
            imgRow.setValue(xmipp.MDL_SHIFT_Z, 0.)
            imgRow.setValue(xmipp.MDL_ANGLE_ROT, angles[0])
            imgRow.setValue(xmipp.MDL_ANGLE_TILT, angles[1])
            imgRow.setValue(xmipp.MDL_ANGLE_PSI, angles[2])

            imgRow.writeToMd(md, objId)

            # Write a new metadata every taskSize number of elements
            # except in the last chunk where we want to add also the
            # remainder and the condition is the last element
            if ((index % taskSize == taskSize - 1
                 and mdCount < numberOfTasks - 1) or index == nPart - 1):
                md.write(self._getInputParticlesSubsetFn(mdCount))
                md.clear()
                mdCount += 1

        x, y, _ = partSet.getDim()
        xmipp.createEmptyFile(self._getProjGalleryFn(), x, y, 1, nPart)
Пример #5
0
 def convertStack(self, inputFn, outputFn, inFormat=None, outFormat=None):
     """ convert format of stack file. Output/input format is
     specified by outFormat/inFormat. If outFormat/inFomat=None then
     there will be inferred from extension
     """
     #get input dim
     (x,y,z,n) = xmipp.getImageSize(inputFn)
     #Create empty output stack for efficiency
     xmipp.createEmptyFile(outputFn,x,y,z,n)
     # handle image formats
     for i in range(1, n+1):
         self.convert((i, inputFn), (i, outputFn))
Пример #6
0
    def convertStack(self, inputFn, outputFn, firstImg=None, lastImg=None,
                     inFormat=None, outFormat=None):
        """ Convert an input stack file into another.
        It is possible to only use a subset of frames to be written in the
            output stack.
        If outFormat/inFomat=None then there will be
        inferred from extension.If firstFrame/lastFrame are not None, the output
        stack will be a subset of input stack. If it are none, the conversion is
        over the whole stack. If the input format is ".dm4" or  ".img" only is
        allowed the conversion of the whole stack.
        """
        inputLower = inputFn.lower()
        outputLower = outputFn.lower()
        if outputLower.endswith('.img'):
            if (firstImg and lastImg) is None:
                # FIXME Since now we can not read dm4 format in Scipion natively
                # or writing recent .img format
                # we are opening an Eman2 process to read the dm4 file
                from pyworkflow.em.packages.eman2.convert import convertImage
                convertImage(inputFn, outputFn)
            else:
                ext = os.path.splitext(outputFn)[1]
                raise Exception("if convert from %s, firstImg and lastImg "
                                "must be None" % ext)
        # elif inputLower.endswith('.tif'):
        #     # FIXME: It seems that we have some flip problem with compressed
        #     # tif files, we need to check that
        #     if outputLower.endswith('.mrc'):
        #         self.runJob('tif2mrc', '%s %s' % (inputFn, outputFn))
        #     else:
        #         raise Exception("Conversion from tif to %s is not "
        #                         "implemented yet. " % pwutils.getExt(outputFn))
        else:
            # get input dim
            (x, y, z, n) = xmipp.getImageSize(inputFn)
            
            location = self._convertToLocation(inputFn)
            self._img.read(location, xmipp.HEADER)

            dataType = self.getSupportedDataType(self._img.getDataType(), outputLower)
            
            if (firstImg and lastImg) is None:
                n = max(z, n)
                firstImg = 1
                lastImg = n
            else:
                n = lastImg - firstImg + 1
            
            # Create empty output stack file to reserve desired space
            xmipp.createEmptyFile(outputFn,x,y,1,n, dataType)
            for i, j in izip(range(firstImg, lastImg + 1), range(1, n+1)):
                self.convert((i, inputFn), (j, outputFn))
Пример #7
0
    def convertInputStep(self, volName):
        # Read volume and convert to DOUBLE
        self.vol = xmipp.Image(volName)
        self.vol.convert2DataType(xmipp.DT_DOUBLE)
        # Mask volume if needed
        if self.refMask.get() is not None:
            maskName = getImageLocation(self.refMask.get())
            self.mask = xmipp.Image(maskName)
            self.mask.convert2DataType(xmipp.DT_DOUBLE)
            self.vol.inplaceMultiply(self.mask)
        padding = 2
        maxFreq = 0.5
        splineDegree = 3
        ###
        self.fourierProjectVol = xmipp.FourierProjector(self.vol, padding, maxFreq, splineDegree)
        ###
        partSet = self.inputParticles.get()
        nPart = len(partSet)
        numberOfTasks = min(nPart, max(self.numberOfThreads.get()-1, 1))
        taskSize = nPart / numberOfTasks
        md = xmipp.MetaData()

        # Convert angles and shifts from volume system of coordinates to
        # projection system of coordinates
        mdCount = 0

        for index, part in enumerate(partSet):
            objId = md.addObject()
            imgRow = XmippMdRow()
            particleToRow(part, imgRow)
            shifts, angles = geometryFromMatrix(part.getTransform().getMatrix(), True)

            imgRow.setValue(xmipp.MDL_SHIFT_X,-shifts[0])
            imgRow.setValue(xmipp.MDL_SHIFT_Y,-shifts[1])
            imgRow.setValue(xmipp.MDL_SHIFT_Z,0.)
            imgRow.setValue(xmipp.MDL_ANGLE_ROT,angles[0])
            imgRow.setValue(xmipp.MDL_ANGLE_TILT,angles[1])
            imgRow.setValue(xmipp.MDL_ANGLE_PSI,angles[2])

            imgRow.writeToMd(md, objId)

            # Write a new metadata every taskSize number of elements
            # except in the last chunk where we want to add also the
            # remainder and the condition is the last element
            if ((index % taskSize == taskSize-1 and
                 mdCount < numberOfTasks-1) or index == nPart-1):
                md.write(self._getInputParticlesSubsetFn(mdCount))
                md.clear()
                mdCount += 1

        x, y, _ = partSet.getDim()
        xmipp.createEmptyFile(self._getProjGalleryFn(), x, y, 1, nPart)
Пример #8
0
    def convertStack(self,
                     inputFn,
                     outputFn,
                     firstImg=None,
                     lastImg=None,
                     inFormat=None,
                     outFormat=None):
        """ Convert an input stack file into another.
        It is possible to only use a subset of frames to be written in the
            output stack.
        If outFormat/inFomat=None then there will be
        inferred from extension.If firstFrame/lastFrame are not None, the output
        stack will be a subset of input stack. If it are none, the conversion is
        over the whole stack. If the input format is ".dm4" or  ".img" only is
        allowed the conversion of the whole stack.
        """
        if (inputFn.lower().endswith('.dm4')
                or outputFn.lower().endswith('.img')):
            if (firstImg and lastImg) is None:
                # FIXME Since now we can not read dm4 format in Scipion natively
                # or writing recent .img format
                # we are opening an Eman2 process to read the dm4 file
                from pyworkflow.em.packages.eman2.convert import convertImage
                convertImage(inputFn, outputFn)
            else:
                ext = os.path.splitext(outputFn)[1]
                raise Exception("if convert from %s, firstImg and lastImg "
                                "must be None" % ext)
        else:
            # get input dim
            (x, y, z, n) = xmipp.getImageSize(inputFn)

            location = self._convertToLocation(inputFn)
            self._img.read(location, xmipp.HEADER)
            dataType = self._img.getDataType()

            if (firstImg and lastImg) is None:
                n = max(z, n)
                firstImg = 1
                lastImg = n
            else:
                n = lastImg - firstImg + 1

            # Create empty output stack file to reserve desired space
            xmipp.createEmptyFile(outputFn, x, y, 1, n, dataType)
            for i, j in izip(range(firstImg, lastImg + 1), range(1, n + 1)):
                self.convert((i, inputFn), (j, outputFn))
def createEmptyVolume(log,Mask,MaskSize):
    createEmptyFile(Mask,MaskSize,MaskSize,MaskSize)