PHY1031 |
Scientific Programming in Python |
2023-24 |
|
Dr J. Hatchell |
|
|
Delivery Weeks: |
T1:01-12, T2:01-11
|
|
Level: |
4 (NQF) |
|
Credits: |
15 NICATS / 7.5 ECTS |
|
Enrolment: |
120 students (approx) |
|
Description
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.
Module Aims
Students learn to write clearly structured and documented programs in
Python (Jupyter notebooks), and are able to find and use Python module
functionality.
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
#comments;
- 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.
Syllabus Plan
-
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
datatypes.
- 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
errorbars.
- 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.
-
Advanced Python
- 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.
-
Projects
- Programming project based on the stage 1 Physics programme content.
Learning and Teaching
Learning Activities and Teaching Methods
Description |
Study time |
KIS type |
18×1-hour lectures |
18 hours
|
SLT |
22×2-hour supervised computer labs |
44 hours
|
SLT |
8×4-hour Python homework assignments |
32 hours
|
GIS |
1×12-hour Python project |
12 hours
|
GIS |
Reading to support own learning requirements |
44 hours
|
GIS |
Assessment
Weight |
Form |
Size |
When |
ILOS assessed |
Feedback |
0% |
19×Python classwork assignments (formative) |
8 hours |
In class |
1-16 |
Written and verbal |
80% |
8×homework assignments |
4 hours per assignment |
Deadline Friday week T1:03,05,08,10,12 T2:03,05,07 |
1-16 |
Written and verbal |
20% |
Programming project |
6 hours (homework) 6 hours (in class) |
Deadline Friday week T2:11 |
1-16 |
Written and verbal |
Resources
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).
Core text:
Supplementary texts:
-
Hill C. (2020), Learning Scientific Programming with Python (2nd edition), Cambridge, ISBN 978-1-108-74591-8
-
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
-
Wood M. (2015), Python and Matplotlib Essentials for Scientists and Engineers, IoP Science, ISBN 978-1-627-05620-5
ELE:
Further Information
Prior Knowledge Requirements
Pre-requisite Modules |
none |
Co-requisite Modules |
Vector Mechanics (PHY1021), Introduction to Astrophysics (PHY1022), Waves and Optics (PHY1023), Properties of Matter (PHY1024) and Mathematics Skills (PHY1025) |
Re-assessment
Re-assessment is not available except when required by referral or deferral.
Original form of assessment |
Form of re-assessment |
ILOs re-assessed |
Time scale for re-assessment |
Programming project and homework assignments |
Programming project (16 hours) 100% wt |
1-16 |
August/September assessment period |
KIS Data Summary
Learning activities and teaching methods |
SLT - scheduled learning & teaching activities |
62 hrs |
GIS - guided independent study |
88 hrs |
PLS - placement/study abroad |
0 hrs |
Total |
150 hrs |
|
|
Summative assessment |
Coursework |
100% |
Written exams |
0% |
Practical exams |
0% |
Total |
100% |
|
Miscellaneous
IoP Accreditation Checklist |
|
Availability |
unrestricted |
Distance learning |
NO |
Keywords |
Physics; Python; Program; Structures; Function; Codes; Project; Data; Computing; Arrays; Designing. |
Created |
29-Mar-22 |
Revised |
18-Jun-22 |