Jake Bobowski
~Home~
SCI 266
jake.bobowski@ubc.ca
   UBCO

Here is a set of Python tutorials designed for the physics undergraduate. I am a Python novice. These tutorials are not intended to cover everything task that you might encounter. However, I hope to add scripts that cover many of the basic tasks that come up repeatedly.

The scripts were written using Anaconda toolkit. It is free and open source. You can download the Individual Edition from the Anaconda website. After the installation is complete, I recommend openning the 'Anaconda Powershell Prompt' and executing the command 'conda update --all' to update all of the packages before starting.

I wrote and executed my Python scripts using Spyder.

UBC students can write and run Python code in Jupyter Notebooks using UBC's Open Jupyter platform or Syzygy. You don't need to install any software, just log in using your CWL.



Note that the "Open in JupyterLab" links below will only work for those with UBC Campus-Wide Login (CWL) credentials.



BASICS
Preliminaries
Jupyter Notebook
Open in JupyterLab
.py/.html/output html
.ipynb/.html
UBC Open Jupyter/UBC Syzygy
Operating on a list/array
Jupyter Notebook
Open in JupyterLab
.py/.html/output html
.ipynb/.html
UBC Open Jupyter/UBC Syzygy
Merging lists/arrays
Jupyter Notebook
Open in JupyterLab
.py/.html/output html
.ipynb/.html
UBC Open Jupyter/UBC Syzygy

SYSTEMS OF EQUATIONS
Linear and simple systems
Jupyter Notebook
.py/.html/output html
.ipynb/.html
Nonlinear equations and systems
Jupyter Notebook
.py/.html/output html
.ipynb/.html

PLOTTING
Plotting data, formatting plots, saving plots
outputs
   
   
   
   

Jupyter Notebook
notebook output files

.py/.html/output html
test_plot.png
test_plot.jpg
test_plot.svg
test_plot.pdf
test_plot.eps

.ipynb/.html
Jupyter test_plot.png
Jupyter test_plot.jpg
Jupyter test_plot.svg
Jupyter test_plot.pdf
Jupyter test_plot.eps

Adding curves/data to existing plots
Jupyter Notebook
.py/.html/output html
.ipynb/.html
Plotting a function
Jupyter Notebook
.py/.html/output html
.ipynb/.html
Loglog and semilog plots
Jupyter Notebook
.py/.html/output html
.ipynb/.html
Histograms
Jupyter Notebook
notebook output files
.py/.html/output html
.ipynb/.html
plot (pdf)
plot (jpg)
plot (png)
plot (eps)
Surface plots
Jupyter Notebook
.py/.html/output html
.ipynb/.html
Interactive plots
Jupyter Notebook
import files

.ipynb/.html
F-H-data.txt
hydrogen spectrum.txt
Creating a gif from data
data file
data gif

Jupyter Notebook
data file
Jupyter data gif

.py/.html/output html
.txt
.gif

.ipynb/.html
.txt
.gif


FUNCTIONS
Functions in a script
Jupyter Notebook
.py/.html/output html
.ipynb/.html
Creating functions to be called by other scripts
Jupyter Notebook
modules/functions
   
all primes from 1 to 1e6
.py/.html/output html
.ipynb/.html
mod1.py/mod1.html
mod2.py/mod2.html
primes_1e6.txt
Jupyter primes_1e6.txt
A more "advanced" fubction
Jupyter Notebook
modules/functions
largest number checked for "primeness"
all primes from 1 to ~1.317e9 (compressed)
read me
.py/.html/output html
.ipynb/.html
modAdv.py/modAdv.html
primes_max.txt
primes_list.zip
read_me.txt

IMPORTING/EXPORTING DATA
Importing data
Jupyter Notebook
import file
.py/.html/output html
.ipynb/.html
.txt import
Importing multiple files
Jupyter Notebook
import files
.py/.html/output html
.ipynb/.html
file001data.txt
file002data.txt
file003data.txt
file004data.txt
file005data.txt
file008data.txt
file012data.txt
Exporting data
output file

Jupyter Notebook
output file

.py/.html/output html
matrix data.txt

.ipynb/.html
Jupyter matrix data.txt


FITTING DATA
Weighted linear fit
Jupyter Notebook
Open in JupyterLab
notebook output files
.py/.html/output html
.ipynb/.html
UBC Open Jupyter/UBC Syzygy
plot (pdf)
Weighted polynomial fit
Jupyter Notebook
Open in JupyterLab

.ipynb/.html
UBC Open Jupyter/UBC Syzygy
Weighted nonlinear fit
Jupyter Notebook #1
Open in JupyterLab
Jupyter Notebook #2
Open in JupyterLab
.py/.html/output html
.ipynb/.html
UBC Open Jupyter/UBC Syzygy
.ipynb/.html (error estimates)
UBC Open Jupyter/UBC Syzygy
Simultaneous nonlinear fits
Jupyter Notebook
Open in JupyterLab
data file
.py/.html/output html
.ipynb/.html
UBC Open Jupyter/UBC Syzygy
S11 - real imag.dat

INTERPOLATING DATA
Interpolation
Jupyter Notebook
data files
.py/.html/output html
.ipynb/.html
calibration data
experimental data

FOURIER TRANSFORMS
Fourier transform
Jupyter Notebook
data file
.py/.html/output html
.ipynb/.html
fftData.dat

INVERSE LAPLACE TRANSFORMS
Inverse Laplace transform
Jupyter Notebook
.py/.html/output html
.ipynb/.html
If you're interested a function capable of numerically evaluating the inverse Laplace transform of complex functions F(s), take a look at the following GitHub repositroy containing the Python function INVLAP.py: https://github.com/jake-bobowski/INVLAP.py.

CONVOLUTIONS
Convolution integrals
Jupyter Notebook
Open in JupyterLab

.ipynb/.html
UBC Open Jupyter/UBC Syzygy

CONTROL STRUCTURES
For loops
Jupyter Notebook
.py/.html/output html
.ipynb/.html
If statements
Jupyter Notebook
.py/.html/output html
.ipynb/.html
While loops
Jupyter Notebook
.py/.html/output html
.ipynb/.html
Nested structures
Jupyter Notebook
.py/.html/output html
.ipynb/.html

MATRICES
Matrix basics
Jupyter Notebook
Open in JupyterLab

.ipynb/.html
UBC Open Jupyter/UBC Syzygy

CALCULUS
Symbolic derivatives
Jupyter Notebook
.py/.html/output html
.ipynb/.html
Symbolic integrals
Jupyter Notebook
.py/.html/output html
.ipynb/.html
Discrete derivatives
Jupyter Notebook
.py/.html/output html
.ipynb/.html
Discrete integrals
Jupyter Notebook
.py/.html/output html
.ipynb/.html
Solving ordinary differential equations (ODEs)
Jupyter Notebook
.py/.html/output html
.ipynb/.html
Another ODE example
Jupyter Notebook

.ipynb/.html
Solving partial differential equations (PDEs)
Jupyter Notebook
.py/.html/output html
.ipynb/.html

NUMERICAL SOLUTIONS
Solving transcendental equations
Jupyter Notebook

.ipynb/.html
Numerical integration
Jupyter Notebook

.ipynb/.html
Numerically solving integral equations
Jupyter Notebook

.ipynb/.html

COMPLEX NUMBERS
Manipulating and ploting complex numbers
Jupyter Notebook
figure
.py/.html/output html
.ipynb/.html
Circuit diagram

NYQUIST RECONSTRUCTION
Reconstructing signals from samples
Jupyter Notebook
.py/.html/output html
.ipynb/.html

IMAGE PROCESSING
Basics of image processing
input image
output image one
output image two

Jupyter Notebook
input image
output image one
output image two

.py/.html/output html
30min.jpg
30min-enhanced.jpg
enhancedInt.jpg

.ipynb/.html
30min.jpg
Jupyter 30min-enhanced.jpg
Jupyter enhancedInt.jpg


MONTE CARLO BASICS
Monte Carlo Hit & Miss integration
Jupyter Notebook
Open in JupyterLab
.py/.html/output html
.ipynb/.html
UBC Open Jupyter/UBC Syzygy
Monte Carlo f-average integration
Jupyter Notebook
Open in JupyterLab
.py/.html/output html
.ipynb/.html
UBC Open Jupyter/UBC Syzygy
Volume of a sphere in d dimensions
Jupyter Notebook
figure
.py/.html/output html
.ipynb/.html
Wikipedia figure
Photomultiplier Tube (PMT) simulation
Jupyter Notebook
.py/.html/output html
.ipynb/.html
Brownian Motion Settling
Open in JupyterLab
.ipynb/.html
UBC Open Jupyter/UBC Syzygy
Brownian Motion Diffusion
Open in JupyterLab
.ipynb/.html
UBC Open Jupyter/UBC Syzygy
Brownian Motion Diffusion 3D
Open in JupyterLab
.ipynb/.html
UBC Open Jupyter/UBC Syzygy

DISPLAYING LATEX
Displaying LaTeX in the IPython console
Jupyter Notebook
.py/.html/output html
.ipynb/.html

APPLICATIONS
Calculating the area of a P-V diagram
circle data
triangle data
noisy ellipse data

Jupyter Notebook
circle data
triangle data
noisy ellipse data

.py/.html
circle.txt
triangle.txt
ellipse_noisy.txt

.ipynb/.html
circle.txt
triangle.txt
ellipse_noisy.txt





created by Jake Bobowski,
jake.bobowski@ubc.ca

last modified: October 21, 2024

URL: https://cmps-people.ok.ubc.ca/jbobowsk/Python.html

Giant Sequoia