Skip to content

Units and constants

Unit-safe scalar types (Wavelength, Energy, Power, …), built-in constants and conversions. Docstrings are the source of truth, rendered with mkdocstrings (numpydoc style).

photonics_helper.base

Physical units and constants for photonics calculations.

PI module-attribute

PI: float = const.pi

C_MS module-attribute

C_MS: float = const.c

EPS_0 module-attribute

EPS_0: float = const.epsilon_0

Z0 module-attribute

Z0: float = 1.0 / (const.epsilon_0 * const.c)

MU_0 module-attribute

MU_0: float = const.mu_0

H_PLANCK module-attribute

H_PLANCK: float = const.h

HBAR module-attribute

HBAR: float = const.hbar

Wavelength

Wavelength stored internally in meters.

Accepts nm, um, or m on construction; converts to meters in __post_init__.

value instance-attribute

value: float

unit instance-attribute

unit: Literal['nm', 'um', 'm']

as_m cached property

as_m: float

Value in metres (the internal storage unit).

as_um cached property

as_um: float

Value in micrometres.

as_nm cached property

as_nm: float

Value in nanometres.

as_meep cached property

as_meep: float

Convert to MEEP frequency units: f_Meep = a/λ.

to_freq

to_freq() -> Frequency

Convert to Frequency (Hz).

to_omega

to_omega() -> AngularFrequency

Convert to AngularFrequency (rad/s).

to_energy

to_energy() -> Energy

Convert to :class:Energy (J).

to_wn

to_wn() -> Wavenumber

Convert to Wavenumber (1/m).

from_meep classmethod

from_meep(value: float, base_length: Wavelength | None = None) -> Self

Create from MEEP frequency units.

In MEEP, c = 1, so f_Meep = a/λ where a is the base_length.

Frequency

Optical frequency stored internally in Hz.

Accepts THz, GHz, MHz, or Hz on construction; converts to Hz in __post_init__.

value instance-attribute

value: float

unit instance-attribute

unit: Literal['THz', 'GHz', 'MHz', 'Hz']

as_Hz cached property

as_Hz: float

as_THz cached property

as_THz: float

as_GHz cached property

as_GHz: float

as_MHz cached property

as_MHz: float

as_meep cached property

as_meep: float

Convert to MEEP units (λ₀ = 1 μm): f_Meep = ν·a/c = a/λ.

to_wl

to_wl() -> Wavelength

Convert to Wavelength (m).

to_omega

to_omega() -> AngularFrequency

Convert to AngularFrequency (rad/s).

to_wn

to_wn() -> Wavenumber

Convert to Wavenumber (1/m).

to_time

to_time() -> Time

Construct the equivalent :class:Time (unit-converted).

to_energy

to_energy() -> Energy

Convert to :class:Energy (J).

from_meep classmethod

from_meep(value: float, base_length: Wavelength | None = None) -> Self

Create from MEEP frequency units.

In MEEP, c = 1, so f_Meep = ν·a/c. Therefore ν = f_Meep·c/a.

AngularFrequency

Angular optical frequency stored internally in rad/s.

Accepts rad/s or rad/ps on construction; converts to rad/s in __post_init__.

value instance-attribute

value: float

unit instance-attribute

unit: Literal['rad/s', 'rad/ps']

as_rad_s cached property

as_rad_s: float

Value in rad/s.

as_rad_ps cached property

as_rad_ps: float

Value in rad/ps.

as_meep cached property

as_meep: float

Convert to MEEP frequency units: f_Meep = aω/(2πc).

to_wl

to_wl() -> Wavelength

Convert to Wavelength (m).

to_freq

to_freq() -> Frequency

Convert to Frequency (Hz).

to_wn

to_wn() -> Wavenumber

Convert to Wavenumber (1/m).

to_time

to_time() -> Time

Construct the equivalent :class:Time (unit-converted).

to_energy

to_energy() -> Energy

Convert to :class:Energy (J).

from_meep classmethod

from_meep(value: float, base_length: Wavelength | None = None) -> Self

Create from MEEP frequency units.

In MEEP, c = 1, so f_Meep = ω·a/(2πc). Therefore ω = 2π·f_Meep·c/a.

Wavenumber

Wavenumber stored internally in 1/m.

Accepts 1/cm or 1/m on construction; converts to 1/m in __post_init__.

value instance-attribute

value: float

unit instance-attribute

unit: Literal['1/cm', '1/m']

as_1_m cached property

as_1_m: float

Value in 1/m (inverse metres).

as_1_cm cached property

as_1_cm: float

Value in 1/cm (per centimetre).

as_angular cached property

as_angular: float

Value expressed in angular units.

as_meep cached property

as_meep: float

Convert to MEEP frequency units: f_Meep = ak/(2π).

to_wl

to_wl() -> Wavelength

Convert to Wavelength (m).

to_freq

to_freq() -> Frequency

Convert to Frequency (Hz).

to_omega

to_omega() -> AngularFrequency

Convert to AngularFrequency (rad/s).

to_energy

to_energy() -> Energy

Convert to :class:Energy (J).

from_meep classmethod

from_meep(value: float, base_length: Wavelength | None = None) -> Self

Create from MEEP frequency units.

In MEEP, c = 1, so f_Meep = k·a/(2π).

Length

Length stored internally in meters.

Accepts km, m, cm, mm, um, nm, or pm on construction; converts to meters in __post_init__.

value instance-attribute

value: float

unit instance-attribute

unit: Literal['km', 'm', 'cm', 'mm', 'um', 'nm', 'pm']

as_km cached property

as_km: float

Value expressed in km units.

as_m cached property

as_m: float

Value in metres (the internal storage unit).

as_cm cached property

as_cm: float

Value expressed in cm units.

as_mm cached property

as_mm: float

Value expressed in mm units.

as_um cached property

as_um: float

Value in micrometres.

as_nm cached property

as_nm: float

Value in nanometres.

as_pm cached property

as_pm: float

Value expressed in pm units.

as_meep cached property

as_meep: float

Value in MEEP normalized units.

to_wl

to_wl() -> Wavelength

Convert to :class:Wavelength (m).

from_wl classmethod

from_wl(wl: Wavelength) -> Self

from_meep classmethod

from_meep(value: float, base_length: Wavelength | None = None) -> Self

Time

Time stored internally in seconds.

Accepts s, ms, us, ns, ps, fs, or as on construction; converts to seconds in __post_init__.

value instance-attribute

value: float

unit instance-attribute

unit: Literal['s', 'ms', 'us', 'ns', 'ps', 'fs', 'as']

as_s cached property

as_s: float

Value in seconds.

as_ms cached property

as_ms: float

Value expressed in ms units.

as_us cached property

as_us: float

Value expressed in us units.

as_ns cached property

as_ns: float

Value in nanoseconds.

as_ps cached property

as_ps: float

Value in picoseconds.

as_fs cached property

as_fs: float

Value in femtoseconds.

as_as cached property

as_as: float

Value expressed in as units.

as_meep cached property

as_meep: float

Value in MEEP normalized units.

to_freq

to_freq() -> Frequency

Convert to :class:Frequency (Hz).

to_omega

to_omega() -> AngularFrequency

Convert to :class:AngularFrequency (rad/s).

from_freq classmethod

from_freq(freq: Frequency) -> Self

from_omega classmethod

from_omega(omega: AngularFrequency) -> Self

from_meep classmethod

from_meep(value: float, base_length: Wavelength | None = None) -> Self

Energy

Energy stored internally in Joules.

Accepts J, mJ, uJ, nJ, pJ, eV, or meV on construction; converts to Joules in __post_init__.

value instance-attribute

value: float

unit instance-attribute

unit: Literal['J', 'mJ', 'uJ', 'nJ', 'pJ', 'eV', 'meV']

as_J cached property

as_J: float

as_mJ cached property

as_mJ: float

as_uJ cached property

as_uJ: float

as_nJ cached property

as_nJ: float

as_pJ cached property

as_pJ: float

as_eV cached property

as_eV: float

as_meV cached property

as_meV: float

as_meep cached property

as_meep: float

Value in MEEP normalized units.

to_freq

to_freq() -> Frequency

Convert to :class:Frequency (Hz).

to_omega

to_omega() -> AngularFrequency

Convert to :class:AngularFrequency (rad/s).

to_wl

to_wl() -> Wavelength

Convert to :class:Wavelength (m).

to_wn

to_wn() -> Wavenumber

Convert to :class:Wavenumber (1/m).

from_freq classmethod

from_freq(freq: Frequency) -> Self

from_omega classmethod

from_omega(omega: AngularFrequency) -> Self

from_wl classmethod

from_wl(wl: Wavelength) -> Self

from_wn classmethod

from_wn(wn: Wavenumber) -> Self

from_meep classmethod

from_meep(value: float, base_length: Wavelength | None = None) -> Self

Power

Power stored internally in Watts.

Accepts kW, W, mW, uW, or nW on construction; converts to Watts in __post_init__.

value instance-attribute

value: float

unit instance-attribute

unit: Literal['kW', 'W', 'mW', 'uW', 'nW']

as_kW cached property

as_kW: float

as_W cached property

as_W: float

as_mW cached property

as_mW: float

as_uW cached property

as_uW: float

as_nW cached property

as_nW: float

as_meep cached property

as_meep: float

Convert to MEEP units: P_meep = P·a²/(h·c²) for a = 1 μm.

from_meep classmethod

from_meep(value: float, base_length: Wavelength | None = None) -> Self

Create from MEEP power units.

Energy unit ħc/a joined with Energy.as_meep (which uses the Planck constant h, not ħ) gives P_meep = P·a²/(h·c²), the exact inverse of :attr:as_meep.

Area

Area stored internally in square meters (m²).

Accepts m^2, cm^2, mm^2, um^2, or nm^2 on construction; converts to m² in __post_init__.

value instance-attribute

value: float

unit instance-attribute

unit: Literal['m^2', 'cm^2', 'mm^2', 'um^2', 'nm^2']

as_m2 cached property

as_m2: float

Value in square metres.

as_cm2 cached property

as_cm2: float

Value expressed in cm2 units.

as_mm2 cached property

as_mm2: float

Value expressed in mm2 units.

as_um2 cached property

as_um2: float

Value in square micrometres.

as_nm2 cached property

as_nm2: float

Value in nm².

as_meep cached property

as_meep: float

Value in MEEP normalized units.

from_meep classmethod

from_meep(value: float, base_length: Wavelength | None = None) -> Self

PeakPower

Bases: Power

Peak power of a pulse, tying normalized envelopes to physical watts.

A thin :class:Power subclass. The conversion from a normalized envelope amplitude A (in V/m, or any consistent field unit) to a physical peak power follows from the plane-wave intensity relation

.. math::

I = \tfrac{1}{2} n \, c \, \varepsilon_0 \, |A|^2
\qquad\Longrightarrow\qquad
P_\mathrm{peak} = I_\mathrm{peak} \, A_\mathrm{eff}
= \tfrac{1}{2} n \, c \, \varepsilon_0 \, A_\mathrm{eff} \, |A|^2.

Wave.peak_power() uses the same relation; this class exposes it for one-shot conversions where only the envelope amplitude is at hand.

from_envelope classmethod

from_envelope(A: NDArray | float, A_eff: Area, n: float = 1.0, lambda0: Wavelength | None = None) -> PeakPower

Convert a normalized envelope amplitude to a physical peak power.

Parameters:

Name Type Description Default
A complex envelope amplitude (array or scalar) in field units.
required
A_eff effective mode area.
required
n refractive index at the carrier wavelength (default 1.0).
1.0
lambda0 optional vacuum carrier wavelength. Retained so call sites

record the wavelength the refractive index refers to; validated when supplied.

None

Returns:

Type Description
PeakPower — the peak power in watts (a :class:`Power`).

WavelengthArray

Array of wavelengths stored internally in meters.

value instance-attribute

value: NDArray

unit instance-attribute

unit: Literal['nm', 'um', 'm']

as_m cached property

as_m: NDArray

Value in metres (the internal storage unit).

as_um cached property

as_um: NDArray

Value in micrometres.

as_nm cached property

as_nm: NDArray

Value in nanometres.

as_meep cached property

as_meep: NDArray

Convert to MEEP frequency units: f_Meep = a/λ.

from_wavelengths classmethod

from_wavelengths(wavelengths: list[Wavelength]) -> Self

Build from a list of Wavelength scalars (stored internally in m).

to_freq

to_freq() -> FrequencyArray

Convert to FrequencyArray (Hz).

to_omega

to_omega() -> AngularFrequencyArray

Convert to AngularFrequencyArray (rad/s).

to_wn

to_wn() -> WavenumberArray

Convert to WavenumberArray (1/m).

to_equally_spaced

to_equally_spaced(points=51) -> NDArray

Return equally-spaced wavelength values between min and max.

from_meep classmethod

from_meep(value: float | NDArray, base_length: Wavelength | None = None) -> Self

Create from MEEP frequency units.

In MEEP, c = 1, so f_Meep = a/λ where a is the base_length.

FrequencyArray

Array of frequencies stored internally in Hz.

value instance-attribute

value: NDArray

unit instance-attribute

unit: Literal['THz', 'GHz', 'MHz', 'Hz']

as_Hz cached property

as_Hz: NDArray

as_THz cached property

as_THz: NDArray

as_GHz cached property

as_GHz: NDArray

as_MHz cached property

as_MHz: NDArray

as_meep cached property

as_meep: NDArray

Convert to MEEP units (λ₀ = 1 μm): f_Meep = ν·a/c.

to_wl

to_wl() -> WavelengthArray

Convert to WavelengthArray (m).

to_omega

to_omega() -> AngularFrequencyArray

Convert to AngularFrequencyArray (rad/s).

to_wn

to_wn() -> WavenumberArray

Convert to WavenumberArray (1/m).

to_equally_spaced

to_equally_spaced(points=51) -> NDArray

Return equally-spaced frequency values between min and max.

from_meep classmethod

from_meep(value: float | NDArray, base_length: Wavelength | None = None) -> Self

Create from MEEP frequency units.

In MEEP, c = 1, so f_Meep = ν·a/c. Therefore ν = f_Meep·c/a.

AngularFrequencyArray

Array of angular frequencies stored internally in rad/s.

value instance-attribute

value: NDArray

unit instance-attribute

unit: Literal['rad/s', 'rad/ps']

as_rad_s cached property

as_rad_s: NDArray

Value in rad/s.

as_rad_ps cached property

as_rad_ps: NDArray

Value in rad/ps.

as_meep cached property

as_meep: NDArray

Convert to MEEP frequency units: f_Meep = aω/(2πc).

to_wl

to_wl() -> WavelengthArray

Convert to WavelengthArray (m).

to_freq

to_freq() -> FrequencyArray

Convert to FrequencyArray (Hz).

to_wn

to_wn() -> WavenumberArray

Convert to WavenumberArray (1/m).

to_equally_spaced

to_equally_spaced(points=51) -> NDArray

Return equally-spaced angular frequency values between min and max.

from_meep classmethod

from_meep(value: float | NDArray, base_length: Wavelength | None = None) -> Self

Create from MEEP frequency units.

In MEEP, c = 1, so f_Meep = ω·a/(2πc). Therefore ω = 2π·f_Meep·c/a.

WavenumberArray

Array of wavenumbers stored internally in 1/m.

value instance-attribute

value: NDArray

unit instance-attribute

unit: Literal['1/cm', '1/m']

as_1_m cached property

as_1_m: NDArray

Value in 1/m (inverse metres).

as_1_cm cached property

as_1_cm: NDArray

Value in 1/cm (per centimetre).

as_angular cached property

as_angular: NDArray

Value expressed in angular units.

as_meep cached property

as_meep: NDArray

Convert to MEEP frequency units: f_Meep = ak/(2π).

to_wl

to_wl() -> WavelengthArray

Convert to WavelengthArray (m).

to_freq

to_freq() -> FrequencyArray

Convert to FrequencyArray (Hz).

to_omega

to_omega() -> AngularFrequencyArray

Convert to AngularFrequencyArray (rad/s).

to_equally_spaced

to_equally_spaced(points=51) -> NDArray

Return equally-spaced wavenumber values between min and max.

from_meep classmethod

from_meep(value: float | NDArray, base_length: Wavelength | None = None) -> Self

Create from MEEP frequency units.

In MEEP, c = 1, so f_Meep = k·a/(2π).

Permittivity

Bases: float

Electric permittivity (F/m). Wraps float with a convenience constructor.

value instance-attribute

value: float

from_relative classmethod

from_relative(relative_value: float)

Create from relative permittivity (ε_r): ε = ε₀ × ε_r.

Permeability

Bases: float

Magnetic permeability (H/m). Wraps float with a convenience constructor.

value instance-attribute

value: float

from_relative classmethod

from_relative(relative_value: float)

Create from relative permeability (μ_r): μ = μ₀ × μ_r.