def startdensity(self, widget): from meg import density from mri import img_nibabel as img from numpy import array, append, size, ones #import nifti gofscale = float(self.builder.get_object('entry1').get_text()) sigma = int(self.builder.get_object('entry2').get_text()) print self.builder.get_object("filechooserbutton2").get_filename() self.mrfilename = self.builder.get_object("filechooserbutton2").get_filename() #mr = nifti.NiftiImage(self.mrfilename) mr = img.loadimage(self.mrfilename) print 'loaded MRI',mr if self.itemselected == 'manual': points = array(eval(self.paired_item.get_text())) gof = ones(size(points,0)) if self.itemselected == 'selected': points = self.data_selected if self.itemselected == 'fileopen': from pdf2py import lA2array, readwrite from meg import dipole datafile = self.builder.get_object("fileopenitem").get_filename() print 'datafile=',datafile try: lA = lA2array.calc(datafile) except AttributeError: #probably not an MEG 4D file, try parsereport lA = dipole.parsereport(datafile) lA.dips[:,1:4] = lA.dips[:,1:4]/100 #xyz in meters (this is the units in the 4D,lA file) points = lA.dips[:,1:4]*1000 # units in mm gof_ind = lA.labels.index('GoF') gof = lA.dips[:,gof_ind] from meg import dipole2densitynifti self.dipoledensityimage = dipole2densitynifti.handler(points,mr,gofscale,gof,sigma) self.fcd = self.builder.get_object("filechooserdialog1") self.fcd.show() self.fcd.set_current_name('*dd.nii.gz') filter = gtk.FileFilter() filter.set_name("Nifti files") filter.add_pattern("*nii.gz") filter.add_pattern("*nii") self.fcd.add_filter(filter) #uridefault = self.fcd.set_uri(self.fcd.get_current_folder_uri()) self.fcd.set_uri('file://'+self.mrfilename) uridefault = self.fcd.get_current_folder_uri() print 'uri', uridefault self.fcd.set_uri(uridefault)
def startdensity(self, widget): from meg import density import nifti gofscale = float(self.builder.get_object('entry1').get_text()) sigma = int(self.builder.get_object('entry2').get_text()) print self.builder.get_object("filechooserbutton2").get_filename() self.mrfilename = self.builder.get_object("filechooserbutton2").get_filename() mr = nifti.NiftiImage(self.mrfilename) try: points = self.data_selected except AttributeError: from pdf2py import lA2array, readwrite from numpy import array, append, size from meg import dipole datafile = self.builder.get_object("filechooserbutton1").get_filename() print 'datafile=',datafile #if datafile[-2:] == 'lA': try: lA = lA2array.calc(datafile) except AttributeError: #probably not an MEG 4D file, try parsereport lA = dipole.parsereport(datafile) #lA.points = array([]) lA.dips[:,1:4] = lA.dips[:,1:4]/100 #xyz in meters (this is the units in the 4D,lA file) points = lA.dips[:,1:4]*1000 # units in mm gof_ind = lA.labels.index('GoF') gof = lA.dips[:,gof_ind] from meg import dipole2densitynifti self.dipoledensityimage = dipole2densitynifti.handler(points,mr,gofscale,gof,sigma) self.fcd = self.builder.get_object("filechooserdialog1") self.fcd.show() self.fcd.set_current_name('*dd.nii.gz') filter = gtk.FileFilter() filter.set_name("Nifti files") filter.add_pattern("*nii.gz") filter.add_pattern("*nii") self.fcd.add_filter(filter) #uridefault = self.fcd.set_uri(self.fcd.get_current_folder_uri()) self.fcd.set_uri('file://'+self.mrfilename) uridefault = self.fcd.get_current_folder_uri() print 'uri', uridefault self.fcd.set_uri(uridefault)