Skip to main content

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

Project description

psfmodels

PyPI Python Version CI codecov

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

This package contains three models:

  1. The vectorial model is described in Auget et al 20091. For more information and implementation details, see Francois' Thesis2.
  2. A scalar model, based on Gibson & Lanni3.
  3. A gaussian approximation (both paraxial and non-paraxial), using paramters from Zhang et al (2007)4.

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

3 F. Gibson and F. Lanni (1992) J. Opt. Soc. Am. A, vol. 9, no. 1, pp. 154-166

4 Zhang et al (2007). Appl Opt . 2007 Apr 1;46(10):1819-29.

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

Install

pip install psfmodels

from source

git clone https://github.com/tlambert03/PSFmodels.git
cd PSFmodels
pip install -e ".[dev]"  # will compile c code via pybind11

Usage

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` microns from coverslip
# shape will be (127, 127, 127)
psf = psfm.make_psf(127, 127, dxy=0.05, dz=0.05, 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))
plt.show()

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
psf = psfm.make_psf(np.linspace(-3, 3, 31), nx=127)
psf.shape  # (31, 127, 127)

all PSF functions accept the following parameters. Units should be provided in microns unless otherwise stated. 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: 150.0]
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.0]
tg (float):     coverslip thickness, experimental value (microns) [default: 170.0]
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]

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.

Lightsheet PSF utility function

The psfmodels.tot_psf() function provides a quick way to simulate the total system PSF (excitation x detection) as might be observed on a light sheet microscope (currently, only strictly orthogonal illumination and detection are supported). See the lightsheet.ipynb Jupyter notebook for examples.

Project details


Download files

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

Source Distribution

psfmodels-0.3.3.tar.gz (581.1 kB view hashes)

Uploaded Source

Built Distributions

psfmodels-0.3.3-cp311-cp311-win_amd64.whl (111.0 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

psfmodels-0.3.3-cp311-cp311-musllinux_1_1_x86_64.whl (673.9 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

psfmodels-0.3.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (158.2 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

psfmodels-0.3.3-cp311-cp311-macosx_11_0_arm64.whl (106.1 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

psfmodels-0.3.3-cp311-cp311-macosx_10_9_x86_64.whl (113.1 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

psfmodels-0.3.3-cp310-cp310-win_amd64.whl (111.0 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

psfmodels-0.3.3-cp310-cp310-musllinux_1_1_x86_64.whl (673.9 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

psfmodels-0.3.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (158.2 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

psfmodels-0.3.3-cp310-cp310-macosx_11_0_arm64.whl (106.1 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

psfmodels-0.3.3-cp310-cp310-macosx_10_9_x86_64.whl (113.1 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

psfmodels-0.3.3-cp39-cp39-win_amd64.whl (110.7 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

psfmodels-0.3.3-cp39-cp39-musllinux_1_1_x86_64.whl (673.9 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

psfmodels-0.3.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (158.1 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

psfmodels-0.3.3-cp39-cp39-macosx_11_0_arm64.whl (106.2 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

psfmodels-0.3.3-cp39-cp39-macosx_10_9_x86_64.whl (113.2 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

psfmodels-0.3.3-cp38-cp38-win_amd64.whl (111.0 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

psfmodels-0.3.3-cp38-cp38-musllinux_1_1_x86_64.whl (673.7 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

psfmodels-0.3.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (158.0 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

psfmodels-0.3.3-cp38-cp38-macosx_11_0_arm64.whl (106.0 kB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

psfmodels-0.3.3-cp38-cp38-macosx_10_9_x86_64.whl (113.0 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

psfmodels-0.3.3-cp37-cp37m-win_amd64.whl (111.5 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

psfmodels-0.3.3-cp37-cp37m-musllinux_1_1_x86_64.whl (675.1 kB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ x86-64

psfmodels-0.3.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (158.1 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

psfmodels-0.3.3-cp37-cp37m-macosx_10_9_x86_64.whl (112.9 kB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page