Skip to content

coming_path

coming_path #

coming_path — where the coming conditions travel through a chart, coloured by need.

WIDTH = 7.0 module-attribute #

The path's width, in points.

Mark = tuple[float, float, str | None] #

A point on the path, (x, y), with the text written beside it or None.

coming_path(axes, xy, need, marks=()) #

The coming path: grey where covered, orange where needed, its start ringed as now.

A nan point breaks the path (the sun set, say). Each mark is a dot, its text beside it.

coming = solar_position(site, forecast.times(span=timedelta(hours=24)))
guidance.coming_path(figure.axes, sky_xy(coming), 1.0 - sun.coverage(coming, taken))

Parameters:

Name Type Description Default
axes Axes

The chart to draw on.

required
xy ndarray

(n, 2) points in chart coordinates, in time order.

required
need ndarray

0–1 at each point: how much it still needs capturing.

required
marks Sequence[Mark]

Points to dot along the way, such as every hour.

()
Source code in capturegraph-recipes/capturegraph_recipes/scheduling/guidance/coming_path.py
def coming_path(
    axes: Axes,
    xy: np.ndarray,
    need: np.ndarray,
    marks: Sequence[Mark] = (),
) -> None:
    """The coming path: grey where covered, orange where needed, its start ringed as now.

    A ``nan`` point breaks the path (the sun set, say). Each mark is a dot, its
    text beside it.

    ```python
    coming = solar_position(site, forecast.times(span=timedelta(hours=24)))
    guidance.coming_path(figure.axes, sky_xy(coming), 1.0 - sun.coverage(coming, taken))
    ```

    Args:
        axes: The chart to draw on.
        xy: ``(n, 2)`` points in chart coordinates, in time order.
        need: 0–1 at each point: how much it still needs capturing.
        marks: Points to dot along the way, such as every hour.
    """
    from matplotlib.collections import LineCollection

    segments = np.stack([xy[:-1], xy[1:]], axis=1)
    drawn = np.isfinite(segments).all(axis=(1, 2))
    shade = need_colors(np.fmax(need[:-1], need[1:])[drawn])
    axes.add_collection(
        LineCollection(
            list(segments[drawn]),
            colors=list(shade),
            linewidths=WIDTH,
            capstyle="round",
            zorder=3,
        )
    )
    axes.plot([], [], color=NEEDED, linewidth=WIDTH, label="Still needed")
    axes.plot([], [], color=SATISFIED, linewidth=WIDTH, label="Covered")
    for x, y, text in marks:
        axes.plot(x, y, "o", color=INK, markersize=7, zorder=4)
        if text is not None:
            axes.annotate(
                text,
                (x, y),
                xytext=(8, 8),
                textcoords="offset points",
                fontsize=14,
                zorder=5,
            )
    start = xy[np.isfinite(xy).all(axis=1)]
    if len(start) and np.isfinite(xy[0]).all():
        axes.plot(
            *start[0],
            "o",
            markersize=22,
            markerfacecolor="none",
            markeredgecolor=INK,
            markeredgewidth=3,
            zorder=5,
            label="Now",
        )