Exemplo n.º 1
0
def _create_nod(metapath, fidlpath, scode):
    triallen = 5

    meta = pd.read_csv(metapath)
    faceshouses = np.array(meta["exp"].tolist())
    trs = np.array(meta["TR"].tolist())
    trial_index = np.array(meta["trialcount"].tolist())

    targets = construct_targets(
            trs=trs,
            faceshouses=faceshouses,
            trial_index=trial_index)

    keepers = ["face", "house"]
    keep_fhs = construct_filter(targets["faceshouses"], keepers, True)
    targets = filter_targets(keep_fhs, targets)
    
    names = targets["faceshouses"]
    onsets = targets["trs"]
    durations = np.array([triallen, ] * len(targets["trial_index"]))

    nod_mat(names, onsets, durations, os.path.join(fidlpath, 
            "nod_" + scode + "_stim_facehouse.mat"))
Exemplo n.º 2
0
def filterX(filtname, X, targets):
    """ Use a config file to filter both X and targets.

    Parameters
    ----------
    filtname - str, a file path
        The name of valid json file (see Info)
    X - 2D array-like (n_samples x n_features)
        The data to filter
    targets - dict-like
        A dictionary of labels/targets for X. Keys 
        are names and values are sklearn compatible
        lebels

    Return
    ------
    The filtered X, targets

    Info
    ----
    The named json file has the must can only have 3 
    top level nodes ["keep", "merge", "join"], one of
    which must be present.

    Below each top-level key is a label name which must be 
    present in targets.

    From there it depends on which top-level branch you are in
        TODO
    """

    # load the json at name,
    filterconf = load(open(filtname, "r"))

    # Validate top level nodes
    validnodes = ["keep", "merge", "join"]
    for k in filterconf.keys():
        if k not in validnodes:
            raise ValueError("Unknown filter command {0}".format(k))

    # Validate that X and targets match
    for k, v in targets.items():
        if v.shape[0] != X.shape[0]:
            raise ValueError("Before: X/target shape mismatch for '{0}'".format(k))

    # test for keep and do that
    if "keep" in filterconf:
        for k, keepers in filterconf["keep"].items():
            labels = targets[k]
            mask = construct_filter(labels, keepers, True)
            targets = filter_targets(mask, targets)
            X = X[mask, :]

    # Test for merge and do that
    if "merge" in filterconf:
        for k, mmap in filterconf["merge"].items():
            labels = targets[k]
            targets[k] = merge_labels(labels, mmap)

    # Test for join and do that
    if "join" in filterconf:
        raise NotImplementedError("join not yet implemented.  Sorry.")

    # revalidate that X and targets match
    for k, v in targets.items():
        if v.shape[0] != X.shape[0]:
            raise ValueError("After: X/targets shape mismatch for '{0}'".format(k))
    assert checkX(X)

    return X, targets
Exemplo n.º 3
0
def filterX(filtname, X, targets):
    """ Use a config file to filter both X and targets.

    Parameters
    ----------
    filtname - str, a file path
        The name of valid json file (see Info)
    X - 2D array-like (n_samples x n_features)
        The data to filter
    targets - dict-like
        A dictionary of labels/targets for X. Keys 
        are names and values are sklearn compatible
        lebels

    Return
    ------
    The filtered X, targets

    Info
    ----
    The named json file has the must can only have 3 
    top level nodes ["keep", "merge", "join"], one of
    which must be present.

    Below each top-level key is a label name which must be 
    present in targets.

    From there it depends on which top-level branch you are in
        TODO
    """

    # load the json at name,
    filterconf = load(open(filtname, "r"))

    # Validate top level nodes
    validnodes = ["keep", "merge", "join"]
    for k in filterconf.keys():
        if k not in validnodes:
            raise ValueError("Unknown filter command {0}".format(k))

    # Validate that X and targets match
    for k, v in targets.items():
        if v.shape[0] != X.shape[0]:
            raise ValueError(
                "Before: X/target shape mismatch for '{0}'".format(k))

    # test for keep and do that
    if "keep" in filterconf:
        for k, keepers in filterconf["keep"].items():
            labels = targets[k]
            mask = construct_filter(labels, keepers, True)
            targets = filter_targets(mask, targets)
            X = X[mask, :]

    # Test for merge and do that
    if "merge" in filterconf:
        for k, mmap in filterconf["merge"].items():
            labels = targets[k]
            targets[k] = merge_labels(labels, mmap)

    # Test for join and do that
    if "join" in filterconf:
        raise NotImplementedError("join not yet implemented.  Sorry.")

    # revalidate that X and targets match
    for k, v in targets.items():
        if v.shape[0] != X.shape[0]:
            raise ValueError(
                "After: X/targets shape mismatch for '{0}'".format(k))
    assert checkX(X)

    return X, targets