コード例 #1
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
コード例 #2
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
コード例 #3
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]
コード例 #4
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
コード例 #5
0
def getParLine(img, p1, p2, m, b):
    parDists = GT.findDistances(np.array([p1[0],p2[0]]),np.array([p1[1],p2[1]]),m,b)[0]

    minD = min(parDists)
    maxD = max(parDists)
    step = (maxD-minD)/max(img.shape)

    return np.arange(minD,maxD,step)
コード例 #6
0
def findFitVertical(img, x, trailSize):
    parDist, perpDist = GT.getDistancesVertical(x, img.shape[1], img.shape[0])

    median = np.median(img)

    bkg = MMMBackground()
    back = bkg(img)

    return fit(img-median, perpDist, parDist, trailSize)
コード例 #7
0
def testTrailFinder(xScale, yScale):
    for i in range(0, 10):
        trail = GT.generateTrailVertical(np.random.random() * xScale,
                                         np.random.random(),
                                         np.random.random(),
                                         np.random.random(),
                                         50 * np.random.random(), xScale,
                                         yScale)
        imgNoTrail = RT.findRemoveTrail(trail, trail, 200, False, True, True,
                                        True, False, False)
コード例 #8
0
def getStarsHotPixelsAlongTrail(m, b, starX, starY, starR, gX, gY, gR, hotX, hotY, dist):
    starX = np.array(starX)
    starY = np.array(starY)
    starR = np.array(starR)
    gX = np.array(gX)
    gY = np.array(gY)
    gR = np.array(gR)
    hotX = np.array(hotX)
    hotY = np.array(hotY)

    starPar,starPerp = GT.findDistances(starX,starY,m,b)
    gPar,gPerp = GT.findDistances(gX,gY,m,b)
    hotPar,hotPerp = GT.findDistances(hotX,hotY,m,b)

    starMask = (np.abs(np.abs(starPerp)-np.abs(starR))<=dist)
    gMask = (np.abs(np.abs(gPerp)-np.abs(gR))<=dist)
    hotMask = (np.abs(hotPerp)<=dist)

    return (starX[starMask], starY[starMask], starR[starMask], gX[gMask], gY[gMask], gR[gMask], hotX[hotMask], hotY[hotMask])
コード例 #9
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
コード例 #10
0
def removeTrailVertical(imgNoBackground, img, showProgress, x, trailSize):
    if showProgress:
        print("Fitting curve brightness...")
    b1, b2, b3, sDev = TF.findFitVertical(imgNoBackground, x, trailSize)
    if showProgress:
        print("Brightness fitted\n")
        print("Removing trail...")
    print(sDev)
    trail = GT.generateTrailVertical(x, b1, b2, b3, sDev, img.shape[1],
                                     img.shape[0])
    if showProgress:
        print("Trail removed!")
    return img - trail
コード例 #11
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
コード例 #12
0
def removeTrailHorizontal(imgNoBackground, img, showProgress, m, b, p1, p2,
                          starX, starY, starR, gX, gY, gR, hotX, hotY,
                          trailSize, PC):
    if showProgress:
        print("Fitting curve brightness...")

    sDev, brightness, offset = TF.findFitHorizontal(imgNoBackground, p1, p2,
                                                    starX, starY, starR, gX,
                                                    gY, gR, hotX, hotY,
                                                    trailSize, PC)

    if showProgress:
        print("Brightness fitted\n")
        print("Removing trail...")
    trail = GT.generateTrailHorizontal(m, b, brightness, sDev, img.shape[1],
                                       img.shape[0], offset)
    if showProgress:
        print("Trail removed!")
    imgNoTrail = img - trail
    showImageWithTrail(imgNoTrail, "Image Without Trail", p1, p2, False,
                       offset)
    mx = img.max()
    mn = img.min()
    median = np.median(img)

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

    axes[0].imshow(-img,
                   cmap=cm.gray,
                   vmin=-(mx + rescale * median) / (rescale + 1),
                   vmax=-(mn + rescale2 * median) / (rescale2 + 1))
    axes[1].imshow(-imgNoTrail,
                   cmap=cm.gray,
                   vmin=-(mx + rescale * median) / (rescale + 1),
                   vmax=-(mn + rescale2 * median) / (rescale2 + 1))
    plt.show()

    return imgNoTrail
コード例 #13
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()
コード例 #14
0
def removeStarsPSF(img, starPixX, starPixY, starR, mags, gX, gY, gR, p1, p2, radius, showProgress, inverted = False):
    remove = []
    for i in range(0,len(starPixX)):
        if i%100 == 0:
            print(i)
        for j in range(i+1,len(starPixX)):
            if np.abs(starPixX[i]-starPixX[j])<2.5*radius and np.abs(starPixY[i]-starPixY[j])<2.5*radius:
                remove.append(i)
                remove.append(j)
    
    mask = np.ones(len(starPixX), dtype = bool)
    mask[np.array(remove)] = 0

    starPixX = starPixX[mask]
    starPixY = starPixY[mask]
    starR = starR[mask]
    mags = mags[mask]

    print(radius)
    mask = np.ones(starPixX.shape[0],dtype=bool)
    for i in range(gX.shape[0]):
        mask = np.logical_and(mask, np.sqrt((starPixX-gX[i])**2+(starPixY-gY[i])**2)>gR[i]+2*radius)

    starPixX = starPixX[mask]
    starPixY = starPixY[mask]
    starR = starR[mask]
    mags = mags[mask]

    mask = (2*radius<starPixX) & (starPixX<img.shape[1]-2*radius) & (2*radius<starPixY) & (starPixY<img.shape[0]-2*radius)
    starPixX = starPixX[mask]
    starPixY = starPixY[mask]
    starR = starR[mask]
    mags = mags[mask]

    if p1[0]==p2[0]:
        psfMask = np.abs(starPixX-p1[0])>2.5*radius
        trailMask = np.abs(starPixX-p1[0])<10
        psfX = starPixX[psfMask]
        psfY = starPixY[psfMask]
        psfR = starR[psfMask]
        psfMags = mags[psfMask]
        trailX = starPixX[trailMask]
        trailY = starPixY[trailMask]
        trailMags = mags[trailMask]
    else:
        m,b = TF.getLineParams(p1,p2)
        par,perp = GT.findDistances(starPixX,starPixY,m,b)
        psfMask = np.abs(perp)>2.5*radius
        trailMask = np.abs(perp)<10
        psfX = starPixX[psfMask]
        psfY = starPixY[psfMask]
        psfR = starR[psfMask]
        psfMags = mags[psfMask]
        trailX = starPixX[trailMask]
        trailY = starPixY[trailMask]
        trailMags = mags[trailMask]

    mask = psfR>10

    psfX = psfX[mask]
    psfY = psfY[mask]
    psfMags = psfMags[mask]
    print(psfX.shape[0])

    showImageWithDetectedHotPixels(img, "Image with Star Picks", psfX, psfY, "b", inverted)

    psfX,psfY = centroid_sources(img, psfX, psfY, box_size=21, centroid_func=centroid_com)

    showImageWithDetectedHotPixels(img, "Image with Star Picks Centroid", psfX, psfY, "b", inverted)

    stars = Table()
    stars["x"] = psfX
    stars["y"] = psfY

    #stars2 = Table()
    #stars2["x_0"] = psfX
    #stars2["y_0"] = psfY

    stars = extract_stars(NDData(data=img), stars, size = 2*int(2*radius)+1)

    nrows = 5
    ncols = 5
    fig, ax = plt.subplots(nrows=nrows, ncols=ncols, figsize=(20, 20), squeeze=True)
    ax = ax.ravel()
    for i in range(nrows*ncols):
        norm = simple_norm(stars[i], 'log', percent=99.)
        ax[i].imshow(stars[i], norm=norm, origin='lower', cmap='viridis')

    plt.show()

    #sigma_psf = 2.0
    #daogroup = DAOGroup(2.0)
    #mmm_bkg = MMMBackground()
    #fitter = LevMarLSQFitter()
    #psf_model = PRF(sigma=sigma_psf)
    #photometry = BasicPSFPhotometry(group_maker=daogroup,bkg_estimator=mmm_bkg,psf_model=psf_model,fitter=LevMarLSQFitter(),fitshape=(11,11))
    #result_tab = photometry(image=img, init_guesses=stars2)
    #residual_image = photometry.get_residual_image()

    epsfBuilder = EPSFBuilder(oversampling=2, maxiters=20, smoothing_kernel = "quadratic")
    epsf, starFits = epsfBuilder(stars)

    #showImage(residual_image,"Image No Stars",True)

    norm = simple_norm(epsf.data, 'log', percent=99.)
    plt.imshow(epsf.data, norm=norm, origin='lower', cmap='viridis')
    plt.colorbar()
    plt.show()

    nrows = 5
    ncols = 5
    fig, ax = plt.subplots(nrows=nrows, ncols=ncols, figsize=(20, 20), squeeze=True)
    ax = ax.ravel()
    for i in range(nrows*ncols):
        norm = simple_norm(starFits[i], 'log', percent=99.)
        ax[i].imshow(starFits[i], norm=norm, origin='lower', cmap='viridis')

    plt.show()

    nrows = 5
    ncols = 5
    fig, ax = plt.subplots(nrows=nrows, ncols=ncols, figsize=(20, 20), squeeze=True)
    ax = ax.ravel()
    for i in range(nrows*ncols):
        norm = simple_norm(stars[i].data-starFits[i].data, 'log', percent=99.)
        ax[i].imshow(stars[i].data-starFits[i].data, norm=norm, origin='lower', cmap='viridis')

    plt.show()

    showImage(finalImg, "Image With No Stars", inverted)
コード例 #15
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)
コード例 #16
0
def getStars(trail, noTrail, baselineImages, trailCoords, noTrailCoords,
             baselineCoords, p1, p2):
    v = Vizier(row_limit=100000)

    center = trailCoords.all_pix2world(
        [(trail.shape[0] / 2, trail.shape[1] / 2)], 0, ra_dec_order=True)[0]
    corner = trailCoords.all_pix2world([(0, 0)], 0, ra_dec_order=True)[0]
    angle = np.sqrt((corner[0] - center[0])**2 + (corner[1] - center[1])**2)

    c = coordinates.SkyCoord(center[0],
                             center[1],
                             unit=('deg', 'deg'),
                             frame='icrs')
    starResult = v.query_region(c,
                                radius=angle * u.deg,
                                catalog=["I/337/gaia"])

    starCoords = []
    mags = []
    for item in starResult:
        for i in range(0, item["RA_ICRS"].shape[0]):
            starCoords.append((item["RA_ICRS"][i], item["DE_ICRS"][i]))
            mags.append(item["__Gmag_"][i])

    starPix = np.transpose(
        trailCoords.all_world2pix(starCoords, 0, ra_dec_order=True))
    starPixX = starPix[0]
    starPixY = starPix[1]
    mags = np.array(mags)

    mask = (starPixX > 50)

    mask = np.logical_and(mask, (starPixX < trail.shape[1] - 50))

    mask = np.logical_and(mask, (starPixY > 50))
    mask = np.logical_and(mask, (starPixY < trail.shape[0] - 50))
    mask = np.logical_and(mask, (starPixX + starPixY < 6000))

    mags = mags[mask]

    newStarCoords = []
    for i in range(len(starCoords)):
        if mask[i]:
            newStarCoords.append(starCoords[i])
    starCoords = newStarCoords

    starPix = np.transpose(
        noTrailCoords.all_world2pix(starCoords, 0, ra_dec_order=True))
    starPixX = starPix[0]
    starPixY = starPix[1]
    mags = np.array(mags)

    mask = (starPixX > 50)

    mask = np.logical_and(mask, (starPixX < trail.shape[1] - 50))

    mask = np.logical_and(mask, (starPixY > 50))
    mask = np.logical_and(mask, (starPixY < trail.shape[0] - 50))

    mags = mags[mask]

    newStarCoords = []
    for i in range(len(starCoords)):
        if mask[i]:
            newStarCoords.append(starCoords[i])
    starCoords = newStarCoords

    for coords in baselineCoords:
        starPix = np.transpose(
            coords.all_world2pix(starCoords, 0, ra_dec_order=True))
        starPixX = starPix[0]
        starPixY = starPix[1]
        mags = np.array(mags)

        mask = (starPixX > 50)

        mask = np.logical_and(mask, (starPixX < trail.shape[1] - 50))

        mask = np.logical_and(mask, (starPixY > 50))
        mask = np.logical_and(mask, (starPixY < trail.shape[0] - 50))

        mags = mags[mask]

        newStarCoords = []
        for i in range(len(starCoords)):
            if mask[i]:
                newStarCoords.append(starCoords[i])
        starCoords = newStarCoords

    trailStarPix = np.transpose(
        trailCoords.all_world2pix(starCoords, 0, ra_dec_order=True))
    trailStarPixX = trailStarPix[0]
    trailStarPixY = trailStarPix[1]

    showImageWithDetectedHotPixels(trail, "", trailStarPixX, trailStarPixY,
                                   "b", True)

    noTrailStarPix = np.transpose(
        noTrailCoords.all_world2pix(starCoords, 0, ra_dec_order=True))
    noTrailStarPixX = noTrailStarPix[0]
    noTrailStarPixY = noTrailStarPix[1]

    showImageWithDetectedHotPixels(noTrail, "", noTrailStarPixX,
                                   noTrailStarPixY, "b", True)

    baselineStarPixX = []
    baselineStarPixY = []
    for i in range(len(baselineCoords)):
        baselinePix = np.transpose(baselineCoords[i].all_world2pix(
            starCoords, 0, ra_dec_order=True))
        baselineStarPixX.append(baselinePix[0])
        baselineStarPixY.append(baselinePix[1])
        showImageWithDetectedHotPixels(baselineImages[i], "",
                                       baselineStarPixX[-1],
                                       baselineStarPixY[-1], "b", True)

    order = np.argsort(mags)
    trailStarPixX = trailStarPixX[order]
    trailStarPixY = trailStarPixY[order]
    noTrailStarPixX = noTrailStarPixX[order]
    noTrailStarPixY = noTrailStarPixY[order]
    for i in range(len(baselineStarPixX)):
        baselineStarPixX[i] = baselineStarPixX[i][order]
        baselineStarPixY[i] = baselineStarPixY[i][order]
    mags = mags[order]

    if p1[0] == p2[0]:
        perp = trailStarPixX - p1[0]
    else:
        m, b = getLineParams(p1, p2)
        par, perp = GT.findDistances(trailStarPixX, trailStarPixY, m, b)

    mask = (np.abs(perp) <= 20)
    antimask = (np.abs(perp) > 20)

    baselineStarTrailPixX = []
    baselineStarTrailPixY = []

    trailStarTrailPixX = trailStarPixX[mask][:12]
    trailStarTrailPixY = trailStarPixY[mask][:12]

    showImageWithDetectedHotPixels(trail, "", trailStarTrailPixX,
                                   trailStarTrailPixY, "b", True)

    noTrailStarTrailPixX = noTrailStarPixX[mask][:12]
    noTrailStarTrailPixY = noTrailStarPixY[mask][:12]

    showImageWithDetectedHotPixels(noTrail, "", noTrailStarTrailPixX,
                                   noTrailStarTrailPixY, "b", True)

    for i in range(len(baselineStarPixX)):
        baselineStarTrailPixX.append(baselineStarPixX[i][mask][:12])
        baselineStarTrailPixY.append(baselineStarPixY[i][mask][:12])
        showImageWithDetectedHotPixels(baselineImages[i], "",
                                       baselineStarTrailPixX[-1],
                                       baselineStarTrailPixY[-1], "b", True)

    baselineStarBackPixX = []
    baselineStarBackPixY = []

    trailStarBackPixX = trailStarPixX[antimask][:200]
    trailStarBackPixY = trailStarPixY[antimask][:200]

    showImageWithDetectedHotPixels(trail, "", trailStarBackPixX,
                                   trailStarBackPixY, "b", True)

    for i in range(len(baselineStarPixX)):
        baselineStarBackPixX.append(baselineStarPixX[i][antimask][:200])
        baselineStarBackPixY.append(baselineStarPixY[i][antimask][:200])
        showImageWithDetectedHotPixels(baselineImages[i], "",
                                       baselineStarBackPixX[-1],
                                       baselineStarBackPixY[-1], "b", True)

    return (trailStarTrailPixX, trailStarTrailPixY, noTrailStarTrailPixX,
            noTrailStarTrailPixY, baselineStarTrailPixX, baselineStarTrailPixY,
            trailStarBackPixX, trailStarBackPixY, baselineStarBackPixX,
            baselineStarBackPixY)
コード例 #17
0
                   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.title(title)

    plt.show()


inFile = "Images/FitsImages/2019-12-22_04-23-01__-30.00_60.00s_185_c.fits"
outFile = "Images/FitsImages/2019-12-22_04-23-01__-30.00_60.00s_185_c_double_trail.fits"

fitsImg = fits.open(inFile)
img = fitsImg[0].data.astype(np.float64)
for i in range(0, 10):
    trail = GT.generateTrailHorizontal(
        4 * np.random.random() - 2, 3000 * np.random.random(),
        0.0003 * np.random.random() - 0.000005,
        0.03 * np.random.random() - 0.0005, 50 * np.random.random() + 50,
        5 * np.random.random(), img.shape[1], img.shape[0])

    imgTrail = img + trail

    showImage(imgTrail, "Image with Artificial Trail", inverted=False)

    fits.writeto(outFile + str(i + 1), imgTrail, header=fitsImg[0].header)
コード例 #18
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