Example #1
0
    def load_centre_stage_file(self, yaml_name):
        """
        Load in centrer-specific annotation parameter list
        Parameters
        ----------
        yaml_name: str
            basename of annotation parameter file

        Returns
        -------
        dict


        """
        path = join(OPTIONS_DIR, yaml_name)
        opts = load_yaml(path)

        # Rename the param_1, param_2 keys with IMPC parameter key
        renamed = {}

        for k in list(opts['parameters']):

            new_key = opts['parameters'][k]['impc_id']
            renamed[new_key] = opts['parameters'][k]

        opts['parameters'] = renamed
        return opts['parameters']
Example #2
0
    def load_centre_stage_file(self, yaml_name):
        """
        Load in centrer-specific annotation parameter list
        Parameters
        ----------
        yaml_name: str
            basename of annotation parameter file

        Returns
        -------
        dict


        """
        path = join(OPTIONS_DIR, yaml_name)
        opts = load_yaml(path)

        # Rename the param_1, param_2 keys with IMPC parameter key
        renamed = {}

        for k in list(opts['parameters']):

            new_key = opts['parameters'][k]['impc_id']
            renamed[new_key] = opts['parameters'][k]

        opts['parameters'] = renamed
        return opts['parameters']
Example #3
0
    def __init__(self):
        # Add assert for default in options
        try:
            opts = load_yaml(OPTIONS_CONFIG_PATH)
        except OSError:
            logging.warning('could not open the annotations yaml file {}'.format(OPTIONS_CONFIG_PATH))
            raise
        self.opts = opts
        self.available_options = self.opts['available_options']

        for center in opts['centers']:
            for stage_id, stage_data in opts['centers'][center]['stages'].items():
                stage_file = stage_data['file_']
                # now add the parameters from each individual centre/stage file to the main options config
                opts['centers'][center]['stages'][stage_id]['parameters'] = self.load_centre_stage_file(stage_file)
Example #4
0
File: appdata.py Project: mpi2/vpv
    def __init__(self):
        self.using_appdata = True  # Set to false if we weren't able to find a sirectory to save the appdata
        appname = 'vpv_viewer'
        appdata_dir = appdirs.user_data_dir(appname)

        if not os.path.isdir(appdata_dir):
            try:
                os.mkdir(appdata_dir)
            except WindowsError:
                #Can't find the AppData directory. So just make one in home directory
                appdata_dir = os.path.join(expanduser("~"), '.' + appname)
                if not os.path.isdir(appdata_dir):
                    os.mkdir(appdata_dir)

        self.app_data_file = os.path.join(appdata_dir, 'vpv_viewer.yaml')

        if os.path.isfile(self.app_data_file):

            self.data = common.load_yaml(self.app_data_file)
            if not self.data:
                logging.error(
                    f'Warning: could not load app data file\nTry deleting {self.app_data_file}'
                )
                self.data = {}
        else:
            self.data = {}

        # Appdata versioning was not always in place. If a we find some appdata without a version, reset the data
        # Also reset the data if we find a previous version

        # This breaks for JIm on v2.02. Complains about NoneType not having a get(). Catch attribute error
        try:
            if self.data.get('version') is None or self.data[
                    'version'] < VPV_APPDATA_VERSION:
                print("resetting appdata")
                self.data = {}
        except AttributeError:
            self.data = {}

        if self.data == {}:
            self.data['version'] = VPV_APPDATA_VERSION

        if 'recent_files' not in self.data:
            self.data['recent_files'] = collections.deque(maxlen=10)
Example #5
0
File: appdata.py Project: mpi2/vpv
    def __init__(self):
        self.using_appdata = True # Set to false if we weren't able to find a sirectory to save the appdata
        appname = 'vpv'
        appdata_dir = appdirs.user_data_dir(appname)

        if not os.path.isdir(appdata_dir):
            try:
                os.mkdir(appdata_dir)
            except WindowsError:
                #Can't find the AppData directory. So just make one in home directory
                appdata_dir = os.path.join(expanduser("~"), '.' + appname)
                if not os.path.isdir(appdata_dir):
                    os.mkdir(appdata_dir)

        self.app_data_file = os.path.join(appdata_dir, 'vpv.yaml')

        if os.path.isfile(self.app_data_file):

            self.app_data = common.load_yaml(self.app_data_file)
            if not self.app_data:
                logging('Warning: could not load app data file')
                self.app_data = {}
        else:
            self.app_data = {}

        # Appdata versioning was not always in place. If a we find some appdata without a version, reset the data
        # Also reset the data if we find a previous version

        # This breaks for JIm on v2.02. Complains about NoneType not having a get(). Catch attribute error
        try:
            if self.app_data.get('version') is None or self.app_data['version'] < VPV_APPDATA_VERSION:
                print("resetting appdata")
                self.app_data = {}
        except AttributeError:
            self.app_data = {}

        if self.app_data == {}:
            self.app_data['version'] = VPV_APPDATA_VERSION

        if 'recent_files' not in self.app_data:
            self.app_data['recent_files'] = collections.deque(maxlen=10)
Example #6
0
    def __init__(self):
        # Add assert for default in options
        try:
            opts = load_yaml(OPTIONS_CONFIG_PATH)
        except OSError:
            logging.warning('could not open the annotations yaml file {}'.format(OPTIONS_CONFIG_PATH))
            raise
        self.opts = opts
        self.available_options = self.opts['available_options']

        # Get the centre/stage-specific parameters

        for centre_id, centre_data in opts['centers'].items():
            for proc_id, proc_data in centre_data['procedures'].items():
                param_file_ = proc_data['file_']

                # now add the parameters from each individual centre/stage file to the main options config
                try:
                    opts['centers'][centre_id]['procedures'][proc_id]['parameters'] = self.load_centre_stage_file(param_file_)
                except KeyError as e:
                    raise
Example #7
0
    def _load_done_status(self):
        """
        Load in the doneList.yaml which specifies which parameters have been loked at. This is used to populate the
        'done' checkboxes, which is just a guide for the user. Has no other effect
        """
        if self.annotation_dir:
            done_file = join(self.annotation_dir, ANNOTATION_DONE_METADATA_FILE)
            if not isfile(done_file):
                return

            done_status = load_yaml(done_file)
            if not done_status:
                return

            self.index = len(self.annotations)  # bodge. Need to reset the annotations iterator

            for ann in self:
                done = done_status.get(ann.term, 'notpresent')

                if done is 'notpresent':
                    logging.warning('Cannot find term in done metadata\n{}'.format(done_file))

                else:
                    ann.looked_at = done
Example #8
0
    def _load_done_status(self):
        """
        Load in the doneList.yaml which specifies which parameters have been loked at. This is used to populate the
        'done' checkboxes, which is just a guide for the user. Has no other effect
        """
        if self.annotation_dir:
            done_file = join(self.annotation_dir, ANNOTATION_DONE_METADATA_FILE)
            if not isfile(done_file):
                return

            done_status = load_yaml(done_file)
            if not done_status:
                return

            self.index = len(self.annotations)  # bodge. Need to reset the annotations iterator

            for ann in self:
                done = done_status.get(ann.term, 'notpresent')

                if done is 'notpresent':
                    logging.warning('Cannot find term in done metadata\n{}'.format(done_file))

                else:
                    ann.looked_at = done
Example #9
0
    def _load_options_and_metadata(self):
        """
        The volume has been loaded. Now see if there is an associated annotation folder that will contain the IMPC
        metadata parameter file. Also load in any partially completed xml annotation files

        Returns
        -------

        """
        if not self.annotation_dir:
            return

        self.metadata_parameter_file = join(self.annotation_dir, PROCEDURE_METADATA)
        
        if not isfile(self.metadata_parameter_file):
            self.metadata_parameter_file = None
            return

        cso = centre_stage_options.opts

        metadata_params = load_yaml(self.metadata_parameter_file)
        if not metadata_params:
            return

        # proc_id = metadata_params['procedure_id']
        proc_id = metadata_params['procedure_id'] = ANNOTATIONS_PROC_VERSION
        center_id = metadata_params['centre_id']
        stage_id = get_stage_from_proc_id(proc_id, center_id)

        self.stage = stage_id
        self.center = center_id

        # Get the procedure parameters for the given center/stage
        center_stage_default_params = cso['centers'][center_id]['stages'][stage_id]['parameters']

        for _, param_info in center_stage_default_params.items():

            try:
                options = centre_stage_options.opts['available_options'][param_info['options']]
            except TypeError as e:
                logging.error('Falied to load annotation parameter file {}'.format(e))
                return

            if param_info['default_option'] not in options:

                logging.error(
                    """Annotation parameter list load error
                    default option: {} not in available options:{}
                    Centre:, stage:{}""".format(param_info['default_option'], options, center_id, stage_id))

                error_dialog(None, 'Annotation options load error', "See log file - 'info/show log'")
                return


            default = param_info['default_option']

            self.add_impc_annotation(None,
                                     None,
                                     None,
                                     param_info['impc_id'],
                                     param_info['name'],
                                     options,
                                     default,
                                     self.stage,
                                     param_info['order'],
                                     param_info['mandatory'],
                                     self.dims
                                     )
        # Sort the list and set the interator index
        self.annotations.sort(key=lambda x: x.order, reverse=True)
        self.index = len(self.annotations)
Example #10
0
    def _load_options_and_metadata(self):
        """
        The volume has been loaded. Now see if there is an associated annotation folder that will contain the IMPC
        metadata parameter file. Also load in any partially completed xml annotation files.

        """
        if not self.annotation_dir:
            return

        self.metadata_parameter_file = join(self.annotation_dir, PROCEDURE_METADATA)
        
        if not isfile(self.metadata_parameter_file):
            self.metadata_parameter_file = None
            return

        cso = centre_stage_options.opts

        metadata_params = load_yaml(self.metadata_parameter_file)
        if not metadata_params:
            return

        proc_id = metadata_params['procedure_id']

        # Temp fix 030320 to increment procedures to 002 so they vallidate correctly
        proc_id = proc_id.replace('_001', '_002')
        self.proc_id = proc_id

        center_id = metadata_params['centre_id']
        stage_id, modality = get_stage_and_modality(proc_id, center_id)

        self.stage = stage_id
        self.center = center_id
        self.modality = modality

        # Get the procedure parameters for the given center/stage
        try:
            cso['centers'][center_id]['procedures'][proc_id]
        except KeyError:
            logging.error(f'Procedure id {proc_id} not in the annotation_conf')
            return

        center_stage_default_params = cso['centers'][center_id]['procedures'][proc_id]['parameters']

        # opts['centers'][center]['procedures'][proc_id]['parameters'] = self.load_centre_stage_file(param_file_)

        for _, param_info in center_stage_default_params.items():

            try:
                options = centre_stage_options.opts['available_options'][param_info['options']]
            except TypeError as e:
                logging.error('Falied to load annotation parameter file {}'.format(e))
                return

            if param_info['default_option'] not in options:

                logging.error(
                    """Annotation parameter list load error
                    default option: {} not in available options:{}
                    Centre:, stage:{}""".format(param_info['default_option'], options, center_id, stage_id))

                error_dialog(None, 'Annotation options load error', "See log file - 'info/show log'")
                return


            default = param_info['default_option']

            self.add_impc_annotation(None,
                                     None,
                                     None,
                                     param_info['impc_id'],
                                     param_info['name'],
                                     options,
                                     default,
                                     self.stage,
                                     param_info['order'],
                                     param_info['mandatory'],
                                     self.dims
                                     )
        # Sort the list and set the interator index
        self.annotations.sort(key=lambda x: x.order, reverse=True)
        self.index = len(self.annotations)