Planet_list in SunPy

I have used the following code to generate the position of the planets:

import matplotlib.pyplot as plt
from astropy.time import Time
from sunpy.coordinates import get_body_heliographic_stonyhurst
obstime = Time('1999-10-24T18:56:00.000')
planet_list = ['sun', 'earth', 'jupiter']
planet_coord = [get_body_heliographic_stonyhurst(
    this_planet, time=obstime) for this_planet in planet_list]
fig = plt.figure()
ax = fig.add_subplot(projection='polar')
for this_planet, this_coord in zip(planet_list, planet_coord):
    ax.plot(this_coord.lon.to('rad'), this_coord.radius, 'o', label=this_planet)
ax.legend()
plt.show()

However, the output also lists some numbers 2, 3 and 4 without any name of the planets.

(1.) I just need the planets in the list labelled in planet_list = ; kindly suggest how to implement.

(2.) Also, how to specify the resolution of the output image; presently it is 453*442 pixels.
Forum24052023PM1223

Hi Smarty,

So those number labels are actually the tickmarks on the radius axis. i.e. these are the distance from the barycentre in AU, not planets.

As for setting the figure size, matplotlib doesn’t work with pixel sizes, rather it uses a physical size and a DPI but you can always calculate a pixel size using the DPI:

import matplotlib.pyplot as plt
from astropy.time import Time
from sunpy.coordinates import get_body_heliographic_stonyhurst
obstime = Time('1999-10-24T18:56:00.000')
planet_list = ['sun', 'earth', 'jupiter']
planet_coord = [get_body_heliographic_stonyhurst(
     this_planet, time=obstime) for this_planet in planet_list]
pixel_size = [1000,1000]
fig = plt.figure()
dpi = fig.get_dpi()
fig.set_size_inches(pixel_size[0]/dpi, pixel_size[1]/dpi)
ax = fig.add_subplot(projection='polar')
for this_planet, this_coord in zip(planet_list, planet_coord):
    ax.plot(this_coord.lon.to('rad'), this_coord.radius, 'o', label=this_planet)
ax.legend()
plt.show()

Hope that helps you,

3 Likes

The Refined Code has perfectly rendered the image, thank you.

Thus, i can see that, the Code that does the work is:

pixel_size = [1000,1000]
dpi = fig.get_dpi()
fig.set_size_inches(pixel_size[0]/dpi, pixel_size[1]/dpi)

Now, if we need the image, say in 300 dpi, kindly suggest how to tweak the Code.

fig.set_dpi(300)

Will set the figure dpi to 300.

2 Likes

Thank you alasdairwilson. The finalized Code that plots the position of the planets on a specific date and time, and render the output image in terms of dpi is:

import matplotlib.pyplot as plt
from astropy.time import Time
from sunpy.coordinates import get_body_heliographic_stonyhurst
obstime = Time('1999-10-24T18:56:00.000')
planet_list = ['sun', 'earth', 'jupiter']
planet_coord = [get_body_heliographic_stonyhurst(
     this_planet, time=obstime) for this_planet in planet_list]
fig = plt.figure()
fig.set_dpi(300)
ax = fig.add_subplot(projection='polar')
for this_planet, this_coord in zip(planet_list, planet_coord):
    ax.plot(this_coord.lon.to('rad'), this_coord.radius, 'o', label=this_planet)
ax.legend()
plt.show()

Myself tried to understand get_body_heliographic_stonyhurst, and found the following two references: Coordinate systems for solar image data and HeliographicStonyhurst. These are much useful to understand the coordinate system.

But still i couldn’t understand how to retrieve the position r and the longitude λ of Sun, Earth and Jupiter in the aforementioned Code. Since these are already plotted means it is calculated. I need help.

In your code, the SkyCoord object for the Sun is planet_coord[0], for the Earth is planet_coord[1], and for Jupiter is planet_coord[2]. Then, for example, “position r” of Jupiter is:

>>> planet_coord[2].radius
<Distance 4.95773414 AU>

and “longitude λ” of Jupiter is:

>>>  planet_coord[2].lon
<Longitude -1.02094647 deg>

Since you are using Stonyhurst heliographic coordinates, the Sun is at zero radius and zero longitude by definition, and the Earth is at zero longitude also by definition.