KrakenOS Formula and Code Map
This page connects equations in Bahaa E. A. Saleh and Malvin Carl Teich, Fundamentals of Photonics, second edition, to the KrakenOS implementation. It is a reading map, not a claim that KrakenOS implements the whole book. The strongest correspondence is in ray, beam, Fourier, electromagnetic, and polarization optics. A formula is marked direct only when the code evaluates that formula, or an algebraically equivalent vector or matrix form.
The printed section, equation, and page numbers below refer to the second edition used by this solution collection. The equations are restated in the notation needed to explain the implementation; surrounding textbook prose and figures are not reproduced. For general identities used in the worked solutions, see Mathematical Formula Reference.
How to read the map
Level |
Meaning |
|---|---|
Direct |
KrakenOS evaluates the stated equation or an algebraically equivalent vector, matrix, or discrete form. |
Partial |
KrakenOS implements the named physics under additional assumptions, or produces only part of the textbook quantity. |
Related |
The code can illustrate the section, but is not a solver for its full mathematical model. |
Not modelled |
No corresponding first-principles model was found in the KrakenOS physics and analysis modules reviewed for this page. |
Important
Units and conventions
Sequential and non-sequential geometry, distance, optical path length, radii, and focal lengths are in millimetres.
Public ray-trace and Gaussian-beam wavelength inputs are normally in micrometres. Code forming a phase therefore converts \(\lambda_0[\mathrm{\mu m}]\) to \(\lambda_0[\mathrm{mm}]\) with a factor of \(10^{-3}\).
Glass-catalog dispersion also evaluates wavelength in micrometres.
KrakenOS/Physics/photodiode.pyuses explicit unit suffixes and mixes nanometres, micrometres, millimetres, and inverse centimetres. Do not pass its absorption coefficient to the core tracer without conversion.The book writes the standard paraxial ray as \((y,\theta)^T\). KrakenOS’ legacy matrices store \((u,y)^T\);
kraken_to_abcdperforms the permutation before Gaussian-beam calculations.Saleh and Teich use an \(\exp(+j\omega t)\) time convention, giving spatial propagation factors such as \(\exp(-jkz)\). Some KrakenOS field code uses the complex-conjugate convention. Intensities are unchanged, but a reported phase sign must be interpreted consistently.
Coverage by chapter
Chapter |
Coverage |
KrakenOS capability |
|---|---|---|
1 Ray Optics |
Direct |
Optical path, vector Snell refraction, reflection, total internal reflection, exact surface intersections, and paraxial matrices. |
2 Wave Optics |
Partial |
Complex phasors, OPL phase, coherent/incoherent detector sums, thin lenses, mirrors, and diffraction gratings. No general Helmholtz solver. |
3 Beam Optics |
Direct for TEM00 |
Gaussian \(q\) propagation, beam radius, curvature, Rayleigh range, divergence, Gouy phase, clipping, and astigmatic X/Y traces. General Hermite-, Laguerre-, and Bessel-Gaussian mode families are not solved. |
4 Fourier Optics |
Direct/partial |
Paraxial Fresnel transfer-function propagation, Fraunhofer FFT, diffraction PSF, and MTF. Hologram recording/reconstruction is absent. |
5 Electromagnetic Optics |
Partial |
Catalog dispersion, Sellmeier forms, exponential bulk attenuation, and complex-index metal reflectance. No Maxwell-field boundary-value solver. |
6 Polarization Optics |
Partial |
P/S Fresnel power, normalized Jones states, branch transport, and coherent vector-field summation. Anisotropic media, optical activity, liquid crystals, and a general Jones-matrix device cascade are absent. |
7-9 Photonic crystals, guides, fibers |
Related |
Layered coating tables and TIR ray guidance can illustrate interfaces and guided rays, but KrakenOS does not solve Bloch modes or waveguide and fiber eigenmodes. |
10 Resonator Optics |
Direct/partial |
ABCD stability and the self-consistent Gaussian cavity eigenmode. No longitudinal spectrum or higher-order resonator-mode solver. |
11 Statistical Optics |
Related |
Detector fields can be summed by source group, fully coherently, or as incoherent power. This is not a stochastic coherence-function solver. |
12-17 Photon, atom, laser, semiconductor-source physics |
Not modelled |
Ray sources can represent emitted light, but KrakenOS does not solve quantum states, rate equations, laser gain, or semiconductor emitters. |
18 Semiconductor Photon Detectors |
Partial teaching model |
Responsivity, absorption, silicon-slab transmission, diode I-V, and photovoltage helpers. Noise, avalanche multiplication, and array-device transport are not general device solvers. |
19-24 Lightwave devices and systems |
Not modelled |
A static diffraction grating is not an acousto-optic interaction model; electro-optic, nonlinear, ultrafast, switching, and communication-system equations are outside the reviewed implementation. |
Chapter 1: ray optics
Optical path length
Section 1.1, Eq. (1.1-1), printed p. 3, defines
for piecewise homogeneous media. system.__CollectData in
KrakenOS/KrakenSys.py calculates each geometric segment
dist = norm(RayOrig - pTarget), appends dist * PrevN to OP, and
accumulates it in TOP. Thus system.OP[i] is \(n_i\ell_i\),
system.TOP_S[i] is the cumulative OPL, and system.TOP is
\(\mathcal L\). This is a direct discrete implementation of
(1).
Snell refraction and total internal reflection
Section 1.1, Eq. (1.1-3), printed p. 5, is Snell’s law,
snell_refraction_vector_physics.calculate and
batch_snell_refraction in KrakenOS/PhysicsClass.py use its vector
form. For unit incident direction \(\boldsymbol s\), a unit normal
\(\boldsymbol N\) facing the incident ray, and
\(\eta=n_1/n_2\), the transmitted direction is
The code tests
\(\eta^2|\boldsymbol N\times\boldsymbol s|^2>1\). This is exactly the
condition that the square root in (3) would be
imaginary, so the path is changed to reflection. The scalar and batched
implementations are equivalent. The code also uses a negative-index sentinel
for a mirror and a Secuen flag for forced reflection; neither is a physical
negative-index material model.
Paraxial ray matrices
Section 1.4, Eqs. (1.4-1) to (1.4-3), printed p. 25, writes
The component matrices used by build_paraxial_matrix_trace in
KrakenOS/ParaxialMatrix.py are the book’s matrices from Sec. 1.4B:
These correspond to Eqs. (1.4-4), (1.4-6), and (1.4-7), respectively. For a mirror, the implementation changes the incident-index sign, reducing the powered-surface term to \(-2/R\), as in Eq. (1.4-9). It multiplies the steps in ray order as required by the cascade rule Eq. (1.4-10).
The apparent transposition in the source is intentional. The legacy matrix
acts on \((u,y)^T\); kraken_to_abcd converts it to the standard
\((y,u)^T\) form in (4). Use
ParaxialMatrixTrace.system_matrix_abcd when comparing a numerical result
with the book.
Chapters 2 and 3: waves, gratings, and Gaussian beams
Phase, intensity, and interference
Section 2.2 defines a complex amplitude in Eq. (2.2-2) and its intensity in Eq. (2.2-10). Section 2.5, Eqs. (2.5-1) and (2.5-4), then gives
The coherent-detector path in
KrakenOS/UI/panels/main_path_detector_analysis.py converts each ray’s OPL
to a relative phase and then adds complex field amplitudes:
The code performs the wavelength conversion before evaluating (7). It can sum all rays coherently, keep separate source-coherence groups, or add only incoherent power. This is a direct discrete implementation of Sec. 2.5, subject to the chosen grouping model.
Diffraction grating
Section 2.4, Eq. (2.4-13), printed p. 56, gives the one-dimensional grating equation
diffraction_grating_physics.calculate in
KrakenOS/PhysicsClass.py evaluates a three-dimensional vector generalization
using the surface normal, groove direction, incident and outgoing refractive
indexes, order Ord, wavelength W, and period d. Equation
(8) is its coplanar, same-index limit. KrakenOS determines
the output ray direction; it does not calculate the diffraction efficiency
of each order from groove shape.
Gaussian \(q\) parameter
Section 3.1, Eqs. (3.1-5), (3.1-6), and (3.1-11), printed pp. 76-77, uses
Section 3.2, Eq. (3.2-21), printed p. 92, supplies the ABCD law
propagate_gaussian_beam in KrakenOS/GaussianBeam.py constructs
\(q_1\) from the waist and applies (10) to every
abcd_matrix step. _beam_quantities then inverts \(q\) to recover
\(W\), \(R\), waist position, \(z_R\), divergence, and Gouy phase.
For m2=1 it is a direct implementation. For m2>1 the code replaces
\(\lambda_0\) by \(M^2\lambda_0\), the usual real-beam engineering
extension rather than the ideal Gaussian beam assumed in Eqs. (3.1-5) to
(3.1-11).
The finite-aperture helper _gaussian_clip_transmission evaluates
which is Eq. (3.1-17) with \(\rho_0=a\). Astigmatic traces propagate independent tangential and sagittal \(q\) values through the currently axisymmetric ABCD sequence.
Chapter 4: Fourier optics and image quality
Fresnel transfer function
Section 4.1B, Eq. (4.1-11), printed p. 113, is the paraxial free-space transfer function. With a convention matching KrakenOS it can be written
propagate_branch_field in KrakenOS/BranchField.py constructs exactly
this array, multiplies the orthonormal FFT of the sampled field by it, and
inverse-transforms the result. The expression is the complex conjugate of
the book’s \(\exp(+j\omega t)\) convention, as noted above. This is a
paraxial scalar propagator; it does not retain the evanescent spectrum in the
exact transfer function Eq. (4.1-9).
Fraunhofer field and angular axis
Section 4.2A, Eq. (4.2-1), printed p. 116, states that the far field is a scaled Fourier transform of the near field. The corresponding sampled form is
fft_vector_field_intensity and fft_angle_axis_mrad in
KrakenOS/UI/coherent_detector_analysis.py apply
(13) independently to the three field components and
sum their intensities. This is a direct sampled Fraunhofer calculation.
Its validity still requires the far-field conditions in Eq. (4.2-2), or an
equivalent Fourier-transforming optical system.
Pupil, PSF, and MTF
For a focused imaging system, Sec. 4.4C, Eqs. (4.4-11) and (4.4-12), printed pp. 133-134, makes the amplitude impulse response proportional to the Fourier transform of the pupil. KrakenOS represents an aberrated pupil as
where \(W\) is in waves. psf4mtf and psf in
KrakenOS/PSFCalc.py build this pupil from Zernike coefficients, FFT it,
and square its magnitude. calculate_mtf normalizes the PSF, Fourier
transforms it, and returns the magnitude of the resulting OTF. The PSF step
is a direct discretization of Sec. 4.4; the named MTF calculation is a
standard incoherent-imaging extension, not an explicitly numbered equation
in that section of this edition.
Zernike_Fitting in KrakenOS/WavefrontFit.py obtains coefficients by
least squares. Zernike decomposition is KrakenOS analysis machinery rather
than a formula developed in Chapters 1-4 of this textbook.
Chapters 5 and 6: materials and polarization
Absorption and dispersion
The derivation following Sec. 5.5 Eq. (5.5-3), printed p. 171, gives the intensity attenuation law
Glass transmission tables are converted to
\(\alpha=-\ln(T)/d\) by n_wave_dispersion in
KrakenOS/Physics/optics.py. system.__CollectData then appends
exp(-alpha * dist) to BULK_TRANS. This is a direct use of
(15); both \(d\) and \(\alpha^{-1}\) must use the
core trace’s millimetre length unit.
Section 5.5, Eq. (5.5-28), printed p. 180, gives the Sellmeier form
For Zemax dispersion formula 2, n_wave_dispersion evaluates the three-term
version of (16). It also supports other catalog forms
(Schott, Herzberger, Conrady, extended, and additional Sellmeier variants).
The coefficients are empirical catalog data and must only be used over their
specified wavelength range.
Fresnel reflection and Jones state
Section 6.2, Eqs. (6.2-8) and (6.2-9), printed p. 211, gives the dielectric Fresnel amplitude coefficients. In the usual s/p notation,
fresnel_dielectric in KrakenOS/Physics/optics.py evaluates
(17) from dot products of the ray and surface-normal
vectors. fresnel_metal uses a complex refractive index. The public
results RP, RS, TP, and TS are power coefficients, not the
complex amplitudes \(r_p,r_s,t_p,t_s\). For an uncoated lossless
dielectric the code sets \(T=1-R\).
This distinction matters for polarization interference. Section 6.1, Eq. (6.1-10), printed p. 203, defines a Jones vector. KrakenOS stores normalized P/S Jones components and transports an equivalent complex 3-D polarization vector along each branch. Fresnel power changes are applied as square-root amplitude weights, while optional coating/beam-splitter phase settings supply relative phase. The current dielectric helper does not preserve the intrinsic sign or complex phase of every Fresnel amplitude, so it is a partial Jones implementation rather than a general Jones-matrix solver.
Chapters 10 and 18: cavity and detector helpers
Gaussian cavity eigenmode
Section 10.2A, Eq. (10.2-5), printed p. 379, gives the ABCD trace stability condition. The self-consistent Gaussian mode also satisfies the fixed-point form of the Chapter 3 ABCD law:
solve_gaussian_cavity_eigenmode in KrakenOS/GaussianBeam.py evaluates
the stability parameter, solves the quadratic, and selects the root with
\(\operatorname{Im}q>0\). Equality is treated as a boundary rather than a
robust stable mode. The input matrix must represent one complete round trip
at the chosen reference plane.
Semiconductor detector relations
Section 18.1B, Eqs. (18.1-3) and (18.1-5), printed pp. 753-754, gives
absorption_intensity, absorption_power, and the silicon-slab helpers
in KrakenOS/Physics/photodiode.py provide the exponential absorption and
surface-reflection factors. They do not model the carrier collection factor
\(\zeta\). responsivity is a direct numerical implementation of the
second relation in (19), returning A/W.
Section 18.3, Eq. (18.3-1), printed p. 763, has the photodiode form
photodiode_current_density implements the same structure per unit area,
with \(i_p/A=eL_pG\). Its ideality_factor generalizes the textbook
exponent to \(eV/(m k_BT)\), with \(m=1\) reproducing
(20). photovoltage sets the current to zero and
solves for the open-circuit voltage. The function docstrings cite equation
numbers from Photonics Essentials, for which these teaching helpers were
originally written; (20) is the corresponding
equation in Fundamentals of Photonics.
Reverse audit: KrakenOS code outside this textbook
Yes. The map above starts with the PDF and asks whether KrakenOS has a matching implementation. The reverse question, starting with KrakenOS and looking for a formula in the PDF, exposes substantial code with no direct match. This is expected: the book develops photonics, whereas KrakenOS also has to construct, trace, assess, optimize, import, and display complete optical systems.
The audit below covers the production Python packages under KrakenOS.
Examples, validation scripts, and tests are not counted as separate physics
capabilities. A row marked outside means that no equation or algorithm
corresponding to the KrakenOS implementation was found in this edition. It
does not mean that the code contradicts the book or has no optical use.
Capability |
Principal code |
Relationship to the PDF |
|---|---|---|
Sequential and non-sequential trace orchestration |
|
The branch queue, reflected/transmitted child paths, nested-solid media state, hit limits, stall rejection, terminal events, provenance, batch execution, and saved trace records are outside. Snell, Fresnel, attenuation, and OPL at each interaction remain direct textbook matches; the software architecture joining those laws is not a book formula. |
Engineering surfaces and exact intersections |
|
The PDF includes an exercise about an aberration-free aspherical imaging surface, but not KrakenOS’ Zemax-style conic-polynomial sag, axicon, user-function, sampled error-map, and Zernike sag conventions. Its finite-difference normals, Newton intersection, arbitrary aperture, triangle-mesh, STL, STEP/BREP-face, and face-identity algorithms are outside. |
Diffuse and measured surface scatter |
|
The PDF discusses Rayleigh scattering and describes an LED as Lambertian, but it does not develop the implemented Lambertian, cosine-lobe, Oren–Nayar, or pySCATMECH BRDF reflection models. The deterministic scatter-child sampler and BRDF branch weighting are outside this textbook. |
Optical-design aberration workflows |
|
Chapter 4 supports the general wavefront, pupil, PSF, and MTF ideas, but
it does not provide KrakenOS’ Seidel sums, Zernike least-squares fit,
reference-sphere construction, pupil ray aiming, best-focus solve, or
wide-field map algorithms. The PDF’s |
Captured-target MTF measurement |
|
MTF itself is a Chapter 4 match. Extracting an edge-spread function from a slanted-edge camera image and fitting USAF-1951 three-bar regions are outside: they are metrology and image-data reduction procedures, not the book’s pupil-to-OTF derivation. |
Lens optimization and manufacturing tolerance |
|
Variables, bounds, weighted merit operands, invalid-trace penalties, the pygmo backend, sensitivity reports, compensators, and Monte Carlo manufacturing trials have no matching optical-design algorithm in the PDF. Uses of the ordinary words optimization and tolerance in the book concern individual physics problems, not these KrakenOS engines. |
Atmospheric refractivity and astronomical refraction |
|
Chapter 5 explains material dispersion, but the Barrell–Sears, Ciddor, Edlen, Owens, Mathar, SLALIB, observatory-condition, zenith refraction, and atmospheric-dispersion models are outside this PDF. |
Ray-source sampling and prescription infrastructure |
|
Some chosen source distributions can represent radiation patterns mentioned in the book. The solid-angle random sampler, pupil patterns, glass and coating catalog readers, Zemax decoding, material lookup, and prescription construction are software/data conventions with no direct equation match. |
CAD workbench, UI, import/export, and acceleration |
|
Scene editing, Open3D interaction, CAD placement and promotion, camera databases, reports, file persistence, layout import/export, plotting, event recording, caches, and CPU/GPU array dispatch are outside. They expose or accelerate models; they are not additional photonics formulae. |
A short code-to-book workflow
The following pattern keeps the book’s ABCD convention throughout. It assumes
system is an already constructed KrakenOS sequential system.
import KrakenOS as Kos
# Book Sec. 1.4: obtain the conventional (y, theta) ABCD trace.
paraxial = system.ParaxMatrices(0.6328) # wavelength in um
matrix = paraxial.system_matrix_abcd
# Book Secs. 3.1-3.2: define a waist and apply q2=(Aq1+B)/(Cq1+D).
beam = Kos.GaussianBeamInput(
wavelength_um=0.6328,
waist_radius_mm=0.25,
waist_offset_mm=0.0,
m2=1.0,
input_index=1.0,
)
result = Kos.propagate_gaussian_beam(paraxial, beam)
last = result.final
print(matrix)
print(last.beam_radius_mm, last.wavefront_radius_mm)
For an equation-level check, calculate \(q_1=j\pi W_0^2/\lambda_0\)
in millimetres and apply (10) to matrix by hand. Its
real and imaginary parts should agree with result.final.q_real_mm and
q_imag_mm to floating-point precision.
Limits of this cross-reference
KrakenOS is primarily a geometrical optical-system simulator with selected paraxial and scalar-wave analyses. A matching variable name is not evidence of a matching physical model. In particular:
GRINcurrently resolves to a placeholder bulk index in the catalog helper; it is not the continuous ray-equation solver of Sec. 1.3.A coating table supplies interpolated P/S power and optional phase data; it is not automatically the multilayer transfer-matrix derivation of Chapter 7.
Geometrical PSF/MTF panels and diffraction PSF/MTF functions are different models.
KrakenOS/PSFCalc.pyis the Fourier-pupil implementation mapped above.The photodiode module is a teaching model and is separate from ray landing on a camera sensor. It does not make every traced image a semiconductor carrier-transport simulation.
No code correspondence should be inferred for chapters marked not modelled until a solver and a validation test for that physics exist.