Example #1
0
def addProcSpec2BestFit(pattern='*bf.pkl'):
    for fname in glob(pattern):
        bestFit=cPickle.load(file(fname))
        bestFit.subSpec=fit.getSubSpec(bestFit['aspec'],bestFit.origSpec)
        bestFit.addSpec=fit.getSubSpec(bestFit['aspec'],bestFit.origSpec)
        tmpAspec=bestFit['aSpec']
        tmpAspec=tmpAspec.interpolate(xref=bestFit.origSpec.x)
        bestFit.divSpec=tmpAspec/bestFit.origSpec
        cPickle.dump(bestFit,file(fname,'w'))
Example #2
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)
Example #3
0
def printCurMerits():
    id=getLastID()
    aSpec=getHistSpec(id)
    aSpecOld=getHistSpec(id-1)
    divSpec=origspec/aSpec
    divSpecOld=origspec/aSpecOld
    subSpec=fit.getSubSpec(aSpec,origspec)
    subSpecOld=fit.getSubSpec(aSpecOld,origspec)
    checkElements=['Ni','Co','Fe','Ca','Ti','Cr','Si','S','O','C','Mg']
    #checkIons=[[]]
    print "General integral: %s last: %s"%(fit.getDiffIntBin(subSpec,1)[1],fit.getDiffIntBin(subSpecOld,1)[1])
    print "Integral slope: %s last: %s"%(fit.getIntSlope(subSpec),fit.getIntSlope(subSpecOld))
    print "UV excess: %s last: %s"%(fit.getUVInt(subSpec),fit.getUVInt(subSpecOld))
    print "UV comparison (UV to optical): %s last: %s"%(fit.getUVIntComp(subSpec),fit.getUVIntComp(subSpecOld))
    print "---------------- Element Ratios --------"
    for element in checkElements:
        try:
            print "Element %s: %.5f  last: %.5f "%(element,getElementMerit(element,divSpec,threshold=0),getElementMerit(element,divSpecOld,threshold=0,id=id-1))
        except Exception as inst:
            print "Problem getting %s merit: %s"%(element,inst)
    print "________________ Ion Ratios ------------"
Example #4
0
    def __init__(
        self,
        aSpec,
        param,
        w,
        machineName=None,
        execTime=None,
        wParam=None,
        error=None,
        ficaLog=None,
        llist=None,
        origSpec=None,
        specFlag=-1,
        fitFunc=None,
    ):
        self.param = param
        self.w = w
        self.machine = machineName
        self.execTime = execTime
        self.wParam = wParam
        self.log = ficaLog
        self.error = error
        self.llist = llist
        self.origSpec = origSpec
        self.specFlag = specFlag
        self.aSpec = aSpec

        # Initializing subspec, divspec....
        if origSpec != None:
            tmpAspec = self.aSpec.interpolate(xref=origSpec.x)
            self.divSpec = tmpAspec / origSpec
            self.subSpec = fit.getSubSpec(tmpAspec, origSpec)
        else:
            self.subSpec = None
            self.divSpec = None

        if fitFunc == None:
            self.fitness = 0
        else:
            self.fitness = fitFunc(self)