예제 #1
0
파일: gui.py 프로젝트: rick-mukherjee-z/cvu
    def _load_parcellation_check(self):
        pcw = self.parcellation_chooser_window
        if not pcw.finished: return
        if pcw.ctl.new_dataset:
            if pcw.ctl.new_dataset_name == '':
                self.error_dialog('Must specify a dataset name!')
                return
            elif pcw.ctl.new_dataset_name in self.controller.ds_instances:
                self.error_dialog('Dataset name is not unique')
                return
            else:
                ds_name = pcw.ctl.new_dataset_name
                import preprocessing
                parc_struct = preprocessing.process_parc(pcw.ctl, self)
                if parc_struct is None: return  #preprocessing errored out

                lab_pos, labnam, srf, labv, subject_name, parc_name = parc_struct

                display_metadata = DisplayMetadata(subject_name=subject_name,
                                                   parc_name=parc_name,
                                                   adj_filename='')
                ds = Dataset(ds_name, lab_pos, labnam, srf, labv, gui=self)
                self.controller.add_dataset(ds, display_metadata)
        else:
            import preprocessing
            parc_struct = preprocessing.process_parc(pcw.ctl, self)
            if parc_struct is None: return

            lab_pos, labnam, srf, labv, subject_name, parc_name = parc_struct
            pcw.ctl.ds_ref._load_parc(lab_pos, labnam, srf, labv)
            self.controller.update_display_metadata(pcw.ctl.ds_ref.name,
                                                    subject_name=subject_name,
                                                    parc_name=parc_name)

            #find the viewports that were previously holding this scene
            #find_dataset_views returns a DatasetViewportInterface object
            #with references to the viewports (source in viewport.py)
            ds_interface = self.controller.find_dataset_views(pcw.ctl.ds_ref)
            ds_interface.mayavi_port = Viewport(pcw.ctl.ds_ref)
            ds_interface.matrix_port = Viewport(pcw.ctl.ds_ref)
            ds_interface.circle_port = Viewport(pcw.ctl.ds_ref)
예제 #2
0
파일: gui.py 프로젝트: mick-d/cvu
	def _load_parcellation_check(self):
		pcw=self.parcellation_chooser_window
		if not pcw.finished: return
		if pcw.ctl.new_dataset:
			if pcw.ctl.new_dataset_name=='':
				self.error_dialog('Must specify a dataset name!'); return
			elif pcw.ctl.new_dataset_name in self.controller.ds_instances:
				self.error_dialog('Dataset name is not unique'); return	
			else:
				ds_name = pcw.ctl.new_dataset_name
				import preprocessing
				parc_struct=preprocessing.process_parc(pcw.ctl,self)
				if parc_struct is None: return #preprocessing errored out
				
				lab_pos,labnam,srf,labv,subject_name,parc_name=parc_struct

				display_metadata=DisplayMetadata(subject_name=subject_name,
					parc_name=parc_name,adj_filename='')
				ds=Dataset(ds_name,lab_pos,labnam,srf,labv,gui=self)
				self.controller.add_dataset(ds,display_metadata)
		else:
			import preprocessing	
			parc_struct=preprocessing.process_parc(pcw.ctl,self)
			if parc_struct is None: return	

			lab_pos,labnam,srf,labv,subject_name,parc_name=parc_struct
			pcw.ctl.ds_ref.load_parc(lab_pos,labnam,srf,labv)
			self.controller.update_display_metadata(pcw.ctl.ds_ref.name,
				subject_name=subject_name, parc_name=parc_name)

			#find the viewports that were previously holding this scene
			#find_dataset_views returns a DatasetViewportInterface object
			#with references to the viewports (source in viewport.py)
			ds_interface=self.controller.find_dataset_views(pcw.ctl.ds_ref)	
			ds_interface.mayavi_port = Viewport(pcw.ctl.ds_ref)
			ds_interface.matrix_port = Viewport(pcw.ctl.ds_ref)
			ds_interface.circle_port = Viewport(pcw.ctl.ds_ref)
예제 #3
0
def load_parc(parcellation, ordering, new_dataset=False, dataset_name = None,
        dataset=None,
        subjects_dir='.', subject='fsavg5', surface_type='pial'):
    '''
    Loads a parcellation, either onto a dataset or creating a new dataset.
    This function is a scripting helper. In other words,
    instead of clicking on the GUI or simulating button presses, this
    function is provided for scripting purposes to just simulate the
    process of loading a parcellation.

    Parameters
    ----------

    parcellation : str
        The parcellation name. For instance, if your parcellation's annotation
        files are called lh.aparc.annot, the parcellation name is 'aparc'.
        Similarly if the annotation file is called lh.aparc.gii, enter 'aparc'.
    ordering : str | list(str)
        The name of a text file containing the parcellation ordering.
        Alternately, a list of label names.
    new_dataset : bool
        If True, spawns a new dataset instead of placing the parcellation on
        an existing dataset. Default value is False.
    dataset_name : str | None
        Required if and only if new_dataset is True.
        If new_dataset is True, specifies the name of the new dataset.
        Otherwise, has no effect.
    dataset : instance(cvu.dataset.Dataset) | None
        Required if and only if new_dataset is False.
        If new_dataset is False, specifies the dataset onto which to load this
        parcellation. If new_dataset is True, has no effect.
    subjects_dir : str
        The superordinate directory used to load the annotation, surface,
        and segmentation files at $SUBJECTS_DIR/$SUBJECT/{surf|label|mri}/* .
        The default value is '.', the current working directory. Under
        normal circumstances this is the working directory relative to cvu's
        main.py file, which is /path/to/cvu/cvu.
    subject : str
        The subject name used to load the annotation, surface, and segmentation
        files at $SUBJECTS_DIR/$SUBJECT/{surf|label|mri}/*
        The default value is 'fsavg5'. Some files for fsavg5 are provided in
        the cvu installation.
    surface_type
        The surface to load. The default value is 'pial'.

    Returns
    -------
    dataset : instance(cvu.dataset.Dataset)
        The instance of the dataset now holding this parcellation. Helpful
        if new_dataset is True.
    '''
    gui = globals()['self']        #explicitly allow dynamic scope
    err_handler = ErrorHandler(quiet=True)

    from preprocessing import process_parc
    from options_struct import ParcellationChooserParameters
    from utils import DisplayMetadata
    from dataset import Dataset

    if new_dataset and dataset_name is None:
        print "Must specify a dataset name!"
        return
    elif new_dataset and dataset_name in gui.controller.ds_instances:
        print "Dataset name is not unique"
        return
    elif not new_dataset and not isinstance(dataset, Dataset):
        print "Must either supply an existing dataset or create a new one"
        return

    parc_params = ParcellationChooserParameters( ds_ref = dataset,
        new_dataset = new_dataset,
            new_dataset_name = dataset_name if dataset_name is not None else '',
        subjects_dir = subjects_dir,
        subject = subject, surface_type = surface_type, 
        labelnames_file = ordering, parcellation_name = parcellation)
    parc_struct = process_parc(parc_params, err_handler)
    if parc_struct is None: return #preprocessing errored out

    lab_pos, labnam, srf, labv, _, _ = parc_struct
    if new_dataset:
        display_metadata = DisplayMetadata(subject_name = subject,
            parc_name = parcellation, adj_filename='')
        dataset = Dataset(dataset_name, lab_pos, labnam, srf, labv, gui=gui)
        gui.controller.add_dataset(dataset, display_metadata)

    else:
        from viewport import Viewport

        dataset._load_parc(lab_pos, labnam, srf, labv)
        gui.controller.update_display_metadata(dataset.name, 
            subject_name = subject, parc_name = parcellation)

        #update the viewports associated with this dataset
        ds_interface = gui.controller.find_dataset_views(dataset)
        ds_interface.mayavi_port = Viewport(dataset)
        ds_interface.matrix_port = Viewport(dataset)
        ds_interface.circle_port = Viewport(dataset)

    return dataset