Steven Christe1,, Matt Earnshaw2, Keith Hughitt1, Jack Ireland1, Florian Mayer3,Albert Shih1, Alex Young11 NASA GSFC2 Imperial College London3 Vienna University of Technology Florian Mayer
What is Python? Introduction to Python Scientific Python NumPy Matplotlib SciPy Python in solar physics
General-purpose Object-oriented (disputed) Cross-platform Windows Mac OS Linux Other Unices (FreeBSD, Solaris, etc.) High-level
Internet companies Google Rackspace Games Battlefield 2 Civilization 4 Graphics Walt Disney Science NASA ESRI
Easy Comprehensive standard library (“batteries included”) Quality does vary, though. Good support for scientific tasks Permissive open-source licenseOn the downside: Slower, but ways to speed up
PYTHON IDL Free open-source software Proprietary software Without cost License cost General purpose Small community Good plotting Cumbersome plotting No solar software Solar software
Implementation started 1989 by Guido van Rossum (BDFL) 2.0 appeared 2000 Garbage collection Unicode 3.0 appeared 2008
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
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
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 youre Dutch. >>> import this
Type Remarks Character codebyte compatible: C char bshort compatible: C short hintc compatible: C int iint_ compatible: Python int llonglong compatible: C long long q large enough to fit aintp p pointerint8 8 bitsint16 16 bitsint32 32 bitsint64 64 bits
Type Remarks Character codeubyte compatible: C u. char Bushort compatible: C u. short Huintc compatible: C unsigned int Iuint compatible: Python int Lulonglong compatible: C long long Q large enough to fit auintp P pointeruint8 8 bitsuint16 16 bitsuint32 32 bitsuint64 64 bits
Type Remarks Character codehalf esingle compatible: C float fdouble compatible: C doublefloat_ compatible: Python float dlongfloat compatible: C long float gfloat16 16 bitsfloat32 32 bitsfloat64 64 bitsfloat96 96 bits, platform?float128 128 bits, platform?
Type Remarks Character codecsingle F compatible: Pythoncomplex_ D complexclongfloat Gcomplex64 two 32-bit floatscomplex128 two 64-bit floats two 96-bit floats,complex192 platform? two 128-bit floats,complex256 platform?
import numpy as npfrom matplotlib import pyplot as pltfrom matplotlib.patches import EllipseNUM = 250ells = [ 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()
Statistics Optimization Numerical integration Linear algebra Fourier transforms Signal processing Image processing ODE solvers Special functions And more.
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
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 pixels8. Compute the mean size of bubbles.
Spatially aware maps Read FITS files RHESSI SDO/AIA EIT TRACE LASCO standard color tables and hist equalization basic image coalignment VSO HEK
Spatially aware array NumPy array Based on SolarSoft Map. MapCube
Two APIs Legacy API (tries to mimic IDL vso_search) New API based on boolean operations
Create VSO queries from HER responses WIP: Plot HER events over images
Use it! File feature requests Express opinion on the mailing list / in IRC File bug reports Contribute documentation Contribute code