Пример #1
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)
Пример #2
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])
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)
Пример #4
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)