예제 #1
0
def shiiba(a,b, gridSize=20, searchWindowHeight=9, searchWindowWidth=9,\
                 display=False, useRecursion=True, toFile="", 
                 centre=(0,0),
                 ):
    """Shiiba global analysis
    """
    #   2014-01-24
    # imports
    from shiiba import regression2 as regression
    from shiiba import regressionCFLfree as cflfree
    results = cflfree.regressGlobal(a,b, gridSize, searchWindowHeight, searchWindowWidth,\
                 display, useRecursion, centre=centre)
    topResult = results[0]
    (m,n), C, Rsquared = topResult
    prediction  = regression.getPrediction(C, a)
    prediction6 = regression.getPrediction(C, a, coeffsUsed=6)
    corr        = b.corr(prediction)
    vect        = regression.convert(C,a)
    C1 = C.copy()
    C1[2] = 0
    C1[5] = 0
    deformation = regression.convert(C1, a)
    README = 'Results for shiiba global regression.  "mn" = shift, where the first coordinate is i=y, the second is j=x, "vect" =  total vector field, "deformation" = deformation vector field, "corr" = correlation between prediction and ground truth,  "prediction6"= prediction with 6 shiiba coeffs (instead of 9), "results" = list of (m,n), C, Rsquared in descending order of Rsquared'
    
    return {"mn"            : (m,n), 
            "C"             :   C, 
            "Rsquared"      : Rsquared, 
            "prediction"    : prediction,
            "prediction6"   : prediction6,
            "vect"          : vect, 
            "deformation"   : deformation,
            "corr"          : corr, 
            "results"       : results, 
            "README"        : README}
예제 #2
0
def shiibaLocal(a, b, windowSize=100, iRange=range(000, 881, 100),\
                    jRange=range(000, 921, 100), searchWindowHeight=11,\
                    searchWindowWidth=11, useRecursion=True, plotting=True ):
    # imports
    from shiiba import regression2 as regression
    from shiiba import regressionCFLfree as cflfree
    import numpy.ma as ma
    #  results =dictionary with
    #         {'mn': mn, 'C':C, 'Rsquared':Rsquared, 'CR2':CR2, 'timeSpent':timeSpent}
    results=cflfree.regressLocalAll(a, b, windowSize, iRange, jRange, searchWindowHeight,\
                    searchWindowWidth, useRecursion, plotting)
    mn  = results['mn']
    C   = results['C']
    Rsquared    = results['Rsquared']
    # constructing the prediction
    a1 = dbz(name  = 'shiiba prediction for %s and %s' % (a.name, b.name),
            matrix = ma.zeros(a.matrix.shape))
    a1.matrix.fill_value = a.matrix.fill_value
    a1.mask = True
    # constructing the vector field
    U = ma.zeros(a.matrix.shape)
    U.fill_value = a.matrix.fill_value
    U.mask = True
    V = ma.zeros(a.matrix.shape)
    V.fill_value = a.matrix.fill_value
    V.mask = True
    vect = pattern.VectorField(U=U, V=V, \
                            title='shiiba prediction for %s and %s' % (a.name, b.name))
    # filling in the local values
    for i, j in mn.keys():
        aa  = a.getWindow(i, j, windowSize)
        a1.matrix[i:i+windowSize, j:j+windowSize] = regression.getPrediction(C[(i,j)], aa)

        vectLocal = regression.convert(C[(i,j)], aa)
        vect.U[i:i+windowSize, j:j+windowSize] = vectLocal.U
        vect.V[i:i+windowSize, j:j+windowSize] = vectLocal.V
        #########
        # added 15 july 2013 ; doesn't make sense to have a global vector map without adding in the mn[(i,j)]'s
        # adding the shift back to the regression result
        # (see pattern.py and regression2.py)
        vect.U[i:i+windowSize, j:j+windowSize] += mn[(i,j)][0]  # U = first (i-) component ; V = j-component 
        vect.V[i:i+windowSize, j:j+windowSize] += mn[(i,j)][1]
        #
        ##########




    results['prediction']   = a1
    results['vect']         = vect
    return results