← All STRAIT modules
TutorDA · STRAIT
Module B-C1

Scientific Programming with Python

This module develops the computational fluency researchers need to turn raw numerical and tabular data into reproducible scientific results using Python. Learners progress from the mechanics of the NumPy ndarray and vectorised arithmetic through Pandas data wrangling, Matplotlib publication-quality graphics, and the environment and packaging discipline that keeps analyses reproducible. Mastery is demonstrated when a learner can refactor a procedural script into a vectorised, documented, environment-pinned notebook whose figures and tables are regenerable from the source data.

Learning Outcomes

1.
Construct and manipulate NumPy ndarrays using dtype, shape, strides, slicing, and broadcasting with predictable memory behaviour.
2.
Refactor explicit Python loops into vectorised NumPy expressions and measure the resulting speed-up.
3.
Wrangle heterogeneous tabular data in Pandas using loc, iloc, groupby, merge, pivot, and missing-value handling.
4.
Produce publication-ready Matplotlib figures using the object-oriented API, subplots, and savefig with specified DPI and formats.
5.
Design Jupyter notebooks that interleave narrative, code, and figures while remaining reproducible from a clean kernel.
6.
Create, activate, and export isolated virtual environments using venv, pip, and requirements files.
7.
Diagnose and debug common numerical pitfalls such as integer overflow, floating-point error, and silent broadcasting bugs.
8.
Package small analysis utilities as importable modules with docstrings and lightweight tests.

Topics Covered

The NumPy ndarray: dtype, shape, strides, views versus copies
Universal functions, vectorisation, and broadcasting rules
Fancy indexing, boolean masking, and axis-wise reductions
Linear algebra with dot, @, matmul, and numpy.linalg
Pandas Series and DataFrame construction and I/O (read_csv, read_excel, to_parquet)
Label- versus position-based indexing: loc, iloc, chained-assignment pitfalls
Grouping, aggregation, and split-apply-combine with groupby
Reshaping with pivot, melt, stack, unstack, and merge/join semantics
Handling missing data: NaN, NA, isna, fillna, dropna
Matplotlib pyplot versus object-oriented API, subplots and figure layout
Saving figures with savefig: DPI, vector formats, and tight bounding boxes
Jupyter notebook workflow, kernels, magics, and reproducible execution order
Virtual environments and dependency pinning with venv and pip
Profiling and performance: %timeit, memory layout, and avoiding Python loops
Reproducible analysis structure: scripts versus notebooks, seeds, and data provenance

Skills Developed

Array programming Data wrangling Scientific visualisation Notebook literacy Environment management Debugging and profiling Reproducible workflow design Numerical reasoning

Suggested Resources

McKinney, W. (2022). Python for Data Analysis, 3rd ed., O'Reilly Media
Harris, C.R. et al. (2020). Array programming with NumPy, Nature 585, 357-362
VanderPlas, J. (2016). Python Data Science Handbook, O'Reilly Media
Hunter, J.D. (2007). Matplotlib: A 2D graphics environment, Computing in Science & Engineering
Official NumPy user guide and Pandas user guide (numpy.org / pandas.pydata.org)
Kluyver, T. et al. (2016). Jupyter Notebooks - a publishing format for reproducible computational workflows
Real Python tutorials on virtual environments and packaging (realpython.com)

Assessment

Learners are judged on their ability to produce vectorised, reproducible analyses rather than on isolated syntax recall. The weighting rewards sustained portfolio work and a terminal practical examination.

Reproducible analysis notebook on an assigned dataset (3000 words incl. code)45%
Timed practical examination and MCQ paper35%
Portfolio of three vectorisation and visualisation exercises20%
Practice bank: 200 MCQs · Timed mock & self-paced modes
Start Practice →