Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plot_schedule_airmass with show_night=True is immensely slow #539

Closed
michaelbaisch opened this issue Mar 3, 2023 · 0 comments · Fixed by #540 · May be fixed by #559
Closed

plot_schedule_airmass with show_night=True is immensely slow #539

michaelbaisch opened this issue Mar 3, 2023 · 0 comments · Fixed by #540 · May be fixed by #559

Comments

@michaelbaisch
Copy link
Contributor

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.

@michaelbaisch michaelbaisch changed the title plot_schedule_airmass with 'show_night=True' is immensely slow plot_schedule_airmass with show_night=True is immensely slow Mar 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant