Beispiel #1
0
    def _validate(self):
        errors = []
        if (not self.patternUntilted.get() or not self.patternTilted.get()):
            errors.append(Message.ERROR_PATTERN_EMPTY)
        else:
            filePathsUntilted = glob(expandPattern(self.patternUntilted.get()))
            filePathsTilted = glob(expandPattern(self.patternTilted.get()))
        
            if (len(filePathsUntilted) == 0 or len(filePathsTilted) == 0):
                errors.append(Message.ERROR_PATTERN_FILES)

        return errors
    def _validate(self):
        errors = []
        if (not self.patternUntilted.get() or not self.patternTilted.get()):
            errors.append(Message.ERROR_PATTERN_EMPTY)
        else:
            filePathsUntilted = glob(expandPattern(self.patternUntilted.get()))
            filePathsTilted = glob(expandPattern(self.patternTilted.get()))

            if (len(filePathsUntilted) == 0 or len(filePathsTilted) == 0):
                errors.append(Message.ERROR_PATTERN_FILES)

        return errors
Beispiel #3
0
    def getPattern(self):
        """ Expand the pattern using environ vars or username
        and also replacing special character # by digit matching.
        """
        self._idRegex = None
        filesPath = self.filesPath.get('').strip()
        filesPattern = self.filesPattern.get('').strip()

        if filesPattern:
            fullPattern = join(filesPath, filesPattern)
        else:
            fullPattern = filesPath

        pattern = expandPattern(fullPattern.replace("$", ""))
        match = re.match('[^#]*(#+)[^#]*', pattern)

        if match is not None:
            g = match.group(1)
            n = len(g)
            # prepare regex pattern - place ids, handle *, handle ?
            idregex = pattern.replace(g, '(%s)' % ('[0-9]' * n))
            idregex = idregex.replace('*', '.*')
            idregex = idregex.replace('?', '.')
            self._idRegex = re.compile(idregex)
            pattern = pattern.replace(g, '[0-9]' * n)

        return pattern
Beispiel #4
0
    def getPattern(self):
        """ Expand the pattern using environ vars or username
        and also replacing special character # by digit matching.
        """
        self._idRegex = None
        filesPath = self.filesPath.get('').strip()
        filesPattern = self.filesPattern.get('').strip()
        
        if filesPattern:
            fullPattern = join(filesPath, filesPattern)
        else:
            fullPattern = filesPath

        pattern = expandPattern(fullPattern.replace("$", ""))
        match = re.match('[^#]*(#+)[^#]*', pattern)
        
        if match is not None:
            g = match.group(1)
            n = len(g)
            # prepare regex pattern - place ids, handle *, handle ?
            idregex = pattern.replace(g, '(%s)' % ('[0-9]'*n))
            idregex = idregex.replace('*','.*')
            idregex = idregex.replace('?', '.')
            self._idRegex = re.compile(idregex)
            pattern = pattern.replace(g, '[0-9]'*n)
        
        return pattern   
    def importMicrographs(self, pattern, suffix, voltage, sphericalAberration,
                          amplitudeContrast):
        """ Copy images matching the filename pattern
        Register other parameters.
        """
        filePaths = glob(expandPattern(pattern))

        #imgSet = SetOfMicrographs(filename=self.micsPairsSqlite, prefix=suffix)
        imgSet = self._createSetOfMicrographs(suffix=suffix)
        acquisition = imgSet.getAcquisition()
        # Setting Acquisition properties
        acquisition.setVoltage(voltage)
        acquisition.setSphericalAberration(sphericalAberration)
        acquisition.setAmplitudeContrast(amplitudeContrast)

        # Call a function that should be implemented by each subclass
        self._setOtherPars(imgSet)

        outFiles = [imgSet.getFileName()]
        imgh = ImageHandler()
        img = imgSet.ITEM_TYPE()
        n = 1
        size = len(filePaths)

        filePaths.sort()

        for i, fn in enumerate(filePaths):
            #             ext = os.path.splitext(basename(f))[1]
            dst = self._getExtraPath(basename(fn))
            if self.copyToProj:
                copyFile(fn, dst)
            else:
                createLink(fn, dst)

            if n > 1:
                for index in range(1, n + 1):
                    img.cleanObjId()
                    img.setFileName(dst)
                    img.setIndex(index)
                    imgSet.append(img)
            else:
                img.cleanObjId()
                img.setFileName(dst)
                # Fill the micName if img is a Micrograph.
                self._fillMicName(img, fn, pattern)
                imgSet.append(img)
            outFiles.append(dst)

            sys.stdout.write("\rImported %d/%d" % (i + 1, size))
            sys.stdout.flush()

        print "\n"

        imgSet.write()

        return imgSet
Beispiel #6
0
    def importMicrographs(self, pattern, suffix, voltage, sphericalAberration, amplitudeContrast):
        """ Copy images matching the filename pattern
        Register other parameters.
        """
        filePaths = glob(expandPattern(pattern))
        
        #imgSet = SetOfMicrographs(filename=self.micsPairsSqlite, prefix=suffix)
        imgSet = self._createSetOfMicrographs(suffix=suffix)
        acquisition = imgSet.getAcquisition()
        # Setting Acquisition properties
        acquisition.setVoltage(voltage)
        acquisition.setSphericalAberration(sphericalAberration)
        acquisition.setAmplitudeContrast(amplitudeContrast)
        
        # Call a function that should be implemented by each subclass
        self._setOtherPars(imgSet)
        
        outFiles = [imgSet.getFileName()]
        imgh = ImageHandler()
        img = imgSet.ITEM_TYPE()
        n = 1
        size = len(filePaths)
        
        filePaths.sort()
        
        for i, fn in enumerate(filePaths):
#             ext = os.path.splitext(basename(f))[1]
            dst = self._getExtraPath(basename(fn))
            if self.copyToProj:
                copyFile(fn, dst)
            else:
                createLink(fn, dst)
            
            if n > 1:
                for index in range(1, n+1):
                    img.cleanObjId()
                    img.setFileName(dst)
                    img.setIndex(index)
                    imgSet.append(img)
            else:
                img.cleanObjId()
                img.setFileName(dst)
                # Fill the micName if img is a Micrograph.
                self._fillMicName(img, fn, pattern)
                imgSet.append(img)
            outFiles.append(dst)
            
            sys.stdout.write("\rImported %d/%d" % (i+1, size))
            sys.stdout.flush()
            
        print "\n"
        
        imgSet.write()
        
        
        return imgSet
Beispiel #7
0
    def getPattern(self):
        """ Expand the pattern using environ vars or username
        and also replacing special character # by digit matching.
        """
        self._idRegex = None
        filesPath = self.filesPath.get('').strip()
        filesPattern = self.filesPattern.get('').strip()

        if filesPattern:
            fullPattern = join(filesPath, filesPattern)
        else:
            fullPattern = filesPath

        pattern = expandPattern(fullPattern)
        match = re.match('[^#]*(#+)[^#]*', pattern)

        if match is not None:
            g = match.group(1)
            n = len(g)
            self._idRegex = re.compile(pattern.replace(g, '(%s)' % ('\d' * n)))
            pattern = pattern.replace(g, '[0-9]' * n)

        return pattern
Beispiel #8
0
 def getPattern(self):
     """ Expand the pattern using environ vars or username
     and also replacing special character # by digit matching.
     """
     self._idRegex = None
     filesPath = self.filesPath.get('').strip()
     filesPattern = self.filesPattern.get('').strip()
     
     if filesPattern:
         fullPattern = join(filesPath, filesPattern)
     else:
         fullPattern = filesPath
         
     pattern = expandPattern(fullPattern)
     match = re.match('[^#]*(#+)[^#]*', pattern)
     
     if match is not None:
         g = match.group(1)
         n = len(g)
         self._idRegex = re.compile(pattern.replace(g, '(%s)' % ('\d'*n)))
         pattern = pattern.replace(g, '[0-9]'*n)
     
     return pattern   
Beispiel #9
0
 def _iterFiles(self, pattern):
     filePaths = glob(expandPattern(pattern))
     for fn in filePaths:
         yield fn