## Load files. Get number of parcels.
fileSourceIdentities = glob.glob(subjectPath + sourceIdPattern)[0]
fileForwardOperator = glob.glob(subjectPath + forwardPattern)[0]
fileInverseOperator = glob.glob(subjectPath + inversePattern)[0]
fileSourceFidelities = glob.glob(subjectPath + sourceFidPattern)[0]

identities = np.load(
    fileSourceIdentities
)  # Source length vector. Expected ids for parcels are 0 to n-1, where n is number of parcels, and -1 for sources that do not belong to any parcel.
forward = np.matrix(np.load(fileForwardOperator))  # sensors x sources
inverse = np.matrix(np.load(fileInverseOperator))  # sources x sensors
sourceFids = np.load(fileSourceFidelities)  # sources

weights = source_fid_to_weights(sourceFids,
                                exponent=exponent,
                                normalize=normalize,
                                inverse=inverse,
                                identities=identities,
                                flips=flips)
inverse_w = np.einsum('ij,i->ij', inverse, weights)

n_parcels = get_n_parcels(identities)
""" Do network estimation. Get cross-patch complex PLV values from paired data"""
parcelSeriesPairs, pairs = make_series_paired(n_parcels, n_samples, seed=1)
_, cp_PLVPW = fidelity_estimation(forward,
                                  inverse_w,
                                  identities,
                                  parcel_series=parcelSeriesPairs)
_, cp_PLVPO = fidelity_estimation(forward,
                                  inverse,
                                  identities,
                                  parcel_series=parcelSeriesPairs)
    print('Simulation resolution: ' + str(resolution1))
    for i2, resolution2 in enumerate(resolutions):
        print('\t Modeling resolution: ' + str(resolution2))
        for isub, subject in enumerate(subjects):
            """ Make simulated parcel series at resolution1. Measure plv at
        resolution2. Get fidelity with original and weighted inv ops. """
            simulatedParcelSeries = make_series(n_parcels,
                                                n_samples,
                                                n_cut_samples=40,
                                                widths=range(5, 6))
            simulatedSourceSeries = simulatedParcelSeries[idArray[isub][i1]]

            for iexp, exponent in enumerate(exponents):
                newWeights = source_fid_to_weights(
                    sourceFidArray[isub][i2],
                    exponent=exponent,
                    normalize=True,
                    inverse=invOps[isub],
                    identities=idArray[isub][i2])
                weightedInvOp = np.einsum('ij,i->ij', invOps[isub], newWeights)
                modeledSourceSeriesW = np.dot(
                    weightedInvOp, np.dot(forwards[isub],
                                          simulatedSourceSeries))

                indicesS = tuple([iexp, isub, i1, i2,
                                  range(int(resolution1))
                                  ])  # indicesS = simulation resolution
                indicesM = tuple([iexp, isub, i1, i2,
                                  range(int(resolution2))
                                  ])  # indicesM = modeling resolution

                plvArray_meth1[indicesM] = np.abs(