In [3]:
%%file custom.css
body {
    font-size: 140%;
    font-family: Lato, Ariel, sans-serif !important;
}

div.slides {
    margin-top: -7%;
}

.left {
    width: 49%;
    float: left;
}

.right {
    width: 49%;
    float: right;
}

.centre {
    text-align: center;
}

h2 {
    text-align: center;
}

div.prompt {
    display: none;
}

div.highlight {
    font-size: 85%; /* This Seems to give an approximate 80char line at 1024 */
}

div.output_html {
    font-size: 85%;
}

li {
    padding-top: 1em !important;
}
Overwriting custom.css

Plan:

  • What is SunPy?

    • Project
    • Community
    • Library
      • Datatypes
      • Downloaders
  • What are people using at the moment?

    • SSWIDL
  • Spreading the SunPy.

    • Bootcamps
    • News
    • Making SunPy Better.
  • The Future for the library and project.

    • Coordinates
    • Downloader
    • More Astropy integration.

SunPy - Python for Solar Physics

Stuart Mumford

The University of Sheffield, UK

The Legacy IDL Code Base

Currently most people in Solar Physics use IDL, and SolarSoft (SSW).

Some Statistics

  • 16 GB
  • 4,543 Directories
  • 138,192 Files
  • 24,383 IDL .pro files containing 3,982,599 lines.
  • 868 .h files containing 685,690 lines.
  • 133 C (.c) files containing 119,976 lines.
  • 5,473,955 Million LOC

Files by Extension

  1. 'genx': 30525
  2. '.pro': 24383
  3. '.dat': 19437
  4. '.fts': 11657
  5. '.log': 10885
  6. '.sav': 6579

The Legacy IDL Code Bases

Other file extensions

  • '' (No extension): 3046
  • '.pro~': 43
  • '.pro_tmp': 45
  • '.exe': 132
  • '.py': 44

Name Conflicts

  • File conflicts: 1879
  • Conflicts where the code differs: 713
  • Total number of conflicting files: 5113

Facts about SSW

  • 'SolarSoft' came into existence around the launch of the SOHO satellite (~1994).
  • Distributed via Perl download (FTP) scripts or rsync.
  • 'gen' tree is managed by people at GSFC.
  • Other trees are managed by other groups, with varying quality control.

What is SunPy?

"A Project to facilitate and promote the use and development of a community-led, free and open-source solar data-analysis software based on the scientific Python environment."

A project to provide a viable alternative .

A community of solar phyicists doing science using Python.

A group of people ranting on IRC.

What can it do?!

The SunPy library currently fulfills two core needs for Solar Physics:

Data Containers

  • Map
  • Lightcurve
  • Spectra

Data Retrevial

Client for common sources of solar physics data, and also generic http or ftp repositories.

  • Virtual Solar Observatory (VSO)
  • Joint Science Operations Center (JSOC)
  • Other small sources.

Contained Data

For example, images:

In [1]:
%matplotlib inline
import matplotlib.pyplot as plt
import sunpy.data
from sunpy.data.sample import AIA_171_IMAGE
In [2]:
import sunpy.map

mymap = sunpy.map.Map(AIA_171_IMAGE)
fig = plt.figure(figsize=(8,6))
im = mymap.plot()
ax = mymap.draw_grid()

Series' of Images

In [34]:
%matplotlib
fig, ax = plt.subplots(figsize=(15,10))
Using matplotlib backend: Qt4Agg
In [35]:
mc = sunpy.map.Map('/home/stuart/sunpy/data/AIA/*fits', cube=True)
In [36]:
anim = mc.plot(axes=ax)
anim.save('sun.ogv', extra_args=['-vcodec', 'theora', '-b:v', '5000k'])

Lightcurve

In [7]:
from sunpy.lightcurve import GOESLightCurve

lc = GOESLightCurve.create('2014/1/1', '2014/1/2')
fig = lc.peek()

Database

Search your local FITS files!

In [15]:
from sunpy.database import Database, attrs
database = Database('sqlite:///sunpydata.sqlite')
In [19]:
database.add_from_dir('/home/stuart/sunpy/AIA')
In [20]:
from sunpy.database.tables import display_entries
cols = ['id', 'observation_time_start', 'observation_time_end', 'instrument', 'wavemin', 'wavemax']
print display_entries(database, cols)
id observation_time_start observation_time_end instrument wavemin wavemax
-- ---------------------- -------------------- ---------- ------- -------
1  2015-03-15 00:00:01    N/A                  AIA_4      9.4     9.4    
2  2015-03-15 00:00:01    N/A                  AIA_4      9.4     9.4    

Searching

In [27]:
res = database.query(attrs.FitsHeaderEntry('CTYPE2', 'HPLT-TAN'))
In [28]:
print display_entries(res, cols)
id observation_time_start observation_time_end instrument wavemin wavemax
-- ---------------------- -------------------- ---------- ------- -------
1  2015-03-15 00:00:01    N/A                  AIA_4      9.4     9.4    
2  2015-03-15 00:00:01    N/A                  AIA_4      9.4     9.4    

Retrieved Data

In [29]:
from sunpy.net import vso


vc = vso.VSOClient()
results = vc.query(vso.attrs.Time('2015/3/1T00:00:25', '2015/3/1T00:00:30'),
                   vso.attrs.Instrument('AIA') | vso.attrs.Instrument('HMI'))
results
Out[29]:
<Table masked=False length=7>
Start Time [1]End Time [1]SourceInstrumentType
string152string152string24string24string64
2015-03-01 00:00:252015-03-01 00:00:26SDOAIAFULLDISK
2015-03-01 00:00:262015-03-01 00:00:27SDOAIAFULLDISK
2015-03-01 00:00:302015-03-01 00:00:31SDOAIAFULLDISK
2015-03-01 00:00:302015-03-01 00:00:31SDOAIAFULLDISK
2015-03-01 00:00:272015-03-01 00:00:28SDOHMIFULLDISK
2015-03-01 00:00:272015-03-01 00:00:28SDOHMIFULLDISK
2015-03-01 00:00:272015-03-01 00:00:28SDOHMIFULLDISK

Spreading the Word

Viable Alternative!

Spreading the Word

Posters / Talks

Bootcamps

Spreading the Word

More code!!

More functionality will encourage more use. More use encourages more functionality!!

The Undiscovered Country

What is next?

  • Lots of Astropy integration

Astropy Units

Around half the code base is now using Astropy Units.

In [30]:
import astropy.units as u
from sunpy.net import vso
vc = vso.VSOClient()

results = vc.query(vso.attrs.Time('2015/3/1T00:00:00', '2015/3/1T00:00:30'),
                   vso.attrs.Instrument('AIA'), vso.attrs.Wave(17.1*u.nm, 171*u.AA))
results
Out[30]:
<Table masked=False length=2>
Start Time [1]End Time [1]SourceInstrumentType
string152string152string24string24string64
2015-03-01 00:00:112015-03-01 00:00:12SDOAIAFULLDISK
2015-03-01 00:00:232015-03-01 00:00:24SDOAIAFULLDISK

Astropy Coordinates

Are awesome!

and we broke them quite a bit ;)

In [31]:
from astropy.coordinates import SkyCoord
import sunpy.coordinates

hpc = SkyCoord(0*u.arcsec, 0*u.arcsec, frame='helioprojective')
hpc
Out[31]:
<SkyCoord (HelioProjective: D0=149597870.7 km, dateobs=None, L0=0.0 deg, B0=0.0 deg, RSun=695508.0 km): (Tx, Ty) in arcsec
    (0.0, 0.0)>
In [32]:
hgs = hpc.transform_to('heliographicstonyhurst')
hgs
Out[32]:
<SkyCoord (HelioGraphicStonyhurst: dateobs=None, RSun=695508.0 km): (lon, lat, rad) in (deg, deg, km)
    (0.0, 0.0, 695508.00000345)>

Fido

Or the Federated Internet Data Retriever.

Because what else do you call it?

It retrieves data from the internet!

In [33]:
import astropy.units as u
import sunpy.net.dataretriever as dr

results = dr.Fido.search(dr.Time('2015/3/1T00:00:00', '2015/3/1T00:00:30'),
                         dr.Instrument('AIA'), dr.Wavelength(17.1*u.nm, 171*u.AA))
results
Out[33]:
<Table masked=False length=2>
Start Time [1]End Time [1]SourceInstrumentType
string152string152string24string24string64
2015-03-01 00:00:112015-03-01 00:00:12SDOAIAFULLDISK
2015-03-01 00:00:232015-03-01 00:00:24SDOAIAFULLDISK

The Undiscovered Country

What is next?

  • Lots of Astropy integration
  • Building links with ground-based instrument teams.
  • Also links with space-based missions.
  • Following the Astropy affiliated package model.

Governance

The SunPy Project has a board.

Who nominate a "Lead Developer" who is responsible for the SunPy Library.

The SunPy Board:

  • Steven Christe (chair)
  • Russell Hewett
  • Andrew Inglis (secretary)
  • Jack Ireland
  • Stuart Mumford
  • Juan Carlos Martínez Oliveros
  • David Perez-Suarez (vice-chair)
  • Thomas Robitaille
  • Albert Shih

Thanks!