Skip to main content

Scalar and vectorial models of the microscope point spread function (PSF).

Project description


Python bindings for scalar and vectorial models of the point spread function.

Original C++ code and MATLAB MEX bindings Copyright © 2006-2013, Francois Aguet, distributed under GPL-3.0 license. Python bindings by Talley Lambert

The model is described in Auget et al 20091. For more information and implementation details, see Francois' Thesis2.

1 F. Aguet et al., (2009) Opt. Express 17(8), pp. 6829-6848

2 F. Aguet. (2009) Super-Resolution Fluorescence Microscopy Based on Physical Models. Swiss Federal Institute of Technology Lausanne, EPFL Thesis no. 4418

see also:

For a different (faster) scalar-based Gibson–Lanni PSF model, see the MicroscPSF project, based on Li et al (2017) which has been implemented in Python, MATLAB, and ImageJ/Java


Prebuilt binaries available on pypi for OS X and Windows, sdist available for linux

pip install psfmodels

from source

(requires cmake and a c++ compiler)

git clone
cd PSFmodels-py
python install


There are two main functions in psfmodels: vectorial_psf and scalar_psf. Additionally, each version has a helper function called vectorial_psf_centered and scalar_psf_centered respectively. The main difference is that the _psf functions accept a vector of Z positions zv (relative to coverslip) at which PSF is calculated. As such, the point source may or may not actually be in the center of the rendered volume. The _psf_centered variants, by contrast, do not accecpt zv, but rather accept nz (the number of z planes) and dz (the z step size in microns), and always generates an output volume in which the point source is positioned in the middle of the Z range, with planes equidistant from each other. All functions accept an argument pz, specifying the position of the point source relative to the coverslip. See additional keyword arguments below

Note, all output dimensions (nx and nz) should be odd.

import psfmodels as psfm
import matplotlib.pyplot as plt
from matplotlib.colors import PowerNorm

# generate centered psf with a point source at `pz` from coverslip
nx = 127
nz = nx
dxy = 0.05
psf = psfm.vectorial_psf_centered(nz=nz, nx=nx, dxy=dxy, dz=dxy, pz=0)
fig, (ax1, ax2) = plt.subplots(1, 2)
ax1.imshow(psf[nz//2], norm=PowerNorm(gamma=0.4))
ax2.imshow(psf[:, nx//2], norm=PowerNorm(gamma=0.4))

Image of PSF

# instead of nz and dz, you can directly specify a vector of z positions
import numpy as np

# generate 31 evenly spaced Z positions from -3 to 3 microns
zv = np.linspace(-3, 3, 31)
psf = psfm.vectorial_psf(zv, nx=127)
psf.shape  # (31, 127, 127)

all PSF functions accept the following parameters. In general, units should be provided in microns. Python API may change slightly in the future. See function docstrings as well.

nx (int):       XY size of output PSF in pixels, must be odd.
dxy (float):    pixel size in sample space (microns) [default: 0.05]
pz (float):     depth of point source relative to coverslip (in microns) [default: 0]
ti0 (float):    working distance of the objective (microns) [default: 1.515]
ni0 (float):    immersion medium refractive index, design value [default: 1.515]
ni (float):     immersion medium refractive index, experimental value [default: 1.515]
tg0 (float):    coverslip thickness, design value (microns) [default: 170]
tg (float):     coverslip thickness, experimental value (microns) [default: 170]
ng0 (float):    coverslip refractive index, design value [default: 1.515]
ng (float):     coverslip refractive index, experimental value [default: 1.515]
ns (float):     sample refractive index [default: 1.47]
wvl (float):    emission wavelength (microns) [default: 0.6]
NA (float):     numerical aperture [default: 1.4]
sf (int):       oversampling factor to approximate pixel integration [default: 3]
mode (int):     if 0, returns oversampled PSF [default: 1]

Comparison with other models

While these models are definitely slower than the one implemented in Li et al (2017) and MicroscPSF, there are some interesting differences between the scalar and vectorial approximations, particularly with higher NA lenses, non-ideal sample refractive index, and increasing spherical aberration with depth from the coverslip.

For an interactive comparison, see the examples.ipynb Jupyter notebook.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for psfmodels, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size psfmodels-0.1.0.tar.gz (163.0 kB) File type Source Python version None Upload date Hashes View
Filename, size psfmodels-0.1.0-cp37-cp37m-win_amd64.whl (83.1 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size psfmodels-0.1.0-cp37-cp37m-macosx_10_9_x86_64.whl (85.0 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size psfmodels-0.1.0-cp36-cp36m-win_amd64.whl (83.1 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size psfmodels-0.1.0-cp36-cp36m-macosx_10_7_x86_64.whl (85.1 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size psfmodels-0.1.0-cp35-cp35m-win_amd64.whl (83.1 kB) File type Wheel Python version cp35 Upload date Hashes View
Filename, size psfmodels-0.1.0-cp35-cp35m-macosx_10_9_x86_64.whl (85.1 kB) File type Wheel Python version cp35 Upload date Hashes View
Filename, size psfmodels-0.1.0-cp27-cp27m-macosx_10_6_x86_64.whl (85.3 kB) File type Wheel Python version cp27 Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page