예제 #1
0
def get_data(name):
    """Return the named Wheelerdata object"""

    if name == 'fh':
        data = FH()
    elif name == 'butterfly':
        data = Butterfly()
    elif name == 'clock':
        data = Clock()
    elif name == 'polygon':
        data = Polygon()
    elif name == 'redgreen':
        data = Redgreen()
    elif name == "biasbox":
        data = Biasbox()
    else:
        raise ValueError('Data not understood.  Try fh, butterfly, clock,'
                         ' polygon, or redgreen')

    return data
예제 #2
0
        "After"
        "EVA wrong number of features")
    assert eva_names.shape[0] == Xeva.shape[1], ("eva_names and Xeva"
                                                 "don't match")

    return Xeva, eva_names


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)
예제 #3
0
    assert Xeva.shape[1] == len(unique_fn) * X.shape[1], ("After" 
        "EVA wrong number of features")
    assert eva_names.shape[0] == Xeva.shape[1], ("eva_names and Xeva" 
        "don't match")

    return Xeva, eva_names


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)
예제 #4
0
def create(maskname, newname, expname, overwrite=False):
    """Save all subjects nifti1 datasets to ./roinii for the given mask/ROI name.
    
    Parameters
    ---------
    maskname : str 
        A valid ROI name (see my `roi` package at `https://github.com/andsoandso/roi`
    newname : str
        A new name for the roi
    expname : str
        A valid `wheelerdata.load.*` instance name
    """

    # Experimental config
    if expname == "fh":
        data = FH()
    elif expname == "butterfly":
        data = Butterfly()
    elif expname == "clock":
        data = Clock()
    elif expname == "polygon":
        data = Polygon()
    elif expname == "redgreen":
        data = Redgreen()
    elif expname == "biasbox":
        data = Biasbox()
    else:
        raise ValueError("expname ({0}) not valid".format(expname))

    basepath = data.datapath
    paths = data.get_subject_paths()
    scodes = data.scodes
    datas = [
        os.path.join(path, "war{0}.nii".format(expname)) for path in paths
    ]

    # then create the roi data for each S.
    for s, data in zip(scodes, datas):
        saveas = os.path.join(basepath, 'roinii',
                              "{0}_{1}.nii.gz".format(newname, s))

        if os.path.exists(saveas) and not overwrite:
            print("{0} exists, moving on.".format(saveas))
            continue

        mask = roi.atlas.get_roi('HarvardOxford', maskname)
        nii = roi.io.read_nifti(data)
        maskednii = roi.pre.mask(nii, mask, standard=True)

        # (Potentially expensive) sanity checks
        assert sum([nz.size for nz in mask.get_data().nonzero()
                    ]) != 0, ("Mask"
                              " {0} was empty".format(maskname))
        assert sum([nz.size for nz in nii.get_data().nonzero()
                    ]) != 0, ("Nifiti1"
                              " {0} was empty".format(maskname))

        # It's possiblethat the ROI covers an area outside the
        # functional acquisition window.  Proceed but warn.
        if sum([nz.size for nz in maskednii.get_data().nonzero()]) == 0:
            print(
                "{0} maskednii was empty. Nothing to write.".format(maskname))
            continue

        print("Writing {0}".format(saveas))
        roi.io.write_nifti(maskednii, saveas)

    # Log success
    f = open("{0}_roinii.log".format(expname), "a")
    f.write("{0}:{1}\n".format(maskname, newname))
    f.close()
예제 #5
0
def create(maskname, newname, expname, overwrite=False):
    """Save all subjects nifti1 datasets to ./roinii for the given mask/ROI name.
    
    Parameters
    ---------
    maskname : str 
        A valid ROI name (see my `roi` package at `https://github.com/andsoandso/roi`
    newname : str
        A new name for the roi
    expname : str
        A valid `wheelerdata.load.*` instance name
    """

    # Experimental config 
    if expname == "fh":
        data = FH()
    elif expname == "butterfly":
        data = Butterfly()
    elif expname == "clock":
        data = Clock()
    elif expname == "polygon":
        data = Polygon()
    elif expname == "redgreen":
        data = Redgreen()
    elif expname == "biasbox":
        data = Biasbox()
    else:
        raise ValueError("expname ({0}) not valid".format(expname))

    basepath = data.datapath
    paths = data.get_subject_paths()
    scodes = data.scodes
    datas = [os.path.join(path,"war{0}.nii".format(expname)) for path in paths]

    # then create the roi data for each S.
    for s, data in zip(scodes, datas):
        saveas = os.path.join(
                basepath, 'roinii', "{0}_{1}.nii.gz".format(newname, s))

        if os.path.exists(saveas) and not overwrite:
            print("{0} exists, moving on.".format(saveas))
            continue

        mask = roi.atlas.get_roi('HarvardOxford', maskname)
        nii = roi.io.read_nifti(data)
        maskednii = roi.pre.mask(nii, mask, standard=True)

        # (Potentially expensive) sanity checks
        assert sum([nz.size for nz in mask.get_data().nonzero()]) != 0, ("Mask" 
                " {0} was empty".format(maskname))
        assert sum([nz.size for nz in nii.get_data().nonzero()]) != 0, ("Nifiti1" 
                " {0} was empty".format(maskname))

        # It's possiblethat the ROI covers an area outside the 
        # functional acquisition window.  Proceed but warn.
        if sum([nz.size for nz in maskednii.get_data().nonzero()]) == 0:
            print("{0} maskednii was empty. Nothing to write.".format(maskname))
            continue

        print("Writing {0}".format(saveas))
        roi.io.write_nifti(maskednii, saveas)
    
    # Log success
    f = open("{0}_roinii.log".format(expname), "a")
    f.write("{0}:{1}\n".format(maskname, newname))
    f.close()