From 5b7653c4e9afc47d5c7f96fdbd8c4a7d7d295df9 Mon Sep 17 00:00:00 2001 From: Shekar V Date: Wed, 6 Mar 2024 09:26:53 -0500 Subject: [PATCH 1/3] Faster raster filling --- gui/control_main.py | 112 ++++++++++++++++++++------------------------ 1 file changed, 52 insertions(+), 60 deletions(-) diff --git a/gui/control_main.py b/gui/control_main.py index cf49b7e0..b709033a 100644 --- a/gui/control_main.py +++ b/gui/control_main.py @@ -2919,11 +2919,13 @@ def center3LoopCB(self): def fillPolyRaster( self, rasterReq, waitTime=1 ): # at this point I should have a drawn polyRaster - time.sleep(waitTime) logger.info("filling poly for " + str(rasterReq["uid"])) - resultCount = len(db_lib.getResultsforRequest(rasterReq["uid"])) rasterResults = db_lib.getResultsforRequest(rasterReq["uid"]) + + if not rasterResults: + return rasterResult = {} + for i in range(0, len(rasterResults)): if rasterResults[i]["result_type"] == "rasterResult": rasterResult = rasterResults[i] @@ -2933,6 +2935,7 @@ def fillPolyRaster( except KeyError: db_lib.deleteRequest(rasterReq["uid"]) return + rasterListIndex = 0 for i in range(len(self.rasterList)): if self.rasterList[i] != None: @@ -2949,12 +2952,18 @@ def fillPolyRaster( self.currentRasterCellList = currentRasterGroup.childItems() cellResults = rasterResult["result_obj"]["rasterCellResults"]["resultObj"] numLines = len(cellResults) - cellResults_array = [{} for i in range(numLines)] + # cellResults_array = [{} for i in range(numLines)] my_array = np.zeros(numLines) spotLineCounter = 0 cellIndex = 0 rowStartIndex = 0 rasterEvalOption = str(self.rasterEvalComboBox.currentText()) + if rasterEvalOption == "Spot Count": + cell_result_key = "spot_count_no_ice" + elif rasterEvalOption == "Intensity": + cell_result_key = "total_intensity" + else: + cell_result_key = "d_min" lenX = abs( rasterDef["rowDefs"][0]["end"]["x"] - rasterDef["rowDefs"][0]["start"]["x"] ) # ugly for tile flip/noflip @@ -2973,12 +2982,7 @@ def fillPolyRaster( "expected: " + str(len(rasterDef["rowDefs"]) * numsteps) ) return # means a raster failure, and not enough data to cover raster, caused a gui crash - try: - spotcount = cellResult["spot_count_no_ice"] - filename = cellResult["image"] - except TypeError: - spotcount = 0 - filename = "empty" + if ( lenX > 180 and self.scannerType == "PI" @@ -2989,16 +2993,12 @@ def fillPolyRaster( cellIndex = spotLineCounter else: cellIndex = rowStartIndex + ((numsteps - 1) - j) + try: - if rasterEvalOption == "Spot Count": - my_array[cellIndex] = spotcount - elif rasterEvalOption == "Intensity": - my_array[cellIndex] = cellResult["total_intensity"] - else: - if float(cellResult["d_min"]) == -1: - my_array[cellIndex] = 50.0 - else: - my_array[cellIndex] = float(cellResult["d_min"]) + my_array[cellIndex] = cellResult[cell_result_key] + if cell_result_key == 'd_min' and my_array[cellIndex] == -1: + my_array[cellIndex] = 50.0 + except IndexError: logger.error("caught index error #2") logger.error("numlines = " + str(numLines)) @@ -3006,59 +3006,51 @@ def fillPolyRaster( "expected: " + str(len(rasterDef["rowDefs"]) * numsteps) ) return # means a raster failure, and not enough data to cover raster, caused a gui crash - cellResults_array[ - cellIndex - ] = cellResult # instead of just grabbing filename, get everything. Not sure why I'm building my own list of results. How is this different from cellResults? - # I don't think cellResults_array is different from cellResults, could maybe test that below by subtituting one for the other. It may be a remnant of trying to store less than the whole result set. spotLineCounter += 1 floor = np.amin(my_array) ceiling = np.amax(my_array) + cellCounter = 0 + color_id = None + if ceiling == 0: + color_id = 255 + elif ceiling == floor: + if rasterEvalOption == "Resolution": + color_id = 0 + else: + color_id = 255 + if color_id is None: + color_ids = ((my_array - floor) / (ceiling - floor)) * 255.0 + else: + color_ids = np.full(my_array.shape, color_id) + + index = 0 for i in range(len(rasterDef["rowDefs"])): - rowCellCount = 0 - for j in range(rasterDef["rowDefs"][i]["numsteps"]): - cellResult = cellResults_array[cellCounter] - try: - spotcount = int(cellResult["spot_count_no_ice"]) - cellFilename = cellResult["image"] - d_min = float(cellResult["d_min"]) - if d_min == -1: - d_min = 50.0 # trying to handle frames with no spots - total_intensity = int(cellResult["total_intensity"]) - except TypeError: - spotcount = 0 - cellFilename = "empty" - d_min = 50.0 - total_intensity = 0 - - if rasterEvalOption == "Spot Count": - param = spotcount - elif rasterEvalOption == "Intensity": - param = total_intensity + numsteps = rasterDef["rowDefs"][i]["numsteps"] + rowStartIndex = cellCounter + for j in range(numsteps): + if i % 2 == 0: # this is trying to figure out row direction + index = cellCounter else: - param = d_min - if ceiling == 0: - color_id = 255 - elif ceiling == floor: + index = rowStartIndex + ((numsteps - 1) - j) + if color_id is None: + #param = my_array[cellCounter] if rasterEvalOption == "Resolution": - color_id = 0 + color = int(255 - color_ids[index]) else: - color_id = 255 - elif rasterEvalOption == "Resolution": - color_id = int( - 255.0 * (float(param - floor) / float(ceiling - floor)) + color = int(color_ids[index]) + self.currentRasterCellList[index].setBrush( + QtGui.QBrush(QtGui.QColor(0, color, 0, 127)) ) else: - color_id = int( - 255 - (255.0 * (float(param - floor) / float(ceiling - floor))) + self.currentRasterCellList[index].setBrush( + QtGui.QBrush(QtGui.QColor(0, 255 - color_id, 0, 127)) ) - self.currentRasterCellList[cellCounter].setBrush( - QtGui.QBrush(QtGui.QColor(0, 255 - color_id, 0, 127)) - ) - self.currentRasterCellList[cellCounter].setData(0, spotcount) - self.currentRasterCellList[cellCounter].setData(1, cellFilename) - self.currentRasterCellList[cellCounter].setData(2, d_min) - self.currentRasterCellList[cellCounter].setData(3, total_intensity) + cellResult = cellResults[cellCounter] + self.currentRasterCellList[index].setData(0, cellResult.get("spot_count_no_ice", 0)) + self.currentRasterCellList[index].setData(1, cellResult.get("image", "empty")) + self.currentRasterCellList[index].setData(2, cellResult.get("d_min", 50.0)) + self.currentRasterCellList[index].setData(3, cellResult.get("total_intensity", 0)) cellCounter += 1 def takeRasterSnapshot(self, rasterReq): From 93b83ff17c5e72728434abe76e83ea54e4c865c2 Mon Sep 17 00:00:00 2001 From: Shekar V Date: Wed, 6 Mar 2024 09:27:16 -0500 Subject: [PATCH 2/3] Raster hover is a tooltip rather than window --- gui/raster.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/gui/raster.py b/gui/raster.py index 845a1a53..cc351265 100644 --- a/gui/raster.py +++ b/gui/raster.py @@ -87,13 +87,25 @@ def mouseReleaseEvent(self, e): def hoverMoveEvent(self, e): super(RasterGroup, self).hoverEnterEvent(e) for cell in self.childItems(): - if isInCell(e.scenePos(), cell): + if cell.contains(e.pos()): if cell.data(0) != None: spotcount = cell.data(0) d_min = cell.data(2) intensity = cell.data(3) - if not (self.parent.rasterExploreDialog.isVisible()): - self.parent.rasterExploreDialog.show() - self.parent.rasterExploreDialog.setSpotCount(spotcount) - self.parent.rasterExploreDialog.setTotalIntensity(intensity) - self.parent.rasterExploreDialog.setResolution(d_min) + viewPos = self.scene().views()[0].mapFromScene(self.scenePos()) + globalPos = self.scene().views()[0].mapToGlobal(viewPos) + text = "" + table_data = {} + + table_data['Spot Count'] = spotcount + table_data['Total Intensity'] = intensity + table_data['Resolution'] = d_min + + text = """ + """ + for key, value in table_data.items(): + text += f""" + """ + text = text + "
{key}{value}
" + + QtWidgets.QToolTip.showText(globalPos, text) From a6c9c7c013831131b8a2c86266e6b10f5a3f39fe Mon Sep 17 00:00:00 2001 From: Shekar V Date: Fri, 5 Apr 2024 15:30:17 -0400 Subject: [PATCH 3/3] Added requested fixes --- gui/control_main.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gui/control_main.py b/gui/control_main.py index b709033a..948b68f1 100644 --- a/gui/control_main.py +++ b/gui/control_main.py @@ -2917,7 +2917,7 @@ def center3LoopCB(self): self.send_to_server("mvaDescriptor", ["omega", 0]) def fillPolyRaster( - self, rasterReq, waitTime=1 + self, rasterReq ): # at this point I should have a drawn polyRaster logger.info("filling poly for " + str(rasterReq["uid"])) rasterResults = db_lib.getResultsforRequest(rasterReq["uid"]) @@ -2952,7 +2952,6 @@ def fillPolyRaster( self.currentRasterCellList = currentRasterGroup.childItems() cellResults = rasterResult["result_obj"]["rasterCellResults"]["resultObj"] numLines = len(cellResults) - # cellResults_array = [{} for i in range(numLines)] my_array = np.zeros(numLines) spotLineCounter = 0 cellIndex = 0