예제 #1
0
def mark_by_threshold(dataset, DV='MEG', threshold=2e-12, above=False, below=None,
                      target='accept'):
    """
    Marks epochs based on a threshold criterion (any sensor exceeding the
    threshold at any time)

    above: True, False, None
        How to mark segments that exceed the threshold: True->good;
        False->bad; None->don't change

    below:
        Same as ``above`` but for segments that do not exceed the threshold

    threshold : float
        The threshold value.
        1.25e-11: detect saturated channels
        2e-12: conservative final rejection

    target : factor or str
        Factor (or its name) in which the result is stored. If ``var`` is
        a string and the dataset does not contain that factor, it is
        created.

    """
    if isinstance(DV, basestring):
        DV = dataset[DV]

    # get the factor on which to store results
    if _data.isfactor(target) or _data.isvar(target):
        assert len(target) == dataset.N
    elif isinstance(target, basestring):
        if target in dataset:
            target = dataset[target]
        else:
            x = _np.ones(dataset.N, dtype=bool)
            target = _data.var(x, name=target)
            dataset.add(target)
    else:
        raise ValueError("target needs to be a factor")

    # do the thresholding
    if _data.isndvar(DV):
        for ID in xrange(dataset.N):
            data = DV[ID]
            v = _np.max(_np.abs(data.x))

            if v > threshold:
                if above is not None:
                    target[ID] = above
            elif below is not None:
                target[ID] = below
    else:
        for ID in xrange(dataset.N):
            v = DV[ID]

            if v > threshold:
                if above is not None:
                    target[ID] = above
            elif below is not None:
                target[ID] = below
예제 #2
0
 def __repr__(self):
     args = [self.Y.name, self.X.name]
     rpr = "celltable(%s)"
     if self.match is not None:
         args.append("match=%s" % self.match.name)
     if self.sub is not None:
         if _data.isvar(self.sub):
             args.append("sub=%s" % self.sub.name)
         else:
             indexes = " ".join(str(i) for i in self.sub[:4])
             args.append("sub=[%s...]" % indexes)
     return rpr % (", ".join(args))