Commit f2a4ee5c57
Unsigned
Layout: unified · split
App/Sources/EclipseDayScreen.swift +6 −3
| @@ -19,6 +19,7 @@ struct EclipseDayScreen: View { | |||
| 19 | @State private var player = CuePlayer() | 19 | @State private var player = CuePlayer() |
| 20 | @State private var spoken: EclipseTimeline.Cue? | 20 | @State private var spoken: EclipseTimeline.Cue? |
| 21 | @AppStorage(SettingsKey.locationMode) private var locationMode = "current" | 21 | @AppStorage(SettingsKey.locationMode) private var locationMode = "current" |
| 22 | @AppStorage(SettingsKey.eclipsePhotographer) private var photographer = false | ||
| 22 | @Environment(\.dismiss) private var dismiss | 23 | @Environment(\.dismiss) private var dismiss |
| 23 | 24 | ||
| 24 | private let ink = Color(red: 0.95, green: 0.95, blue: 0.93) | 25 | private let ink = Color(red: 0.95, green: 0.95, blue: 0.93) |
| @@ -56,9 +57,11 @@ struct EclipseDayScreen: View { | |||
| 56 | .navigationBarTitleDisplayMode(.inline) | 57 | .navigationBarTitleDisplayMode(.inline) |
| 57 | .toolbar { ToolbarItem(placement: .confirmationAction) { Button("Done") { dismiss() } } } | 58 | .toolbar { ToolbarItem(placement: .confirmationAction) { Button("Done") { dismiss() } } } |
| 58 | } | 59 | } |
| 59 | .task(id: [site.latitude, site.longitude, site.height, (fix?.accuracy ?? .infinity) < EclipseTimeline.maximumAccuracy ? 1 : 0]) { | 60 | .task(id: [site.latitude, site.longitude, site.height, (fix?.accuracy ?? .infinity) < EclipseTimeline.maximumAccuracy ? 1 : 0, photographer ? 1 : 0]) { |
| 60 | let date = date, site = site, accuracy = fix?.accuracy | 61 | let date = date, site = site, accuracy = fix?.accuracy, photographer = photographer |
| 61 | let t = await Task.detached { LocalEclipse.at(site, near: date).flatMap { try? EclipseTimeline($0, observer: site, accuracy: accuracy) } }.value | 62 | let t = await Task.detached { |
| 63 | LocalEclipse.at(site, near: date).flatMap { try? EclipseTimeline($0, observer: site, accuracy: accuracy, photographer: photographer) } | ||
| 64 | }.value | ||
| 62 | timeline = t | 65 | timeline = t |
| 63 | if rehearsal, shift == nil, let t { shift = t.rehearsalStart.timeIntervalSinceNow } | 66 | if rehearsal, shift == nil, let t { shift = t.rehearsalStart.timeIntervalSinceNow } |
| 64 | } | 67 | } |
App/Sources/EclipseScreen.swift +7
| @@ -22,6 +22,7 @@ struct EclipseScreen: View { | |||
| 22 | /// Started when the safety note closes. | 22 | /// Started when the safety note closes. |
| 23 | @State private var pending: Day? | 23 | @State private var pending: Day? |
| 24 | @AppStorage(SettingsKey.eclipseSafetyShown) private var safetyShown = false | 24 | @AppStorage(SettingsKey.eclipseSafetyShown) private var safetyShown = false |
| 25 | @AppStorage(SettingsKey.eclipsePhotographer) private var photographer = false | ||
| 25 | @AppStorage(SettingsKey.locationMode) private var locationMode = "current" | 26 | @AppStorage(SettingsKey.locationMode) private var locationMode = "current" |
| 26 | @Environment(\.dismiss) private var dismiss | 27 | @Environment(\.dismiss) private var dismiss |
| 27 | 28 | ||
| @@ -54,6 +55,7 @@ struct EclipseScreen: View { | |||
| 54 | if let timeline { | 55 | if let timeline { |
| 55 | SunDiagram(timeline: timeline, ink: ink, accent: accent) | 56 | SunDiagram(timeline: timeline, ink: ink, accent: accent) |
| 56 | dayTools(timeline) | 57 | dayTools(timeline) |
| 58 | ExposureGuide(total: timeline.eclipse.kind == "Total", accent: accent) | ||
| 57 | } | 59 | } |
| 58 | } | 60 | } |
| 59 | .padding(20) | 61 | .padding(20) |
| @@ -162,6 +164,11 @@ struct EclipseScreen: View { | |||
| 162 | if let activityNote { Text(activityNote).font(.footnote).dimmed(0.7) } | 164 | if let activityNote { Text(activityNote).font(.footnote).dimmed(0.7) } |
| 163 | Text("The countdown speaks each cue and taps at the contacts while Moonrise is open, and keeps the screen on.") | 165 | Text("The countdown speaks each cue and taps at the contacts while Moonrise is open, and keeps the screen on.") |
| 164 | .font(.footnote).dimmed(0.7) | 166 | .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) | ||
| 165 | } | 172 | } |
| 166 | .tint(accent) | 173 | .tint(accent) |
| 167 | } | 174 | } |
App/Sources/ExposureGuide.swift added +37
| @@ -0,0 +1,37 @@ | |||
| 1 | import SkyEngine | ||
| 2 | import SwiftUI | ||
| 3 | |||
| 4 | /// Shutter speeds for the partial phases (through the filter) and, for a total eclipse, the features of totality. | ||
| 5 | struct 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 { | |||
| 27 | static let cloudForecast = "cloudForecast" | 27 | static let cloudForecast = "cloudForecast" |
| 28 | /// The eclipse eye-safety note has been shown before a countdown or rehearsal. | 28 | /// The eclipse eye-safety note has been shown before a countdown or rehearsal. |
| 29 | static let eclipseSafetyShown = "eclipseSafetyShown" | 29 | static let eclipseSafetyShown = "eclipseSafetyShown" |
| 30 | /// Camera filter cues in the eclipse-day countdown. | ||
| 31 | static let eclipsePhotographer = "eclipsePhotographer" | ||
| 30 | } | 32 | } |
| 31 | 33 | ||
| 32 | struct City: Hashable, Identifiable { | 34 | struct City: Hashable, Identifiable { |
Packages/MoonriseKit/Sources/SkyEngine/EclipseExposure.swift added +49
| @@ -0,0 +1,49 @@ | |||
| 1 | import 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. | ||
| 5 | public 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 { | |||
| 45 | public var glassesOffWithheld: Withheld? | 45 | public var glassesOffWithheld: Withheld? |
| 46 | 46 | ||
| 47 | /// `accuracy`: horizontal accuracy of the location fix in metres, or nil for a chosen place. | 47 | /// `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 { | ||
| 49 | self.eclipse = eclipse | 50 | self.eclipse = eclipse |
| 50 | self.observer = observer | 51 | self.observer = observer |
| 51 | var named = [("C1", eclipse.partialBegin)] | 52 | var named = [("C1", eclipse.partialBegin)] |
| @@ -64,17 +65,18 @@ public struct EclipseTimeline: Sendable { | |||
| 64 | } else if contacts[1].sun.altitude <= 0 { | 65 | } else if contacts[1].sun.altitude <= 0 { |
| 65 | glassesOffWithheld = .sunDown | 66 | glassesOffWithheld = .sunDown |
| 66 | } | 67 | } |
| 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 } |
| 68 | } | 69 | } |
| 69 | 70 | ||
| 70 | static func script(_ e: LocalEclipse, withheld: Withheld?) -> [Cue] { | 71 | static func script(_ e: LocalEclipse, withheld: Withheld?, photographer: Bool = false) -> [Cue] { |
| 71 | func cue(_ date: Date, _ text: String, _ haptic: Haptic = .tap, warning: Bool = false) -> Cue { | 72 | func cue(_ date: Date, _ text: String, _ haptic: Haptic = .tap, warning: Bool = false) -> Cue { |
| 72 | Cue(date: date, text: text, haptic: haptic, warning: warning) | 73 | Cue(date: date, text: text, haptic: haptic, warning: warning) |
| 73 | } | 74 | } |
| 74 | var cues: [Cue] = [] | 75 | var cues: [Cue] = [] |
| 76 | let filtersStay = photographer ? " Filters stay on." : "" | ||
| 75 | guard e.kind == "Total", let c2 = e.centralBegin, let c3 = e.centralEnd else { | 77 | guard e.kind == "Total", let c2 = e.centralBegin, let c3 = e.centralEnd else { |
| 76 | let annular = e.kind == "Annular" | 78 | 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)) |
| 78 | if annular, let c2 = e.centralBegin, let c3 = e.centralEnd { | 80 | if annular, let c2 = e.centralBegin, let c3 = e.centralEnd { |
| 79 | cues.append(cue(c2, "The ring of the Sun is complete. Glasses stay on.", .long)) | 81 | cues.append(cue(c2, "The ring of the Sun is complete. Glasses stay on.", .long)) |
| 80 | cues.append(cue(c3, "The ring is breaking. Glasses stay on.")) | 82 | cues.append(cue(c3, "The ring is breaking. Glasses stay on.")) |
| @@ -89,17 +91,18 @@ public struct EclipseTimeline: Sendable { | |||
| 89 | if c2.timeIntervalSince(e.partialBegin) > 360 { cues.append(cue(c2.addingTimeInterval(-300), "Five minutes to totality.")) } | 91 | if c2.timeIntervalSince(e.partialBegin) > 360 { cues.append(cue(c2.addingTimeInterval(-300), "Five minutes to totality.")) } |
| 90 | cues.append(cue(c2.addingTimeInterval(-120), "Two minutes. Lay out a white sheet and watch it for shadow bands.")) | 92 | cues.append(cue(c2.addingTimeInterval(-120), "Two minutes. Lay out a white sheet and watch it for shadow bands.")) |
| 91 | cues.append(cue(c2.addingTimeInterval(-60), "One minute to totality. Glasses stay on.", .double)) | 93 | 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.")) } | ||
| 92 | cues.append(cue(c2.addingTimeInterval(-15), "Watch for Baily's beads and the diamond ring, through your glasses.", .double)) | 95 | cues.append(cue(c2.addingTimeInterval(-15), "Watch for Baily's beads and the diamond ring, through your glasses.", .double)) |
| 93 | for n in 1...5 { cues.append(cue(c2.addingTimeInterval(-Double(n)), "\(n)")) } | 96 | for n in 1...5 { cues.append(cue(c2.addingTimeInterval(-Double(n)), "\(n)")) } |
| 94 | switch withheld { | 97 | switch withheld { |
| 95 | case nil: | 98 | 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)) |
| 97 | case .short: | 100 | 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)) |
| 99 | case .imprecise: | 102 | 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)) |
| 101 | case .sunDown, .partial: | 104 | 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)) |
| 103 | } | 106 | } |
| 104 | let duration = c3.timeIntervalSince(c2) | 107 | let duration = c3.timeIntervalSince(c2) |
| 105 | if duration >= 60 { cues.append(cue(c3.addingTimeInterval(-30), "Thirty seconds of totality left.")) } | 108 | 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 | |||
| 82 | let path = try t.sunPath(every: 300) | 82 | let path = try t.sunPath(every: 300) |
| 83 | #expect(path.first?.date == t.eclipse.partialBegin && path.last?.date == t.eclipse.partialEnd) | 83 | #expect(path.first?.date == t.eclipse.partialBegin && path.last?.date == t.eclipse.partialEnd) |
| 84 | } | 84 | } |
| 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 | } | ||