def sbar(Ss):
    """
    calculate average s,sigma from list of "s"s.
    """
    if type(Ss) == list:
        Ss = np.array(Ss)
    npts = Ss.shape[0]
    Ss = Ss.transpose()

    avd, avs = [], []
    # D=np.array([Ss[0],Ss[1],Ss[2],Ss[3]+0.5*(Ss[0]+Ss[1]),Ss[4]+0.5*(Ss[1]+Ss[2]),Ss[5]+0.5*(Ss[0]+Ss[2])]).transpose()
    D = np.array([Ss[0], Ss[1], Ss[2], Ss[3] + 0.5 * (Ss[0] + Ss[1]),
                  Ss[4] + 0.5 * (Ss[1] + Ss[2]), Ss[5] + 0.5 * (Ss[0] + Ss[2])])
    for j in range(6):
        avd.append(np.average(D[j]))
        avs.append(np.average(Ss[j]))
    D = D.transpose()
    # for s in Ss:
    #    print 'from sbar: ',s
    #    D.append(s[:]) # append a copy of s
    #    D[-1][3]=D[-1][3]+0.5*(s[0]+s[1])
    #    D[-1][4]=D[-1][4]+0.5*(s[1]+s[2])
    #    D[-1][5]=D[-1][5]+0.5*(s[0]+s[2])
    #    for j in range(6):
    #        avd[j]+=(D[-1][j])/float(npts)
    #        avs[j]+=(s[j])/float(npts)
#   calculate sigma
    nf = (npts - 1) * 6  # number of degrees of freedom
    s0 = 0
    Dels = (D - avd)**2
    s0 = np.sum(Dels)
    sigma = np.sqrt(s0/float(nf))
    return nf, sigma, avs
calculate average s,sigma from list of "s"s.