{"id":179,"date":"2024-09-07T21:04:35","date_gmt":"2024-09-07T20:04:35","guid":{"rendered":"https:\/\/blogs.kent.ac.uk\/photonsforlife\/?p=179"},"modified":"2026-01-02T21:11:27","modified_gmt":"2026-01-02T21:11:27","slug":"lp-modes-in-python","status":"publish","type":"post","link":"https:\/\/blogs.kent.ac.uk\/photonsforlife\/2024\/09\/07\/lp-modes-in-python\/","title":{"rendered":"LP Modes in Python"},"content":{"rendered":"<p>A few years back I uploaded a collection of <a href=\"https:\/\/uk.mathworks.com\/matlabcentral\/fileexchange\/77497-fibre-mode-solver-and-simulator\">Matlab scripts to MathWorks<\/a> that allowed for solving LP modes for step-index fibres. For those who aren\u2019t overly familiar with this, it essentially involves solving Maxwell\u2019s equations to tell you the allowed electric field distributions within the fibre. Each allowed distribution is called a \u2018mode\u2019, with the number of available modes ranging from 1 for small diameter \u2018single mode\u2019 fibres to many thousands in larger diameter \u2018multimode\u2019 fibres. If we couple coherent light into a fibre, the pattern of light exiting the other end is some coherent combination of these modes, and usually ends up looking like a random speckle pattern whenever the fibre supports more than a few modes.<\/p>\n<p>While solving the general problem is quite hard, for reasonably low numerical aperture fibres there is a well-known simplification that reduces the problem to finding solutions of a single \u2018characteristic\u2019 equation. This is all very well-known, the Matlab code doesn\u2019t do anything novel, but it provided a convenient implementation (or at least convenient for what I wanted to do at the time).<\/p>\n<p>While the Matlab code worked well enough, I\u2019ve long since switched to using Python, and as I had a need to do some modelling that needed LP mode solutions, I decided to port the code. I could have done something quickly (or found someone else\u2019s code) but since I was still getting a trickle of monthly downloads for the Matlab code (and over 1000 in total) I decided to do a proper job and make a public package in the hope that others might find it useful.<\/p>\n<p>So, here it is: LPModes is available on GitHub, <a href=\"https:\/\/github.com\/MikeHughesKent\/lpmodes\">https:\/\/github.com\/MikeHughesKent\/lpmodes<\/a>, or by<\/p>\n<pre>pip install lpmodes<\/pre>\n<p>and the documentation is on readthedocs: <a href=\"https:\/\/lpmodes.readthedocs.io\/en\/latest\/\">https:\/\/lpmodes.readthedocs.io\/en\/latest\/<\/a><\/p>\n<p>I think the Python package is actually a lot better than the Matlab original, it includes a GUI and some additional functionality around propagating electric fields along a length of fibre. You can calculate the parameters of each mode, and plot its amplitude and intensity. You can also simulate coupling of arbitrary beams (E-fields), calculating the resulting power in each mode, and the total coupled power, and plot the amplitude, phase and intensity distributions at entry or after propagation of any distance along the fibre.<\/p>\n<p>It would be interesting to see if there are more potential users, how many still prefer Matlab for this kind of work?<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-181\" src=\"http:\/\/blogs.kent.ac.uk\/photonsforlife\/files\/2026\/01\/lp_modes_gui.png\" alt=\"Screenshot of GUI\" width=\"1219\" height=\"857\" \/><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A few years back I uploaded a collection of Matlab scripts to MathWorks that allowed for solving LP modes for step-index fibres. For those who &hellip; <a href=\"https:\/\/blogs.kent.ac.uk\/photonsforlife\/2024\/09\/07\/lp-modes-in-python\/\">Read&nbsp;more<\/a><\/p>\n","protected":false},"author":50306,"featured_media":180,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[44],"tags":[314198,314200,16560],"_links":{"self":[{"href":"https:\/\/blogs.kent.ac.uk\/photonsforlife\/wp-json\/wp\/v2\/posts\/179"}],"collection":[{"href":"https:\/\/blogs.kent.ac.uk\/photonsforlife\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.kent.ac.uk\/photonsforlife\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.kent.ac.uk\/photonsforlife\/wp-json\/wp\/v2\/users\/50306"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.kent.ac.uk\/photonsforlife\/wp-json\/wp\/v2\/comments?post=179"}],"version-history":[{"count":2,"href":"https:\/\/blogs.kent.ac.uk\/photonsforlife\/wp-json\/wp\/v2\/posts\/179\/revisions"}],"predecessor-version":[{"id":183,"href":"https:\/\/blogs.kent.ac.uk\/photonsforlife\/wp-json\/wp\/v2\/posts\/179\/revisions\/183"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.kent.ac.uk\/photonsforlife\/wp-json\/wp\/v2\/media\/180"}],"wp:attachment":[{"href":"https:\/\/blogs.kent.ac.uk\/photonsforlife\/wp-json\/wp\/v2\/media?parent=179"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.kent.ac.uk\/photonsforlife\/wp-json\/wp\/v2\/categories?post=179"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.kent.ac.uk\/photonsforlife\/wp-json\/wp\/v2\/tags?post=179"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}