def getCakeImage(self, calibrationData, qLower, qUpper, numQ, chiLower, chiUpper, numChi, doPolarizationCorrection, P, maskedPixelInfo, width, height, colorMaps, colorMapName, lowerBound, upperBound, logScale=None, invert=None): data = Cake.Cake(self.theDiffractionData.data, calibrationData, qLower, qUpper, numQ, chiLower, chiUpper, numChi, doPolarizationCorrection, P, maskedPixelInfo) image = data.getImage(lowerBound, upperBound, logScale, colorMaps, colorMapName, invert) # change width and height of image if width == None or height == None: return image return image.resize((width, height), Image.BILINEAR)
def setUp(self): ingredients1 = [ "chocolate", "cocoa powder", "flour", "eggs", "sugar", "butter" ] cake1 = Cake("Brownie", ingredients1, 5) ingredients2 = [ "carrots", "raisins", "cinnamon", "flour", "eggs", "sugar", "butter" ] cake2 = Cake("Carrot Cake", ingredients2, 2.5) ingredients3 = ["lemon juice", "flour", "eggs", "sugar", "butter"] cake3 = Cake("Lemon Drizzle", ingredients3, 1.5) cakes = [cake1, cake2, cake3] self.cake_shop = CakeShop(cakes)
def saveCakeData(self, filename, calibrationData, qLower, qUpper, numQ, chiLower, chiUpper, numChi, doPolarizationCorrection, P, maskedPixelInfo): data = Cake.Cake(diffractionData=self.theDiffractionData.data, calibrationData=calibrationData, qLower=qLower, qUpper=qUpper, numQ=numQ, chiLower=chiLower, chiUpper=chiUpper, numChi=numChi, doPolarizationCorrection=doPolarizationCorrection, P=P, maskedPixelInfo=maskedPixelInfo) data.toFile(filename, self.theDiffractionData.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 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 setUp(self): ingredients1 = ["chocolate", "cocoa powder", "flour", "eggs", "sugar", "butter"] self.cake = Cake("Brownie", ingredients1, 5)