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

        return errors
Beispiel #2
0
class Config:
    # scipion-pyworkflow will generate the path $SCIPION_HOME/software/bindings
    # The path will be created in the working directory if SCIPION_HOME is not set
    SCIPION_ED_HOME = os.environ.get(
        'SCIPION_HOME', pwutils.expandPattern("~/.scipion-ed-home"))
    # Allowing the user to set SCIPION_ED_USERDATA at installation is issue #8
    SCIPION_ED_USERDATA = os.environ.get(
        'SCIPION_ED_USERDATA', pwutils.expandPattern("~/ScipionEdUserData"))
    # Location of the contents from scipion-ed-testdata
    SCIPION_ED_TESTDATA = os.environ.get('SCIPION_ED_TESTDATA', None)

    SCIPION_ED_TEST_OUTPUT = os.environ.get(
        'SCIPION_ED_TEST_OUTPUT', os.path.join(SCIPION_ED_USERDATA, 'Tests'))
Beispiel #3
0
    def openPath(self, path):
        "Try to open the selected path"
        path = expandPattern(path)

        # If the path is a dir, open it with scipion browser dir <path>
        if os.path.isdir(path):
            dpath = (path if os.path.isabs(path)
                     else os.path.join(os.getcwd(), path))
            subprocess.Popen([pw.getScipionScript(), 'view', dpath])
            return

        # If it is a file, interpret it correctly and open it with DataView
        dirname = os.path.dirname(path)
        fname = os.path.basename(path)
        if '@' in fname:
            path = os.path.join(dirname, fname.split('@', 1)[-1])
        else:
            path = os.path.join(dirname, fname)

        if os.path.exists(path):
            import xmippLib
            fn = xmippLib.FileName(path)
            if fn.isImage() or fn.isMetaData():
                from pyworkflow.em.viewers import DataView
                DataView(path).show()
            else:
                _open_cmd(path)
        else:
            # This is probably one special reference, like sci-open:... that
            # can be interpreted with our handlers.
            tag = path.split(':', 1)[0] if ':' in path else None
            if tag in self.handlers:
                self.handlers[tag](path.split(':', 1)[-1])
            else:
                print "Can't find %s" % path
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 = pwutils.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 #5
0
    def openPath(self, path):
        "Try to open the selected path"
        path = expandPattern(path)

        # If the path is a dir, open it with   scipion browser dir <path>
        if os.path.isdir(path):
            dpath = (path if os.path.isabs(path)
                     else os.path.join(os.getcwd(), path))
            subprocess.Popen(['%s/scipion' % os.environ['SCIPION_HOME'],
                              'browser', 'dir', dpath])
            return

        # If it is a file, interpret it correctly and open it with DataView
        dirname = os.path.dirname(path)
        fname = os.path.basename(path)
        if '@' in fname:
            path = os.path.join(dirname, fname.split('@', 1)[-1])
        else:
            path = os.path.join(dirname, fname)

        if os.path.exists(path):
            _open_cmd(path)
        else:
            # This is probably one special reference, like sci-open:... that
            # can be interpreted with our handlers.
            tag = path.split(':', 1)[0] if ':' in path else None
            if tag in self.handlers:
                self.handlers[tag](path.split(':', 1)[-1])
            else:
                print "Can't find %s" % path
Beispiel #6
0
    def openPath(self, path):
        "Try to open the selected path"
        path = expandPattern(path)

        # If the path is a dir, open it with   scipion browser dir <path>
        if os.path.isdir(path):
            dpath = (path if os.path.isabs(path) else os.path.join(
                os.getcwd(), path))
            subprocess.Popen([
                '%s/scipion' % os.environ['SCIPION_HOME'], 'browser', 'dir',
                dpath
            ])
            return

        # If it is a file, interpret it correctly and open it with DataView
        dirname = os.path.dirname(path)
        fname = os.path.basename(path)
        if '@' in fname:
            path = os.path.join(dirname, fname.split('@', 1)[-1])
        else:
            path = os.path.join(dirname, fname)

        if os.path.exists(path):
            _open_cmd(path)
        else:
            # This is probably one special reference, like sci-open:... that
            # can be interpreted with our handlers.
            tag = path.split(':', 1)[0] if ':' in path else None
            if tag in self.handlers:
                self.handlers[tag](path.split(':', 1)[-1])
            else:
                print "Can't find %s" % path
Beispiel #7
0
    def openPath(self, path):
        "Try to open the selected path"
        path = expandPattern(path)

        # If the path is a dir, open it with scipion browser dir <path>
        if os.path.isdir(path):
            dpath = (path if os.path.isabs(path)
                     else os.path.join(os.getcwd(), path))
            subprocess.Popen([pw.getScipionScript(), 'view', dpath])
            return

        # If it is a file, interpret it correctly and open it with DataView
        dirname = os.path.dirname(path)
        fname = os.path.basename(path)
        if '@' in fname:
            path = os.path.join(dirname, fname.split('@', 1)[-1])
        else:
            path = os.path.join(dirname, fname)

        if os.path.exists(path):
            import xmipp
            fn = xmipp.FileName(path)
            if fn.isImage() or fn.isMetaData():
                from pyworkflow.em.viewer import DataView
                DataView(path).show()
            else:
                _open_cmd(path)
        else:
            # This is probably one special reference, like sci-open:... that
            # can be interpreted with our handlers.
            tag = path.split(':', 1)[0] if ':' in path else None
            if tag in self.handlers:
                self.handlers[tag](path.split(':', 1)[-1])
            else:
                print "Can't find %s" % path
    def importMicrographs(self, pattern, suffix, voltage, sphericalAberration,
                          amplitudeContrast):
        """ Copy images matching the filename pattern
        Register other parameters.
        """
        filePaths = glob(pwutils.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 = emlib.image.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:
                pwutils.copyFile(fn, dst)
            else:
                pwutils.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 #9
0
def castConf(var, value):
    """ Casting definitions for config parameters.
    """
    value = pwutils.expandPattern(value)

    castList = [c for k, c, d in formatConfParameters if k == var]
    if castList:
        cast = castList[0]
    else:
        cast = 'default'

    if cast == 'splitTimesFloat':
        if "*" in value:
            newvar = reduce(lambda x, y: float(x) * float(y), value.split('*'))
        elif "/" in value:
            newvar = reduce(lambda x, y: float(x) / float(y), value.split('/'))
        else:
            newvar = float(value)
    elif cast == bool:
        try:
            newvar = int(value) > 0
        except:
            newvar = False if value.lower() == 'false' else True
    elif cast == 'path':
        newvar = pwutils.expandPattern(value)
    elif cast == 'default':
        if value.lower() == 'true':
            newvar = True
        elif value.lower() == 'false':
            newvar = False
        else:
            try:  # to transform to int: '-1'.isdigit() = False...
                newvar = int(value)
            except:
                try:  # to transform to float (1.234, 1.32E-4...)
                    newvar = float(value)
                except ValueError:
                    newvar = value
    else:
        newvar = cast(value)
    return newvar
        [DELAY, default 30]: delay in seconds between file appearance
    """ % error
    sys.exit(1)


if not len(sys.argv) in (3, 4):
    usage("Incorrect number of input parameters")

inputPattern = sys.argv[1]
outputDir = sys.argv[2]
if len(sys.argv) == 4:
    delay = sys.argv[3]
else:
    delay = 30

inputFiles = glob(pwutils.expandPattern(inputPattern))
inputFiles.sort()

print "Input pattern: ", inputPattern
print "Input files: ", inputFiles
print "Delay: ", str(delay), " seconds."

print "Cleaning output directory: ", outputDir
pwutils.cleanPath(outputDir)
pwutils.makePath(outputDir)

aTime = int(delay)
n = 5
t = aTime / n
print "t=%s" % t
    sys.exit(1)


if not len(sys.argv) in (3, 4, 5):
    usage("Incorrect number of input parameters")

inputPattern = sys.argv[1]
outputDir = sys.argv[2]
gain = None
delay = 30
if len(sys.argv) == 4:
    try:
        delay = int(sys.argv[3])
        gain = None
    except Exception:
        gain = pwutils.expandPattern(sys.argv[3])
        delay = 30
elif len(sys.argv) == 5:
    try:
        delay = int(sys.argv[3])
        gain = pwutils.expandPattern(sys.argv[4])
    except Exception:
        try:
            gain = pwutils.expandPattern(sys.argv[3])
            delay = int(sys.argv[4])
        except:
            usage("DELAY must be an integer.")

inputFiles = glob(pwutils.expandPattern(inputPattern))
inputFiles.sort()
if gain is not None:
Beispiel #12
0
 def _iterFiles(self, pattern):
     filePaths = glob(pwutils.expandPattern(pattern))
     for fn in filePaths:
         yield fn
    def _onAction(self, e=None):
        def is_running(process):
            counter = 0
            s = subprocess.Popen(["ps", "axw"], stdout=subprocess.PIPE)
            for x in s.stdout:
                if re.search(process, x):
                    counter = x.split()[0]
                    break
            return counter

        errors = []
        doBackup = True
        # Check the Data folder exists
        dataFolder = pwutils.expandPattern(self._getValue(DATA_FOLDER))
        if not os.path.exists(pwutils.expandPattern(dataFolder)):
            errors.append("Data folder '%s' does not exists" % dataFolder)
        # check errors
        counter = is_running("mirror_directory.sh")
        if counter > 0:
            errors.append("There is a backup script running in the background")
            errors.append("I cannot continue unless you stop it.")
            errors.append('The command "kill -9 %s" will kill it.' % counter)
            errors.append('Execute it at your own risk from a terminal')

        backupFolder = pwutils.expandPattern(self._getValue(DATA_BACKUP))
        if backupFolder == '':
            doBackup = False
        elif backupFolder.find("@") != -1:  # if remote directory do not check
            pass
        elif not os.path.exists(pwutils.expandPattern(backupFolder)):
            errors.append(
                """Backup folder '%s' already exists. If you want to use you must delete it first"""
                % backupFolder)

        userName = self._getValue(USER_NAME)
        if self.re.match(userName.strip()) is None:
            errors.append("Wrong username")

        sampleName = self._getValue(SAMPLE_NAME)
        if self.re.match(sampleName.strip()) is None:
            errors.append("Wrong sample name")

        projName = self._getProjectName()
        projPath = os.path.join(dataFolder, projName)

        scipionProj = self._getConfValue('SCIPION_PROJECT')
        scipionProjPath = os.path.join(projPath, scipionProj)
        # Do more checks only if there are not previous errors
        if not errors:
            if os.path.exists(projPath):
                errors.append("Project path '%s' already exists." % projPath)

        if not errors:
            if not (self._getValue(MOTIONCORR) or self._getValue(MOTIONCOR2)
                    or self._getValue(OPTICAL_FLOW)):
                errors.append("You should use at least one alignment method."
                              "(%s or %s)" % (MOTIONCORR, OPTICAL_FLOW))

        if errors:
            errors.insert(0, "*Errors*:")
            self.windows.showError("\n  - ".join(errors))
        else:
            self._createDataFolder(projPath, scipionProjPath)
            command = os.path.join(os.getenv("SCIPION_HOME"),
                                   "scripts/mirror_directory.sh")
            if doBackup:
                subprocess.Popen([command, dataFolder, projName, backupFolder],
                                 stdout=open('logfile_out.log', 'w'),
                                 stderr=open('logfile_err.log', 'w'))
            print projName, projPath, scipionProjPath
            self._createScipionProject(projName, projPath, scipionProjPath)
            self.windows.close()