Example #1
0
	def calibrateEnergy(self):
		if self.peakData == None:
			print 'Add a gaussian fit first, before trying to calibrate energy'
		else:
			showCorrelateEnergyDialog(self.peakData, self.processCalibratedEnergy)
	def processCalibratedEnergy(self, energyCalibrationData):
		self.peakData = TestData(['Param','Peak','PeakErr'],[], [],[]) #reset peak data
		#print [{	'params' : f['params'], 'fit_errors' : f['fit_errors'], 'energy' : f['energy'], 'interval' : getIntervalString(f['interval'])}for f in fitData]
		self.currentEnergyCalibrationFit = processAndPlotEnergyCalibrationData(energyCalibrationData)
		self.saveSelectedGaussianFits()
		self.saveEnergyCalibration()
	def saveEnergyCalibration(self):
		fit = self.currentEnergyCalibrationFit
		f = open(os.path.join(config.energyFitDir, self.basefilename + config.energyFitDataSuffix + '.txt'), 'w')
		f.write(fit.text(config.tabWidth))
		f.close()
		f = open(os.path.join(config.energyFitDir, self.basefilename + config.energyFitCsvSuffix + '.csv'), 'w')
		f.write(fit.params.text(fieldSeparator=';'))
		f.close()
		print 'Energy calibration saved'

if __name__ == '__main__': #means it's only gonna work when run from the command line
	#Start script
	datafilename = config.datafile
	bkgfilename = config.backgroundfile
	data = loadTestFileWithBackgroundAndCalculateCountErr(datafilename, bkgfilename, config.durationRegex)
	basefilename = os.path.basename(datafilename)[0:-4] #basename gets just the filename, [0:-4] gets the part without the extension
	mgc = MainGuiController(data, basefilename, config.datastart, config.dataend)
	mgc.printInstructions(intro="Remember: its:", prefix='\t')
	mgc.show()
Example #2
0
		
	def show(self):
		plt.show()

	#Callback functions
	def addTestData(self): 
		pass
	def deleteLastPlot(self):
		pass
	
	#Handle key presses
	def handle_key(self, event):
		if event.key in ['A', 'a']:
			addTestData()
		elif event.key in ['D', 'd']:
			deleteLastPlot()
		else:
			print 'Detected keypress {0}, unknown command'.format(event.key)



if __name__ == '__main__':
	mgc = MainGuiController()
	mgc.init(config.datastart, config.dataend)
	mgc.setTitle(config.title)
	for (filepath, background, label, fmt) in config.inputfiles:
		data = loadTestFileWithBackgroundAndCalculateCountErr(filepath, background, config.durationRegex, config.rescaletoduration)
		mgc.addPlot(data, label, fmt)
	mgc.generateLegend()
	mgc.show()