Beispiel #1
0
def findOffsetX(p1, p2, m, b, starX, starY, starR, hotX, hotY, img, PC):
    perpLine = np.arange(-4,4.1,0.1)
    parLine = getParLine(img, p1, p2, m, b)
    x,y = getParLineXYBand(perpLine, img, p1, p2, m, b)

    pars = []
    offsets = []
    for i in range(0,x.shape[1]):
        bright = [PC(x[j,i],y[j,i]) for j in range(0,x.shape[0])]
        off = [perpLine[j] for j in range(0,x.shape[0])]
        maxOff = off[np.argmax(bright)]

        offsets.append(maxOff)
        pars.append(parLine[i])

    offsets = np.array(offsets)

    parLine2 = getParLine(img, p1, p2, m, b)
    trailX,trailY = GT.getXY(parLine2, offsets, m, b)

    fig,axes = plt.subplots(2,1,True,True)
    axes[0].plot(pars,offsets)
    axes[0].set_title("Wobble with Stars")

    mask = getValueMask(img, trailX, trailY, starX, starY, starR, hotX, hotY, 1)
    interpolateSignal(parLine2, offsets, mask)

    axes[1].plot(pars,offsets)
    axes[1].set_title("Wobble without Stars")
    plt.show()


    pars = np.array(pars)
    offset = FF.FourierFit(pars, offsets, int(pars.shape[0]*0.87))#0.92))
    
    if True:
        plt.plot(pars,offsets,label="Wobble")
        plt.plot(pars,offset(pars), label="Wobble Fit")
        plt.legend()
        plt.show()

    x2,y2 = GT.getXY(pars, offset(pars), m, b)

    if True:
        mx = img.max()
        mn = img.min()
        median = np.median(img)

        plt.imshow(-img, cmap=cm.gray, vmin = -(mx+rescale*median)/(rescale+1), vmax = -(mn+rescale2*median)/(rescale2+1))
        plt.title("Trail With Wobble Fit")

        plt.plot(x2,y2)
        
        plt.show()

    return offset
Beispiel #2
0
def fitGaussianX(img, m, b, bright, offset, starX, starY, starR, gX, gY, gR, hotX, hotY):
    parDist,perpDist = GT.getDistancesHorizontal(m, b, img.shape[1], img.shape[0], offset)
    parF,perpF,imgF = getTrailBand(parDist, perpDist, img, 6)
    x,y = GT.getXY(parF,perpF,m,b,offset)
    
    trailScaled = imgF/bright(parF)

    fig,axes = plt.subplots(1,2,sharex = True, sharey = True)

    axes[0].plot(perpF,trailScaled,"bo")
    axes[0].set_title("Trail Gaussian With Stars")

    mask = getValueMask(img, x, y, starX, starY, starR, gX, gY, gR, hotX, hotY, 1)
    perpF = perpF[mask]
    trailScaled = trailScaled[mask]
    

    axes[1].plot(perpF,trailScaled,"bo")
    axes[1].set_title("Trail Gaussian Without Stars")

    plt.show()


    sDev = cf(gauss, perpF, trailScaled)[0][0]


    x = np.arange(-5,5,0.1)
    
    plt.plot(perpF,trailScaled,"bo",label = "Pixel Brightnesses")
    plt.plot(x,gauss(x,sDev), label = "Gaussian Fit")
    plt.title("Gaussian Fit")
    plt.show()

    return sDev
Beispiel #3
0
def fitBrightnessPolyX(img, p1, p2, m, b, offset, PC, starX, starY, starR, gX, gY, gR, hotX, hotY):
    parDists = getParLine(img, p1, p2, m, b)
    perpDists = parDists*0
    x,y = GT.getXY(parDists,perpDists,m,b,offset)

    #weights = ((dists-np.mean(dists))/max(dists))**2+1
        
    brightness = np.array([PC(x[i],y[i]) for i in range(0,len(x))])

    fig,axes = plt.subplots(2,1,True,True)
    axes[0].plot(parDists,brightness)
    axes[0].set_title("Britghtness with Stars")

    mask = getValueMask(img, x, y, starX, starY, starR, gX, gY, gR, hotX, hotY, 1)
    interpolateSignal(parDists, brightness, mask)

    axes[1].plot(parDists,brightness)
    axes[1].set_title("Brightness without Stars")
    plt.show()

    bPol = np.poly1d(np.polyfit(parDists,brightness,20))#,weights = weights))
    bFour = FF.FourierFit(parDists, brightness, int(parDists.shape[0]*0.98))#0.92))

    plt.plot(parDists, brightness, label = "Brightness")
    plt.plot(parDists, bPol(parDists), label = "Brightness Fit")
    #plt.plot(parDists, bFour(parDists), label = "Brightness Fit")
    plt.title("Brightness Fit")
    plt.legend()
    plt.show()

    return bFour
Beispiel #4
0
def fitBrightnessSDev(img, m, b, offset, starX, starY, starR, gX, gY, gR, hotX, hotY, trailSize):
    parDist,perpDist = GT.getDistancesHorizontal(m, b, img.shape[1], img.shape[0], offset)
    parDistF,perpDistF,imgF = getTrailBand(parDist, perpDist, img, trailSize)
    x,y = GT.getXY(parDistF,perpDistF,m,b,offset)

    mask = getValueMask(img, x, y, starX, starY, starR, gX, gY, gR, hotX, hotY, 1)
    par = parDistF[mask]
    perp = perpDistF[mask]
    band = imgF[mask]

    b1, b2, b3, b4, b5, sDev = cf(GT.gaussian2, [par, perp], band, bounds = ([-math.inf,-math.inf,-math.inf,-math.inf,-math.inf,0],[math.inf,math.inf,math.inf,math.inf,math.inf,trailSize]))[0]

    return [np.poly1d([b1, b2, b3, b4, b5]), sDev]
Beispiel #5
0
def estimateBackground(img, m, b, offset, starX, starY, starR, gX, gY, gR, hotX, hotY):
    parDist,perpDist = GT.getDistancesHorizontal(m, b, img.shape[1], img.shape[0], offset)
    par,perp,band = getNonTrailBand(parDist, perpDist, img, 10, 20)
    x,y = GT.getXY(par,perp,m,b,offset)

    mask = getValueMask(img, x, y, starX, starY, starR, gX, gY, gR, hotX, hotY, 1)
    par = par[mask]
    band = band[mask]

    mean = np.mean(band)

    plt.plot(par,band,"bo",label = "Background Pixel Brightnesses")
    plt.plot([par[0],par[-1]],[mean, mean],label = "Average Background Brightness: "+str(np.round(mean,decimals = 3)))
    plt.title("Background Estimate")
    plt.legend()
    plt.show()

    print(mean)
    return mean
Beispiel #6
0
def fitBrightnessPolyX2(img, p1, p2, m, b, offset, PC, starX, starY, starR, hotX, hotY, gaussRange, step, sDev):
    parLine = getParLine(img, p1, p2, m, b)
    perpLine = np.arange(-gaussRange,gaussRange+step,step)
    x,y = getParLineXYBand(perpLine, img, p1, p2, m, b, offset)

    gaussian = gauss(perpLine,sDev)

    brightness = []
    for i in range(0,x.shape[1]):
        brightness.append(np.mean([PC(x[j,i],y[j,i])*gaussian[j] for j in range(0,len(x))]))

    brightness = np.array(brightness)

    trailX,trailY = GT.getXY(parLine, parLine*0, m, b, offset)
    mask = getValueMask(img, trailX, trailY, starX, starY, starR, hotX, hotY, gaussRange)

    interpolateSignal(parLine, brightness, mask)


    bPol = np.poly1d(np.polyfit(parLine,brightness,5))#,weights = weights))
    #bFour = FF.FourierFit(parLine, brightness, int(parLine.shape[0]*0.98))#0.92))

    plt.plot(parLine, brightness)
    plt.plot(parLine, bPol(parLine))
    #plt.plot(parLine, bFour(parLine))
    plt.title("Brightness Fit")
    plt.show()

    middleIndex = int(np.round(gaussRange/step))
    brightness2 = np.array([(PC(x[middleIndex,i],y[middleIndex,i])/bPol(parLine[i])) for i in range(0,len(x))])

    bPol2 = np.poly1d(np.polyfit(parLine,brightness2,0))#,weights = weights))
    #bFour = FF.FourierFit(parLine, brightness, int(parLine.shape[0]*0.98))#0.92))


    plt.plot(parLine, brightness2)
    plt.plot(parLine, bPol2(parLine))
    #plt.plot(parLine, bFour(parLine))
    plt.title("Brightness Fit")
    plt.show()

    return bPol
Beispiel #7
0
def showImageWithTrail(img, title, p1, p2, inverted, offset=None):
    mx = img.max()
    mn = img.min()
    median = np.median(img)

    if inverted:
        plt.imshow(-img,
                   cmap=cm.gray,
                   vmin=-(mx + rescale * median) / (rescale + 1),
                   vmax=-(mn + rescale2 * median) / (rescale2 + 1))
    else:
        plt.imshow(img,
                   cmap=cm.gray,
                   vmin=(mn + rescale2 * median) / (rescale2 + 1),
                   vmax=(mx + rescale * median) / (rescale + 1))

    plt.plot((p1[0], p2[0]), (p1[1], p2[1]))
    if offset != None:
        m, b = TF.getLineParams(p1, p2)
        pars = TF.getParLine(img, p1, p2, m, b)
        perps = offset(pars)
        x, y = GT.getXY(pars, perps, m, b)
        plt.plot(x, y)
    plt.show()
Beispiel #8
0
def getParLineXYBand(perpLine, img, p1, p2, m, b, offset=None):
    parLine = getParLine(img, p1, p2, m, b)

    parLine,perpLine = np.meshgrid(parLine,perpLine)
    return GT.getXY(parLine,perpLine,m,b,offset)
Beispiel #9
0
def findOffsetX2(p1, p2, m, b, starX, starY, starR, gX, gY, gR, hotX, hotY, img, PC, perpRangeSize, step, gaussRange, sDev):
    perpLine = np.arange(-perpRangeSize-gaussRange, perpRangeSize+gaussRange+step, step)
    parLine = getParLine(img, p1, p2, m, b)
    x,y = getParLineXYBand(perpLine, img, p1, p2, m, b)

    perpRange = np.arange(-gaussRange,gaussRange+step,step)
    gaussian = gauss(perpRange,sDev)

    plt.plot(perpRange,gaussian)
    plt.show()

    startI = int(np.round(gaussRange/step))
    endI = int(np.round(len(perpLine)-1-gaussRange/step))

    pars = []
    offsets = []
    for i in range(0, x.shape[1]):
        bright = [PC(x[j,i],y[j,i]) for j in range(0,x.shape[0])]
        gaussBright = []

        for j in range(startI,endI):
            brightList = []
            for k in range(-startI,startI):
                brightList.append(bright[j+k]*gaussian[startI+k])
            gaussBright.append(np.mean(brightList))

        off = [perpLine[j] for j in range(startI,endI)]
        maxOff = off[np.argmax(gaussBright)]

        offsets.append(maxOff)
        pars.append(parLine[i])

    offsets = np.array(offsets)

    parLine2 = getParLine(img, p1, p2, m, b)
    trailX,trailY = GT.getXY(parLine2, offsets, m, b)

    fig,axes = plt.subplots(2,1,True,True)
    axes[0].plot(pars,offsets)
    axes[0].set_title("Wobble with Stars")

    mask = getValueMask(img, trailX, trailY, starX, starY, starR, gX, gY, gR, hotX, hotY, 1)
    interpolateSignal(parLine2, offsets, mask)

    axes[1].plot(pars,offsets)
    axes[1].set_title("Wobble without Stars")
    plt.show()

    pars = np.array(pars)
    offset = FF.FourierFit(pars, offsets, int(pars.shape[0]*0.95))
    
    if True:
        plt.plot(pars,offsets,label="Wobble")
        plt.plot(pars,offset(pars), label="Wobble Fit")
        plt.legend()
        plt.title("Wobble Fit")
        plt.show()

    x2,y2 = GT.getXY(pars, offset(pars), m, b)

    if True:
        mx = img.max()
        mn = img.min()
        median = np.median(img)

        plt.imshow(-img, cmap=cm.gray, vmin = -(mx+rescale*median)/(rescale+1), vmax = -(mn+rescale2*median)/(rescale2+1))
        plt.title("Trail With Wobble Fit")

        plt.plot(x2,y2)
        plt.plot(trailX,trailY)
        plt.plot([p1[0],p2[0]],[p1[1],p2[1]])
        
        plt.show()

    return offset