Ejemplo n.º 1
0
 def __init__(self, filename=None, dim=512, dpi=96, image=None, label=None):
     
     dpi = min(dpi, dim)
     
     if filename is None and image is None:
         reportError("You should provide image or filename")
 
     import xmipp
     #from pylab import axes, Slider
     from protlib_xmipp import getImageData
     
     
     h = 0.5
     lf0 = 0.15
     hf0 = 0.35
     axcolor = 'lightgoldenrodyellow'
     
     if image is None:
         image = xmipp.Image()
         image.readPreview(filename, dim)
     if filename is None:
         filename = "No filename"
         
     xdim, ydim, zdim, n = image.getDimensions()
     Z = getImageData(image)
     xdim += 10
     ydim += 10
     figure = Figure(figsize=(xdim/dpi, ydim/dpi), dpi=dpi, frameon=False)
     # a tk.DrawingArea
     self.root = tk.Tk()
     self.root.title(filename)
     self.imagePreview=ImagePreview(self.root,dim, dpi)
     self.imagePreview.updateData(Z)
Ejemplo n.º 2
0
    def run(self):
        fn = self.getParam("-i")
        from os.path import splitext

        [fnBase, ext] = splitext(fn)
        if ext != ".cpp":
            reportError(fn + " is not a .cpp file")
        command = "g++ "
        if self.checkParam("--debug"):
            command += "-g -pg"
        xmippDir = getXmippPath()
        if xmippDir == "":
            reportError("$XMIPP_HOME is not set in the environment")
        scipionDir = os.environ["SCIPION_HOME"]
        command += (
            " -o "
            + fnBase
            + " "
            + fn
            + " -O -D_LINUX "
            + "-L"
            + xmippDir
            + "/lib "
            + "-I"
            + xmippDir
            + "/libraries "
            + "-I"
            + xmippDir
            + " "
            + "-lXmippClassif -lXmippData -lXmippInterface -lXmippRecons -lXmippDimred -lXmippBilib -lfftw3 -lfftw3_threads -lsqlite3 -ltiff -ljpeg"
        )
        command += (
            " -I"
            + xmippDir
            + "/external/python/Python-2.7.2/Include -I"
            + xmippDir
            + "/external/python/Python-2.7.2 -L"
            + xmippDir
            + "/external/python/Python-2.7.2 -lpython2.7 -I"
            + xmippDir
            + "/lib/python2.7/site-packages/numpy/core/include"
            + " -I"
            + xmippDir
            + "/external"
            + " -I"
            + scipionDir
            + "/software/include -L"
            + scipionDir
            + "/software/lib"
        )
        os.system(command)
Ejemplo n.º 3
0
    def __init__(self, protocol, script, isMainLoop=True):
        self.ContinueAtStep = getattr(protocol, "ContinueAtStep", 0)
        self.runBehavior = getattr(protocol, "Behavior", "Resume")
        self.dbName = protocol.project.dbName
        self.Import = protocol.Import
        self.Log = protocol.Log
        self.NumberOfMpi = getattr(protocol, "NumberOfMpi", 1)
        self.sqlDict = projectDefaults
        self.connection = sqlite.Connection(self.dbName, timeout=DB_TIMEOUT)
        self.connection.row_factory = sqlite.Row
        self.cur = self.connection.cursor()
        self.cur_aux = self.connection.cursor()
        self.lastStepId = XmippProjectDb.FIRST_STEP
        self.iter = XmippProjectDb.FIRST_ITER
        self.ProjDir = "."
        self.execSqlCommand("pragma foreign_keys=ON", "Foreing key activation failed")
        self.protocolScript = script
        # get run_id
        run_id = self.getRunId(protocol.Name, protocol.RunName)
        if not run_id:
            reportError("Protocol run '%(run_name)s' has not been registered in project database" % self.sqlDict)
        self.sqlDict["run_id"] = run_id

        if isMainLoop:
            # Restart or resume, only meaningless for execution on main protocol loop
            if self.runBehavior == "Restart":
                self.insertStatus = True
                _sqlCommand = "DELETE FROM %(TableSteps)s WHERE run_id = %(run_id)d" % self.sqlDict
                self.execSqlCommand(_sqlCommand, "Error cleaning table: %(TableSteps)s" % self.sqlDict)
            else:
                # This will select steps for comparision in resume mode when insertStep is invoked
                sqlCommand = (
                    """ SELECT step_id, iter, command, parameters, verifyFiles 
                                 FROM %(TableSteps)s 
                                 WHERE (run_id = %(run_id)d)
                                 ORDER BY step_id """
                    % self.sqlDict
                )
                self.cur.execute(sqlCommand)
                self.insertStatus = False
Ejemplo n.º 4
0
    def insertStep(
        self,
        command,
        verifyfiles=[],
        parent_step_id=None,
        execution_mode=SqliteDb.EXEC_MAINLOOP,
        passDb=False,
        **_Parameters
    ):

        if not parent_step_id:
            parent_step_id = self.lastStepId

        parameters = pickle.dumps(_Parameters, 0)
        # Eventually verifyfiles will be dropped and replaced by verifyfilesDictionary

        verifyfilesString = pickle.dumps(verifyfiles, 0)

        if not self.insertStatus:
            # This will use previous select query in constructor
            row = self.cur.fetchone()
            if row is None:
                self.insertStatus = True
            else:
                if self.runBehavior == "Continue" and row["step_id"] >= self.ContinueAtStep:
                    self.insertStatus = True
                elif (
                    self.differentParams(_Parameters, pickle.loads(str(row["parameters"])))
                    or row["verifyFiles"] != verifyfilesString
                ):
                    self.insertStatus = True
                else:
                    for f in verifyfiles:
                        if not exists(f):
                            self.insertStatus = True
                            break
                self.lastStepId = row["step_id"]
                if self.insertStatus:
                    self.sqlDict["step_id"] = row["step_id"]
                    sqlCommand = (
                        """DELETE FROM %(TableSteps)s 
                                           WHERE run_id = %(run_id)d 
                                             AND step_id>=%(step_id)d"""
                        % self.sqlDict
                    )
                    self.cur.execute(sqlCommand)
                    self.connection.commit()
        if self.insertStatus:
            try:

                #                if parent_step_id ==-1:
                #                    self.execSqlCommand('pragma foreign_keys=OFF',"Foreing key deactivation failed")
                #                    parent_step_id = self.lastStepId

                self.cur_aux.execute(
                    """INSERT INTO 
                                    %(TableSteps)s(command,
                                                   parameters,
                                                   verifyfiles,
                                                   iter,
                                                   execution_mode,
                                                   passDb,
                                                   run_id,
                                                   parent_step_id)
                                     VALUES (?,?,?,?,?,?,?,?)"""
                    % self.sqlDict,
                    [
                        command,
                        parameters,
                        verifyfilesString,
                        self.iter,
                        execution_mode,
                        passDb,
                        self.sqlDict["run_id"],
                        parent_step_id,
                    ],
                )

                #                if parent_step_id ==-1:
                #                     self.execSqlCommand('pragma foreign_keys=ON',"Foreing key activation failed")

                # select the last step_id inserted for this run
                self.cur_aux.execute(
                    """SELECT MAX(step_id) 
                                        FROM %(TableSteps)s 
                                        WHERE run_id = %(run_id)d"""
                    % self.sqlDict
                )

                # self.connection.commit()
                self.lastStepId = self.cur_aux.fetchone()[0]
                # fill table with verify files aliases, since they are linke to step_id in cascade I
                # do not need to worry about deleting them
            except sqlite.Error, e:
                reportError("Cannot insert command " + e.args[0])
Ejemplo n.º 5
0
    def __init__(self, dbName):
        try:
            self.dbName = dbName
            self.connection = sqlite.Connection(dbName, timeout=DB_TIMEOUT)
            self.connection.row_factory = sqlite.Row
            self.cur = self.connection.cursor()
            self.sqlDict = projectDefaults
            self.sqlDict["execution_parallel"] = SqliteDb.EXEC_PARALLEL
            self.sqlDict["execution_mainloop"] = SqliteDb.EXEC_MAINLOOP
            self.sqlDict["execution_always"] = SqliteDb.EXEC_ALWAYS
            # enable foreign keys must be executed BEFORE table creation
            self.execSqlCommand("pragma foreign_keys=ON", "Foreing key activation failed")
            self.createProtocolTables()

            _sqlCommand = (
                """CREATE TABLE IF NOT EXISTS %(TableRuns)s
                         (run_id INTEGER PRIMARY KEY AUTOINCREMENT,
                          run_name TEXT,  -- label 
                          run_state INT  DEFAULT 0,  -- state of the run, possible values are:
                                          -- 0 - Saved (Never executed)
                                          -- 1 - Launched (Submited to queue)
                                          -- 2 - Running (Directly or from queue)
                                          -- 3 - Finished (Run finish correctly)
                                          -- 4 - Failed (Run produced an error)
                                          -- 5 - Aborted
                          script TEXT,    -- strip full name
                          init DATE,      -- run started at
                          last_modified DATE, --last modification (edition usually)
                          protocol_name TEXT REFERENCES %(TableProtocols)s(protocol_name), -- protocol name
                          comment TEXT,             -- user defined comment
                          pid  INTEGER DEFAULT -1,  -- process id
                          jobid INTEGER DEFAULT -1, -- this will be different of -1 of queue launched jobs
                          CONSTRAINT unique_workingdir UNIQUE(run_name, protocol_name));"""
                % self.sqlDict
            )
            self.execSqlCommand(_sqlCommand, "Error creating '%(TableRuns)s' table: " % self.sqlDict)
            _sqlCommand = (
                """ CREATE TABLE IF NOT EXISTS %(TableSteps)s 
                         (step_id INTEGER DEFAULT 0, -- primary key (weak entity)
                         command TEXT,               -- command
                         parameters TEXT,            -- wrapper parameters
                         init DATE,                  -- process started at
                         finish DATE,                -- process finished at
                         verifyFiles TEXT,           -- list with files to modify
                         iter INTEGER DEFAULT 1,     -- for iterative scripts, iteration number
                                                     -- useful to resume at iteration n
                         execution_mode INTEGER,     -- Possible values are: 0 - DoAlways, 1 - Mainloop, >1 - Parallel
                                                     -- an external program that will run it
                         passDb BOOL,                -- Should the script pass the database handler
                         run_id INTEGER REFERENCES %(TableRuns)s(run_id)  ON DELETE CASCADE,
                                                     -- key that unify all processes belonging to a run 
                         parent_step_id INTEGER       -- do not set this as a foreign key
                                                      -- because can not reffer to step_id in the same row
                         ,PRIMARY KEY(step_id, run_id)
                         )"""
                % self.sqlDict
            )
            self.execSqlCommand(_sqlCommand, "Error creating %(TableSteps)s table: " % self.sqlDict)

            _sqlCommand = (
                """CREATE TABLE IF NOT EXISTS %(TableParams)s 
                            (parameters TEXT,
                            run_id INTEGER REFERENCES %(TableRuns)s(run_id) ON DELETE CASCADE);"""
                % self.sqlDict
            )
            self.execSqlCommand(_sqlCommand, "Error creating '%(TableParams)s' table: " % self.sqlDict)

            _sqlCommand = (
                """CREATE TRIGGER IF NOT EXISTS increment_step_id 
                             AFTER INSERT ON %(TableSteps)s FOR EACH ROW  
                             BEGIN 
                                UPDATE steps SET step_id = (SELECT MAX(step_id) + 1 
                                                           FROM %(TableSteps)s 
                                                           WHERE run_id = NEW.run_id)
                                WHERE step_id = 0 AND run_id = NEW.run_id; 
                             END """
                % self.sqlDict
            )
            self.execSqlCommand(_sqlCommand, "Error creating trigger: increment_step_id ")
        except sqlite.Error, e:
            reportError("database initialization failed: " + e.args[0])