def getNextLumInterval(params,sampleSize=3): #lumMerits=read.getGridInt(params['divSpec']) lumMerits=2.*read.getGridInt(params['subSpec'])/read.getGridInt(params['addSpec']) paramSortID=np.argsort(np.abs(lumMerits)) bestParam=paramSortID[:sampleSize] m,t=np.polyfit(params['lum'][bestParam],lumMerits[bestParam],1) bestLum=(-t)/m lumDev=min(np.abs(params['lum']-bestLum)) interval=[bestLum-lumDev,bestLum+lumDev] minIntervalCheck=False steadParam=checkSteadiness(lumMerits) if steadParam<4: print "Warning merits not steady suggestions might be problematic (steadParam=%s)"%steadParam #WARNING. CHECK SAMPLES THIS WILL BE BAD LATER ON minInterval=0.02 if 2*lumDev<minInterval: minIntervalCheck=True print "Interval too small" intervalIDs=[0,1] i=2 while True: intervalPoints=params['lum'][paramSortID][intervalIDs] minIntervalPoint,maxIntervalPoint=min(intervalPoints),max(intervalPoints) if np.abs(minIntervalPoint-maxIntervalPoint)>minInterval: interval=[minIntervalPoint,maxIntervalPoint] break if len(intervalIDs)>len(lumMerits)-3: interval=[bestLum-2*lumDev,bestLum+2*lumDev] break intervalIDs.append(i) i+=1 evalDic={'suggestValue':bestLum, 'bestFitID':bestParam[0], 'merit':abs(lumMerits[bestParam[0]]), 'merits':lumMerits, 'interval':interval, 'dev':lumDev, 'sortedModelIDX':paramSortID, 'fitKey':'lum', 'mininterval':minIntervalCheck, 'steady':steadParam} return evalDic return bestLum,bestParam[0],abs(lumMerits[bestParam[0]]),[bestLum-lumDev,bestLum+lumDev]
def getNextLumGuess(params,noForFit=2): lums=params['lum'] lumMerits=read.getGridInt(params['subspec']) selLumMerits=np.argsort(lumMerits)[:noForFit] print lums[selLumMerits],lumMerits[selLumMerits] return np.polyfit(lums[selLumMerits],lumMerits[selLumMerits],1)
def getLumScale(params,noForFit=2): lums=params['lum'] lumMerits=read.getGridInt(params['divSpec']) selLumMerits=np.argsort(lumMerits)[:noForFit] return np.polyfit(lums[selLumMerits],lumMerits[selLumMerits],1)