import sys
import tqdm

import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)

import numpy as np
np.set_printoptions(threshold=sys.maxsize)

fmri = np.load('data/fmri_autism_ts.npy', allow_pickle=True)
labels = np.load('data/fmri_autism_labels.npy')

num_subjects = len(fmri)
num_samples, num_rois = np.shape(fmri[0])

"""
Explanation: If this tutorial we are going to use estimate the connectivity and subsequently filter them.

Load data
End of explanation
"""


conn_mtx = np.zeros((num_subjects, num_rois, num_rois))

for subj in tqdm.tqdm(range(num_subjects)):
    fmri_ts = fmri[subj]
    conn_mtx[subj, ...] = np.corrcoef(fmri_ts.T)

np.save('data/fmri_autism_conn_mtx.npy', conn_mtx)

"""
Explanation: Compute the connectivity
End of explanation
"""


thres_conn_mtx = np.zeros_like(conn_mtx)

from dyconnmap.graphs import threshold_eco

for subj in tqdm.tqdm(range(num_subjects)):
    subj_conn_mtx = np.abs(conn_mtx[subj])
    _, CIJtree, _  = threshold_eco(subj_conn_mtx)
    
    thres_conn_mtx[subj] = CIJtree

np.save('data/fmri_autism_thres_conn_mtx.npy', thres_conn_mtx)

"""
Explanation: Filter connectivity matrices
End of explanation
"""


