if not 'fe' in locals():
    import pyfits
    #fe_NS_mosaic.fits H2_NS_mosaic.fits   H2_mosaic.fits      KS_mosaic.fits      Ks_NS_mosaic.fits
    # fe_montage_georgs_southeast.fits
    # altair_big_h2.fits
    # fe_montage_georgs_southeast.fits
    fef = pyfits.open('altair_big_fe.fits')
    fe = fef[0].data
    if os.path.exists('altair_big_fe_unsharp.fits'):
        feunsharp = pyfits.getdata('altair_big_fe_unsharp.fits')
        fenormed = pyfits.getdata('altair_big_fe_normed.fits')
    else:
        #kernel = astropy.nddata.convolution.make_kernel.make_kernel([151,151],kernelwidth=50)
        #fesmooth = astropy.nddata.convolve(fe,kernel)
        fesmooth = agpy.smooth(mask_image(fe,downsample=4),250, fft_pad=False,
                interpolate_nan=True, psf_pad=False, ignore_edge_zeros=True,
                normalize_kernel=True, use_numpy_fft=True, nthreads=1,
                use_rfft=True, complextype=np.float32, silent=False,
                boundary='fill')
        feunsharp = fe
        for ii in xrange(4):
            for jj in xrange(4):
                shape = feunsharp[ii::4,jj::4].shape
                feunsharp[ii::4,jj::4] -= fesmooth[:shape[0],:shape[1]]
        fef[0].data = feunsharp
        fef.writeto("altair_big_fe_unsharp.fits",clobber=True)
        fenormed = fe
        for ii in xrange(4):
            for jj in xrange(4):
                shape = fenormed[ii::4,jj::4].shape
import agpy
import numpy as np
import PIL, ImageEnhance
prefix = ""

if not 'fe' in locals():
    import pyfits
    fef = pyfits.open('big_mosaic_feii.fits')
    fe = fef[0].data
    if os.path.exists('big_mosaic_feii_unsharp.fits'):
        feunsharp = pyfits.getdata('big_mosaic_feii_unsharp.fits')
        fenormed = pyfits.getdata('big_mosaic_feii_normed.fits')
    else:
        #kernel = astropy.nddata.convolution.make_kernel.make_kernel([151,151],kernelwidth=50)
        #fesmooth = astropy.nddata.convolve(fe,kernel)
        mimg = mask_image(fe, downsample=4)
        fesmooth = agpy.smooth(mimg,
                               250,
                               fft_pad=False,
                               interpolate_nan=True,
                               psf_pad=False,
                               ignore_edge_zeros=True,
                               normalize_kernel=True,
                               use_numpy_fft=True,
                               nthreads=1,
                               use_rfft=True,
                               complextype=np.float32,
                               silent=False,
                               boundary='fill')
        feunsharp = fe
        for ii in xrange(4):
import FITS_tools
prefix=""

if not 'fe' in locals():
    fef = pyfits.open('big_mosaic_feii.fits')
    header = fef[0].header
    fe = fef[0].data
    avm = pyavm.AVM.from_header(header)
    mywcs = avm.to_wcs()
    if os.path.exists('big_mosaic_feii_unsharp.fits'):
        feunsharp = pyfits.getdata('big_mosaic_feii_unsharp.fits')
        fenormed = pyfits.getdata('big_mosaic_feii_normed.fits')
    else:
        #kernel = astropy.nddata.convolution.make_kernel.make_kernel([151,151],kernelwidth=50)
        #fesmooth = astropy.nddata.convolve(fe,kernel)
        mimg = mask_image(fe,downsample=4)
        fesmooth = convolve_fft(mimg, Gaussian2DKernel(250), fft_pad=False,
                                interpolate_nan=True, psf_pad=False,
                                ignore_edge_zeros=True, normalize_kernel=True,
                                use_numpy_fft=True, nthreads=1, use_rfft=True,
                                complextype=np.float32, silent=False,
                                boundary='fill')
        feunsharp = fe
        for ii in range(4):
            for jj in range(4):
                shape = feunsharp[ii::4,jj::4].shape
                feunsharp[ii::4,jj::4] -= fesmooth[:shape[0],:shape[1]]
        fef[0].data = feunsharp
        fef.writeto("big_mosaic_feii_unsharp.fits",clobber=True)
        fenormed = fe
        for ii in range(4):