SlideShare una empresa de Scribd logo
1 de 59
Descargar para leer sin conexión
Steven Christe1,, Matt Earnshaw2, Keith Hughitt1, Jack Ireland1, Florian Mayer3,
Albert Shih1, Alex Young1
1 NASA GSFC
2 Imperial College   London
3 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 license

On 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 you're Dutch.
   >>> import this
Brief introduction into Python
   Infix notation operations
   Python 2 defaults to floor division
   More mathematical operations in math
   Complex math in cmath
   Integers are arbitrary size.
   Floats are platform doubles.
   decimal module for arbitrary precision
    decimal numbers
   fractions module for fractions
STRINGS / BYTES            UNICODE

 "foo"                     u"foo"
 Store bytes               Store unicode codepoints
 Useful for binary data    Useful for text
                            Behave as expected for
                             multibyte characters
   [1, 2, 3, 4]          (1, u"foo")
   Mutable               Immutable
   Multiple records      Different objects
                           describing one record
   if/elif/else
   for-loop
     break
     continue
     else
   while-loop
   pass
   Default arguments are evaluated once at
    compile time!
   lambda alternative syntax for definition of
    trivial functions
   Functions are objects, too!
   Unordered key-value mappings
   Approx. O(1) lookup and storage
   Keys must be immutable (hashable)
   Unordered collection of unique objects
   Approx. O(1) membership test
   Members must be immutable (hashable)
   Classes
   Explicit self
   Multiple inheritance

   Also in IDL 8; no escaping it
   try / except / else
   raise
   Exceptions inherit from Exception
PYTHON 2.7                       PYTHON 3.2

 Print statement                 Print function
 String / Unicode                Bytes / String
 Floor division                  Float Division
 Relative imports                Absolute imports
 Lists                           Views


                     Tons of other changes
                      http://bit.ly/newpy3
   Fundamental package for science in Python
   Multidimensional fixed-size, homogenous
    arrays
   Derived objects: e.g. matrices
   More efficient
   Less code
   Python list
   arange
   linspace / logspace
   ones / zeros / eye / diag
   random
   Absence of explicit looping
     Conciseness – less bugs
     Closer to mathematical notation
     More pythonic.
   Also possible for user functions
   Expansion of multidimensional arrays
   Implicit element-by-element behavior
   Boolean area
   Integer area
Type       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'
           large enough to fit a
intp                                 'p'
           pointer
int8       8 bits
int16      16 bits
int32      32 bits
int64      64 bits
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'
            large enough to fit a
uintp                                    'P'
            pointer
uint8       8 bits
uint16      16 bits
uint32      32 bits
uint64      64 bits
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?
Type         Remarks               Character code
csingle                            'F'
             compatible: Python
complex_                           'D'
             complex
clongfloat                         'G'
complex64    two 32-bit floats
complex128   two 64-bit floats
             two 96-bit floats,
complex192
             platform?
             two 128-bit floats,
complex256
             platform?
   NumPy: weave.blitz (fast NumPy
    expressions)
   NumPy: weave.inline (inline C/C++)
   f2py (interface Fortran)
   Pyrex/Cython (python-like compiled
    language)
 2D plotting library
 Some 3D support
 Publication-quality
  figures
 “Make easy things easy
  and hard things
  possible”
 Configurable using
  matplotlibrc
import numpy as np
from 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()
import numpy as np
from 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()
import   numpy as np
import   matplotlib.path as mpath
import   matplotlib.patches as mpatches
import   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()
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import (LinearLocator, FixedLocator,
FormatStrFormatter)
import matplotlib.pyplot as plt
import 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()
import numpy as np
from matplotlib import pyplot as plt
from 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()
   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 it
2.       Crop away panel at bottom
         Examine histogram
3. Apply median filter
4. Determine thresholds
5. Display colored image
6. Use mathematical morphology to clean the
   different phases
7. 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.
   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
   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
   Email: florian.mayer@bitsrc.org
   IRC: __name__ in #sunpy on freenode
   XMPP: segfaulthunter@jabber.ccc.de
   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/
   Steven Christe1,
   Matt Earnshaw2
   Keith Hughitt1
   Jack Ireland1             Thanks to
   Florian Mayer3
   Albert Shih1
   Alex Young1
1 NASA GSFC
2 Imperial College London
3 Vienna University of Technology

Más contenido relacionado

La actualidad más candente

La actualidad más candente (18)

Intro to Python Programming Language
Intro to Python Programming LanguageIntro to Python Programming Language
Intro to Python Programming Language
 
Introduction to Python Part-1
Introduction to Python Part-1Introduction to Python Part-1
Introduction to Python Part-1
 
Introduction to Structure Programming with C++
Introduction to Structure Programming with C++Introduction to Structure Programming with C++
Introduction to Structure Programming with C++
 
Introduction To Programming with Python
Introduction To Programming with PythonIntroduction To Programming with Python
Introduction To Programming with Python
 
Python Tutorial Part 1
Python Tutorial Part 1Python Tutorial Part 1
Python Tutorial Part 1
 
Introduction to Python Pandas for Data Analytics
Introduction to Python Pandas for Data AnalyticsIntroduction to Python Pandas for Data Analytics
Introduction to Python Pandas for Data Analytics
 
Python Workshop
Python WorkshopPython Workshop
Python Workshop
 
Python programming language
Python programming languagePython programming language
Python programming language
 
1. python programming
1. python programming1. python programming
1. python programming
 
Python For Scientists
Python For ScientistsPython For Scientists
Python For Scientists
 
What is Python?
What is Python?What is Python?
What is Python?
 
PYTHON NOTES
PYTHON NOTESPYTHON NOTES
PYTHON NOTES
 
Python Tutorial
Python TutorialPython Tutorial
Python Tutorial
 
Python basic
Python basicPython basic
Python basic
 
python.ppt
python.pptpython.ppt
python.ppt
 
Presentation on python
Presentation on pythonPresentation on python
Presentation on python
 
Python ppt
Python pptPython ppt
Python ppt
 
Fundamentals of Python Programming
Fundamentals of Python ProgrammingFundamentals of Python Programming
Fundamentals of Python Programming
 

Destacado

helium-neon laser
helium-neon laserhelium-neon laser
helium-neon laser
Jeevan M C
 
BASICS OF LASER AND IT'S USE IN DERMATOLOGY
BASICS OF LASER AND IT'S USE IN DERMATOLOGYBASICS OF LASER AND IT'S USE IN DERMATOLOGY
BASICS OF LASER AND IT'S USE IN DERMATOLOGY
Rohit Singh
 
Laser ppt by jithin m.p,amrita
Laser ppt by jithin m.p,amritaLaser ppt by jithin m.p,amrita
Laser ppt by jithin m.p,amrita
jithinmp
 
B.Tech sem I Engineering Physics U-II Chapter 2-LASER
B.Tech sem I Engineering Physics U-II Chapter 2-LASERB.Tech sem I Engineering Physics U-II Chapter 2-LASER
B.Tech sem I Engineering Physics U-II Chapter 2-LASER
Abhi Hirpara
 
He ne lasers 1
He ne lasers 1He ne lasers 1
He ne lasers 1
Chuhdry
 
Laser & Its Application
Laser & Its ApplicationLaser & Its Application
Laser & Its Application
Tuhin_Das
 

Destacado (20)

Gas analyzer workshop
Gas analyzer workshopGas analyzer workshop
Gas analyzer workshop
 
Up and Down the Python Data & Web Visualization Stack by Rob Story PyData SV ...
Up and Down the Python Data & Web Visualization Stack by Rob Story PyData SV ...Up and Down the Python Data & Web Visualization Stack by Rob Story PyData SV ...
Up and Down the Python Data & Web Visualization Stack by Rob Story PyData SV ...
 
Python in a physics lab
Python in a physics labPython in a physics lab
Python in a physics lab
 
types of laser by Himanshu Vaid
types of laser by Himanshu Vaidtypes of laser by Himanshu Vaid
types of laser by Himanshu Vaid
 
Scientific Plotting in Python
Scientific Plotting in PythonScientific Plotting in Python
Scientific Plotting in Python
 
ruby laser
ruby laser ruby laser
ruby laser
 
helium-neon laser
helium-neon laserhelium-neon laser
helium-neon laser
 
BASICS OF LASER AND IT'S USE IN DERMATOLOGY
BASICS OF LASER AND IT'S USE IN DERMATOLOGYBASICS OF LASER AND IT'S USE IN DERMATOLOGY
BASICS OF LASER AND IT'S USE IN DERMATOLOGY
 
Laser and its medical applications
Laser and its medical applicationsLaser and its medical applications
Laser and its medical applications
 
LASER Ignition System
LASER Ignition SystemLASER Ignition System
LASER Ignition System
 
Types of laser
Types of laserTypes of laser
Types of laser
 
Laser ppt by jithin m.p,amrita
Laser ppt by jithin m.p,amritaLaser ppt by jithin m.p,amrita
Laser ppt by jithin m.p,amrita
 
TDLTech Presentation 14
TDLTech Presentation 14TDLTech Presentation 14
TDLTech Presentation 14
 
Introduction to Lasers
Introduction to LasersIntroduction to Lasers
Introduction to Lasers
 
Laser Communications
Laser CommunicationsLaser Communications
Laser Communications
 
Laser Communication
Laser CommunicationLaser Communication
Laser Communication
 
Laser
LaserLaser
Laser
 
B.Tech sem I Engineering Physics U-II Chapter 2-LASER
B.Tech sem I Engineering Physics U-II Chapter 2-LASERB.Tech sem I Engineering Physics U-II Chapter 2-LASER
B.Tech sem I Engineering Physics U-II Chapter 2-LASER
 
He ne lasers 1
He ne lasers 1He ne lasers 1
He ne lasers 1
 
Laser & Its Application
Laser & Its ApplicationLaser & Its Application
Laser & Its Application
 

Similar a SunPy: Python for solar physics

Introduction to phyton , important topic
Introduction to phyton , important topicIntroduction to phyton , important topic
Introduction to phyton , important topic
akpgenious67
 
PPT on Python - illustrating Python for BBA, B.Tech
PPT on Python - illustrating Python for BBA, B.TechPPT on Python - illustrating Python for BBA, B.Tech
PPT on Python - illustrating Python for BBA, B.Tech
ssuser2678ab
 
unit (1)INTRODUCTION TO PYTHON course.pptx
unit (1)INTRODUCTION TO PYTHON course.pptxunit (1)INTRODUCTION TO PYTHON course.pptx
unit (1)INTRODUCTION TO PYTHON course.pptx
usvirat1805
 

Similar a SunPy: Python for solar physics (20)

Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python Programming
 
Introduction to phyton , important topic
Introduction to phyton , important topicIntroduction to phyton , important topic
Introduction to phyton , important topic
 
C language
C languageC language
C language
 
PPT on Python - illustrating Python for BBA, B.Tech
PPT on Python - illustrating Python for BBA, B.TechPPT on Python - illustrating Python for BBA, B.Tech
PPT on Python - illustrating Python for BBA, B.Tech
 
Lecture1_cis4930.pdf
Lecture1_cis4930.pdfLecture1_cis4930.pdf
Lecture1_cis4930.pdf
 
Python (3).pdf
Python (3).pdfPython (3).pdf
Python (3).pdf
 
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf
python-online&offline-training-in-kphb-hyderabad (1) (1).pdfpython-online&offline-training-in-kphb-hyderabad (1) (1).pdf
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf
 
C language introduction
C language introduction C language introduction
C language introduction
 
Introduction to Python Programming | InsideAIML
Introduction to Python Programming | InsideAIMLIntroduction to Python Programming | InsideAIML
Introduction to Python Programming | InsideAIML
 
Clanguage
ClanguageClanguage
Clanguage
 
Python internals and how they affect your code - kasra ahmadvand
Python internals and how they affect your code - kasra ahmadvandPython internals and how they affect your code - kasra ahmadvand
Python internals and how they affect your code - kasra ahmadvand
 
unit (1)INTRODUCTION TO PYTHON course.pptx
unit (1)INTRODUCTION TO PYTHON course.pptxunit (1)INTRODUCTION TO PYTHON course.pptx
unit (1)INTRODUCTION TO PYTHON course.pptx
 
Introduction to Python Programming .pptx
Introduction to Python Programming .pptxIntroduction to Python Programming .pptx
Introduction to Python Programming .pptx
 
python ppt | Python Course In Ghaziabad | Scode Network Institute
python ppt | Python Course In Ghaziabad | Scode Network Institutepython ppt | Python Course In Ghaziabad | Scode Network Institute
python ppt | Python Course In Ghaziabad | Scode Network Institute
 
Python unit1
Python unit1Python unit1
Python unit1
 
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
 
Python
PythonPython
Python
 
Python-01| Fundamentals
Python-01| FundamentalsPython-01| Fundamentals
Python-01| Fundamentals
 
Phyton Learning extracts
Phyton Learning extracts Phyton Learning extracts
Phyton Learning extracts
 
Learning python
Learning pythonLearning python
Learning python
 

Último

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
MateoGardella
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
SanaAli374401
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 

Último (20)

ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 

SunPy: Python for solar physics

  • 1. Steven Christe1,, Matt Earnshaw2, Keith Hughitt1, Jack Ireland1, Florian Mayer3, Albert Shih1, Alex Young1 1 NASA GSFC 2 Imperial College London 3 Vienna University of Technology Florian Mayer
  • 2. What is Python?  Introduction to Python  Scientific Python  NumPy  Matplotlib  SciPy  Python in solar physics
  • 3. General-purpose  Object-oriented (disputed)  Cross-platform  Windows  Mac OS  Linux  Other Unices (FreeBSD, Solaris, etc.)  High-level
  • 4. Internet companies  Google  Rackspace  Games  Battlefield 2  Civilization 4  Graphics  Walt Disney  Science  NASA  ESRI
  • 5. Easy  Comprehensive standard library (“batteries included”) Quality does vary, though.  Good support for scientific tasks  Permissive open-source license On the downside:  Slower, but ways to speed up
  • 6. 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
  • 7. Implementation started 1989 by Guido van Rossum (BDFL)  2.0 appeared 2000  Garbage collection  Unicode  3.0 appeared 2008
  • 8. 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
  • 9. 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
  • 10. 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
  • 12. Infix notation operations  Python 2 defaults to floor division  More mathematical operations in math  Complex math in cmath
  • 13. Integers are arbitrary size.  Floats are platform doubles.  decimal module for arbitrary precision decimal numbers  fractions module for fractions
  • 14. STRINGS / BYTES UNICODE  "foo"  u"foo"  Store bytes  Store unicode codepoints  Useful for binary data  Useful for text  Behave as expected for multibyte characters
  • 15. [1, 2, 3, 4]  (1, u"foo")  Mutable  Immutable  Multiple records  Different objects describing one record
  • 16. if/elif/else  for-loop  break  continue  else  while-loop  pass
  • 17. Default arguments are evaluated once at compile time!  lambda alternative syntax for definition of trivial functions  Functions are objects, too!
  • 18. Unordered key-value mappings  Approx. O(1) lookup and storage  Keys must be immutable (hashable)
  • 19. Unordered collection of unique objects  Approx. O(1) membership test  Members must be immutable (hashable)
  • 20. Classes  Explicit self  Multiple inheritance  Also in IDL 8; no escaping it
  • 21. try / except / else  raise  Exceptions inherit from Exception
  • 22. PYTHON 2.7 PYTHON 3.2  Print statement  Print function  String / Unicode  Bytes / String  Floor division  Float Division  Relative imports  Absolute imports  Lists  Views Tons of other changes http://bit.ly/newpy3
  • 23. Fundamental package for science in Python  Multidimensional fixed-size, homogenous arrays  Derived objects: e.g. matrices  More efficient  Less code
  • 24. Python list  arange  linspace / logspace  ones / zeros / eye / diag  random
  • 25. Absence of explicit looping  Conciseness – less bugs  Closer to mathematical notation  More pythonic.  Also possible for user functions
  • 26. Expansion of multidimensional arrays  Implicit element-by-element behavior
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33. Boolean area  Integer area
  • 34. Type 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' large enough to fit a intp 'p' pointer int8 8 bits int16 16 bits int32 32 bits int64 64 bits
  • 35. 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' large enough to fit a uintp 'P' pointer uint8 8 bits uint16 16 bits uint32 32 bits uint64 64 bits
  • 36. 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?
  • 37. Type Remarks Character code csingle 'F' compatible: Python complex_ 'D' complex clongfloat 'G' complex64 two 32-bit floats complex128 two 64-bit floats two 96-bit floats, complex192 platform? two 128-bit floats, complex256 platform?
  • 38. NumPy: weave.blitz (fast NumPy expressions)  NumPy: weave.inline (inline C/C++)  f2py (interface Fortran)  Pyrex/Cython (python-like compiled language)
  • 39.  2D plotting library  Some 3D support  Publication-quality figures  “Make easy things easy and hard things possible”  Configurable using matplotlibrc
  • 40. import numpy as np from 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()
  • 41. import numpy as np from 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()
  • 42. import numpy as np import matplotlib.path as mpath import matplotlib.patches as mpatches import 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()
  • 43. from mpl_toolkits.mplot3d import Axes3D from matplotlib import cm from matplotlib.ticker import (LinearLocator, FixedLocator, FormatStrFormatter) import matplotlib.pyplot as plt import 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()
  • 44. import numpy as np from matplotlib import pyplot as plt from 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()
  • 45.
  • 46.
  • 47. Statistics  Optimization  Numerical integration  Linear algebra  Fourier transforms  Signal processing  Image processing  ODE solvers  Special functions  And more.
  • 48. 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
  • 49. 1. Open image and examine it 2. Crop away panel at bottom  Examine histogram 3. Apply median filter 4. Determine thresholds 5. Display colored image 6. Use mathematical morphology to clean the different phases 7. 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.
  • 50. Spatially aware maps  Read FITS files  RHESSI  SDO/AIA  EIT  TRACE  LASCO  standard color tables and hist equalization  basic image coalignment  VSO  HEK
  • 51. Spatially aware array  NumPy array  Based on SolarSoft Map.  MapCube
  • 52. Two APIs  Legacy API (tries to mimic IDL vso_search)  New API based on boolean operations
  • 53. Create VSO queries from HER responses  WIP: Plot HER events over images
  • 54.
  • 55. Use it!  File feature requests  Express opinion on the mailing list / in IRC  File bug reports  Contribute documentation  Contribute code
  • 56. 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
  • 57. Email: florian.mayer@bitsrc.org  IRC: __name__ in #sunpy on freenode  XMPP: segfaulthunter@jabber.ccc.de
  • 58. 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/
  • 59. Steven Christe1,  Matt Earnshaw2  Keith Hughitt1  Jack Ireland1 Thanks to  Florian Mayer3  Albert Shih1  Alex Young1 1 NASA GSFC 2 Imperial College London 3 Vienna University of Technology