API for laserbeamsize package

laserbeamsize.laserbeamsize Module

A module for finding the beam size in an monochrome image.

Full documentation is available at <https://laserbeamsize.readthedocs.io>

Simple and fast calculation of beam sizes from a single monochrome image based on the ISO 11146 method of variances. Some effort has been made to make the algorithm less sensitive to background offset and noise.

Finding the center and diameters of a beam in a monochrome image is simple:

>>>> import imageio
>>>> import numpy as np
>>>> import laserbeamsize as lbs
>>>> beam_image = imageio.imread("t-hene.pgm")
>>>> x, y, dx, dy, phi = lbs.beam_size(beam_image)
>>>> print("The center of the beam ellipse is at (%.0f, %.0f)" % (x, y))
>>>> print("The ellipse diameter (closest to horizontal) is %.0f pixels" % dx)
>>>> print("The ellipse diameter (closest to   vertical) is %.0f pixels" % dy)
>>>> print("The ellipse is rotated %.0f° ccw from the horizontal" % (phi * 180/3.1416))

A full graphic can be created by:

>>>> lbs.beam_size_plot(beam_image)
>>>> plt.show()

A mosaic of images might be created by:

>>>> # read images for each location
>>>> z = np.array([89,94,99,104,109,114,119,124,129,134,139], dtype=float) #[mm]
>>>> filenames = ["%d.pgm" % location for location in z]
>>>> images = [imageio.imread(filename) for filename in filenames]
>>>> lbs.beam_size_montage(images, z * 1e-3, pixel_size=3.75, crop=True)
>>>> plt.show()


subtract_image(original, background)

Subtract background from original image.

subtract_threshold(image, threshold)

Return image with constant subtracted.

subtract_tilted_background(image[, ...])

Return image with tilted planar background subtracted.

corner_background(image[, corner_fraction])

Return the mean and stdev of background in corners of image.

corner_mask(image[, corner_fraction])

Create boolean mask for image with corners marked as True.

perimeter_mask(image[, corner_fraction])

Create boolean mask for image with a perimeter marked as True.

corner_subtract(image[, corner_fraction, nT])

Return image with background subtracted.

rotate_image(original, x0, y0, phi)

Create image rotated about specified centerpoint.

rotated_rect_mask(image, xc, yc, dx, dy, phi)

Create ISO 11146 rectangular mask for specified beam.

rotated_rect_arrays(xc, yc, dx, dy, phi[, ...])

Return x, y arrays to draw a rotated rectangle.

axes_arrays(xc, yc, dx, dy, phi[, ...])

Return x, y arrays needed to draw semi-axes of ellipse.


Determine the beam center, diameters, and tilt using ISO 11146 standard.


Slow but simple implementation of ISO 11146 beam standard.

beam_size(image[, mask_diameters, ...])

Determine beam parameters in an image with noise.

beam_ellipticity(dx, dy)

Calculate the ellipticity of the beam.

beam_test_image(h, v, xc, yc, dx, dy, phi[, ...])

Create a test image.


Draw a simple astigmatic beam ellipse with labels.

ellipse_arrays(xc, yc, dx, dy, phi[, npoints])

Return x, y arrays to draw a rotated ellipse.

elliptical_mask(image, xc, yc, dx, dy, phi)

Create a boolean mask for a rotated elliptical disk.

major_axis_arrays(image, xc, yc, dx, dy, phi)

Return x, y, z, and distance values along semi-major axis.

minor_axis_arrays(image, xc, yc, dx, dy, phi)

Return x, y, z, and distance values along semi-minor axis.

beam_size_plot(o_image[, title, pixel_size, ...])

Create a visual report for image fitting.

beam_size_and_plot(o_image[, pixel_size, ...])

Plot the image, fitted ellipse, integration area, and semi-major/minor axes.

beam_size_montage(images[, z, cols, ...])

Create a beam size montage for a set of images.

laserbeamsize.m2 Module

A module for finding M² values for a laser beam.

Full documentation is available at <https://laserbeamsize.readthedocs.io>

Start with necessary imports:

>>>> import numpy as np
>>>> import laserbeamsize as lbs

Finding the beam waist size, location, and M² for a beam is straightforward:

>>>> lambda0 = 632.8e-9 # m
>>>> z = np.array([168, 210, 280, 348, 414, 480, 495, 510, 520, 580, 666, 770])
>>>> r = np.array([597, 572, 547, 554, 479, 403, 415, 400, 377, 391, 326, 397])
>>>> lbs.M2_report(z * 1e-3, 2 * r * 1e-6, lambda0)

A graphic of the fit to diameters can be created by:

>>>> lbs.M2_diameter_plot(z * 1e-3, 2 * r * 1e-6, lambda0)
>>>> plt.show()

A graphic of the radial fit can be created by:

>>>> lbs.M2_radius_plot(z * 1e-3, 2 * r * 1e-6, lambda0)
>>>> plt.show()


z_rayleigh(w0, lambda0[, M2])

Return the Rayleigh distance for a Gaussian beam.

beam_radius(w0, lambda0, z[, z0, M2])

Return the beam radius at an axial location.

magnification(w0, lambda0, s, f[, M2])

Return the magnification of a Gaussian beam.

image_distance(w0, lambda0, s, f[, M2])

Return the image location of a Gaussian beam.

curvature(w0, lambda0, z[, z0, M2])

Calculate the radius of curvature of a Gaussian beam.

divergence(w0, lambda0[, M2])

Calculate the full angle of divergence of a Gaussian beam.

gouy_phase(w0, lambda0, z[, z0])

Calculate the Gouy phase of a Gaussian beam.

focused_diameter(f, lambda0, d[, M2])

Diameter of diffraction-limited focused beam.

beam_parameter_product(Theta, d0[, ...])

Find the beam parameter product (BPP).

artificial_to_original(params, errors, f[, ...])

Convert artificial beam parameters to original beam parameters.

M2_fit(z, d, lambda0[, strict, z0, d0])

Return the hyperbolic fit to the supplied diameters.

M2_report(z, dx, lambda0[, dy, f, strict, ...])

Return string describing a one or more sets of beam measurements.

M2_diameter_plot(z, dx, lambda0[, dy, ...])

Plot the semi-major and semi-minor beam fits and residuals.

M2_radius_plot(z, d, lambda0[, strict, z0, d0])

Plot radii, beam fits, and asymptotes.

M2_focus_plot(w0, lambda0, f, z0[, M2])

Plot a beam from its waist through a lens to its focus.