Beispiel #1
0
    def hello(self, im):
        " filename is the classavg image "
        if self.docfile == "" or self.serfile == "":
            self.callTemplates()

        filename = im.info['filename']
            
        #print "hello from " + filename
        tmp = self.doctemplate.get()
        fn = Spiderutils.template2filename(tmp, os.path.basename(filename))
        if len(fn) < 1:
            return
        if not os.path.exists(fn):
            print "Unable to find " + fn
            return
        D = Spiderutils.readdoc(fn, keys='all')
        plist = []
        files = D.keys()
        for f in files:
            num = int(D[f][0])  # each element is a list (of column data)
            imgfilename = Spiderutils.template2filename(self.serfile, num)
            plist.append(imgfilename)
        title = "images for class: " + os.path.basename(filename)
        newtop = Toplevel(self.top)
        m = montage.montage(newtop, imagelist=plist, title=title,
                            useLabels=0)
        m.makeMenus()
        m.createMontage()
Beispiel #2
0
    def getdata(self, filename=None, xcol=None, ycol=None):
        if filename == None or filename == "":
            filename = self.filename
            if self.filename == None or self.filename == "":
                return

        try:
            #D = spiderutils.readSpiderDocFile(filename, [xcol,ycol])
            D = Spiderutils.readdoc(filename, keys='all')
        except:
            print "Unable to get data from %s" % filename
            return

        keys = D.keys()
        if len(keys) < 1:
            print "%s contains no data" % filename
            return

        f = D[keys[0]]
        xmin = f[0]
        xmax = f[0]
        ymin = f[1]
        ymax = f[1]
        
        for k in keys:
            x = D[k][0]
            y = D[k][1]
            if x < xmin: xmin = x
            elif x > xmax: xmax = x
            if y < ymin: ymin = y
            elif y > ymax: ymax = y

        vector_x = (xmin,xmax)
        vector_y = (ymin,ymax)
        return (D, vector_x, vector_y)
Beispiel #3
0
def readDefocus(filename):
    " returns list of (mic#, defocus) pairs (mic=int defocus=string)"
    #    F = spiderutils.readSpiderDocFile(filename, col_list=(1,2))
    F = Spiderutils.readdoc(filename, keys='all')
    if F == None: return []
    keys = F.keys()
    keys.sort()

    M = []
    for key in keys:
        mic = int(F[key][0])
        defocus = str(int(F[key][1]))
        M.append((mic, defocus))
    return M
Beispiel #4
0
def readDefocus(filename):
    " returns list of (mic#, defocus) pairs (mic=int defocus=string)"
#    F = spiderutils.readSpiderDocFile(filename, col_list=(1,2))
    F = Spiderutils.readdoc(filename, keys='all')
    if F == None: return []
    keys = F.keys()
    keys.sort()
    
    M = []
    for key in keys:
        mic     = int(F[key][0])
        defocus = str(int(F[key][1]))
        M.append( (mic, defocus) )
    return M
Beispiel #5
0
def readdoc(filename, factor=1.0, squared=1):
    F = Spiderutils.readdoc(filename, keys='all')
    if F == None: return []
    roofile = 0
    A = []
    B = []
    C = []
    D = []
    E = []
    keys = F.keys()
    keys.sort()

    # get the 1st line of data, test if roo (cols 3 & 4 = 1)
    k = keys[0]
    vals = F[k]
    vlen = len(vals)
    if vlen < 4:
        roofile = 1
    else:  #
        if vals[2] == 1 and vals[3] == 1:
            roofile = 1

    # get the data
    for key in keys:
        if roofile:
            a = factor * F[key][0]
            D.append(a)
        else:
            freq = F[key][0]
            bgd = factor * F[key][1]
            sub = factor * F[key][2]
            env = factor * F[key][3]
            roo = bgd + sub  # get original spectrum
            if squared == 1:
                k = env + bgd
                roo = roo * roo  # square the spectrum
                bgd = bgd * bgd  # square the background
                sub = roo - bgd  # new subtracted curve
                env = k * k - bgd  # new envelope
            A.append(freq)
            B.append(bgd)
            C.append(sub)
            D.append(env)
            E.append(roo)

    if roofile:
        return [D]
    else:
        return [A, B, C, D, E]
Beispiel #6
0
def readdoc(filename, factor=1.0, squared=1):
    F = Spiderutils.readdoc(filename, keys='all')
    if F == None: return []
    roofile = 0
    A = []; B = []; C = []; D = []; E = []
    keys = F.keys()
    keys.sort()
    
    # get the 1st line of data, test if roo (cols 3 & 4 = 1)
    k = keys[0]
    vals = F[k]
    vlen = len(vals)
    if vlen < 4:
        roofile = 1
    else:  #
        if vals[2] == 1 and vals[3] == 1:
            roofile = 1
            
    # get the data
    for key in keys:
        if roofile:
            a = factor * F[key][0]
            D.append(a)
        else:
            freq = F[key][0] 
            bgd  = factor * F[key][1]
            sub  = factor * F[key][2]
            env  = factor * F[key][3]
            roo  = bgd + sub     # get original spectrum
            if squared == 1:
                k = env + bgd  
                roo = roo * roo  # square the spectrum
                bgd = bgd * bgd  # square the background
                sub = roo - bgd  # new subtracted curve
                env = k*k - bgd  # new envelope
            A.append(freq)
            B.append(bgd)
            C.append(sub)
            D.append(env)
            E.append(roo)

    if roofile:
        return [D]
    else:
        return [A,B,C,D,E]
Beispiel #7
0
    def saveDefocus(self, filename=None):
        "save current defocus and file number to a doc file"
        if filename != None:
            self.savefile = filename
        if self.savefile == "":
            filename = asksaveasfilename()
            if filename == "":
                return
            self.savefile = filename
        self.setFileLabels()

        if self.tfedfile == "":
            print "defocus data will be saved to %s" % self.savefile
            return

        micnum = self.filenumber(os.path.basename(self.tfedfile))
        defocus = int(float(self.defocus.get()))
        outfile = self.savefile
        headers = Spiderutils.getDocfileHeaders(outfile)
        if os.path.exists(outfile):
            # try to replace the line
            d = Spiderutils.readdoc(outfile, keys='all')
            keys = d.keys()
            found = 0
            for k in keys:
                mic = d[k][0]
                if mic == micnum:
                    d[k][1] = defocus
                    found = 1
                    break
            if found:
                Spiderutils.writedoc(outfile, columns=d)
            else:
                Spiderutils.writedoc(outfile,
                                     columns=[[micnum], [defocus]],
                                     mode='a')
        else:
            Spiderutils.writedoc(outfile,
                                 columns=[[micnum], [defocus]],
                                 headers=headers)
        #if writedoc(self.savefile, column1=micnum, column2=defocus):
        print "defocus %s saved to %s" % (defocus, outfile)
Beispiel #8
0
    def saveDefocus(self, filename=None):
        "save current defocus and file number to a doc file"
        if filename != None:
            self.savefile = filename
        if self.savefile == "":
            filename = asksaveasfilename()
            if filename == "":
                return 
            self.savefile = filename
        self.setFileLabels()

        if self.tfedfile == "":
            print "defocus data will be saved to %s" % self.savefile
            return

        micnum = self.filenumber(os.path.basename(self.tfedfile))
        defocus = int(float(self.defocus.get()))
        outfile = self.savefile
        headers = Spiderutils.getDocfileHeaders(outfile)
        if os.path.exists(outfile):
            # try to replace the line
            d = Spiderutils.readdoc(outfile, keys='all')
            keys = d.keys()
            found = 0
            for k in keys:
                mic = d[k][0]
                if mic == micnum:
                    d[k][1] = defocus
                    found = 1
                    break
            if found:
                Spiderutils.writedoc(outfile,columns=d)
            else:
                Spiderutils.writedoc(outfile,columns=[[micnum],[defocus]],mode='a')
        else:
            Spiderutils.writedoc(outfile,columns=[[micnum],[defocus]],headers=headers)
        #if writedoc(self.savefile, column1=micnum, column2=defocus):
        print "defocus %s saved to %s" % (defocus, outfile)