|
51 | 51 | # Streamlit App |
52 | 52 | # ─────────────────────────────────────────────── |
53 | 53 | st.set_page_config(page_title="Glasgow Starplot Viewer", page_icon="🌌") |
54 | | - |
55 | 54 | st.title("🌌 Glasgow Starplot Viewer") |
56 | 55 |
|
57 | 56 | # Sidebar: controls |
|
60 | 59 | obs_time = st.sidebar.time_input("Time", value=datetime.now().time()) |
61 | 60 | mag_limit = st.sidebar.slider("Magnitude Limit", 1, 8, 5) |
62 | 61 |
|
63 | | -# Session state to persist chart path |
| 62 | +# Extra option: fast vs HD |
| 63 | +quality = st.sidebar.radio("Quality", ["Fast (preview)", "HD (slower)"]) |
| 64 | +resolution = 1200 if quality == "Fast (preview)" else 2400 |
| 65 | + |
| 66 | +# Session state |
64 | 67 | if "chart_bytes" not in st.session_state: |
65 | 68 | st.session_state.chart_bytes = None |
66 | 69 |
|
| 70 | + |
| 71 | +# ─────────────────────────────────────────────── |
| 72 | +# Cached chart generator |
| 73 | +# ─────────────────────────────────────────────── |
| 74 | +@st.cache_data |
| 75 | +def generate_chart(plot_type, dt, mag_limit, resolution): |
| 76 | + if plot_type == "Horizon": |
| 77 | + return make_horizon_plot(dt=dt, mag_limit=mag_limit, resolution=resolution) |
| 78 | + else: |
| 79 | + return make_zenith_plot(dt=dt, mag_limit=mag_limit, resolution=resolution) |
| 80 | + |
| 81 | + |
67 | 82 | # ─────────────────────────────────────────────── |
68 | 83 | # Generate chart button |
69 | 84 | # ─────────────────────────────────────────────── |
70 | | -# Generate chart |
71 | 85 | if st.sidebar.button("Generate Chart"): |
72 | 86 | tz = ZoneInfo("Europe/London") |
73 | 87 | dt = datetime.combine(obs_date, obs_time).replace(tzinfo=tz) |
74 | 88 |
|
75 | 89 | with st.spinner("Generating chart, please wait..."): |
76 | | - if plot_type == "Horizon": |
77 | | - img_bytes = make_horizon_plot(dt=dt, mag_limit=mag_limit) |
78 | | - else: |
79 | | - img_bytes = make_zenith_plot(dt=dt, mag_limit=mag_limit) |
| 90 | + img_bytes = generate_chart(plot_type, dt, mag_limit, resolution) |
80 | 91 |
|
81 | 92 | st.session_state.chart_bytes = img_bytes |
82 | 93 | st.success("✅ Chart generated!") |
83 | 94 |
|
| 95 | + |
84 | 96 | # ─────────────────────────────────────────────── |
85 | 97 | # Display chart + download button |
86 | 98 | # ─────────────────────────────────────────────── |
|
0 commit comments