def _graphSignal(self, ddict, ownsignal = None): if self.changeTagOn: if self.__selectionMask is not None and ddict['event']=="mouseClicked" and ddict['button']=="middle" : x,y = int(ddict["x"]), int(ddict["y"]) y, x = sole_MaskImageWidget.convertToRowAndColumn(x , y, self.__imageData.shape, xScale=self._xScale, yScale=self._yScale, safe=True) id_target = self.__selectionMask[y,x] if id_target and id_target!= self._nRoi: mask_target = (self.__selectionMask == id_target ) mask_swap = (self.__selectionMask== self._nRoi) self.__selectionMask [mask_target] = self._nRoi self.__selectionMask [mask_swap] = id_target emitsignal = True if emitsignal: self.plotImage(update = False) self._emitMaskChangedSignal() return # super(MaskImageWidget, self)._graphSignal(ddict, ownsignal) sole_MaskImageWidget.MaskImageWidget._graphSignal(self, ddict, ownsignal)
def _rixsID26(self): allCurves = self.getAllCurves() nCurves = len(allCurves) if nCurves < 2: msg = "ID26 RIXS scans are built combining several single scans" raise ValueError(msg) self._xLabel = self.getGraphXLabel() self._yLabel = self.getGraphYLabel() if self._xLabel not in [ "energy", "Spec.Energy", "arr_hdh_ene", "Mono.Energy" ]: msg = "X axis does not correspond to a BM20 or ID26 RIXS scan" raise ValueError(msg) motorNames = allCurves[0][3]["MotorNames"] if self._xLabel == "Spec.Energy": # ID26 fixedMotorMne = "Mono.Energy" elif (self._xLabel == "energy") and ("xes_en" in motorNames): # BM20 case fixedMotorMne = "xes_en" elif "Spec.Energy" in motorNames: # ID26 fixedMotorMne = "Spec.Energy" else: # TODO: Show a combobox to allow the selection of the "motor" msg = "Cannot automatically recognize motor mnemomnic to be used" raise ValueError(msg) fixedMotorIndex = allCurves[0][3]["MotorNames"].index(fixedMotorMne) #get the min and max values of the curves if fixedMotorMne == "Mono.Energy": info = allCurves[0][3] xMin = info["MotorValues"][fixedMotorIndex] xMax = xMin nData = 0 i = 0 minValues = numpy.zeros((nCurves, ), numpy.float64) for curve in allCurves: info = curve[3] tmpMin = info['MotorValues'][fixedMotorIndex] tmpMax = info['MotorValues'][fixedMotorIndex] minValues[i] = tmpMin if tmpMin < xMin: xMin = tmpMin if tmpMax > xMax: xMax = tmpMax nData += len(curve[0]) i += 1 else: xMin = allCurves[0][0][0] # ID26 data are already ordered xMax = allCurves[0][0][-1] minValues = numpy.zeros((nCurves, ), numpy.float64) minValues[0] = xMin nData = len(allCurves[0][0]) i = 0 for curve in allCurves[1:]: i += 1 tmpMin = curve[0][0] tmpMax = curve[0][-1] minValues[i] = tmpMin if tmpMin < xMin: xMin = tmpMin if tmpMax > xMax: xMax = tmpMax nData += len(curve[0]) #sort the curves orderIndex = minValues.argsort() #print "ORDER INDEX = ", orderIndex # express data in eV if (xMax - xMin) < 5.0: # it seems data need to be multiplied factor = 1000. else: factor = 1.0 motor2Values = numpy.zeros((nCurves, ), numpy.float64) xData = numpy.zeros((nData, ), numpy.float32) yData = numpy.zeros((nData, ), numpy.float32) zData = numpy.zeros((nData, ), numpy.float32) start = 0 for i in range(nCurves): idx = orderIndex[i] curve = allCurves[idx] info = curve[3] nPoints = max(curve[0].shape) end = start + nPoints x = curve[0] z = curve[1] x.shape = -1 z.shape = -1 if fixedMotorMne == "Mono.Energy": xData[ start:end] = info["MotorValues"][fixedMotorIndex] * factor yData[start:end] = x * factor else: xData[start:end] = x * factor yData[ start:end] = info["MotorValues"][fixedMotorIndex] * factor zData[start:end] = z start = end # construct the grid in steps of eStep eV eStep = 0.05 n = (xMax - xMin) * (factor / eStep) grid0 = numpy.linspace(xMin * factor, xMax * factor, n) grid1 = numpy.linspace(yData.min(), yData.max(), n) # create the meshgrid xx, yy = numpy.meshgrid(grid0, grid1) if 0: # get the interpolated values try: zz = griddata(xData, yData, zData, xx, yy) except RuntimeError: zz = griddata(xData, yData, zData, xx, yy, interp='linear') # show them if self._rixsWidget is None: self._rixsWidget = MaskImageWidget.MaskImageWidget(\ imageicons=False, selection=False, profileselection=True, scanwindow=self) self._rixsWidget.setImageData(zz, xScale=(xx.min(), xx.max()), yScale=(yy.min(), yy.max())) self._rixsWidget.show() elif 1: etData = xData - yData grid3 = numpy.linspace(etData.min(), etData.max(), n) # create the meshgrid xx, yy = numpy.meshgrid(grid0, grid3) # get the interpolated values try: zz = griddata(xData, etData, zData, xx, yy) except RuntimeError: # Natural neighbor interpolation not always possible zz = griddata(xData, etData, zData, xx, yy, interp='linear') if self._rixsWidget is None: self._rixsWidget = MaskImageWidget.MaskImageWidget(\ imageicons=False, selection=False, aspect=True, profileselection=True, scanwindow=self) self._rixsWidget.setLineProjectionMode('X') #actualMax = zData.max() #actualMin = zData.min() #zz = numpy.where(numpy.isfinite(zz), zz, actualMax) shape = zz.shape xScale = (xx.min(), (xx.max() - xx.min()) / float(zz.shape[1])) yScale = (yy.min(), (yy.max() - yy.min()) / float(zz.shape[0])) self._rixsWidget.setImageData(zz, xScale=xScale, yScale=yScale) self._rixsWidget.setXLabel("Incident Energy (eV)") self._rixsWidget.setYLabel("Energy Transfer (eV)") self._rixsWidget.show() return
def __init__(self, parent=None, graph=None, bgrx=True, image_shape=None): qt.QWidget.__init__(self, parent) self.setWindowTitle("PyMca RGB Correlator") self.setWindowIcon( qt.QIcon(qt.QPixmap(RGBCorrelatorGraph.IconDict['gioconda16']))) self.mainLayout = qt.QVBoxLayout(self) self.mainLayout.setContentsMargins(0, 0, 0, 0) self.mainLayout.setSpacing(6) self.splitter = qt.QSplitter(self) self.splitter.setOrientation(qt.Qt.Horizontal) self.controller = RGBCorrelatorWidget.RGBCorrelatorWidget( self.splitter, image_shape=image_shape) self._y1AxisInverted = False self._imageBuffer = None self._matplotlibSaveImage = None standaloneSaving = True if graph is None: if MATPLOTLIB: standaloneSaving = False if USE_MASK_WIDGET: self.graphWidgetContainer = MaskImageWidget.MaskImageWidget( self.splitter, selection=True, imageicons=True, standalonesave=standaloneSaving, profileselection=False, polygon=True) self.graphWidget = self.graphWidgetContainer.graphWidget else: self.graphWidget = RGBCorrelatorGraph.RGBCorrelatorGraph( self.splitter, standalonesave=standaloneSaving) if not standaloneSaving: self.graphWidget.saveToolButton.clicked.connect( \ self._saveToolButtonSignal) self._saveMenu = qt.QMenu() self._saveMenu.addAction(QString("Standard"), self.graphWidget._saveIconSignal) self._saveMenu.addAction(QString("Matplotlib"), self._saveMatplotlibImage) self.graph = self.graphWidget.graph #add flip Icon self.graphWidget.hFlipToolButton.clicked.connect( \ self._hFlipIconSignal) self._handleGraph = True else: self.graph = graph self._handleGraph = False #self.splitter.setStretchFactor(0,1) #self.splitter.setStretchFactor(1,1) self.mainLayout.addWidget(self.splitter) self.reset = self.controller.reset self.addImage = self.controller.addImage self.removeImage = self.controller.removeImage self.addImageSlot = self.controller.addImageSlot self.removeImageSlot = self.controller.removeImageSlot self.replaceImageSlot = self.controller.replaceImageSlot self.setImageShape = self.controller.setImageShape self.update = self.controller.update self.transposeImages = self.controller.transposeImages self.controller.sigRGBCorrelatorWidgetSignal.connect( \ self.correlatorSignalSlot) self.controller.sigMaskImageWidgetSignal.connect( \ self.maskImageSlot)
def _energyTransfer(self, mode="energytransfer"): allCurves = self.getAllCurves() nCurves = len(allCurves) if nCurves < 2: msg = "RIXS scans are built combining several single scans" raise ValueError(msg) self._xLabel = self.getGraphXLabel() self._yLabel = self.getGraphYLabel() if self._xLabel not in \ ["energy", "Energy", "Spec.Energy", "arr_hdh_ene", "Mono.Energy"]: msg = "X axis does not correspond to a supported RIXS scan" raise ValueError(msg) motorNames = allCurves[0][3]["MotorNames"] CHESS = False if self._xLabel == "Spec.Energy": # ID26 fixedMotorMne = "Mono.Energy" elif (self._xLabel == "Energy") and ("xes_dn_ana" in motorNames): # CHESS fixedMotorMne = "xes_dn_ana" CHESS = True msg = "Please use CHESS provided plugin. Contact beamline staff" raise RuntimeError(msg) elif (self._xLabel == "energy") and ("xes_en" in motorNames): # BM20 case fixedMotorMne = "xes_en" elif "Spec.Energy" in motorNames: # ID26 fixedMotorMne = "Spec.Energy" else: # TODO: Show a combobox to allow the selection of the "motor" msg = "Cannot automatically recognize motor mnemomnic to be used" raise ValueError(msg) fixedMotorIndex = allCurves[0][3]["MotorNames"].index(fixedMotorMne) #get the min and max values of the curves if fixedMotorMne != "Mono.Energy": xMin = allCurves[0][0][0] # ID26 data are already ordered xMax = allCurves[0][0][-1] minValues = numpy.zeros((nCurves, ), numpy.float64) minValues[0] = xMin nData = len(allCurves[0][0]) i = 0 for curve in allCurves[1:]: i += 1 tmpMin = curve[0][0] tmpMax = curve[0][-1] minValues[i] = tmpMin if tmpMin < xMin: xMin = tmpMin if tmpMax > xMax: xMax = tmpMax nData += len(curve[0]) else: info = allCurves[0][3] xMin = info["MotorValues"][fixedMotorIndex] xMax = xMin nData = 0 i = 0 minValues = numpy.zeros((nCurves, ), numpy.float64) for curve in allCurves: info = curve[3] tmpMin = info['MotorValues'][fixedMotorIndex] tmpMax = info['MotorValues'][fixedMotorIndex] minValues[i] = tmpMin if tmpMin < xMin: xMin = tmpMin if tmpMax > xMax: xMax = tmpMax nData += len(curve[0]) i += 1 #sort the curves orderIndex = minValues.argsort() #print "ORDER INDEX = ", orderIndex # express data in eV if (xMax - xMin) < 5.0: # it seems data need to be multiplied factor = 1000. else: factor = 1.0 motor2Values = numpy.zeros((nCurves, ), numpy.float64) xData = numpy.zeros((nData, ), numpy.float32) yData = numpy.zeros((nData, ), numpy.float32) zData = numpy.zeros((nData, ), numpy.float32) start = 0 for i in range(nCurves): idx = orderIndex[i] curve = allCurves[idx] info = curve[3] nPoints = max(curve[0].shape) end = start + nPoints x = curve[0] z = curve[1] x.shape = -1 z.shape = -1 if fixedMotorMne == "Mono.Energy": xData[ start:end] = info["MotorValues"][fixedMotorIndex] * factor yData[start:end] = x * factor elif CHESS: xData[start:end] = x * factor #yData[start:end] = info["MotorValues"][fixedMotorIndex] thetaDeg = 78.1119 + 0.5 * ( info["MotorValues"][fixedMotorIndex] + 5.25) yData[start:end] = 12398.4 / ( 1.656446 * numpy.sin(numpy.pi * thetaDeg / 180.)) else: xData[start:end] = x * factor yData[ start:end] = info["MotorValues"][fixedMotorIndex] * factor zData[start:end] = z start = end # construct the grid in steps of eStep eV eStep = 0.05 n = (xMax - xMin) * (factor / eStep) grid0 = numpy.linspace(xMin * factor, xMax * factor, n) grid1 = numpy.linspace(yData.min(), yData.max(), n) # create the meshgrid xx, yy = numpy.meshgrid(grid0, grid1) if 0: # get the interpolated values etData = xData - yData grid3 = numpy.linspace(etData.min(), etData.max(), n) xx, yy = numpy.meshgrid(grid0, grid3) try: zz = griddata(xData, etData, zData, xx, yy) except RuntimeError: zz = griddata(xData, etData, zData, xx, yy, interp='linear') # show them if self._rixsWidget is None: self._rixsWidget = MaskImageWidget.MaskImageWidget(\ imageicons=False, selection=False, profileselection=True, scanwindow=self) shape = zz.shape xScale = (xx.min(), (xx.max() - xx.min()) / float(zz.shape[1])) yScale = (yy.min(), (yy.max() - yy.min()) / float(zz.shape[0])) self._rixsWidget.setImageData(zz, xScale=xScale, yScale=yScale) self._rixsWidget.setXLabel("Incident Energy (eV)") self._rixsWidget.setYLabel("Energy Transfer (eV)") self._rixsWidget.show() elif 1: if mode == "mesh": etData = yData else: etData = xData - yData grid3 = numpy.linspace(etData.min(), etData.max(), n) # create the meshgrid xx, yy = numpy.meshgrid(grid0, grid3) # get the interpolated values if GRIDDATA == "matplotlib": try: zz = griddata(xData, etData, zData, xx, yy) except: # Natural neighbor interpolation not always possible zz = griddata(xData, etData, zData, xx, yy, interp='linear') elif GRIDDATA == "scipy": zz = griddata((xData, etData), zData, (xx, yy), method='cubic') else: raise RuntimeError("griddata function not available") if self._rixsWidget is None: self._rixsWidget = MaskImageWidget.MaskImageWidget(\ imageicons=False, selection=False, aspect=True, profileselection=True, scanwindow=self) self._rixsWidget.setLineProjectionMode('X') #actualMax = zData.max() #actualMin = zData.min() #zz = numpy.where(numpy.isfinite(zz), zz, actualMax) shape = zz.shape xScale = (xx.min(), (xx.max() - xx.min()) / float(zz.shape[1])) if mode == "energyout": yScale = (yy.min() + yData.min(), (yy.max() - yy.min()) / float(zz.shape[0])) else: yScale = (yy.min(), (yy.max() - yy.min()) / float(zz.shape[0])) self._rixsWidget.setXLabel("Incident Energy (eV)") if mode == "mesh": self._rixsWidget.setYLabel("Emitted Energy (eV)") elif mode == "energyout": self._rixsWidget.setYLabel("Emitted Energy (eV)") else: self._rixsWidget.setYLabel("Energy Transfer (eV)") self._rixsWidget.setImageData(zz, xScale=xScale, yScale=yScale) # self._rixsWidget.graph.replot() self._rixsWidget.show() self._rixsWidget.raise_() return
def _convert(self): x, y, legend, info = self.getActiveCurve() self._x = x[:] self._y = y[:] if 'Header' not in info: raise ValueError("Active curve does not seem to be a mesh scan") header = info['Header'][0] item = header.split() if item[2] not in ['mesh', 'hklmesh']: raise ValueError("Active curve does not seem to be a mesh scan") self._xLabel = self.getGraphXLabel() self._yLabel = self.getGraphYLabel() self._motor0Mne = item[3] self._motor1Mne = item[7] #print("Scanned motors are %s and %s" % (motor0Mne, motor1Mne)) #Assume an EXACTLY regular mesh for both motors self._motor0 = numpy.linspace(float(item[4]), float(item[5]), int(item[6]) + 1) self._motor1 = numpy.linspace(float(item[8]), float(item[9]), int(item[10]) + 1) #Didier's contribution: Try to do something if scan has been interrupted if y.size < (int(item[6]) + 1) * (int(item[10]) + 1): _logger.warning("WARNING: Incomplete mesh scan") self._motor1 = numpy.resize(self._motor1, (y.size / (int(item[6]) + 1), 1)) y = numpy.resize(y, ((y.size / (int(item[6]) + 1) * (int(item[6]) + 1)), 1)) try: if xLabel.upper() == motor0Mne.upper(): self._motor0 = self._x self._motor0Mne = self._xLabel elif xLabel.upper() == motor1Mne.upper(): self._motor1 = self._x self._motor1Mne = self._xLabel elif xLabel == info['selection']['cntlist'][0]: self._motor0 = self._x self._motor0Mne = self._xLabel elif xLabel == info['selection']['cntlist'][1]: self._motor1 = self._x self._motor1Mne = self._xLabel except: _logger.debug("XLabel should be one of the scanned motors") self._legend = legend self._info = info yView = y[:] yView.shape = len(self._motor1), len(self._motor0) if self.imageWidget is None: self.imageWidget = MaskImageWidget.MaskImageWidget(\ imageicons=False, selection=False, profileselection=True, scanwindow=self) deltaX = self._motor0[1] - self._motor0[0] deltaY = self._motor1[1] - self._motor1[0] self.imageWidget.setImageData(yView, xScale=(self._motor0[0], deltaX), yScale=(self._motor1[0], deltaY)) self.imageWidget.setXLabel(self._motor0Mne) self.imageWidget.setYLabel(self._motor1Mne) self.imageWidget.show()
def _build(self, math=True, replace=False, scanwindow=False): if math: self._buildMath() self.graphWidget = MaskImageWidget.MaskImageWidget( self, colormap=True, standalonesave=True, imageicons=False, profileselection=True, selection=False, scanwindow=scanwindow, aspect=True) self.nameBox = qt.QWidget(self) self.nameBox.mainLayout = qt.QHBoxLayout(self.nameBox) self.nameLabel = qt.QLabel(self.nameBox) self.nameLabel.setText("Image Name = ") #self.nameLabel.setText(qt.QString(qt.QChar(0x3A3))) self.name = qt.QLineEdit(self.nameBox) self.nameBox.mainLayout.addWidget(self.nameLabel) self.nameBox.mainLayout.addWidget(self.name) # The IMAGE selection #self.imageButtonBox = qt.QWidget(self) self.imageButtonBox = self.nameBox buttonBox = self.imageButtonBox #self.imageButtonBoxLayout = qt.QHBoxLayout(buttonBox) self.imageButtonBoxLayout = self.nameBox.mainLayout self.imageButtonBoxLayout.setContentsMargins(0, 0, 0, 0) self.imageButtonBoxLayout.setSpacing(0) self.addImageButton = qt.QPushButton(buttonBox) icon = qt.QIcon(qt.QPixmap(IconDict["rgb16"])) self.addImageButton.setIcon(icon) self.addImageButton.setText("ADD IMAGE") self.removeImageButton = qt.QPushButton(buttonBox) self.removeImageButton.setIcon(icon) self.removeImageButton.setText("REMOVE IMAGE") self.imageButtonBoxLayout.addWidget(self.addImageButton) self.imageButtonBoxLayout.addWidget(self.removeImageButton) if replace: self.replaceImageButton = qt.QPushButton(buttonBox) self.replaceImageButton.setIcon(icon) self.replaceImageButton.setText("REPLACE IMAGE") self.imageButtonBoxLayout.addWidget(self.replaceImageButton) #self.mainLayout.addWidget(self.nameBox) self.mainLayout.addWidget(self.graphWidget) self.mainLayout.addWidget(buttonBox) self.addImageButton.clicked[()].connect(self._addImageClicked) self.removeImageButton.clicked[()].connect(self._removeImageClicked) if replace: self.replaceImageButton.clicked[()].connect( \ self._replaceImageClicked) #it consumes too much CPU, therefore only on click #self.graphWidget.graph.canvas().setMouseTracking(1) self.graphWidget.graphWidget.showInfo() self.graphWidget.graphWidget.graph.sigPlotSignal.connect(\ self._graphSignal)
def _build(self, vertical=False): box = qt.QSplitter(self) if vertical: box.setOrientation(qt.Qt.Vertical) boxmainlayout = qt.QVBoxLayout(box) else: box.setOrientation(qt.Qt.Horizontal) boxmainlayout = qt.QHBoxLayout(box) self.stackWindow = qt.QWidget(box) self.stackWindow.mainLayout = qt.QVBoxLayout(self.stackWindow) self.stackWindow.mainLayout.setContentsMargins(0, 0, 0, 0) self.stackWindow.mainLayout.setSpacing(0) self.stackWidget = MaskImageWidget.MaskImageWidget( self.stackWindow, selection=False, standalonesave=False, imageicons=False, aspect=True) self._stackSaveMenu = qt.QMenu() if HDF5: self._stackSaveMenu.addAction( QString("Save Zoomed Stack Region as Spectra"), self.saveStackAsNeXusSpectra) self._stackSaveMenu.addAction( QString("Save Zoomed Stack Region as Images"), self.saveStackAsNeXusImages) self._stackSaveMenu.addAction( QString("Save Zoomed Stack Region as Compressed Spectra"), self.saveStackAsNeXusCompressedSpectra) self._stackSaveMenu.addAction( QString("Save Zoomed Stack Region as Compressed Images"), self.saveStackAsNeXusCompressedImages) self._stackSaveMenu.addAction( QString("Save Zoomed Stack Region as Float32 Spectra"), self.saveStackAsFloat32NeXusSpectra) self._stackSaveMenu.addAction( QString("Save Zoomed Stack Region as Float64 Spectra"), self.saveStackAsFloat64NeXusSpectra) self._stackSaveMenu.addAction( QString("Save Zoomed Stack Region as Float32 Images"), self.saveStackAsFloat32NeXusImages) self._stackSaveMenu.addAction( QString("Save Zoomed Stack Region as Float64 Images"), self.saveStackAsFloat64NeXusImages) self._stackSaveMenu.addAction( QString("Save Zoomed Stack Region as HDF5 /data"), self.saveStackAsSimplestHDF5) self._stackSaveMenu.addAction( QString("Save Zoomed Stack Region as Monochromatic TIFF Images"), self.saveStackAsMonochromaticTiffImages) self._stackSaveMenu.addAction( QString("Save Zoomed Stack Region as Float32 TIFF Images"), self.saveStackAsFloat32TiffImages) self._stackSaveMenu.addAction( QString("Standard Graphics"), self.stackWidget.graphWidget._saveIconSignal) self.stackWidget.graphWidget.saveToolButton.clicked.connect( \ self._stackSaveToolButtonSignal) self.stackGraphWidget = self.stackWidget.graphWidget self.roiWindow = qt.QWidget(box) self.roiWindow.mainLayout = qt.QVBoxLayout(self.roiWindow) self.roiWindow.mainLayout.setContentsMargins(0, 0, 0, 0) self.roiWindow.mainLayout.setSpacing(0) standaloneSaving = True self.roiWidget = MaskImageWidget.MaskImageWidget( parent=self.roiWindow, rgbwidget=self.rgbWidget, selection=True, colormap=True, imageicons=True, standalonesave=standaloneSaving, profileselection=True, aspect=True) infotext = 'Toggle background subtraction from current image\n' infotext += 'subtracting a straight line between the ROI limits.' self.roiBackgroundIcon = qt.QIcon(qt.QPixmap(IconDict["subtract"])) self.roiBackgroundButton = self.roiWidget.graphWidget._addToolButton(\ self.roiBackgroundIcon, self._roiSubtractBackgroundClicked, infotext, toggle = True, state = False, position = 6) self.roiGraphWidget = self.roiWidget.graphWidget self.stackWindow.mainLayout.addWidget(self.stackWidget) self.roiWindow.mainLayout.addWidget(self.roiWidget) box.addWidget(self.stackWindow) box.addWidget(self.roiWindow) boxmainlayout.addWidget(self.stackWindow) boxmainlayout.addWidget(self.roiWindow) self.mainLayout.addWidget(box) #add some missing icons offset = 6 infotext = 'If checked, spectra will be added normalized to the number\n' infotext += 'of pixels. Be carefull if you are preparing a batch and you\n' infotext += 'fit the normalized spectra because the data in the batch will\n' infotext += 'have a different weight because they are not normalized.' self.normalizeIcon = qt.QIcon(qt.QPixmap(IconDict["normalize16"])) self.normalizeButton = self.stackGraphWidget._addToolButton(\ self.normalizeIcon, self.normalizeIconChecked, infotext, toggle = True, state = False, position = 6) offset += 1 if self.master: self.loadIcon = qt.QIcon(qt.QPixmap(IconDict["fileopen"])) self.loadStackButton = self.stackGraphWidget._addToolButton(\ self.loadIcon, self.loadSlaveStack, 'Load another stack of same shape', position = offset) offset += 1 self.pluginIcon = qt.QIcon(qt.QPixmap(IconDict["plugin"])) infotext = "Call/Load Stack Plugins" self.stackGraphWidget._addToolButton(self.pluginIcon, self._pluginClicked, infotext, toggle=False, state=False, position=offset)
def _convert(self): x, y, legend, info = self.getActiveCurve() self._x = x self._y = y if 'Header' not in info: raise ValueError("Active curve does not seem to be a mesh scan") header = info['Header'][0] item = header.split() if item[2] not in ['mesh', 'hklmesh']: raise ValueError("Active curve does not seem to be a mesh scan") self._xLabel = self.getGraphXLabel() self._yLabel = self.getGraphYLabel() self._motor0Mne = item[3] self._motor1Mne = item[7] #print("Scanned motors are %s and %s" % (motor0Mne, motor1Mne)) #Assume an EXACTLY regular mesh for both motors self._motor0 = numpy.linspace(float(item[4]), float(item[5]), int(item[6]) + 1) self._motor1 = numpy.linspace(float(item[8]), float(item[9]), int(item[10]) + 1) try: if xLabel.upper() == motor0Mne.upper(): self._motor0 = self._x self._motor0Mne = self._xLabel elif xLabel.upper() == motor1Mne.upper(): self._motor1 = self._x self._motor1Mne = self._xLabel elif xLabel == info['selection']['cntlist'][0]: self._motor0 = self._x self._motor0Mne = self._xLabel elif xLabel == info['selection']['cntlist'][1]: self._motor1 = self._x self._motor1Mne = self._xLabel except: if DEBUG: print("XLabel should be one of the scanned motors") self._legend = legend self._info = info y.shape = len(self._motor1), len(self._motor0) if self.imageWidget is None: self.imageWidget = MaskImageWidget.MaskImageWidget(\ imageicons=False, selection=False, profileselection=True, scanwindow=self) self.imageWidget.setImageData(y, xScale=(self._motor0[0], self._motor0[-1]), yScale=(self._motor1[0], self._motor1[-1])) self.imageWidget.setXLabel(self._motor0Mne) self.imageWidget.setYLabel(self._motor1Mne) self.imageWidget.show()
def _convert(self): x, y, legend, info = self.getActiveCurve() self._x = x[:] self._y = y[:] if 'Header' in info: # SPEC command = info['Header'][0] elif "title" in info: command = info["title"] else: raise ValueError("Active curve does not seem to be a mesh scan") if "mesh" not in command: raise ValueError("Active curve does not seem to be a mesh scan") idx = command.index("mesh") item = command[idx:].split() xLabel = self.getGraphXLabel() yLabel = self.getGraphYLabel() m0idx = 1 m1idx = 5 self._motor0Mne = item[m0idx] self._motor1Mne = item[m1idx] #print("Scanned motors are %s and %s" % (self._motor0Mne, self._motor1Mne)) #print("MOTOR 0 ", float(item[m0idx + 1]), # float(item[m0idx + 2]), # int(item[m0idx + 3])) #print("MOTOR 1 ", float(item[m1idx + 1]), # float(item[m1idx + 2]), # int(item[m1idx + 3])) _logger.info("Assuming scans written in terms of number of intervals") plusOne = 1 #Assume an EXACTLY regular mesh for both motors self._motor0 = numpy.linspace(float(item[m0idx + 1]), float(item[m0idx + 2]), int(item[m0idx + 3]) + plusOne) self._motor1 = numpy.linspace(float(item[m1idx + 1]), float(item[m1idx + 2]), int(item[m1idx + 3]) + plusOne) #Didier's contribution: Try to do something if scan has been interrupted if y.size < (int(item[m0idx + 3]) + plusOne) * (int(item[m1idx + 3]) + plusOne): _logger.warning("WARNING: Incomplete mesh scan") self._motor1 = numpy.resize( self._motor1, (y.size // (int(item[m0idx + 3]) + plusOne), 1)) y = numpy.resize(y,((y.size // (int(item[m0idx + 3])+plusOne) * \ (int(item[m0idx + 3])+plusOne)),1)) try: if xLabel.upper() == motor0Mne.upper(): self._motor0 = self._x self._motor0Mne = self._xLabel elif xLabel.upper() == motor1Mne.upper(): self._motor1 = self._x self._motor1Mne = self._xLabel elif xLabel == info['selection']['cntlist'][0]: self._motor0 = self._x self._motor0Mne = self._xLabel elif xLabel == info['selection']['cntlist'][1]: self._motor1 = self._x self._motor1Mne = self._xLabel except: _logger.debug("XLabel should be one of the scanned motors") if "dmesh" in command: # relative positions, we have to provide an offset # the offset should be in the positioners if present offsets = [] if ["MotorNames" in info] and ["MotorValues" in info]: for key in [self._motor0Mne, self._motor1Mne]: if key in info["MotorNames"]: idx = info["MotorNames"].index(key) offsets.append(info["MotorValues"][idx]) if len(offsets) == 2: self._motor0 += offsets[0] self._motor1 += offsets[1] else: _logger.warning("Using relative positions") self._legend = legend self._info = info yView = y[:] yView.shape = len(self._motor1), len(self._motor0) if self.imageWidget is None: self.imageWidget = MaskImageWidget.MaskImageWidget(\ imageicons=False, selection=False, profileselection=True, aspect=True, scanwindow=self) deltaX = self._motor0[1] - self._motor0[0] deltaY = self._motor1[1] - self._motor1[0] self.imageWidget.setImageData(yView, xScale=(self._motor0[0], deltaX), yScale=(self._motor1[0], deltaY)) self.imageWidget.setXLabel(self._motor0Mne) self.imageWidget.setYLabel(self._motor1Mne) self.imageWidget.show()