An Update on the SunPy Project

PyHC Spring Meeting / Virtual / 11 March 2024

Will Barnes

AU/NASA GSFC

Stuart Mumford

Aperio Software

The SunPy Project

What’s New in The SunPy Project?

  • v5.1 Released 21 November 2023
  • v6.0 coming May 2024
  • New affiliated package: sunkit-magex (a successor to pfsspy)
  • Updates to package template and packaging guide
  • pyOpenSci Partnership pyopensci

sunpy v5.1

  • New features in v5.1 include:
    • Calculating the amount of solar eclipse
    • Computations using SPICE kernels
    • Coordinate frames related to the Earth’s magnetic dipole
    • Support for GONG Synoptic Data
    • New Method for Determining Visibility of Helioprojective Coordinates
    • Improved Support for WISPR Data
  • By the numbers:
    • Since v5.0: 361 commits, 27 issues closed, 102 pull requests merged
    • 19 contributors, 7 of whom are new contributors
  • Full details here: docs.sunpy.org/en/stable/whatsnew

New Features: Calculating the Amount of a Solar Eclipse

from astropy.coordinates import EarthLocation, solar_system_ephemeris
from sunpy.coordinates.sun import eclipse_amount

location = EarthLocation.from_geodetic(-77.6088*u.deg, 43.1566*u.deg)  # Rochester, NY
times = Time('2024-04-08 19:22') + np.arange(-120, 121, 1/60) * u.min
observer = location.get_itrs(times)

with solar_system_ephemeris.set('de440s'):
    amount = eclipse_amount(observer)
Eclipse detected:
  Partial solar eclipse starts at 2024-04-08 18:07:04.000 UTC
  Total solar eclipse starts at 2024-04-08 19:20:09.000 UTC
  Total solar eclipse ends at 2024-04-08 19:23:49.000 UTC
  Partial solar eclipse ends at 2024-04-08 20:33:25.000 UTC

New Features: Computations Using SPICE Kernels

  • SPICE–used by space missions to describe the locations of spacecraft, time-varying orientations of reference frames
  • sunpy.coordinates.spice–use SkyCoord API to perform SPICE computations
  • Depends on spiceypy
from sunpy.coordinates import spice

spice.initialize(kernel_files)
spice.install_frame('IAU_SUN')

obstime = parse_time('2022-10-12') + np.arange(720) * u.min
spacecraft = spice.get_body('Solar Orbiter',
                            obstime,
                            spice_frame='SOLO_HEEQ')
print(spacecraft[:1])

with time_support():
  plt.plot(obstime, spacecraft.distance.to('AU'))
plt.ylabel('Radial Distance from Sun Center [AU]');
<SkyCoord (spice_SOLO_HEEQ: obstime=['2022-10-12T00:00:00.000']): (lon, lat, distance) in (deg, deg, km)
    [(-119.01442862, -3.70146925, 43862837.40904176)]>

New Features: Computations Using SPICE Kernels

spacecraft_gae = spacecraft.transform_to("spice_SOLO_GAE")
print(spacecraft_gae[:4])
<SkyCoord (spice_SOLO_GAE: obstime=['2022-10-12T00:00:00.000' '2022-10-12T00:01:00.000'
 '2022-10-12T00:02:00.000' '2022-10-12T00:03:00.000']): (lon, lat, distance) in (deg, deg, km)
    [(-149.06635461, -1.03769419, 1.74975667e+08),
     (-149.06492563, -1.03771064, 1.74972891e+08),
     (-149.06349666, -1.03772709, 1.74970115e+08),
     (-149.06206771, -1.03774353, 1.74967339e+08)]>
# 0 degrees is anti-Sun in the STIX frame
stix_ils = SkyCoord(np.repeat(0*u.deg, len(obstime)),
                    np.repeat(0*u.deg, len(obstime)),
                    frame='spice_SOLO_STIX_ILS', obstime=obstime)
print(stix_ils[:4])
<SkyCoord (spice_SOLO_STIX_ILS: obstime=['2022-10-12T00:00:00.000' '2022-10-12T00:01:00.000'
 '2022-10-12T00:02:00.000' '2022-10-12T00:03:00.000']): (lon, lat) in deg
    [(0., 0.), (0., 0.), (0., 0.), (0., 0.)]>
stix_fov = spice.get_fov('SOLO_STIX', obstime[0])
print(stix_fov)
<SkyCoord (spice_SOLO_STIX_ILS: obstime=2022-10-12T00:00:00.000): (lon, lat) in deg
    [( 179.,  0.99984773), ( 179., -0.99984773), (-179., -0.99984773),
     (-179.,  0.99984773)]>
stix_fov_hpc = stix_fov.to_helioprojective() 
print(stix_fov_hpc)
<SkyCoord (Helioprojective: obstime=2022-10-12T00:00:00.000, rsun=695700.0 km, observer=<HeliographicStonyhurst Coordinate (obstime=2022-10-12T00:00:00.000, rsun=695700.0 km): (lon, lat, radius) in (deg, deg, km)
    (-119.01442821, -3.70146956, 43862838.513974)>): (Tx, Ty) in arcsec
    [( 3127.44364431,  4016.75973995), ( 4017.02831673, -3126.97425142),
     (-3127.76039243, -4016.69031087), (-4017.34510585,  3127.04367531)]>

Introducing sunkit-magex

  • pfsspyde facto way to do PFSS extrapolations in Python
  • pfsspy is no longer maintained
  • sunkit-magex package
    • SunPy-affiliated package maintained by the SunPy Project
    • Currently “just a fork” of pfsspy
    • Future: interface to other extrapolation methods, e.g. NLFF, other PF methods
  • streamtracer package now also under SunPy Project: github.com/sunpy/streamtracer

The SunPy Package Template

  • Updated OpenAstronomy packaging guide: packaging-guide.openastronomy.org
    • Narrative documentation describing how to structure a package
    • cruft to automate updates to packages when template changes
    • cruft create github.com/OpenAstronomy/packaging-guide
  • Differences with pyOpenSci?
    • More opinionated, specific choices
    • Everything “looks like” sunpy/astropy
  • OpenAstronomy template + SunPy specific functionality: github.com/sunpy/package-template
    • Enable automatic packaging, linting and other configuration updates over all SunPy-maintained packages.

Summary

  • v5.1 Released 21 November 2023
    • Calculating the amount of solar eclipse
    • Computations using SPICE kernels
    • Coordinate frames related to the Earth’s magnetic dipole
  • v6.0 coming May 2024
  • New affiliated package: sunkit-magex
  • Updates to package template and packaging guide
  • pyOpenSci Partnership pyopensci