Пример #1
0
def _particlesToEmx(emxData, partSet, micSet=None, **kwargs):
    """ Write a SetOfMicrograph as expected in EMX format 
    Params:
        micSet: input set of micrographs
        filename: the EMX file where to store the micrographs information.
        micSet: micrographs set associated with the particles
        **kwargs: writeImages: if set to False, only coordinates are exported.
                  imagesStack: if passed all images will be output into a single
                    stack file. 
                  imagesPrefix: used when not imagesStack is passed. A different
                    stack will be created per micrograph.
    """
    writeImages = kwargs.get('writeImages', True)
    imagesPrefix = kwargs.get('imagesPrefix', None)
    micDict = {}
    # Use singleMic for count all particles to be written to a single stack
    imagesStack = kwargs.get('imagesStack', None)
    singleMic = Micrograph()
    singleMic.setFileName(imagesStack)
    singleMic.counter = pwobj.Integer(0)

    def _getMicKey(particle):
        coord = particle.getCoordinate()
        if coord is None or coord.getMicName() is None:
            return '%05d' % particle.getMicId()
        else:
            return pwutils.removeExt(coord.getMicName())

    def _getLocation(particle):
        if imagesStack is not None:
            mic = singleMic
        else:
            micKey = _getMicKey(particle)
            if micKey not in micDict:
                mic = Micrograph()
                mic.setFileName(join(imagesPrefix,
                                     'particles_%s.mrc' % micKey))
                mic.counter = pwobj.Integer(0)
                micDict[micKey] = mic
            else:
                mic = micDict[micKey]
        # Count one more particle assigned to this micrograph
        mic.counter.increment()
        return (mic.counter.get(), mic.getFileName())

    ih = ImageHandler()
    partAlign = partSet.getAlignment()

    for particle in partSet:
        if writeImages:
            newLoc = _getLocation(particle)
            ih.convert(particle, newLoc)
            localFn = basename(newLoc[1])
            particle.setLocation(newLoc[0], localFn)
            emxObj = _particleToEmx(emxData, particle, micSet, partAlign)
        else:
            emxObj = _coordinateToEmx(emxData, particle, micSet)
        emxData.addObject(emxObj)
Пример #2
0
def _particlesToEmx(emxData, partSet, micSet=None, **kwargs):
    """ Write a SetOfMicrograph as expected in EMX format 
    Params:
        micSet: input set of micrographs
        filename: the EMX file where to store the micrographs information.
        micSet: micrographs set associated with the particles
        **kwargs: writeImages: if set to False, only coordinates are exported.
                  imagesStack: if passed all images will be output into a single
                    stack file. 
                  imagesPrefix: used when not imagesStack is passed. A different
                    stack will be created per micrograph.
    """
    writeImages = kwargs.get('writeImages', True)
    imagesPrefix = kwargs.get('imagesPrefix', None)
    micDict = {}
    # Use singleMic for count all particles to be written to a single stack
    imagesStack = kwargs.get('imagesStack', None)
    singleMic = Micrograph()
    singleMic.setFileName(imagesStack)
    singleMic.counter = pwobj.Integer(0)
    
    def _getMicKey(particle):
        coord = particle.getCoordinate()
        if coord is None or coord.getMicName() is None:
            return '%05d' % particle.getMicId()
        else:
            return pwutils.removeExt(coord.getMicName())
        
    def _getLocation(particle):
        if imagesStack is not None:
            mic = singleMic
        else:
            micKey = _getMicKey(particle)
            if micKey not in micDict:
                mic = Micrograph()
                mic.setFileName(join(imagesPrefix, 'particles_%s.mrc' % micKey))
                mic.counter = pwobj.Integer(0)
                micDict[micKey] = mic
            else:
                mic = micDict[micKey]
        # Count one more particle assigned to this micrograph            
        mic.counter.increment()
        return (mic.counter.get(), mic.getFileName())
                
    ih = ImageHandler()
    partAlign = partSet.getAlignment()

    for particle in partSet:
        if writeImages:
            newLoc = _getLocation(particle)
            ih.convert(particle, newLoc)
            localFn = basename(newLoc[1])
            particle.setLocation(newLoc[0], localFn)
            emxObj = _particleToEmx(emxData, particle, micSet, partAlign)
        else:
            emxObj = _coordinateToEmx(emxData, particle, micSet)
        emxData.addObject(emxObj)
Пример #3
0
 def _getLocation(particle):
     if imagesStack is not None:
         mic = singleMic
     else:
         micKey = _getMicKey(particle)
         if micKey not in micDict:
             mic = Micrograph()
             mic.setFileName(join(imagesPrefix, 'particles_%s.mrc' % micKey))
             mic.counter = pwobj.Integer(0)
             micDict[micKey] = mic
         else:
             mic = micDict[micKey]
     # Count one more particle assigned to this micrograph            
     mic.counter.increment()
     return (mic.counter.get(), mic.getFileName())
Пример #4
0
 def _getLocation(particle):
     if imagesStack is not None:
         mic = singleMic
     else:
         micKey = _getMicKey(particle)
         if micKey not in micDict:
             mic = Micrograph()
             mic.setFileName(join(imagesPrefix,
                                  'particles_%s.mrc' % micKey))
             mic.counter = pwobj.Integer(0)
             micDict[micKey] = mic
         else:
             mic = micDict[micKey]
     # Count one more particle assigned to this micrograph
     mic.counter.increment()
     return (mic.counter.get(), mic.getFileName())