Welcome to the UNF-Physics Python Boot Camp 2016

Objectives

  • Introduce you to the Python language
  • Get you writing Python code. Build Python hacking muscle memory
  • Convince you of its utility in your research and academic life
  • Instill good coding and curation practices
  • We try not to proselytize, but sometimes it’s too hard to resist
  • This talk is a sacrificial talk designed to make sure you are ready to go.

Organization

Introduction

  • What is Python?
  • Why Python?
  • Getting Started...

What is Python?

Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Its high-level built in data structures, combined with dynamic typing and dynamic binding, make it very attractive for Rapid Application Development, as well as for use as a scripting or glue language to connect existing components together. Python's simple, easy to learn syntax emphasizes readability and therefore reduces the cost of program maintenance. Python supports modules and packages, which encourages program modularity and code reuse. The Python interpreter and the extensive standard library are available in source or binary form without charge for all major platforms, and can be freely distributed.

https://www.python.org/doc/essays/blurb/

What is Python?

interpreted no need for a compiling stage
object-oriented programming paradigm that uses objects (complex data structures with methods)
high level abstraction from the way machine interprets & executes
dynamic semantics can change meaning on-the-fly
built in core language (not external)
data structures ways of storing/manipulating data
script/glue programs that control other programs
typing the sort of variable (int, string)
syntax grammar which defines the language
library reusable collection of code
binary a file that you can run/execute

Development History

  • started over the Christmas break 1989, by Guido van Rossum (now at Dropbox)
  • developed in the early 1990s
  • name comes from Monty Python’s Flying Circus
  • Guido is the Benevolent Dictator for Life (BDFL), meaning that he continues to oversee Python’s development.

Why Python?

  • Free (BSD license), highly portable (Linux, OSX, Windows, lots...)
  • Interactive interpreter provided.
  • Extremely readable syntax (“executable pseudo-code”).
  • Simple: non-professional programmers can use it effectively
    • great documentation
    • total abstraction of memory management
  • Clean object-oriented model, but not mandatory.
  • Rich built-in types: lists, sets, dictionaries (hash tables), strings, ...
  • Very comprehensive standard library (batteries included)
  • Standard libraries for IDL/Matlab-like arrays (NumPy)
  • Easy to wrap existing C, C++ and FORTRAN codes.

Amazingly Scalable

  • Interactive experimentation
  • build small, self-contained scripts or million-lines projects.
  • From occasional/novice to full-time use (try that with C++).

The Kitchen Sink (in a good way)

  • really can do anything you want, with impressive simplicity

Performance, if you need it

  • As an interpreted language, Python is slow.
  • But...if you need speed you can do the heavy lifting in C or FORTRAN
    ...or you can use a Python compiler (e.g., Cython)

What I Use Python For

(I was forced into using python...)

  • Interface to the low-level (c++) code - Interactive data analysis
  • Scripting
  • Developing new analysis techniques
  • Adding features to static code quickly
  • Providing high-level analysis tools (light-curve generation, SED generation, statistical testing, simulation development and so on and so forth)
  • Science Validation and Testing

  • A comprehensive data analysis framework for Astronomy

    • processing FITS images quickly
    • wrapping around 3rd party software
  • A Handy & Quick Calculator
  • Prototyping new algorithms/ideas
  • Making plots for papers
  • Notebooking (i.e. making me remember stuff)
    • see the iPython sessions later
  • Writing Presentations (these slides)

Python is everywhere

https://wiki.python.org/moin/OrganizationsUsingPython

Applications are Numerous

  • Scripting and Programing
  • GUI's
  • Web Development
  • Interactive Notebooks (see later)
  • Visualization
  • Parralelization
  • Animation
  • And so on...

Getting Started

  • The goal of the end of this talk is to make sure that you can
    • Start-up Python
    • Edit a text file
    • (start up the notebook)

Ask questions at any time

  • Just speak up or raise your hand

Get help at any time

  • We are wandering around the room
  • Just get our attention

It's important to not flail around and fall behind.

Last Thing: The Notebook

  • The iPython Notebook is a powerful tool
  • You will want to use it.
  • To start it up from the terminal type

jupyter notebook

and a browser window should open that looks like this

iPython on an iPad

The Notebook in Windows with Anaconda

Start -> All Programs -> Anaconda -> iPython Notebook


In [1]:
from matplotlib import pyplot as plt
import numpy as np
%matplotlib inline

In [2]:
plt.xkcd()
plt.figure(figsize=(16,8))
x = np.arange(10)
plt.plot(x,x+0.5*x*x)
plt.xlabel('Years Since Release')
plt.ylabel('Interest in Python')
plt.show()



In [3]:
import antigravity

How I made this talk

ipython nbconvert 00_introding_python.ipynb --to slides --post serve