def updateKnots(self): min = self.plot.knots[0].getPosition() max = self.plot.knots[-1].getPosition() kmin = calc.toKSpace(min, self.E0) kmax = calc.toKSpace(max, self.E0) self.plot.resetPlot() size = self.spinBoxes.spinBox1.value() div = (kmax - kmin) / (size - 1) self.plot.addKnot(min) self.plot.addBoundsExceptions(0, 0, self.E0) for i in range(1, size - 1): temp = calc.fromKSpace(kmin + i * div, self.E0) temp2 = calc.getClosest(temp, self.xdata) self.plot.addKnot(temp2) self.plot.addKnot(max) # self.normCurve=self.plot.insertCurve("norm") self.plot.setCurvePen(self.normCurve, QPen(QColor(Qt.black), 2)) # self.splineCurve=self.plot.insertCurve("spline") self.plot.setCurvePen(self.splineCurve, QPen(QColor(Qt.darkGreen), 2)) self.updatePlot()
def getSegs(self): knots = self.plot.knots segs = [] orders = self.getOrders() for i in range(len(knots) - 1): # get position from knots temp = knots[i].getPosition() xlow = calc.getClosest(temp, self.xdata) temp = knots[i + 1].getPosition() xhigh = calc.getClosest(temp, self.xdata) # generate segments (order, xlow, xhigh) and arrays seg = (orders[i].value() + 1, xlow, xhigh) segs.append(seg) return segs
def updatePlot(self,*args): # def calcBackground(self,xmin,xmax): order=self.getSpinBoxValue()+1 #need constant! temp=self.plot.knots[0].getPosition() xmin=calc.getClosest(temp,self.xdata) lindex=self.xdata.index(xmin) temp=self.plot.knots[1].getPosition() xmax=calc.getClosest(temp,self.xdata) hindex=self.xdata.index(xmax) self.background=calc.calcBackground(self.xdata,self.ydata,lindex,hindex,order,self.E0) self.plot.setCurveData(self.backCurve,self.xdata,self.background) ymax=max([max(self.ydata),max(self.background)]) ymin=min([min(self.ydata),min(self.background)]) self.plot.setAxisScale(QwtPlot.yLeft,ymin,ymax) self.plot.replot() self.emit(PYSIGNAL('signalPlotChanged'),())
def slotMouseReleased(self,event): self.mode='NONE' xpos=self.invTransform(QwtPlot.xBottom,event.x()) temp="x: %.3f" % self.newx+", y: %.3f" %self.newy if(len(self.knots)>0): temp+="; [ " for knot in self.knots[:-1]: #tempnum=knot.getPosition() tempnum=calc.getClosest(knot.getPosition(),self.data) knot.setPosition(tempnum) temp+="%.3f, "%(tempnum,) #temp+=str(self.knots[-1].getPosition()) tempnum=calc.getClosest(self.knots[-1].getPosition(),self.data) self.knots[-1].setPosition(tempnum) temp+="%.3f ]"%(tempnum,) status=QString(temp) self.emit(PYSIGNAL('positionMessage()'),(status,)) self.emit(PYSIGNAL('signalUpdate'),()) self.replot()
def setupNormPlot(self,xdata,markers,orders): #make sure scale of plot is reasonable self.norm.plot.setAxisScale(QwtPlot.xBottom,xdata[0],xdata[-1]) #adjust markers to closest data positions for i in range(len(markers)): temp=calc.getClosest(markers[i],xdata) self.norm.plot.addKnot(temp) self.norm.plot.addBoundsExceptions(0,0,self.E0) #set number of knots in normplot window self.norm.setNumKnots(len(markers)) self.norm.setOrders(orders) self.norm.initializeSlots()
def editParameters(self): edgeDialog=EdgeDialog() edgeDialog.slotCheckBoxToggled(True) edgeDialog.checkBox1.setChecked(True) edgeDialog.setTitle(self.title) edgeDialog.setValue(self.E0) result=edgeDialog.exec_loop() if(result==QDialog.Rejected): return self.E0=edgeDialog.getValue() self.title=edgeDialog.getTitle() xdata=self.raw.xdata #check to see if E0 is reasonable!! while((self.E0 < xdata[0]) or (self.E0 > xdata[-1])): #for some reason, in windows, the str version used wasn't the #builtin version to convert between numbers and strings errstr="There appears to be a problem with E0="+__builtins__.str(self.E0)+". This value does not fall in the range of your data." QMessageBox.critical(self,QString("Error with E0"),QString(errstr)) result=edgeDialog.exec_loop() if(result==QDialog.Rejected): return self.E0=edgeDialog.getValue() self.title=edgeDialog.getTitle() self.norm.plot.addBoundsExceptions(0,0,self.E0) pos=calc.getClosest(self.E0,xdata) self.norm.plot.knots[0].setPosition(pos) kmax=calc.toKSpace(xdata[-1],self.E0) kmin=calc.toKSpace(pos,self.E0) self.kspace.plot.resetPlot() self.setupXAFSPlot(kmax,kmin,kmax) #self.kdata,self.k0index=self.calcKSpace(self.xdata) self.updateNormPlot()
def fileStringOpen(self,str): if str == None: return self.filename=str file=open(str) #check to see if it has a title line=file.readline() if(line[:5]=='TITLE'): self.title=line[6:-1] line=file.readline() #check to see if line is a comment while(line[0]=='#'): self.comments.append(line[2:-1]) line=file.readline() #read E0 array=string.split(line) self.E0=float(array[1]) #read background bounds and order #BACKGROUND lowx (order) highx line=file.readline() array=string.split(line) rawlowx = float(array[1]) rawhighx = float(array[3]) raworder = int(array[2][1:-1]) #read spline info into makers and orders lists #SPLINE marker (order) marker (order) marker ..... line=file.readline() array=string.split(line) markers=[] orders=[] for i in range(1,len(array)-2,2): markers.append(float(array[i])) orders.append(int(array[i+1][1])) markers.append(float(array[-2])) #check to see if k-window is specified #if not, column header is stripped line=file.readline() array=string.split(line) if(array[0]=='KWIN'): window=(float(array[1]),float(array[2])) line=file.readline() #file stream is now data, read it arrs=self.readArray(file) file.close() #arrs looks like: #[ [col1 col2 col3 col4] # [col1 col2 col3 col4] # .... # ]] #transpose to get columns in useful format data=transpose(arrs) xdata=data[0].tolist() i0data=data[2].tolist() ydata=data[3].tolist() self.resetPlots() rawlowx=calc.getClosest(rawlowx,xdata) rawhighx=calc.getClosest(rawhighx,xdata) self.setupRawPlot(xdata,ydata,rawlowx,rawhighx,raworder) self.setupNormPlot(xdata,markers,orders) self.i0.setI0Data(xdata,i0data) kmax=calc.toKSpace(xdata[-1],self.E0) self.setupXAFSPlot(kmax,window[0],window[1]) self.raw.updatePlot()