Exemple #1
0
def construct3by3(listOfDBZs, showCoast=True, 
                  plotCentroidTrajectory=True,  #   this parameter and below added 2013-11-18
                  DBZstream="",
                  verbose=False,
                  ):                #   
    """   set the 0th in the middle, with 1-8 around it """
    from armor.geometry.frames import setSideBySide, setUpDown
    L = listOfDBZs  #alias
    #print [type(v) for v in L]  #debug
    #time.sleep(3)               #debug
    #L = [v for v in L if isinstance(v, dbz)]
    for im in L:
        if not isinstance(im.matrix, np.ma.MaskedArray):
            im.matrix = np.ma.array(im.matrix)
        im.load()
        im.setThreshold(0)
        if plotCentroidTrajectory:
             im.matrix= im.shortTermTrajectory(hours=6, timeInterval=3, radius=40, verbose=verbose, drawCoast=showCoast).matrix
        im.drawFrame(intensity=9999)
        #im.show()
        #im.showWithCoast(intensity=68)
        #if showCoast:
        #    im.drawCoast(intensity=9999)
        #im.show()

    #debug
    #print L
    #print L.name
    #print '\n'.join([v.name for v in L])
    #time.sleep(1)
    #print "shapes for L[5], L[0], L[6]:", L[5].matrix.shape, L[0].matrix.shape, L[6].matrix.shape
    #debug end
    if len(L) < 9:
        for i in range(9-len(L)):
            L.append(dbz(name='', matrix=L[0].matrix*0))
    #print [type(v) for v in L]  #debug
    #time.sleep(3)               #debug
    #L = [v for v in L if isinstance(v, dbz)]

    a = setSideBySide(L[1:4])
    b = setSideBySide([L[4],L[0],L[5]]) #bug fixed 2013-11-22
    c = setSideBySide(L[6:9])
    #output = setUpDown([a,b,c])
    output = setUpDown([c, b, a])   # 2013-11-22 
    output.name = L[1].name + ', ' + L[2].name + ', ' + L[3].name + '\n' +\
                  L[4].name + ', ' + L[0].name + ', ' + L[5].name + '\n' +\
                  L[6].name + ', ' + L[7].name + ', ' + L[8].name
    return output
def test20131016():
    """
    data sets:  (1) 20120612.0200-0230-0300
                (2) 20120612.0210-0240-0310
    algorithms: (1) plain correlation
                (2) correlation with axes aligned and shift by centroid matching
                (3) correlation with axes aligned and shift by ABLER
                (4) correlation with axes aligned and shift by ABLER and axes rescaled
                (5) (4) with cutoffs
                (6) invariant moments feature comparison
    """
    #   1. get the centroids and moment matrices for both arrays a, b
    #   2. compute both thetas and moment arms
    #   3. translate, backrotate, and scale array a
    #   4. translate and rotate the result to match with b (ABLER or centroid matching)
    #   5. get the correlation of the result with b
    import time
    outputFolder = '/media/KINGSTON/ARMOR/labReports/2013-10-14/0200-0310/'
    outputSting = ''
    logFileName      = 'log' + str(int(time.time())) + '.txt'
    logFile = open(outputFolder+logFileName, 'a')
    import os
    result = []
    try:
        os.makedirs(outputFolder)
    except:
        pass
    from armor.shiiba import regressionCFLfree as cflfree
    reload(cflfree)
    from armor import analysis
    reload(analysis)
    from armor import pattern
    reload(pattern)
    from armor import objects
    reload(objects)
    from armor.objects import a,b,c,d,e,f
    L = [a,b,c,e,d,f]
    LL = {a: [b,c], d: [e,f]}
    LL = {a: [b,c ], d: [e,f]}     #after break
    results = []
    for p in [d, a]:
        for q in LL[p]:
            print '.......................'
            print p.name, '/', q.name
            print 'no shiiba'
            p1 = p.momentNormalise(q, useShiiba=False)
            outputString =  '......................\nno shiiba\n'
            outputString += p.name + '/'+ q.name +'\n'
            outputString += str( p.corr(q) ) +'\n'
            outputString += p1.name + '/'+ q.name +'\n'
            outputString += str( p1.corr(q) )+'\n'
            
            print outputString
            logFile.write(outputString)
            
            p1.imagePath = outputFolder+ p1.name+'.png'
            p1.outputPath = outputFolder+ p1.name+'.txt'
            p1.saveImage()
            p1.saveMatrix()

            pq1 = frames.setSideBySide(q, p1)
            pq1.imagePath = outputFolder+ pq1.name+'.png'
            pq1.outputPath = outputFolder+ pq1.name+'.txt'
            #pq1.saveImage()
            pq1.saveMatrix()
            
            ##############################################################################
            
            print '\n\nwith shiiba'
            xx = raw_input(' \n................\ncentre ?')
            xx = xx.split()
            while len(xx)==2:
                i0, j0 = [int(v) for v in xx]
                p2 = p.momentNormalise(q, centre=(i0, j0), searchWindowHeight=7, searchWindowWidth=13, useShiiba=True)
                print p2.Maffine
                xx = raw_input(' do again? centre ?')
                xx = xx.split()
    

            outputString =  '......................\nwith shiiba\n'
            outputString += p.name + '/'+ q.name+'\n'
            outputString += str( p.corr(q) )+'\n'
            outputString += p.name + '/'+ q.name+'\n'
            outputString += str( p2.corr(q) )+'\n'

            outputString += '\nMaffine: ' + str(p2.Maffine) + '\n\n'
            p2.imagePath = outputFolder+ p2.name+'.png'
            p2.outputPath = outputFolder+ p2.name+'.txt'
            p2.saveImage()
            p2.saveMatrix()

            pq2 = frames.setSideBySide(q, p2)
            pq2.imagePath = outputFolder+ pq2.name+'.png'
            pq2.outputPath = outputFolder+ pq2.name+'.txt'
            #pq2.saveImage()
            pq2.saveMatrix()
            
            print outputString
            logFile.write(outputString)
                        
        result.append( (p, p1, p2, pq1, pq2) )

    return result