pyMMF.IndexProfile#
- class pyMMF.IndexProfile(npoints, areaSize)[source]#
Class representing the refractive index profile of the fiber.
- Parameters:
- npointsint
The number of points in each dimension of the grid.
- areaSizefloat
The size in um of the area (let it be larger that the core size!)
- Parameters:
npoints (int)
areaSize (float)
Methods
fromFile
(filename)Load the index profile from a file.
getOptimalSolver
([curvature])Returns the optimal solver based on the index profile and curvature flag.
initFromArray
(n_array)Initializes the index profile from a numpy array.
Initializes the index profile from a radial function.
initParabolicGRIN
(n1, a, NA[, alpha])Initializes the refractive index profile for a parabolic GRIN fiber.
initStepIndex
(n1, a, NA)Initializes the step index profile.
load
(filename)Load the index profile from a file.
plot
()Plot the 2d index profile map.
save
(filename)Save the index profile to a file.
Methods
__init__
(npoints, areaSize)fromFile
(filename)Load the index profile from a file.
getOptimalSolver
([curvature])Returns the optimal solver based on the index profile and curvature flag.
initFromArray
(n_array)Initializes the index profile from a numpy array.
Initializes the index profile from a radial function.
initParabolicGRIN
(n1, a, NA[, alpha])Initializes the refractive index profile for a parabolic GRIN fiber.
initStepIndex
(n1, a, NA)Initializes the step index profile.
load
(filename)Load the index profile from a file.
plot
()Plot the 2d index profile map.
save
(filename)Save the index profile to a file.
Attributes
Number of points in each dimension of the grid
Index profile
Size in um of the area
X coordinate of the grid (2d array)
Y coordinate of the grid (2d array)
Azimuthal coordinate of the grid (2d array)
Radial coordinate of the grid (2d array)
Spatial resolution of the grid
Radial function (if initialized from a function)
Type of index profile (custom, GRIN, SI)
- R: ndarray#
Radial coordinate of the grid (2d array)
- TH: ndarray#
Azimuthal coordinate of the grid (2d array)
- X: ndarray#
X coordinate of the grid (2d array)
- Y: ndarray#
Y coordinate of the grid (2d array)
- areaSize: float#
Size in um of the area
- dh: float#
Spatial resolution of the grid
- classmethod fromFile(filename)[source]#
Load the index profile from a file.
- Parameters:
- filenamestr
The name of the file where the index profile is saved.
- Returns:
- IndexProfile
The index profile loaded from the file.
- Parameters:
filename (str)
Examples
import pyMMF filename = "index_profile.pkl" profile = pyMMF.IndexProfile.fromFile(filename)
- getOptimalSolver(curvature=False)[source]#
Returns the optimal solver based on the index profile and curvature flag.
- Parameters:
curvature (bool): Flag indicating whether curvature is considered.
- Returns:
- str: The optimal solver based on the index profile and curvature flag.
Possible values are “SI” (for self.type == “SI” and not curvature), “radial” (if self.indexProfile.radialFunc is not None), or “eig” (default).
- Parameters:
curvature (bool)
- initFromArray(n_array)[source]#
Initializes the index profile from a numpy array. Use this function to define a custom index profile.
- Parameters:
- n_arraynp.ndarray
2d array containing the index values. Each value correspond to a pixel with coordinates given by (self.X, self.Y) in the cartesian coordinate system, or (self.R, self.TH) in the polar coordinate system.
- Returns:
- None
- Parameters:
n_array (ndarray)
- Return type:
None
Examples
Square fiber index profile:
import numpy as np import pyMMF n1 = 1.45 n2 = 1.44 npoints = 64 core_size = 10 areaSize = 20 profile = pyMMF.IndexProfile(npoints=npoints, areaSize=areaSize) index_array = n2*np.ones((npoints,npoints)) mask_core = (np.abs(profile.X) < core_size/2) & (np.abs(profile.Y) < core_size/2) index_array[mask_core] = n1 profile.initFromArray(index_array)
- initFromRadialFunction(nr)[source]#
Initializes the index profile from a radial function. Use this function to define a custom axisymmetric index profile.
- Parameters:
- nrCallable[[float], float]
A callable function that takes a float argument and returns the refractive index.
- Returns:
- None
- Parameters:
nr (Callable[[float], float])
- Return type:
None
Examples
Ring core fiber index profile:
import numpy as np import pyMMF n1 = 1.445 n2 = 1.45 n3 = 1.44 a = 5 b = 10 npoints = 256 areaSize = 25 profile = pyMMF.IndexProfile(npoints=npoints, areaSize=areaSize) def radialFunc(r): if r < a: return n1 elif r < b: return n2 else: return n3 profile.initFromRadialFunction(radialFunc)
- initParabolicGRIN(n1, a, NA, alpha=2.0)[source]#
Initializes the refractive index profile for a parabolic GRIN fiber.
[ begin{eqnarray} n(r) &=& sqrt{n_1^2 left[1 - 2 (r / a)^alpha Delta n right]} quad forall , r leq a \ n(r) &=& n_2 quad forall , r > a end{eqnarray} ]
with
[ Delta n = frac{NA^2}{2 n_1^2} ]
- Parameters:
- n1float
The refractive index at the core center.
- afloat
The core radius.
- NAfloat
The numerical aperture.
- alphafloat, optional
The exponent of the parabolic profile. Default is 2.0.
- Returns:
- None
- Parameters:
n1 (float)
a (float)
NA (float)
alpha (float)
- Return type:
None
Examples
Parabolic GRIN fiber:
import pyMMF n1 = 1.45; a = 10; NA = 0.2 npoints = 64 areaSize = 20 profile = pyMMF.IndexProfile(npoints=npoints, areaSize=areaSize) profile.initParabolicGRIN(n1=n1, a=a, NA=NA)
- initStepIndex(n1, a, NA)[source]#
Initializes the step index profile.
- Parameters:
- n1float
The refractive index inside the core region.
- afloat
The core radius.
- NAfloat
The numerical aperture.
- Returns:
- None
- Parameters:
n1 (float)
a (float)
NA (float)
- Return type:
None
Examples
import pyMMF n1 = 1.45; a = 10; NA = 0.2 npoints = 256 areaSize = 20 profile = pyMMF.IndexProfile(npoints=npoints, areaSize=areaSize) profile.initStepIndex(n1=n1, a=a, NA=NA)
- load(filename)[source]#
Load the index profile from a file.
- Parameters:
- filenamestr or dict
The name of the file where the index profile is saved, or a dictionary containing the index profile data.
- Returns:
- None
- Parameters:
filename ([<class 'str'>, <class 'dict'>])
- Return type:
None
- n: ndarray#
Index profile
- npoints: int#
Number of points in each dimension of the grid
- radialFunc: Callable[[float], float]#
Radial function (if initialized from a function)
- save(filename)[source]#
Save the index profile to a file.
- Parameters:
- filenamestr
The name of the file where to save the index profile.
- Returns:
- None
- Parameters:
filename (str)
- Return type:
None
Examples
import pyMMF npoints = 256 areaSize = 20 profile = pyMMF.IndexProfile(npoints=npoints, areaSize=areaSize) ... profile.save("index_profile.pkl")
- type: str#
Type of index profile (custom, GRIN, SI)