示例#1
0
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
示例#2
0
def fitGaussianAndAddToPlotOdr(interval, xfield, x, y, x_err, y_err, startingGaussianParameters, max_iterations, fig, axes, nb_of_fits, config, label):
	countSum = numpy.sum(y)
	
	output = fitFunctionOdr(x, y, x_err, y_err, fitFunction=gaussianOdr, startingParameters=startingGaussianParameters)
	params = output.beta
	param_std_dev = output.sd_beta #seems to calculated this for us already	
	print 'Params: ', params, '\nParam Std Dev: ', param_std_dev
#	(a,b,c) = params
#	(err_a, err_b, err_c) = fit_errors
	gaussParams = FitData(TestData(['Param','Value','Std Dev'], ['a','b','c'], params, param_std_dev), output.cov_beta, interval, xfield, residualVariance=output.res_var, inverseConditionNumber=output.inv_condnum, relativeError=output.rel_error, haltingReasons='\n'.join(output.stopreason))
#	gaussParams = ({'a':a, 'b':b, 'c':c},variance_matrix,{'a':err_a, 'b':err_b, 'c':err_c},countSum)
	fittedGaussian = fittedOdrFunction(gaussianOdr, params)
	addFunctionToPlot(axes, x, fittedGaussian, fmt=config.gaussianfitformats[nb_of_fits%len(config.gaussianfitformats)], label=label)
	axes.legend()
	fig.show()
	return (gaussParams, countSum)