def processAndPlotEnergyCalibrationData(energyCalibrationData): x = energyCalibrationData['Peak'] x_err = energyCalibrationData['PeakErr'] y = energyCalibrationData['Energy'] y_err = energyCalibrationData['EnergyErr'] (fig, axes) = createEmptyPlottingArea(config.energy_x_axis_label, config.energy_y_axis_label, fontsize = config.fontsize, figWidth=config.plotwidth, figHeight=config.plotheight) axes.set_title(config.energytitle) addDataWithErrorBarsToPlot(axes, x, y, x_err=x_err, y_err=y_err, fmt=config.energyplotformat, label=config.energyplotlabel) axes.legend() fig.show() #find fit for energy calibration output = fitFunctionOdr(x, y, x_err, y_err, fitFunction=lineOdr, startingParameters=[0.2,10.0]) params = output.beta param_std_dev = output.sd_beta #seems to calculated this for us already print (params, param_std_dev) energyCalibrationFit = FitData(TestData(['Param','Value','Std Dev'], ['a','b'], params, param_std_dev), output.cov_beta, energyCalibrationData, 'Peak', residualVariance=output.res_var, inverseConditionNumber=output.inv_condnum, relativeError=output.rel_error, haltingReasons='\n'.join(output.stopreason)) (a,b) = params #fits for line fittedLine = fittedOdrFunction(lineOdr, params) addFunctionToPlot(axes, x, fittedLine, config.energyfitplotformat, label=config.energyfitplotlabel) axes.legend() fig.show() return energyCalibrationFit
def __init__(self, testData, xfield, xerrfield, yfield, yerrfield, basefilename, start, end, xAxisLabel, yAxisLabel, x_majorticks = -1, x_minorticks = -1, x_length=10000, y_majorticks = -1, y_minorticks = -1, y_length=10000, fontsize=14, extraKeybindings = None, config=None, figWidth=16, figHeight=10): self.testData = testData internalKeyBindings = { 'c': (self.toggleSpanSelector, "'c' to start the selector. Drag and drop over the area. The selection will show up in commandline. You can keep selecting until the desired invertal is selected. Click C again to stop the selector (useful when zooming in). You only need to click 'c' once to start the selector."), 'g': (self.choosecurrentStartEndForGaussianFit,"'g' to run the Gaussian fit for the current selection. Press 'g' again without making a new selection to run again (you can change starting values and iterations). Select the next peak and press 'g'."), 'a': (self.addGaussianToList,"'a' to Add the gaussian fit for later calculations."), } if extraKeybindings != None: keybindings = dict(internalKeyBindings.items() + extraKeybindings.items()) else: keybindings = internalKeyBindings super(InteractiveGaussianFitTestDataFigure, self).__init__(keybindings, figsize=(figWidth, figHeight)) self.axes = addSinglePlottingArea(self.fig, xAxisLabel, yAxisLabel, x_majorticks, x_minorticks, x_length, y_majorticks, y_minorticks, y_length, fontsize) self.xfield = xfield self.xerrfield = xerrfield self.yfield = yfield self.yerrfield = yerrfield self.testData = testData self.basefilename = basefilename self.config = config self.axes.set_title(config.testdatatitle) x = testData[self.xfield][start:end] y = testData[self.yfield][start:end] if self.xerrfield != None: x_err = testData[self.xerrfield][start:end] else: x_err = None if self.yerrfield != None: y_err = testData[self.yerrfield][start:end] else: y_err = None addDataWithErrorBarsToPlot(self.axes, x, y, x_err=x_err, y_err=y_err, fmt=config.testdataplotformat, label=config.testdatalabel) # extrema = [(x[i],y[i]) for i in argrelmax(numpy.array(y), order=config.extremaOrder)[0]] #argrelmax gives the index of the maximums found in the array # for point in extrema: # self.axes.annotate('Max', point) self.axes.legend()
def addPlot(self, data, label, fmt, start=-1, end=-1): if start == -1: start = self.start if end == -1: end = self.end addDataWithErrorBarsToPlot(self.axes, data['Energy'][start:end], data['Count'][start:end], x_err=data['EnergyErr'][start:end], y_err=data['CountErr'][start:end], fmt=fmt, label=label)