8 - Using Callables


Tutorial - Callables

Callables allow you to define your own functions for calculating a few of the style properties for stars: size, alpha (opacity), color, and their labels. DSOs support callables for alpha and labels only. Starplot has a few basic callables built-in, but you can also create your own.

Here's an example that uses the built-in callable color_by_bv to create an optic plot of Antares that colorizes the stars based on their B-V index (Antares B-V is 1.83 so it appears red/orange in the sky):

from datetime import datetime

from pytz import timezone

from starplot import Star, optics, styles, callables

tonight = datetime.now(timezone("America/Los_Angeles")).replace(hour=21)

style = styles.PlotStyle().extend(
    styles.extensions.GRAYSCALE_DARK,
    styles.extensions.OPTIC,
)

antares = Star.get(name="Antares")

p = antares.create_optic(
    lat=32.97,
    lon=-117.038611,
    dt=tonight,
    optic=optics.Binoculars(
        magnification=10,
        fov=65,
    ),
    style=style,
    raise_on_below_horizon=False,
)

p.stars(
    where=[Star.magnitude < 12],
    where_labels=[Star.magnitude < 8],
    bayer_labels=True,
    catalog="big-sky-mag11",
    color_fn=callables.color_by_bv,  # <-- here's where we specify the callable
)

p.export("tutorial_08.png", padding=0)

For more details on using callables and an example of how to create your own, check out the reference page.

In the next section, we'll learn where to go from here...