diff --git a/pymapmanager/interface2/core/dendrogram_widget.py b/pymapmanager/interface2/core/dendrogram_widget.py index 6f78792..2b870a4 100644 --- a/pymapmanager/interface2/core/dendrogram_widget.py +++ b/pymapmanager/interface2/core/dendrogram_widget.py @@ -1115,11 +1115,20 @@ def dendrogramReplot(self, newSegmentID): # Logic: adjust y val by abs value of angle. + or - depending on angle # this allows us to accurately plot angle anchorYVal = anchorY[i] - angledY = xVal * math.tan((angle + 90)* math.pi/180) + angledY = xVal * math.tan((angle)* math.pi/180) diff = abs(anchorYVal) - abs(angledY) - if angle < 90: + + if 0 <= angle and angle <= 90: # GOOD + # label.setPos(QtCore.QPointF(x + adjustX, y + adjustY)) + angledY = anchorYVal + abs(diff) + elif 90 <= angle and angle <= 180: + # label.setPos(QtCore.QPointF(x - adjustX, y + adjustY)) angledY = anchorYVal - abs(diff) - else: + elif 180 <= angle and angle <= 270: + # label.setPos(QtCore.QPointF(x - adjustX, y - adjustY)) + angledY = anchorYVal - abs(diff) + elif 270 <= angle and angle <= 360: #BAD + # label.setPos(QtCore.QPointF(x + adjustX, y - adjustY)) angledY = anchorYVal + abs(diff) # logger.info(f"index {index} angle {angle} xVal {xVal} angledY {angledY}") @@ -1138,9 +1147,6 @@ def dendrogramReplot(self, newSegmentID): spineLineY.append(spineY[i]) spineLineY.append(np.nan) - # filteredLineDF = self._laDF[self._laDF.index == newSegmentID] - # logger.info(f"filteredLineDF {filteredLineDF}") - # self.segmentLength = filteredLineDF["length"].iloc[0] filteredLineDF = self._summaryLaDF[self._summaryLaDF.index == newSegmentID] self.segmentLength = filteredLineDF["Length"].iloc[0] # logger.info(f"segmentLength {segmentLength}") diff --git a/pymapmanager/interface2/runInterfaceJohnson.py b/pymapmanager/interface2/runInterfaceJohnson.py index d91757c..b7cded1 100644 --- a/pymapmanager/interface2/runInterfaceJohnson.py +++ b/pymapmanager/interface2/runInterfaceJohnson.py @@ -26,14 +26,14 @@ def run(): # path = '../PyMapManager-Data/core-map/one-timepoint/oneTimepoint.mmap' # path ='\\Users\\johns\\Documents\\GitHub\\MapManagerCore\\sandbox\\data\\rr30a_s0.mmap' # path = 'C:\\Users\\johns\\Documents\\GitHub\\MapManagerCore\\data\\rr30a_s0u.mmap' - # path = '\\Users\\johns\\Documents\\GitHub\\MapManagerCore\\data\\rr30a_s0u.mmap' + path = '\\Users\\johns\\Documents\\GitHub\\MapManagerCore\\data\\rr30a_s0u.mmap' # path = '/Users/johns/Documents/GitHub/MapManagerCore/data/rr30a_s0u.mmap' # path = '/Users/johns/Documents/GitHub/MapManagerCore/data/rr30a_s0u_v3.mmap' # path = '/Users/johns/Documents/GitHub/MapManagerCore/data/test2.mmap' # path = '/Users/johns/Documents/GitHub/PyMapManager-Data/one-timepoint/rr30a_s0_ch1.mmap' - path = 'C:/Users/johns/Documents/TestMMCMaps/rr30a_s0u.mmap' + # path = 'C:/Users/johns/Documents/TestMMCMaps/rr30a_s0u.mmap' # import mapmanagercore # pooch path @@ -74,6 +74,7 @@ def run2(): def run3(): app = PyMapManagerApp() path = 'C:/Users/johns/Documents/TestMMCMaps/rr30a_s0u.mmap' + # path = 'C:/Users/johns/Documents/TestMMCMaps/rr30a_s0u_newSpineAngle.mmap' sw2 = app.loadStackWidget(path) sw2.zoomToPointAnnotation(120, isAlt=True) @@ -81,6 +82,6 @@ def run3(): if __name__ == '__main__': - # run() + run() # run2() - run3() \ No newline at end of file + # run3() \ No newline at end of file diff --git a/pymapmanager/interface2/stackWidgets/annotationPlotWidget2.py b/pymapmanager/interface2/stackWidgets/annotationPlotWidget2.py index ccf925b..0222c04 100644 --- a/pymapmanager/interface2/stackWidgets/annotationPlotWidget2.py +++ b/pymapmanager/interface2/stackWidgets/annotationPlotWidget2.py @@ -76,15 +76,15 @@ def setLabelPos(self, labelID, label): y = self.df.getValue('y', labelID) spineAngles = self._df.getDataFrame()["spineAngle"] idSpineAngle = spineAngles[labelID] - adjustConstant = 2 + adjustConstant = 3 adjustX = adjustConstant * math.cos(idSpineAngle * math.pi/180) adjustY = adjustConstant * math.sin(idSpineAngle * math.pi/180) adjustX = abs(adjustX) adjustY = abs(adjustY) - if 0 <= abs(idSpineAngle) and abs(idSpineAngle) <= 90: + if 0 <= idSpineAngle and idSpineAngle <= 90: label.setPos(QtCore.QPointF(x + adjustX, y + adjustY)) - elif 90 <= abs(idSpineAngle) and abs(idSpineAngle) <= 180: + elif 90 <= idSpineAngle and idSpineAngle <= 180: label.setPos(QtCore.QPointF(x - adjustX, y + adjustY)) elif 180 <= idSpineAngle and idSpineAngle <= 270: label.setPos(QtCore.QPointF(x - adjustX, y - adjustY)) diff --git a/pymapmanager/interface2/stackWidgets/pmmDendrogramWidget.py b/pymapmanager/interface2/stackWidgets/pmmDendrogramWidget.py index 153c862..ce0280c 100644 --- a/pymapmanager/interface2/stackWidgets/pmmDendrogramWidget.py +++ b/pymapmanager/interface2/stackWidgets/pmmDendrogramWidget.py @@ -224,252 +224,4 @@ def manualConnectSpineEvent(self, event : pmmEvent): def autoConnectSpineEvent(self, event : pmmEvent): # Nothing needs to be done since same spine will be selected within highlighter pass - - - - - # # def _buildDendrogram(self): - # # self._buildGUI() - - # def setupPlots(self): - - # penWidth = 6 - # color = "red" - # _pen = pg.mkPen(width=penWidth, color=color) - - # # _scatter is pyqtgraph.graphicsItems.PlotDataItem.PlotDataItem - # self._spines = self._view.plot( - # [], - # [], - # pen=_pen, # None to not draw lines - # symbol='o', - # # symbolColor = 'red', - # symbolPen=None, - # fillOutline=False, - # markeredgewidth=0.0, - # symbolBrush=color, - # connect=None - # ) - - # self._spines.setZValue(2) - - # color = "blue" - # _pen = pg.mkPen(width=penWidth, color=color) - # self._spineLines = self._view.plot( - # [], - # [], - # pen=_pen, # None to not draw lines - # symbol=None, - # # symbolColor = 'red', - # symbolPen=None, - # fillOutline=False, - # markeredgewidth=0.0, - # symbolBrush=color, - # connect="finite" - # ) - # self._spineLines.setZValue(1) - - # self._segmentLine = self._view.plot( - # [], - # [], - # pen=_pen, # None to not draw lines - # symbol=None, - # # symbolColor = 'red', - # symbolPen=None, - # fillOutline=False, - # markeredgewidth=0.0, - # symbolBrush=color, - # # connect= - # ) - # self._segmentLine.setZValue(1) - - # def _buildGUI(self): - # self.layout = QtWidgets.QVBoxLayout() - # # self.setLayout(self.layout) - # windowLayout = self._buildMainLayout() - # self.layout.addLayout(windowLayout) - # self._makeCentralWidget(self.layout) - - # def _buildMainLayout(self): - # # main layout - # hLayout = QtWidgets.QHBoxLayout() - # hSplitter = QtWidgets.QSplitter(QtCore.Qt.Horizontal) - # hLayout.addWidget(hSplitter) - - # # controls and both stat lists - # vLayout = QtWidgets.QVBoxLayout() - - # self.setSegmentIDList() - # hLayoutHeader = QtWidgets.QHBoxLayout() - # self.segmentIDComboBox = QtWidgets.QComboBox() - # for id in self.segmentIDList: # add ids to combobox - # logger.info(f"id {id}") - # self.segmentIDComboBox.addItem(str(id)) - # self.segmentIDComboBox.currentTextChanged.connect(self._on_new_segment_ID) - # hLayoutHeader.addWidget(self.segmentIDComboBox) - - # # Invert Y Checkbox - # self.spineLengthCheckbox = QtWidgets.QCheckBox('Spine Length') - # self.spineLengthCheckbox.setChecked(True) - # self.spineLengthCheckbox.stateChanged.connect(self._on_spine_length_checkbox) - # hLayoutHeader.addWidget(self.spineLengthCheckbox) - - # # Histogram Checkbox - # self.spineAngleCheckbox = QtWidgets.QCheckBox("Spine Angle") - # self.spineAngleCheckbox.setChecked(True) - # self.spineAngleCheckbox.stateChanged.connect(self._on_spine_angle_checkbox) - # hLayoutHeader.addWidget(self.spineAngleCheckbox) - - # vLayout.addLayout(hLayoutHeader) - - # # columnsWidget = list of controls (checkboxes) - # columnsWidget = QtWidgets.QWidget() - # columnsWidget.setLayout(vLayout) - # hSplitter.addWidget(columnsWidget) - - # # Set up scatter plot - # # self.fig = mpl.figure.Figure() - # # self.static_canvas = backend_qt5agg.FigureCanvas(self.fig) - # # self.static_canvas.setFocusPolicy( - # # QtCore.Qt.ClickFocus - # # ) - # # self.static_canvas.setFocus() - # # self.mplToolbar = mpl.backends.backend_qt5agg.NavigationToolbar2QT( - # # self.static_canvas, self.static_canvas - # # ) - - # # Accept Checkbox - # plotWidget = QtWidgets.QWidget() - # vLayoutPlot = QtWidgets.QVBoxLayout() - - # vLayoutPlot.addWidget(self._view) - # # vLayoutPlot.addWidget(self.static_canvas) - # # vLayoutPlot.addWidget(self.mplToolbar) - # plotWidget.setLayout(vLayoutPlot) - # hSplitter.addWidget(plotWidget) - # self.finalLayout = hLayout - - # return self.finalLayout - - # def replot(self, newSegmentID): - # """ - # """ - # logger.info(f"newSegmentID {newSegmentID}") - - # filteredPointDF = self._paDf[self._paDf["segmentID"] == newSegmentID] - # logger.info(f"filteredPointDF0 {filteredPointDF}") - # spinePositions = filteredPointDF["spinePosition"] - # spineLength = filteredPointDF["spineLength"] - # logger.info(f"spineLength {spineLength}") - # spineAngle= filteredPointDF["spineAngle"] - # spineSide = filteredPointDF["spineSide"] - # spineIndex = filteredPointDF["index"] - - # anchorX = [] - # anchorY = [] - # for val in spinePositions: - # # print(i) - # anchorX.append(0) - # anchorY.append(val) - - # spineX = [] - # spineY = [] - # # TODO: change indexing to account for spineLength/ spineSide using df index - # # index = actual spine index - # # i = counting index starting from 0 - # for i, index in enumerate(spineIndex): - # constant = spineLength[index] - # # print("i", spineSide[i][0]) - # direction = spineSide[index] # need to index to get first and only value in series - # if(direction == "Left"): - # spineX.append(constant) - # spineY.append(anchorY[i]) - # elif(direction == "Right"): - # spineX.append(-1 *(constant)) - # spineY.append(anchorY[i]) - - - # spineLineX = [] - # spineLineY = [] - # for i, val in enumerate(anchorX): - # # print("here") - # spineLineX.append(anchorX[i]) - # spineLineX.append(spineX[i]) - # spineLineX.append(np.nan) - # spineLineY.append(anchorY[i]) - # spineLineY.append(spineY[i]) - # spineLineY.append(np.nan) - - # # plot spines - - # # _lineConnect = self._getScatterConnect(self._spines) - # # self._spines.setData(spineX, spineY, connect = "pairs") - # self._spineLines.setData(spineLineX, spineLineY) - # self._spines.setData(spineX, spineY) - - # # filteredLineDF0 = self._laDf[self._laDf["segmentID"] == 0] - # # logger.info(f"self._laDf {self._laDf.index}") - # filteredLineDF = self._laDf[self._laDf.index == newSegmentID] - # # self._laDf[] - # # get length of segment, get the first row since all rows will have same value within same segmemt - # segmentLength = filteredLineDF["length"].iloc[0] - # logger.info(f"segmentLength {segmentLength}") - # # length0 = lineString0.length - # self._segmentLine.setData([0,0],[0,segmentLength]) - - - # def _getScatterConnect(self, df : pd.DataFrame) -> Optional[np.ndarray]: - # """Given a line df to plot (for a slice) - # Build a connect array with - # 1 : connect to next - # 0 : do not connect to next - # """ - # # logger.info(df) - - # if len(df) == 0: - # return None - - # dfRet = np.diff(df.index.to_numpy()) - # dfRet[ dfRet != 0] = -1 - # dfRet[ dfRet == 0] = 1 - # dfRet[ dfRet == -1] = 0 - - # rowIndexDiff = np.diff(df['rowIndex']) # 1 when contiguous rows - # # rowIndexDiff = np.diff(df.index) # 1 when contiguous rows - # dfRet[ (dfRet == 1) & (rowIndexDiff != 1)] = 0 - - # dfRet = np.append(dfRet, 0) # append 0 value - - # return dfRet - - - # def setSegmentIDList(self): - # # self.hueIDList = ["All", self._df[hueColumnStr].unique().tolist()] - # # logger.info(f"self._laDf {self._laDf}") - # index = self._laDf.index - # self.segmentIDList = index.unique() - # # logger.info(f"self.segmentIDList {self.segmentIDList}") - - # def _on_new_segment_ID(self, newSegmentID): - # """ - # """ - - # # replot new ID - # newSegmentID = int(newSegmentID) - # self.replot(newSegmentID) - - # def _on_spine_length_checkbox(self): - # """ - # """ - - # # if true replot using spine lengths from backend - # # else: use set constant - - # def _on_spine_angle_checkbox(self): - # """ - # """ - - # # if true replot using spine angle from backend - # # else: use set constant - - + \ No newline at end of file