Python for Physics and Astronomy: Difference between revisions

From AstroEdWiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(61 intermediate revisions by the same user not shown)
Line 1: Line 1:
The Python programming language is a widely used tool for basic research and engineering.  Its rapid rise in popularity is supported by comprehensive, largely open-source, contributions from scientists who use it for their own work.  This short course offers an introduction to Python with examples drawn from physics and astronomy as part of a full semester
The Python programming language is a widely used tool for basic research and engineering.  Its rapid rise in popularity is supported by comprehensive, largely open-source, contributions from scientists who use it for their own work.  This short course offers an introduction to Python with examples drawn from physics and astronomy.  
[http://prancer.physics.louisville.edu/astrowiki/index.php/Research_Methods Research Methods] class.


The examples are collected [http://prancer.physics.louisville.edu/astrowiki/index.php/Python_examples here].


All the assignments are [http://prancer.physics.louisville.edu/astrowiki/index.php/Python_assignments here].
This resource was developed as a component of a
[http://prancer.physics.louisville.edu/astrowiki/index.php/Research_Methods Research Methods] class Various examples that may be useful for
developing small Python programs are collected [http://prancer.physics.louisville.edu/astrowiki/index.php/Python_examples here]. They are a basis for a few exercises that were assigned during the course are are available [http://prancer.physics.louisville.edu/astrowiki/index.php/Python_assignments here].


Homework should be uploaded [http://prancer.physics.louisville.edu/homework here].
This resource is maintained so that it is reasonable current with the latest releases of Python 3 and component modules.  The code discussed has been tested in Python 3.6, though some pieces of older code may still be lurking, they should be recognizable and easily modified if errors occur.


The topics and examples covered are --
 
The topics and examples covered --


#[http://prancer.physics.louisville.edu/astrowiki/index.php/Programming_for_Physics_and_Astronomy  Why program? Choosing a language.]  
#[http://prancer.physics.louisville.edu/astrowiki/index.php/Programming_for_Physics_and_Astronomy  Why program? Choosing a language.]  
#[http://prancer.physics.louisville.edu/astrowiki/index.php/Very_simple_Python Very simple Python]
#[http://prancer.physics.louisville.edu/astrowiki/index.php/Very_simple_Python Very simple Python]
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Very_simple_Python#Installing_Python_on_your_computer Installing it on your computer]
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Very_simple_Python#Installing_Python_on_your_computer Installing it on your computer]
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Very_simple_Python#IDE.27s_and_Editors_and_Python_environments Editors and environments]
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Very_simple_Python#Using_Python_in_real_time Using it in real time]
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Very_simple_Python#Using_Python_in_real_time Using it in real time]
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Very_simple_Python#Using_Python_code_as_a_standalone_program Using code as a standalone program]
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Very_simple_Python#Using_Python_code_as_a_standalone_program Using code as a standalone program]
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Python_examples Examples]  
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Python_examples Examples]  
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Python_assignments Assignments]
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Python_assignments Assignments]
#Elements of Python programming
#[http://prancer.physics.louisville.edu/astrowiki/index.php/Elements_of_Python_programming Elements of Python programming]
##Input and output
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Elements_of_Python_programming#Input_and_output Input and output]
##Data types: numbers and strings
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Elements_of_Python_programming#Numbers.2C_text.2C_and_data_types Data types: numbers and strings]
##Lists, tuples, dictionaries, and statements
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Elements_of_Python_programming#Lists.2C_tuples.2C_dictionaries.2C_and_statements Lists, tuples, dictionaries, and statements]
##Mathematics
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Python_examples Examples]
##Examples  
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Python_assignments Assignments]
##Assignments
#[http://prancer.physics.louisville.edu/astrowiki/index.php/Solving_problems_with_Python Solving problems with Python]
#Solving problems with Python
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Solving_problems_with_Python#Flow.2C_control Flow control]
##Flow control
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Solving_problems_with_Python#Functions Functions]
##Functions
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Solving_problems_with_Python#Iteration Iteration]
##Iteration
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Python_examples Examples]
##Examples
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Python_assignments Assignments]
##Assignments
#[http://prancer.physics.louisville.edu/astrowiki/index.php/Graphical_User_Interface_with_Python Graphical User Interfaces with Python]
#Graphics
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Graphical_User_Interface_with_Python#A_Tk_Tutorial A Tk Tutorial]
##Matplotlib
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Graphical_User_Interface_with_Python#Building_a_Program Building a Program]
##Examples
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Graphical_User_Interface_with_Python#Interfacing_an_Instrument:_Phidgets Interfacing an Instrument]
##Assignments
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Graphical_User_Interface_with_Python#Events_and_Control_Within_the_User_Interface Events and Control]
#Numpy, Scipy and Scikit
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Graphical_User_Interface_with_Python#Widgets Widgets]
##Numpy arrays
#[http://prancer.physics.louisville.edu/astrowiki/index.php/Graphics_with_Python Graphics with Python]
##Numpy math
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Graphics_with_Python#Installation_of_matplotlib Matplotlib]
##Scipy interpolation and integration
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Graphics_with_Python#Learning_the_basics_of_2D_data_and_function_plotting Learning the basics of 2D data and function plotting]
##Scipy statistics
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Graphics_with_Python#Interactive_plotting Interactive plotting]
##Examples
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Graphics_with_Python#A_little_3D_plotting A little 3D plotting]
##Assignments
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Graphics_with_Python#Bokeh Bokeh]
#Images
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Python_examples Examples]
##Python Imaging Library - PIL
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Python_assignments Assignments]
##Astronomical FITS files with Pyfits
#[http://prancer.physics.louisville.edu/astrowiki/index.php/NumPy,_SciPy_and_SciKits NumPy, SciPy and SciKits]
##FITS headers
##[http://prancer.physics.louisville.edu/astrowiki/index.php/NumPy,_SciPy_and_SciKits#NumPy NumPy]
##Processing and displaying images
###[http://prancer.physics.louisville.edu/astrowiki/index.php/NumPy,_SciPy_and_SciKits#Arrays Arrays]
##Scipy and Scikit for image processing
###[http://prancer.physics.louisville.edu/astrowiki/index.php/NumPy,_SciPy_and_SciKits#Indexing Indexing]
##Examples
###[http://prancer.physics.louisville.edu/astrowiki/index.php/NumPy,_SciPy_and_SciKits#Functions_Broadcasting_Over_an_Array Functions and Broadcasting]
##Assignments
###[http://prancer.physics.louisville.edu/astrowiki/index.php/NumPy,_SciPy_and_SciKits#Matrix_and_Vector_Math_in_NumPy Matrix and Vector Math]
#Data acquisition and processing
###[http://prancer.physics.louisville.edu/astrowiki/index.php/NumPy,_SciPy_and_SciKits#Fourier_Transforms_in_NumPy Fourier Transforms in NumPy]
##Real world interfacing
##[http://prancer.physics.louisville.edu/astrowiki/index.php/NumPy,_SciPy_and_SciKits#SciPy_and_SciKits  SciPy and SciKits]
##Numerical data from images
###[http://prancer.physics.louisville.edu/astrowiki/index.php/NumPy,_SciPy_and_SciKits#Interpolation Interpolation]
##Fourier Transforms
###[http://prancer.physics.louisville.edu/astrowiki/index.php/NumPy,_SciPy_and_SciKits#Integration Integration]
##Spectra
###[http://prancer.physics.louisville.edu/astrowiki/index.php/NumPy,_SciPy_and_SciKits#Differentiation Differentiation]
##Probability and statistics
###[http://prancer.physics.louisville.edu/astrowiki/index.php/NumPy,_SciPy_and_SciKits#Statistics Statistics]
##Examples
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Python_examples Examples]
##Assignments
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Python_assignments Assignments]
#User interfaces
#[http://prancer.physics.louisville.edu/astrowiki/index.php/Image_processing_with_Python_and_SciPy Image processing with Python and SciPy]
##Command line and the operating system
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Image_processing_with_Python_and_SciPy#Python_Imaging_Library_-_PIL Python Imaging Library - PIL]
##Graphical user interfaces in Python (GUI)
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Image_processing_with_Python_and_SciPy#Images_with_NumPy_and_SciPy Images with NumPy and SciPy]
##Examples
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Image_processing_with_Python_and_SciPy#Astronomical_FITS_Files Astronomical FITS Files]
##Assignments
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Image_processing_with_Python_and_SciPy#Other_Processing Other Processing]
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Image_processing_with_Python_and_SciPy#SciKits SciKits]
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Image_processing_with_Python_and_SciPy#AstroImageJ_and_Alsvid AstroImageJ and Alsvid]
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Python_examples Examples]
##[http://prancer.physics.louisville.edu/astrowiki/index.php/Python_assignments Assignments]
#[http://prancer.physics.louisville.edu/astrowiki/index.php/User_Interfaces User Interfaces]
##[http://prancer.physics.louisville.edu/astrowiki/index.php/User_Interfaces#Command_Line_Interfacing_and_Access_to_the_Operating_System  Command Line Interfacing and Access to the Operating System]
##[http://prancer.physics.louisville.edu/astrowiki/index.php/User_Interfaces#Graphical_User_Interface_to_Plotting  Graphical User Interface to Plotting]
##[http://prancer.physics.louisville.edu/astrowiki/index.php/User_Interfaces#Running_a_Bokeh_Server_for_Live_Plotting_of_Python_Data Running a Bokeh Server for LIve Plotting of Python Data]
##[http://prancer.physics.louisville.edu/astrowiki/index.php/User_Interfaces#Running_a_Server_for_Javascript_in_a_Browser_Engine  Running a Server for Javascript in a Browser Engine]
#[http://prancer.physics.louisville.edu/astrowiki/index.php/How_to_Create_a_Javascript_Program How to create a javascript program]
 
 
These topics may be added to a longer version of this course or as working notes when time allows.
 
#Bayesian methods with Python and Markov Chain Monte Carlo (MCMC)  analyses
#Real world interfacing
##Instrumentation and communication
##Serial ports
##USB
##Ethernet and TCPIP
#Parallel processing
##Using all the processors (CPUs) in your computer
##Using graphical processing units (GPUs)
##Artificial intelligence computing with tensor processing units (TPUs)
#Working with the web
#Working with the web
##HTTP servers
##HTTP servers
##Getting data from servers
##Getting data from servers
##Sending data to servers
##Sending data to servers
##Common gateway interface - CGI
##Using Python with the Common Gateway Interface (CGI)
##Using Python with CGI  
##Programming for server-side processing
##Programming for server-side processing
##Examples
#Python and  other languages
##Assignments
#Comparing Python to other languages
##Bash scripting in Unix-like systems
##Bash scripting in Unix-like systems
##Gnu Data Language (GDL) as a replacement for IDL or bridge to Python
##Very simple C
##Very simple C
##Using Python with other code
##Connecting Python to the browser engine
##Android for web development
##Chrome and Firefox for web development
##LabVIEW for instrument control and data analysis
##Java for astronomical calculations: AstroCC and AstroImageJ
##Java for astronomical calculations: AstroCC
##Java for astronomical image processing and photometry: AstroImageJ

Latest revision as of 06:41, 17 April 2018

The Python programming language is a widely used tool for basic research and engineering. Its rapid rise in popularity is supported by comprehensive, largely open-source, contributions from scientists who use it for their own work. This short course offers an introduction to Python with examples drawn from physics and astronomy.


This resource was developed as a component of a Research Methods class Various examples that may be useful for developing small Python programs are collected here. They are a basis for a few exercises that were assigned during the course are are available here.

This resource is maintained so that it is reasonable current with the latest releases of Python 3 and component modules. The code discussed has been tested in Python 3.6, though some pieces of older code may still be lurking, they should be recognizable and easily modified if errors occur.


The topics and examples covered --

  1. Why program? Choosing a language.
  2. Very simple Python
    1. Installing it on your computer
    2. Editors and environments
    3. Using it in real time
    4. Using code as a standalone program
    5. Examples
    6. Assignments
  3. Elements of Python programming
    1. Input and output
    2. Data types: numbers and strings
    3. Lists, tuples, dictionaries, and statements
    4. Examples
    5. Assignments
  4. Solving problems with Python
    1. Flow control
    2. Functions
    3. Iteration
    4. Examples
    5. Assignments
  5. Graphical User Interfaces with Python
    1. A Tk Tutorial
    2. Building a Program
    3. Interfacing an Instrument
    4. Events and Control
    5. Widgets
  6. Graphics with Python
    1. Matplotlib
    2. Learning the basics of 2D data and function plotting
    3. Interactive plotting
    4. A little 3D plotting
    5. Bokeh
    6. Examples
    7. Assignments
  7. NumPy, SciPy and SciKits
    1. NumPy
      1. Arrays
      2. Indexing
      3. Functions and Broadcasting
      4. Matrix and Vector Math
      5. Fourier Transforms in NumPy
    2. SciPy and SciKits
      1. Interpolation
      2. Integration
      3. Differentiation
      4. Statistics
    3. Examples
    4. Assignments
  8. Image processing with Python and SciPy
    1. Python Imaging Library - PIL
    2. Images with NumPy and SciPy
    3. Astronomical FITS Files
    4. Other Processing
    5. SciKits
    6. AstroImageJ and Alsvid
    7. Examples
    8. Assignments
  9. User Interfaces
    1. Command Line Interfacing and Access to the Operating System
    2. Graphical User Interface to Plotting
    3. Running a Bokeh Server for LIve Plotting of Python Data
    4. Running a Server for Javascript in a Browser Engine
  10. How to create a javascript program


These topics may be added to a longer version of this course or as working notes when time allows.

  1. Bayesian methods with Python and Markov Chain Monte Carlo (MCMC) analyses
  2. Real world interfacing
    1. Instrumentation and communication
    2. Serial ports
    3. USB
    4. Ethernet and TCPIP
  3. Parallel processing
    1. Using all the processors (CPUs) in your computer
    2. Using graphical processing units (GPUs)
    3. Artificial intelligence computing with tensor processing units (TPUs)
  4. Working with the web
    1. HTTP servers
    2. Getting data from servers
    3. Sending data to servers
    4. Using Python with the Common Gateway Interface (CGI)
    5. Programming for server-side processing
  5. Python and other languages
    1. Bash scripting in Unix-like systems
    2. Gnu Data Language (GDL) as a replacement for IDL or bridge to Python
    3. Very simple C
    4. Connecting Python to the browser engine
    5. Chrome and Firefox for web development
    6. Java for astronomical calculations: AstroCC and AstroImageJ