当前位置: 首页>>代码示例>>Python>>正文


Python Transform.convertQToTwoTheta方法代码示例

本文整理汇总了Python中Transform.convertQToTwoTheta方法的典型用法代码示例。如果您正苦于以下问题:Python Transform.convertQToTwoTheta方法的具体用法?Python Transform.convertQToTwoTheta怎么用?Python Transform.convertQToTwoTheta使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Transform的用法示例。


在下文中一共展示了Transform.convertQToTwoTheta方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: savePeakListToFile

# 需要导入模块: import Transform [as 别名]
# 或者: from Transform import convertQToTwoTheta [as 别名]
    def savePeakListToFile(self,filename,initialGuess,qData,
            numberOfChi,maskedPixelInfo,stddev):
        peakList = Fit.getPeakList(self.theDiffractionData.data,qData,
                initialGuess,numberOfChi,stddev)

        # now, save to file
        file = open(filename,"w")
        file.write("# A list of diffraction peaks found.\n")
        file.write("# Diffraction Data: %s\n" % self.theDiffractionData.filename)
        file.write("# Calculated on "+time.asctime()+"\n")
        file.write("# Calibration data used to find peaks:\n")
        initialGuess.writeCommentString(file)
        file.write("# Q data used to find peaks:\n")
        file.write("# Peaks:\n")
        qData.writeCommentString(file)

        if maskedPixelInfo.doPolygonMask and maskedPixelInfo.numPolygons() > 0:
            file.write("# All peaks inside of polygon mask(s) were ignored.\n")
            file.write(maskedPixelInfo.writePolygonCommentString())

        file.write("#%16s%21s%21s%21s%21s%21s%21s%21s\n" % \
                ("x","y","Real Q","Fit Q","chi","width","intensity","2theta"))
        for peak in peakList.getMaskedPeakList(maskedPixelInfo):
            x,y,realQ,fitQ,chi,width = peak
            
            intensity=self.getPixelValueBilinearInterpolation(x,y)
            twoTheta = Transform.convertQToTwoTheta(fitQ,initialGuess)
            file.write("%17.10f    %17.10f    %17.10f    %17.10f    %17.10f    %17.10f    %17.10f    %17.10f\n" % \
                    (x,y,realQ,fitQ,chi,width,intensity,twoTheta) )
        file.close()
        return peakList
开发者ID:joshualande,项目名称:AreaDiffractionMachine,代码行数:33,代码来源:DiffractionData.py

示例2: addConstantQLineCakeImage

# 需要导入模块: import Transform [as 别名]
# 或者: from Transform import convertQToTwoTheta [as 别名]
def addConstantQLineCakeImage(image,Q,qOrTwoThetaLower,
        qOrTwoThetaUpper,numQOrTwoTheta,chiLower,
        chiUpper,numChi,color,calibrationData,type):

    draw = ImageDraw.Draw(image)

    if type == "Q":
        if Q < qOrTwoThetaLower or Q > qOrTwoThetaUpper:
            return

        qIndex = (numQOrTwoTheta-1)*(Q-qOrTwoThetaLower)/ \
                (qOrTwoThetaUpper-qOrTwoThetaLower)

        draw.line( (qIndex,0)+(qIndex,numChi-1),fill=color)
    
    elif type == "2theta":
        twoTheta = Transform.convertQToTwoTheta(Q,calibrationData)
        if twoTheta < qOrTwoThetaLower or \
                twoTheta > qOrTwoThetaUpper:
            return

        twoThetaIndex = (numQOrTwoTheta-1)* \
                (twoTheta-qOrTwoThetaLower)/ \
                (qOrTwoThetaUpper-qOrTwoThetaLower)

        draw.line( (twoThetaIndex,0)+(twoThetaIndex,numChi-1),
                fill=color)
        
    else:
        raise Exception("Unable to add constant Q \
lines to the cake image. The function must be passed \
for the parameter type either 'Q', or '2theta'")
开发者ID:joshualande,项目名称:AreaDiffractionMachine,代码行数:34,代码来源:Cake.py

示例3: getSmallestRange

# 需要导入模块: import Transform [as 别名]
# 或者: from Transform import convertQToTwoTheta [as 别名]
    def getSmallestRange(self,calibrationData,type):
        """ Get Smallest Range picks the smallest 
            range in the image which contains
            the whole diffraction image. 

            If the center of the beam is inside the 
            diffraction data, we know that there will
            be some of all chi so chi should very 
            from -180 to 180. Furthermore, we
            know that Q will vary from 0 to its max 
            which will be on a corner. So
            in that case, we can just look in the 
            corners to find the largets Q value.

            If the center of the image is ouside the 
            diffraction data, that all we know is
            that the extremum will be somewhere on 
            the edge of the image. In that case, we 
            have to loop through the entire border 
            to find the extremum
        """

        # check if it has already been calculated
        if self.lastCalibrationDataGetSmallsetRange != None and \
                calibrationData == self.lastCalibrationDataGetSmallsetRange and \
                self.lastTypeGetSmallestRange == type:
            return self.lastRangeGetSmallestRange

        # store value in case it changes.
        self.lastCalibrationDataGetSmallsetRange = copy.deepcopy(calibrationData)
        self.lastTypeGetSmallestRange = type
            
        if calibrationData.getCenterX()["val"] < 0 or \
            calibrationData.getCenterX()["val"]  > self.theDiffractionData.size-1 or \
            calibrationData.getCenterY()["val"] < 0 or \
            calibrationData.getCenterY()["val"]  > self.theDiffractionData.size-1:

            qLower = None
            qUpper = None
            chiLower = None
            chiUpper = None

            for temp in range(self.theDiffractionData.size):
                # go around each edge of the image, finding the most extreme q and chi values
                q0,chi0 = Transform.getQChi(calibrationData,0,temp)
                q1,chi1 = Transform.getQChi(calibrationData,self.theDiffractionData.size-1,temp)
                q2,chi2 = Transform.getQChi(calibrationData,temp,0)
                q3,chi3 = Transform.getQChi(calibrationData,temp,self.theDiffractionData.size-1)

                lowerQ = min(q0,q1,q2,q3)
                higherQ = max(q0,q1,q2,q3)
                if qLower==None or lowerQ < qLower: qLower = lowerQ
                if qUpper==None or higherQ > qUpper: qUpper = higherQ

                if chi0 > 180: chi0 -=360
                if chi1 > 180: chi1 -=360
                if chi2 > 180: chi2 -=360
                if chi3 > 180: chi3 -=360

                lowerChi = min(chi0,chi1,chi2,chi3)
                higherChi = max(chi0,chi1,chi2,chi3)

                if chiLower==None or lowerChi < chiLower: chiLower = lowerChi
                if chiUpper==None or higherChi > chiUpper: chiUpper = higherChi

            tempRange = {"qLower":qLower,"qUpper":qUpper,"chiLower":chiLower,"chiUpper":chiUpper}
            self.lastRangeGetSmallestRange = tempRange
            return tempRange

        else:
            q0,chi0 = Transform.getQChi(calibrationData,0,0)
            q1,chi1 = Transform.getQChi(calibrationData,0,self.theDiffractionData.size-1)
            q2,chi2 = Transform.getQChi(calibrationData,self.theDiffractionData.size-1,0)
            q3,chi3 = Transform.getQChi(calibrationData,self.theDiffractionData.size-1,
                    self.theDiffractionData.size-1)

            qUpper = max(q0,q1,q2,q3)
            qUpper = float(str(qUpper)[:8])

            if type == "Q":
                lower = 0
                upper = qUpper
            elif type == "2theta":
                lower = Transform.convertQToTwoTheta(0,calibrationData)
                upper = Transform.convertQToTwoTheta(qUpper,calibrationData)

            else:
                raise Exception("Unable to find smallest range. \
This function must be passed for the parameter type either \
'Q', or '2theta'")

            tempRange = {"qOrTwoThetaLower":lower,"qOrTwoThetaUpper":upper,
                    "chiLower":-180,"chiUpper":180}

            self.lastRangeGetSmallestRange = tempRange
            return tempRange
开发者ID:joshualande,项目名称:AreaDiffractionMachine,代码行数:98,代码来源:DiffractionData.py

示例4: addPeaksCakeImage

# 需要导入模块: import Transform [as 别名]
# 或者: from Transform import convertQToTwoTheta [as 别名]
def addPeaksCakeImage(image,qOrTwoThetaLower,
        qOrTwoThetaUpper,numQOrTwoTheta,chiLower,
        chiUpper,numChi,peakList,calibrationData,
        color,smallestRangeQOrTwoThetaLower,
        smallestRangeQOrTwoThetaUpper,
        smallestRangeChiLower,smallestRangeChiUpper,
        maskedPixelInfo,type):

    draw = ImageDraw.Draw(image)

    unZoomWidth = 2.5
    # scale the length of the xs. For example, zoomed 
    # in to 50% means will cause the xs to be drawn 
    # with double the length.
    numTimesZoomInQOrTwoTheta = \
            abs((smallestRangeQOrTwoThetaUpper - \
            smallestRangeQOrTwoThetaLower)/ \
            (qOrTwoThetaUpper-qOrTwoThetaLower))

    numTimesZoomInChi = abs((smallestRangeChiUpper-\
            smallestRangeChiLower)/(chiUpper-chiLower))

    scalingFactor = min(numTimesZoomInQOrTwoTheta,
            numTimesZoomInChi)

    halflength = unZoomWidth*scalingFactor

    for x,y,qReal,qFit,chi,width in \
            peakList.getMaskedPeakList(maskedPixelInfo):
        
        # for each peak, we want to take the true 
        # x,y value of where the peak is on the 
        # image and figure out where it belongs on 
        # the cake data.
        qTemp,chiTemp = Transform.getQChi(calibrationData,x,y)

        # if our chi range begins in the negative, 
        # we might have to place our chi values 
        # in their 360 degree rotated values. Note 
        # that getQChi always returns chi between 
        # 0 and 360
        if (chiTemp-360) > chiLower and \
                (chiTemp-360) < chiUpper:
                chiTemp -= 360
            
        if type == "Q":    
            cakeX = (numQOrTwoTheta-1)*(qTemp-qOrTwoThetaLower)/ \
                    (qOrTwoThetaUpper-qOrTwoThetaLower)
        elif type == '2theta':
            twoThetaTemp = Transform.convertQToTwoTheta(
                    qTemp,calibrationData)
            cakeX = (numQOrTwoTheta-1)* \
                    (twoThetaTemp-qOrTwoThetaLower)/ \
                    (qOrTwoThetaUpper-qOrTwoThetaLower)
        else:
            raise Exception("Unable to add peak to the cake \
image. The function must be passed for the parameter type \
either 'Q', or '2theta'")

        cakeY = (numChi-1)*(chiTemp-chiLower)/(chiUpper-chiLower)

        # add in new lines if they would be visible
        if cakeX >= 0 and cakeX < numQOrTwoTheta and  \
                cakeY >= 0 and cakeY < numChi:

            draw.line( (cakeX-halflength,cakeY-halflength) +
                    (cakeX+halflength,cakeY+halflength),fill=color)

            draw.line( (cakeX+halflength,cakeY-halflength) +
                    (cakeX-halflength,cakeY+halflength),fill=color)
开发者ID:joshualande,项目名称:AreaDiffractionMachine,代码行数:72,代码来源:Cake.py


注:本文中的Transform.convertQToTwoTheta方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。