Example #1
0
def getPeakList(data, qData, initialGuess, numberOfChi, stddev, verbose=1):

    if numberOfChi <= 1:
        raise Exception("This program must look for at least 2 chi slices.")
    chiUpper = 360.0
    chiLower = 0.11
    # the -1 allows for us to include chiLower & chiUpper in our count
    chiStep = (chiUpper - chiLower) * 1.0 / (numberOfChi - 1)

    peakList = PeakList.PeakList()

    for Q, dQ in qData.getAllQPairs():

        for chi in frange(chiLower, chiUpper, chiStep):
            try:
                x, y, qFit, width = FitWrap.getPeak(
                    data, stddev,
                    initialGuess.getCenterX()['val'],
                    initialGuess.getCenterY()['val'],
                    initialGuess.getDistance()['val'],
                    initialGuess.getEnergy()['val'],
                    initialGuess.getAlpha()['val'],
                    initialGuess.getBeta()['val'],
                    initialGuess.getRotation()['val'], Q - dQ, Q + dQ, chi,
                    initialGuess.getPixelLength()['val'],
                    initialGuess.getPixelHeight()['val'])

                peakList.addPeak(x, y, Q, qFit, chi, width)

            except ValueError:  # this means no peak found
                pass

    return peakList
def findPeaks(data,qData,initialGuess,numberOfChi,stddev,verbose=1):

    if numberOfChi <=1:
        raise Exception("This program must look for at least 2 chi slices.")
    chiUpper = 360.0
    chiLower = 0.11
    # the -1 allows for us to include chiLower & chiUpper in our count
    chiStep = (chiUpper-chiLower)*1.0/(numberOfChi-1)

    peakList = []

    if verbose: print ' - %d total Q values. Calculating peaks for Q =' % (len(qData.getAllQPairs())),
    for Q,dQ in qData.getAllQPairs():
        if verbose: print ' %f' % Q,

        for chi in frange(chiLower,chiUpper,chiStep):
            try:
                x,y,qFit,width=FitWrap.getPeak(data,stddev,initialGuess.getCenterX()['val'],
                        initialGuess.getCenterY()['val'],initialGuess.getDistance()['val'],
                        initialGuess.getEnergy()['val'],initialGuess.getAlpha()['val'],
                        initialGuess.getBeta()['val'],initialGuess.getRotation()['val'],Q-dQ,Q+dQ,chi,
                        initialGuess.getPixelLength()['val'],initialGuess.getPixelHeight()['val'])

                peakList.append([x,y,Q,qFit,chi,width])

            except ValueError: # this means no peak found
                pass

    print 
    return peakList
    def makeVerticleAxis(self):
        for id in self.allIDs:
            self.axis.delete(id)

        if self.lowestValue == None or self.highestValue == None:
            return

        lowestValueToDisplay,highestValueToDisplay,stepSizeToDisplay=\
                self.getNiceRange(self.lowestValue,self.highestValue)

        if self.side == "left":
            self.allIDs.append(self.axis.create_line(
                    self.width-1,0,self.width-1,self.height) )
        else:
            self.allIDs.append(self.axis.create_line(0,0,0,self.height) )
        for currentValueToDisplay in frange(lowestValueToDisplay,
                highestValueToDisplay+stepSizeToDisplay/100,stepSizeToDisplay):

            if self.logscale:
                # if log scale, then currentValueToDisplay is given 
                # as the log of it,
                canvasValue=(currentValueToDisplay-log10(self.lowestValue))/\
                        (log10(self.highestValue)-\
                        log10(self.lowestValue))*(self.height-1)
                currentValueToDisplay = pow(10,currentValueToDisplay)

                self.addVerticleLine(canvasValue,currentValueToDisplay)

                for loop in range(2,10):
                    # minor tic marks, don't add numbers!
                    # going into loop, remember that current val is now
                    # the acutal value to display
                    logMinorValue = log10(loop*currentValueToDisplay)

                    canvasValue=(logMinorValue-log10(self.lowestValue))/\
                            (log10(self.highestValue)-\
                            log10(self.lowestValue))*(self.height-1)

                    self.addVerticleLine(canvasValue)

            else:
                # otherwise, calculate the canvasValue regularly
                canvasValue = (currentValueToDisplay-self.lowestValue)/\
                        (self.highestValue-self.lowestValue)*(self.height-1)

                self.addVerticleLine(canvasValue,currentValueToDisplay)
                        



        if self.title != None:
            if self.side == "left":
                self.allIDs.append(self.axis.create_text(
                        0,self.height/2.0,fill="black",
                        anchor="w",text=self.title))
            else:
                self.allIDs.append(self.axis.create_text(
                        self.width,self.height/2.0,
                        fill="black",anchor="e",text=self.title))
Example #4
0
def addConstantQLineDiffractionImage(image, Q, calibrationData, color):
    draw = ImageDraw.Draw(image)

    polygon = []
    for chi in frange(0, 360, 3):
        x, y = Transform.getXY(calibrationData, Q, chi)
        polygon += [x, y]

    draw.polygon(polygon, outline=color)
def addConstantQLineDiffractionImage(image,Q,calibrationData,color):
    draw = ImageDraw.Draw(image)

    polygon = []
    for chi in frange(0,360,3):
        x,y = Transform.getXY(calibrationData,Q,chi)
        polygon += [x,y]

    draw.polygon(polygon, outline=color)
    def makeVerticleAxis(self):
        for id in self.allIDs:
            self.axis.delete(id)

        if self.lowestValue == None or self.highestValue == None:
            return

        lowestValueToDisplay,highestValueToDisplay,stepSizeToDisplay=self.getNiceRange(self.lowestValue,self.highestValue)

        if self.side == "left":
            self.allIDs.append( self.axis.create_line(self.width-1,0,self.width-1,self.height) )
        else:
            self.allIDs.append( self.axis.create_line(0,0,0,self.height) )
        for currentValueToDisplay in frange(lowestValueToDisplay,highestValueToDisplay+stepSizeToDisplay/100,stepSizeToDisplay):

            if self.logscale:
                # if log scale, then currentValueToDisplay is given as the log of it,
                canvasValue = (currentValueToDisplay-log10(self.lowestValue))/(log10(self.highestValue)-
                        log10(self.lowestValue))*(self.height-1)
                currentValueToDisplay = pow(10,currentValueToDisplay)
            else:
                # otherwise, calculate the canvasValue regularly
                canvasValue = (currentValueToDisplay-self.lowestValue)/(self.highestValue-self.lowestValue)*(self.height-1)

            if self.flip:
                # possibly flip the numbers
                canvasValue = self.height-1 - canvasValue

            # don't display numbers too close to the edge
            if canvasValue < 10 or canvasValue > (self.height-1) - 10: continue

            #if canvasValue < 2: canvasValue = 2 # tk bug 

            if self.side == "left": 
                self.allIDs.append( self.axis.create_line(self.width*5.0/6.0,canvasValue,self.width,canvasValue) )
            else: 
                self.allIDs.append( self.axis.create_line(0,canvasValue,self.width/6.0,canvasValue) )

            if self.side == "left":
                anchor = 'e'
                self.allIDs.append( self.axis.create_text(self.width*(3.0/4),
                        canvasValue,fill="black",anchor=anchor,text="%g" % currentValueToDisplay) )
            else:
                anchor = 'w'
                self.allIDs.append( self.axis.create_text(self.width*(1.0/4),
                        canvasValue,fill="black",anchor=anchor,text="%g" % currentValueToDisplay) )
            
            if self.title != None:
                if self.side == "left":
                    self.allIDs.append(self.axis.create_text(0,self.height/2.0,fill="black",anchor="w",text=self.title))
                else:
                    self.allIDs.append(self.axis.create_text(self.width,self.height/2.0,fill="black",anchor="e",text=self.title))
    def makeHorizontalAxis(self):
        for id in self.allIDs:
            self.axis.delete(id)

        if self.lowestValue == None or self.highestValue == None:
            return

        lowestValueToDisplay,highestValueToDisplay,stepSizeToDisplay=self.getNiceRange(self.lowestValue,self.highestValue)

        if self.side == "bottom":
            self.allIDs.append( self.axis.create_line(0,1,self.width,1) )
        else:
            self.allIDs.append( self.axis.create_line(0,self.height,self.width,self.height) )

        for currentValueToDisplay in frange(lowestValueToDisplay,highestValueToDisplay+stepSizeToDisplay/100,stepSizeToDisplay):

            canvasValue = (currentValueToDisplay-self.lowestValue)/(self.highestValue-self.lowestValue)*(self.width-1)
            if self.flip:
                # possibly flip the numbers
                canvasValue = self.width-1 - canvasValue

            # don't display numbers too close to the edge
            if canvasValue < 10 or canvasValue > (self.width-1) - 10: continue

            #if canvasValue < 2: canvasValue = 2 # tk bug 

            if self.side == "bottom": 
                self.allIDs.append( self.axis.create_line(canvasValue,0,canvasValue,self.height/6.0) )
            else: 
                self.allIDs.append( self.axis.create_line(canvasValue,self.height,canvasValue,self.height*5.0/6.0) )

            anchor = 'c'

            if self.side == "bottom":
                self.allIDs.append(self.axis.create_text(canvasValue,self.height*1.0/3,fill="black",anchor=anchor,text="%g" % currentValueToDisplay))
            else:
                self.allIDs.append(self.axis.create_text(canvasValue,self.height*2.0/3,fill="black",anchor=anchor,text="%g" % currentValueToDisplay))
            
        if self.title != None:
            if self.side == "bottom":
                self.allIDs.append(self.axis.create_text((self.width-1.0)/2.0,self.height*2.0/3.0,fill="black",anchor="c",text=self.title))
            else:
                self.allIDs.append(self.axis.create_text((self.width-1.0)/2.0,self.height*1.0/3.0,fill="black",anchor="c",text=self.title))
Example #8
0
    def makeVerticleAxis(self):
        for id in self.allIDs:
            self.axis.delete(id)

        if self.lowestValue == None or self.highestValue == None:
            return

        lowestValueToDisplay, highestValueToDisplay, stepSizeToDisplay = self.getNiceRange(
            self.lowestValue, self.highestValue)

        if self.side == "left":
            self.allIDs.append(
                self.axis.create_line(self.width - 1, 0, self.width - 1,
                                      self.height))
        else:
            self.allIDs.append(self.axis.create_line(0, 0, 0, self.height))
        for currentValueToDisplay in frange(
                lowestValueToDisplay,
                highestValueToDisplay + stepSizeToDisplay / 100,
                stepSizeToDisplay):

            if self.logscale:
                # if log scale, then currentValueToDisplay is given as the log of it,
                canvasValue = (currentValueToDisplay - log10(
                    self.lowestValue)) / (log10(self.highestValue) - log10(
                        self.lowestValue)) * (self.height - 1)
                currentValueToDisplay = pow(10, currentValueToDisplay)
            else:
                # otherwise, calculate the canvasValue regularly
                canvasValue = (currentValueToDisplay - self.lowestValue) / (
                    self.highestValue - self.lowestValue) * (self.height - 1)

            if self.flip:
                # possibly flip the numbers
                canvasValue = self.height - 1 - canvasValue

            # don't display numbers too close to the edge
            if canvasValue < 10 or canvasValue > (self.height - 1) - 10:
                continue

            #if canvasValue < 2: canvasValue = 2 # tk bug

            if self.side == "left":
                self.allIDs.append(
                    self.axis.create_line(self.width * 5.0 / 6.0, canvasValue,
                                          self.width, canvasValue))
            else:
                self.allIDs.append(
                    self.axis.create_line(0, canvasValue, self.width / 6.0,
                                          canvasValue))

            if self.side == "left":
                anchor = 'e'
                self.allIDs.append(
                    self.axis.create_text(self.width * (3.0 / 4),
                                          canvasValue,
                                          fill="black",
                                          anchor=anchor,
                                          text="%g" % currentValueToDisplay))
            else:
                anchor = 'w'
                self.allIDs.append(
                    self.axis.create_text(self.width * (1.0 / 4),
                                          canvasValue,
                                          fill="black",
                                          anchor=anchor,
                                          text="%g" % currentValueToDisplay))

            if self.title != None:
                if self.side == "left":
                    self.allIDs.append(
                        self.axis.create_text(0,
                                              self.height / 2.0,
                                              fill="black",
                                              anchor="w",
                                              text=self.title))
                else:
                    self.allIDs.append(
                        self.axis.create_text(self.width,
                                              self.height / 2.0,
                                              fill="black",
                                              anchor="e",
                                              text=self.title))
Example #9
0
    def makeHorizontalAxis(self):
        for id in self.allIDs:
            self.axis.delete(id)

        if self.lowestValue == None or self.highestValue == None:
            return

        lowestValueToDisplay, highestValueToDisplay, stepSizeToDisplay = self.getNiceRange(
            self.lowestValue, self.highestValue)

        if self.side == "bottom":
            self.allIDs.append(self.axis.create_line(0, 1, self.width, 1))
        else:
            self.allIDs.append(
                self.axis.create_line(0, self.height, self.width, self.height))

        for currentValueToDisplay in frange(
                lowestValueToDisplay,
                highestValueToDisplay + stepSizeToDisplay / 100,
                stepSizeToDisplay):

            canvasValue = (currentValueToDisplay - self.lowestValue) / (
                self.highestValue - self.lowestValue) * (self.width - 1)
            if self.flip:
                # possibly flip the numbers
                canvasValue = self.width - 1 - canvasValue

            # don't display numbers too close to the edge
            if canvasValue < 10 or canvasValue > (self.width - 1) - 10:
                continue

            #if canvasValue < 2: canvasValue = 2 # tk bug

            if self.side == "bottom":
                self.allIDs.append(
                    self.axis.create_line(canvasValue, 0, canvasValue,
                                          self.height / 6.0))
            else:
                self.allIDs.append(
                    self.axis.create_line(canvasValue, self.height,
                                          canvasValue,
                                          self.height * 5.0 / 6.0))

            anchor = 'c'

            if self.side == "bottom":
                self.allIDs.append(
                    self.axis.create_text(canvasValue,
                                          self.height * 1.0 / 3,
                                          fill="black",
                                          anchor=anchor,
                                          text="%g" % currentValueToDisplay))
            else:
                self.allIDs.append(
                    self.axis.create_text(canvasValue,
                                          self.height * 2.0 / 3,
                                          fill="black",
                                          anchor=anchor,
                                          text="%g" % currentValueToDisplay))

        if self.title != None:
            if self.side == "bottom":
                self.allIDs.append(
                    self.axis.create_text((self.width - 1.0) / 2.0,
                                          self.height * 2.0 / 3.0,
                                          fill="black",
                                          anchor="c",
                                          text=self.title))
            else:
                self.allIDs.append(
                    self.axis.create_text((self.width - 1.0) / 2.0,
                                          self.height * 1.0 / 3.0,
                                          fill="black",
                                          anchor="c",
                                          text=self.title))
Example #10
0
    def makeVerticleAxis(self):
        for id in self.allIDs:
            self.axis.delete(id)

        if self.lowestValue == None or self.highestValue == None:
            return

        lowestValueToDisplay,highestValueToDisplay,stepSizeToDisplay=\
                self.getNiceRange(self.lowestValue,self.highestValue)

        if self.side == "left":
            self.allIDs.append(
                self.axis.create_line(self.width - 1, 0, self.width - 1,
                                      self.height))
        else:
            self.allIDs.append(self.axis.create_line(0, 0, 0, self.height))
        for currentValueToDisplay in frange(
                lowestValueToDisplay,
                highestValueToDisplay + stepSizeToDisplay / 100,
                stepSizeToDisplay):

            if self.logscale:
                # if log scale, then currentValueToDisplay is given
                # as the log of it,
                canvasValue=(currentValueToDisplay-log10(self.lowestValue))/\
                        (log10(self.highestValue)-\
                        log10(self.lowestValue))*(self.height-1)
                currentValueToDisplay = pow(10, currentValueToDisplay)

                self.addVerticleLine(canvasValue, currentValueToDisplay)

                for loop in range(2, 10):
                    # minor tic marks, don't add numbers!
                    # going into loop, remember that current val is now
                    # the acutal value to display
                    logMinorValue = log10(loop * currentValueToDisplay)

                    canvasValue=(logMinorValue-log10(self.lowestValue))/\
                            (log10(self.highestValue)-\
                            log10(self.lowestValue))*(self.height-1)

                    self.addVerticleLine(canvasValue)

            else:
                # otherwise, calculate the canvasValue regularly
                canvasValue = (currentValueToDisplay-self.lowestValue)/\
                        (self.highestValue-self.lowestValue)*(self.height-1)

                self.addVerticleLine(canvasValue, currentValueToDisplay)

        if self.title != None:
            if self.side == "left":
                self.allIDs.append(
                    self.axis.create_text(0,
                                          self.height / 2.0,
                                          fill="black",
                                          anchor="w",
                                          text=self.title))
            else:
                self.allIDs.append(
                    self.axis.create_text(self.width,
                                          self.height / 2.0,
                                          fill="black",
                                          anchor="e",
                                          text=self.title))