File: create_rectangle_on_map.rst

package info (click to toggle)
sunpy 7.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,632 kB
  • sloc: python: 41,887; ansic: 1,720; makefile: 28
file content (97 lines) | stat: -rw-r--r-- 3,171 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
.. _sunpy-how-to-create-rectangle-on-map:

**************************************
Draw a rectangle on a `~sunpy.map.Map`
**************************************

``sunpy`` provides a convenient method called :meth:`~sunpy.map.GenericMap.draw_quadrangle` to draw rectangles on maps.
In this guide, we will demonstrate four different methods to draw a rectangle on a `sunpy.map.Map`.

Specify corners with a single `~astropy.coordinates.SkyCoord`
=============================================================

We will use one `~astropy.coordinates.SkyCoord` to represent the two opposite corners.

.. plot::
    :include-source:
    :context: close-figs

    import matplotlib.pyplot as plt

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

    import sunpy.data.sample
    import sunpy.map

    aia_map = sunpy.map.Map(sunpy.data.sample.AIA_171_IMAGE)

    fig = plt.figure()
    ax = fig.add_subplot(projection=aia_map)

    aia_map.plot(axes=ax, clip_interval=(1, 99.99)*u.percent)

    coords = SkyCoord(Tx=(100, 500) * u.arcsec, Ty=(200, 500) * u.arcsec,frame=aia_map.coordinate_frame)
    aia_map.draw_quadrangle(coords, axes=ax, edgecolor="blue")

    plt.show()

Specify corners with separate `~astropy.coordinates.SkyCoord`
=============================================================

We will use two `~astropy.coordinates.SkyCoord` to represent the two opposite corners.

.. plot::
    :include-source:
    :context: close-figs

    fig = plt.figure()
    ax = fig.add_subplot(projection=aia_map)

    aia_map.plot(axes=ax, clip_interval=(1, 99.99)*u.percent)

    bottom_left = SkyCoord(100 * u.arcsec, 200 * u.arcsec, frame=aia_map.coordinate_frame)
    top_right = SkyCoord(500 * u.arcsec, 500 * u.arcsec, frame=aia_map.coordinate_frame)
    aia_map.draw_quadrangle(bottom_left, axes=ax, top_right=top_right, edgecolor="green")

    plt.show()

Specify one corner with a width and height
==========================================

We will use one `~astropy.coordinates.SkyCoord` to represent the bottom left and supply a width and height to complete the rectangle.

.. plot::
    :include-source:
    :context: close-figs

    fig = plt.figure()
    ax = fig.add_subplot(projection=aia_map)

    aia_map.plot(axes=ax, clip_interval=(1, 99.99)*u.percent)

    bottom_left = SkyCoord(100 * u.arcsec, 200 * u.arcsec, frame=aia_map.coordinate_frame)
    width = 400 * u.arcsec
    height = 300 * u.arcsec
    aia_map.draw_quadrangle(bottom_left, axes=ax, width=width, height=height, edgecolor="yellow")

    plt.show()

Using pixel coordinates
=======================

We will use a `~astropy.coordinates.SkyCoord` to work out the pixel coordinates instead of using coordinates as we do above.

.. plot::
    :include-source:
    :context: close-figs

    fig = plt.figure()
    ax = fig.add_subplot(projection=aia_map)
    aia_map.plot(axes=ax, clip_interval=(1, 99.99)*u.percent)

    bottom_left = aia_map.wcs.pixel_to_world(551 * u.pixel, 594 * u.pixel)
    top_right = aia_map.wcs.pixel_to_world(717 * u.pixel, 719 * u.pixel)
    aia_map.draw_quadrangle(bottom_left, axes=ax, top_right=top_right, edgecolor="red")

    plt.show()