pychopmarg.<misc.>

Miscellaneous modules in the PyChOpMarg package.

cli

Main Entry Point for PyChOpMarg when using the CLI.

Original author: David Banas <capn.freako@gmail.com>

Original date: March 25, 2024

Copyright (c) 2024 David Banas; all rights reserved World wide.

common

Definitions common to all PyChOpMarg modules.

Original author: David Banas <capn.freako@gmail.com>

Original date: March 3, 2024

Copyright (c) 2024 David Banas; all rights reserved World wide.

pychopmarg.common.PI = 3.14159

Value of Pi

pychopmarg.common.TWOPI = 6.28318

2 * Pi

class pychopmarg.common.OptMode(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Linear equalization optimization mode.

PRZF = 1
MMSE = 2
class pychopmarg.common.NormMode(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Tap weight normalization mode.

P8023dj = 1

As per standard (i.e. - clip then renormalize for unit amplitude pulse response.)

Scaled = 2

Uniformly and minimally scaled to bring tap weights just within their limits.

Unaltered = 3

Use constrained optimization solution, unchanged.

UnitDcGain = 4

Tap weights are uniformly scaled, to yield unity gain at d.c.

excel

MS Excel importing utilities for PyChOpMarg.

Original author: David Banas <capn.freako@gmail.com>

Original date: January 17, 2025

Copyright (c) 2025 David Banas; all rights reserved World wide.

pychopmarg.excel.first(f: Callable[[T1], T2]) Callable[[tuple[T1, T3]], tuple[T2, T3]][source]

Translation of Haskell first function.

pychopmarg.excel.second(f: Callable[[T1], T2]) Callable[[tuple[T3, T1]], tuple[T3, T2]][source]

Translation of Haskell second function.

pychopmarg.excel.compose(*functions)[source]

Function composition w/ NO TYPE CHECKING!

pychopmarg.excel.apply2(f: Callable[[T1], T2], g: Callable[[T3], T4]) Callable[[tuple[T1, T3]], tuple[T2, T4]][source]

Translation of Haskell *** operator.

pychopmarg.excel.alternative(f: Callable[[T1], T2], g: Callable[[T1], T2], x: T1) T2[source]

Try f and if it fails apply g.

Parameters:
  • f – First function to try.

  • g – Second function to try.

  • x – Function argument.

Notes

1. It would be preferable to omit x from the argument list and return a function, instead of a value, but we can’t do that, because Python doesn’t allow a try/except block inside a lambda.

pychopmarg.excel.parse_Mrange(mStr: str) ndarray[Any, dtype[ScalarType]][source]

Parse a string containing an M-code range.

pychopmarg.excel.parse_Mfloat(mStr: str) ndarray[Any, dtype[ScalarType]][source]

Parse a string containing a single M-code number.

pychopmarg.excel.parse_Mfloats(mStr: str) ndarray[Any, dtype[ScalarType]][source]

Parse a string containing a repeated M-code number.

pychopmarg.excel.parse_Mlist(mStr: str) ndarray[Any, dtype[ScalarType]][source]

Parse a string containing an M-code list of numbers.

pychopmarg.excel.parse_Marray(mStr: str) ndarray[Any, dtype[ScalarType]][source]

Parse a string containing either an M-code range or list of numbers.

pychopmarg.excel.parse_Mmatrix(mStr: str) ndarray[Any, dtype[ScalarType]][source]

Parse a string containing an M-code matrix of numbers.

pychopmarg.excel.match_ignored_field_name_prefix(mName: str) bool[source]

Match MATLAB field name prefix to any ignored field name.

pychopmarg.excel.cfg_trans(com_cfg: ndarray[Any, dtype[ScalarType]]) dict[str, Any][source]

Translate/filter the names/values of the given 2D NumPy array.

pychopmarg.excel.get_com_params(cfg_file: Path) COMParams[source]

Read a COM configuration XLS file and return an equivalent COMParams instance.

matlab

General MATLAB utilities for PyChOpMarg.

Original author: David Banas <capn.freako@gmail.com>

Original date: January 17, 2025

Copyright (c) 2025 David Banas; all rights reserved World wide.

pychopmarg.matlab.run_com_matlab(chnl_sets: list[tuple[str, dict[str, list[Path]]]], cfg_sheet: Path, matlab_exec: Path) dict[str, dict[str, dict[str, Any]]][source]

Run COM on a list of grouped channel sets, using the MATLAB code.

Parameters:
  • chnl_sets

    List of pairs, each consisting of:

    • ch_grp_name: The group name for this list of channel sets.

    • ch_sets: List of channel sets to run.

  • cfg_sheet – Path to MS Excel configuration spreadsheet.

  • matlab_exec – Path to MATLAB executable.

Returns:

Dictionary, indexed by channel group name, containing dictionaries of MATLAB COM results, indexed by channel set name.

plot

General plotting utilities for PyChOpMarg.

Original author: David Banas <capn.freako@gmail.com>

Original date: January 17, 2025

Copyright (c) 2025 David Banas; all rights reserved World wide.

class pychopmarg.plot.ZoomMode(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Plot zoom extent.

FULL = 1
ISI = 2
PULSE = 3
MANUAL = 4
RELATIVE = 5
pychopmarg.plot.plot_group_samps(plot_func: Callable[[COM, str, str, str, dict[str, str], Any, Any], None], x_lbl: str, y_lbls: tuple[str, str], coms: list[tuple[str, dict[str, str], dict[str, dict[str, COM]]]], maxRows: int = 3, dx=4, dy=3, chnls_by_grp: dict[str, list[str]] | None = None, auto_yscale: bool = False) dict[str, list[str]][source]

Call the given plotting function for several randomly chosen channel sets from each available group.

Parameters:
  • plot_func

    The plotting function to use. Should take the following arguments:

    • com: The COM object to use for plotting.

    • grp: Channel set group name

    • lbl: Channel set name

    • name: COM set name

    • opts: Plotting options to use

    • ax1: First y-axis

    • ax2: Second y-axis

  • x_lbl – Label for x-axis

  • y_lbls – Pair of labels, one for each y-axis

  • coms

    List of tuples, each containing:

    • name: Identifying name,

    • opts: Plotting options to use,

    • coms: dictionary of COM objects to select from.

      Should be indexed first by group name then by channel set name.

Keyword Arguments:
  • maxRows – Maximum number of rows desired in resultant plot matrix. (Number of columns is equal to number of groups.) Default: 3

  • dx – Width of individual plots (in.) Default: 4

  • dy – Height of individual plots (in.) Default: 3

  • chnls_by_grp – Dictionary of key/value pairs of the form: <group name>: [<channel set name>]. (Used to enforce identical channel set choices across multiple calls.) Default: None

  • auto_yscale – When True, scale the y-axis to just accommodate the visible portion of the plotted waveforms. Default: False

Returns:

Dictionary containing lists of channel sets used by group name (for subsequent calls).

Raises:

KeyError – If there are any inconsistencies in dictionary key naming, either within the list of COMs given or between those COMs and the chnls_by_grp keyword argument, if provided.

pychopmarg.plot.plot_pulse_resps_gen(zoom: ZoomMode, noeq: bool = False, nopkg: bool = False, plot_ntwk: bool = True, xlims: tuple[float, float] | None = None) Callable[[COM, str, str, str, dict[str, str], Any, Any], None][source]

Generate a pulse response plotting function for use with plot_group_samps().

Parameters:

zoom – Zoom mode.

Keyword Arguments:
  • noeq – Plot unequalized pulse response when True. Default: False

  • nopkg – Plot raw channel pulse response when True. (Takes priority over noeq.) Default: False

  • plot_ntwk – Add SciKit-RF pulse response estimate to plot when True. (Only valid when either nopkg or noeq is True.) Default: True

  • xlims – X-axis min. & max., for use w/ zoom = MANUAL. Default: None

Returns:

Pulse response plotting function suitable for sending to plot_group_samps().

Todo

  1. Add a fourth pulse response option: pre-FFE.

pychopmarg.plot.plot_H(H: ndarray[Any, dtype[Comp]]) None[source]

Plot magnitude and phase of given frequency response.