Exemplo n.º 1
0
    def load_modules_or_scalars(self, params):
        if not params.mat:
            self.error_dialog('You must specify a valid matrix file')
            return
        if params.whichkind == 'scalars' and not params.measure_name:
            self.error_dialog('Cannot leave scalar name blank.  cvu uses '
                              'this value as a dictionary index')
            return

        import preprocessing
        try:
            ci = preprocessing.loadmat(params.mat,
                                       field=params.field_name,
                                       is_adjmat=False)
        except (CVUError, IOError) as e:
            self.error_dialog(str(e))
            return

        if params.mat_order:
            try:
                init_ord, bads = preprocessing.read_ordering_file(
                    params.mat_order)
            except (IndexError, UnicodeDecodeError) as e:
                self.error_dialog(str(e))
                return

            #delete the bads
            if not params.ignore_deletes:
                ci = np.delete(ci, bads)

            #perform the swapping
            try:
                ci_ord = preprocessing.adj_sort(init_ord, self.labnam)
            except CVUError as e:
                self.error_dialog(str(e))
                return
            except KeyError as e:
                self.error_dialog('Field not found: %s' % str(e))
                return
            ci = ci[ci_ord]

        try:
            ci = np.reshape(ci, (self.nr_labels, ))
        except ValueError as e:
            self.error_dialog('The %s file is of size %i after deletions, but '
                              'the dataset has %i regions' %
                              (params.whichkind, len(ci), self.nr_labels))
            return

        if params.whichkind == 'modules':
            import bct
            self.modules = bct.ci2ls(ci)
            self.nr_modules = len(self.modules)
        elif params.whichkind == 'scalars':
            self.save_scalar(params.measure_name, ci)
            params._increment_scalar_count()
Exemplo n.º 2
0
def preproc(args):
    import preprocessing as pp

    #load label names from specified text file for ordering
    labnam,_ = pp.read_ordering_file(args['parcorder'])
    
    #load adjacency matrix and put entries in order of labnam
    adj = pp.loadmat(args['adjmat'],args['field']) 
    adj = pp.flip_adj_ord(adj, args['adjorder'], labnam)

    #load surface for visual display
    surf_fname = os.path.join(
        args['subjdir'],args['subject'],'surf','lh.%s'%args['surftype'])
    srf, geom_format = pp.loadsurf(surf_fname,args['surftype'])

    #load parcellation and vertex positions
    labels = pp.loadannot(
        geom_format, 
        args['parc'], args['subject'], args['subjdir'], labnam=labnam,
        surf_type=args['surftype'], surf_struct=srf, quiet=args['quiet'])

    #calculate label positions from vertex positions
    if args['subject']=='fsavg5':
        lab_pos,labv = pp.calcparc(labels,labnam,quiet=args['quiet'],
            parcname=args['parc'])
    else:
        lab_pos,labv = pp.calcparc(labels,labnam,quiet=args['quiet'],
            parcname=args['parc'],subjdir=args['subjdir'],
            subject=args['subject'],
            lhsurf=srf.lh_verts,rhsurf=srf.rh_verts)

    dataset_name='sample_data'

    from utils import DisplayMetadata	
    sample_metadata=DisplayMetadata(subject_name=args['subject'],
        parc_name=args['parc'],adj_filename=args['adjmat'])

    from dataset import Dataset
    sample_dataset=Dataset(dataset_name,lab_pos,labnam,srf,labv,
        adj=adj,soft_max_edges=args['maxedges'],
        gui=ErrorHandler(args['quiet']))
    # pass an ErrorHandler as the current GUI to handle errors. Replace it later.
    # Package dataloc and modality into tuple for passing

    exec_script = args['script']
    
    return sample_dataset,sample_metadata,exec_script
Exemplo n.º 3
0
    def load_modules_or_scalars(self,params):
        if not params.mat:
            self.error_dialog('You must specify a valid matrix file'); return
        if params.whichkind=='scalars' and not params.measure_name:
            self.error_dialog('Cannot leave scalar name blank.  cvu uses '
                'this value as a dictionary index'); return

        import preprocessing
        try:
            ci=preprocessing.loadmat(params.mat, field=params.field_name, 
                is_adjmat=False)
        except (CVUError,IOError) as e: self.error_dialog(str(e)); return

        if params.mat_order:
            try:
                init_ord, bads = preprocessing.read_ordering_file(
                    params.mat_order)	
            except (IndexError,UnicodeDecodeError) as e:
                self.error_dialog(str(e)); return

            #delete the bads
            if not params.ignore_deletes:
                ci=np.delete(ci,bads)

            #perform the swapping
            try:
                ci_ord = preprocessing.adj_sort(init_ord, self.labnam)	
            except CVUError as e: self.error_dialog(str(e)); return
            except KeyError as e:
                self.error_dialog('Field not found: %s'%str(e)); return
            ci=ci[ci_ord]

        try:
            ci=np.reshape(ci,(self.nr_labels,))
        except ValueError as e:
            self.error_dialog('The %s file is of size %i after deletions, but '
                'the dataset has %i regions' %
                (params.whichkind, len(ci), self.nr_labels)); return

        if params.whichkind=='modules':	
            import bct
            self.modules=bct.ci2ls(ci)
            self.nr_modules=len(self.modules)
        elif params.whichkind=='scalars':
            self.save_scalar(params.measure_name,ci)
            params._increment_scalar_count()