def saveCakeImage(self, filename, calibrationData, qLower, qUpper, numQ, chiLower, chiUpper,numChi, doPolarizationCorrection,P,maskedPixelInfo, colorMaps, colorMapName, lowerBound, upperBound, logScale = None, invert = None, drawQLines = None, drawdQLines = None, QData = None, drawPeaks = None, peakList = None, qLinesColor = None, dQLinesColor = None, peakLinesColor = None): image = self.getCakeImage( calibrationData = calibrationData, qLower = qLower, qUpper = qUpper, numQ = numQ, chiLower = chiLower, chiUpper = chiUpper, numChi = numChi, doPolarizationCorrection = doPolarizationCorrection, P = P, maskedPixelInfo = maskedPixelInfo, width = None, height = None, colorMaps = colorMaps, colorMapName = colorMapName, lowerBound = lowerBound, upperBound = upperBound, logScale = logScale, invert = invert) if drawQLines or drawdQLines: if QData == None: raise Exception("Cannot save the cake data until a q list is given.") if drawQLines: if qLinesColor == None: raise Exception('Cannot add q lines to the saved image until the q line color is set.') for Q,dQ in QData.getAllQPairs(): Cake.addConstantQLineCakeImage(image,Q,qLower,qUpper,numQ,chiLower,chiUpper,numChi,qLinesColor) if drawdQLines: if dQLinesColor == None: raise Exception('Cannot add delta q lines to the saved image until the delta q line color is set.') for Q,dQ in QData.getAllQPairs(): Cake.addConstantQLineCakeImage(image,Q-dQ,qLower,qUpper,numQ,chiLower,chiUpper,numChi,dQLinesColor) Cake.addConstantQLineCakeImage(image,Q+dQ,qLower,qUpper,numQ,chiLower,chiUpper,numChi,dQLinesColor) if drawPeaks and peakList != None: if peakLinesColor == None: raise Exception("Cannot add peaks to the saved iamge until the peak color is set.") smallest = self.getSmallestRange(calibrationData) Cake.addPeaksCakeImage(image,qLower,qUpper,numQ,chiLower,chiUpper,numChi, peakList,calibrationData,peakLinesColor, smallestRangeQLower = smallest['qLower'], smallestRangeQUpper = smallest['qUpper'], smallestRangeChiLower = smallest['chiLower'], smallestRangeChiUpper = smallest['chiUpper']) try: image.save(filename) except Exception,e: raise UserInputException("Cannot save the cake: %s has an unknown file extension" % filename )
def saveDiffractionImage(self,filename,colorMaps,colorMapName, maskedPixelInfo, pixel1X=None,pixel1Y=None, pixel2X=None, pixel2Y=None, lowerBound=0, upperBound=1, logScale = None, invert = None, drawQLines=None,drawdQLines=None,QData=None,calibrationData=None, drawPeaks=None,peakList=None, qLinesColor = None, dQLinesColor = None, peakLinesColor = None): # save EDF data specially if getextension(filename) == ".edf": edf = EdfFile(filename) #You can write any relevant information in the dictionnary. edf.WriteImage({'Title':"Edf file converted by the Area Diffraction Machine"}, Numeric.transpose(self.theDiffractionData.data), DataType= "SignedInteger", Append=0) del edf # to force file close return # otherwise, try to save it using the PIL image = self.getDiffractionImage(colorMaps,colorMapName, maskedPixelInfo, None,None,None,None,None,None, lowerBound,upperBound,logScale,invert) if drawQLines or drawdQLines: if QData == None: raise Exception("Cannot save the diffraction data until a q list is given.") if calibrationData == None: raise Exception("Cannot save the diffraction data until the calibration Data is given.") if drawQLines: if qLinesColor == None: raise Exception('Cannot add q lines to the saved image until the q line color is set.') for Q,dQ in QData.getAllQPairs(): MakeDiffractionImage.addConstantQLineDiffractionImage(image,Q, calibrationData,qLinesColor) if drawdQLines: if dQLinesColor == None: raise Exception('Cannot add delta q lines to the saved image until the delta q line color is set.') for Q,dQ in QData.getAllQPairs(): MakeDiffractionImage.addConstantQLineDiffractionImage(image,Q-dQ, calibrationData,dQLinesColor) MakeDiffractionImage.addConstantQLineDiffractionImage(image,Q+dQ, calibrationData,dQLinesColor) if drawPeaks and peakList != None: if peakLinesColor == None: raise Exception("Cannot add peaks to the saved iamge until the peak color is set.") MakeDiffractionImage.addPeaksDiffractionImage(image,peakList,peakLinesColor) # by default, return entire image if pixel1X != None and pixel1Y != None and pixel2X != None and pixel2Y !=None: image = image.crop((min(int(pixel1X),int(pixel2X)), min(int(pixel1Y),int(pixel2Y)), max(int(pixel1X),int(pixel2X)), max(int(pixel1Y),int(pixel2Y)))) try: image.save(filename) except Exception,e: raise UserInputException("Cannot save image: %s has an unknown file extension" % filename )
def saveCakeImage(self, filename, calibrationData, qLower, qUpper, numQ, chiLower, chiUpper, numChi, doPolarizationCorrection, P, maskedPixelInfo, colorMaps, colorMapName, lowerBound, upperBound, logScale=None, invert=None, drawQLines=None, drawdQLines=None, QData=None, drawPeaks=None, peakList=None, qLinesColor=None, dQLinesColor=None, peakLinesColor=None): image = self.getCakeImage( calibrationData=calibrationData, qLower=qLower, qUpper=qUpper, numQ=numQ, chiLower=chiLower, chiUpper=chiUpper, numChi=numChi, doPolarizationCorrection=doPolarizationCorrection, P=P, maskedPixelInfo=maskedPixelInfo, width=None, height=None, colorMaps=colorMaps, colorMapName=colorMapName, lowerBound=lowerBound, upperBound=upperBound, logScale=logScale, invert=invert) if drawQLines or drawdQLines: if QData == None: raise Exception( "Cannot save the cake data until a q list is given.") if drawQLines: if qLinesColor == None: raise Exception( 'Cannot add q lines to the saved image until the q line color is set.' ) for Q, dQ in QData.getAllQPairs(): Cake.addConstantQLineCakeImage(image, Q, qLower, qUpper, numQ, chiLower, chiUpper, numChi, qLinesColor) if drawdQLines: if dQLinesColor == None: raise Exception( 'Cannot add delta q lines to the saved image until the delta q line color is set.' ) for Q, dQ in QData.getAllQPairs(): Cake.addConstantQLineCakeImage(image, Q - dQ, qLower, qUpper, numQ, chiLower, chiUpper, numChi, dQLinesColor) Cake.addConstantQLineCakeImage(image, Q + dQ, qLower, qUpper, numQ, chiLower, chiUpper, numChi, dQLinesColor) if drawPeaks and peakList != None: if peakLinesColor == None: raise Exception( "Cannot add peaks to the saved iamge until the peak color is set." ) smallest = self.getSmallestRange(calibrationData) Cake.addPeaksCakeImage(image, qLower, qUpper, numQ, chiLower, chiUpper, numChi, peakList, calibrationData, peakLinesColor, smallestRangeQLower=smallest['qLower'], smallestRangeQUpper=smallest['qUpper'], smallestRangeChiLower=smallest['chiLower'], smallestRangeChiUpper=smallest['chiUpper']) try: image.save(filename) except Exception, e: raise UserInputException( "Cannot save the cake: %s has an unknown file extension" % filename)
def saveCakeImage(self, filename, calibrationData, qOrTwoThetaLower, qOrTwoThetaUpper, numQOrTwoTheta, chiLower, chiUpper,numChi, doPolarizationCorrection,P,maskedPixelInfo, colorMaps, colorMapName, lowerBound, upperBound,type, doScaleFactor, scaleFactor, setMinMax, minIntensity, maxIntensity, logScale=None, invert=None, drawQOrTwoThetaLines=None, drawdQOrTwoThetaLines=None, QData=None, drawPeaks=None, peakList=None, qOrTwoThetaLinesColor=None, dQOrTwoThetaLinesColor=None, peakLinesColor=None): image = self.getCakeImage( calibrationData=calibrationData, qOrTwoThetaLower=qOrTwoThetaLower, qOrTwoThetaUpper=qOrTwoThetaUpper, numQOrTwoTheta=numQOrTwoTheta, chiLower=chiLower, chiUpper=chiUpper, numChi=numChi, doPolarizationCorrection=doPolarizationCorrection, P=P, maskedPixelInfo=maskedPixelInfo, width=None, height=None, colorMaps=colorMaps, colorMapName=colorMapName, lowerBound=lowerBound, upperBound=upperBound, logScale=logScale, invert=invert, type=type, doScaleFactor=doScaleFactor, scaleFactor=scaleFactor, setMinMax=setMinMax, minIntensity=minIntensity, maxIntensity=maxIntensity) if drawQOrTwoThetaLines or drawdQOrTwoThetaLines: if QData == None: raise Exception("Cannot save the cake data until \ a Q list is given.") if drawQOrTwoThetaLines: if qOrTwoThetaLinesColor == None: raise Exception("Cannot add Q lines to the \ saved image until the Q line color is set.") for Q,dQ in QData.getAllQPairs(): Cake.addConstantQLineCakeImage(image,Q,qOrTwoThetaLower, qOrTwoThetaUpper,numQOrTwoTheta,chiLower,chiUpper,numChi, qOrTwoThetaLinesColor,calibrationData,type) if drawdQOrTwoThetaLines: if dQOrTwoThetaLinesColor == None: raise Exception("Cannot add delta QOrTwoTheta lines to the saved \ image until the delta QOrTwoTheta line color is set.") for Q,dQ in QData.getAllQPairs(): Cake.addConstantQLineCakeImage(image,Q-dQ,qOrTwoThetaLower, qOrTwoThetaUpper,numQOrTwoTheta,chiLower,chiUpper, numChi,dQOrTwoThetaLinesColor,calibrationData,type) Cake.addConstantQLineCakeImage(image,Q+dQ,qOrTwoThetaLower, qOrTwoThetaUpper,numQOrTwoTheta,chiLower,chiUpper, numChi,dQOrTwoThetaLinesColor,calibrationData,type) if drawPeaks and peakList != None: if peakLinesColor == None: raise Exception("Cannot add peaks to the saved image \ until the peak color is set.") smallest = self.getSmallestRange(calibrationData,type) Cake.addPeaksCakeImage(image,qOrTwoThetaLower,qOrTwoThetaUpper, numQOrTwoTheta,chiLower,chiUpper,numChi, peakList,calibrationData,peakLinesColor, smallestRangeQOrTwoThetaLower = smallest["qOrTwoThetaLower"], smallestRangeQOrTwoThetaUpper = smallest["qOrTwoThetaUpper"], smallestRangeChiLower = smallest["chiLower"], smallestRangeChiUpper = smallest["chiUpper"], maskedPixelInfo = maskedPixelInfo, type = type) try: image.save(filename) except Exception,e: raise UserInputException("Cannot save the cake: %s has an \ unknown file extension" % filename )
def saveDiffractionImage(self, filename, colorMaps, colorMapName, maskedPixelInfo, pixel1X=None, pixel1Y=None, pixel2X=None, pixel2Y=None, lowerBound=0, upperBound=1, logScale=None, invert=None, drawQLines=None, drawdQLines=None, QData=None, calibrationData=None, drawPeaks=None, peakList=None, qLinesColor=None, dQLinesColor=None, peakLinesColor=None): # save EDF data specially if getextension(filename) == ".edf": edf = EdfFile(filename) #You can write any relevant information in the dictionnary. edf.WriteImage( { 'Title': "Edf file converted by the Area Diffraction Machine" }, Numeric.transpose(self.theDiffractionData.data), DataType="SignedInteger", Append=0) del edf # to force file close return # otherwise, try to save it using the PIL image = self.getDiffractionImage(colorMaps, colorMapName, maskedPixelInfo, None, None, None, None, None, None, lowerBound, upperBound, logScale, invert) if drawQLines or drawdQLines: if QData == None: raise Exception( "Cannot save the diffraction data until a q list is given." ) if calibrationData == None: raise Exception( "Cannot save the diffraction data until the calibration Data is given." ) if drawQLines: if qLinesColor == None: raise Exception( 'Cannot add q lines to the saved image until the q line color is set.' ) for Q, dQ in QData.getAllQPairs(): MakeDiffractionImage.addConstantQLineDiffractionImage( image, Q, calibrationData, qLinesColor) if drawdQLines: if dQLinesColor == None: raise Exception( 'Cannot add delta q lines to the saved image until the delta q line color is set.' ) for Q, dQ in QData.getAllQPairs(): MakeDiffractionImage.addConstantQLineDiffractionImage( image, Q - dQ, calibrationData, dQLinesColor) MakeDiffractionImage.addConstantQLineDiffractionImage( image, Q + dQ, calibrationData, dQLinesColor) if drawPeaks and peakList != None: if peakLinesColor == None: raise Exception( "Cannot add peaks to the saved iamge until the peak color is set." ) MakeDiffractionImage.addPeaksDiffractionImage( image, peakList, peakLinesColor) # by default, return entire image if pixel1X != None and pixel1Y != None and pixel2X != None and pixel2Y != None: image = image.crop( (min(int(pixel1X), int(pixel2X)), min(int(pixel1Y), int(pixel2Y)), max(int(pixel1X), int(pixel2X)), max(int(pixel1Y), int(pixel2Y)))) try: image.save(filename) except Exception, e: raise UserInputException( "Cannot save image: %s has an unknown file extension" % filename)