Skip to content

plot_schedule_airmass with show_night=True is immensely slow #539

@michaelbaisch

Description

@michaelbaisch

Greetings,

I've noticed that running plot_schedule_airmass() is very slow when I activate the argument show_night=True, I'm talking like 8 seconds for a very simple plot. As this comment realized there is a lot of overlap here. My suggestion is calculating all midnights first and coloring in the nights once:

if show_night:
        midnights = []
        test_time = schedule.start_time
        while (midnight := schedule.observer.midnight(test_time, which='next')) < schedule.end_time:
            test_time = midnight + 6 * u.hour
            midnights.append(midnight)

        # Ceating darker bands
        for midnight in midnights:
            previous_sunset = schedule.observer.sun_set_time(
                midnight, which='previous')
            next_sunrise = schedule.observer.sun_rise_time(
                midnight, which='next')

            previous_twilight = schedule.observer.twilight_evening_astronomical(
                midnight, which='previous')
            next_twilight = schedule.observer.twilight_morning_astronomical(
                midnight, which='next')

            plt.axvspan(previous_sunset.plot_date, previous_twilight.plot_date,
                        facecolor='lightgrey', alpha=0.5)
            plt.axvspan(previous_twilight.plot_date, next_twilight.plot_date,
                        facecolor='lightgrey', alpha=0.7)
            plt.axvspan(next_twilight.plot_date, next_sunrise.plot_date,
                        facecolor='lightgrey', alpha=0.5)

This makes it a lot faster.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions