def correlationCoefficient(x, y, mask=None):
    """
        calcualate the correlation coefficient of two numpys
        """
    if x.shape != y.shape:
        apDisplay.printError(
            "images are not the same shape in correlation calc")
    if mask != None:
        if x.shape != mask.shape:
            apDisplay.printError(
                "mask is not the same shape as images in correlation calc")
        tot = mask.sum()
        if tot == 0:
            return 0.0
        x = imagenorm.normStdevMask(x, mask)
        y = imagenorm.normStdevMask(y, mask)
    else:
        tot = float(x.shape[0] * x.shape[1])
        x = imagenorm.normStdev(x)
        y = imagenorm.normStdev(y)
    z = x * y
    if mask != None:
        z = z * mask
    sm = z.sum()
    return sm / tot
def msd(x,y,mask=None):
        if mask != None:
                tot = float(mask.sum())
                if tot == 0:
                        return 1.0e13
                x = imagenorm.normStdevMask(x,mask)
                y = imagenorm.normStdevMask(y,mask)
        else:
                tot = float(x.shape[0]*x.shape[1])
                x = imagenorm.normStdev(x)
                y = imagenorm.normStdev(y)
        z = (x-y)**2
        if mask != None:
                z = z*mask
        sm  = z.sum()
        return sm/tot
def msd(x, y, mask=None):
    if mask != None:
        tot = float(mask.sum())
        if tot == 0:
            return 1.0e13
        x = imagenorm.normStdevMask(x, mask)
        y = imagenorm.normStdevMask(y, mask)
    else:
        tot = float(x.shape[0] * x.shape[1])
        x = imagenorm.normStdev(x)
        y = imagenorm.normStdev(y)
    z = (x - y)**2
    if mask != None:
        z = z * mask
    sm = z.sum()
    return sm / tot
def correlationCoefficient(x,y,mask=None):
        """
        calcualate the correlation coefficient of two numpys
        """
        if x.shape != y.shape:
                apDisplay.printError("images are not the same shape in correlation calc")
        if mask != None:
                if x.shape != mask.shape:
                        apDisplay.printError("mask is not the same shape as images in correlation calc")
                tot = mask.sum()
                if tot == 0:
                        return 0.0
                x = imagenorm.normStdevMask(x,mask)
                y = imagenorm.normStdevMask(y,mask)
        else:
                tot = float(x.shape[0]*x.shape[1])
                x = imagenorm.normStdev(x)
                y = imagenorm.normStdev(y)
        z = x*y
        if mask != None:
                z = z*mask
        sm  = z.sum()
        return sm/tot