diff --git a/fixtracks/utils/trackingdata.py b/fixtracks/utils/trackingdata.py index 4dcc3f0..213b520 100644 --- a/fixtracks/utils/trackingdata.py +++ b/fixtracks/utils/trackingdata.py @@ -14,8 +14,8 @@ class TrackingData(QObject): if "userlabeled" not in self._data.keys(): self._data["userlabeled"] = np.zeros_like(self["frame"], dtype=bool) self._columns = [k for k in self._data.keys()] - self._indices = self["index"] - self._selection = np.asarray([]) + self._indices = np.arange(len(self["index"]), dtype=int) + self._selection_indices = np.asarray([]) self._selected_ids = None @property @@ -43,8 +43,8 @@ class TrackingData(QObject): ids = np.sort(ids) indexes = np.ones_like(ids, dtype=int) * -1 j = 0 - for idx, i in enumerate(self._indices): - if i == ids[j]: + for idx in self._indices: + if self["index"][idx] == ids[j]: indexes[j] = idx j += 1 if j == len(indexes): @@ -54,19 +54,23 @@ class TrackingData(QObject): @property def selectionIndices(self): - return self._selection + return self._selection_indices + + @property + def selectionIDs(self): + return self._selected_ids def setSelectionRange(self, col, start, stop): logging.info("Trackingdata: set selection range based on column %s to %.2f - %.2f", col, start, stop) col_indices = np.where((self[col] >= start) & (self[col] < stop))[0] - self._selection = self._indices[col_indices] + self._selection_indices = self._indices[col_indices] if len(col_indices) < 1: logging.warning("TrackingData: Selection range is empty!") def selectedData(self, col:str): if col not in self.columns: logging.error("TrackingData:selectedData: Invalid column name! %s", col) - return self[col][self._selection] + return self[col][self._selection_indices] def setSelection(self, ids): """ @@ -78,8 +82,9 @@ class TrackingData(QObject): An array-like object containing the IDs to be set as user selections. """ logging.debug("TrackingData.setSelection: %i number of ids", len(ids)) - self._selection = self._find(ids) + self._selection_indices = self._find(ids) self._selected_ids = ids + print(self._selected_ids, self._selection_indices) def setTrack(self, track_id:int, setUserLabeled:bool=True)-> None: """Assign a new track_id to the user-selected detections @@ -92,9 +97,12 @@ class TrackingData(QObject): Should the "userlabeled" state of the detections be set to True? Otherwise they will be left untouched. """ logging.info("TrackingData: set track id %i for selection, set user-labeled status %s", track_id, str(setUserLabeled)) - self["track"][self._selection] = track_id + print(self._selected_ids, self._selection_indices) + print("before: ", self["track"][self._selection_indices], self["frame"][self._selection_indices]) + self["track"][self._selection_indices] = track_id if setUserLabeled: self.setUserLabeledStatus(True, True) + print("after: ", self["track"][self._selection_indices], self["frame"][self._selection_indices]) def setUserLabeledStatus(self, new_status: bool, selection=True): """Sets the status of the "userlabeled" column to a given value (True|False). This can done for ALL data in one go, or only for the UserSelection. @@ -109,7 +117,7 @@ class TrackingData(QObject): logging.debug("TrackingData: (Re-)setting assignment status of %s to %s", "user selected data" if selection else " ALL", str(new_status)) if selection: - self["userlabeled"][self._selection] = new_status + self["userlabeled"][self._selection_indices] = new_status else: self["userlabeled"][:] = new_status @@ -123,12 +131,14 @@ class TrackingData(QObject): def deleteDetections(self, ids=None): if ids is not None: + logging.debug("TrackingData.deleteDetections of %i detections", len(ids)) del_indices = self._find(ids) else: - del_indices = self._indices + logging.debug("TrackingData.deleteDetections of all selected detections (%i)", len(self._selected_ids)) + del_indices = self._selected_ids for c in self._columns: self._data[c] = np.delete(self._data[c], del_indices, axis=0) - self._indices = self["index"] + self._indices = self._indices[:-len(del_indices)] self._selected_ids = np.setdiff1d(self._selected_ids, del_indices) def assignTracks(self, tracks:np.ndarray): @@ -171,10 +181,10 @@ class TrackingData(QObject): and M is number of keypoints """ if selection: - if len(self._selection) < 1: + if len(self._selection_indices) < 1: logging.info("TrackingData.coordinates returns empty array, not detections in range!") return np.ndarray([]) - return np.stack(self["keypoints"][self._selection]).astype(np.float32) + return np.stack(self["keypoints"][self._selection_indices]).astype(np.float32) return np.stack(self["keypoints"]).astype(np.float32) def keypointScores(self, selection=False): @@ -188,10 +198,10 @@ class TrackingData(QObject): with N the number of detections and M the number of keypoints. """ if selection: - if len(self._selection) < 1: + if len(self._selection_indices) < 1: logging.info("TrackingData.scores returns empty array, not detections in range!") return None - return np.stack(self["keypoint_score"][self._selection]).astype(np.float32) + return np.stack(self["keypoint_score"][self._selection_indices]).astype(np.float32) return np.stack(self["keypoint_score"]).astype(np.float32) def centerOfGravity(self, selection=False, threshold=0.8, nodes=[0,1,2]):