Skip to content

linkbudget.waterfall_publisher

waterfall_publisher

waterfall_publisher.py

WaterfallPublisher -- renders the signal- and noise-power cascade ("waterfall") through the budget stages to an image file. The output format is taken from the file extension (.png, .svg, .pdf ...).

matplotlib is imported lazily inside WaterfallPublisher.publish, so it is only required when this publisher is actually used. Install it with pip install 'linkbudget-rf[plot]'.

SIGNAL_COLOR module-attribute

SIGNAL_COLOR = '#2b6cb0'

NOISE_COLOR module-attribute

NOISE_COLOR = '#c53030'

FILL_COLOR module-attribute

FILL_COLOR = '#2b6cb0'

WaterfallPublisher

WaterfallPublisher(fpath: str, title: str = 'Link Budget Cascade', figsize: tuple[float, float] = (11, 6), dpi: int = 140)

Bases: Publisher

Render the per-stage signal / noise power cascade to an image.

The shaded band between the signal and noise traces is the running SNR; stages carrying zero signal or noise power (-inf dBW) are drawn along the bottom of the axes.

Source code in linkbudget/waterfall_publisher.py
def __init__(self, fpath: str, title: str = "Link Budget Cascade",
             figsize: tuple[float, float] = (11, 6), dpi: int = 140) -> None:
    self.fpath = fpath
    self.title = title
    self.figsize = figsize
    self.dpi = dpi

fpath instance-attribute

fpath = fpath

title instance-attribute

title = title

figsize instance-attribute

figsize = figsize

dpi instance-attribute

dpi = dpi

publish

publish(data_list: StageList, power_units: str = 'W') -> None

Render the cascade to self.fpath (format from the extension).

Source code in linkbudget/waterfall_publisher.py
def publish(self, data_list: StageList, power_units: str = "W") -> None:
    """Render the cascade to ``self.fpath`` (format from the extension)."""
    # matplotlib is an optional dependency, only needed for this publisher
    import matplotlib  # pylint: disable=import-outside-toplevel
    matplotlib.use("Agg")
    import matplotlib.pyplot as plt  # pylint: disable=import-outside-toplevel

    fig, ax = plt.subplots(figsize=self.figsize)
    try:
        if data_list:
            self._draw(ax, data_list)
        else:
            ax.text(0.5, 0.5, "empty link budget", ha="center", va="center",
                    transform=ax.transAxes, color="#888888")
            ax.set_axis_off()
        ax.set_title(self.title)
        fig.tight_layout()
        fig.savefig(self.fpath, dpi=self.dpi)
    finally:
        plt.close(fig)