Python Resources
The Python reference pages used in this course live on the Physics Labs Python site, shared across the undergraduate lab courses. Everything below opens there.
You will use Python in every prelab and every lab: to turn a derivation into a function you can re-run with measured component values, and to plot your data against that prediction. See Prelab Expectations and Recommendations for how that fits into the week.
Start here
| Page | What it covers |
|---|---|
| Setup & Installation | Installing Python and VS Code on your own laptop. Do this before the first prelab |
| Python Basics | The language itself — values, functions, loops, imports |
| Workflows | Notebooks vs. scripts, and when to reach for each |
| Working Effectively | Writing calculations as reusable functions and collecting them in a module you import |
Or work in the browser with Colab
The program recommends installing Python and VS Code, and that is the path the setup page walks you through. For this course, Google Colab is a perfectly good alternative — nothing in Labs 1–10 asks Python to talk to an instrument, so the one thing Colab cannot do is not something you need. If you would rather not install anything, or you are on a machine where you can’t, use it.
Three things to know before you choose it:
- It doesn’t get you out of installing software. You need LTspice on your own laptop for the simulation in every prelab, and Lab 10 asks you to install the Arduino IDE.
- Your reusable
.pymodule takes an extra step. Collecting your functions in one file and importing it is the habit this course leans on hardest, and it assumes the file sits next to your notebook. On Colab you upload it each session or mount Google Drive. - Data files have to be uploaded, including the LTspice exports you make in Lab 7.
Nothing else changes — the lab guides’ code runs the same either way, and you submit the same thing: one PDF to Canvas, made with the department’s Jupyter Notebook to PDF converter, which takes a notebook from either.
Analyzing data
| Page | What it covers |
|---|---|
| Arrays and Plotting | NumPy arrays, reading and writing data files, Matplotlib figures — every lab |
| Curve Fitting | scipy.optimize.curve_fit, uncertainties from the covariance matrix, residuals — Lab 7 onward |
Controlling instruments
Nothing in Labs 1–10 asks you to drive an instrument from Python — you will work the front panels by hand. It becomes worth knowing for the final project, where automating a measurement can be the difference between one frequency response and ten.
| Page | What it covers |
|---|---|
| VISA Instrument Control | Driving bench instruments from Python with pyvisa, over the USB or Ethernet port on the back |
That page is written against this course’s bench — the Keysight EDU33212A waveform generator, the Keysight EDU36311A power supply, and the Tektronix TBS2000 oscilloscope — so its examples are the instruments in front of you, not generic ones you have to translate. It covers setting up a waveform, reading a measurement off the scope, and capturing a raw trace.
Its longest example steps a generator and a scope together to trace a frequency response: the Bode magnitude plot you made by hand in Lab 3, run as a loop. Lab 9 makes the same point from the hardware side — your scope has an ADC in it and a port on the back, and this is what that port is for.
The Setup page covers the pyvisa install.
Final projects are graded on analog understanding, and programming-heavy projects are strongly discouraged. Automating a sweep so you can characterize a circuit properly is squarely a measurement technique. Building a project whose substance is software is not.