Ejemplo n.º 1
0
    def items(self):
        # return dict with keys for experiment
        # and subkey 'models' for models within experiment
        if self.value:
            for experiment_uuid, model_uuids in self.value.items():
                item = {}
                expbrain = uuidToCatalogBrain(experiment_uuid)
                # TODO: we have an experiment_uuid, but can't access the
                #       experiment (deleted?, access denied?)
                #       shall we at least try to get some details?
                if expbrain is None:
                    continue
                item['title'] = expbrain.Title
                item['uuid'] = expbrain.UID
                item['brain'] = expbrain

                # TODO: what else wolud I need from an experiment?
                exp = expbrain.getObject()
                expmd = IBCCVLMetadata(exp)
                item['resolution'] = expmd.get('resolution')

                # now search all datasets within and add infos
                pc = getToolByName(self.context, 'portal_catalog')
                results = pc.searchResults(path=expbrain.getPath(),
                                           portal_type='Folder',
                                           job_state='COMPLETED')
                brains = pc.searchResults(path=[r.getPath() for r in results],
                                          BCCDataGenre=self.genre)
                # TODO: maybe as generator?
                item['subitems'] = []
                for brain in brains:
                    # FIXME: I need a different list of thresholds for display;
                    # esp. don't look up threshold, but take vales (threshold
                    # id and value) from field as is
                    thresholds = dataset.getThresholds(brain.UID)[brain.UID]
                    threshold = self.value[experiment_uuid].get(brain.UID)
                    # is threshold in list?
                    if threshold and threshold['label'] not in thresholds:
                        # maybe a custom entered number?
                        # ... I guess we don't really care as long as we produce the same the user entered. (validate?)
                        thresholds[threshold['label']] = threshold['label']
                    dsobj = brain.getObject()
                    dsmd = IBCCVLMetadata(dsobj)
                    item['subitems'].append({
                        'uuid': brain.UID,
                        'title': brain.Title,
                        'selected': brain.UID in self.value[experiment_uuid],
                        'threshold': threshold,
                        'thresholds': thresholds,
                        'brain': brain,
                        'md': dsmd,
                        'obj': dsobj,
                        # TODO: this correct? only one layer ever?
                        'layermd': dsmd['layers'].values()[0]
                    })
                yield item
Ejemplo n.º 2
0
    def items(self):
        # return dict with keys for experiment
        # and subkey 'models' for models within experiment
        if self.value:
            for experiment_uuid, model_uuids in self.value.items():
                item = {}
                expbrain = uuidToCatalogBrain(experiment_uuid)
                item['title'] = expbrain.Title
                item['uuid'] = expbrain.UID
                item['brain'] = expbrain

                # TODO: what else wolud I need from an experiment?
                exp = expbrain.getObject()
                expmd = IBCCVLMetadata(exp)
                item['resolution'] = expmd.get('resolution')

                # now search all datasets within and add infos
                pc = getToolByName(self.context, 'portal_catalog')
                brains = pc.searchResults(path=expbrain.getPath(),
                                          BCCDataGenre=self.genre)
                # TODO: maybe as generator?
                item['datasets'] = []
                for brain in brains:
                    # FIXME: I need a different list of thresholds for display; esp. don't look up threshold, but take vales (threshold id and value) from field as is
                    thresholds = dataset.getThresholds(brain.UID)[brain.UID]
                    threshold = self.value[experiment_uuid].get(brain.UID)
                    # is threshold in list?
                    if threshold and threshold['label'] not in thresholds:
                        # maybe a custom entered number?
                        # ... I guess we don't really care as long as we produce the same the user entered. (validate?)
                        thresholds[threshold['label']] = threshold['label']
                    dsobj = brain.getObject()
                    dsmd = IBCCVLMetadata(dsobj)
                    item['datasets'].append({
                        'uuid':
                        brain.UID,
                        'title':
                        brain.Title,
                        'selected':
                        brain.UID in self.value[experiment_uuid],
                        'threshold':
                        threshold,
                        'thresholds':
                        thresholds,
                        'brain':
                        brain,
                        'md':
                        dsmd,
                        'obj':
                        dsobj,
                        # TODO: this correct? only one layer ever?
                        'layermd':
                        dsmd['layers'].values()[0]
                    })
                yield item
Ejemplo n.º 3
0
 def toFieldValue(self, value):
     """Just dispatch it."""
     if not len(value):
         return self.field.missing_value
     # if there is no value, we'll have to fetch it
     for exp in value:
         for ds, threshold in value[exp].items():
             thresholds = dataset.getThresholds(ds)[ds]
             if threshold['label'] not in thresholds:
                 # label not in list: is it a number?
                 try:
                     threshold['value'] = Decimal(threshold['label'])
                 except:
                     raise ValueError("Invalid '{0}' value for threshold".format(threshold['label']))
             else:
                 threshold['value'] = thresholds[threshold['label']]
     return value
Ejemplo n.º 4
0
 def toFieldValue(self, value):
     """Just dispatch it."""
     if not len(value):
         return self.field.missing_value
     # if there is no value, we'll have to fetch it
     for exp in value:
         for ds, threshold in value[exp].items():
             thresholds = dataset.getThresholds(ds)[ds]
             if threshold['label'] not in thresholds:
                 # label not in list: is it a number?
                 try:
                     threshold['value'] = Decimal(threshold['label'])
                 except:
                     raise ValueError("Invalid '{0}' value for threshold".format(threshold['label']))
             else:
                 threshold['value'] = thresholds[threshold['label']]
     return value
Ejemplo n.º 5
0
    def item(self):
        # return dict with keys for experiment
        # and subkey 'models' for models within experiment
        item = {}
        if self.value:
            experiment_uuid = self.value.keys()[0]
            expbrain = uuidToCatalogBrain(experiment_uuid)
            if expbrain is None:
                return {
                    'title': u'Not Available',
                    'uuid': experiment_uuid,
                    'subitems': []  # models
                }
            item['title'] = expbrain.Title
            item['uuid'] = expbrain.UID
            exp = expbrain.getObject()
            # TODO: To get layers of all subsets?
            if getattr(exp, 'datasubsets', None):
                env_datasets = exp.datasubsets[0].get('environmental_datasets')
                item['layers'] = set((chain(*env_datasets.values())))
            else:
                item['layers'] = set(
                    (chain(*exp.environmental_datasets.values())))
            expmd = IBCCVLMetadata(exp)
            item['resolution'] = expmd.get('resolution')
            # now search all models within and add infos
            pc = getToolByName(self.context, 'portal_catalog')
            # only get result folders that are completed
            brains = pc.searchResults(path={
                'query': expbrain.getPath(),
                'depth': 1
            },
                                      portal_type='Folder',
                                      job_state='COMPLETED')
            # TODO: maybe as generator?
            item['subitems'] = []
            for fldbrain in brains:
                # Get the SDM model from result folder
                brain = pc.searchResults(path=fldbrain.getPath(),
                                         BCCDataGenre=self.genre)
                if not brain:
                    # ignore this folder, as it does not have a result we want
                    continue
                brain = brain[0]
                # get algorithm term
                algoid = getattr(brain.getObject(), 'job_params',
                                 {}).get('function')
                algobrain = self.algo_dict.get(algoid, None)
                # Filter out geographic models
                if algobrain.getObject().algorithm_category == 'geographic':
                    continue
                # FIXME: I need a different list of thresholds for display;
                # esp. don't look up threshold, but take vales (threshold
                # id and value) from field as is
                thresholds = dataset.getThresholds(brain.UID)[brain.UID]
                threshold = self.value[experiment_uuid].get(brain.UID)
                # is threshold in list?
                if threshold and threshold['label'] not in thresholds:
                    # maybe a custom entered number?
                    # ... I guess we don't really care as long as we produce the same the user entered. (validate?)
                    thresholds[threshold['label']] = threshold['label']

                # current projection tiff file, and its metadata
                cpbrains = pc.searchResults(path=expbrain.getPath(),
                                            BCCDataGenre=['DataGenreCP'])
                cpmd = IBCCVLMetadata(cpbrains[0].getObject())

                item['subitems'].append({
                    'item':
                    brain,
                    'uuid':
                    brain.UID,
                    'title':
                    brain.Title,
                    'selected':
                    brain.UID in self.value[experiment_uuid],
                    'algorithm':
                    algobrain,
                    'threshold':
                    threshold,
                    'thresholds':
                    thresholds,
                    'layermd':
                    cpmd['layers'].values()[0]
                })
        return item
Ejemplo n.º 6
0
    def item(self):
        # return dict with keys for experiment
        # and subkey 'models' for models within experiment
        item = {}
        if self.value:
            experiment_uuid = self.value.keys()[0]
            expbrain = uuidToCatalogBrain(experiment_uuid)
            if expbrain is None:
                return {
                    'title': u'Not Available',
                    'uuid': experiment_uuid,
                    'subitems': []  # models
                }
            item['title'] = expbrain.Title
            item['uuid'] = expbrain.UID
            exp = expbrain.getObject()
            # TODO: To get layers of all subsets?
            if getattr(exp, 'datasubsets', None):
                env_datasets = exp.datasubsets[0].get('environmental_datasets')
                item['layers'] = set((chain(*env_datasets.values())))
            else:
                item['layers'] = set((chain(*exp.environmental_datasets.values())))
            expmd = IBCCVLMetadata(exp)
            item['resolution'] = expmd.get('resolution')
            # now search all models within and add infos
            pc = getToolByName(self.context, 'portal_catalog')
            # only get result folders that are completed
            brains = pc.searchResults(path={'query': expbrain.getPath(), 'depth': 1},
                                      portal_type='Folder',
                                      job_state='COMPLETED')
            # TODO: maybe as generator?
            item['subitems'] = []
            for fldbrain in brains:
                # Get the SDM model from result folder
                brain = pc.searchResults(path=fldbrain.getPath(),
                                         BCCDataGenre=self.genre)
                if not brain:
                    # ignore this folder, as it does not have a result we want
                    continue
                brain = brain[0]
                # get algorithm term
                algoid = getattr(brain.getObject(), 'job_params',
                                 {}).get('function')
                algobrain = self.algo_dict.get(algoid, None)
                # Filter out geographic models
                if algobrain.getObject().algorithm_category == 'geographic':
                    continue
                # FIXME: I need a different list of thresholds for display;
                # esp. don't look up threshold, but take vales (threshold
                # id and value) from field as is
                thresholds = dataset.getThresholds(brain.UID)[brain.UID]
                threshold = self.value[experiment_uuid].get(brain.UID)
                # is threshold in list?
                if threshold and threshold['label'] not in thresholds:
                    # maybe a custom entered number?
                    # ... I guess we don't really care as long as we produce the same the user entered. (validate?)
                    thresholds[threshold['label']] = threshold['label']

                # current projection tiff file, and its metadata
                cpbrains = pc.searchResults(path=expbrain.getPath(),
                                          BCCDataGenre=['DataGenreCP'])
                cpmd = IBCCVLMetadata(cpbrains[0].getObject())

                item['subitems'].append(
                    {'item': brain,
                     'uuid': brain.UID,
                     'title': brain.Title,
                     'selected': brain.UID in self.value[experiment_uuid],
                     'algorithm': algobrain,
                     'threshold': threshold,
                     'thresholds': thresholds,
                     'layermd': cpmd['layers'].values()[0]
                     }
                )
        return item
Ejemplo n.º 7
0
 def getThresholds(self, datasets, thresholds=None):
     # datasets: a future projection dataset as a result of projectien experiment
     # thresholds: list of names to retrieve or all
     return dataset.getThresholds(datasets, thresholds)