コード例 #1
0
    def getPairsIndicesList(self, i, allPermutations=False):
        """
        Returns a list of tuples of numeric indices from a combined type of
        indices.
        """
        permutate = permutations if allPermutations else combinations
        if i is None:
            return permutate([*range(0, self.channelNumber)], 2)

        if isinstance(i, slice):
            return self.getPairsIndicesList(self.getIndicesList(None)[i])

        if isinstance(i, tuple) and len(i) == 2:
            return [tuple(self.getIndicesList(list(i)))]

        if isinstance(i, list):
            if listType(i) is tuple:
                return [self.getPairsIndicesList(c)[0] for c in i]
            return permutate(self.getIndicesList(i), 2)

        raise ValueError("This method only accepts int, str, list or " +
                         "slice types and not %s" % type(i))
コード例 #2
0
ファイル: test_auxFunctions.py プロジェクト: Xiul109/eeglib
 def test_listType_sameTypes(self):
     v = aux.listType([*range(10)])
     self.assertEqual(v, int)
     v = aux.listType(["a", 'b', "1", '2', """"long text"""])
     self.assertEqual(v, str)
コード例 #3
0
ファイル: test_auxFunctions.py プロジェクト: Xiul109/eeglib
 def test_listType_diffTypes(self):
     v = aux.listType([1, "2", 3.0])
     self.assertEqual(v, None)
     v = aux.listType([*range(10), "10", *range(11, 21)])
     self.assertEqual(v, None)
コード例 #4
0
ファイル: test_auxFunctions.py プロジェクト: Xiul109/eeglib
 def test_listType_noLength(self):
     testList = []
     v = aux.listType(testList)
     self.assertEqual(v, None)
コード例 #5
0
ファイル: test_auxFunctions.py プロジェクト: Xiul109/eeglib
 def test_listType_noList(self):
     noList = "asd"
     with self.assertRaises(ValueError):
         aux.listType(noList)
コード例 #6
0
    def getPairOfChannels(self, channels=None, allPermutations=False):
        """
        Applies a function that uses two signals by selecting the channels to
        use. It will apply the function to different channels depending on the
        parameters. Note: a single channel can be selected by using an int or
        a string if a name for the channel was specified.

        Parameters
        ----------
        channels: Variable type, optional
            * tuple of lenght 2 containing channel indexes: applies the
              function to the two channels specified by the tuple.
            * list of tuples(same restrictions than the above): applies the
              function to every tuple in the list.
            * list of index: creates combinations of channels specifies in the
              list depending of the allPermutations parameter.
            * None: Are channels are used in the same way than in the list
              above. This is the default value.

        allPermutations: bool, optional
            Only used when channels is a list of index or None. If True all
            permutations of the channels in every order are used; if False only
            combinations of different channels are used. Example: with the list
            [0, 2, 4] and allPermutations = True, the channels used will be
            (0,2), (0,4), (2,0), (2,4), (4,0), (4,2); meanwhile, with
            allPermutations = False, the channels used will be: (0,2), (0,4),
            (2,4). Default: False.

        Returns
        -------
        If a tuple is passed the it returns the result of applying the function
        to the channels specified in the tuple. If another valid value is
        passed, the method returns a dictionary, being the key the two channels
        used and the value the result of applying the function to those
        channels.
        """
        permutate = permutations if allPermutations else combinations

        if channels is None:
            channels = [*range(self.channelNumber)]
        elif isinstance(channels, slice):
            channels = [*range(self.channelNumber)[channels]]

        if isinstance(channels, tuple):
            if len(channels) != 2:
                raise ValueError("If you specify a tuple, it must have " +
                                 "exactly two(2) elements")
            return (self.getChannel(channels[0]), self.getChannel(channels[1]))

        if isinstance(channels, list):
            t = listType(channels)
            if t is tuple:
                acs = np.array(channels)
                if len(acs.shape) == 2 and acs.shape[1] == 2:
                    return [(self.getChannel(c[0]), self.getChannel(c[1]))
                            for c in channels]
                raise ValueError("The tuples of the list must have " +
                                 "exactly two(2) elements")
            try:
                return permutate(self.getChannel(channels), 2)
            except ValueError as err:
                raise ValueError("The list must contain either tuples " +
                                 "or integers and strings, but no " +
                                 "combinations of them.") from err

        raise ValueError("This method only accepts list (either of int " +
                         "and str or tuples) or tuple types and not %s" %
                         type(channels))