def _startScan(self): mot1 = self._getHorizontalMotor() mot2 = self._getVerticalMotor() table = self._widgetTree.child('__table') argList = [] for row in range(2): for col in range(1, 4): stringVal = table.text(row, col) value, valid = stringVal.toFloat() if not valid: dialog = qt.QErrorMessage(self) dialog.message('value in mesh must be float') return argList.append(value) argList.insert(0, mot1.getMotorMnemonic()) argList.insert(4, mot2.getMotorMnemonic()) timeWidget = self._widgetTree.child('__time') stringVal = timeWidget.text() value, valid = stringVal.toFloat() if not valid: dialog = qt.QErrorMessage(self) dialog.message('Time must be float') return argList.append(value) self._logArgs = dict( zip(('mot1', 'mot1_start', 'mot1_final', 'mot1_intervals', 'mot2', 'mot2_start', 'mot2_final', 'mot2_intervals', 'scan_time'), argList)) self._logArgs['scan_type'] = 'mesh' try: self._logArgs['scanId'] = self.SCAN_N.getValue() except: pass startButton = self._widgetTree.child('__startScan') startButton.setEnabled(False) stopButton = self._widgetTree.child('__stopScan') stopButton.setEnabled(True) self._SpecCmd(*argList)
def _startScan(self): mot1 = self._getHorizontalMotor() mot2 = self._getVerticalMotor() table = self._widgetTree.child("__table") argList = [] for row in range(2): for col in range(1, 3): stringVal = table.text(row, col) value, valid = stringVal.toFloat() if not valid: dialog = qt.QErrorMessage(self) dialog.message("value must be float") return argList.append(value) argList.insert(0, mot1.getMotorMnemonic()) argList.insert(3, mot2.getMotorMnemonic()) intervals_widget = self._widgetTree.child("__intervals") stringVal = intervals_widget.text() intervals, valid = stringVal.toInt() argList.append(intervals) timeWidget = self._widgetTree.child("__time") stringVal = timeWidget.text() timeVal, valid = stringVal.toFloat() argList.append(timeVal) self._logArgs = dict( zip( ( "mot1", "mot1_start", "mot1_final", "mot2", "mot2_start", "mot2_final", "intervals", "scan_time", ), argList, )) self._logArgs["scan_type"] = "a2scan" try: self._logArgs["scanId"] = self.SCAN_N.getValue() except BaseException: pass self._SpecCmd(*argList) startButton = self._widgetTree.child("__startScan") startButton.setEnabled(False) stopButton = self._widgetTree.child("__stopScan") stopButton.setEnabled(True)
def _startScan(self) : try : self._matchPoints.index(True) # if not point math -> go to exception mot1Widget = self._widgetTree.child('__motor1') mot2Widget = self._widgetTree.child('__motor2') self._ltinit(str(mot1Widget.currentText()),str(mot2Widget.currentText())) except ValueError: dialog = qt.QErrorMessage(self) dialog.message('Nothing to scan') return
def _movetoStart(self): table = self._widgetTree.child('__table') stringVal = table.text(0, 1) mot1StartPos, valid = stringVal.toFloat() if not valid: dialog = qt.QErrorMessage(self) dialog.message('Start must be float') return stringVal = table.text(1, 1) mot2StartPos, valid = stringVal.toFloat() if not valid: dialog = qt.QErrorMessage(self) dialog.message('Start must be float') return mot1 = self._getHorizontalMotor() mot2 = self._getVerticalMotor() mot1.move(mot1StartPos) mot2.move(mot2StartPos) self._moveGraphicInBeam(self._beamx, self._beamy)
def __saveImageTree(self, i): pickleObjects = [] self.__saveImageRecurse(self.__imageList.firstChild(), pickleObjects) if pickleObjects: fullpathname = qt.QFileDialog.getSaveFileName( self.__saveImageTreeDirName, 'Camera mosaic (*.mosaic)', self, 'Save mosaic images', "Choose a filename to save under") if fullpathname: fullpathname = fullpathname.latin1() self.__saveImageTreeDirName, fname = os.path.split( fullpathname) filename, ext = os.path.splitext(fname) fullpathname = os.path.join(self.__saveImageTreeDirName, '%s.mosaic' % filename) pickle.dump(pickleObjects, file(fullpathname, 'w')) else: errorMess = qt.QErrorMessage(self) errorMess.message('Nothing to Save!!!')
def _valueChangedScanParam(self, row, column): if column == 0: self._updateGUI() elif column == 1 or column == 2: # resize rectangle if self.__rect is not None: meshTable = self._widgetTree.child('__table') stringVal = meshTable.text(row, column) pos, valid = stringVal.toFloat() if valid: # distance stringVal = meshTable.text(row, (column % 2) + 1) otherpos, valid = stringVal.toFloat() if valid: meshTable.setText( row, 5, self._formatString % abs(otherpos - pos)) if row == 0: hmotor = self._getHorizontalMotor() pos -= hmotor.getPosition() pix = (pos / self._XSize * hmotor.getProperty('unit')) + self._beamx if column == 1: self.__rect.setLeft(pix) else: self.__rect.setRight(pix) else: vmotor = self._getVerticalMotor() pos -= vmotor.getPosition() pix = (pos / self._YSize * vmotor.getProperty('unit')) + self._beamy if column == 1: self.__rect.setTop(pix) else: self.__rect.setBottom(pix) self._graphicSelection.setRect(self.__rect.x(), self.__rect.y(), self.__rect.width(), self.__rect.height()) else: dialog = qt.QErrorMessage(self) dialog.message('Motors position must be float') elif column == 3: # interval self.__fillOneRow(row) elif column == 4: self.__fillOneRow(row, True)
def __intervalsChanged(self): intervals_widget = self._widgetTree.child('__intervals') intervals, valid = intervals_widget.text().toInt() try: aTable = self._widgetTree.child('__table') ####### step calc ####### for row in range(2): (start, v1), (stop, v2) = [ aTable.text(row, column).toFloat() for column in range(1, 3) ] if v1 and v2: aTable.setText( row, 3, self._formatString % ((stop - start) / float(intervals))) else: dialog = qt.QErrorMessage(self) dialog.message('Start and stop must be float') return except: import traceback traceback.print_exc()
def _valueChangedScanParam(self, row, column): if row != 2: if column == 0: self._updateGUI() elif column == 1 or column == 2: # point has moved aTable = self._widgetTree.child('__table') stringVal = aTable.text(row, column) pos, valid = stringVal.toFloat() if valid: #distance stringVal = aTable.text(row, (column % 2) + 1) otherpos, valid = stringVal.toFloat() if valid: aTable.setText( row, 4, self._formatString % abs(otherpos - pos)) if row == 0: hmotor = self._getHorizontalMotor() pos -= hmotor.getPosition() pix = (pos / self._XSize * hmotor.getProperty('unit')) + self._beamx if column == 1: self.__points[0] = pix else: self.__points[2] = pix else: vmotor = self._getVerticalMotor() pos -= vmotor.getPosition() pix = (pos / self._YSize * vmotor.getProperty('unit')) + self._beamy if column == 1: self.__points[1] = pix else: self.__points[3] = pix self._graphicSelection.setPoints(*self.__points) else: dialog = qt.QErrorMessage(self) dialog.message('Motors position must be float') elif column == 3: aTable = self._widgetTree.child('__table') (start, v1), (stop, v2) = [ aTable.text(row, column).toFloat() for column in range(1, 3) ] if v1 and v2: stringVal = aTable.text(row, 3) val, okFlag = stringVal.toFloat() if okFlag: intervals = math.ceil((stop - start) / val) intervals_widget = self._widgetTree.child( '__intervals') intervals_widget.setText('%d' % int(abs(intervals))) stop = start + intervals * val aTable.setText(row, 2, self._formatString % stop) self._valueChangedScanParam(row, 2) # update self.__intervalsChanged() # update else: if column == 3: aTable = self._widgetTree.child('__table') angle, v1 = aTable.text(2, 0).toFloat() step, v2 = aTable.text(2, column).toFloat() if v1 and v2: angle = angle * math.pi / 180 hstep = step * math.cos(angle) aTable.setText(0, column, self._formatString % hstep) vstep = step * math.sin(angle) aTable.setText(1, column, self._formatString % vstep) (startMot1, v1), (stopMot1, v2) = [ aTable.text(0, column).toFloat() for column in range(1, 3) ] (startMot2, v1), (stopMot2, v2) = [ aTable.text(1, column).toFloat() for column in range(1, 3) ] distance = math.sqrt((stopMot1 - startMot1)**2 + (stopMot2 - startMot2)**2) interval = int(math.ceil(distance / step)) corr = (interval * step) / distance stopMot1 = startMot1 + corr * (stopMot1 - startMot1) stopMot2 = startMot2 + corr * (stopMot2 - startMot2) aTable.setText(0, 2, self._formatString % stopMot1) aTable.setText(1, 2, self._formatString % stopMot2) intervals_widget = self._widgetTree.child('__intervals') intervals_widget.setText('%d' % int(abs(interval))) for row in range(2): for column in range(1, 3): self._valueChangedScanParam(row, column)
def __ltinitFinished(self, *args): table = self._widgetTree.child('__gridTable') stringVal = table.text(0, 0) nbColumn, valid = stringVal.toInt() if not valid: dialog = qt.QErrorMessage(self) dialog.message('Interval must be integer') return nbColumn += 1 self._logArgs['scan_type'] = 'lookup' posMot1 = [] posMot2 = [] pointMatchNb = 0 matchPointId = [] for i, (match, point) in enumerate( itertools.izip(self._matchPoints, self.__gridPoints)): if match: posMot1.append(point[0, 0]) posMot2.append(point[0, 1]) matchPointId.append((i / nbColumn, pointMatchNb)) pointMatchNb += 1 if posMot1: mot1Widget = self._widgetTree.child('__motor1') mot2Widget = self._widgetTree.child('__motor2') timeWidget = self._widgetTree.child('__time') ctime, valid = timeWidget.text().toFloat() mot1 = self.__getMotor(mot1Widget.currentText(), self._horizontalMotors) mot2 = self.__getMotor(mot2Widget.currentText(), self._verticalMotors) posMot1 = numpy.array(posMot1) posMot1 -= self._beamx posMot1 *= (self._XSize / mot1.getProperty('unit')) posMot1 += mot1.getPosition() posMot2 = numpy.array(posMot2) posMot2 -= self._beamy posMot2 *= (self._YSize / mot2.getProperty('unit')) posMot2 += mot2.getPosition() lineStartStop = [] lastLineId = -1 currentPointInLine = [] for lineId, pointId in matchPointId: if lineId != lastLineId: if currentPointInLine: lineStartStop.append(currentPointInLine) currentPointInLine = [pointId] lastLineId = lineId else: currentPointInLine.append(pointId) if currentPointInLine: lineStartStop.append(currentPointInLine) startIndex = [] stopIndex = [] for line in lineStartStop: startIndex.append(line[0]) stopIndex.append(line[-1]) startIndex = numpy.array(startIndex) stopIndex = numpy.array(stopIndex) specVersion = self._ltinit.specVersion for motor_name, pos_motor in zip( [str(mot1Widget.currentText()), str(mot2Widget.currentText())], [posMot1, posMot2]): ho = self.getHardwareObject(self["command"]) MOTOR_ARRAY = ho.addChannel( { "type": "spec", "version": specVersion, "name": "MOTOR_ARRAY", "dispatchMode": None }, "%s_ltscan_arr" % motor_name) MOTOR_ARRAY.setValue(SpecArray.SpecArray(pos_motor.ravel())) LT_START = SpecVariable.SpecVariable('LT_START', specVersion) LT_START.setValue(SpecArray.SpecArray(startIndex)) LT_STOP = SpecVariable.SpecVariable('LT_STOP', specVersion) LT_STOP.setValue(SpecArray.SpecArray(stopIndex)) LT_LINE = SpecVariable.SpecVariable('LT_LINE', specVersion) LT_LINE.setValue(len(stopIndex)) self._SpecCmd(str(mot1Widget.currentText()), str(mot2Widget.currentText()), ctime)
def _valueChangedScanParam(self, row, column): table = self._widgetTree.child('__gridTable') if column == 0: stringVal = table.text(row, column) val, okFlag = stringVal.toInt() if okFlag: if row == 0: self._graphicSelection.setNbPointAxis1(val) else: self._graphicSelection.setNbPointAxis2(val) self.__refreshSteps() self.__createGridPoints() else: dialog = qt.QErrorMessage(self) dialog.message('Interval must be integer') elif column == 1: stringVal = table.text(row, column) step, ok1 = stringVal.toFloat() stringVal = table.text(row, 0) interval, ok2 = stringVal.toInt() if ok1 and step > 0.: if ok2: distance = interval * step table.setText(row, 2, self._formatString % distance) self._valueChangedScanParam(row, 2) else: dialog = qt.QErrorMessage(self) dialog.message('Step must be a positif float') elif column == 2: self.__refreshSteps() # UPDATE GRAPHIC points = self._graphicSelection.points() if len(points) == 3: angle = self._graphicSelection.angle()[0] * math.pi / 180 pixelSize = math.sqrt((self._XSize * math.cos(angle)) ** 2 + \ (self._YSize * math.sin(angle)) ** 2) if row == 0: stringVal = table.text(0, 2) dist1, ok1 = stringVal.toFloat() dist1 /= self.__offsetMeasure width = dist1 / pixelSize height = math.sqrt(((points[1][0] - points[2][0])) ** 2 + \ ((points[1][1] - points[2][1])) ** 2) else: width = math.sqrt(((points[0][0] - points[1][0])) ** 2 + \ ((points[0][1] - points[1][1])) ** 2) stringVal = table.text(1, 2) dist2, ok2 = stringVal.toFloat() dist2 /= self.__offsetMeasure height = dist2 / pixelSize xori, yori = points[0] p = numpy.array([[xori, yori], [xori + width, yori], [xori + width, yori + height]]) translation = numpy.matrix([xori, yori]) rotation = numpy.matrix( [[numpy.cos(-angle), -numpy.sin(-angle)], [numpy.sin(-angle), numpy.cos(-angle)]]) p -= translation p = p * rotation p += translation self._graphicSelection.setPoints(p.tolist())
def _startScan(self): self._scanFinished() try: self._matchPoints.index( True) # if not point math -> go to exception except ValueError: dialog = qt.QErrorMessage(self) dialog.message('Nothing to scan') return table = self._widgetTree.child('__gridTable') stringVal = table.text(0, 0) nbColumn, valid = stringVal.toInt() if not valid: dialog = qt.QErrorMessage(self) dialog.message('Interval must be integer') return nbColumn += 1 posMot1 = [] posMot2 = [] pointMatchNb = 0 matchPointId = [] for i, (match, point) in enumerate(zip(self._matchPoints, self.__gridPoints)): if match: posMot1.append(point[0, 0]) posMot2.append(point[0, 1]) matchPointId.append((i / nbColumn, pointMatchNb)) pointMatchNb += 1 if posMot1: timeWidget = self._widgetTree.child('__time') ctime, valid = timeWidget.text().toFloat() if not valid: dialog = qt.QErrorMessage(self) dialog.message('Time must be float') return mot1 = self._horizontalMotors[0] mot2 = self._verticalMotors[0] posMot1 = numpy.array(posMot1) posMot1 -= self._beamx posMot1 *= (self._XSize / mot1.getProperty('unit')) posMot1 += mot1.getPosition() posMot2 = numpy.array(posMot2) posMot2 -= self._beamy posMot2 *= (self._YSize / mot2.getProperty('unit')) posMot2 += mot2.getPosition() lineStartStop = [] lastLineId = -1 currentPointInLine = [] for lineId, pointId in matchPointId: if lineId != lastLineId: if currentPointInLine: lineStartStop.append(currentPointInLine) currentPointInLine = [pointId] lastLineId = lineId else: currentPointInLine.append(pointId) if currentPointInLine: lineStartStop.append(currentPointInLine) startIndex = [] stopIndex = [] for line in lineStartStop: startIndex.append(line[0]) stopIndex.append(line[-1]) startIndex = numpy.array(startIndex) stopIndex = numpy.array(stopIndex) self.emit(qt.PYSIGNAL("clearQueue"), (0, )) #clear entire queue params = {} self.emit(qt.PYSIGNAL("dataCollectParametersRequest"), (params, )) # determine points and add to queue collectList = [] params["exposure_time"] = str(ctime) params["directory"] = os.path.join(params["directory"], "mesh") params["osc_range"] = "0.5" params["number_images"] = "1" params["osc_start"] = params["current_osc_start"] motor1_name = mot1.getMotorMnemonic() motor2_name = mot2.getMotorMnemonic() i = 1 for pos1, pos2 in zip(posMot1, posMot2): oscillation_parameters = { "motors": { mot1: float(pos1), mot2: float(pos2) } } oscillation_parameters.update(params) oscillation_parameters["run_number"] = i i += 1 oscillation_parameters["comments"] = "%s: %f, %s: %f" % ( motor1_name, pos1, motor2_name, pos2) self.emit(qt.PYSIGNAL("addToQueue"), ([oscillation_parameters], )) self.emit(qt.PYSIGNAL("goToCollect"), ())