.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "generated/gallery/remove_lightleak.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_generated_gallery_remove_lightleak.py: =================== Removing Light Leak =================== In this example, we show how to remove the light leak (visible stray light) from XRT synoptic composite images. .. GENERATED FROM PYTHON SOURCE LINES 9-19 .. code-block:: Python from pathlib import Path import matplotlib.pyplot as plt import sunpy.map from astropy.utils.data import get_pkg_data_path from astropy.visualization import ImageNormalize, SqrtStretch from xrtpy.image_correction import remove_lightleak .. GENERATED FROM PYTHON SOURCE LINES 20-22 This example will be using XRT synoptic data from the first day of summer of 2015. This is stored in the ``example_data`` directory of the `xrtpy` package. .. GENERATED FROM PYTHON SOURCE LINES 22-27 .. code-block:: Python directory = get_pkg_data_path("data/example_data", package="xrtpy.image_correction") data_file = Path(directory) / "comp_XRT20150621_055911.7.fits" xrt_map = sunpy.map.Map(data_file) .. GENERATED FROM PYTHON SOURCE LINES 28-29 Removing the light leak from the composite image is done using the `xrtpy.image_correction.remove_lightleak` function. .. GENERATED FROM PYTHON SOURCE LINES 29-32 .. code-block:: Python lightleak_map = remove_lightleak(xrt_map) .. GENERATED FROM PYTHON SOURCE LINES 33-34 Finally, we plot the original and light leak subtracted images side by side. .. GENERATED FROM PYTHON SOURCE LINES 34-54 .. code-block:: Python fig = plt.figure(figsize=(12, 6)) ax = fig.add_subplot(121, projection=xrt_map) xrt_map.plot( axes=ax, title="Original", norm=ImageNormalize(vmin=0, vmax=7e3, stretch=SqrtStretch()), ) ax1 = fig.add_subplot(122, projection=lightleak_map) lightleak_map.plot( axes=ax1, title="Light Leak Subtracted", norm=ImageNormalize(vmin=0, vmax=7e3, stretch=SqrtStretch()), ) ax1.coords[1].set_ticks_visible(False) ax1.coords[1].set_ticklabel_visible(False) fig.tight_layout() .. image-sg:: /generated/gallery/images/sphx_glr_remove_lightleak_001.png :alt: Original, Light Leak Subtracted :srcset: /generated/gallery/images/sphx_glr_remove_lightleak_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 55-57 They look almost identical, but the light leak has been removed from the second image. To confirm this we can plot the difference between the two images. .. GENERATED FROM PYTHON SOURCE LINES 57-69 .. code-block:: Python diff_data = xrt_map.data - lightleak_map.data # For this image, the difference is very small. print(diff_data.min(), diff_data.max()) fig = plt.figure() ax = fig.add_subplot(111) ax.set_title("Lightleak Difference") im = ax.imshow(diff_data, origin="lower") fig.colorbar(im) plt.show() .. image-sg:: /generated/gallery/images/sphx_glr_remove_lightleak_002.png :alt: Lightleak Difference :srcset: /generated/gallery/images/sphx_glr_remove_lightleak_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none -4.0320206 6.7845306 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.568 seconds) .. _sphx_glr_download_generated_gallery_remove_lightleak.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: remove_lightleak.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: remove_lightleak.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: remove_lightleak.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_