예제 #1
0
def analysis(**kwargs):
    """
    Method to fast analyze states from matrices.
  
    
    Parameters
    ----------
    kwargs : dictionary of several parameters
    
        path : string of the data path
        filetype : string ('masked', 'original')
                if you want to use masked matrix or full rank.
        fname : string. pattern of the mat file in input
            default ("mat_corr_sub_%s.mat")
        conditions : list of string of data conditions. 
                should cope with file pattern specified in fname.
        method : string ('speed', 'variance')
                Method used to subsample data.
        max_k : integer (default = 15).
                The maximum number of cluster to use
        state_res_fname : pattern of the output file 
            (default "clustering_labels_%s_maxk_%s_%s_%s.pyobj")
                File used to save labels after clustering.
    
    
    """
    from mvpa_itab.conn.states.utils import plot_metrics, plot_states_matrices

    configuration = {
        "path": "/media/robbis/DATA/fmri/movie_viviana/",
        "filetype": "masked",
        "fname": "mat_corr_sub_%s.mat",
        "conditions": ["movie", "scramble", "rest"],
        "state_res_fname": "clustering_labels_%s_maxk_%s_%s_%s.pyobj",
        "max_k": 15,
        "method": "speed",
    }

    configuration.update(kwargs)

    conditions = configuration["conditions"]
    max_k = configuration["max_k"]
    method = configuration["method"]
    filetype = configuration["filetype"]

    for cond in conditions:

        path = os.path.join(configuration["path"], configuration["filetype"])

        data_, n_roi = get_data(os.path.join(path, "mat_corr_sub_%s.mat" % (str.upper(cond))))

        X, clustering_ = cluster_state(data_, max_k, method)

        metrics_, k_step, metrics_keys = calculate_metrics(X, clustering_)

        fig = plot_metrics(metrics_, metrics_keys, k_step)

        directory = os.path.join(path, method, cond)
        if not os.path.exists(directory):
            os.makedirs(directory)

        state_res_fname = configuration["state_res_fname"]
        pickle.dump(
            clustering_, file(os.path.join(directory, state_res_fname % (cond, str(max_k), method, filetype)), "w")
        )

        fig_fname = os.path.join(directory, "metrics.png")
        fig.savefig(fig_fname)

        for i, cl in enumerate(clustering_):
            if not os.path.exists(os.path.join(directory, str(i + 2))):
                os.makedirs(os.path.join(directory, str(i + 2)))
            plot_states_matrices(X, cl, os.path.join(directory, str(i + 2)), cond)
예제 #2
0
    max_k = 15
    method = 'speed'
    
    X, clustering_ = cluster_state(data_, max_k, method)
    
    metrics_, k_step, metrics_keys = calculate_metrics(X, clustering_)
    pickle.dump(clustering_, file(os.path.join(path, 
                                               "clustering_labels_%s_maxk_%s_%s_%s.pyobj" %(cond,
                                                                                            str(max_k),
                                                                                            method,
                                                                                            filetype), 
                                                   ),
                                  'w'))
    
    plot_states_matrices(X, 
                         clustering_[3],
                         path,
                         cond)

#################

order = {'MOVIE': [0,1,2,3,4],
         'REST': [4,3,1,0,2],
         'SCRAMBLE' : [1,2,4,0,3]
         }

order = {'MOVIE': [0,1,2,3,4],
         'REST': [3,1,2,4,0],
         'SCRAMBLE' : [0,4,2,1,3]
         }

path = '/media/robbis/DATA/fmri/movie_viviana/masked'