Exemple #1
0
    def __init__(self, string):
        m = re.match(
            r'(?:([\w+-]+)\|)?'  # stimulus
            r'([\w:-]+)'  # pedictor code
            r'(?:\$'  # begin shuffling
            r'(?:\[(-?\d+-?|\w*)\])?'  # band/index
            r'([a-zA-Z]+)(\d*))?$',
            string)
        if not m:
            raise CodeError(string, "not a valid code")
        stim, code_string, shuffle_index, shuffle, angle = m.groups()
        if shuffle:
            index_str = '' if shuffle_index is None else f'[{shuffle_index}]'
            self.shuffle_string = f"${index_str}{shuffle}{angle}"
            self.code_with_rand = f'{code_string}{self.shuffle_string}'
            if angle:
                angle = int(angle)
                if angle == 180:
                    raise CodeError(string,
                                    "shuffle angle '180' should be omitted")
                elif not 360 > angle > 0:
                    raise CodeError(string, f"shuffle angle {angle}")
            else:
                angle = 180

            if shuffle_index:
                m = re.match(r'^(-?)(\d+)(-?)$', shuffle_index)
                if m:
                    pre, index, post = m.groups()
                    if pre:
                        if post:
                            raise ValueError(f'{string!r} (shuffle index)')
                        shuffle_index = slice(int(index))
                    elif post:
                        shuffle_index = slice(int(index), None)
                    else:
                        shuffle_index = int(index)
            else:
                shuffle_index = None
        else:
            self.code_with_rand = code_string
            self.shuffle_string = ''
            shuffle_index = shuffle = angle = None
        self.stim = stim or None
        self.code = code_string
        self.shuffle = shuffle
        self.shuffle_index = shuffle_index
        self.shuffle_angle = angle
        CodeBase.__init__(self, string, code_string)
        self.has_randomization = shuffle in VALUE_SHUFFLE_METHODS or '>' in string
        self.has_permutation = shuffle in SHUFFLE_METHODS or '>' in string
        self._shuffle_done = False
        self.key = Dataset.as_key(self.string)
Exemple #2
0
    def __init__(self, string):
        m = re.match(r'(?:([\w+-]+)\|)?([\w:-]+)(?:\$(-?\d*-?)([a-zA-Z]+)(\d*))?$', string)
        if not m:
            raise CodeError(string, "not a valid code")
        stim, code_string, shuffle_band, shuffle, angle = m.groups()
        if shuffle:
            self.code_with_rand = f'{code_string}${shuffle_band}{shuffle}{angle}'
            if angle:
                angle = int(angle)
                if angle == 180:
                    raise CodeError(string, "shuffle angle '180' should be omitted")
                elif not 360 > angle > 0:
                    raise CodeError(string, f"shuffle angle {angle}")
            else:
                angle = 180

            if shuffle_band:
                m = re.match(r'^(-?)(\d+)(-?)$', shuffle_band)
                if not m:
                    raise ValueError(f'{string!r} (shuffle index)')
                pre, index, post = m.groups()
                if pre:
                    if post:
                        raise ValueError(f'{string!r} (shuffle index)')
                    shuffle_band = slice(int(index))
                elif post:
                    shuffle_band = slice(int(index), None)
                else:
                    shuffle_band = int(index)
            else:
                shuffle_band  = None
        else:
            self.code_with_rand = code_string
            shuffle_band = shuffle = angle = None
        self.stim = stim or None
        self.code = code_string
        self.shuffle = shuffle
        self.shuffle_band = shuffle_band
        self.shuffle_angle = angle
        CodeBase.__init__(self, string, code_string)
        self.has_randomization = shuffle in VALUE_SHUFFLE_METHODS or '>' in string
        self.has_permutation = shuffle in SHUFFLE_METHODS or '>' in string
        self._shuffle_done = False
        self.key = Dataset.as_key(self.string)
Exemple #3
0
 def dataset_based_key(self):
     term_keys = [Dataset.as_key(term.string) for term in self.terms]
     return '+'.join(sorted(term_keys))