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.

Slides:



Advertisements
Similar presentations
Guy Griffiths. General purpose interpreted programming language Widely used by scientists and programmers of all stripes Supported by many 3 rd -party.
Advertisements

Python: Your new best friend print “Adam Avison”.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Reasons to study concepts of PL
Python Jordan Miller and Lauren Winkleman CS 311 Fall 2011.
Jonathan Huelman CSC 415 – Programming Languages
Python plotting for lab folk Only the stuff you need to know to make publishable figures of your data. For all else: ask Sourish.
Introduction to Python (for C++ programmers). Background Information History – created in December 1989 by Guido van Rossum Interpreted Dynamically-typed.
Computational Tools for Image Processing Lecture 1, Jan 22nd, 2007 Part 2 (8:10-9:20pm) by Lexing Xie EE4830 Digital Image Processing
01- Intro-Java-part1 1 Introduction to Java, and DrJava Barb Ericson Georgia Institute of Technology June 2008.
Invitation to Computer Science 5th Edition
Interpreting the data: Parallel analysis with Sawzall LIN Wenbin 25 Mar 2014.
Introduction to MATLAB adapted from Dr. Rolf Lakaemper.
CIS Computer Programming Logic
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Introduction to Python By Neil Cook Twitter: njcuk Slides/Notes:
Computer Science 111 Fundamentals of Programming I Overview of Programming.
Python 0 Some material adapted from Upenn cmpe391 slides and other sources.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
418512: Computer Programming Languages Lecture 7 Pramook Khungurn TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: A AAAA.
Scientific Computing Beyond Matlab Nov 19, 2012 Jason Su.
Scientific Computing with NumPy & SciPy NumPy Installation and Documentation  Not much on the home page—don’t buy the guide, it’s.
Input, Output, and Processing
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Ch 1. A Python Q&A Session Spring Why do people use Python? Software quality Developer productivity Program portability Support libraries Component.
Basics of Java IMPORTANT: Read Chap 1-6 of How to think like a… Lecture 3.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
Data Structure & File Systems Hun Myoung Park, Ph.D., Public Management and Policy Analysis Program Graduate School of International Relations International.
Guide to Programming with Python Chapter One Getting Started: The Game Over Program.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
C463 / B551 Artificial Intelligence Dana Vrajitoru Python.
ISBN Chapter 6 Data Types Introduction Primitive Data Types User-Defined Ordinal Types.
An Introduction. What is Python? Interpreted language Created by Guido Van Rossum – early 90s Named after Monty Python
Python Primer 1: Types and Operators © 2013 Goodrich, Tamassia, Goldwasser1Python Primer.
CS 127 Introduction to Computer Science. What is a computer?  “A machine that stores and manipulates information under the control of a changeable program”
Scientific Python Numpy Linear Algebra Matrices Scipy Signal Processing Optimization IPython Interactive Console Matplotlib Plotting Sympy Symbolic Math.
Python for: Data Science. Python  Python is an open source scripting language.  Developed by Guido Van Rossum in late 1980s  Named after Monty Python.
By Austin Laudenslager AN INTRODUCTION TO PYTHON.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
8 January 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems
CIS 601 Fall 2003 Introduction to MATLAB Longin Jan Latecki Based on the lectures of Rolf Lakaemper and David Young.
Python & NetworkX Youn-Hee Han
1. COMPUTERS AND PROGRAMS Rocky K. C. Chang September 6, 2015 (Adapted from John Zelle’s slides)
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
CIS 595 MATLAB First Impressions. MATLAB This introduction will give Some basic ideas Main advantages and drawbacks compared to other languages.
Python Programming Language by Vasu Chetty. Origins of Python Created by: Guido van Rossum, a Dutch Programmer Created during: Christmas Break, 1989 Created.
Introduction to Programming AP Computer Science. Computers What is a computer? –CPU –ALU –Memory –Hard Drive.
Functional Programming
Introduction to Programming
Fundamentals of Programming I Overview of Programming
PH2150 Scientific Computing Skills
CSC391/691 Intro to OpenCV Dr. Rongzhong Li Fall 2016
MatLab Programming By Kishan Kathiriya.
Internet and Java Foundations, Programming and Practice
IPYTHON AND MATPLOTLIB Python for computational science
Introduction to Programming
PH2150 Scientific Computing Skills
.NET and .NET Core 5.2 Type Operations Pan Wuming 2016.
Introduction to MATLAB
What Is a Program? A program is like an algorithm, but describes a process that is ready or can be made ready to run on a real computer Retrieved from:
Introduction to Python
Matplotlib.
PYTHON Graphs Prof. Muhammad Saeed.
Simulation And Modeling
Python Basics. Topics Features How does Python work Basic Features I/O in Python Operators Control Statements Function/Scope of variables OOP Concepts.
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

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 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

PYTHONIDL  Proprietary software  License cost  Small community  Cumbersome plotting  Solar software  Free open-source software  Without cost  General purpose  Good plotting  No 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  "foo"  Store bytes  Useful for binary data UNICODE  u"foo"  Store unicode codepoints  Useful for text  Behave as expected for multibyte characters

 [1, 2, 3, 4]  Mutable  Multiple records  (1, u"foo")  Immutable  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  Print statement  String / Unicode  Floor division  Relative imports  Lists PYTHON 3.2  Print function  Bytes / String  Float Division  Absolute imports  Views Tons of other changes

 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

TypeRemarksCharacter code bytecompatible: C char'b' shortcompatible: C short'h' intccompatible: C int'i' int_compatible: Python int'l' longlongcompatible: C long long'q' intp large enough to fit a pointer 'p' int88 bits int1616 bits int3232 bits int6464 bits

TypeRemarksCharacter code ubytecompatible: C u. char'B' ushortcompatible: C u. short'H' uintccompatible: C unsigned int'I' uintcompatible: Python int'L' ulonglongcompatible: C long long'Q' uintp large enough to fit a pointer 'P' uint88 bits uint1616 bits uint3232 bits uint6464 bits

TypeRemarksCharacter code half 'e' singlecompatible: C float'f' doublecompatible: C double float_compatible: Python float'd' longfloatcompatible: C long float'g' float1616 bits float3232 bits float6464 bits float9696 bits, platform? float bits, platform?

TypeRemarksCharacter code csingle 'F' complex_ compatible: Python complex 'D' clongfloat 'G' complex64two 32-bit floats complex128two 64-bit floats complex192 two 96-bit floats, platform? complex256 two 128-bit floats, 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:  Mailing list:  IRC: #sunpy on irc.freenode.net  Git code repository:

  IRC: __name__ in #sunpy on freenode  XMPP:

 SciPy:  Astronomical modules:  Science modules:  NumPy/IDL:  Python for interactive data analysis:  SciPy lecture notes:  This talk:  SunPy doc:

 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 3 Vienna University of Technology Thanks to