Exemple #1
0
	def onButtonCheckPOIs(self, event):
		dir0          = os.path.join(self.dir0, 'dbrr')
		if not os.path.exists(dir0):
			wx.MessageBox('Registration must be conducted and parameters applied before checking POIs.', 'Error:', wx.OK)
		if not os.path.exists(   os.path.join(self.dir0, '_poi.npy')   ):
			wx.MessageBox('POIs must be defined before checking.\nUse the "POI analysis" button to define POIs', 'Error:', wx.OK)
		else:
			self.metadata = DB.load_metadata(self.dir0)
			POI           = self.metadata.load_pois()
			allnone       = True
			for poi in POI:
				for p in poi:
					if p!=None:
						allnone = False
						break
			if allnone:
				wx.MessageBox('Warning:  No POIs defined.\nUse the "POI analysis" button to define POIs', 'Error:', wx.OK)
			else:
				dialog        = ppp_selector.PPDatabaseQueryDialog(self.metadata, by_foot=True)
				dialog.ShowModal()
				subj          = None
				if not dialog.canceled:
					canceled  = dialog.canceled
					if not canceled:
						subj,byfoot,LR,FH,alltrials,trials = dialog.get_choices()
				dialog.Destroy()
				if subj!=None:
					subjname  = self.metadata.USUBJ[subj]
					footlabel = self.metadata.get_foot_label(LR, FH)
					frame     = checkpoiGUI.CheckPOIFrame(None, -1, 'PPP Check POIs (%s: %s)'%(subjname,footlabel), metadata=self.metadata, subj=subj, LR=LR, FH=FH)
				 	frame.Show(True)
Exemple #2
0
	def onButtonExportMeans(self, event):
 		dir0          = os.path.join(self.dir0, 'dbrr')
		if not os.path.exists(dir0):
			wx.MessageBox('Registration must be conducted and parameters applied before exporting COP trajectories.', 'Error:', wx.OK)
		else:
			result        = wx.MessageBox('Computing means may take several minutes.\nPress OK to continue.', 'Note:', wx.OK|wx.CANCEL)
			if result == wx.OK:
				dir1          = os.path.join(self.dir0, 'dbmeans')
				if not os.path.exists(dir1):
					os.mkdir(dir1)
				dialog    = wx.ProgressDialog("", "Computing means and saving to ./dbmeans...", maximum=4*self.metadata.nSubj, style=wx.PD_ELAPSED_TIME)
				self.metadata = DB.load_metadata(self.dir0)
				ii = 0
				for subj in range(self.metadata.nSubj):
					i     = 0
					for FH in [False,True]:
						for LR in [False,True]:
							rollovers = self.metadata.get_rollovers(subj, LR=LR, FH=FH, only_good=True)
							II        = self.metadata.load_rollovers(rollovers, dbdir='dbrr', max=True)
							II        = np.dstack(II)
							I         = II.mean(axis=2)
							fname1    = os.path.join(dir1, 'subj%03d_mean%d.h5'%(subj,i))
							PM.save(fname1, I)
							dialog.Update(ii)
							i += 1
							ii += 1
				dialog.Destroy()
Exemple #3
0
	def onButtonCheckMeans(self, event):
 		dir0          = os.path.join(self.dir0, 'dbmeans')
		if not os.path.exists(dir0):
			wx.MessageBox('Means not yet computed.\nUse "Export means" from the main menu.', 'Error:', wx.OK)
		else:
			self.metadata = DB.load_metadata(self.dir0)
			frame = checkmeansGUI.CheckMeansFrame(None, -1, 'PPP Check Means', metadata=self.metadata)
			frame.Show(True)
Exemple #4
0
	def onButtonPOI(self, event):
		if not os.path.exists(  os.path.join(self.dir0, 'dbmeans')  ):
			wx.MessageBox('Mean images must be exported before conducting POI analysis.', 'Error:', wx.OK)
		else:
			self.metadata = DB.load_metadata(self.dir0)
			if not os.path.exists( os.path.join(self.dir0, '_poi.npy')  ):
				self.metadata.save_pois()
			frame = poiGUI.POIFrame(None, -1, 'PPP POI Selector', metadata=self.metadata)
			frame.Show(True)
Exemple #5
0
	def OnInit(self):
		import pressure_database as DB;  reload(DB)
		# dir0     = '/Volumes/DataProc/projectsExternal/uQueensland/test2/'
		dir0     = '/Users/todd/Desktop/test2'
		metadata = DB.load_metadata(dir0)
		subj = 0
		frame = POIFrame(None, -1, 'Points of Interest (POIs)', metadata=metadata)
		frame.Show(True)
		self.SetTopWindow(frame)
		return True
Exemple #6
0
	def onButtonCheckFeet(self, event):
		metadata      = DB.load_metadata(self.dir0)
		self.metadata = metadata
		dialog        = ppp_selector.PPDatabaseQueryDialog(metadata, by_foot=True, only_good=True)
		dialog.ShowModal()
		rollovers = None
		if not dialog.canceled:
			rollovers = dialog.get_rollovers()
		dialog.Destroy()
		if rollovers!=None:
			frame = checkfeetGUI.CheckFeetFrame(None, -1, 'PPP Check Foot Labels', metadata=metadata, rollovers=rollovers)
			frame.Show(True)
Exemple #7
0
 def OnInit(self):
     import pressure_database as DB
     reload(DB)
     # dir0     = '/Volumes/DataProc/projectsExternal/uQueensland/test2/'
     dir0 = '/Users/todd/Desktop/test2'
     metadata = DB.load_metadata(dir0)
     subj = 0
     frame = POIFrame(None,
                      -1,
                      'Points of Interest (POIs)',
                      metadata=metadata)
     frame.Show(True)
     self.SetTopWindow(frame)
     return True
Exemple #8
0
	def onButtonIdentify(self, event):
		if not os.path.exists(  os.path.join(self.dir0, 'dbr') ):
			result = wx.MessageBox('Images must be resized before idenitfying feet.\nSelect "Resize image grids" from the main menu.', 'Error.', wx.OK)
			return
		self.metadata = DB.load_metadata(self.dir0)
		dialog        = ppp_selector.PPDatabaseQueryDialog(self.metadata, by_trial=True)
		dialog.ShowModal()
		rollovers = None
		if not dialog.canceled:
			rollovers = dialog.get_rollovers(group_by_trial=True)
		dialog.Destroy()
		if rollovers!=None:
			frame = identifyGUI.IdentifyFrame(None, -1, 'PPP Foot Identificaiton', metadata=self.metadata, rollovers=rollovers)
			frame.Show(True)
Exemple #9
0
	def onButtonTemplates(self, event):
		metadata      = DB.load_metadata(self.dir0)
		labels        = ['Fore Left', 'Fore Right', 'Hind Left', 'Hind Right']
		### check that good feet are available for all subjects:
		for subj in range(metadata.nSubj):
			n = metadata.get_nrollovers_by_subj(subj, only_good=True)
			if np.any( np.array(n)<1 ):
				ind    = np.argwhere(np.array(n)<1).flatten()
				ind    = ind[0]
				label  = labels[ind]
				result = wx.MessageBox('No good rollovers found for subject "%s", foot: "%s".\nYou must identify at least one good rollover to proceed.'%(metadata.USUBJ[subj], label), 'Error', wx.OK)
				return None
		self.metadata = metadata
		frame = templateGUI.TemplateFrame(None, -1, 'PPP Template Selection', metadata=metadata)
		frame.Show(True)
Exemple #10
0
	def onButtonRegister(self, event):
		self.metadata = DB.load_metadata(self.dir0)
		if not os.path.exists( os.path.join(self.dir0, '_registration_params.npy')  ):
			self.metadata.save_registration_parameters()
		dialog        = ppp_selector.PPDatabaseQueryDialog(self.metadata, by_foot=True)
		dialog.ShowModal()
		subj          = None
		if not dialog.canceled:
			canceled  = dialog.canceled
			if not canceled:
				subj,byfoot,LR,FH,alltrials,trials = dialog.get_choices()
		dialog.Destroy()
		if subj!=None:
			subjname  = self.metadata.USUBJ[subj]
			footlabel = self.metadata.get_foot_label(LR, FH)
			frame    = registrationGUI.RegistrationFrame(None, -1, 'PPP Registration (%s: %s)'%(subjname,footlabel), metadata=self.metadata, subj=subj, LR=LR, FH=FH)
			frame.Show(True)
Exemple #11
0
	def onButtonCheckRegistration(self, event):
 		dir0          = os.path.join(self.dir0, 'dbrr')
		if not os.path.exists(dir0):
			wx.MessageBox('Registration must be conducted and parameters applied before checking registration.', 'Error:', wx.OK)
		else:
			self.metadata = DB.load_metadata(self.dir0)
			dialog        = ppp_selector.PPDatabaseQueryDialog(self.metadata, by_foot=True)
			dialog.ShowModal()
			subj          = None
			if not dialog.canceled:
				canceled  = dialog.canceled
				if not canceled:
					subj,byfoot,LR,FH,alltrials,trials = dialog.get_choices()
			dialog.Destroy()
			if subj!=None:
				subjname  = self.metadata.USUBJ[subj]
				footlabel = self.metadata.get_foot_label(LR, FH)
				frame     = checkregistrationGUI.CheckRegistrationFrame(None, -1, 'PPP Check Registration (%s: %s)'%(subjname,footlabel), metadata=self.metadata, subj=subj, LR=LR, FH=FH)
	 			frame.Show(True)
Exemple #12
0
	def onButtonApplyParams(self, event):
		result        = wx.MessageBox('All rollovers will now be transformed and saved in the "dbrr" director.\nThis process may take several minutes to complete.\n\nOK to proceed?', 'Note:', wx.OK|wx.CANCEL)
		if result==wx.OK:
			self.metadata = DB.load_metadata(self.dir0)
			PARAMS        = self.metadata.load_registration_params()
			dir0          = os.path.join(self.dir0, 'dbr')
			dir1          = os.path.join(self.dir0, 'dbrr')
			if not os.path.exists(dir1):
				os.mkdir(dir1)
			dialog    = wx.ProgressDialog("", "Transforming pressure time series and saving to ./dbrr...", maximum=self.metadata.nRollovers, style = wx.PD_ELAPSED_TIME)
			for i in range(self.metadata.nRollovers):
				dialog.Update(i)
				fname0    = os.path.join(dir0, 'rollover%05d.h5'%i)
				fname1    = os.path.join(dir1, 'rollover%05d.h5'%i)
				I         = PM.load(fname0)
				if np.any(   np.abs(PARAMS[i] - [0,0,0,1]) > 1e-5  ):
					I     = PM.transformXYRS(I, PARAMS[i])
				PM.save(fname1, I)
			dialog.Destroy()
Exemple #13
0
	def onButtonSetProjectDirectory(self, event):
		dir0   = None
		dialog = wx.DirDialog(self.parent, 'Select a directory...', self.dir0, style=wx.DD_DEFAULT_STYLE)
		if dialog.ShowModal() == wx.ID_OK:
			dir0 = dialog.GetPath()
		dialog.Destroy()
		### load metadata:
		if dir0!=None:
			self.dir0 = dir0
			self.settings.set_dir_project(dir0)
			self.parent.statusbar.SetStatusText(dir0, 1)
			for button in self.buttons[1:-1]:
				button.Enable(True)
			db        = DB.PressureDatabaseInitializer(dir0)
			db.check_initiated()
			db.check_for_other_files()
			if db.isinitiated:
				self.metadata = DB.load_metadata(dir0)
				self.metadata.dir0 = dir0
				self.metadata.save()
			else:
				db.assemble_xml_filenames()
				db.check_xml_filenames()
				metadataXML = db.parse_xml_filenames()
				result = wx.MessageBox('This project has not yet been initialized.\nInitialize now?\n\nNote: All XML files will be imported. This could take several minutes to complete.', 'Database initialization', wx.CANCEL | wx.OK)
				if result==wx.OK:
					importer  = DB.XMLImporter(metadataXML, False)
					dialog    = wx.ProgressDialog("", "Importing XML files...", maximum=importer.nFiles, style = wx.PD_CAN_ABORT | wx.PD_ELAPSED_TIME)
					keepGoing = True
					count     = 0
					while keepGoing and (count < importer.nFiles):
						keepGoing = dialog.Update(count)[0]
						importer.filenum = count
						importer.import_next()
						count += 1
					dialog.Destroy()
					### save metadata:
					metadataH5 = importer.finish()
					metadataH5.save()
					metadataH5.savexls()
					metadataH5.savexls_subjmetadata()
					metadataH5.save_template_choices()
Exemple #14
0
	def onButtonResize(self, event):
		result = wx.MessageBox('Resizing image grids can take several minutes to complete. Click OK to proceed.', 'Image resizing', wx.CANCEL | wx.OK)
		if result==wx.OK:
			metadata  = DB.load_metadata(self.dir0)
			dialog    = wx.ProgressDialog("", "Reading image sizes...", maximum=metadata.nRollovers, style = wx.PD_CAN_ABORT | wx.PD_ELAPSED_TIME)
			dirDB     = os.path.join(self.dir0, 'db')
			dirDBr    = os.path.join(self.dir0, 'dbr')
			if not os.path.exists(dirDBr):
				os.mkdir(dirDBr)
			fnames    = [os.path.join(dirDB, 'rollover%05d.h5'%i)   for i in range(metadata.nRollovers)]
			gs        = PM.find_max_grid(fnames)
			pad       = 5
			gs        = [gs[0]+2*pad, gs[1]+2*pad]
			keepGoing = dialog.Update(0, 'Resizing images...')[0]
			count     = 0
			for i,fname in enumerate(fnames):
				I     = PM.load(fname)
				I     = PM.resize(I,gs)
				keepGoing = dialog.Update(i)[0]
				fname1 = os.path.join( dirDBr, os.path.split(fname)[1]  )
				PM.save(fname1, I)
			dialog.Destroy()
Exemple #15
0
	def onButtonExportCOP(self, event):
 		dir0          = os.path.join(self.dir0, 'dbrr')
		if not os.path.exists(dir0):
			wx.MessageBox('Registration must be conducted and parameters applied before exporting COP trajectories.', 'Error:', wx.OK)
		else:
			dialog    = wx.ProgressDialog("", "Extracting COP trajectories and saving to ./dbcop...", maximum=4*self.metadata.nSubj, style=wx.PD_ELAPSED_TIME)
			self.metadata = DB.load_metadata(self.dir0)
			dir1          = os.path.join(self.dir0, 'dbcop')
			if not os.path.exists(dir1):
				os.mkdir(dir1)
			ii = 0
			for subj in range(self.metadata.nSubj):
				i     = 0
				for FH in [False,True]:
					for LR in [False,True]:
						rollovers = self.metadata.get_rollovers(subj, LR=LR, FH=FH, only_good=True)
						II        = self.metadata.load_rollovers(rollovers, dbdir='dbrr', max=False)
						R         = np.array([PM.extract_cop(I, interp=True, n=101)   for I in II])
						fname1    = os.path.join(dir1, 'subj%03d_cop%d.npy'%(subj,i))
						np.save(fname1, R)
						dialog.Update(ii)
						i += 1
						ii += 1
			dialog.Destroy()