steven christe 1,, matt earnshaw 2, keith hughitt 1, jack ireland 1, florian mayer 3, albert shih 1,...
TRANSCRIPT
![Page 1: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/1.jpg)
SunPy: Python for solar physics
Steven Christe1,, Matt Earnshaw2, Keith Hughitt1, Jack Ireland1, Florian Mayer3, Albert Shih1, Alex Young1
1 NASA GSFC2 Imperial College London3 Vienna University of Technology
Florian Mayer
![Page 2: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/2.jpg)
Outline
What is Python? Introduction to Python Scientific Python
NumPy Matplotlib SciPy
Python in solar physics
![Page 3: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/3.jpg)
What is Python?
General-purpose Object-oriented (disputed) Cross-platform
Windows Mac OS Linux Other Unices (FreeBSD, Solaris, etc.)
High-level
![Page 4: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/4.jpg)
Who uses Python?
Internet companies Google Rackspace
Games Battlefield 2 Civilization 4
Graphics Walt Disney
Science NASA ESRI
![Page 5: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/5.jpg)
Why Python?
Easy Comprehensive standard library
(“batteries included”)Quality does vary, though.
Good support for scientific tasksPermissive open-source license
On the downside: Slower, but ways to speed up
![Page 6: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/6.jpg)
Python / IDL
PYTHON IDL
Proprietary software License cost Small community Cumbersome plotting Solar software
Free open-source software
Without cost General purpose Good plotting No solar software
![Page 7: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/7.jpg)
History of Python
Implementation started 1989 by Guido van Rossum (BDFL)
2.0 appeared 2000 Garbage collection Unicode
3.0 appeared 2008
![Page 8: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/8.jpg)
Python in science
Astronomy Artificial intelligence & machine learning Bayesian Statistics Biology (including Neuroscience) Dynamical systems Economics and Econometrics Electromagnetics Electrical Engineering Geosciences Molecular modeling Signal processing Symbolic math, number theory
![Page 9: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/9.jpg)
Python in astronomy
pyFITS – read FITS files pyRAF – run IRAF tasks pywcs pyephem – compute positions of
objects in space spacepy (space sciences, just
released) Planned standard library AstroPy
![Page 10: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/10.jpg)
Zen of Python by Tim Peters
Beautiful is better than ugly.Explicit is better than implicit.Simple is better than complex.Readability counts.There should be one – and
preferably only one – obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
>>> import this
![Page 11: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/11.jpg)
Python tutorialBrief introduction into Python
![Page 12: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/12.jpg)
Python as a calculator
Infix notation operations Python 2 defaults to floor division More mathematical operations in
math Complex math in cmath
![Page 13: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/13.jpg)
Integers and Floats
Integers are arbitrary size. Floats are platform doubles. decimal module for arbitrary
precision decimal numbers fractions module for fractions
![Page 14: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/14.jpg)
Strings and Unicode
STRINGS / BYTES
"foo" Store bytes Useful for binary data
UNICODE
u"foo" Store unicode
codepoints Useful for text Behave as expected
for multibyte characters
![Page 15: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/15.jpg)
Lists and Tuples
[1, 2, 3, 4] Mutable Multiple records
(1, u"foo") Immutable Different objects
describing one record
![Page 16: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/16.jpg)
Control flow
if/elif/else for-loop
break continue else
while-loop pass
![Page 17: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/17.jpg)
Functions
Default arguments are evaluated once at compile time!
lambda alternative syntax for definition of trivial functions
Functions are objects, too!
![Page 18: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/18.jpg)
Dictionaries
Unordered key-value mappings Approx. O(1) lookup and storage Keys must be immutable (hashable)
![Page 19: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/19.jpg)
Sets
Unordered collection of unique objects
Approx. O(1) membership test Members must be immutable
(hashable)
![Page 20: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/20.jpg)
Object-orientation
Classes Explicit self Multiple inheritance
Also in IDL 8; no escaping it
![Page 21: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/21.jpg)
Exception handling
try / except / else raise Exceptions inherit from Exception
![Page 22: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/22.jpg)
Current versions
PYTHON 2.7
Print statement String / Unicode Floor division Relative imports Lists
PYTHON 3.2
Print function Bytes / String Float Division Absolute imports Views
Tons of other changeshttp://bit.ly/newpy3
![Page 23: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/23.jpg)
NumPy
Fundamental package for science in Python
Multidimensional fixed-size, homogenous arrays
Derived objects: e.g. matrices More efficient Less code
![Page 24: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/24.jpg)
NumPy: Create arrays
Python list arange linspace / logspace ones / zeros / eye / diag random
![Page 25: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/25.jpg)
NumPy: Vectorization
Absence of explicit looping Conciseness – less bugs Closer to mathematical notation More pythonic.
Also possible for user functions
![Page 26: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/26.jpg)
NumPy: Broadcasting
Expansion of multidimensional arrays
Implicit element-by-element behavior
![Page 27: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/27.jpg)
NumPy: Broadcasting illustrated
![Page 28: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/28.jpg)
NumPy: Indexing
![Page 29: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/29.jpg)
arr[0,3:5]
![Page 30: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/30.jpg)
arr[4:,4:]
![Page 31: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/31.jpg)
arr[:,2]
![Page 32: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/32.jpg)
arr[2::2,::2]
![Page 33: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/33.jpg)
Other Options
Boolean area Integer area
![Page 34: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/34.jpg)
NumPy Data-types: IntegersType Remarks Character code
byte compatible: C char 'b'
short compatible: C short 'h'
intc compatible: C int 'i'
int_ compatible: Python int 'l'
longlong compatible: C long long 'q'
intp large enough to fit a pointer 'p'
int8 8 bits
int16 16 bits
int32 32 bits
int64 64 bits
![Page 35: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/35.jpg)
NumPy Data-types: Unsigned
Type Remarks Character code
ubyte compatible: C u. char 'B'
ushort compatible: C u. short 'H'
uintc compatible: C unsigned int 'I'
uint compatible: Python int 'L'
ulonglong compatible: C long long 'Q'
uintp large enough to fit a pointer 'P'
uint8 8 bits
uint16 16 bits
uint32 32 bits
uint64 64 bits
![Page 36: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/36.jpg)
NumPy Data-types: Floating point
Type Remarks Character code
half 'e'
single compatible: C float 'f'
double compatible: C double
float_ compatible: Python float 'd'
longfloat compatible: C long float 'g'
float16 16 bits
float32 32 bits
float64 64 bits
float96 96 bits, platform?
float128 128 bits, platform?
![Page 37: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/37.jpg)
NumPy Data-types: Complex
Type Remarks Character code
csingle 'F'
complex_ compatible: Python complex 'D'
clongfloat 'G'
complex64 two 32-bit floats
complex128 two 64-bit floats
complex192 two 96-bit floats, platform?
complex256 two 128-bit floats, platform?
![Page 38: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/38.jpg)
Optimize Python
NumPy: weave.blitz (fast NumPy expressions)
NumPy: weave.inline (inline C/C++) f2py (interface Fortran) Pyrex/Cython (python-like compiled
language)
![Page 39: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/39.jpg)
Matplotlib
2D plotting library Some 3D support Publication-quality
figures “Make easy things
easy and hard things possible”
Configurable using matplotlibrc
![Page 40: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/40.jpg)
Matplotlib: Simple Plot
import numpy as npfrom matplotlib import pyplot as plt
t = np.linspace(0, 2, 200)s = np.sin(2*pi*t)plt.plot(t, s, linewidth=1.0)
plt.xlabel('time (s)')plt.ylabel('voltage (mV)')plt.title('About as simple as it gets, folks')plt.grid(True)plt.show()
![Page 41: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/41.jpg)
Matplotlib: Subplots
import numpy as npfrom matplotlib import pyplot as plt
def f(t): s1 = np.cos(2*pi*t) e1 = np.exp(-t) return np.multiply(s1,e1)
t1 = np.arange(0.0, 5.0, 0.1)t2 = np.arange(0.0, 5.0, 0.02)t3 = np.arange(0.0, 2.0, 0.01)
plt.subplot(211)l = plot(t1, f(t1), 'bo', t2, f(t2), 'k--', markerfacecolor='green')plt.grid(True)plt.title('A tale of 2 subplots')plt.ylabel('Damped oscillation')
plt.subplot(212)plt.plot(t3, np.cos(2*pi*t3), 'r.')plt.grid(True)plt.xlabel('time (s)')plt.ylabel('Undamped')plt.show()
![Page 42: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/42.jpg)
Matplotlib: Paths
import numpy as npimport matplotlib.path as mpathimport matplotlib.patches as mpatchesimport matplotlib.pyplot as plt
Path = mpath.Path
fig = plt.figure()ax = fig.add_subplot(111)
pathdata = [ (Path.MOVETO, (1.58, -2.57)), (Path.CURVE4, (0.35, -1.1)), (Path.CURVE4, (-1.75, 2.0)), (Path.CURVE4, (0.375, 2.0)), (Path.LINETO, (0.85, 1.15)), (Path.CURVE4, (2.2, 3.2)), (Path.CURVE4, (3, 0.05)), (Path.CURVE4, (2.0, -0.5)), (Path.CLOSEPOLY, (1.58, -2.57)), ]
codes, verts = zip(*pathdata)path = mpath.Path(verts, codes)patch = mpatches.PathPatch(path, facecolor='red', edgecolor='yellow', alpha=0.5)ax.add_patch(patch)
x, y = zip(*path.vertices)line, = ax.plot(x, y, 'go-')ax.grid()ax.set_xlim(-3,4)ax.set_ylim(-3,4)ax.set_title('spline paths')plt.show()
![Page 43: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/43.jpg)
Matplotlib: mplot3d
from mpl_toolkits.mplot3d import Axes3Dfrom matplotlib import cmfrom matplotlib.ticker import (LinearLocator, FixedLocator, FormatStrFormatter)import matplotlib.pyplot as pltimport numpy as np fig = plt.figure()ax = fig.gca(projection='3d')X = np.arange(-5, 5, 0.25)Y = np.arange(-5, 5, 0.25)X, Y = np.meshgrid(X, Y)R = np.sqrt(X**2 + Y**2)Z = np.sin(R)surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.jet, linewidth=0, antialiased=False)ax.set_zlim3d(-1.01, 1.01) ax.w_zaxis.set_major_locator(LinearLocator(10))ax.w_zaxis.set_major_formatter(FormatStrFormatter('%.03f')) fig.colorbar(surf, shrink=0.5, aspect=5) plt.show()
![Page 44: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/44.jpg)
Matplotlib: Ellipses
import numpy as npfrom matplotlib import pyplot as pltfrom matplotlib.patches import Ellipse
NUM = 250
ells = [ Ellipse(xy=rand(2)*10, width=np.rand(), height=np.rand(), angle=np.rand()*360) for i in xrange(NUM)]
fig = plt.figure()ax = fig.add_subplot(111, aspect='equal')for e in ells: ax.add_artist(e) e.set_clip_box(ax.bbox) e.set_alpha(rand()) e.set_facecolor(rand(3))
ax.set_xlim(0, 10)ax.set_ylim(0, 10)
plt.show()
![Page 45: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/45.jpg)
Matplotlib Example: EEG viewer
![Page 46: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/46.jpg)
Matplotlib: Gallery
![Page 47: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/47.jpg)
SciPy
Statistics Optimization Numerical integration Linear algebra Fourier transforms Signal processing Image processing ODE solvers Special functions And more.
![Page 48: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/48.jpg)
SciPy Example: Problem
Three phases Glass sample – light
grey Bubbles – black Sand grains – dark
grey
Determine Fraction of the
sample covered by these
Typical size of sand grains or bubbles
![Page 49: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/49.jpg)
SciPy Example: Solution
1. Open image and examine it2. Crop away panel at bottom
Examine histogram3. Apply median filter4. Determine thresholds5. Display colored image6. Use mathematical morphology to clean the
different phases7. Attribute labels to all bubbles and sand grains
Remove from the sand mask grains that are smaller than 10 pixels
8. Compute the mean size of bubbles.
![Page 50: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/50.jpg)
SunPy
Spatially aware maps Read FITS files
RHESSI SDO/AIA EIT TRACE LASCO
standard color tables and hist equalization basic image coalignment VSO HEK
![Page 51: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/51.jpg)
SunPy: Maps
Spatially aware array NumPy array Based on SolarSoft Map.
MapCube
![Page 52: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/52.jpg)
SunPy: VSO
Two APIs Legacy API (tries to mimic IDL
vso_search) New API based on boolean operations
![Page 53: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/53.jpg)
SunPy: HEK HER
Create VSO queries from HER responses
WIP: Plot HER events over images
![Page 54: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/54.jpg)
SunPy: Plotman
![Page 55: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/55.jpg)
SunPy: Get involved!
Use it! File feature requests Express opinion on the mailing list /
in IRC File bug reports Contribute documentation Contribute code
![Page 56: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/56.jpg)
SunPy: Reaching us
Website: http://sunpy.org Mailing list: http://bit.ly/sunpy-forum IRC: #sunpy on irc.freenode.net Git code repository: https://
github.com/sunpy/sunpy
![Page 58: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/58.jpg)
Resources
SciPy: http://scipy.org Astronomical modules: http://
bit.ly/astropy Science modules: http://
bit.ly/sciencepy NumPy/IDL: http://hvrd.me/numpy-idl Python for interactive data analysis:
http://bit.ly/pydatatut SciPy lecture notes: http://
bit.ly/scipylec This talk: http://graz-talk.bitsrc.org SunPy doc: http://sunpy.org/doc/
![Page 59: Steven Christe 1,, Matt Earnshaw 2, Keith Hughitt 1, Jack Ireland 1, Florian Mayer 3, Albert Shih 1, Alex Young 1 1 NASA GSFC 2 Imperial College London](https://reader036.vdocuments.net/reader036/viewer/2022062301/56649e1c5503460f94b0a245/html5/thumbnails/59.jpg)
Thanks
Steven Christe1,
Matt Earnshaw2
Keith Hughitt1
Jack Ireland1
Florian Mayer3
Albert Shih1
Alex Young1
1 NASA GSFC2 Imperial College London3 Vienna University of Technology
Thanks to