Downloading and Compressing a FITS file using SunPy, aiapy, and Astropy#

Written by Matt Wentzel-Long. The purpose of this demo is to demonstrate:

  1. SunPy’s ability to retrieve a Level 1 AIA data, 2) deconvolve the FITS file using aiapy,

  2. convert this to Level 1.5 AIA data using aiapy, and 4) demonstrate the compression ability of Astropy when saving the file.

First import the packages

import astropy.units as u
from import CompImageHDU

from import Map
from import Fido, attrs as a

import aiapy.psf as psf_
from aiapy.calibrate import register, update_pointing

import os

Use the SunPy tool Fido to find and download level 1 AIA data.

q ='2011-06-07T06:52:00', '2011-06-07T06:52:10'),
                a.Wavelength(wavemin=171*u.angstrom, wavemax=171*u.angstrom))
aia_map = Map(Fido.fetch(q))

Compute the point-spread function (PSF) and use it to deconvolve the image. Deconvolution should only be performed on level 1 data (see this guide for prepairing AIA data using aiapy). Warning: the PSF computation can take over 16 minutes on a CPU. If you have an NVIDIA GPU and CuPy installed, then PSF will automatically use it. See the PSF documentation for details.

psf = psf_.psf(aia_map.wavelength)
map_deconvolved = psf_.deconvolve(aia_map, psf=psf)

Convert to level 1.5 AIA data. See the registering and aligning level 1 data example in aiapy documentation for more details.

m_updated_pointing = update_pointing(map_deconvolved)
m_registered = register(m_updated_pointing)
m_normalized = Map(, 

Save the deconvolved image as a FITS file without compression using SunPy. Note: this resulted in a 128 MB file while testing.'aia_map_deconv.fits')
WARNING: VerifyWarning: Invalid 'BLANK' keyword in header.  The 'BLANK' keyword is only applicable to integer data, and will be ignored in this HDU. []

This time pass SunPy the CompImagHDU compression routine from Astropy.'aia_map_deconv_comp.fits', hdu_type=CompImageHDU)