示例#1
0
def getParamsFromModel(modelGrid):
    merits=[]
    i=0
    origSpec=modelGrid.origSpec
    for j,(aSpec,subSpec,llist,w,t) in enumerate(zip(modelGrid['aspec'],modelGrid['subspec'],modelGrid['llist'],modelGrid['w'],modelGrid['t'])):
        print i
        i+=1
        #subSpec=model['subspec']
        addSpec=aSpec+origSpec
        intTotal=fit.getInt(subSpec)/fit.getInt(addSpec)
        intUV=fit.getUVInt(subSpec)/fit.getUVInt(addSpec)
        slope=fit.getSlope(subSpec)
        elementMerits=[]
        for element in ['C','O','Na','Mg','Si','S','Ca','Ti','Cr','Ni','Fe']:
            try:
                lmerits,weights=fitelem.getElementMerit(element,llist,subSpec)
                elementMerits.append(np.average(lmerits,weights=weights))
                #pdb.set_trace()
            except:
                elementMerits.append(-1)
        allMerit=[intTotal,intUV,slope,w,t]+elementMerits
        tmpParam=modelGrid.grid[j].param
        #tmpParam.update(modelGrid.grid[j].param.comp.data)
        merits.append((np.array(allMerit),tmpParam))
    return merits
示例#2
0
def getFeaturesFromBestFit(bestFit):
    merits=[]
    i=0
    origSpec=bestFit.origSpec
    aSpec,subSpec,llist,w,t=bestFit['aspec'],bestFit['subspec'],bestFit['llist'],bestFit['w'],bestFit['t']
    addSpec=aSpec+origSpec
    intTotal=fit.getInt(subSpec)/fit.getInt(addSpec)
    intUV=fit.getUVInt(subSpec)/fit.getUVInt(addSpec)
    slope=fit.getSlope(subSpec)
    chiSquared=fit.getChiSquared(subSpec)
    modChiSquared=fit.getModChiSquared(subSpec)
    elementMerits=[]
    for element in ['C','O','Na','Mg','Si','S','Ca','Ti','Cr','Ni','Fe']:
        try:
            lmerits,weights=fitelem.getElementMerit(element,llist,subSpec)
            elementMerits.append(np.average(lmerits,weights=weights))
            #pdb.set_trace()
        except:
            elementMerits.append(-1)
    allMerit=[intTotal,intUV,chiSquared,modChiSquared,slope,w,t]+elementMerits
    print "modincl"
    tmpParam=bestFit.param
    #tmpParam.update(modelGrid.grid[j].param.comp.data)
    merits.append((np.array(allMerit),tmpParam))
    return merits
示例#3
0
def calcTargetFeatureRelDistance(params,ids,bestFitDict):
    #Calculates the target with relative distance to features
    bestFitTarget={}
    targets=[]
    for bestFitName,bestFitModel in bestFitDict.items():
        origSpec=bestFitModel.origSpec
        aSpec=bestFitModel.aSpec
        subSpec=fit.getSubSpec(aSpec,origSpec)
        addSpec=aSpec+origSpec
        intTotal=fit.getInt(subSpec)/fit.getInt(addSpec)
        intUV=fit.getUVInt(subSpec)/fit.getUVInt(addSpec)
        slope=fit.getSlope(subSpec)
        elementMerits=[]
        for element in ['C','O','Na','Mg','Si','S','Ca','Ti','Cr','Ni','Fe']:
            try:
                lmerits,weights=fitelem.getElementMerit(element,bestFitModel.llist,subSpec)
                elementMerits.append(np.average(lmerits,weights=weights))
                #pdb.set_trace()
            except:
                elementMerits.append(-1)
        allMerit=[intTotal,intUV,slope,bestFitModel['w'],bestFitModel['t']]+elementMerits
        bestFitTarget[bestFitName]=allMerit
    for id,param in zip(ids,params):
        bestFitName=re.search('(.+)ts\d+\.pkl',id[0]).groups()[0]+'bf.pkl'
        #tmpTarget=[abs(iparam-itarget)/abs(iparam+itarget) for iparam,itarget in zip(param[0],bestFitTarget[bestFitName])]
        tmpTarget=[abs(iparam/itarget)-1 for iparam,itarget in zip(param[0],bestFitTarget[bestFitName]) if itarget!=0]
        targets.append(tmpTarget)
    return np.array(targets)
示例#4
0
def getInputFromModel(modelGrid):
    merits=[]
    i=0
    origSpec=modelGrid.origSpec
    for aSpec,subSpec,llist,w,t in zip(modelGrid['aspec'],modelGrid['subspec'],modelGrid['llist'],modelGrid['w'],modelGrid['t']):
        print i
        i+=1
        #subSpec=model['subspec']
        addSpec=aSpec+origSpec
        intTotal=fit.getInt(subSpec)/fit.getInt(addSpec)
        intUV=fit.getUVInt(subSpec)/fit.getUVInt(addSpec)
        slope=fit.getSlope(subSpec)
        chiSquared=fit.getChiSquared(subSpec)
        modChiSquared=fit.getModChiSquared(subSpec)
        MAD=fit.getMAD(aSpec,origSpec)
        elementMerits=[]
        for element in ['C','O','Na','Mg','Si','S','Ca','Ti','Cr','Ni','Fe']:
            try:
                lmerits,weights=fitelem.getElementMerit(element,llist,subSpec)
                elementMerits.append(np.average(lmerits,weights=weights))
                #pdb.set_trace()
            except:
                elementMerits.append(-1)
        allMerit=[intTotal,intUV,chiSquared,modChiSquared,MAD,slope,w,t]+elementMerits
        print 'MAD'
        merits.append(allMerit)
    return np.array(merits)
示例#5
0
        self.specFlag = vecFunc(self.grid)

    def _getDivSpec(self):
        self.divSpec = np.array([item.divSpec for item in self.grid])

    def _getFitness(self):
        self.fitness = np.array([item.fitness for item in self.grid])
        # def divSpecGetter(item):
        #    tmpAspec=item['aspec']
        #    tmpAspec=tmpAspec.interpolate(xref=self.origSpec.x)
        #    return tmpAspec/self.origSpec
        # vecFunc=np.vectorize(divSpecGetter)
        # self.divSpec=vecFunc(self.grid)

    def toDB(self, conn, dicaID=None, storeLList=None, storeWParam=None):
        modelGridIDs = []
        # saving all models to db
        for model in self.grid:
            modelGridIDs.append(model.toDB(conn, dicaID=dicaID, storeLList=storeLList, storeWParam=storeWParam))
        return np.array(modelGridIDs)


# simple Functions to extract merits
# getGridInt=np.vectorize(lambda item: fit.getDiffIntBin(item,1)[1][0])
getGridInt = np.vectorize(lambda item: fit.getInt(item))
getGridUV = np.vectorize(lambda item: fit.getUVInt(item, norm=False))
getGridOptical = np.vectorize(lambda item: fit.getInt(item, lower=3950.0, norm=False))
getGridUVComp = np.vectorize(lambda item: fit.getUVIntComp(item))
getGridSlope = np.vectorize(lambda item: fit.getIntSlope(item))
getGridSlope = np.vectorize(lambda item: fit.getSlope(item))