コード例 #1
0
ファイル: base.py プロジェクト: parenthetical-e/wheelerexp
    def run(self, basename, roi, cond, smooth=False, filtfile=None, event=False):
        # Save here....
        table = join_by_underscore(False, basename, roi, cond)

        # and reinit write flags.
        roicount = 0
        mode = 'w'
        header = True

        # Getting to work, find subjects data
        paths = self.data.get_roi_data_paths(roi)
        if not event:
            metas = self.data.get_metapaths_containing(cond)
        else:
            metas = self.data.get_RT_metadata_event_paths()

        # And decompose it
        for path, meta in zip(paths, metas):
            roiname = get_roiname(path)
            print("\t{0}".format(roiname))  ## ...progress

            # If were past the first Ss data, append.
            if roicount > 0:
                mode = 'a'
                header = False

            # Get data
            targets = csv_to_targets(meta)

            X = load_nii(path, clean=True, sparse=False, smooth=smooth)
            targets = tr_pad_targets(targets, "TR", X.shape[0], pad=np.nan)

            # Preprocess labels
            if filtfile is not None:
                targets = reprocess_targets(filtfile, targets, np.nan)
                assert targets["TR"].shape[0] == X.shape[0], ("target" 
                    "reprocessing is broken")
            
            
            norm = MinMaxScaler((0,1))
            X = norm.fit_transform(X.astype(np.float))
            
            Xcs, csnames, ti_cs = self.spacetime.fit_transform(
                    X, targets[cond], targets["trialcount"], 
                    self.window, self.tr)

            # and write.
            dataname = join_by_underscore(False, roiname)
            known = []
            for Xc, csname, ti in zip(Xcs, csnames, ti_cs):
                if not csname in known:
                    save_tcdf(
                            name=join_by_underscore(True, table, csname), 
                            X=Xc, 
                            cond=csname,
                            dataname=dataname,
                            index=ti.astype(np.int),
                            header=header, 
                            mode=mode,
                            float_format="%.{0}f".format(self.nsig))
                    known.append(csname)
                else:
                    save_tcdf(
                            name=join_by_underscore(True, table, csname), 
                            X=Xc, 
                            cond=csname,
                            dataname=dataname,
                            index=ti.astype(np.int),
                            header=False, 
                            mode='a',
                            float_format="%.{0}f".format(self.nsig))
            roicount += 1
コード例 #2
0

if __name__ == '__main__':
    from wheelerdata.load.fh import FH
    from fmrilearn.preprocess.labels import csv_to_targets
    from fmrilearn.load import load_meta
    from fmrilearn.load import load_nii
    from fmrilearn.preprocess.labels import filter_targets

    data = FH()

    metas = data.get_metapaths_containing('rt')
    targets = csv_to_targets(metas[0])

    paths = data.get_roi_data_paths('Insula')
    X = load_nii(paths[0], clean=True, sparse=False, smooth=False)
    scaler = MinMaxScaler(feature_range=(0, 1))
    X = scaler.fit_transform(X.astype(np.float))
    X = X[targets['TR'], :]
    X = X.mean(1)[:, np.newaxis]

    y = targets['rt']
    tc = targets['trialcount']
    Xfir, flfir = fir(X, y, tc, 20, 1.5)
    #Xeva, fleva = eva(X, y, tc, 11, 1.5)

    import matplotlib.pyplot as plt

    fig = plt.figure()
    #    ax1 = fig.add_subplot(211)
    #    ax1.plot(Xeva)
コード例 #3
0
ファイル: analysis.py プロジェクト: parenthetical-e/fmrilearn

if __name__ == '__main__':
    from wheelerdata.load.fh import FH 
    from fmrilearn.preprocess.labels import csv_to_targets
    from fmrilearn.load import load_meta
    from fmrilearn.load import load_nii
    from fmrilearn.preprocess.labels import filter_targets

    data = FH()
    
    metas = data.get_metapaths_containing('rt')
    targets = csv_to_targets(metas[0])

    paths = data.get_roi_data_paths('Insula')
    X = load_nii(paths[0], clean=True, sparse=False, smooth=False)
    scaler = MinMaxScaler(feature_range=(0, 1))
    X = scaler.fit_transform(X.astype(np.float))
    X = X[targets['TR'],:]
    X = X.mean(1)[:,np.newaxis]

    y = targets['rt']
    tc = targets['trialcount']
    Xfir, flfir = fir(X, y, tc, 20, 1.5)
    #Xeva, fleva = eva(X, y, tc, 11, 1.5)

    import matplotlib.pyplot as plt

    fig = plt.figure()
#    ax1 = fig.add_subplot(211)
#    ax1.plot(Xeva)