pyMMF.Modes#

class pyMMF.Modes[source]#

Class to store the modes of a multimode fiber, typically returned by the solver

Methods

fromFile(filename)

Load the object from a file using pickle.

getCurvedModes(curvature[, npola])

Calculates the curved modes of the fiber.

getEvolutionOperator([npola, curvature])

Returns the evolution operator B of the fiber.

getModeMatrix([npola, shift, angle])

Returns the matrix containing the mode profiles.

getNearDegenerate([tol])

Find the groups of near degenerate modes with a given tolerence tol given in term of propagation constant expressed in 1/micrometer unit.

getNearDegenerateMask([tol])

Generates a mask for near-degenerate modes based on a given tolerance value in term of propagation constant expressed in 1/micrometer unit.

getPropagationMatrix(distance[, npola, ...])

Returns the transmission matrix T for a given fiber length in the basis of the fiber modes.

load(filename)

Load the object from a file using pickle.

save(filename[, save_indes_profile])

Save the object to a file using pickle.

sort([fn])

Sorts the modes based on the provided function fn.

Methods

__init__()

fromFile(filename)

Load the object from a file using pickle.

getCurvedModes(curvature[, npola])

Calculates the curved modes of the fiber.

getEvolutionOperator([npola, curvature])

Returns the evolution operator B of the fiber.

getModeMatrix([npola, shift, angle])

Returns the matrix containing the mode profiles.

getNearDegenerate([tol])

Find the groups of near degenerate modes with a given tolerence tol given in term of propagation constant expressed in 1/micrometer unit.

getNearDegenerateMask([tol])

Generates a mask for near-degenerate modes based on a given tolerance value in term of propagation constant expressed in 1/micrometer unit.

getPropagationMatrix(distance[, npola, ...])

Returns the transmission matrix T for a given fiber length in the basis of the fiber modes.

load(filename)

Load the object from a file using pickle.

save(filename[, save_indes_profile])

Save the object to a file using pickle.

sort([fn])

Sorts the modes based on the provided function fn.

classmethod fromFile(filename)[source]#

Load the object from a file using pickle.

Parameters:
filenamestr

The name of the file to load the object from.

Returns:
Modes

The object loaded from the file.

Parameters:

filename (str)

Examples

>>> modes = Modes.fromFile("modes.pkl")
getCurvedModes(curvature, npola=1)[source]#

Calculates the curved modes of the fiber.

Parameters:
curvaturefloat

The curvature of the fiber.

npolaint, optional

Number of polarizations. Default is 1.

Returns:
tuple

A tuple containing the eigenvalues (new_betas) and the transposed modes (new_modes).

getEvolutionOperator(npola=1, curvature=None)[source]#

Returns the evolution operator B of the fiber. The diagonal of the evolution operator correspond to the propagation constants. The off-diagonal terms account for the mode coupling. The transmission matrix of the fiber reads exp(iBL) with L the propagation distance. For a straight fiber, B is a diagonal matrix.

One can add the effect of curvature to a system solved for a straight fiber. It returns then the evolution operator in the basis of the straight fiber modes. The calculation is different from directly solving the system for a bent fiber [1] [2].

Parameters:
npolaint, optional

Number of polarizations. Default is 1.

curvaturefloat or None, optional

The curvature of the fiber. Default is None.

Returns:
Bnumpy.ndarray

The propagation operator.

References

getModeMatrix(npola=1, shift=None, angle=None)[source]#

Returns the matrix containing the mode profiles. Note that while you can set two polarizations, the modes profiles are obtained under a scalar apporoximation.

Parameters:
npolaint

Number of polarizations considered. For npola = 2, the mode matrix will be a block diagonal matrix.

shiftlist or None

(slow) Value of a coordinate offset, allows to return the mode matrix for a fiber with the center shifted with regard to the center of the observation window. Defaults to None.

anglefloat or None

(slow) Angle in radians, allows to rotate the mode matrix with an arbitrary angle. Note that the rotation is applied BEFORE the transverse shift. Defaults to None.

Returns:
Mnumpy.ndarray

The matrix representing the basis of the propagating modes.

getNearDegenerate(tol=0.01)[source]#

Find the groups of near degenerate modes with a given tolerence tol given in term of propagation constant expressed in 1/micrometer unit.

Parameters:
tolfloat

Tolerance value for determining near-degeneracy.

Returns:
groupsList[List[int]]

List of groups of near-degenerate modes, each represented as a list of indices.

Examples

>>> groups = getNearDegenerate(tol=1e-5)
>>> print(groups)
[[1], [2, 3], [4, 5, 6], [7, 8, 9, 10], [11, 12, 13, 14, 15]]
getNearDegenerateMask(tol=0.01)[source]#

Generates a mask for near-degenerate modes based on a given tolerance value in term of propagation constant expressed in 1/micrometer unit. It first identifies groups of near-degenerate modes using the getNearDegenerate method. Then, it creates a square matrix of size nmodes x nmodes, where nmodes is the number of modes. The elements of the matrix are initialized to zero. For each group of near-degenerate modes, the corresponding submatrix in the mask is set to one. The resulting mask is returned as a complex-valued ndarray.

Parameters:
tolfloat

Tolerance value for determining near-degeneracy.

Returns:
mask_near_degeneratendarray

Mask for near-degenerate modes.

Examples

>>> mask = getNearDegenerateMask(tol=1e-5)
getPropagationMatrix(distance, npola=1, curvature=None)[source]#

Returns the transmission matrix T for a given fiber length in the basis of the fiber modes. Note that while you can set two polarizations, the modes profiles are obtained under a scalar apporoximation. For a straight fiber, T is a diagonal matrix.

One can add the effect of curvature to a system solved for a straight fiber. It returns then the evolution operator in the basis of the straight fiber modes. The calculation is different from directly solving the system for a bent fiber [3].

If B is the evolution operator of the fiber, the transmission matrix (in the mode basis) T for a fiber length l is computed using:: T = np.exp(1j * B * l)

Parameters:
distancefloat

Size of the fiber segment (in microns).

npolaint

Number of polarizations considered. For npola = 2, the mode matrix will be a block diagonal matrix.

curvaturefloat

Curvature of the fiber segment (in microns).

Returns:
Tnumpy.ndarray

The transmission matrix of the fiber.

Notes

load(filename)[source]#

Load the object from a file using pickle.

Parameters:
filenamestr

The name of the file to load the object from.

Returns:
None
Parameters:

filename (str)

Examples

>>> modes = Modes()
>>> modes.load("modes.pkl")
save(filename, save_indes_profile=False)[source]#

Save the object to a file using pickle.

Parameters:
filenamestr

The name of the file to save the object to.

save_indes_profilebool, optional

If True, the index profile will be saved. Default is False.

Returns:
None
Parameters:

filename (str)

Examples

>>> modes = Modes()
>>> ...
>>> modes.save("modes.pkl")
sort(fn=None)[source]#

Sorts the modes based on the provided function fn. If none provided, sort by the values of self.betas in descending order.

Rearranges the elements of self.betas and other associated lists (such as self.u, self.w, self.m, self.l, self.profiles, self.modesList, and self.data) based on the sorted order of self.betas in descending order. Data is sorted in place.

Parameters:
fnfunction or None, optional

The function used to sort the modes. Default is None.

Returns:
idx: list

The indices of the sorted modes, in case the user wants to keep track of the sorting order.

Examples

>>> # sort the modes based on the imaginary part of the propagation constant
>>> modes.sort()
>>> # sort the modes by inscreasing order of m, and for the same m, by increasing order of l
>>> idx = modes.sort(lambda x: x.m + np.sign(x.m) * 1e-2 * x.l)