Apply atmosphere overlay ON TOP of moon, add overcast fallback

The core mental model was wrong: clouds are between the observer and
the moon, so they occlude the disk — they don't sit behind it.

moon_composite.py:
  _make_east_sky_backdrop() → _make_atmosphere_layer()
  render_phase_closeup() pipeline is now:
    1. Black background
    2. NASA moon disk centred (correct phase / libration / shadows)
    3. East frame scaled + blurred → composited OVER the disk at
       atmosphere_opacity (0.0 = clear, 0.68 = heavy overcast)
  Parameters: east_sky_enabled/blur → atmosphere_opacity/blur

moon_phase_monthly.py:
  _atmosphere_opacity_from_quality() maps detection quality to opacity:
    quality >= 0.85 → 0.00 (clear)
    quality   0.70  → 0.20 (light haze)
    quality   0.55  → 0.40 (notable cloud, still detected)
    quality   None  → 0.68 (no detection, heavy overcast)

  Frame scan now tracks two lists:
    qualifying     — frames passing quality + illumination (existing)
    above_horizon  — frames where moon is up but detection failed

  When qualifying is empty and MOON_CLOUDY_POST_ENABLED=true, the
  above-horizon frame closest to the exact phase moment is used with
  opacity 0.45–0.68.  The month is always represented — full moon,
  first quarter, and third quarter each get a post even in cloudy
  months, showing the moon as a faint glow behind cloud.

sky-cam.conf:
  MOON_EAST_SKY_ENABLED/BLUR → MOON_ATMOSPHERE_BLUR (opacity is
  computed automatically from quality, not configured directly)
  New: MOON_CLOUDY_POST_ENABLED=true

test_moon_composite.py:
  Generates three outputs at opacity 0.00 / 0.20 / 0.65 so the
  full opacity range is visible in one test run.

https://claude.ai/code/session_01HkTxpNSTWtViZzxbrbKytR
This commit is contained in:
Claude
2026-05-01 21:51:42 +00:00
parent 1425a6e5f4
commit c09b872f52
4 changed files with 180 additions and 143 deletions
+23 -15
View File
@@ -524,24 +524,32 @@ MOON_HEIGHT_PCT=0.92 # moon disk fills this fraction of frame heig
MOON_DIALAMOON_TARGET_PX=2048 # cached PNG longest side; downsampled on save
MOON_DIALAMOON_TIMEOUT_SEC=30
# East sky backdrop ───────────────────────────────────────────────────────────
# When east verifies a moon sighting, its full camera frame is scaled to
# output size and blurred heavily (GaussianBlur r ≈ output_width / 6) to
# produce an atmospheric backdrop behind the NASA moon disk.
# Atmospheric overlay ─────────────────────────────────────────────────────────
# East's camera frame is scaled to output size, blurred, and composited OVER
# the NASA moon disk. This is physically correct: clouds sit between the
# observer and the moon, so they occlude the disk rather than appear behind it.
#
# The blur removes RTSP artefacts, OSD text, and the wide-angle look while
# preserving the real sky colour, any cloud or haze gradients, and the dark
# tree/ground silhouette at the bottom of frame. The NASA moon is pasted
# sharp on top — the result looks like east shot it through a telephoto, with
# its actual sky that night as the background.
# Opacity is derived from the moon detection quality in that frame:
# quality ≥ 0.85 → 0% (clear sky — pure NASA render)
# quality 0.70 → 20% (light haze)
# quality 0.55 → 40% (notable cloud, moon still detected)
# quality < 0.55 → 4065% (overcast fallback — see MOON_CLOUDY_POST_ENABLED)
# no detection → 68% (heavy overcast)
#
# This is the honest solution to "east doesn't capture high-res clouds": east's
# real atmospheric fingerprint (dark and clear, softly hazy, or cloud-diffused)
# becomes the background without pretending to photograph detail that isn't there.
# blur radius: 0 = auto (output_width / 10); set in px to override.
#MOON_ATMOSPHERE_BLUR=0
#
# Set false to use a plain black background instead (original behaviour).
MOON_EAST_SKY_ENABLED=true
#MOON_EAST_SKY_BLUR=0 # blur radius in px; 0 = auto (output_width / 6)
# Cloudy-month fallback ───────────────────────────────────────────────────────
# If no frame in the collection window passes the quality + illumination
# thresholds, the script normally skips posting that month. With
# MOON_CLOUDY_POST_ENABLED=true it instead finds the above-horizon frame
# closest to the exact phase moment, applies a heavy atmospheric overlay
# (opacity 0.450.68), and posts the month anyway — the moon shows as a faint
# glow behind cloud rather than being absent entirely.
#
# This applies to all three phases: full, first-quarter, third-quarter.
# Caption will read "cloud cover — YYYY-MM-DD — NASA SVS Dial-a-Moon".
MOON_CLOUDY_POST_ENABLED=true
# ── Mattermost — daily sunrise upload ─────────────────────────────────────────
# mattermost_url, access_token, channel_id go in .env (see bottom of this file).