krz/moonrise

Night-sky companion for iPhone, Apple Watch and Vision Pro: what's up tonight, the Moon, planets, launches and missions, and a Library of the solar system. SwiftUI app with a Cloudflare Workers backend. astronomy cloudflare-workers ios night-sky space swiftui visionos watchos

Commit f2a4ee5c57

f2a4ee5c574957c5fc77730e08b8c9f6b2f20004

parent: 28452ecc79

Unsigned

cmc <hello@cleberg.net> · 2026-10-22 03:19 UTC

Eclipse: photographer cues and exposure guide (!111)

- `EclipseTimeline(…, photographer:)`: 
  - total, glasses-off allowed: C2 − 30 s "Cameras: filters stay on through the diamond ring."; C2 cue ends "glasses off, and filters off cameras."
  - total, glasses-off withheld (short, imprecise fix, Sun down): C2 cue ends "Filters stay on."; no filters-off cue.
  - annular or partial: first-contact cue adds "Filters stay on cameras the whole time too."
  - C3 − 15 s "Glasses on, and filters back on cameras and binoculars." is unchanged and always present.
- `EclipseExposure`: Espenak's Solar Eclipse Exposure Guide (NASA GSFC, 1996), Q values from its Table 2, t = f²/(ISO × 2^Q), nearest whole stop between 1/4000 and 2 min; credit shown.
- Eclipse screen: "Photographer cues" toggle (`eclipsePhotographer`, off) and an exposure guide (ISO 100–1600, f/2.8–16); totality rows only for a total eclipse.
- Tests: filters come off only with the glasses-off cue and never when it is withheld; exposure values against the table. SkyEngine tests pass; iOS builds.

Layout: unified · split

App/Sources/EclipseDayScreen.swift +6 −3
@@ -19,6 +19,7 @@ struct EclipseDayScreen: View {
1919 @State private var player = CuePlayer()
2020 @State private var spoken: EclipseTimeline.Cue?
2121 @AppStorage(SettingsKey.locationMode) private var locationMode = "current"
22 @AppStorage(SettingsKey.eclipsePhotographer) private var photographer = false
2223 @Environment(\.dismiss) private var dismiss
2324
2425 private let ink = Color(red: 0.95, green: 0.95, blue: 0.93)
@@ -56,9 +57,11 @@ struct EclipseDayScreen: View {
5657 .navigationBarTitleDisplayMode(.inline)
5758 .toolbar { ToolbarItem(placement: .confirmationAction) { Button("Done") { dismiss() } } }
5859 }
59 .task(id: [site.latitude, site.longitude, site.height, (fix?.accuracy ?? .infinity) < EclipseTimeline.maximumAccuracy ? 1 : 0]) {
60 let date = date, site = site, accuracy = fix?.accuracy
61 let t = await Task.detached { LocalEclipse.at(site, near: date).flatMap { try? EclipseTimeline($0, observer: site, accuracy: accuracy) } }.value
60 .task(id: [site.latitude, site.longitude, site.height, (fix?.accuracy ?? .infinity) < EclipseTimeline.maximumAccuracy ? 1 : 0, photographer ? 1 : 0]) {
61 let date = date, site = site, accuracy = fix?.accuracy, photographer = photographer
62 let t = await Task.detached {
63 LocalEclipse.at(site, near: date).flatMap { try? EclipseTimeline($0, observer: site, accuracy: accuracy, photographer: photographer) }
64 }.value
6265 timeline = t
6366 if rehearsal, shift == nil, let t { shift = t.rehearsalStart.timeIntervalSinceNow }
6467 }
App/Sources/EclipseScreen.swift +7
@@ -22,6 +22,7 @@ struct EclipseScreen: View {
2222 /// Started when the safety note closes.
2323 @State private var pending: Day?
2424 @AppStorage(SettingsKey.eclipseSafetyShown) private var safetyShown = false
25 @AppStorage(SettingsKey.eclipsePhotographer) private var photographer = false
2526 @AppStorage(SettingsKey.locationMode) private var locationMode = "current"
2627 @Environment(\.dismiss) private var dismiss
2728
@@ -54,6 +55,7 @@ struct EclipseScreen: View {
5455 if let timeline {
5556 SunDiagram(timeline: timeline, ink: ink, accent: accent)
5657 dayTools(timeline)
58 ExposureGuide(total: timeline.eclipse.kind == "Total", accent: accent)
5759 }
5860 }
5961 .padding(20)
@@ -162,6 +164,11 @@ struct EclipseScreen: View {
162164 if let activityNote { Text(activityNote).font(.footnote).dimmed(0.7) }
163165 Text("The countdown speaks each cue and taps at the contacts while Moonrise is open, and keeps the screen on.")
164166 .font(.footnote).dimmed(0.7)
167 Toggle("Photographer cues", isOn: $photographer).tint(accent)
168 Text(t.eclipse.kind == "Total"
169 ? "Adds camera filter cues. Filters come off only with the glasses-off cue, and go back on 15 s before third contact."
170 : "Adds camera filter cues. This eclipse is not total here, so filters stay on the whole time.")
171 .font(.footnote).dimmed(0.7)
165172 }
166173 .tint(accent)
167174 }
App/Sources/ExposureGuide.swift added +37
@@ -0,0 +1,37 @@
1import SkyEngine
2import SwiftUI
3
4/// Shutter speeds for the partial phases (through the filter) and, for a total eclipse, the features of totality.
5struct ExposureGuide: View {
6 var total: Bool
7 var accent: Color
8 @AppStorage("exposureISO") private var iso = 100.0
9 @AppStorage("exposureFNumber") private var fNumber = 8.0
10
11 private let isos: [Double] = [100, 200, 400, 800, 1600]
12 private let fNumbers: [Double] = [2.8, 4, 5.6, 8, 11, 16]
13
14 var body: some View {
15 VStack(alignment: .leading, spacing: 10) {
16 Text("Exposure guide").font(.caption2.weight(.medium)).textCase(.uppercase).tracking(0.8).dimmed(0.6)
17 HStack {
18 Picker("ISO", selection: $iso) { ForEach(isos, id: \.self) { Text("ISO \(Int($0))").tag($0) } }
19 Picker("Aperture", selection: $fNumber) { ForEach(fNumbers, id: \.self) { Text("f/\($0.formatted())").tag($0) } }
20 }
21 .pickerStyle(.menu).tint(accent)
22 Grid(alignment: .leading, horizontalSpacing: 16, verticalSpacing: 6) {
23 ForEach(EclipseExposure.partial + (total ? EclipseExposure.totality : [])) { s in
24 GridRow {
25 Text(s.name)
26 Text(EclipseExposure.shutter(fNumber: fNumber, iso: iso, q: s.q) ?? "–").monospacedDigit()
27 .gridColumnAlignment(.trailing)
28 }
29 }
30 }
31 .font(.footnote)
32 Text((total ? "Partial phases through the filter only; the rest in totality, filter off. " : "Filter on the whole time. ") +
33 "Bracket a stop or two either side. " + EclipseExposure.credit)
34 .font(.footnote).dimmed(0.7)
35 }
36 }
37}
App/Sources/SettingsScreen.swift +2
@@ -27,6 +27,8 @@ enum SettingsKey {
2727 static let cloudForecast = "cloudForecast"
2828 /// The eclipse eye-safety note has been shown before a countdown or rehearsal.
2929 static let eclipseSafetyShown = "eclipseSafetyShown"
30 /// Camera filter cues in the eclipse-day countdown.
31 static let eclipsePhotographer = "eclipsePhotographer"
3032}
3133
3234struct City: Hashable, Identifiable {
Packages/MoonriseKit/Sources/SkyEngine/EclipseExposure.swift added +49
@@ -0,0 +1,49 @@
1import Foundation
2
3/// Exposure times for eclipse photography from F. Espenak's Solar Eclipse Exposure Guide (NASA GSFC, 1996):
4/// t = f² / (ISO × 2^Q), with Q the subject's brightness exponent.
5public enum EclipseExposure {
6 public struct Subject: Sendable, Identifiable {
7 public var name: String
8 public var q: Int
9 /// Partial phases are photographed through the filter; everything else only in totality.
10 public var filtered: Bool
11 public var id: String { name }
12 }
13
14 public static let partial = [
15 Subject(name: "Partial phases, ND 4.0 filter", q: 11, filtered: true),
16 Subject(name: "Partial phases, ND 5.0 filter", q: 8, filtered: true),
17 ]
18
19 public static let totality = [
20 Subject(name: "Baily's beads", q: 11, filtered: false),
21 Subject(name: "Chromosphere", q: 10, filtered: false),
22 Subject(name: "Prominences", q: 9, filtered: false),
23 Subject(name: "Corona, 0.1 solar radii", q: 7, filtered: false),
24 Subject(name: "Corona, 0.2 solar radii; diamond ring", q: 5, filtered: false),
25 Subject(name: "Corona, 0.5 solar radii", q: 3, filtered: false),
26 Subject(name: "Corona, 1 solar radius", q: 1, filtered: false),
27 Subject(name: "Corona, 2 solar radii", q: 0, filtered: false),
28 Subject(name: "Corona, 4 solar radii", q: -1, filtered: false),
29 Subject(name: "Corona, 8 solar radii", q: -3, filtered: false),
30 ]
31
32 public static let credit = "After F. Espenak, Solar Eclipse Exposure Guide (NASA GSFC, 1996)."
33
34 /// Seconds.
35 public static func time(fNumber: Double, iso: Double, q: Int) -> Double {
36 fNumber * fNumber / (iso * pow(2, Double(q)))
37 }
38
39 /// Whole-stop shutter speeds in seconds, as in the guide.
40 static let speeds: [Double] = [1 / 4000, 1 / 2000, 1 / 1000, 1 / 500, 1 / 250, 1 / 125, 1 / 60, 1 / 30, 1 / 15, 1 / 8, 1 / 4, 1 / 2, 1, 2, 4, 8, 15, 30, 60, 120]
41
42 /// The nearest whole-stop speed, "1/250" or "2 s"; nil outside 1/4000 to 2 minutes.
43 public static func shutter(fNumber: Double, iso: Double, q: Int) -> String? {
44 let t = time(fNumber: fNumber, iso: iso, q: q)
45 guard t >= speeds.first! / 1.5, t <= speeds.last! * 1.5,
46 let s = speeds.min(by: { abs(log2($0 / t)) < abs(log2($1 / t)) }) else { return nil }
47 return s < 1 ? "1/\(Int((1 / s).rounded()))" : "\(Int(s)) s"
48 }
49}
Packages/MoonriseKit/Sources/SkyEngine/EclipseTimeline.swift +11 −8
@@ -45,7 +45,8 @@ public struct EclipseTimeline: Sendable {
4545 public var glassesOffWithheld: Withheld?
4646
4747 /// `accuracy`: horizontal accuracy of the location fix in metres, or nil for a chosen place.
48 public init(_ eclipse: LocalEclipse, observer: Observer, accuracy: Double?) throws {
48 /// `photographer` adds camera filter cues; filters come off only with the glasses-off cue.
49 public init(_ eclipse: LocalEclipse, observer: Observer, accuracy: Double?, photographer: Bool = false) throws {
4950 self.eclipse = eclipse
5051 self.observer = observer
5152 var named = [("C1", eclipse.partialBegin)]
@@ -64,17 +65,18 @@ public struct EclipseTimeline: Sendable {
6465 } else if contacts[1].sun.altitude <= 0 {
6566 glassesOffWithheld = .sunDown
6667 }
67 cues = Self.script(eclipse, withheld: glassesOffWithheld).sorted { $0.date < $1.date }
68 cues = Self.script(eclipse, withheld: glassesOffWithheld, photographer: photographer).sorted { $0.date < $1.date }
6869 }
6970
70 static func script(_ e: LocalEclipse, withheld: Withheld?) -> [Cue] {
71 static func script(_ e: LocalEclipse, withheld: Withheld?, photographer: Bool = false) -> [Cue] {
7172 func cue(_ date: Date, _ text: String, _ haptic: Haptic = .tap, warning: Bool = false) -> Cue {
7273 Cue(date: date, text: text, haptic: haptic, warning: warning)
7374 }
7475 var cues: [Cue] = []
76 let filtersStay = photographer ? " Filters stay on." : ""
7577 guard e.kind == "Total", let c2 = e.centralBegin, let c3 = e.centralEnd else {
7678 let annular = e.kind == "Annular"
77 cues.append(cue(e.partialBegin, "First contact. This eclipse is \(annular ? "annular" : "partial") here, so keep your glasses on the whole time.", warning: true))
79 cues.append(cue(e.partialBegin, "First contact. This eclipse is \(annular ? "annular" : "partial") here, so keep your glasses on the whole time." + (photographer ? " Filters stay on cameras the whole time too." : ""), warning: true))
7880 if annular, let c2 = e.centralBegin, let c3 = e.centralEnd {
7981 cues.append(cue(c2, "The ring of the Sun is complete. Glasses stay on.", .long))
8082 cues.append(cue(c3, "The ring is breaking. Glasses stay on."))
@@ -89,17 +91,18 @@ public struct EclipseTimeline: Sendable {
8991 if c2.timeIntervalSince(e.partialBegin) > 360 { cues.append(cue(c2.addingTimeInterval(-300), "Five minutes to totality.")) }
9092 cues.append(cue(c2.addingTimeInterval(-120), "Two minutes. Lay out a white sheet and watch it for shadow bands."))
9193 cues.append(cue(c2.addingTimeInterval(-60), "One minute to totality. Glasses stay on.", .double))
94 if photographer { cues.append(cue(c2.addingTimeInterval(-30), "Cameras: filters stay on through the diamond ring.")) }
9295 cues.append(cue(c2.addingTimeInterval(-15), "Watch for Baily's beads and the diamond ring, through your glasses.", .double))
9396 for n in 1...5 { cues.append(cue(c2.addingTimeInterval(-Double(n)), "\(n)")) }
9497 switch withheld {
9598 case nil:
96 cues.append(cue(c2, "Totality. Once no sunlight shows through your glasses, not even one bead, glasses off.", .long))
99 cues.append(cue(c2, "Totality. Once no sunlight shows through your glasses, not even one bead, glasses off" + (photographer ? ", and filters off cameras." : "."), .long))
97100 case .short:
98 cues.append(cue(c2, "Totality here is under \(Int(Self.minimumTotality)) seconds. Keep your glasses on.", .long, warning: true))
101 cues.append(cue(c2, "Totality here is under \(Int(Self.minimumTotality)) seconds. Keep your glasses on." + filtersStay, .long, warning: true))
99102 case .imprecise:
100 cues.append(cue(c2, "Totality is due, but your position is not precise enough to call it. Keep your glasses on.", .long, warning: true))
103 cues.append(cue(c2, "Totality is due, but your position is not precise enough to call it. Keep your glasses on." + filtersStay, .long, warning: true))
101104 case .sunDown, .partial:
102 cues.append(cue(c2, "Keep your glasses on.", .long, warning: true))
105 cues.append(cue(c2, "Keep your glasses on." + filtersStay, .long, warning: true))
103106 }
104107 let duration = c3.timeIntervalSince(c2)
105108 if duration >= 60 { cues.append(cue(c3.addingTimeInterval(-30), "Thirty seconds of totality left.")) }
Packages/MoonriseKit/Tests/SkyEngineTests/EclipseTimelineTests.swift +26
@@ -82,3 +82,29 @@ private func offCues(_ t: EclipseTimeline) -> [EclipseTimeline.Cue] { t.cues.fil
8282 let path = try t.sunPath(every: 300)
8383 #expect(path.first?.date == t.eclipse.partialBegin && path.last?.date == t.eclipse.partialEnd)
8484}
85
86@Test func photographerFiltersComeOffOnlyWithGlasses() throws {
87 let site = try #require(LocalEclipse.at(tarifa, near: peak2027))
88 let precise = try EclipseTimeline(site, observer: tarifa, accuracy: 5, photographer: true)
89 let c2 = try #require(precise.eclipse.centralBegin)
90 let off = precise.cues.filter { $0.text.contains("filters off") }
91 #expect(off.map(\.date) == [c2])
92 #expect(off.first?.text.contains("glasses off") == true)
93 #expect(precise.cues.contains { $0.date == c2.addingTimeInterval(-30) && $0.text.contains("filters stay on") })
94 for accuracy in [500.0, nil] {
95 let withheld = try EclipseTimeline(site, observer: tarifa, accuracy: accuracy, photographer: true)
96 #expect(!withheld.cues.contains { $0.text.contains("filters off") })
97 #expect(withheld.cues.contains { $0.date == c2 && $0.text.hasSuffix("Filters stay on.") })
98 }
99 let plain = try EclipseTimeline(site, observer: tarifa, accuracy: 5)
100 #expect(!plain.cues.contains { $0.text.contains("filters off") || $0.text.contains("Filters stay on") })
101}
102
103@Test func exposureMatchesEspenaksTable() {
104 // Table 2 at ISO 100, f/8: corona at 1 solar radius 1/4, at 8 solar radii 4 s; ND 5.0 partial phases
105 // 1/400 s, so 1/500. Faster than 1/4000 is a dash in the table, nil here.
106 #expect(EclipseExposure.shutter(fNumber: 8, iso: 100, q: 1) == "1/4")
107 #expect(EclipseExposure.shutter(fNumber: 8, iso: 100, q: -3) == "4 s")
108 #expect(EclipseExposure.shutter(fNumber: 8, iso: 100, q: 8) == "1/500")
109 #expect(EclipseExposure.shutter(fNumber: 2.8, iso: 100, q: 11) == nil)
110}