mokka.utils
Utilities sub-module for MOKKa.
This sub-module contains a lot of useful utiltiies used throughout the MOKKa package.
- mokka.utils.N0(SNR)
Calculate \(N_0\) from SNR.
- Parameters:
SNR – signal-to-noise ratio \(s\) [dB]
- Returns:
\(10^{-\frac{s}{10}}\)
- mokka.utils.beta2(D, wavelength)
Calculate \(\beta_2\) from the dispersion coefficient and wavelength.
- Parameters:
D – Dispersion coefficient [ps/nm/km]
wavelength – wavelength of optical carrier [nm]
- Returns:
beta2 in [ps**2/km]
- mokka.utils.bits2hex(bits)
Convert bit array to their hex representation MSB first.
- Parameters:
bits – array of bit arrays
- Returns:
list of hex strings
- mokka.utils.bits2int(bits)
Convert bit array to their integer representation MSB first.
- Parameters:
bits – array of bit arrays
- Returns:
array of ints
- mokka.utils.db2pow(ydb)
Calculate the power in linear units.
- Parameters:
ydb – power in decibel [dB]
- Returns:
power in linear units [W]
- mokka.utils.dbm2pow(ydbm)
Calculate the power in linear units.
- Parameters:
ydbm – power in dBm [dBm]
- Returns:
power in linear units [W]
- mokka.utils.estimate_SNR(x, y)
Calculate the (non-linear) SNR from the sent and received symbols.
- Params x:
signal vector
- Params y:
signal + noise vector
- mokka.utils.export_constellation(output_file, constellation)
Export a constellation to a csv file.
- Parameters:
output_file – path to file
constellation – tensor of complex constellation points
- Returns:
- mokka.utils.hex2bits(hexs, m)
Convert list of hex strings to their bit representation MSB first.
- Parameters:
hexs – list of hex strings
m – bit-width per hex
- Returns:
array of bit arrays
- mokka.utils.ints2bits(ints, m)
Convert integers to their bit representations MSB first.
- Parameters:
ints – array of ints
m – bit-width per int
- Returns:
array of bit arrays
- mokka.utils.plot_bitwise_decision_regions(axs, demapper, num_samples=10000, meshgrid=False, additional_args=None, sample_radius=1.2)
Plot the bitwise decision regions of the demapper.
This is done by either sampling random points within a radius or using a meshgrid to sample points along the real and imaginary axis with a fixed spacing.
- Parameters:
axs – Matplotlib axis
demapper – demapper object
num_samples – number of samples in total or per axis is meshgrid is used
meshgrid – Use a meshgrid to sample the 2D area
additional_args – additional arguments to provide to the demapper
sample_radius – either the radius or the maximum amplitude for meshgrid
- mokka.utils.plot_classifier(ax, class_fn, range_x, range_y, points_x, points_y)
Plot classifier regions.
- Params ax:
matplotlib axis
- mokka.utils.plot_constellation(ax, constellation, label=True, keep=False, color=None, size=2, probabilities=None, label_type='hex')
Plot constellation points.
- Parameters:
ax – matplotlib axis
constellation – Constellation points in the order of their bitlabels
label – Switch to plot labels
keep – Keep existing drawing on the axis
color – Color for the constellation points
size – Size of the constellation points
probabilities – scale the size of the constellation according to their probability.
label_type – Hexadecimal or bitstring labels
- Returns:
axis
- mokka.utils.plot_scatter(ax, samples, labels)
Scatter plot a bunch of samples with labels.
- Params ax:
matplotlib axis
- Params samples:
complex samples to plot
- Params labels:
list of labels assigning a label per sample
- mokka.utils.pow2db(y)
Calculate the power in decibel.
- Parameters:
y – power in linear units [W]
- Returns:
power in decibel [dBW]
- mokka.utils.pow2dbm(y)
Calculate the power in dBm.
- Parameters:
y – power in linear units [W]
- Returns:
power in dBm [dBm]
- mokka.utils.setup_logging(level, component='')
Configure the Python logging module to print logs for given component and minimum level on stdout.
- Parameters:
level – A level from the logging module as minimum level
component – The parent component for which all logs should be displayed.
- mokka.utils.setup_plot(title)
Create a figure and axes.
- Params title:
Title of the figure
- mokka.utils.sigma_phi(linewidth, symbolrate)
Calculate \(\sigma_{\phi}\) given a laser linewidth and symbol rate.
- Parameters:
linewidth – laser linewidth \(\Delta f\) [Hz]
symbolrate – symbol rate \(R_{\mathrm{sym}}\) [Bd]
- Returns:
\(\sqrt{2 \pi \Delta f / R_{\mathrm{sym}}}\)
- mokka.utils.wavelength(D, beta2)
Calculate the wavelength from \(\beta_2\) and the dispersion coefficient.
- Parameters:
D – Dispersion coefficient [ps/nm/km]
beta2 – Group velocity dispersion [ps**2/km]
- Param:
returns wavelength of optical carrier [nm]
This sub-module provides decorators for use in mokka.
- mokka.utils.decorators.deprecated(reason)
Mark functions as deprecated.
It will result in a warning being emitted when the function is used.
- Parameters:
reason – Human readable reason for deprecation of function or class