Esempio n. 1
0
def solve(fn):
    p = Dispatch('PinPoint.Plate')
    p.Catalog = 4  # Tycho2 catalog
    p.CatalogPath = filepath.catalog

    if 'B' in fn:
        p.colorband = 1  # B band
    else:
        p.colorband = 2  # V band

    fn_orig = fn
    m = int(fn_orig[-7:-4])

    if m in range(0, 50, 5):
        print 'Solving images %i/45' % m

    # Masking the area near the horizon in image 0-15
    if m < 16:
        f = fits.open(fn, uint=False)[0]
        f.data[630:] = 0.
        fn = fn[:-4] + 'c.fit'
        f.writeto(fn, overwrite=True)

    p.attachFits(fn)
    p.ArcsecPerPixelHoriz = 96
    p.ArcsecPerPixelVert = 96
    p.SigmaAboveMean = 3
    p.Minimumbrightness = 2500
    p.FindImageStars()

    p.RightAscension = p.TargetRightAscension
    p.Declination = p.TargetDeclination

    p.CatalogMaximumMagnitude = 7.
    p.CatalogMinimumMagnitude = 2.
    p.CatalogExpansion = 0.1
    p.Maxsolvetime = 60
    p.FindCatalogStars()

    try:
        p.Solve()
        p.UpdateFITS()
        message = ['normal', fn_orig]  # files that have been solved normally
    except:
        # trying to just solve the cropped (200x200 pix) image
        f = fits.open(fn, uint=False)[0]
        l = len(f.data) / 2
        f.data = f.data[l - 100:l + 100, l - 100:l + 100]
        fn = fn[:-4] + 's.fit'
        f.writeto(fn, overwrite=True)

        p.DetachFITS()
        p.attachFits(fn)
        p.ArcsecPerPixelHoriz = 96
        p.ArcsecPerPixelVert = 96
        p.SigmaAboveMean = 2
        p.Minimumbrightness = 2000
        p.FindImageStars()

        p.RightAscension = p.TargetRightAscension
        p.Declination = p.TargetDeclination

        p.CatalogMaximumMagnitude = 9.
        p.CatalogMinimumMagnitude = 2.
        p.CatalogExpansion = 0.3
        p.Maxsolvetime = 40
        p.FindCatalogStars()

        try:
            p.Solve()
            p.UpdateFITS()
            message = ['cropped',
                       fn_orig]  #files that have been cropped & solved
        except:
            message = ['failed',
                       fn_orig]  #files that haven been failed to solve

    p.DetachFITS()

    #save the updated fits header to the first row horizon images
    if (m < 16) & (p.solved == True):
        f = fits.open(fn_orig, uint=False)
        data = f[0].data.copy()
        f.close()
        header = fits.open(fn)[0].header
        fits.writeto(fn_orig, data, header=header, overwrite=True)

    return message