# Longitude and Latitude Lines¶

How to draw your own (Stonyhurst) longitude and latitude lines

from __future__ import print_function, division

import numpy as np
import astropy.units as u
import matplotlib.pyplot as plt

from astropy.coordinates import SkyCoord

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


We first create the Map using the sample data.

aia = sunpy.map.Map(AIA_171_IMAGE)


Let’s first consider a simple example of transforming a single coordinate. Here we consider the “center” coordinate of 0,0 degrees

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


Next we transform it into the coordinate frame of our map which is in helioprojective coordinates though we don’t really need to know that.

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


Out:

<SkyCoord (Helioprojective: obstime=2011-06-07 06:33:02.770000, rsun=696000000.0 m, observer=<HeliographicStonyhurst Coordinate (obstime=2011-06-07 06:33:02.770000): (lon, lat, radius) in (deg, deg, m)
(0., 0.048591, 1.51846026e+11)>): (Tx, Ty, distance) in (arcsec, arcsec, km)
(0., -0.80491639, 1.51150519e+08)>


Now let’s consider transform two lines, one of zero longitude and one of of zero latitude. First define the coordinates as we did before and then transform them.

lon0 = SkyCoord(np.linspace(-80, 80, 100) * u.deg,
np.zeros(100) * u.deg, frame=frames.HeliographicStonyhurst)
lat0 = SkyCoord(np.zeros(100) * u.deg,
np.linspace(-90, 90, 100)*u.deg,
frame=frames.HeliographicStonyhurst)

hpc_lon0 = lon0.transform_to(aia.coordinate_frame)
hpc_lat0 = lat0.transform_to(aia.coordinate_frame)


Let’s now plot the results. We’ll overlay the autogenerated SunPy lon/lat grid as well for comparison.

fig = plt.figure()
ax = plt.subplot(projection=aia)
aia.plot()
ax.plot_coord(hpc_lat0, color="C0")
ax.plot_coord(hpc_lon0, color="C0")
aia.draw_grid()
plt.show()


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

Gallery generated by Sphinx-Gallery