File: lat_lon_lines.py

package info (click to toggle)
sunpy 4.1.2-1%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 11,972 kB
  • sloc: python: 39,301; ansic: 1,780; makefile: 35
file content (63 lines) | stat: -rw-r--r-- 2,384 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
"""
=================================================
Drawing heliographic longitude and latitude lines
=================================================

How to draw your own (Stonyhurst) longitude and latitude lines.
"""
import matplotlib.pyplot as plt
import numpy as np

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

import sunpy.map
from sunpy.coordinates import frames
from sunpy.data.sample import AIA_171_IMAGE

###############################################################################
# The purpose of this example is to demonstrate the coordinate transformations
# that occur under the hood to show the heliographic grid lines of longitude
# latitude. We first create the Map using the sample data.

aia = sunpy.map.Map(AIA_171_IMAGE)

###############################################################################
# Let's first transform a single heliographic point coordinate.

stonyhurst_center = SkyCoord(12 * u.deg, 12 * u.deg,
                             frame=frames.HeliographicStonyhurst)

###############################################################################
# Next we transform it into the coordinate frame of our map which is in
# helioprojective coordinates.

hpc_stonyhurst_center = stonyhurst_center.transform_to(aia.coordinate_frame)
print(hpc_stonyhurst_center)

###############################################################################
# Now let's define two lines, one of longitude and one of of latitude.
# We don't need to explicitly transform them to the coordinate frame of our
# map because they will be transformed automatically when plotted.

num_points = 100
lat_value = 12 * u.deg
lon_value = 35 * u.deg
lon0 = SkyCoord(np.linspace(-80, 80, num_points) * u.deg,
                np.ones(num_points) * lon_value, frame=frames.HeliographicStonyhurst)
lat0 = SkyCoord(np.ones(num_points) * lat_value,
                np.linspace(-90, 90, num_points) * u.deg,
                frame=frames.HeliographicStonyhurst)

###############################################################################
# Now let's plot the results. We'll overlay the autogenerated lon/lat
# grid as well for comparison.

fig = plt.figure()
ax = fig.add_subplot(projection=aia)
aia.plot(axes=ax, clip_interval=(1, 99.99)*u.percent)
ax.plot_coord(lat0, color="C0")
ax.plot_coord(lon0, color="C0")
aia.draw_grid(axes=ax)

plt.show()