Developer ToolsFree generatorPDF, Excel, Word exportPhotonics and Optics

Gaussian Beam Spot Size and Rayleigh Range Python Script Generator

This generator writes a short Python script that turns your laser wavelength, beam quality, focal length and input beam size into a focused spot size, Rayleigh range, depth of focus, peak intensity and pulse fluence. You can paste it into any Python 3 environment, change the inputs and rerun it for process tuning.

Fill in

Laser wavelength in nanometers

1.0 is a perfect Gaussian beam

Focusing lens or scan lens focal length

Diameter at the 1/e squared intensity points

Use 0 for a continuous wave laser

Generated code
Download:

gaussian_focus.py

import math

# Inputs
wavelength_m = 1064 * 1e-9
m2 = 1.3
focal_m = 160 * 1e-3
beam_d_m = 8 * 1e-3
power_w = 50
rep_khz = 100

# Input beam radius (1/e^2) at the lens
w_in = beam_d_m / 2.0

# Focused waist radius (far-field approximation, lens at the beam waist)
w0 = m2 * wavelength_m * focal_m / (math.pi * w_in)

# Rayleigh range and depth of focus (2 x Rayleigh range)
z_r = math.pi * w0 ** 2 / (m2 * wavelength_m)
dof = 2.0 * z_r

# Far-field half-angle divergence in the focused beam
theta = m2 * wavelength_m / (math.pi * w0)

# Peak intensity of a CW Gaussian beam: 2P / (pi w0^2)
peak_intensity = 2.0 * power_w / (math.pi * w0 ** 2)

print('Focused spot diameter (1/e^2): %.1f um' % (2 * w0 * 1e6))
print('Rayleigh range: %.2f mm' % (z_r * 1e3))
print('Depth of focus (2 x zR): %.2f mm' % (dof * 1e3))
print('Divergence half-angle: %.2f mrad' % (theta * 1e3))
print('Peak intensity (CW): %.3e W/cm^2' % (peak_intensity / 1e4))

if rep_khz > 0:
    pulse_energy_j = power_w / (rep_khz * 1e3)
    fluence_j_cm2 = 2.0 * pulse_energy_j / (math.pi * w0 ** 2) / 1e4
    print('Pulse energy: %.1f uJ' % (pulse_energy_j * 1e6))
    print('Peak fluence per pulse: %.2f J/cm^2' % fluence_j_cm2)

Uses the standard Gaussian beam focusing relation w0 = M2 x lambda x f / (pi x w_in), valid when the input beam is collimated and the lens is not aberration limited. Strongly focused or truncated beams, large scan angles and thick optics need a full ray trace or measured spot data. Verify with a beam profiler per ISO 11146.

Process data to ERP review

Want laser process parameters linked to lots and yield in your ERP? Describe your setup and we will suggest an approach. Optional.

Optional. The tool and every export work without this. No spam.

How to use it

Fill in the six fields, copy the generated code, and run it with Python 3. The only import is the standard math library, so it runs anywhere. Enter the beam diameter at the 1/e squared points, not the full width at half maximum, since the formulas assume 1/e squared radius. For a CW laser set repetition rate to zero and the fluence lines are skipped. Edit the numbers to explore what-if cases such as a different lens.

  • Use the 1/e squared diameter at the lens
  • Enter M-squared from the laser datasheet or beam profiler
  • Set repetition rate to 0 for CW lasers
  • Compare results against a measured burn or profiler image

The formulas

For a collimated Gaussian beam of radius w_in on a lens of focal length f, the focused waist is w0 = M2 x lambda x f / (pi x w_in). The Rayleigh range is zR = pi x w0 squared / (M2 x lambda), the distance over which the beam area doubles, and the depth of focus is commonly taken as twice that. Peak intensity for a CW beam is 2P / (pi x w0 squared). Pulse fluence uses the pulse energy P / f_rep in place of power.

Worked example

A 1064 nm laser with M-squared of 1.3, an 8 mm input beam and a 160 mm lens gives a waist radius of about 22 micrometers, so a spot diameter near 44 micrometers. The Rayleigh range is about 1.4 mm and the depth of focus about 2.8 mm. Doubling the input beam diameter halves the spot, but the Rayleigh range falls with the square of the waist, so the depth of focus shrinks to about a quarter. That is the core trade-off in laser processing.

Common mistakes

People often enter the full-width half-maximum beam diameter and get a spot that is too small. Another error is applying the formula to a beam clipped by an aperture, which adds diffraction rings and enlarges the spot. Scan lenses and f-theta optics add aberrations at the edge of the field. Finally, the formulas give an idealised spot, so real thresholds, such as ablation fluence, should be confirmed on sample material.

Frequently Asked Questions

What is the Rayleigh range?

It is the distance from the beam waist over which a Gaussian beam radius grows by a factor of the square root of two, so the beam area doubles. It is calculated as pi x w0 squared divided by M-squared times wavelength, and twice that value is a common definition of depth of focus.

Does a better M-squared always give a smaller spot?

For the same wavelength, lens and input beam size, a lower M-squared gives a proportionally smaller waist and a longer Rayleigh range relative to it. A perfect Gaussian beam has M-squared of 1, and real lasers range from about 1.05 for good single-mode systems to 20 or more for multimode ones.

Why does the script ask for the 1/e squared diameter?

The Gaussian beam formulas are defined using the radius where intensity falls to 1/e squared, about 13.5 percent of peak. Using other width definitions, such as FWHM or D4 sigma without conversion, changes the result, so check which one your datasheet or profiler reports.

Can I use this for a fiber-delivered beam?

Yes, if you enter the collimated beam diameter after the collimator and the beam quality of the fiber output. For multimode process fibers the spot is closer to the fiber core image scaled by the focal length ratio, so use the imaging relation instead for those.

If your laser process parameters and results are logged in an MES or ERP, we can help build a private assistant that links spot size and fluence to yield and scrap data. Get in touch to see how that could work for you.