def recommend_data_object(self): import gdpgutil as gd hints = self.get("type_hints") print "gd190: hints=", hints if hints: modandclass = gd.pick_config(hints, self._suggested_data_classes, "leaves") return modandclass else: modandclass = gd.pick_config(self, self._suggested_data_classes, "leaves") return modandclass
def get_calculator(dataset): """ This function gets the Calculator instance appropriate for the specified dataset. Conflicts, arising from Calculators being associated with more than one AstroData type classification, are resolved by traversing the type tree to see if one type is a subtype of the other so the more specific type can be used. @param dataset: the dataset to load a calculator for @type dataset: AstroData @returns: the appropriate Calculator instance for this type of dataset @rtype: Calculator @note: OPEN ISSUE: how to deal with conflicts not resolved this way... i.e. if there are two assignments related to types which do not appear in the same type trees. """ #NOTE: Handle hdulist as well as AstroData instance as 'dataset'? types = dataset.discover_types() calcs = [] # use classification library from dataset's context cl = dataset.get_classification_library() calc = None leaflist = [] from gdpgutil import pick_config cfg = pick_config(dataset, centralCalculatorIndex, style="leaves") foundtypes = cfg.keys() # to the descriptor type. # print "D661:",repr(foundtypes) if (len(foundtypes) == 0): #then none were found, use default calculator return Calculator() # first check loadedDescriptorIndex else: foundcalcs = [] for calctype in foundtypes: #print "D669: checking", calctype if loadedCalculatorIndex.has_key(calctype): #print "D671: already loaded" foundcalcs.append(loadedCalculatorIndex[calctype]) else: #print "D674: loading", calctype # if here we need to import and instantiate the basic # calculator # note: module name is first part of calc string calcID = cfg[calctype] modname = calcID.split(".")[0] #print "D679:",modname, calcID if calcID[-2:] == "()": calcID = calcID[:-2] # print "D682:",modname, calcID exec "import " + modname calcClass = eval(calcID) # add this calculator to the loadedCalculatorIndex (aka # "calculator cache") loadedCalculatorIndex.update({calctype: calcClass}) foundcalcs.append(calcClass) concreteCalcClass = type("CompositeCalcClass", tuple(foundcalcs), {}) #for calc in foundcalcs: # concreteCalcClass.__bases__ += (calc.__class__, ) finalCalc = concreteCalcClass() from debugmodes import get_descriptor_throw # p rint "get_descriptor_throw", get_descriptor_throw() finalCalc.throwExceptions = get_descriptor_throw() return finalCalc