コード例 #1
0
ファイル: inspect_gui.py プロジェクト: byteyoo/ibeis
 def parse_column_tuples(self, col_name_list, col_types_dict, col_getters_dict,
                         col_bgrole_dict, col_ider_dict, col_setter_dict,
                         editable_colnames, sortby, sort_reverse=True):
     # Unpack the column tuples into names, getters, and types
     self.col_name_list = col_name_list
     self.col_type_list = [col_types_dict.get(colname, str) for colname in col_name_list]
     self.col_getter_list = [col_getters_dict.get(colname, str) for colname in col_name_list]  # First col is always a getter
     # Get number of rows / columns
     self.nCols = len(self.col_getter_list)
     self.nRows = 0 if self.nCols == 0 else len(self.col_getter_list[0])  # FIXME
     # Init iders to default and then overwite based on dict inputs
     self.col_ider_list = utool.alloc_nones(self.nCols)
     for colname, ider_colnames in six.iteritems(col_ider_dict):
         col = self.col_name_list.index(colname)
         # Col iders might have tuple input
         ider_cols = utool.uinput_1to1(self.col_name_list.index, ider_colnames)
         col_ider  = utool.uinput_1to1(lambda c: partial(self.get, c), ider_cols)
         self.col_ider_list[col] = col_ider
     # Init setters to data, and then overwrite based on dict inputs
     self.col_setter_list = list(self.col_getter_list)
     for colname, col_setter in six.iteritems(col_setter_dict):
         col = self.col_name_list.index(colname)
         self.col_setter_list[col] = col_setter
     # Init bgrole_getters to None, and then overwrite based on dict inputs
     self.col_bgrole_getter_list = [col_bgrole_dict.get(colname, None) for colname in self.col_name_list]
     # Mark edtiable columns
     self.col_edit_list = [name in editable_colnames for name in col_name_list]
     # Mark the sort column index
     if utool.is_str(sortby):
         self.col_sort_index = self.col_name_list.index(sortby)
     else:
         self.col_sort_index = sortby
     self.col_sort_reverse = sort_reverse
コード例 #2
0
ファイル: clustering.py プロジェクト: SU-ECE-18-7/vtool
def _compute_cluster_centers(num_data, num_clusters, data, centroids, datax2_clusterx):
    """ Computes the cluster centers and stores output in the outvar: centroids.
    This outvar is also returned """
    # sort data by cluster
    datax_sort    = datax2_clusterx.argsort()
    clusterx_sort = datax2_clusterx[datax_sort]
    # group datapoints by cluster using a sliding grouping algorithm
    _L = 0
    clusterx2_dataLRx = ut.alloc_nones(num_clusters)
    for _R in range(len(datax_sort) + 1):  # Slide R
        if _R == num_data or clusterx_sort[_L] != clusterx_sort[_R]:
            clusterx2_dataLRx[clusterx_sort[_L]] = (_L, _R)
            _L = _R
    # Compute the centers of each group (cluster) of datapoints
    ut.print_('+')
    for clusterx, dataLRx in enumerate(clusterx2_dataLRx):
        if dataLRx is None:
            continue  # ON EMPTY CLUSTER
        (_L, _R) = dataLRx
        # The cluster center is the mean of its datapoints
        centroids[clusterx] = np.mean(data[datax_sort[_L:_R]], axis=0)
        #centroids[clusterx] = np.array(np.round(centroids[clusterx]), dtype=np.uint8)
    return centroids
コード例 #3
0
ファイル: api_item_widget.py プロジェクト: Erotemic/guitool
    def parse_column_tuples(self,
                            col_name_list,
                            col_types_dict,
                            col_getter_dict,
                            col_bgrole_dict,
                            col_ider_dict,
                            col_setter_dict,
                            editable_colnames,
                            sortby,
                            sort_reverse=True,
                            strict=False,
                            **kwargs):
        """
        parses simple lists into information suitable for making guitool headers
        """
        # Unpack the column tuples into names, getters, and types
        if not strict:
            # slopply colname definitions
            flag_list = [colname in col_getter_dict for colname in col_name_list]
            if not all(flag_list):
                invalid_colnames = ut.compress(col_name_list, ut.not_list(flag_list))
                print('[api_item_widget] Warning: colnames=%r have no getters' % (invalid_colnames,))
                col_name_list = ut.compress(col_name_list, flag_list)
            # sloppy type inference
            for colname in col_name_list:
                getter_ = col_getter_dict[colname]
                if colname not in col_types_dict:
                    type_ = ut.get_homogenous_list_type(getter_)
                    if type_ is not None:
                        col_types_dict[colname] = type_
        # sloppy kwargs.
        # FIXME: explicitly list col_nice_dict
        col_nice_dict = kwargs.get('col_nice_dict', {})
        self.col_nice_list = [col_nice_dict.get(name, name) for name in col_name_list]

        self.col_name_list = col_name_list
        self.col_type_list = [col_types_dict.get(colname, str) for colname in col_name_list]
        self.col_getter_list = [col_getter_dict.get(colname, str) for colname in col_name_list]  # First col is always a getter
        # Get number of rows / columns
        self.nCols = len(self.col_getter_list)
        self.nRows = 0 if self.nCols == 0 else len(self.col_getter_list[0])  # FIXME
        # Init iders to default and then overwite based on dict inputs
        self.col_ider_list = ut.alloc_nones(self.nCols)
        for colname, ider_colnames in six.iteritems(col_ider_dict):
            try:
                col = self.col_name_list.index(colname)
                # Col iders might have tuple input
                ider_cols = ut.uinput_1to1(self.col_name_list.index, ider_colnames)
                col_ider  = ut.uinput_1to1(lambda c: partial(self.get, c), ider_cols)
                self.col_ider_list[col] = col_ider
                del col_ider
                del ider_cols
                del col
                del colname
            except Exception as ex:
                ut.printex(ex, keys=['colname', 'ider_colnames', 'col', 'col_ider', 'ider_cols'])
                raise
        # Init setters to data, and then overwrite based on dict inputs
        self.col_setter_list = list(self.col_getter_list)
        for colname, col_setter in six.iteritems(col_setter_dict):
            col = self.col_name_list.index(colname)
            self.col_setter_list[col] = col_setter
        # Init bgrole_getters to None, and then overwrite based on dict inputs
        self.col_bgrole_getter_list = [col_bgrole_dict.get(colname, None) for colname in self.col_name_list]
        # Mark edtiable columns
        self.col_edit_list = [name in editable_colnames for name in col_name_list]
        # Mark the sort column index
        if ut.is_str(sortby):
            self.col_sort_index = self.col_name_list.index(sortby)
        else:
            self.col_sort_index = sortby
        self.col_sort_reverse = sort_reverse
コード例 #4
0
def get_annot_text(ibs, aid_list, draw_lbls):
    if draw_lbls:
        text_list = ibs.get_annot_names(aid_list)
    else:
        text_list = ut.alloc_nones(len(aid_list))
    return text_list
コード例 #5
0
ファイル: viz_helpers.py プロジェクト: Erotemic/ibeis
def get_annot_text(ibs, aid_list, draw_lbls):
    if draw_lbls:
        text_list = ibs.get_annot_names(aid_list)
    else:
        text_list = ut.alloc_nones(len(aid_list))
    return text_list
コード例 #6
0
    def parse_column_tuples(self,
                            col_name_list,
                            col_types_dict,
                            col_getter_dict,
                            col_bgrole_dict,
                            col_ider_dict,
                            col_setter_dict,
                            editable_colnames,
                            sortby,
                            sort_reverse=True,
                            strict=False,
                            **kwargs):
        """
        parses simple lists into information suitable for making guitool headers
        """
        # Unpack the column tuples into names, getters, and types
        if not strict:
            # slopply colname definitions
            flag_list = [
                colname in col_getter_dict for colname in col_name_list
            ]
            if not all(flag_list):
                invalid_colnames = ut.compress(col_name_list,
                                               ut.not_list(flag_list))
                print(
                    '[api_item_widget] Warning: colnames=%r have no getters' %
                    (invalid_colnames, ))
                col_name_list = ut.compress(col_name_list, flag_list)
            # sloppy type inference
            for colname in col_name_list:
                getter_ = col_getter_dict[colname]
                if colname not in col_types_dict:
                    type_ = ut.get_homogenous_list_type(getter_)
                    if type_ is not None:
                        col_types_dict[colname] = type_
        # sloppy kwargs.
        # FIXME: explicitly list col_nice_dict
        col_nice_dict = kwargs.get('col_nice_dict', {})
        self.col_nice_list = [
            col_nice_dict.get(name, name) for name in col_name_list
        ]

        self.col_name_list = col_name_list
        self.col_type_list = [
            col_types_dict.get(colname, str) for colname in col_name_list
        ]
        self.col_getter_list = [
            col_getter_dict.get(colname, str) for colname in col_name_list
        ]  # First col is always a getter
        # Get number of rows / columns
        self.nCols = len(self.col_getter_list)
        self.nRows = 0 if self.nCols == 0 else len(
            self.col_getter_list[0])  # FIXME
        # Init iders to default and then overwite based on dict inputs
        self.col_ider_list = ut.alloc_nones(self.nCols)
        for colname, ider_colnames in six.iteritems(col_ider_dict):
            try:
                col = self.col_name_list.index(colname)
                # Col iders might have tuple input
                ider_cols = ut.uinput_1to1(self.col_name_list.index,
                                           ider_colnames)
                col_ider = ut.uinput_1to1(lambda c: partial(self.get, c),
                                          ider_cols)
                self.col_ider_list[col] = col_ider
                del col_ider
                del ider_cols
                del col
                del colname
            except Exception as ex:
                ut.printex(ex,
                           keys=[
                               'colname', 'ider_colnames', 'col', 'col_ider',
                               'ider_cols'
                           ])
                raise
        # Init setters to data, and then overwrite based on dict inputs
        self.col_setter_list = list(self.col_getter_list)
        for colname, col_setter in six.iteritems(col_setter_dict):
            col = self.col_name_list.index(colname)
            self.col_setter_list[col] = col_setter
        # Init bgrole_getters to None, and then overwrite based on dict inputs
        self.col_bgrole_getter_list = [
            col_bgrole_dict.get(colname, None)
            for colname in self.col_name_list
        ]
        # Mark edtiable columns
        self.col_edit_list = [
            name in editable_colnames for name in col_name_list
        ]
        # Mark the sort column index
        if ut.is_str(sortby):
            self.col_sort_index = self.col_name_list.index(sortby)
        else:
            self.col_sort_index = sortby
        self.col_sort_reverse = sort_reverse