||Scientific Programming in Python
||Dr J. Hatchell
||15 NICATS / 7.5 ECTS
||120 students (approx)
A knowledge of a computing language and how to write programs to solve
physics related problems is a valuable transferable skill. This module
teaches the Python programming language, but the principles involved are
applicable to almost every procedural programming language. Python is
an interpreted, high-level, general-purpose programming language that is
widely used in commercial and academic environments and for scientific
research including high level data analysis work.
The module is taught through a series of lectures and practical sessions
based on Jupyter notebooks. The student will learn the building blocks
of the language, and a logical approach to coding, and use these to
create their own programs with physics applications.
Students learn to write clearly structured and documented programs in
Python (Jupyter notebooks), and are able to find and use Python module
Intended Learning Outcomes (ILOs)
A student who has passed this module should be able to:
Module Specific Skills and Knowledge:
- explain and use standard features of the Python programming language including
statements, assignments, objects, loops, conditionals and functions.
- write and modify simple programs in Python;
- find errors and debug code;
- write structured code based on short routines with a clear purpose and interfaces
that are simple and unambiguous;
- write self-explanatory, self-documenting code using markdown, docstrings and
- select and apply existing tools for scientific programming from modules including
Numpy, Scipy, Matplotlib and Astropy, based on the documentation;
Discipline Specific Skills and Knowledge:
- apply logic to the solution of problems;
- keep proper records of work;
- apply the Python programming language to simple physical
problems including calculations, modelling and data analysis;
- produce publication-quality plots;
- present a portfolio of work;
Personal and Key Transferable / Employment Skills and Knowledge:
- deal with the practicalities of writing a computer program;
- think and plan in a logical manner;
- apply a structured approach to problem solving.
Introduction to Python
- Running interactive Python; loading modules and packages; using Python as a
graphical calculator; simple calculations, maths, simple functions and plotting.
- Using Jupyter notebooks with Numpy and Matplotlib.
Core Python programming
- Objects, variables and assignments. Dynamic 'Duck' typing. Numerical
- More datatypes: strings, lists, tuples, and dictionaries.
- Control flow I: Conditionals, comparisons and Boolean logic.
- Control flow II: Loops.
- Functions: keyword and positional arguments, default arguments, *args and
**kwargs, docstrings, variable scope.
- Program structure and documentation, error handling, testing and debugging.
Python for labs
- Numpy arrays and datatypes.
- Using Numpy for reading and writing data; simple statistics; plotting data with
- Fitting a straight line with a least-squares fit.
- Nonlinear least-squares fitting with Scipy.
- Publication-quality plots with Matplotlib: multiple axes, control of plot elements.
Python packages and modules
- How to find out what's available and use the documentation.
- Further examples from Matplotlib e.g. histograms, 2D plots.
- Further examples from Numpy e.g. random numbers, matrices.
- Introduction and examples from Scipy e.g. root finding and numerical integration.
- Introduction and examples from Astropy e.g. reading and displaying FITS images.
- File handling with contexts. Filename and process handling with 'sys' and 'os'.
- Classes and objects.
- Creating a Python program and /or module in an IDE. if __name_ ==
"__main__" and command-line arguments.
- Programming project based on the stage 1 Physics programme content.
Learning and Teaching
Learning Activities and Teaching Methods
|22×2-hour supervised computer labs
|8×4-hour Python homework assignments
|1×12-hour Python project
|Reading to support own learning requirements
||19×Python classwork assignments (formative)
||Written and verbal
||4 hours per assignment
||Deadline Friday week T1:03,05,08,10,12 T2:03,05,07
||Written and verbal
||6 hours (homework) 6 hours (in class)
||Deadline Friday week T2:11
||Written and verbal
The following list is offered as an indication of the type & level of information that
students are expected to consult. Further guidance will be provided by the Module Instructor(s).
Hill C. (2020), Learning Scientific Programming with Python (2nd edition), Cambridge, ISBN 978-1-108-74591-8 (UL: eBook)
Kong Q., Slauw T. and Bayen A.M. (2021), Python Programming and Numerical Methods: a Guide for Engineers and Scientists, Academic Press, ISBN 978-0-128-19550-5 (UL: eBook)
Wood M. (2015), Python and Matplotlib Essentials for Scientists and Engineers, IoP Science, ISBN 978-1-627-05620-5 (UL: eBook)
Prior Knowledge Requirements
||Vector Mechanics (PHY1021), Introduction to Astrophysics (PHY1022), Waves and Optics (PHY1023), Properties of Matter (PHY1024) and Mathematics Skills (PHY1025)
Re-assessment is not available except when required by referral or deferral.
|Original form of assessment
||Form of re-assessment
||Time scale for re-assessment
|Programming project and homework assignments
||Programming project (16 hours) 100% wt
||August/September assessment period
KIS Data Summary
|Learning activities and teaching methods|
|SLT - scheduled learning & teaching activities
|GIS - guided independent study
|PLS - placement/study abroad
|IoP Accreditation Checklist
||Physics; Python; Program; Structures; Function; Codes; Project; Data; Computing; Arrays; Designing.