laserbeamsize


Namelaserbeamsize JSON
Version 2.0.4 PyPI version JSON
download
home_pagehttps://github.com/scottprahl/laserbeamsize
SummaryISO 11146 Calculation of Laser Beam Center, Diameter, and M²
upload_time2023-10-24 16:31:21
maintainer
docs_urlNone
authorScott Prahl
requires_python>=3.5
licenseMIT
keywords variance gaussian m-squared d4sigma m2 spotsize laser beam is011146 divergence beam waist tem00 beam diameter beam parameter product bpp
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            laserbeamsize
=============

by Scott Prahl

.. image:: https://img.shields.io/pypi/v/laserbeamsize?color=68CA66
   :target: https://pypi.org/project/laserbeamsize/
   :alt: pypi

.. image:: https://img.shields.io/github/v/tag/scottprahl/laserbeamsize?label=github&color=68CA66
   :target: https://github.com/scottprahl/laserbeamsize
   :alt: github

.. image:: https://img.shields.io/conda/vn/conda-forge/laserbeamsize?label=conda&color=68CA66
   :target: https://github.com/conda-forge/laserbeamsize-feedstock
   :alt: conda

.. image:: https://zenodo.org/badge/107437651.svg
   :target: https://zenodo.org/badge/latestdoi/107437651
   :alt: zenodo

|

.. image:: https://img.shields.io/github/license/scottprahl/laserbeamsize?color=68CA66
   :target: https://github.com/scottprahl/laserbeamsize/blob/master/LICENSE.txt
   :alt: License

.. image:: https://github.com/scottprahl/laserbeamsize/actions/workflows/test.yaml/badge.svg
   :target: https://github.com/scottprahl/laserbeamsize/actions/workflows/test.yaml
   :alt: testing

.. image:: https://readthedocs.org/projects/laserbeamsize/badge?color=68CA66
  :target: https://laserbeamsize.readthedocs.io
  :alt: docs

.. image:: https://img.shields.io/pypi/dm/laserbeamsize?color=68CA66
   :target: https://pypi.org/project/laserbeamsize/
   :alt: Downloads

__________

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.

This module also supports M² calculations based on a series of images
collected at various distances from the focused beam. 

Extensive documentation can be found at <https://laserbeamsize.readthedocs.io>

Installation
------------

Use ``pip``::
    
    pip install --user laserbeamsize

or ``conda``::

    conda install -c conda-forge laserbeamsize


or use immediately by clicking the Google Colaboratory button below

.. image:: https://colab.research.google.com/assets/colab-badge.svg
  :target: https://colab.research.google.com/github/scottprahl/laserbeamsize/blob/master
  :alt: Colab

Determining the beam size in an image
-------------------------------------

Finding the center and dimensions of a good beam image::

    import imageio.v3 as iio
    import laserbeamsize as lbs
    
    file = "https://github.com/scottprahl/laserbeamsize/raw/master/docs/t-hene.pgm"
    image = iio.imread(file)
    
    x, y, dx, dy, phi = lbs.beam_size(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))

to produce::

    The center of the beam ellipse is at (651, 492)
    The ellipse diameter (closest to horizontal) is 369 pixels
    The ellipse diameter (closest to   vertical) is 347 pixels
    The ellipse is rotated -12° ccw from the horizontal

A visual report can be done with one function call::

    lbs.plot_image_analysis(beam)
    plt.show()
    
produces something like

.. image:: https://raw.githubusercontent.com/scottprahl/laserbeamsize/master/docs/hene-report.png
   :alt: HeNe report

or::

    lbs.plot_image_analysis(beam, r"Original Image $\lambda$=4µm beam", pixel_size = 12, units='µm')
    plt.show()

produces something like

.. image:: https://raw.githubusercontent.com/scottprahl/laserbeamsize/master/docs/astigmatic-report.png
   :alt: astigmatic report

Non-gaussian beams work too::

    # 12-bit pixel image stored as high-order bits in 16-bit values
    tem02 = imageio.imread("TEM02_100mm.pgm") >> 4
    lbs.plot_image_analysis(tem02, title = r"TEM$_{02}$ at z=100mm", pixel_size=3.75)
    plt.show()

produces

.. image:: https://raw.githubusercontent.com/scottprahl/laserbeamsize/master/docs/tem02.png
   :alt: TEM02

Determining M² 
--------------

Determining M² for a laser beam is also straightforward.  Just collect beam diameters from
five beam locations within one Rayleigh distance of the focus and from five locations more
than two Rayleigh distances::

    lambda1=308e-9 # meters
    z1_all=np.array([-200,-180,-160,-140,-120,-100,-80,-60,-40,-20,0,20,40,60,80,99,120,140,160,180,200])*1e-3
    d1_all=2*np.array([416,384,366,311,279,245,216,176,151,120,101,93,102,120,147,177,217,256,291,316,348])*1e-6
    lbs.M2_radius_plot(z1_all, d1_all, lambda1, strict=True)
    plt.show()

produces

.. image:: https://raw.githubusercontent.com/scottprahl/laserbeamsize/master/docs/m2fit.png
   :alt: fit for M2

Here is an analysis of a set of images that do not meet the ISO 11146
requirements for determining M² (because the image locations are not taken
in right locations relative to the focus).  These beam images are from a HeNe
laser with slightly misaligned mirrors to primarily lase in a TEM₀₁ transverse mode.
The laser resonator had a fixed rotation of 38.7° from the plane of
the optical table.::

    lambda0 = 632.8e-9 # meters
    z10 = np.array([247,251,259,266,281,292])*1e-3 # meters
    filenames = ["sb_%.0fmm_10.pgm" % (number*1e3) for number in z10]

    # the 12-bit pixel images are stored in high-order bits in 16-bit values
    tem10 = [imageio.imread(name)>>4 for name in filenames]

    # remove top to eliminate artifact 
    for i in range(len(z10)):
        tem10[i] = tem10[i][200:,:]

    # find beam rotated by 38.7° in all images
    fixed_rotation = np.radians(38.7)
    options = {'pixel_size': 3.75, 'units': "µm", 'crop': [1400,1400], 'z':z10, 'phi':fixed_rotation}
    dy, dx= lbs.beam_size_montage(tem10, **options)  # dy and dx in microns
    plt.show()

produces

.. image:: https://raw.githubusercontent.com/scottprahl/laserbeamsize/master/docs/sbmontage.png
   :alt: montage of laser images

Here is one way to plot the fit using the above diameters::

    lbs.M2_diameter_plot(z10, dx*1e-6, lambda0, dy=dy*1e-6)
    plt.show()

In the graph on the below right, the dashed line shows the expected divergence
of a pure gaussian beam.  Since real beams should diverge faster than this (not slower)
there is some problem with the measurements (too few!).  On the other hand, the M² value 
the semi-major axis 2.6±0.7 is consistent with the expected value of 3 for the TEM₁₀ mode.

.. image:: https://raw.githubusercontent.com/scottprahl/laserbeamsize/master/docs/sbfit.png
   :alt: fit


License
-------

``laserbeamsize`` is licensed under the terms of the MIT license.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/scottprahl/laserbeamsize",
    "name": "laserbeamsize",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.5",
    "maintainer_email": "",
    "keywords": "variance,gaussian,M-squared,d4sigma,M2,M\u00b2,spotsize,laser beam,IS011146,divergence,beam waist,TEM00,beam diameter,beam parameter product,BPP",
    "author": "Scott Prahl",
    "author_email": "scott.prahl@oit.edu",
    "download_url": "https://files.pythonhosted.org/packages/22/fa/970bc0780598d36b15bbd3dfe4a4864ce982b85984acec6ad52e01e395df/laserbeamsize-2.0.4.tar.gz",
    "platform": null,
    "description": "laserbeamsize\n=============\n\nby Scott Prahl\n\n.. image:: https://img.shields.io/pypi/v/laserbeamsize?color=68CA66\n   :target: https://pypi.org/project/laserbeamsize/\n   :alt: pypi\n\n.. image:: https://img.shields.io/github/v/tag/scottprahl/laserbeamsize?label=github&color=68CA66\n   :target: https://github.com/scottprahl/laserbeamsize\n   :alt: github\n\n.. image:: https://img.shields.io/conda/vn/conda-forge/laserbeamsize?label=conda&color=68CA66\n   :target: https://github.com/conda-forge/laserbeamsize-feedstock\n   :alt: conda\n\n.. image:: https://zenodo.org/badge/107437651.svg\n   :target: https://zenodo.org/badge/latestdoi/107437651\n   :alt: zenodo\n\n|\n\n.. image:: https://img.shields.io/github/license/scottprahl/laserbeamsize?color=68CA66\n   :target: https://github.com/scottprahl/laserbeamsize/blob/master/LICENSE.txt\n   :alt: License\n\n.. image:: https://github.com/scottprahl/laserbeamsize/actions/workflows/test.yaml/badge.svg\n   :target: https://github.com/scottprahl/laserbeamsize/actions/workflows/test.yaml\n   :alt: testing\n\n.. image:: https://readthedocs.org/projects/laserbeamsize/badge?color=68CA66\n  :target: https://laserbeamsize.readthedocs.io\n  :alt: docs\n\n.. image:: https://img.shields.io/pypi/dm/laserbeamsize?color=68CA66\n   :target: https://pypi.org/project/laserbeamsize/\n   :alt: Downloads\n\n__________\n\nSimple and fast calculation of beam sizes from a single monochrome image based\non the ISO 11146 method of variances.  Some effort has been made to make the \nalgorithm less sensitive to background offset and noise.\n\nThis module also supports M\u00b2 calculations based on a series of images\ncollected at various distances from the focused beam. \n\nExtensive documentation can be found at <https://laserbeamsize.readthedocs.io>\n\nInstallation\n------------\n\nUse ``pip``::\n    \n    pip install --user laserbeamsize\n\nor ``conda``::\n\n    conda install -c conda-forge laserbeamsize\n\n\nor use immediately by clicking the Google Colaboratory button below\n\n.. image:: https://colab.research.google.com/assets/colab-badge.svg\n  :target: https://colab.research.google.com/github/scottprahl/laserbeamsize/blob/master\n  :alt: Colab\n\nDetermining the beam size in an image\n-------------------------------------\n\nFinding the center and dimensions of a good beam image::\n\n    import imageio.v3 as iio\n    import laserbeamsize as lbs\n    \n    file = \"https://github.com/scottprahl/laserbeamsize/raw/master/docs/t-hene.pgm\"\n    image = iio.imread(file)\n    \n    x, y, dx, dy, phi = lbs.beam_size(image)\n    print(\"The center of the beam ellipse is at (%.0f, %.0f)\" % (x, y))\n    print(\"The ellipse diameter (closest to horizontal) is %.0f pixels\" % dx)\n    print(\"The ellipse diameter (closest to   vertical) is %.0f pixels\" % dy)\n    print(\"The ellipse is rotated %.0f\u00b0 ccw from the horizontal\" % (phi * 180/3.1416))\n\nto produce::\n\n    The center of the beam ellipse is at (651, 492)\n    The ellipse diameter (closest to horizontal) is 369 pixels\n    The ellipse diameter (closest to   vertical) is 347 pixels\n    The ellipse is rotated -12\u00b0 ccw from the horizontal\n\nA visual report can be done with one function call::\n\n    lbs.plot_image_analysis(beam)\n    plt.show()\n    \nproduces something like\n\n.. image:: https://raw.githubusercontent.com/scottprahl/laserbeamsize/master/docs/hene-report.png\n   :alt: HeNe report\n\nor::\n\n    lbs.plot_image_analysis(beam, r\"Original Image $\\lambda$=4\u00b5m beam\", pixel_size = 12, units='\u00b5m')\n    plt.show()\n\nproduces something like\n\n.. image:: https://raw.githubusercontent.com/scottprahl/laserbeamsize/master/docs/astigmatic-report.png\n   :alt: astigmatic report\n\nNon-gaussian beams work too::\n\n    # 12-bit pixel image stored as high-order bits in 16-bit values\n    tem02 = imageio.imread(\"TEM02_100mm.pgm\") >> 4\n    lbs.plot_image_analysis(tem02, title = r\"TEM$_{02}$ at z=100mm\", pixel_size=3.75)\n    plt.show()\n\nproduces\n\n.. image:: https://raw.githubusercontent.com/scottprahl/laserbeamsize/master/docs/tem02.png\n   :alt: TEM02\n\nDetermining M\u00b2 \n--------------\n\nDetermining M\u00b2 for a laser beam is also straightforward.  Just collect beam diameters from\nfive beam locations within one Rayleigh distance of the focus and from five locations more\nthan two Rayleigh distances::\n\n    lambda1=308e-9 # meters\n    z1_all=np.array([-200,-180,-160,-140,-120,-100,-80,-60,-40,-20,0,20,40,60,80,99,120,140,160,180,200])*1e-3\n    d1_all=2*np.array([416,384,366,311,279,245,216,176,151,120,101,93,102,120,147,177,217,256,291,316,348])*1e-6\n    lbs.M2_radius_plot(z1_all, d1_all, lambda1, strict=True)\n    plt.show()\n\nproduces\n\n.. image:: https://raw.githubusercontent.com/scottprahl/laserbeamsize/master/docs/m2fit.png\n   :alt: fit for M2\n\nHere is an analysis of a set of images that do not meet the ISO 11146\nrequirements for determining M\u00b2 (because the image locations are not taken\nin right locations relative to the focus).  These beam images are from a HeNe\nlaser with slightly misaligned mirrors to primarily lase in a TEM\u2080\u2081 transverse mode.\nThe laser resonator had a fixed rotation of 38.7\u00b0 from the plane of\nthe optical table.::\n\n    lambda0 = 632.8e-9 # meters\n    z10 = np.array([247,251,259,266,281,292])*1e-3 # meters\n    filenames = [\"sb_%.0fmm_10.pgm\" % (number*1e3) for number in z10]\n\n    # the 12-bit pixel images are stored in high-order bits in 16-bit values\n    tem10 = [imageio.imread(name)>>4 for name in filenames]\n\n    # remove top to eliminate artifact \n    for i in range(len(z10)):\n        tem10[i] = tem10[i][200:,:]\n\n    # find beam rotated by 38.7\u00b0 in all images\n    fixed_rotation = np.radians(38.7)\n    options = {'pixel_size': 3.75, 'units': \"\u00b5m\", 'crop': [1400,1400], 'z':z10, 'phi':fixed_rotation}\n    dy, dx= lbs.beam_size_montage(tem10, **options)  # dy and dx in microns\n    plt.show()\n\nproduces\n\n.. image:: https://raw.githubusercontent.com/scottprahl/laserbeamsize/master/docs/sbmontage.png\n   :alt: montage of laser images\n\nHere is one way to plot the fit using the above diameters::\n\n    lbs.M2_diameter_plot(z10, dx*1e-6, lambda0, dy=dy*1e-6)\n    plt.show()\n\nIn the graph on the below right, the dashed line shows the expected divergence\nof a pure gaussian beam.  Since real beams should diverge faster than this (not slower)\nthere is some problem with the measurements (too few!).  On the other hand, the M\u00b2 value \nthe semi-major axis 2.6\u00b10.7 is consistent with the expected value of 3 for the TEM\u2081\u2080 mode.\n\n.. image:: https://raw.githubusercontent.com/scottprahl/laserbeamsize/master/docs/sbfit.png\n   :alt: fit\n\n\nLicense\n-------\n\n``laserbeamsize`` is licensed under the terms of the MIT license.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "ISO 11146 Calculation of Laser Beam Center, Diameter, and M\u00b2",
    "version": "2.0.4",
    "project_urls": {
        "Homepage": "https://github.com/scottprahl/laserbeamsize"
    },
    "split_keywords": [
        "variance",
        "gaussian",
        "m-squared",
        "d4sigma",
        "m2",
        "m\u00b2",
        "spotsize",
        "laser beam",
        "is011146",
        "divergence",
        "beam waist",
        "tem00",
        "beam diameter",
        "beam parameter product",
        "bpp"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d48b1a7715c0e3a0ab51fa7dd4773bdd8ecb7a93f51def0fc42f2c94e432c148",
                "md5": "291d743a06cd5b8a0590d4e377814b22",
                "sha256": "2c32d0f739a1cab55aefa4d59d859e38a87a43526c0ecb78097fc16db0fbaf17"
            },
            "downloads": -1,
            "filename": "laserbeamsize-2.0.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "291d743a06cd5b8a0590d4e377814b22",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.5",
            "size": 34759,
            "upload_time": "2023-10-24T16:31:20",
            "upload_time_iso_8601": "2023-10-24T16:31:20.082737Z",
            "url": "https://files.pythonhosted.org/packages/d4/8b/1a7715c0e3a0ab51fa7dd4773bdd8ecb7a93f51def0fc42f2c94e432c148/laserbeamsize-2.0.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "22fa970bc0780598d36b15bbd3dfe4a4864ce982b85984acec6ad52e01e395df",
                "md5": "b027ae7b4e1aebeb567041b6bf71155b",
                "sha256": "549ecbf2591f7d636b4db99200b47dbac54c53c80324ebfdaece23d133c4f37c"
            },
            "downloads": -1,
            "filename": "laserbeamsize-2.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "b027ae7b4e1aebeb567041b6bf71155b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.5",
            "size": 41789,
            "upload_time": "2023-10-24T16:31:21",
            "upload_time_iso_8601": "2023-10-24T16:31:21.993379Z",
            "url": "https://files.pythonhosted.org/packages/22/fa/970bc0780598d36b15bbd3dfe4a4864ce982b85984acec6ad52e01e395df/laserbeamsize-2.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-24 16:31:21",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "scottprahl",
    "github_project": "laserbeamsize",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "laserbeamsize"
}
        
Elapsed time: 0.13976s