"""
Interactive Satellite Link Animation
=====================================
HTML5 Canvas animation showing a satellite communicating with a ground station,
with toggleable impairment layers (atmosphere, rain, free-space loss, noise…).
"""
import streamlit as st
import streamlit.components.v1 as components
_ANIMATION_HTML = """
📡 Satellite Link Overview
Toggle each impairment to see how it affects the signal.
Cyan = Downlink (sat → ground).
Green = Uplink (ground → sat).
The signal strength bar shows the cumulative effect.
"""
def render():
"""Render the satellite link animation page."""
st.markdown("## 🛰️ Satellite Link — Interactive Animation")
st.markdown(
"Visualise how a signal travels from a **GEO satellite** to a "
"**ground station** and discover the impairments that degrade it. "
"Toggle each effect on/off to see the impact on signal strength."
)
st.divider()
components.html(_ANIMATION_HTML, height=680, scrolling=False)
# ── Pedagogical summary below the animation ──
st.divider()
st.markdown("### 📚 Understanding the Link Budget")
col1, col2 = st.columns(2)
with col1:
st.markdown("""
**Uplink & Downlink path:**
The signal travels ~36 000 km from a geostationary satellite to Earth.
Along the way it encounters multiple sources of degradation:
1. **Free-Space Path Loss** — the dominant factor, purely geometric (1/r²)
2. **Atmospheric gases** — O₂ and H₂O absorption (ITU-R P.676)
3. **Rain** — scattering & absorption, worst at Ka-band (ITU-R P.618)
4. **Ionosphere** — Faraday rotation, scintillation (ITU-R P.531)
""")
with col2:
st.markdown("""
**At the receiver:**
Even after the signal arrives, further degradation occurs:
5. **Thermal noise** — every component adds noise: $N = k \\cdot T_{sys} \\cdot B$
6. **Pointing loss** — antenna misalignment reduces gain
7. **Implementation losses** — ADC quantisation, filter roll-off, etc.
The **Shannon limit** $C = B \\log_2(1 + C/N)$ tells us the maximum
bit rate achievable given the remaining signal-to-noise ratio.
""")
with st.expander("🔗 Key ITU-R Recommendations"):
st.markdown("""
| Recommendation | Topic |
|:---:|:---|
| **P.618** | Rain attenuation & propagation effects for satellite links |
| **P.676** | Gaseous attenuation on terrestrial and slant paths |
| **P.531** | Ionospheric effects on radiowave propagation |
| **P.837** | Rainfall rate statistics for prediction models |
| **P.839** | Rain height model for prediction methods |
| **S.1428** | Reference satellite link for system design |
""")