Пример #1
0
 def selectRows(self, searchStr: str):
     if self.selectedColumn == -1:
         Task.showMessage(
             "Workflow violation", "",
             "Must select a table column before this operation can be applied",
             QMessageBox.Warning)
     else:
         print(f"SELECT: {searchStr}")
         rows = self.table.rowCount()
         srows = ItemContainer()
         self._selected_rows = []
         for iRow in range(rows):
             item: QTableWidgetItem = self.table.item(
                 iRow, self.selectedColumn)
             try:
                 match: re.Match = re.match(searchStr, item.text())
                 if (match is not None):
                     pid_item: QTableWidgetItem = self.table.item(
                         iRow, self._index_column)
                     try:
                         srows.add(self.getRS(iRow, int(pid_item.text()),
                                              0))
                         self._selected_rows.append(iRow)
                     except:
                         pass
             except:
                 break
         self.selectRowsByIndex(srows, False)
         if (self.name == "catalog"):
             event = dict(event="pick",
                          type="directory",
                          rows=srows,
                          mark=False,
                          source=self.name)
             self.submitEvent(event, EventMode.Gui)
Пример #2
0
 def findRow(self, searchStr: str):
     if self.selectedColumn == -1:
         Task.showMessage(
             "Workflow violation", "",
             "Must select a table column before this operation can be applied",
             QMessageBox.Warning)
     else:
         if not searchStr.startswith(self._current_search_str):
             self._search_row = 0
         print(f"FIND: {searchStr}")
         rows = self.table.rowCount()
         for iRow in range(self._search_row, rows):
             item: QTableWidgetItem = self.table.item(
                 iRow, self.selectedColumn)
             try:
                 if item.text().startswith(searchStr):
                     pid_item: QTableWidgetItem = self.table.item(
                         iRow, self._index_column)
                     try:
                         pid = int(pid_item.text())
                         srows = ItemContainer([self.getRS(iRow, pid, 0)])
                         self.selectRowsByIndex(srows, False)
                         self._current_search_str = searchStr
                         self._search_row = iRow
                         event = dict(event="pick",
                                      type="directory",
                                      rows=srows,
                                      mark=False,
                                      source=self.name)
                         self.submitEvent(event, EventMode.Gui)
                     except:
                         pass
                     break
             except:
                 break
Пример #3
0
 def processEvent(self, event: Dict):
     from hyperclass.gui.tasks import taskRunner, Task
     from hyperclass.data.events import dataEventHandler
     from hyperclass.graph.flow import activationFlowManager
     super().processEvent(event)
     if dataEventHandler.isDataLoadEvent(event):
         point_data = dataEventHandler.getPointData(event,
                                                    DataType.Embedding)
         if point_data.size == 0:
             Task.showMessage("Data access warning", "",
                              "This block does not have any valid data",
                              QMessageBox.Warning)
         else:
             self.initLabelsData(point_data)
             self._flow = activationFlowManager.getActivationFlow(
                 point_data)
Пример #4
0
    def spread(self,
               sample_labels: xa.DataArray,
               nIter: int = 1,
               **kwargs) -> Optional[xa.Dataset]:
        if self.D is None:
            Task.showMessage("Awaiting task completion", "",
                             "The NN graph computation has not yet finished",
                             QMessageBox.Critical)
            return None
        sample_data = sample_labels.values
        sample_mask = sample_data == 0
        if self.C is None or self.reset:
            self.C = sample_data
        else:
            self.C = np.where(sample_mask, self.C, sample_data)
        label_count = np.count_nonzero(self.C)
        if label_count == 0:
            Task.showMessage(
                "Workflow violation", "",
                "Must label some points before this algorithm can be applied",
                QMessageBox.Critical)
            return None
        if (self.P is None) or self.reset:
            self.P = np.full(self.C.shape, float('inf'), dtype=np.float32)
        self.P = np.where(sample_mask, self.P, 0.0)
        print(f"Beginning graph flow iterations, #C = {label_count}")
        t0 = time.time()
        converged = False
        for iter in range(nIter):
            try:
                iterate_spread_labels(self.I, self.D, self.C, self.P)
                new_label_count = np.count_nonzero(self.C)
                if new_label_count == label_count:
                    print("Converged!")
                    converged = True
                    break
                else:
                    label_count = new_label_count

#                   print(f"\n -->> Iter{iter + 1}: #C = {label_count}\n")
            except Exception as err:
                print(f"Error in graph flow iteration {iter}:")
                traceback.print_exc(50)
                break

        t1 = time.time()
        result_attrs = dict(converged=converged, **sample_labels.attrs)
        result_attrs['_FillValue'] = -2
        xC: xa.DataArray = xa.DataArray(self.C,
                                        dims=sample_labels.dims,
                                        coords=sample_labels.coords,
                                        attrs=result_attrs)
        xP: xa.DataArray = xa.DataArray(self.P,
                                        dims=sample_labels.dims,
                                        coords=sample_labels.coords,
                                        attrs=result_attrs)
        print(
            f"Completed graph flow {nIter} iterations in {(t1 - t0)} sec, Class Range = [ {xC.min().values} -> {xC.max().values} ], #marked = {np.count_nonzero(xC.values)}"
        )
        self.reset = False
        return xa.Dataset(dict(C=xC, D=xP))