Exemplo n.º 1
0
def getTiltTransformFromParticle(partdata):
        t0 = time.time()

        ### figure out if its particle 1 or 2
        tiltpartq1 = appiondata.ApTiltParticlePairData()
        tiltpartq1['particle1'] = partdata
        tiltpartdatas1 = tiltpartq1.query(results=1, readimages=False)

        tiltpartq2 = appiondata.ApTiltParticlePairData()
        tiltpartq2['particle2'] = partdata
        tiltpartdatas2 = tiltpartq2.query(results=1, readimages=False)

        if tiltpartdatas1 and not tiltpartdatas2:
                imgnum = 1
                transformdata = tiltpartdatas1[0]['transform']
                otherpartdata = tiltpartdatas1[0]['particle2']
        elif not tiltpartdatas1 and tiltpartdatas2:
                imgnum = 2
                transformdata = tiltpartdatas2[0]['transform']
                otherpartdata = tiltpartdatas2[0]['particle1']
        else:
                print partdata
                print tiltpartdatas1
                print tiltpartdatas2
                apDisplay.printError("failed to get tilt pair data")

        if time.time()-t0 > 1.0:
                apDisplay.printMsg("long getTiltTransFromPart1 "+apDisplay.timeString(time.time()-t0))
        return imgnum, transformdata, otherpartdata
Exemplo n.º 2
0
def getStackParticleTiltPair(stackid, partnum, tiltstackid=None):
    """
	takes a stack id and particle number (1+) spider-style
	returns the stack particle number for the tilt pair
	"""
    #print stackid, partnum
    if tiltstackid is None:
        tiltstackid = stackid

    t0 = time.time()
    stackpartdata1 = apStack.getStackParticle(stackid, partnum)
    partdata = stackpartdata1['particle']

    ### figure out if its particle 1 or 2
    tiltpartq1 = appiondata.ApTiltParticlePairData()
    tiltpartq1['particle1'] = partdata
    tiltpartdatas1 = tiltpartq1.query(results=1, readimages=False)

    tiltpartq2 = appiondata.ApTiltParticlePairData()
    tiltpartq2['particle2'] = partdata
    tiltpartdatas2 = tiltpartq2.query(results=1, readimages=False)

    if not tiltpartdatas1 and tiltpartdatas2:
        #print "image1"
        otherpart = tiltpartdatas2[0]['particle1']
    elif tiltpartdatas1 and not tiltpartdatas2:
        #print "image2"
        otherpart = tiltpartdatas1[0]['particle2']
    else:
        print partdata
        print tiltpartdatas1
        print tiltpartdatas2
        apDisplay.printError("failed to get tilt pair data")

    ### get tilt stack particle
    tiltstackdata = apStack.getOnlyStackData(tiltstackid, msg=False)
    stackpartq = appiondata.ApStackParticleData()
    stackpartq['stack'] = tiltstackdata
    stackpartq['particle'] = otherpart
    stackpartdatas2 = stackpartq.query(results=1, readimages=False)
    if not stackpartdatas2:
        #print otherpart.dbid
        #apDisplay.printError("particle "+str(partnum)+" has no tilt pair in stackid="+str(tiltstackid))
        return None
    stackpartdata = stackpartdatas2[0]

    #print partnum,"-->",stackpartnum
    if time.time() - t0 > 1.0:
        apDisplay.printMsg("long getStackPartTiltPair " +
                           apDisplay.timeString(time.time() - t0))
    return stackpartdata
Exemplo n.º 3
0
def insertParticlePeakPairs(peaktree1, peaktree2, peakerrors, imgdata1,
                            imgdata2, transdata, runname):
    """
	takes both image data (imgdata) and inserts particle pairs into DB from peaktrees
	"""
    #INFO
    sessiondata = imgdata1['session']
    legimgid1 = int(imgdata1.dbid)
    legimgid2 = int(imgdata2.dbid)
    imgname1 = imgdata1['filename']
    imgname2 = imgdata2['filename']

    #CHECK ARRAY LENGTHS
    len1 = len(peaktree1)
    len2 = len(peaktree2)
    len3 = len(peakerrors)
    if len1 != len2 or len2 != len3:
        apDisplay.printError("insertParticlePeakPairs particle arrays must have the same length "+\
         str(len1)+" "+str(len2)+" "+str(len3))

    #GET RUN DATA
    runq = appiondata.ApSelectionRunData()
    runq['name'] = runname
    runq['session'] = sessiondata
    selectionruns = runq.query(results=1)
    if not selectionruns:
        apDisplay.printError("could not find selection run in database")

    #GET TRANSFORM DATA
    transq = appiondata.ApImageTiltTransformData()
    transq['image1'] = imgdata1
    transq['image2'] = imgdata2
    transq['tiltrun'] = selectionruns[0]
    transids = transq.query(results=1)
    if not transids:
        apDisplay.printError("could not find transform id in database")

    ### WRITE PARTICLES TO DATABASE
    count = 0
    t0 = time.time()
    last50 = time.time()
    apDisplay.printMsg("looping over " + str(len(peaktree1)) + " particles")
    for i in range(len(peaktree1)):
        remaining_peaks = len(peaktree1) - count
        if count and remaining_peaks and remaining_peaks % 50 == 0:
            #sys.stderr.write("<"+str(len(peaktree1)-count))
            print(
                "%d particles remain, %s time remains, %s per particle, %s last 50 particles"
                % (
                    len(peaktree1) - count,
                    apDisplay.timeString(
                        (time.time() - t0) / count * (remaining_peaks)),
                    apDisplay.timeString((time.time() - t0) / count),
                    apDisplay.timeString(time.time() - last50),
                ))
            last50 = time.time()
        peakdict1 = peaktree1[i]
        peakdict2 = peaktree2[i]
        error = peakerrors[i]

        partq1 = appiondata.ApParticleData()
        partq1['selectionrun'] = selectionruns[0]
        partq1['image'] = imgdata1
        partq1['xcoord'] = peakdict1['xcoord']
        partq1['ycoord'] = peakdict1['ycoord']
        partq1['peakarea'] = 1

        partq2 = appiondata.ApParticleData()
        partq2['selectionrun'] = selectionruns[0]
        partq2['image'] = imgdata2
        partq2['xcoord'] = peakdict2['xcoord']
        partq2['ycoord'] = peakdict2['ycoord']
        partq2['peakarea'] = 1

        # I do NOT have to check if particles already exist, because this is a NEW selectionrun

        partpairq = appiondata.ApTiltParticlePairData()
        partpairq['particle1'] = partq1
        partpairq['particle2'] = partq2
        #NEED TO LOOK UP TRANSFORM DATA
        partpairq['transform'] = transdata
        #NEED TO CALCULATE ERROR, ALWAYS POSITIVE
        partpairq['error'] = error

        #presult = partpairq.query()
        #if not presult:
        count += 1
        partq1.insert(force=True)
        partq2.insert(force=True)
        partpairq.insert(force=True)

    apDisplay.printMsg("inserted " + str(count) + " of " +
                       str(len(peaktree1)) + " peaks into database" + " in " +
                       apDisplay.timeString(time.time() - t0))
    return