Cropping a Map

How to crop a map by using submap.

import astropy.units as u
from astropy.coordinates import SkyCoord

import sunpy.map
import sunpy.data.sample
import matplotlib.pyplot as plt

We start with the sample data

swap_map = sunpy.map.Map(sunpy.data.sample.SWAP_LEVEL1_IMAGE)

To crop the data you create a submap, specifying the top right and bottom left as SkyCoord objects.

top_right = SkyCoord(0 * u.arcsec, -200 * u.arcsec, frame=swap_map.coordinate_frame)
bottom_left = SkyCoord(-900 * u.arcsec, -900 * u.arcsec, frame=swap_map.coordinate_frame)
swap_submap = swap_map.submap(bottom_left, top_right)

Out:

/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/v1.1.4/lib/python3.8/site-packages/sunpy/map/mapbase.py:294: RuntimeWarning: cdelt will be ignored since cd is present
  w2.wcs.cdelt = u.Quantity(self.scale)
/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/v1.1.4/lib/python3.8/site-packages/sunpy/map/mapbase.py:294: RuntimeWarning: cdelt will be ignored since cd is present
  w2.wcs.cdelt = u.Quantity(self.scale)
/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/v1.1.4/lib/python3.8/site-packages/sunpy/map/mapbase.py:294: RuntimeWarning: cdelt will be ignored since cd is present
  w2.wcs.cdelt = u.Quantity(self.scale)
/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/v1.1.4/lib/python3.8/site-packages/sunpy/map/mapbase.py:294: RuntimeWarning: cdelt will be ignored since cd is present
  w2.wcs.cdelt = u.Quantity(self.scale)
/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/v1.1.4/lib/python3.8/site-packages/sunpy/map/mapbase.py:294: RuntimeWarning: cdelt will be ignored since cd is present
  w2.wcs.cdelt = u.Quantity(self.scale)

Let’s plot the results

fig = plt.figure()
ax = fig.add_subplot(111, projection=swap_submap)
swap_submap.plot()
swap_submap.draw_limb()
swap_submap.draw_grid()
plt.show()
SWAP $174 \; \mathrm{\mathring{A}}$ 2011-06-07 06:33:29

Out:

/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/v1.1.4/lib/python3.8/site-packages/sunpy/map/mapbase.py:294: RuntimeWarning: cdelt will be ignored since cd is present
  w2.wcs.cdelt = u.Quantity(self.scale)
/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/v1.1.4/lib/python3.8/site-packages/sunpy/map/mapbase.py:294: RuntimeWarning: cdelt will be ignored since cd is present
  w2.wcs.cdelt = u.Quantity(self.scale)
/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/v1.1.4/lib/python3.8/site-packages/sunpy/map/mapbase.py:294: RuntimeWarning: cdelt will be ignored since cd is present
  w2.wcs.cdelt = u.Quantity(self.scale)
/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/v1.1.4/lib/python3.8/site-packages/sunpy/map/mapbase.py:588: SunpyUserWarning: Missing metadata for solar radius: assuming photospheric limb as seen from Earth.
  warnings.warn("Missing metadata for solar radius: assuming photospheric limb as seen from Earth.",
/home/docs/checkouts/readthedocs.org/user_builds/sunpy/conda/v1.1.4/lib/python3.8/site-packages/sunpy/map/mapbase.py:294: RuntimeWarning: cdelt will be ignored since cd is present
  w2.wcs.cdelt = u.Quantity(self.scale)

Total running time of the script: ( 0 minutes 2.241 seconds)

Gallery generated by Sphinx-Gallery