#    plt.imshow(np.corrcoef(ts, rowvar = 0), interpolation = 'nearest')
#    plt.colorbar()
#    plt.subplot(1,2,2)
#    plt.imshow(S, interpolation = 'nearest')
#    plt.colorbar()

#    with open('data/test_gf.bin', 'r') as f:
#        d = cPickle.load(f)
    
    # initialize a parallel pool
    pool = Pool(POOL_SIZE)
    
    # compute the eigenvalues/eigenvectos of the covariance matrix of
    d = gf.data()
    if COSINE_REWEIGHTING:
        d = d * gf.qea_latitude_weights()
        
    Ud, dlam, _ = pca_components_gf(d)
    Ud = Ud[:, :NUM_EIGS]
    dlam = dlam[:NUM_EIGS]
    
    sd = SurrGeoFieldAR([0, 30], 'sbc')
    sd.copy_field(gf)
    sd.prepare_surrogates(pool)
    slam = np.zeros((NUM_SURR, NUM_EIGS))
    maxU = np.zeros((NUM_SURR, NUM_EIGS))
    
    # generate and compute eigenvalues for 20000 surrogates
    t1 = datetime.now()
    
    # construct the surrogates in parallel