def getXY_UGLY(xCenter,yCenter,distance,energy,alpha,beta,rotation,Q, chi,pixelLength,pixelHeight,cos_beta=None, sin_beta=None, cos_alpha=None, sin_alpha=None, cos_rotation = None, sin_rotation = None): # call wrapped c code. if cos_beta == None or sin_beta == None or \ cos_alpha == None or sin_alpha == None or\ cos_rotation == None or sin_rotation == None: return DiffractionAnalysisWrap.getXY(xCenter,yCenter,distance,energy, alpha,beta,rotation,Q,chi,pixelLength,pixelHeight) return DiffractionAnalysisWrap.getXY(xCenter,yCenter,distance,energy,alpha, beta,rotation,Q,chi,pixelLength,pixelHeight,cos_beta,sin_beta, cos_alpha,sin_alpha,cos_rotation,sin_rotation)
def getPixelValueBilinearInterpolation(self, x, y): if x<0 or x>self.theDiffractionData.size or \ y<0 or y>self.theDiffractionData.size: raise Exception( "Cannot calculate the intensity outside of the image.\n") return DiffractionAnalysisWrap.bilinearInterpolation( self.theDiffractionData.data, x, y)
def getQChi(calibrationData, xPixel, yPixel, cos_beta=None, sin_beta=None, cos_alpha=None, sin_alpha=None, cos_rotation=None, sin_rotation=None): """ calibrationData is a CalibrationData object holding the x and y center of the image in pixels, the distance from detector to sample, the energy of the incoming photons, and the alpha and beta tilt parameters of the experiment. It also holds pixelLength, the physical length of one pixel in micron units, and pixelheight, the physical length of one pixel in micron units (1 mm = 1000 microns). x,y are the coordinates to transform into Q and Chi values. Returns chi in units of degrees. """ # call wrapped c code. if cos_beta == None or sin_beta == None or \ cos_alpha == None or sin_alpha == None or \ cos_rotation == None or sin_rotation == None: return DiffractionAnalysisWrap.getQChi( calibrationData.getCenterX()['val'], calibrationData.getCenterY()['val'], calibrationData.getDistance()['val'], calibrationData.getEnergy()['val'], calibrationData.getAlpha()['val'], calibrationData.getBeta()['val'], calibrationData.getRotation()['val'], xPixel, yPixel, calibrationData.getPixelLength()['val'], calibrationData.getPixelHeight()['val']) return DiffractionAnalysisWrap.getQChi( calibrationData.getCenterX()['val'], calibrationData.getCenterY()['val'], calibrationData.getDistance()['val'], calibrationData.getEnergy()['val'], calibrationData.getAlpha()['val'], calibrationData.getBeta()['val'], calibrationData.getRotation()['val'], xPixel, yPixel, calibrationData.getPixelLength()['val'], calibrationData.getPixelHeight()['val'], cos_beta, sin_beta, cos_alpha, sin_alpha, cos_rotation, sin_rotation)
def getPixelValueBilinearInterpolation(self,x,y): if x<0 or x>self.theDiffractionData.size or \ y<0 or y>self.theDiffractionData.size: raise Exception("Cannot calculate the intensity \ outside of the image.\n") return DiffractionAnalysisWrap.bilinearInterpolation( self.theDiffractionData.data,x,y)
def getXY(calibrationData, Q, chi, cos_beta=None, sin_beta=None, cos_alpha=None, sin_alpha=None, cos_rotation=None, sin_rotation=None): """ calibrationData is a CalibrationData object holding the x and y center of the image in pixels, the distance from detector to sample, the energy of the incoming photons, and the alpha and beta tilt parameters of the experiment. CalibrationData also holds the rotation angle and the pixel length and pixel height in micron units (1mm = 1000 microns). Q and chi are the coordinates to convert to x,y pixel values. chi is in units of degrees. """ # call wrapped c code. if cos_beta == None or sin_beta == None or \ cos_alpha == None or sin_alpha == None or\ cos_rotation == None or sin_rotation == None: return DiffractionAnalysisWrap.getXY( calibrationData.getCenterX()['val'], calibrationData.getCenterY()['val'], calibrationData.getDistance()['val'], calibrationData.getEnergy()['val'], calibrationData.getAlpha()['val'], calibrationData.getBeta()['val'], calibrationData.getRotation()['val'], Q, chi, calibrationData.getPixelLength()['val'], calibrationData.getPixelHeight()['val']) return DiffractionAnalysisWrap.getXY( calibrationData.getCenterX()['val'], calibrationData.getCenterY()['val'], calibrationData.getDistance()['val'], calibrationData.getEnergy()['val'], calibrationData.getAlpha()['val'], calibrationData.getBeta()['val'], calibrationData.getRotation()['val'], Q, chi, calibrationData.getPixelLength()['val'], calibrationData.getPixelHeight()['val'], cos_beta, sin_beta, cos_alpha, sin_alpha, cos_rotation, sin_rotation)
def getQChi(calibrationData,xPixel,yPixel,cos_beta=None, sin_beta=None, cos_alpha=None, sin_alpha=None, cos_rotation=None, sin_rotation=None): """ calibrationData is a CalibrationData object holding the x and y center of the image in pixels, the distance from detector to sample, the energy of the incoming photons, and the alpha and beta tilt parameters of the experiment. It also holds pixelLength, the physical length of one pixel in micron units, and pixelheight, the physical length of one pixel in micron units (1 mm = 1000 microns). x,y are the coordinates to transform into Q and Chi values. Returns chi in units of degrees. """ # call wrapped c code. if cos_beta == None or sin_beta == None or \ cos_alpha == None or sin_alpha == None or \ cos_rotation == None or sin_rotation == None: return DiffractionAnalysisWrap.getQChi( calibrationData.getCenterX()['val'], calibrationData.getCenterY()['val'], calibrationData.getDistance()['val'], calibrationData.getEnergy()['val'], calibrationData.getAlpha()['val'], calibrationData.getBeta()['val'], calibrationData.getRotation()['val'], xPixel,yPixel, calibrationData.getPixelLength()['val'], calibrationData.getPixelHeight()['val']) return DiffractionAnalysisWrap.getQChi( calibrationData.getCenterX()['val'], calibrationData.getCenterY()['val'], calibrationData.getDistance()['val'], calibrationData.getEnergy()['val'], calibrationData.getAlpha()['val'], calibrationData.getBeta()['val'], calibrationData.getRotation()['val'], xPixel,yPixel, calibrationData.getPixelLength()['val'], calibrationData.getPixelHeight()['val'], cos_beta,sin_beta, cos_alpha,sin_alpha, cos_rotation,sin_rotation)
def getXY(calibrationData,Q,chi, cos_beta=None, sin_beta=None, cos_alpha=None, sin_alpha=None, cos_rotation = None,sin_rotation = None): """ calibrationData is a CalibrationData object holding the x and y center of the image in pixels, the distance from detector to sample, the energy of the incoming photons, and the alpha and beta tilt parameters of the experiment. CalibrationData also holds the rotation angle and the pixel length and pixel height in micron units (1mm = 1000 microns). Q and chi are the coordinates to convert to x,y pixel values. chi is in units of degrees. """ # call wrapped c code. if cos_beta == None or sin_beta == None or \ cos_alpha == None or sin_alpha == None or\ cos_rotation == None or sin_rotation == None: return DiffractionAnalysisWrap.getXY( calibrationData.getCenterX()['val'], calibrationData.getCenterY()['val'], calibrationData.getDistance()['val'], calibrationData.getEnergy()['val'], calibrationData.getAlpha()['val'], calibrationData.getBeta()['val'], calibrationData.getRotation()['val'], Q,chi, calibrationData.getPixelLength()['val'], calibrationData.getPixelHeight()['val']) return DiffractionAnalysisWrap.getXY( calibrationData.getCenterX()['val'], calibrationData.getCenterY()['val'], calibrationData.getDistance()['val'], calibrationData.getEnergy()['val'], calibrationData.getAlpha()['val'], calibrationData.getBeta()['val'], calibrationData.getRotation()['val'], Q,chi, calibrationData.getPixelLength()['val'], calibrationData.getPixelHeight()['val'], cos_beta,sin_beta, cos_alpha,sin_alpha, cos_rotation,sin_rotation)
def cake(self,diffractionData,calibrationData,qLower,qUpper,numQ, chiLower,chiUpper,numChi,doPolarizationCorrection,P, maskedPixelInfo): if chiLower >= chiUpper: raise Exception("Unable to cake. The lower chi value must be less then the upper chi value.") if (chiUpper - chiLower) > 360: raise Exception("The chi values must have a range no larger then 360 degrees.") if qLower >= qUpper: raise Exception("Unable to cake. The lower q value must be less then the upper q value.") if qLower < 0: raise Exception("Unable to cake. The lower q value must be larger then 0.") if qUpper > Transform.getMaxQ(calibrationData): raise Exception("Unable to cake. The upper q value must be less then the largest possible Q value.") if maskedPixelInfo.doLessThanMask: lessThanMask = maskedPixelInfo.lessThanMask else: # We can just send the function a bunch of junk since it won't be used lessThanMask = -1 if maskedPixelInfo.doGreaterThanMask: greaterThanMask = maskedPixelInfo.greaterThanMask else: greaterThanMask = -1 if maskedPixelInfo.doPolygonMask: polygonsX = maskedPixelInfo.polygonsX polygonsY = maskedPixelInfo.polygonsY polygonBeginningsIndex = maskedPixelInfo.polygonBeginningsIndex polygonNumberOfItems = maskedPixelInfo.polygonNumberOfItems else: polygonsX = Numeric.array([]) polygonsY = Numeric.array([]) polygonBeginningsIndex = Numeric.array([]) polygonNumberOfItems = Numeric.array([]) # use the wraped C code to do the caking self.cakeData = DiffractionAnalysisWrap.cake( diffractionData, calibrationData.getCenterX()['val'], calibrationData.getCenterY()['val'], calibrationData.getDistance()['val'], calibrationData.getEnergy()['val'], calibrationData.getAlpha()['val'], calibrationData.getBeta()['val'], calibrationData.getRotation()['val'], qLower, qUpper, numQ, chiLower, chiUpper, numChi, doPolarizationCorrection, P, maskedPixelInfo.doGreaterThanMask, greaterThanMask, maskedPixelInfo.doLessThanMask, lessThanMask, maskedPixelInfo.doPolygonMask, polygonsX, polygonsY, polygonBeginningsIndex, polygonNumberOfItems, calibrationData.getPixelLength()['val'], calibrationData.getPixelHeight()['val']) if type(self.cakeData) == type(None): raise Exception("Error occured while caking the data.") # store the values for later self.qLower=qLower self.qUpper=qUpper self.numQ=numQ self.chiLower=chiLower self.chiUpper=chiUpper self.numChi=numChi self.doPolarizationCorrection=doPolarizationCorrection self.P=P # We should make a shallow copy so that the widget dose # not get copied over. Nevertheless, all the stuff we # care about are single values so they will get really copied over self.maskedPixelInfo = copy.copy(maskedPixelInfo) self.calibrationData = copy.deepcopy(calibrationData) self.diffractionData = diffractionData
def integrate(self, diffractionData, calibrationData, lower, upper, num, constraintLower, constraintUpper, doConstraint, doPolarizationCorrection, P, typeOfIntegration, typeOfConstraint, maskedPixelInfo): if typeOfIntegration == 'Q': if lower >= upper: raise Exception( "Unable to integrate the intensity. The lower Q value must be less then the upper Q value" ) if lower < 0: raise Exception( "Unable to integrate intensity. The lower Q value must be larger then 0." ) if upper > Transform.getMaxQ(calibrationData): raise Exception( "Unable to integrate intensity. The upper Q value must be less then the largest possible Q value." ) if num < 1: raise Exception( "Unable to integrate intensity. The number of Q must be at least 1." ) elif typeOfIntegration == '2theta': if lower >= upper: raise Exception( "Unable to integrate the intensity. The lower 2theta value must be less then the upper 2theta value" ) if lower < 0: raise Exception( "Unable to integrate intensity. The lower 2theta value must be larger then 0." ) if upper > 90: raise Exception( "Unable to integrate intensity. The upper 2theta value must be smaller then 90." ) if num < 1: raise Exception( "Unable to integrate intensity. The number of 2theta must be at least 1." ) elif typeOfIntegration == 'chi': if lower >= upper: raise Exception( "Unable to integrate the intensity. The lower chi value must be less then the upper chi value" ) if lower < -360: raise Exception( "Unable to integrate intensity. The lower chi value must be larger then -360 degrees." ) if upper > +360: raise Exception( "Unable to integrate intensity. The upper chi value must be lower then 360 degrees." ) if upper - lower > 360: raise Exception( "Unable to integrate intensity. The chi range can be at most 360 degrees." ) if num < 1: raise Exception( "Unable to integrate intensity. The number of chi must be at least 1." ) else: raise Exception( "Unable to integrate intensity. The function integrate must be passed for the parameter typeOfIntegration either 'Q', '2theta', or 'chi'" ) if doConstraint: if (typeOfIntegration == 'Q' or typeOfIntegration == '2theta') and \ typeOfConstraint == 'chi': if constraintLower >= constraintUpper: raise Exception( "Unable to integrate the intensity. The constraint lower chi value must be less then the upper chi value" ) if constraintLower < -360: raise Exception( "Unable to integrate intensity. The constraint lower chi value must be larger then -360 degrees." ) if constraintUpper > +360: raise Exception( "Unable to integrate intensity. The constraint upper chi value must be lower then 360 degrees." ) if constraintUpper - constraintLower > 360: raise Exception( "Unable to integrate intensity. The constraint chi range can be at most 360 degrees." ) elif (typeOfIntegration == 'chi' and typeOfConstraint == 'Q'): if constraintLower >= constraintUpper: raise Exception( "Unable to integrate the intensity. The constraint lower Q value must be less then the upper Q value" ) if constraintLower < 0: raise Exception( "Unable to integrate intensity. The constraint lower Q value must be larger then 0." ) if constraintUpper > Transform.getMaxQ(calibrationData): raise Exception( "Unable to integrate intensity. The constraint upper Q value must be less then the largest possible Q value." ) elif (typeOfIntegration == 'chi' and typeOfConstraint == '2theta'): if constraintLower >= constraintUpper: raise Exception( "Unable to integrate the intensity. The constraint lower 2theta value must be less then the upper 2theta value" ) if constraintLower < 0: raise Exception( "Unable to integrate intensity. The constraint lower 2theta value must be larger then 0." ) if constraintUpper > 90: raise Exception( "Unable to integrate intensity. The constraint upper 2theta value must be smaller then 90." ) else: raise Exception( "Constraint must be of the from chi, 2theta, or Q. Also, the constraint must be different from the type of integration." ) if maskedPixelInfo.doLessThanMask: lessThanMask = maskedPixelInfo.lessThanMask else: # We can just send the function a bunch of junk since it won't be used lessThanMask = -1 if maskedPixelInfo.doGreaterThanMask: greaterThanMask = maskedPixelInfo.greaterThanMask else: greaterThanMask = -1 if maskedPixelInfo.doPolygonMask: polygonsX = maskedPixelInfo.polygonsX polygonsY = maskedPixelInfo.polygonsY polygonBeginningsIndex = maskedPixelInfo.polygonBeginningsIndex polygonNumberOfItems = maskedPixelInfo.polygonNumberOfItems else: polygonsX = Numeric.array([]) polygonsY = Numeric.array([]) polygonBeginningsIndex = Numeric.array([]) polygonNumberOfItems = Numeric.array([]) # use the wraped C code to do the caking self.values, self.intensityData = DiffractionAnalysisWrap.integrate( diffractionData, calibrationData.getCenterX()['val'], calibrationData.getCenterY()['val'], calibrationData.getDistance()['val'], calibrationData.getEnergy()['val'], calibrationData.getAlpha()['val'], calibrationData.getBeta()['val'], calibrationData.getRotation()['val'], lower, upper, num, constraintLower, constraintUpper, doConstraint, doPolarizationCorrection, P, maskedPixelInfo.doGreaterThanMask, greaterThanMask, maskedPixelInfo.doLessThanMask, lessThanMask, maskedPixelInfo.doPolygonMask, polygonsX, polygonsY, polygonBeginningsIndex, polygonNumberOfItems, calibrationData.getPixelLength()['val'], calibrationData.getPixelHeight()['val'], typeOfIntegration, typeOfConstraint) if type(self.intensityData) == type(None): raise Exception( "Unspecified Error occured while integrating the data") self.typeOfIntegration = typeOfIntegration self.lower = lower self.upper = upper self.num = num self.constraintLower = constraintLower self.constraintUpper = constraintUpper self.doConstraint = doConstraint self.doPolarizationCorrection = doPolarizationCorrection self.P = P # We should make a shallow copy so that the widget dose # not get copied over. Nevertheless, all the stuff we # care about are single values so they will get really copied over self.maskedPixelInfo = copy.copy(maskedPixelInfo) self.typeOfConstraint = typeOfConstraint self.calibrationData = copy.deepcopy(calibrationData)
def cake(self,diffractionData,calibrationData,qOrTwoThetaLower, qOrTwoThetaUpper,numQOrTwoTheta,chiLower,chiUpper,numChi, doPolarizationCorrection,P,maskedPixelInfo,type): if chiLower >= chiUpper: raise Exception("Unable to cake. The lower chi value must be \ less then the upper chi value.") if (chiUpper - chiLower) > 360: raise Exception("The chi values must have a range no larger \ then 360 degrees.") if type == 'Q': if qOrTwoThetaLower >= qOrTwoThetaUpper: raise Exception("Unable to cake. The lower Q value must be \ less then the upper Q value") if qOrTwoThetaLower < 0: raise Exception("Unable to cake. The lower Q value must be \ larger then 0.") if qOrTwoThetaUpper > Transform.getMaxQ(calibrationData): raise Exception("Unable to cake. The upper Q value must be \ less then the largest possible Q value.") if numQOrTwoTheta < 1: raise Exception("Unable to cake. The number of Q must be at \ least 1.") elif type == '2theta': if qOrTwoThetaLower >= qOrTwoThetaUpper: raise Exception("Unable to cake. The lower 2theta value must \ be less then the upper 2theta value") if qOrTwoThetaLower < 0: raise Exception("Unable to cake. The lower 2theta value must \ be larger then 0.") if qOrTwoThetaUpper > Transform.getMaxTwoTheta(): raise Exception("Unable to cake. The upper 2theta value must \ be smaller then 90.") if numQOrTwoTheta < 1: raise Exception("Unable to cake. The number of 2theta must \ be at least 1.") else: raise Exception("Unable to cake. The function must be passed \ for the parameter type either 'Q', or '2theta'") if maskedPixelInfo.doLessThanMask: lessThanMask = maskedPixelInfo.lessThanMask else: # We can just send the function a bunch of junk since # it won't be used lessThanMask = -1 if maskedPixelInfo.doGreaterThanMask: greaterThanMask = maskedPixelInfo.greaterThanMask else: greaterThanMask = -1 if maskedPixelInfo.doPolygonMask: polygonsX = maskedPixelInfo.polygonsX polygonsY = maskedPixelInfo.polygonsY polygonBeginningsIndex = maskedPixelInfo.polygonBeginningsIndex polygonNumberOfItems = maskedPixelInfo.polygonNumberOfItems else: polygonsX = Numeric.array([]) polygonsY = Numeric.array([]) polygonBeginningsIndex = Numeric.array([]) polygonNumberOfItems = Numeric.array([]) # use the wraped C code to do the caking self.cakeData = DiffractionAnalysisWrap.cake( diffractionData, calibrationData.getCenterX()['val'], calibrationData.getCenterY()['val'], calibrationData.getDistance()['val'], calibrationData.getEnergy()['val'], calibrationData.getAlpha()['val'], calibrationData.getBeta()['val'], calibrationData.getRotation()['val'], qOrTwoThetaLower, qOrTwoThetaUpper, numQOrTwoTheta, chiLower, chiUpper, numChi, doPolarizationCorrection, P, maskedPixelInfo.doGreaterThanMask, greaterThanMask, maskedPixelInfo.doLessThanMask, lessThanMask, maskedPixelInfo.doPolygonMask, polygonsX, polygonsY, polygonBeginningsIndex, polygonNumberOfItems, calibrationData.getPixelLength()['val'], calibrationData.getPixelHeight()['val'], type) # store the values for later self.qOrTwoThetaLower=qOrTwoThetaLower self.qOrTwoThetaUpper=qOrTwoThetaUpper self.numQOrTwoTheta=numQOrTwoTheta self.chiLower=chiLower self.chiUpper=chiUpper self.numChi=numChi self.doPolarizationCorrection=doPolarizationCorrection self.P=P self.type = type # We should make a shallow copy so that the widget dose # not get copied over. Nevertheless, all the stuff we # care about are single values so they will get really copied over self.maskedPixelInfo = copy.copy(maskedPixelInfo) self.calibrationData = copy.deepcopy(calibrationData) self.diffractionData = diffractionData
def convertQToTwoTheta(Q,calibrationData): """ Calculates twoTheta when given Q and the wavelength. """ return DiffractionAnalysisWrap.convertQToTwoTheta(Q, calibrationData.getWavelength()['val'])
def convertTwoThetaToQ(twoTheta,calibrationData): """ Calculates Q when given twoTheta and the wavelength. """ wav= calibrationData.getWavelength()['val'] print wav return DiffractionAnalysisWrap.convertTwoThetaToQ(twoTheta,wav)
def convertWavelengthToEnergy(wavelength): return DiffractionAnalysisWrap.convertWavelengthToEnergy(wavelength)
def convertEnergyToWavelength(energy): return DiffractionAnalysisWrap.convertEnergyToWavelength(energy)
def integrate(self,diffractionData,calibrationData,lower, upper,num,constraintLower,constraintUpper,doConstraint, doPolarizationCorrection,P, typeOfIntegration,typeOfConstraint,maskedPixelInfo): if typeOfIntegration == 'Q': if lower >= upper: raise Exception("Unable to integrate the intensity. The lower Q value must be less then the upper Q value") if lower < 0: raise Exception("Unable to integrate intensity. The lower Q value must be larger then 0.") if upper > Transform.getMaxQ(calibrationData): raise Exception("Unable to integrate intensity. The upper Q value must be less then the largest possible Q value.") if num < 1: raise Exception("Unable to integrate intensity. The number of Q must be at least 1.") elif typeOfIntegration == '2theta': if lower >= upper: raise Exception("Unable to integrate the intensity. The lower 2theta value must be less then the upper 2theta value") if lower < 0: raise Exception("Unable to integrate intensity. The lower 2theta value must be larger then 0.") if upper > 90: raise Exception("Unable to integrate intensity. The upper 2theta value must be smaller then 90.") if num < 1: raise Exception("Unable to integrate intensity. The number of 2theta must be at least 1.") elif typeOfIntegration == 'chi': if lower >= upper: raise Exception("Unable to integrate the intensity. The lower chi value must be less then the upper chi value") if lower < -360: raise Exception("Unable to integrate intensity. The lower chi value must be larger then -360 degrees.") if upper > +360: raise Exception("Unable to integrate intensity. The upper chi value must be lower then 360 degrees.") if upper - lower > 360: raise Exception("Unable to integrate intensity. The chi range can be at most 360 degrees.") if num < 1: raise Exception("Unable to integrate intensity. The number of chi must be at least 1.") else: raise Exception("Unable to integrate intensity. The function integrate must be passed for the parameter typeOfIntegration either 'Q', '2theta', or 'chi'") if doConstraint: if (typeOfIntegration == 'Q' or typeOfIntegration == '2theta') and \ typeOfConstraint == 'chi': if constraintLower >= constraintUpper: raise Exception("Unable to integrate the intensity. The constraint lower chi value must be less then the upper chi value") if constraintLower < -360: raise Exception("Unable to integrate intensity. The constraint lower chi value must be larger then -360 degrees.") if constraintUpper > +360: raise Exception("Unable to integrate intensity. The constraint upper chi value must be lower then 360 degrees.") if constraintUpper - constraintLower > 360: raise Exception("Unable to integrate intensity. The constraint chi range can be at most 360 degrees.") elif (typeOfIntegration == 'chi' and typeOfConstraint == 'Q'): if constraintLower >= constraintUpper: raise Exception("Unable to integrate the intensity. The constraint lower Q value must be less then the upper Q value") if constraintLower < 0: raise Exception("Unable to integrate intensity. The constraint lower Q value must be larger then 0.") if constraintUpper > Transform.getMaxQ(calibrationData): raise Exception("Unable to integrate intensity. The constraint upper Q value must be less then the largest possible Q value.") elif (typeOfIntegration == 'chi' and typeOfConstraint == '2theta'): if constraintLower >= constraintUpper: raise Exception("Unable to integrate the intensity. The constraint lower 2theta value must be less then the upper 2theta value") if constraintLower < 0: raise Exception("Unable to integrate intensity. The constraint lower 2theta value must be larger then 0.") if constraintUpper > 90: raise Exception("Unable to integrate intensity. The constraint upper 2theta value must be smaller then 90.") else: raise Exception("Constraint must be of the from chi, 2theta, or Q. Also, the constraint must be different from the type of integration.") if maskedPixelInfo.doLessThanMask: lessThanMask = maskedPixelInfo.lessThanMask else: # We can just send the function a bunch of junk since it won't be used lessThanMask = -1 if maskedPixelInfo.doGreaterThanMask: greaterThanMask = maskedPixelInfo.greaterThanMask else: greaterThanMask = -1 if maskedPixelInfo.doPolygonMask: polygonsX = maskedPixelInfo.polygonsX polygonsY = maskedPixelInfo.polygonsY polygonBeginningsIndex = maskedPixelInfo.polygonBeginningsIndex polygonNumberOfItems = maskedPixelInfo.polygonNumberOfItems else: polygonsX = Numeric.array([]) polygonsY = Numeric.array([]) polygonBeginningsIndex = Numeric.array([]) polygonNumberOfItems = Numeric.array([]) # use the wraped C code to do the caking self.values,self.intensityData = DiffractionAnalysisWrap.integrate( diffractionData, calibrationData.getCenterX()['val'], calibrationData.getCenterY()['val'], calibrationData.getDistance()['val'], calibrationData.getEnergy()['val'], calibrationData.getAlpha()['val'], calibrationData.getBeta()['val'], calibrationData.getRotation()['val'], lower, upper, num, constraintLower, constraintUpper, doConstraint, doPolarizationCorrection, P, maskedPixelInfo.doGreaterThanMask, greaterThanMask, maskedPixelInfo.doLessThanMask, lessThanMask, maskedPixelInfo.doPolygonMask, polygonsX, polygonsY, polygonBeginningsIndex, polygonNumberOfItems, calibrationData.getPixelLength()['val'], calibrationData.getPixelHeight()['val'], typeOfIntegration, typeOfConstraint) if type(self.intensityData) == type(None): raise Exception("Unspecified Error occured while integrating the data") self.typeOfIntegration = typeOfIntegration self.lower=lower self.upper=upper self.num=num self.constraintLower = constraintLower self.constraintUpper = constraintUpper self.doConstraint = doConstraint self.doPolarizationCorrection=doPolarizationCorrection self.P=P # We should make a shallow copy so that the widget dose # not get copied over. Nevertheless, all the stuff we # care about are single values so they will get really copied over self.maskedPixelInfo = copy.copy(maskedPixelInfo) self.typeOfConstraint = typeOfConstraint self.calibrationData=copy.deepcopy(calibrationData)
def cake(self, diffractionData, calibrationData, qOrTwoThetaLower, qOrTwoThetaUpper, numQOrTwoTheta, chiLower, chiUpper, numChi, doPolarizationCorrection, P, maskedPixelInfo, type): if chiLower >= chiUpper: raise Exception("Unable to cake. The lower chi value must be \ less then the upper chi value.") if (chiUpper - chiLower) > 360: raise Exception("The chi values must have a range no larger \ then 360 degrees.") if type == 'Q': if qOrTwoThetaLower >= qOrTwoThetaUpper: raise Exception("Unable to cake. The lower Q value must be \ less then the upper Q value") if qOrTwoThetaLower < 0: raise Exception("Unable to cake. The lower Q value must be \ larger then 0.") if qOrTwoThetaUpper > Transform.getMaxQ(calibrationData): raise Exception("Unable to cake. The upper Q value must be \ less then the largest possible Q value.") if numQOrTwoTheta < 1: raise Exception("Unable to cake. The number of Q must be at \ least 1.") elif type == '2theta': if qOrTwoThetaLower >= qOrTwoThetaUpper: raise Exception("Unable to cake. The lower 2theta value must \ be less then the upper 2theta value") if qOrTwoThetaLower < 0: raise Exception("Unable to cake. The lower 2theta value must \ be larger then 0.") if qOrTwoThetaUpper > Transform.getMaxTwoTheta(): raise Exception("Unable to cake. The upper 2theta value must \ be smaller then 90.") if numQOrTwoTheta < 1: raise Exception("Unable to cake. The number of 2theta must \ be at least 1.") else: raise Exception("Unable to cake. The function must be passed \ for the parameter type either 'Q', or '2theta'") if maskedPixelInfo.doLessThanMask: lessThanMask = maskedPixelInfo.lessThanMask else: # We can just send the function a bunch of junk since # it won't be used lessThanMask = -1 if maskedPixelInfo.doGreaterThanMask: greaterThanMask = maskedPixelInfo.greaterThanMask else: greaterThanMask = -1 if maskedPixelInfo.doPolygonMask: polygonsX = maskedPixelInfo.polygonsX polygonsY = maskedPixelInfo.polygonsY polygonBeginningsIndex = maskedPixelInfo.polygonBeginningsIndex polygonNumberOfItems = maskedPixelInfo.polygonNumberOfItems else: polygonsX = Numeric.array([]) polygonsY = Numeric.array([]) polygonBeginningsIndex = Numeric.array([]) polygonNumberOfItems = Numeric.array([]) # use the wraped C code to do the caking self.cakeData = DiffractionAnalysisWrap.cake( diffractionData, calibrationData.getCenterX()['val'], calibrationData.getCenterY()['val'], calibrationData.getDistance()['val'], calibrationData.getEnergy()['val'], calibrationData.getAlpha()['val'], calibrationData.getBeta()['val'], calibrationData.getRotation()['val'], qOrTwoThetaLower, qOrTwoThetaUpper, numQOrTwoTheta, chiLower, chiUpper, numChi, doPolarizationCorrection, P, maskedPixelInfo.doGreaterThanMask, greaterThanMask, maskedPixelInfo.doLessThanMask, lessThanMask, maskedPixelInfo.doPolygonMask, polygonsX, polygonsY, polygonBeginningsIndex, polygonNumberOfItems, calibrationData.getPixelLength()['val'], calibrationData.getPixelHeight()['val'], type) # store the values for later self.qOrTwoThetaLower = qOrTwoThetaLower self.qOrTwoThetaUpper = qOrTwoThetaUpper self.numQOrTwoTheta = numQOrTwoTheta self.chiLower = chiLower self.chiUpper = chiUpper self.numChi = numChi self.doPolarizationCorrection = doPolarizationCorrection self.P = P self.type = type # We should make a shallow copy so that the widget dose # not get copied over. Nevertheless, all the stuff we # care about are single values so they will get really copied over self.maskedPixelInfo = copy.copy(maskedPixelInfo) self.calibrationData = copy.deepcopy(calibrationData) self.diffractionData = diffractionData
def cake(self, diffractionData, calibrationData, qLower, qUpper, numQ, chiLower, chiUpper, numChi, doPolarizationCorrection, P, maskedPixelInfo): if chiLower >= chiUpper: raise Exception( "Unable to cake. The lower chi value must be less then the upper chi value." ) if (chiUpper - chiLower) > 360: raise Exception( "The chi values must have a range no larger then 360 degrees.") if qLower >= qUpper: raise Exception( "Unable to cake. The lower q value must be less then the upper q value." ) if qLower < 0: raise Exception( "Unable to cake. The lower q value must be larger then 0.") if qUpper > Transform.getMaxQ(calibrationData): raise Exception( "Unable to cake. The upper q value must be less then the largest possible Q value." ) if maskedPixelInfo.doLessThanMask: lessThanMask = maskedPixelInfo.lessThanMask else: # We can just send the function a bunch of junk since it won't be used lessThanMask = -1 if maskedPixelInfo.doGreaterThanMask: greaterThanMask = maskedPixelInfo.greaterThanMask else: greaterThanMask = -1 if maskedPixelInfo.doPolygonMask: polygonsX = maskedPixelInfo.polygonsX polygonsY = maskedPixelInfo.polygonsY polygonBeginningsIndex = maskedPixelInfo.polygonBeginningsIndex polygonNumberOfItems = maskedPixelInfo.polygonNumberOfItems else: polygonsX = Numeric.array([]) polygonsY = Numeric.array([]) polygonBeginningsIndex = Numeric.array([]) polygonNumberOfItems = Numeric.array([]) # use the wraped C code to do the caking self.cakeData = DiffractionAnalysisWrap.cake( diffractionData, calibrationData.getCenterX()['val'], calibrationData.getCenterY()['val'], calibrationData.getDistance()['val'], calibrationData.getEnergy()['val'], calibrationData.getAlpha()['val'], calibrationData.getBeta()['val'], calibrationData.getRotation()['val'], qLower, qUpper, numQ, chiLower, chiUpper, numChi, doPolarizationCorrection, P, maskedPixelInfo.doGreaterThanMask, greaterThanMask, maskedPixelInfo.doLessThanMask, lessThanMask, maskedPixelInfo.doPolygonMask, polygonsX, polygonsY, polygonBeginningsIndex, polygonNumberOfItems, calibrationData.getPixelLength()['val'], calibrationData.getPixelHeight()['val']) if type(self.cakeData) == type(None): raise Exception("Error occured while caking the data.") # store the values for later self.qLower = qLower self.qUpper = qUpper self.numQ = numQ self.chiLower = chiLower self.chiUpper = chiUpper self.numChi = numChi self.doPolarizationCorrection = doPolarizationCorrection self.P = P # We should make a shallow copy so that the widget dose # not get copied over. Nevertheless, all the stuff we # care about are single values so they will get really copied over self.maskedPixelInfo = copy.copy(maskedPixelInfo) self.calibrationData = copy.deepcopy(calibrationData) self.diffractionData = diffractionData