.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "generated/gallery/retrieve_compress.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_generated_gallery_retrieve_compress.py: ========================================================================= 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) convert this to Level 1.5 AIA data using aiapy, 3) deconvolve the FITS file using aiapy, and 4) demonstrate the compression ability of Astropy when saving the file. .. GENERATED FROM PYTHON SOURCE LINES 14-15 First import the packages .. GENERATED FROM PYTHON SOURCE LINES 15-27 .. code-block:: default import astropy import astropy.units as u from astropy.io.fits import CompImageHDU from sunpy.net import Fido, attrs as a import sunpy.map import aiapy.psf as psf_ from aiapy.calibrate import register, update_pointing import os .. GENERATED FROM PYTHON SOURCE LINES 28-29 Use the SunPy tool `Fido `_ to find and download level 1 AIA data. .. GENERATED FROM PYTHON SOURCE LINES 29-34 .. code-block:: default q = Fido.search(a.Time('2011-06-07T06:52:00', '2011-06-07T06:52:10'), a.Instrument('AIA'), a.Wavelength(wavemin=171*u.angstrom, wavemax=171*u.angstrom)) aia_map = sunpy.map.Map(Fido.fetch(q)) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Files Downloaded: 0%| | 0/1 [00:00`_ example in aiapy documentation for more details. .. GENERATED FROM PYTHON SOURCE LINES 37-43 .. code-block:: default m_updated_pointing = update_pointing(aia_map) m_registered = register(m_updated_pointing) m_normalized = sunpy.map.Map( m_registered.data/m_registered.exposure_time.to(u.s).value, m_registered.meta) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none /Users/shpo9723/git/gallery/.tox/build_gallery/lib/python3.9/site-packages/astropy/wcs/wcs.py:707: FITSFixedWarning: 'datfix' made the change 'Set MJD-OBS to 55719.286115 from DATE-OBS'. warnings.warn( /Users/shpo9723/git/gallery/.tox/build_gallery/lib/python3.9/site-packages/astropy/table/table.py:3899: AstropyUserWarning: dropping mask in Quantity column 'A_304_X0': masked Quantity not supported warnings.warn("dropping mask in Quantity column '{}': " /Users/shpo9723/git/gallery/.tox/build_gallery/lib/python3.9/site-packages/astropy/table/table.py:3899: AstropyUserWarning: dropping mask in Quantity column 'A_304_Y0': masked Quantity not supported warnings.warn("dropping mask in Quantity column '{}': " /Users/shpo9723/git/gallery/.tox/build_gallery/lib/python3.9/site-packages/astropy/wcs/wcs.py:707: FITSFixedWarning: 'datfix' made the change 'Set MJD-OBS to 55719.286115 from DATE-OBS'. warnings.warn( /Users/shpo9723/git/gallery/.tox/build_gallery/lib/python3.9/site-packages/sunpy/image/transform.py:120: SunpyUserWarning: Integer input data has been cast to float64. warnings.warn("Integer input data has been cast to float64.", .. GENERATED FROM PYTHON SOURCE LINES 44-48 Compute the point-spread function (PSF) and use it to deconvolve the image. 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. .. GENERATED FROM PYTHON SOURCE LINES 48-51 .. code-block:: default psf = psf_.psf(m_normalized.wavelength) map_deconvolved = psf_.deconvolve(m_normalized, psf=psf) .. GENERATED FROM PYTHON SOURCE LINES 52-54 Save the deconvolved image as a FITS file without compression using SunPy. Note: this resulted in a 128 MB file while testing. .. GENERATED FROM PYTHON SOURCE LINES 54-61 .. code-block:: default map_deconvolved.save('aia_map_deconv.fits') print(os.path.getsize('aia_map_deconv.fits')) # This time pass SunPy the `CompImagHDU `_ compression routine from Astropy. sunpy.io.fits.write('aia_map_deconv_comp.fits', map_deconvolved.data, map_deconvolved.fits_header, hdu_type=CompImageHDU) print(os.path.getsize('aia_map_deconv_comp.fits')) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none /Users/shpo9723/git/gallery/.tox/build_gallery/lib/python3.9/site-packages/astropy/io/fits/hdu/image.py:605: VerifyWarning: Invalid 'BLANK' keyword in header. The 'BLANK' keyword is only applicable to integer data, and will be ignored in this HDU. warnings.warn(msg, VerifyWarning) 134236800 14181120 .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 6 minutes 55.505 seconds) .. _sphx_glr_download_generated_gallery_retrieve_compress.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/HeliophysicsPy/gallery/gh-pages?urlpath=lab/tree/notebooks/generated/gallery/retrieve_compress.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: retrieve_compress.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: retrieve_compress.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_