Exemplo n.º 1
0
    def subset_channel(self, by, value):
        """ Returns a subsetted TemporalDataset defined by
        a certain channel descriptor value

        Args:
            by(String): the descriptor by which the subset selection is
                made from channel dimension
            value:      the value by which the subset selection is made
                from channel dimension

        Returns:
            TemporalDataset,
            with subset defined by the selected channel_descriptor

        """
        selection = num_index(self.channel_descriptors[by], value)
        measurements = self.measurements[:, selection]
        descriptors = self.descriptors
        obs_descriptors = self.obs_descriptors
        channel_descriptors = subset_descriptor(self.channel_descriptors,
                                                selection)
        time_descriptors = self.time_descriptors
        dataset = TemporalDataset(measurements=measurements,
                                  descriptors=descriptors,
                                  obs_descriptors=obs_descriptors,
                                  channel_descriptors=channel_descriptors,
                                  time_descriptors=time_descriptors)
        return dataset
Exemplo n.º 2
0
    def subset_time(self, by, t_from, t_to):
        """ Returns a subsetted TemporalDataset
        with time between t_from and t_to

        Args:
            by(String): the descriptor by which the subset selection is
                made from channel dimension
            t_from: time-point from which onwards data should be subsetted
            t_to: time-point until which data should be subsetted

        Returns:
            TemporalDataset
                with subset defined by the selected time_descriptor

        """

        time = get_unique_unsorted(self.time_descriptors[by])
        sel_time = [t for t in time if t_from <= t <= t_to]

        selection = num_index(self.time_descriptors[by], sel_time)
        measurements = self.measurements[:, :, selection]
        descriptors = self.descriptors
        obs_descriptors = self.obs_descriptors
        channel_descriptors = self.channel_descriptors
        time_descriptors = subset_descriptor(self.time_descriptors, selection)
        dataset = TemporalDataset(measurements=measurements,
                                  descriptors=descriptors,
                                  obs_descriptors=obs_descriptors,
                                  channel_descriptors=channel_descriptors,
                                  time_descriptors=time_descriptors)
        return dataset
Exemplo n.º 3
0
    def split_time(self, by):
        """ Returns a list TemporalDataset splited by time

        Args:
            by(String): the descriptor by which the splitting is made

        Returns:
            list of TemporalDataset,  splitted by the selected time_descriptor
        """

        time = get_unique_unsorted(self.time_descriptors[by])
        dataset_list = []
        for v in time:
            selection = [
                i for i, val in enumerate(self.time_descriptors[by])
                if val == v
            ]
            measurements = self.measurements[:, :, selection]
            descriptors = self.descriptors
            obs_descriptors = self.obs_descriptors
            channel_descriptors = self.channel_descriptors
            time_descriptors = subset_descriptor(self.time_descriptors,
                                                 selection)
            dataset = TemporalDataset(measurements=measurements,
                                      descriptors=descriptors,
                                      obs_descriptors=obs_descriptors,
                                      channel_descriptors=channel_descriptors,
                                      time_descriptors=time_descriptors,
                                      check_dims=False)
            dataset_list.append(dataset)
        return dataset_list
Exemplo n.º 4
0
    def split_channel(self, by):
        """ Returns a list TemporalDataset splited by channels

        Args:
            by(String): the descriptor by which the splitting is made

        Returns:
            list of TemporalDataset,
                split by the selected channel_descriptor
        """
        unique_values, inverse = get_unique_inverse(
            self.channel_descriptors[by])
        dataset_list = []
        for i_v, v in enumerate(unique_values):
            selection = np.where(inverse == i_v)[0]
            measurements = self.measurements[:, selection, :]
            descriptors = self.descriptors.copy()
            descriptors[by] = v
            obs_descriptors = self.obs_descriptors
            channel_descriptors = subset_descriptor(self.channel_descriptors,
                                                    selection)
            time_descriptors = self.time_descriptors
            dataset = TemporalDataset(measurements=measurements,
                                      descriptors=descriptors,
                                      obs_descriptors=obs_descriptors,
                                      channel_descriptors=channel_descriptors,
                                      time_descriptors=time_descriptors,
                                      check_dims=False)
            dataset_list.append(dataset)
        return dataset_list
Exemplo n.º 5
0
    def split_obs(self, by):
        """ Returns a list Datasets splited by obs

        Args:
            by(String): the descriptor by which the splitting is made

        Returns:
            list of Datasets, splitted by the selected obs_descriptor
        """
        unique_values, inverse = get_unique_inverse(self.obs_descriptors[by])
        dataset_list = []
        for i_v, _ in enumerate(unique_values):
            selection = np.where(inverse == i_v)[0]
            measurements = self.measurements[selection, :]
            descriptors = self.descriptors.copy()
            obs_descriptors = subset_descriptor(self.obs_descriptors,
                                                selection)
            channel_descriptors = self.channel_descriptors
            dataset = Dataset(measurements=measurements,
                              descriptors=descriptors,
                              obs_descriptors=obs_descriptors,
                              channel_descriptors=channel_descriptors,
                              check_dims=False)
            dataset_list.append(dataset)
        return dataset_list
Exemplo n.º 6
0
    def sort_by(self, by):
        """ sorts the dataset by a given observation descriptor

        Args:
            by(String): the descriptor by which the dataset shall be sorted

        Returns:
            ---

        """
        desc = self.obs_descriptors[by]
        order = np.argsort(desc)
        self.measurements = self.measurements[order]
        self.obs_descriptors = subset_descriptor(self.obs_descriptors, order)
Exemplo n.º 7
0
 def __getitem__(self, idx):
     """
     allows indexing with []
     and iterating over RDMs with `for rdm in rdms:`
     """
     dissimilarities = self.dissimilarities[np.array(idx)].reshape(
         -1, self.dissimilarities.shape[1])
     rdm_descriptors = subset_descriptor(self.rdm_descriptors, idx)
     rdms = RDMs(dissimilarities,
                 dissimilarity_measure=self.dissimilarity_measure,
                 descriptors=self.descriptors,
                 rdm_descriptors=rdm_descriptors,
                 pattern_descriptors=self.pattern_descriptors)
     return rdms
Exemplo n.º 8
0
    def subset_obs(self, by, value):
        """ Returns a subsetted Dataset defined by certain obs value

        Args:
            by(String): the descriptor by which the subset selection
                is made from obs dimension
            value:      the value by which the subset selection is made
                from obs dimension

        Returns:
            Dataset, with subset defined by the selected obs_descriptor

        """
        selection = num_index(self.obs_descriptors[by], value)
        measurements = self.measurements[selection, :]
        descriptors = self.descriptors
        obs_descriptors = subset_descriptor(self.obs_descriptors, selection)
        channel_descriptors = self.channel_descriptors
        dataset = Dataset(measurements=measurements,
                          descriptors=descriptors,
                          obs_descriptors=obs_descriptors,
                          channel_descriptors=channel_descriptors)
        return dataset
Exemplo n.º 9
0
 def test_subset_descriptor(self):
     from rsatoolbox.util.descriptor_utils import subset_descriptor
     descriptors = {'foo': ['bar', 'bar2']}
     self.assertEqual(subset_descriptor(descriptors, 0), {'foo': ['bar']})
     self.assertEqual(subset_descriptor(descriptors, (0, 1)),
                      {'foo': ['bar', 'bar2']})