Utilities¶
utils ¶
rotated_mode ¶
rotated_mode(func)
Decorator that adds an angle keyword argument to a mode-generating
method, rotating the mode analytically by temporarily rotating the
beam's coordinate grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
callable
|
A method with signature |
required |
Returns:
| Type | Description |
|---|---|
callable
|
A wrapped version of |
Source code in structured_optics\utils.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
herm ¶
herm(X, N)
Evaluate the physicists' Hermite polynomial of order N.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array_like
|
Points at which to evaluate the polynomial. |
required |
N
|
int
|
Polynomial order. |
required |
Returns:
| Type | Description |
|---|---|
array_like
|
|
Source code in structured_optics\utils.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
laguerre ¶
laguerre(X, L, P)
Evaluate the generalized (associated) Laguerre polynomial.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
array_like
|
Points at which to evaluate the polynomial. |
required |
L
|
int
|
Passed as the |
required |
P
|
int
|
Passed as the degree |
required |
Returns:
| Type | Description |
|---|---|
array_like
|
|
Source code in structured_optics\utils.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
even_coeffs ¶
even_coeffs(p, q, kind)
Compute the eigenvalues and coefficient vectors of even Ince
polynomials of order p (i.e. C_p^m for kind 'C', or the even-p
'S' family), by solving the tridiagonal-like recurrence relation as
an eigenvalue problem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
int
|
Ince polynomial order. Must be even. |
required |
q
|
float
|
Ellipticity parameter of the Ince equation. |
required |
kind
|
(C, S)
|
Which family of Ince polynomials to build the recurrence matrix for ('C' for cosine-type, 'S' for sine-type). |
'C'
|
Returns:
| Name | Type | Description |
|---|---|---|
eigvals_sorted |
ndarray
|
Eigenvalues, sorted in ascending order (for kind 'S', the zero eigenvalue -- corresponding to the trivial/degenerate solution -- is kept first, followed by the remaining eigenvalues sorted ascending). |
eigvecs_sorted |
ndarray
|
Matrix whose columns are the coefficient vectors |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in structured_optics\utils.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |
odd_coeffs ¶
odd_coeffs(p, q, kind)
Compute the eigenvalues and coefficient vectors of odd Ince
polynomials of order p (i.e. C_p^m/S_p^m for odd p), by
solving the corresponding recurrence relation as an eigenvalue
problem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
int
|
Ince polynomial order. Must be odd. |
required |
q
|
float
|
Ellipticity parameter of the Ince equation. |
required |
kind
|
(C, S)
|
Which family of Ince polynomials to build the recurrence matrix for ('C' for cosine-type, 'S' for sine-type). |
'C'
|
Returns:
| Name | Type | Description |
|---|---|---|
eigvals_sorted |
ndarray
|
Eigenvalues, sorted in ascending order. |
eigvecs_sorted |
ndarray
|
Matrix whose columns are the coefficient vectors corresponding to each sorted eigenvalue, normalized so that the sum of each column's coefficients is positive. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in structured_optics\utils.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
C_ince ¶
C_ince(xi, p, m, q)
Evaluate the even (cosine-type) Ince polynomial C_p^m(xi, q).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xi
|
array_like
|
Points at which to evaluate the polynomial. |
required |
p
|
int
|
Ince polynomial order (p >= 0). |
required |
m
|
int
|
Ince polynomial degree (0 <= m <= p), with |
required |
q
|
float
|
Ellipticity parameter of the Ince equation. |
required |
Returns:
| Type | Description |
|---|---|
array_like
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in structured_optics\utils.py
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 | |
S_ince ¶
S_ince(xi, p, m, q)
Evaluate the odd (sine-type) Ince polynomial S_p^m(xi, q).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xi
|
array_like
|
Points at which to evaluate the polynomial. |
required |
p
|
int
|
Ince polynomial order (p >= 0). |
required |
m
|
int
|
Ince polynomial degree (0 <= m <= p), with |
required |
q
|
float
|
Ellipticity parameter of the Ince equation. |
required |
Returns:
| Type | Description |
|---|---|
array_like
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in structured_optics\utils.py
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 | |
cartesian_to_elliptic ¶
cartesian_to_elliptic(x, y, q, w0, z, lamb)
Convert Cartesian coordinates (x, y) to elliptic coordinates (xi, eta), for an elliptic coordinate system whose foci scale with the beam's waist as it propagates (used for Ince-Gaussian modes).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
array_like
|
Cartesian coordinates. |
required |
y
|
array_like
|
Cartesian coordinates. |
required |
q
|
float
|
Ellipticity parameter. |
required |
w0
|
float
|
Beam waist at |
required |
z
|
float
|
Propagation distance, used (with |
required |
lamb
|
float
|
Wavelength. |
required |
Returns:
| Type | Description |
|---|---|
xi, eta : array_like
|
Elliptic radial coordinate |
Source code in structured_optics\utils.py
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 | |
elliptic_to_cartesian ¶
elliptic_to_cartesian(xi, eta, q, w0, z, lamb)
Convert elliptic coordinates (xi, eta) to Cartesian coordinates
(x, y); the inverse of cartesian_to_elliptic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xi
|
array_like
|
Elliptic radial coordinate. |
required |
eta
|
array_like
|
Elliptic angular coordinate. |
required |
q
|
float
|
Ellipticity parameter. |
required |
w0
|
float
|
Beam waist at |
required |
z
|
float
|
Propagation distance, used (with |
required |
lamb
|
float
|
Wavelength. |
required |
Returns:
| Type | Description |
|---|---|
x, y : array_like
|
Cartesian coordinates, same shape as |
Source code in structured_optics\utils.py
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 | |
v_number ¶
v_number(n_core, n_clad, a, lamb)
Compute the normalized frequency (V-number) of a step-index fiber.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_core
|
float
|
Core refractive index. |
required |
n_clad
|
float
|
Cladding refractive index. |
required |
a
|
float
|
Core radius. |
required |
lamb
|
float
|
Wavelength (same length units as |
required |
Returns:
| Type | Description |
|---|---|
float
|
|
Source code in structured_optics\utils.py
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 | |
characteristic_eq ¶
characteristic_eq(u, V, l)
Evaluate the LP-mode characteristic (eigenvalue) equation for a
step-index fiber, whose roots u give the guided LP_l,m modes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
array_like
|
Trial value(s) of the normalized transverse core wavenumber. |
required |
V
|
float
|
Fiber V-number (see |
required |
l
|
int
|
Azimuthal mode order. |
required |
Returns:
| Type | Description |
|---|---|
array_like
|
The characteristic function
|
Source code in structured_optics\utils.py
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 | |
find_LP_roots ¶
find_LP_roots(V, l, m_max=6, n_samples=400)
Find up to m_max roots u (i.e. LP_l,1 ... LP_l,m_max) for azimuthal order l.
Source code in structured_optics\utils.py
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 | |
effective_index ¶
effective_index(u, V, n_core, n_clad)
n_eff via normalized propagation constant b = (V^2-u^2)/V^2? use standard: n_eff^2 = n_clad^2 + (v/V)^2*(n_core^2-n_clad^2)
Source code in structured_optics\utils.py
567 568 569 570 571 | |
lp_cutoff_V ¶
lp_cutoff_V(l, m)
Cutoff V-number for LP_lm: the m-th zero of J_{l-1} (l>0), or the (m-1)-th zero of J_1 for l=0 (LP01 itself has no cutoff, V_c=0).
Source code in structured_optics\utils.py
573 574 575 576 577 578 579 580 581 582 | |
find_all_LP_modes ¶
find_all_LP_modes(V, l_max=4, m_max=4)
Return dict {(l, m): (u, v)} for all supported LP_lm modes.
Source code in structured_optics\utils.py
585 586 587 588 589 590 591 592 593 594 595 596 | |
get_LP_params ¶
get_LP_params(l, m, n_core, n_clad, a, lamb)
Return the (u, v, n_eff, ...) parameters of a single LP_lm mode.
Raises ValueError, with an explanation, if: - l, m are not valid integers (l >= 0, m >= 1) - n_core <= n_clad (no guiding at all) - the fiber's V-number does not exceed the cutoff V-number for LP_lm (i.e. this mode is not supported by this fiber at this wavelength)
Source code in structured_optics\utils.py
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 | |
get_section ¶
get_section(Beam, ang_min, ang_max, pol_index=None)
Return the field restricted to the angular section [ang_min, ang_max).
Angles are given in radians.
Source code in structured_optics\utils.py
647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 | |
inv_sinc ¶
inv_sinc(A, n=10000)
Numerically invert the normalized sinc function on its first
monotonic branch, sinc(x/pi) for x in [0, pi].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
A
|
array_like
|
Value(s) of |
required |
n
|
int
|
Number of samples used to tabulate |
10000
|
Returns:
| Type | Description |
|---|---|
array_like
|
|
Source code in structured_optics\utils.py
674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 | |
inv_J0 ¶
inv_J0(A, n=10000)
Numerically invert the Bessel function J0 on its first monotonic
branch, x in [0, j01] where j01 is the first zero of J0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
A
|
array_like
|
Value(s) of |
required |
n
|
int
|
Number of samples used to tabulate |
10000
|
Returns:
| Type | Description |
|---|---|
array_like
|
|
Source code in structured_optics\utils.py
701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 | |
inv_J1 ¶
inv_J1(A, a=None, n=10000)
Numerically invert the Bessel function J1 on its first monotonic
branch, x in [0, x1_max] where x1_max is the location of J1's
first maximum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
A
|
array_like
|
Normalized value(s) to invert; internally clipped to |
required |
a
|
float
|
Scale factor applied to |
None
|
n
|
int
|
Number of samples used to tabulate |
10000
|
Returns:
| Type | Description |
|---|---|
array_like
|
|
Source code in structured_optics\utils.py
729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 | |
radial_poly ¶
radial_poly(n, m, r)
Evaluate the Zernike radial polynomial R_n^m(r).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Radial order. |
required |
m
|
int
|
Absolute value of the azimuthal frequency (0 <= m <= n),
with |
required |
r
|
array_like
|
Normalized radial coordinate(s) at which to evaluate the polynomial. |
required |
Returns:
| Type | Description |
|---|---|
array_like
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in structured_optics\utils.py
768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 | |
zernike ¶
zernike(n, m, r, phi)
Evaluate the (n, m) Zernike polynomial in polar coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Radial order. |
required |
m
|
int
|
Signed azimuthal frequency. |
required |
r
|
array_like
|
Normalized radial coordinate(s). |
required |
phi
|
array_like
|
Azimuthal angle(s), in radians. |
required |
Returns:
| Type | Description |
|---|---|
array_like
|
|
Source code in structured_optics\utils.py
805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 | |
zernikes_phase ¶
zernikes_phase(beam, coefs, strengths)
Build a complex phase-only transmittance from a weighted sum of
Zernike polynomials, evaluated on beam's own grid (normalized by
its waist).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
beam
|
object
|
Beam instance supplying the coordinate grids |
required |
coefs
|
array_like
|
Array of shape (N, 2), where each row |
required |
strengths
|
array_like
|
Length-N array of coefficient strengths, one per row of
|
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Complex array |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in structured_optics\utils.py
833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 | |