Making useless (but beautiful) gifs with fiber modes

Social media like (too) short content like pictures or quotes, but above all, people love gifs (probably way too much). Publish a link to a few pages long post you wrote about a paper, a physical concept, or a piece of code, and a few people will like your tweet/post. Publish a gif, and the number of people you will reach will increase dramatically. Is it a good thing? Well, that depends on what you do with it. I try to use gifs to draw attention to more in-depth content that I hope some people will read. Let's make one together.

What we will do is something like this gif I posted on Twitter.

 

It represents the spatial profile of some modes of a multimode fiber when we introduce a bending in one direction. The value it the top left corner is the curvature. The details about the effect of curvature on multimode fibers are presented here and some numerical tests here.

First, we will need the pyMMF module to calculate the mode of multimode fibers, you can find it on our GitHub account: PyMMF.

Once installed, we import the required modules and define the fiber parameters. We will estimate the modes for 10 values of the curvature between 10 mm and 1mm. 1mm is a strong bending, I am not sure the approximations we did in the calculation still stand, but because it is just to get a nice visual, let's not worry about that.

 

import matplotlib.pyplot as plt
import numpy as np
import pyMMF

'''fiber settings'''
a = 5.# radius in um
areaSizeFactor = 2.8 # size of the window, in unit of radius
NA = 0.22 # numerical aperture
n1 = 1.45
npoints = 2**7 # resolution of the window (in each direction)
wl = 0.6328 # wavelength (in um)
poisson = 0.17 # Poisson coefficient of the fiber core material
N_curvature = 10
curvature_min = 1e3
curvature_max = 1e4
# curvature_vec = 1./np.linspace(1./curvature_max,1./curvature_min,N_curvature)
curvature_vec = np.linspace(curvature_max,curvature_min,N_curvature)

 

Now we use pyMMF to estimate the modes of the straight fiber. We create the profile for a step-index fiber and feed it to our solver. Note that we need the Poisson coefficient to estimate the response of the material. We then instantiate the solver and run it to find the modes.

 

# Create the fiber
areaSize = areaSizeFactor*a

# Create the fiber object
profile = pyMMF.IndexProfile(npoints = npoints, areaSize = areaSize)

# Initialize the index profile
profile.initStepIndex(n1=n1,a=a,NA=NA)

# Instantiate the solver
solver = pyMMF.propagationModeSolver()

# Set the profile to the solver
solver.setIndexProfile(profile)

# Set the wavelength
solver.setWL(wl)

# Set the Poisson coefficient
solver.setPoisson(poisson)

# Estimate the number of modes for a graded index fiber
Nmodes_estim = pyMMF.estimateNumModesSI(wl,a,NA,pola=1)

# We find a bit more modes to be safe
Nmodes_max = Nmodes_estim+10

# Find the modes of the straight fiber
modes = solver.solve(
    nmodesMax=Nmodes_max,
    boundary = 'close',
    mode = 'SI'
)

M0_straight = modes.getModeMatrix()

 

Under some approximation, we can estimate the effect of bending from the modes of the straight fiber, without having to calculate everything again. It is faster, and again, we do not need scientific accuracy to make a gif. We introduce the bending in one direction (x), on the other direction (y), we set a large value for the curvature (1e8) corresponding to basically no bending in this direction.

 

# TMs = [get_TM(c) for c in curvature_vec]
def get_modes_curv(c):
    _,M0_bent = modes.getCurvedModes(curvature=[c,1e8])
    return M0_bent
M0_bent_vec = [get_modes_curv(c) for c in curvature_vec]  

 

Now we just have to choose which modes to display and create the figures. We save them as png files.

 

modes_to_record = [0,4,9,11,28]

for m in modes_to_record:
    for c,M in  zip(curvature_vec,M0_bent_vec[:-1]):
        plt.figure()
        plt.imshow(
            np.abs(M[:,m].reshape([npoints]*2)),
            aspect='equal',
            interpolation = 'None',
            cmap=plt.cm.gray)
        plt.text(5, 12, rf'$r={c/1e3:.0f} mm$', fontsize=20, color = 'white') 
        plt.axis('off')
        plt.savefig(f"mode_{m}_{c}.png")

 

Now you have your images! You just have to create a gif animation from them. There are many ways and pieces of software to do it. Personally, I use Gimp because I already have it and it handles gifs very well. If you do not know about Gimp, it is a great free open-source replacement for Adobe Photoshop. To make gifs, you can follow these good tutorials (1 and 2).

A full Jupyter notebook file is available on our GitHub account here.



Created by sebastien.popoff on 14/07/2020