@math.gl/earth 0.0.0-stage → 5.0.0-alpha.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -2
- package/dist/geoid/create-geoid-from-grid.d.ts +15 -0
- package/dist/geoid/create-geoid-from-grid.d.ts.map +1 -0
- package/dist/geoid/create-geoid-from-grid.js +38 -0
- package/dist/geoid/create-geoid-from-grid.js.map +1 -0
- package/dist/geoid/geoid.d.ts +60 -0
- package/dist/geoid/geoid.d.ts.map +1 -0
- package/dist/geoid/geoid.js +261 -0
- package/dist/geoid/geoid.js.map +1 -0
- package/dist/geoid/index.cjs +727 -0
- package/dist/geoid/index.cjs.map +6 -0
- package/dist/geoid/index.d.ts +5 -0
- package/dist/geoid/index.d.ts.map +1 -0
- package/dist/geoid/index.js +7 -0
- package/dist/geoid/index.js.map +1 -0
- package/dist/geoid/parse-pgm.d.ts +12 -0
- package/dist/geoid/parse-pgm.d.ts.map +1 -0
- package/dist/geoid/parse-pgm.js +183 -0
- package/dist/geoid/parse-pgm.js.map +1 -0
- package/dist/index.cjs +2646 -0
- package/dist/index.cjs.map +6 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/sun/astronomy.cjs +1729 -0
- package/dist/sun/astronomy.cjs.map +6 -0
- package/dist/sun/astronomy.d.ts +359 -0
- package/dist/sun/astronomy.d.ts.map +1 -0
- package/dist/sun/astronomy.js +181 -0
- package/dist/sun/astronomy.js.map +1 -0
- package/dist/sun/celestial.d.ts +4 -0
- package/dist/sun/celestial.d.ts.map +1 -0
- package/dist/sun/celestial.js +18 -0
- package/dist/sun/celestial.js.map +1 -0
- package/dist/sun/cloud-lighting.d.ts +49 -0
- package/dist/sun/cloud-lighting.d.ts.map +1 -0
- package/dist/sun/cloud-lighting.js +121 -0
- package/dist/sun/cloud-lighting.js.map +1 -0
- package/dist/sun/cloud-spectral.d.ts +3 -0
- package/dist/sun/cloud-spectral.d.ts.map +1 -0
- package/dist/sun/cloud-spectral.js +45 -0
- package/dist/sun/cloud-spectral.js.map +1 -0
- package/dist/sun/data/bright-stars.d.ts +3 -0
- package/dist/sun/data/bright-stars.d.ts.map +1 -0
- package/dist/sun/data/bright-stars.js +7015 -0
- package/dist/sun/data/bright-stars.js.map +1 -0
- package/dist/sun/data/sunlight.d.ts +2 -0
- package/dist/sun/data/sunlight.d.ts.map +1 -0
- package/dist/sun/data/sunlight.js +970 -0
- package/dist/sun/data/sunlight.js.map +1 -0
- package/dist/sun/index.cjs +1744 -0
- package/dist/sun/index.cjs.map +6 -0
- package/dist/sun/index.d.ts +23 -0
- package/dist/sun/index.d.ts.map +1 -0
- package/dist/sun/index.js +17 -0
- package/dist/sun/index.js.map +1 -0
- package/dist/sun/moon-appearance.d.ts +25 -0
- package/dist/sun/moon-appearance.d.ts.map +1 -0
- package/dist/sun/moon-appearance.js +50 -0
- package/dist/sun/moon-appearance.js.map +1 -0
- package/dist/sun/moon-sky-brightness.d.ts +7 -0
- package/dist/sun/moon-sky-brightness.d.ts.map +1 -0
- package/dist/sun/moon-sky-brightness.js +50 -0
- package/dist/sun/moon-sky-brightness.js.map +1 -0
- package/dist/sun/moon.d.ts +26 -0
- package/dist/sun/moon.d.ts.map +1 -0
- package/dist/sun/moon.js +74 -0
- package/dist/sun/moon.js.map +1 -0
- package/dist/sun/moonlight.d.ts +23 -0
- package/dist/sun/moonlight.d.ts.map +1 -0
- package/dist/sun/moonlight.js +48 -0
- package/dist/sun/moonlight.js.map +1 -0
- package/dist/sun/planet-position.d.ts +63 -0
- package/dist/sun/planet-position.d.ts.map +1 -0
- package/dist/sun/planet-position.js +189 -0
- package/dist/sun/planet-position.js.map +1 -0
- package/dist/sun/planet-times.d.ts +41 -0
- package/dist/sun/planet-times.d.ts.map +1 -0
- package/dist/sun/planet-times.js +86 -0
- package/dist/sun/planet-times.js.map +1 -0
- package/dist/sun/planet-visibility.d.ts +39 -0
- package/dist/sun/planet-visibility.d.ts.map +1 -0
- package/dist/sun/planet-visibility.js +82 -0
- package/dist/sun/planet-visibility.js.map +1 -0
- package/dist/sun/planets.cjs +411 -0
- package/dist/sun/planets.cjs.map +6 -0
- package/dist/sun/planets.d.ts +7 -0
- package/dist/sun/planets.d.ts.map +1 -0
- package/dist/sun/planets.js +7 -0
- package/dist/sun/planets.js.map +1 -0
- package/dist/sun/sky-brightness.d.ts +32 -0
- package/dist/sun/sky-brightness.d.ts.map +1 -0
- package/dist/sun/sky-brightness.js +108 -0
- package/dist/sun/sky-brightness.js.map +1 -0
- package/dist/sun/sky-events.d.ts +16 -0
- package/dist/sun/sky-events.d.ts.map +1 -0
- package/dist/sun/sky-events.js +60 -0
- package/dist/sun/sky-events.js.map +1 -0
- package/dist/sun/sky-globe.d.ts +15 -0
- package/dist/sun/sky-globe.d.ts.map +1 -0
- package/dist/sun/sky-globe.js +51 -0
- package/dist/sun/sky-globe.js.map +1 -0
- package/dist/sun/sky-lighting.d.ts +27 -0
- package/dist/sun/sky-lighting.d.ts.map +1 -0
- package/dist/sun/sky-lighting.js +88 -0
- package/dist/sun/sky-lighting.js.map +1 -0
- package/dist/sun/sky-observer.d.ts +22 -0
- package/dist/sun/sky-observer.d.ts.map +1 -0
- package/dist/sun/sky-observer.js +57 -0
- package/dist/sun/sky-observer.js.map +1 -0
- package/dist/sun/sky-time.d.ts +9 -0
- package/dist/sun/sky-time.d.ts.map +1 -0
- package/dist/sun/sky-time.js +38 -0
- package/dist/sun/sky-time.js.map +1 -0
- package/dist/sun/star-galactic.d.ts +15 -0
- package/dist/sun/star-galactic.d.ts.map +1 -0
- package/dist/sun/star-galactic.js +98 -0
- package/dist/sun/star-galactic.js.map +1 -0
- package/dist/sun/star-milky-way.d.ts +14 -0
- package/dist/sun/star-milky-way.d.ts.map +1 -0
- package/dist/sun/star-milky-way.js +32 -0
- package/dist/sun/star-milky-way.js.map +1 -0
- package/dist/sun/star-render.d.ts +38 -0
- package/dist/sun/star-render.d.ts.map +1 -0
- package/dist/sun/star-render.js +98 -0
- package/dist/sun/star-render.js.map +1 -0
- package/dist/sun/star-types.d.ts +60 -0
- package/dist/sun/star-types.d.ts.map +1 -0
- package/dist/sun/star-types.js +5 -0
- package/dist/sun/star-types.js.map +1 -0
- package/dist/sun/starfield.d.ts +13 -0
- package/dist/sun/starfield.d.ts.map +1 -0
- package/dist/sun/starfield.js +86 -0
- package/dist/sun/starfield.js.map +1 -0
- package/dist/sun/stars.cjs +7519 -0
- package/dist/sun/stars.cjs.map +6 -0
- package/dist/sun/stars.d.ts +26 -0
- package/dist/sun/stars.d.ts.map +1 -0
- package/dist/sun/stars.js +188 -0
- package/dist/sun/stars.js.map +1 -0
- package/dist/sun/suncalc.d.ts +26 -0
- package/dist/sun/suncalc.d.ts.map +1 -0
- package/dist/sun/suncalc.js +94 -0
- package/dist/sun/suncalc.js.map +1 -0
- package/dist/sun/sunlight.d.ts +25 -0
- package/dist/sun/sunlight.d.ts.map +1 -0
- package/dist/sun/sunlight.js +76 -0
- package/dist/sun/sunlight.js.map +1 -0
- package/dist/timezone/index.cjs +205 -0
- package/dist/timezone/index.cjs.map +6 -0
- package/dist/timezone/index.d.ts +6 -0
- package/dist/timezone/index.d.ts.map +1 -0
- package/dist/timezone/index.js +8 -0
- package/dist/timezone/index.js.map +1 -0
- package/dist/timezone/instant.d.ts +4 -0
- package/dist/timezone/instant.d.ts.map +1 -0
- package/dist/timezone/instant.js +20 -0
- package/dist/timezone/instant.js.map +1 -0
- package/dist/timezone/local-date-time.d.ts +4 -0
- package/dist/timezone/local-date-time.d.ts.map +1 -0
- package/dist/timezone/local-date-time.js +34 -0
- package/dist/timezone/local-date-time.js.map +1 -0
- package/dist/timezone/lookup-async.d.ts +3 -0
- package/dist/timezone/lookup-async.d.ts.map +1 -0
- package/dist/timezone/lookup-async.js +14 -0
- package/dist/timezone/lookup-async.js.map +1 -0
- package/dist/timezone/lookup.cjs +83 -0
- package/dist/timezone/lookup.cjs.map +6 -0
- package/dist/timezone/lookup.d.ts +3 -0
- package/dist/timezone/lookup.d.ts.map +1 -0
- package/dist/timezone/lookup.js +18 -0
- package/dist/timezone/lookup.js.map +1 -0
- package/dist/timezone/temporal.cjs +5696 -0
- package/dist/timezone/temporal.cjs.map +6 -0
- package/dist/timezone/temporal.d.ts +9 -0
- package/dist/timezone/temporal.d.ts.map +1 -0
- package/dist/timezone/temporal.js +60 -0
- package/dist/timezone/temporal.js.map +1 -0
- package/dist/timezone/timezone-label.d.ts +5 -0
- package/dist/timezone/timezone-label.d.ts.map +1 -0
- package/dist/timezone/timezone-label.js +27 -0
- package/dist/timezone/timezone-label.js.map +1 -0
- package/dist/timezone/timezone-offset.d.ts +3 -0
- package/dist/timezone/timezone-offset.d.ts.map +1 -0
- package/dist/timezone/timezone-offset.js +22 -0
- package/dist/timezone/timezone-offset.js.map +1 -0
- package/dist/timezone/types.d.ts +23 -0
- package/dist/timezone/types.d.ts.map +1 -0
- package/dist/timezone/types.js +5 -0
- package/dist/timezone/types.js.map +1 -0
- package/dist/timezone/vendor/temporal/runtime.d.ts +3 -0
- package/dist/timezone/vendor/temporal/runtime.d.ts.map +1 -0
- package/dist/timezone/vendor/temporal/runtime.js +5649 -0
- package/dist/timezone/vendor/temporal/runtime.js.map +1 -0
- package/dist/timezone/vendor/temporal/types.d.ts +939 -0
- package/dist/timezone/vendor/temporal/types.d.ts.map +1 -0
- package/dist/timezone/vendor/temporal/types.js +4 -0
- package/dist/timezone/vendor/temporal/types.js.map +1 -0
- package/dist/timezone/vendor/tz-lookup/runtime.d.ts +3 -0
- package/dist/timezone/vendor/tz-lookup/runtime.d.ts.map +1 -0
- package/dist/timezone/vendor/tz-lookup/runtime.js +53 -0
- package/dist/timezone/vendor/tz-lookup/runtime.js.map +1 -0
- package/geoid/data/README.md +28 -0
- package/geoid/data/geoid-egm96-hi.pgm +0 -0
- package/geoid/data/geoid-egm96-low.pgm +0 -0
- package/geoid/data/geoid-manifest.json +22 -0
- package/package.json +91 -4
- package/src/geoid/create-geoid-from-grid.ts +51 -0
- package/src/geoid/geoid.ts +297 -0
- package/src/geoid/index.ts +8 -0
- package/src/geoid/parse-pgm.ts +189 -0
- package/src/index.ts +7 -0
- package/src/sun/astronomy.ts +272 -0
- package/src/sun/celestial.ts +22 -0
- package/src/sun/cloud-lighting.ts +198 -0
- package/src/sun/cloud-spectral.ts +54 -0
- package/src/sun/data/bright-stars.ts +7024 -0
- package/src/sun/data/sunlight.ts +969 -0
- package/src/sun/index.ts +43 -0
- package/src/sun/moon-appearance.ts +81 -0
- package/src/sun/moon-sky-brightness.ts +64 -0
- package/src/sun/moon.ts +122 -0
- package/src/sun/moonlight.ts +88 -0
- package/src/sun/planet-position.ts +305 -0
- package/src/sun/planet-times.ts +142 -0
- package/src/sun/planet-visibility.ts +143 -0
- package/src/sun/planets.ts +18 -0
- package/src/sun/sky-brightness.ts +148 -0
- package/src/sun/sky-events.ts +66 -0
- package/src/sun/sky-globe.ts +72 -0
- package/src/sun/sky-lighting.ts +118 -0
- package/src/sun/sky-observer.ts +66 -0
- package/src/sun/sky-time.ts +42 -0
- package/src/sun/star-galactic.ts +111 -0
- package/src/sun/star-milky-way.ts +61 -0
- package/src/sun/star-render.ts +149 -0
- package/src/sun/star-types.ts +66 -0
- package/src/sun/starfield.ts +100 -0
- package/src/sun/stars.ts +260 -0
- package/src/sun/suncalc.ts +141 -0
- package/src/sun/sunlight.ts +112 -0
- package/src/timezone/index.ts +9 -0
- package/src/timezone/instant.ts +21 -0
- package/src/timezone/local-date-time.ts +40 -0
- package/src/timezone/lookup-async.ts +15 -0
- package/src/timezone/lookup.ts +21 -0
- package/src/timezone/temporal.ts +81 -0
- package/src/timezone/timezone-label.ts +30 -0
- package/src/timezone/timezone-offset.ts +21 -0
- package/src/timezone/types.ts +30 -0
- package/src/timezone/vendor/temporal/JSBI-LICENSE.txt +179 -0
- package/src/timezone/vendor/temporal/LICENSE.txt +16 -0
- package/src/timezone/vendor/temporal/README.md +23 -0
- package/src/timezone/vendor/temporal/runtime.ts +5070 -0
- package/src/timezone/vendor/temporal/types.ts +1146 -0
- package/src/timezone/vendor/tz-lookup/LICENSE.txt +119 -0
- package/src/timezone/vendor/tz-lookup/README.md +22 -0
- package/src/timezone/vendor/tz-lookup/runtime.ts +53 -0
- package/sun/LICENSE-BRIGHT-STARS +21 -0
- package/sun/LICENSE-HOSEK-WILKIE +30 -0
- package/sun/LICENSE-SUNCALC +24 -0
- package/timezone/data/LICENSE-ODbL.txt +538 -0
- package/timezone/data/README.md +50 -0
- package/timezone/data/manifest.json +37 -0
- package/timezone/data/timezone-geometry-hi.json +1 -0
- package/timezone/data/timezone-geometry-hi.parquet +0 -0
- package/timezone/data/timezone-geometry-low.json +1 -0
- package/timezone/data/timezone-geometry-low.parquet +0 -0
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
// SPDX-FileComment: Original rendering adapter for MIT-licensed Astronomy Engine 2.1.19.
|
|
5
|
+
// API/model provenance: https://github.com/cosinekitty/astronomy/tree/v2.1.19/source/js
|
|
6
|
+
// Physical mean radii: https://ssd.jpl.nasa.gov/planets/phys_par.html
|
|
7
|
+
// Galilean mean radii: https://ssd.jpl.nasa.gov/sats/phys_par/
|
|
8
|
+
// Galilean geometric albedos: https://nssdc.gsfc.nasa.gov/planetary/factsheet/joviansatfact.html
|
|
9
|
+
import {
|
|
10
|
+
AstroTime,
|
|
11
|
+
Body,
|
|
12
|
+
CorrectLightTravel,
|
|
13
|
+
HelioVector,
|
|
14
|
+
Illumination,
|
|
15
|
+
JupiterMoons,
|
|
16
|
+
KM_PER_AU,
|
|
17
|
+
Observer,
|
|
18
|
+
ObserverVector,
|
|
19
|
+
RotateVector,
|
|
20
|
+
Rotation_EQJ_HOR,
|
|
21
|
+
Vector
|
|
22
|
+
} from 'astronomy-engine';
|
|
23
|
+
import type {RotationMatrix} from 'astronomy-engine';
|
|
24
|
+
import {getPlanetVisibility} from './planet-visibility';
|
|
25
|
+
import type {PlanetVisibility, PlanetVisibilityOptions} from './planet-visibility';
|
|
26
|
+
import {createSkyTime} from './sky-time';
|
|
27
|
+
import type {SkyTimeScales} from './sky-time';
|
|
28
|
+
|
|
29
|
+
type Triple = [number, number, number];
|
|
30
|
+
export type PlanetName = 'Mercury' | 'Venus' | 'Mars' | 'Jupiter' | 'Saturn' | 'Uranus' | 'Neptune';
|
|
31
|
+
export type GalileanMoonName = 'Io' | 'Europa' | 'Ganymede' | 'Callisto';
|
|
32
|
+
export type PlanetSkyOptions = {
|
|
33
|
+
timeScales?: SkyTimeScales;
|
|
34
|
+
/** Local terrain horizon altitude in radians at south-to-west azimuth. */
|
|
35
|
+
horizon?: (azimuth: number) => number;
|
|
36
|
+
/** Observer elevation above sea level in meters. Default 0. */
|
|
37
|
+
elevation?: number;
|
|
38
|
+
/** Include Io, Europa, Ganymede and Callisto. Default true. */
|
|
39
|
+
galileanMoons?: boolean;
|
|
40
|
+
/** Conditions for the current twilight visibility estimate. */
|
|
41
|
+
visibility?: PlanetVisibilityOptions;
|
|
42
|
+
};
|
|
43
|
+
export type PlanetSkyBody = {
|
|
44
|
+
name: PlanetName | GalileanMoonName;
|
|
45
|
+
parent: 'Jupiter' | null;
|
|
46
|
+
/** Outward observer-to-body unit vector in east/north/up coordinates. */
|
|
47
|
+
direction: Triple;
|
|
48
|
+
/** Outward observer-to-body unit vector in J2000 equatorial coordinates. */
|
|
49
|
+
equatorialDirection: Triple;
|
|
50
|
+
/** Geometric altitude in radians; no atmospheric refraction. */
|
|
51
|
+
altitude: number;
|
|
52
|
+
/** Radians measured from south towards west, matching getSunPosition. */
|
|
53
|
+
azimuth: number;
|
|
54
|
+
/** Observer-to-body center distance, kilometers. */
|
|
55
|
+
distance: number;
|
|
56
|
+
/** Full angular disk diameter in radians, using a spherical mean radius. */
|
|
57
|
+
angularDiameter: number;
|
|
58
|
+
/** Sun/body/observer angle in radians; 0 is full phase. */
|
|
59
|
+
phaseAngle: number;
|
|
60
|
+
illuminatedFraction: number;
|
|
61
|
+
/** Body-to-Sun unit vector in local ENU, for shading a sphere. */
|
|
62
|
+
sunDirection: Triple;
|
|
63
|
+
/** Visual magnitude before extinction/occultation; Lambert approximation for satellites. */
|
|
64
|
+
magnitude: number | null;
|
|
65
|
+
/** Approximate current naked-eye detectability; null for Galilean moons. */
|
|
66
|
+
visibility: PlanetVisibility | null;
|
|
67
|
+
/** Apparent offset from Jupiter's center in ENU kilometers; null for planets. */
|
|
68
|
+
jupiterOffset: Triple | null;
|
|
69
|
+
/** Approximate spherical-disk occultation by Jupiter; independent of horizon. */
|
|
70
|
+
occultation: 'none' | 'partial' | 'total';
|
|
71
|
+
/** Galilean moon overlaps Jupiter's disk in front of it. */
|
|
72
|
+
transiting: boolean;
|
|
73
|
+
/** Entire solar disk is obscured at the satellite center. */
|
|
74
|
+
inJupiterShadow: boolean;
|
|
75
|
+
/** Unblocked solar disk fraction at satellite center, including penumbra. */
|
|
76
|
+
sunlitFraction: number;
|
|
77
|
+
/** Approximate unocculted satellite disk fraction. */
|
|
78
|
+
visibleDiskFraction: number;
|
|
79
|
+
/** Satellite magnitude including eclipse/occultation; null when completely dark. */
|
|
80
|
+
apparentMagnitude: number | null;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const PLANETS: [PlanetName, Body, number][] = [
|
|
84
|
+
['Mercury', Body.Mercury, 2439.4],
|
|
85
|
+
['Venus', Body.Venus, 6051.8],
|
|
86
|
+
['Mars', Body.Mars, 3389.5],
|
|
87
|
+
['Jupiter', Body.Jupiter, 69911],
|
|
88
|
+
['Saturn', Body.Saturn, 58232],
|
|
89
|
+
['Uranus', Body.Uranus, 25362],
|
|
90
|
+
['Neptune', Body.Neptune, 24622]
|
|
91
|
+
];
|
|
92
|
+
const MOONS: [GalileanMoonName, 'io' | 'europa' | 'ganymede' | 'callisto', number][] = [
|
|
93
|
+
['Io', 'io', 1821.49],
|
|
94
|
+
['Europa', 'europa', 1560.8],
|
|
95
|
+
['Ganymede', 'ganymede', 2631.2],
|
|
96
|
+
['Callisto', 'callisto', 2410.3]
|
|
97
|
+
];
|
|
98
|
+
const JUPITER_RADIUS = 69911;
|
|
99
|
+
// IAU nominal solar radius, km (2015 Resolution B3).
|
|
100
|
+
// https://www.iau.org/static/resolutions/IAU2015_English.pdf
|
|
101
|
+
const SUN_RADIUS = 695700;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Positions and disk geometry for rendering seven planets and four Galilean moons.
|
|
105
|
+
* Import from @math.gl/earth/sun/planets; requires the optional astronomy-engine peer.
|
|
106
|
+
* The ephemeris accounts for light travel, precession and nutation; not aberration.
|
|
107
|
+
*/
|
|
108
|
+
export function getPlanetSkyInfo(
|
|
109
|
+
timestamp: number | Date,
|
|
110
|
+
latitude: number,
|
|
111
|
+
longitude: number,
|
|
112
|
+
options: PlanetSkyOptions = {}
|
|
113
|
+
): PlanetSkyBody[] {
|
|
114
|
+
const date = new Date(timestamp);
|
|
115
|
+
const {elevation = 0, galileanMoons = true} = options;
|
|
116
|
+
if (!Number.isFinite(date.getTime()))
|
|
117
|
+
throw new RangeError('Timestamp must be a valid Date or Unix milliseconds');
|
|
118
|
+
if (!Number.isFinite(latitude) || Math.abs(latitude) > 90)
|
|
119
|
+
throw new RangeError('Latitude must be between -90 and 90');
|
|
120
|
+
if (!Number.isFinite(longitude)) throw new RangeError('Longitude must be finite');
|
|
121
|
+
if (!Number.isFinite(elevation) || elevation < -1000 || elevation > 100000)
|
|
122
|
+
throw new RangeError('Elevation must be between -1000 and 100000 meters');
|
|
123
|
+
if (typeof galileanMoons !== 'boolean') throw new RangeError('galileanMoons must be a boolean');
|
|
124
|
+
const year = date.getUTCFullYear();
|
|
125
|
+
// Deliberately restrict this rendering adapter to a documented modern range.
|
|
126
|
+
if (year < 1900 || year > 2100) throw new RangeError('Planet sky dates must be within 1900–2100');
|
|
127
|
+
const time = createSkyTime(date, options.timeScales);
|
|
128
|
+
const observer = new Observer(latitude, longitude % 360, elevation);
|
|
129
|
+
const rotation = Rotation_EQJ_HOR(time, observer);
|
|
130
|
+
const earth = HelioVector(Body.Earth, time);
|
|
131
|
+
const surface = ObserverVector(time, observer, false);
|
|
132
|
+
const origin = [earth.x + surface.x, earth.y + surface.y, earth.z + surface.z];
|
|
133
|
+
const sunView = normalized(enu(new Vector(-origin[0], -origin[1], -origin[2], time), rotation));
|
|
134
|
+
const sunAltitude = Math.atan2(sunView[2], Math.hypot(sunView[0], sunView[1]));
|
|
135
|
+
const states = PLANETS.map(([name, body, radius]) => {
|
|
136
|
+
const relative = CorrectLightTravel(t => {
|
|
137
|
+
const target = HelioVector(body, t);
|
|
138
|
+
return new Vector(target.x - origin[0], target.y - origin[1], target.z - origin[2], t);
|
|
139
|
+
}, time);
|
|
140
|
+
const heliocentric = HelioVector(body, relative.t);
|
|
141
|
+
const info = renderInfo(name, null, radius, relative, heliocentric, rotation, time);
|
|
142
|
+
info.magnitude = Illumination(body, time).mag;
|
|
143
|
+
info.apparentMagnitude = info.magnitude;
|
|
144
|
+
const horizonAltitude = options.horizon?.(info.azimuth);
|
|
145
|
+
info.visibility = getPlanetVisibility(
|
|
146
|
+
info.magnitude,
|
|
147
|
+
info.altitude,
|
|
148
|
+
sunAltitude,
|
|
149
|
+
angularSeparation(info.direction, sunView),
|
|
150
|
+
horizonAltitude === undefined
|
|
151
|
+
? options.visibility
|
|
152
|
+
: {
|
|
153
|
+
...options.visibility,
|
|
154
|
+
minimumAltitude: Math.max(
|
|
155
|
+
options.visibility?.minimumAltitude ?? (5 * Math.PI) / 180,
|
|
156
|
+
horizonAltitude
|
|
157
|
+
)
|
|
158
|
+
}
|
|
159
|
+
);
|
|
160
|
+
return {relative, info};
|
|
161
|
+
});
|
|
162
|
+
const result = states.map(state => state.info);
|
|
163
|
+
if (!galileanMoons) return result;
|
|
164
|
+
const jupiter = states[3];
|
|
165
|
+
for (const [name, key, radius] of MOONS) {
|
|
166
|
+
// Evaluate the satellite at emission time: Jupiter's light delay is tens of
|
|
167
|
+
// minutes, enough for Io to move noticeably. Solve each satellite separately.
|
|
168
|
+
const relative = CorrectLightTravel(t => {
|
|
169
|
+
const planet = HelioVector(Body.Jupiter, t);
|
|
170
|
+
const moon = JupiterMoons(t)[key];
|
|
171
|
+
return new Vector(
|
|
172
|
+
planet.x + moon.x - origin[0],
|
|
173
|
+
planet.y + moon.y - origin[1],
|
|
174
|
+
planet.z + moon.z - origin[2],
|
|
175
|
+
t
|
|
176
|
+
);
|
|
177
|
+
}, time);
|
|
178
|
+
const planet = HelioVector(Body.Jupiter, relative.t);
|
|
179
|
+
const offset = JupiterMoons(relative.t)[key];
|
|
180
|
+
const heliocentric = new Vector(
|
|
181
|
+
planet.x + offset.x,
|
|
182
|
+
planet.y + offset.y,
|
|
183
|
+
planet.z + offset.z,
|
|
184
|
+
relative.t
|
|
185
|
+
);
|
|
186
|
+
const info = renderInfo(name, 'Jupiter', radius, relative, heliocentric, rotation, time);
|
|
187
|
+
const difference = new Vector(
|
|
188
|
+
relative.x - jupiter.relative.x,
|
|
189
|
+
relative.y - jupiter.relative.y,
|
|
190
|
+
relative.z - jupiter.relative.z,
|
|
191
|
+
time
|
|
192
|
+
);
|
|
193
|
+
info.jupiterOffset = enu(difference, rotation).map(value => value * KM_PER_AU) as Triple;
|
|
194
|
+
const separation = angularSeparation(
|
|
195
|
+
info.equatorialDirection,
|
|
196
|
+
jupiter.info.equatorialDirection
|
|
197
|
+
);
|
|
198
|
+
const moonRadius = info.angularDiameter / 2;
|
|
199
|
+
const planetRadius = jupiter.info.angularDiameter / 2;
|
|
200
|
+
const overlaps = separation < planetRadius + moonRadius;
|
|
201
|
+
if (info.distance > jupiter.info.distance && overlaps) {
|
|
202
|
+
info.occultation = separation + moonRadius < planetRadius ? 'total' : 'partial';
|
|
203
|
+
}
|
|
204
|
+
info.transiting = info.distance < jupiter.info.distance && overlaps;
|
|
205
|
+
// Finite solar disk: spherical Jupiter obscures part or all of the Sun.
|
|
206
|
+
// Original circle-overlap geometry; geometric center illumination, not a
|
|
207
|
+
// resolved penumbra across the satellite surface.
|
|
208
|
+
const moonToSun = normalized([-heliocentric.x, -heliocentric.y, -heliocentric.z]);
|
|
209
|
+
const moonToPlanet = normalized([-offset.x, -offset.y, -offset.z]);
|
|
210
|
+
const sunRadius = Math.asin(SUN_RADIUS / (heliocentric.Length() * KM_PER_AU));
|
|
211
|
+
const jupiterRadius = Math.asin(
|
|
212
|
+
JUPITER_RADIUS / (Math.hypot(offset.x, offset.y, offset.z) * KM_PER_AU)
|
|
213
|
+
);
|
|
214
|
+
info.sunlitFraction =
|
|
215
|
+
1 - diskOverlapFraction(sunRadius, jupiterRadius, angularSeparation(moonToSun, moonToPlanet));
|
|
216
|
+
info.inJupiterShadow = info.sunlitFraction === 0;
|
|
217
|
+
info.visibleDiskFraction =
|
|
218
|
+
info.distance > jupiter.info.distance
|
|
219
|
+
? 1 - diskOverlapFraction(moonRadius, planetRadius, separation)
|
|
220
|
+
: 1;
|
|
221
|
+
const albedo = {Io: 0.62, Europa: 0.68, Ganymede: 0.44, Callisto: 0.19}[name];
|
|
222
|
+
const phase =
|
|
223
|
+
(Math.sin(info.phaseAngle) + (Math.PI - info.phaseAngle) * Math.cos(info.phaseAngle)) /
|
|
224
|
+
Math.PI;
|
|
225
|
+
const flux =
|
|
226
|
+
(albedo * (radius / KM_PER_AU) ** 2 * phase) /
|
|
227
|
+
(heliocentric.Length() ** 2 * relative.Length() ** 2);
|
|
228
|
+
info.magnitude = -26.74 - 2.5 * Math.log10(flux);
|
|
229
|
+
const transmission = info.sunlitFraction * info.visibleDiskFraction;
|
|
230
|
+
info.apparentMagnitude =
|
|
231
|
+
transmission > 0 ? info.magnitude - 2.5 * Math.log10(transmission) : null;
|
|
232
|
+
result.push(info);
|
|
233
|
+
}
|
|
234
|
+
return result;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function renderInfo(
|
|
238
|
+
name: PlanetSkyBody['name'],
|
|
239
|
+
parent: PlanetSkyBody['parent'],
|
|
240
|
+
radius: number,
|
|
241
|
+
relative: Vector,
|
|
242
|
+
heliocentric: Vector,
|
|
243
|
+
rotation: RotationMatrix,
|
|
244
|
+
time: AstroTime
|
|
245
|
+
): PlanetSkyBody {
|
|
246
|
+
const direction = normalized(enu(relative, rotation));
|
|
247
|
+
const equatorialDirection = normalized([relative.x, relative.y, relative.z]);
|
|
248
|
+
const towardSun = new Vector(-heliocentric.x, -heliocentric.y, -heliocentric.z, time);
|
|
249
|
+
const sunDirection = normalized(enu(towardSun, rotation));
|
|
250
|
+
const phaseAngle = Math.acos(Math.max(-1, Math.min(1, -dot(direction, sunDirection))));
|
|
251
|
+
const distance = relative.Length() * KM_PER_AU;
|
|
252
|
+
return {
|
|
253
|
+
name,
|
|
254
|
+
parent,
|
|
255
|
+
direction,
|
|
256
|
+
equatorialDirection,
|
|
257
|
+
altitude: Math.atan2(direction[2], Math.hypot(direction[0], direction[1])),
|
|
258
|
+
azimuth: Math.atan2(-direction[0], -direction[1]),
|
|
259
|
+
distance,
|
|
260
|
+
angularDiameter: 2 * Math.asin(radius / distance),
|
|
261
|
+
phaseAngle,
|
|
262
|
+
illuminatedFraction: (1 + Math.cos(phaseAngle)) / 2,
|
|
263
|
+
sunDirection,
|
|
264
|
+
magnitude: null,
|
|
265
|
+
visibility: null,
|
|
266
|
+
jupiterOffset: null,
|
|
267
|
+
occultation: 'none',
|
|
268
|
+
transiting: false,
|
|
269
|
+
inJupiterShadow: false,
|
|
270
|
+
sunlitFraction: 1,
|
|
271
|
+
visibleDiskFraction: 1,
|
|
272
|
+
apparentMagnitude: null
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/** Fraction of disk r covered by disk R separated by d (small-angle disk geometry). */
|
|
277
|
+
function diskOverlapFraction(r: number, R: number, d: number): number {
|
|
278
|
+
if (d >= r + R) return 0;
|
|
279
|
+
if (d <= Math.abs(R - r)) return R >= r ? 1 : (R / r) ** 2;
|
|
280
|
+
const clamp = (x: number) => Math.max(-1, Math.min(1, x));
|
|
281
|
+
const area =
|
|
282
|
+
r * r * Math.acos(clamp((d * d + r * r - R * R) / (2 * d * r))) +
|
|
283
|
+
R * R * Math.acos(clamp((d * d + R * R - r * r) / (2 * d * R))) -
|
|
284
|
+
0.5 * Math.sqrt(Math.max(0, (-d + r + R) * (d + r - R) * (d - r + R) * (d + r + R)));
|
|
285
|
+
return Math.max(0, Math.min(1, area / (Math.PI * r * r)));
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function enu(vector: Vector, rotation: RotationMatrix): Triple {
|
|
289
|
+
const v = RotateVector(rotation, vector);
|
|
290
|
+
// Astronomy Engine's horizontal frame is north/west/up.
|
|
291
|
+
return [-v.y, v.x, v.z];
|
|
292
|
+
}
|
|
293
|
+
function normalized(values: number[]): Triple {
|
|
294
|
+
const length = Math.hypot(...values);
|
|
295
|
+
return values.map(value => value / length) as Triple;
|
|
296
|
+
}
|
|
297
|
+
function dot(a: number[], b: number[]): number {
|
|
298
|
+
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
299
|
+
}
|
|
300
|
+
function angularSeparation(a: Triple, b: Triple): number {
|
|
301
|
+
return Math.atan2(
|
|
302
|
+
Math.hypot(a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]),
|
|
303
|
+
dot(a, b)
|
|
304
|
+
);
|
|
305
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
// SPDX-FileComment: Original event-window search using the MIT Astronomy Engine API.
|
|
5
|
+
// https://github.com/cosinekitty/astronomy/tree/v2.1.19/source/js#searchriseset
|
|
6
|
+
import {Body, Observer, SearchRiseSet} from 'astronomy-engine';
|
|
7
|
+
import {getPlanetSkyInfo} from './planet-position';
|
|
8
|
+
import type {PlanetName, PlanetSkyBody, PlanetSkyOptions} from './planet-position';
|
|
9
|
+
import type {PlanetVisibilityOptions} from './planet-visibility';
|
|
10
|
+
import {validateRange} from './celestial';
|
|
11
|
+
|
|
12
|
+
export type PlanetVisibilityTimesOptions = PlanetVisibilityOptions & {
|
|
13
|
+
horizon?: PlanetSkyOptions['horizon'];
|
|
14
|
+
/** Sampling interval in seconds. Default 60; shorter catches narrower windows. */
|
|
15
|
+
sampleSeconds?: number;
|
|
16
|
+
/** Numerical transition bracket in seconds. Default 5. */
|
|
17
|
+
transitionSeconds?: number;
|
|
18
|
+
/** Window length in hours, greater than 0 and at most 72. Default 24. */
|
|
19
|
+
durationHours?: number;
|
|
20
|
+
/** Observer elevation above sea level in meters. Default 0. */
|
|
21
|
+
elevation?: number;
|
|
22
|
+
};
|
|
23
|
+
export type PlanetVisibilityInterval = {
|
|
24
|
+
/** Unix milliseconds, inclusive. */
|
|
25
|
+
start: number;
|
|
26
|
+
/** Unix milliseconds, exclusive. */
|
|
27
|
+
end: number;
|
|
28
|
+
/** Interval was already active at the requested window start. */
|
|
29
|
+
startClipped: boolean;
|
|
30
|
+
/** Interval continues beyond the requested window end. */
|
|
31
|
+
endClipped: boolean;
|
|
32
|
+
};
|
|
33
|
+
export type PlanetVisibilityTimes = {
|
|
34
|
+
name: PlanetName;
|
|
35
|
+
/** Next conventional rise in the search window, Unix milliseconds; null if none. */
|
|
36
|
+
riseTime: number | null;
|
|
37
|
+
/** Next conventional set in the search window, Unix milliseconds; null if none. */
|
|
38
|
+
setTime: number | null;
|
|
39
|
+
/** Heuristic visibility at the beginning of the requested window. */
|
|
40
|
+
visibleAtStart: boolean;
|
|
41
|
+
/** Estimated detectability windows; empty when none were found. */
|
|
42
|
+
visibleIntervals: PlanetVisibilityInterval[];
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Search upcoming rise/set events and approximate visibility intervals for seven planets.
|
|
47
|
+
* Samples once per minute and refines detected transitions to a five-second bracket.
|
|
48
|
+
* Very short/grazing visibility intervals between samples can be missed.
|
|
49
|
+
*/
|
|
50
|
+
export function getPlanetVisibilityTimes(
|
|
51
|
+
timestamp: number | Date,
|
|
52
|
+
latitude: number,
|
|
53
|
+
longitude: number,
|
|
54
|
+
options: PlanetVisibilityTimesOptions = {}
|
|
55
|
+
): PlanetVisibilityTimes[] {
|
|
56
|
+
const {
|
|
57
|
+
durationHours = 24,
|
|
58
|
+
elevation = 0,
|
|
59
|
+
horizon,
|
|
60
|
+
sampleSeconds = 60,
|
|
61
|
+
transitionSeconds = Math.min(5, sampleSeconds),
|
|
62
|
+
...visibility
|
|
63
|
+
} = options;
|
|
64
|
+
validateRange('Duration hours', durationHours, Number.MIN_VALUE, 72);
|
|
65
|
+
validateRange('Sample seconds', sampleSeconds, 1, 3600);
|
|
66
|
+
validateRange('Transition seconds', transitionSeconds, 0.001, sampleSeconds);
|
|
67
|
+
if ((durationHours * 3600) / sampleSeconds > 100000)
|
|
68
|
+
throw new RangeError('Search would exceed 100000 samples');
|
|
69
|
+
const start = new Date(timestamp).getTime();
|
|
70
|
+
const end = start + durationHours * 3600000;
|
|
71
|
+
if (end <= start) throw new RangeError('Duration must advance the timestamp');
|
|
72
|
+
const skyOptions = {elevation, horizon, galileanMoons: false, visibility};
|
|
73
|
+
const first = getPlanetSkyInfo(start, latitude, longitude, skyOptions);
|
|
74
|
+
// Validate the whole requested date range before starting the search.
|
|
75
|
+
getPlanetSkyInfo(end, latitude, longitude, skyOptions);
|
|
76
|
+
const observer = new Observer(latitude, longitude % 360, elevation);
|
|
77
|
+
const result: PlanetVisibilityTimes[] = first.map(body => ({
|
|
78
|
+
name: body.name as PlanetName,
|
|
79
|
+
riseTime:
|
|
80
|
+
SearchRiseSet(
|
|
81
|
+
Body[body.name as PlanetName],
|
|
82
|
+
observer,
|
|
83
|
+
1,
|
|
84
|
+
new Date(start),
|
|
85
|
+
durationHours / 24
|
|
86
|
+
)?.date.getTime() ?? null,
|
|
87
|
+
setTime:
|
|
88
|
+
SearchRiseSet(
|
|
89
|
+
Body[body.name as PlanetName],
|
|
90
|
+
observer,
|
|
91
|
+
-1,
|
|
92
|
+
new Date(start),
|
|
93
|
+
durationHours / 24
|
|
94
|
+
)?.date.getTime() ?? null,
|
|
95
|
+
visibleAtStart: body.visibility!.visible,
|
|
96
|
+
visibleIntervals: []
|
|
97
|
+
}));
|
|
98
|
+
const activeStarts = first.map(body => (body.visibility!.visible ? start : null));
|
|
99
|
+
let previousTime = start;
|
|
100
|
+
let previous = first;
|
|
101
|
+
while (previousTime < end) {
|
|
102
|
+
const time = Math.min(end, previousTime + sampleSeconds * 1000);
|
|
103
|
+
const current = getPlanetSkyInfo(time, latitude, longitude, skyOptions);
|
|
104
|
+
for (let i = 0; i < current.length; i++) {
|
|
105
|
+
const before = previous[i].visibility!.visible;
|
|
106
|
+
const after = current[i].visibility!.visible;
|
|
107
|
+
if (before === after) continue;
|
|
108
|
+
let lower = previousTime;
|
|
109
|
+
let upper = time;
|
|
110
|
+
// This brackets the predicate transition; it does not imply visibility-model accuracy.
|
|
111
|
+
while (upper - lower > transitionSeconds * 1000) {
|
|
112
|
+
const middle = (lower + upper) / 2;
|
|
113
|
+
const state: PlanetSkyBody = getPlanetSkyInfo(middle, latitude, longitude, skyOptions)[i];
|
|
114
|
+
if (state.visibility!.visible === before) lower = middle;
|
|
115
|
+
else upper = middle;
|
|
116
|
+
}
|
|
117
|
+
const transition = (lower + upper) / 2;
|
|
118
|
+
if (after) activeStarts[i] = transition;
|
|
119
|
+
else {
|
|
120
|
+
result[i].visibleIntervals.push({
|
|
121
|
+
start: activeStarts[i]!,
|
|
122
|
+
end: transition,
|
|
123
|
+
startClipped: activeStarts[i] === start,
|
|
124
|
+
endClipped: false
|
|
125
|
+
});
|
|
126
|
+
activeStarts[i] = null;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
previousTime = time;
|
|
130
|
+
previous = current;
|
|
131
|
+
}
|
|
132
|
+
for (let i = 0; i < result.length; i++) {
|
|
133
|
+
if (activeStarts[i] !== null)
|
|
134
|
+
result[i].visibleIntervals.push({
|
|
135
|
+
start: activeStarts[i]!,
|
|
136
|
+
end,
|
|
137
|
+
startClipped: activeStarts[i] === start,
|
|
138
|
+
endClipped: true
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
return result;
|
|
142
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
// SPDX-FileComment: Independently implemented legacy twilight heuristic and optional Crumey contrast equations; no reference code copied.
|
|
5
|
+
// Crumey (2014): https://arxiv.org/abs/1405.4209
|
|
6
|
+
// Air mass: Kasten & Young (1989), https://doi.org/10.1364/AO.28.004735
|
|
7
|
+
// Visibility context only (not a reproduction of its model): Tousey & Koomen (1953),
|
|
8
|
+
// https://doi.org/10.1364/JOSA.43.000177
|
|
9
|
+
import {validateRange} from './celestial';
|
|
10
|
+
import {getSkyLuminance, getSkyTransmission} from './sky-brightness';
|
|
11
|
+
import type {SkyAtmosphereOptions} from './sky-brightness';
|
|
12
|
+
|
|
13
|
+
export type PlanetVisibilityOptions = {
|
|
14
|
+
/** Published contrast model, or backward-compatible twilight heuristic. Default legacy. */
|
|
15
|
+
model?: 'legacy' | 'contrast';
|
|
16
|
+
atmosphere?: SkyAtmosphereOptions;
|
|
17
|
+
/** Human visual field factor in the contrast model. Default 2. */
|
|
18
|
+
observerFactor?: number;
|
|
19
|
+
/** Additional directional luminance (e.g. scattered moonlight), cd/m². Default 0. */
|
|
20
|
+
additionalSkyLuminance?: number;
|
|
21
|
+
/** Faintest extincted magnitude at a fully dark sky. Default 6. */
|
|
22
|
+
darkSkyLimitingMagnitude?: number;
|
|
23
|
+
/** Atmospheric extinction in visual magnitudes per air mass. Default 0.2. */
|
|
24
|
+
extinction?: number;
|
|
25
|
+
/** Minimum geometric planet altitude in radians. Default 5 degrees. */
|
|
26
|
+
minimumAltitude?: number;
|
|
27
|
+
/** Minimum angle from the Sun in radians. Default 10 degrees. */
|
|
28
|
+
minimumSunSeparation?: number;
|
|
29
|
+
};
|
|
30
|
+
export type PlanetVisibility = {
|
|
31
|
+
/** Estimated detectability under the specified heuristic, not guaranteed visibility. */
|
|
32
|
+
visible: boolean;
|
|
33
|
+
/** Smooth rendering fade around the visibility threshold, from 0 to 1. */
|
|
34
|
+
fade: number;
|
|
35
|
+
/** Approximate faintest detectable magnitude, including the dark-sky cap. */
|
|
36
|
+
limitingMagnitude: number;
|
|
37
|
+
/** Catalog magnitude plus atmospheric extinction. */
|
|
38
|
+
extinctedMagnitude: number;
|
|
39
|
+
/** Positive when brightness exceeds the approximate sky threshold, in magnitudes. */
|
|
40
|
+
brightnessMargin: number;
|
|
41
|
+
/** Geometric Sun altitude in radians used for the estimate. */
|
|
42
|
+
sunAltitude: number;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Rendering estimate of naked-eye detectability during twilight and darkness.
|
|
47
|
+
* Angle arguments use radians. Default legacy model excludes daylight;
|
|
48
|
+
* optional contrast model uses directional sky background and atmospheric transmission.
|
|
49
|
+
*/
|
|
50
|
+
export function getPlanetVisibility(
|
|
51
|
+
magnitude: number,
|
|
52
|
+
altitude: number,
|
|
53
|
+
sunAltitude: number,
|
|
54
|
+
sunSeparation: number,
|
|
55
|
+
options: PlanetVisibilityOptions = {}
|
|
56
|
+
): PlanetVisibility {
|
|
57
|
+
const {
|
|
58
|
+
darkSkyLimitingMagnitude = 6,
|
|
59
|
+
extinction = 0.2,
|
|
60
|
+
minimumAltitude = (5 * Math.PI) / 180,
|
|
61
|
+
minimumSunSeparation = (10 * Math.PI) / 180
|
|
62
|
+
} = options;
|
|
63
|
+
validateRange('Magnitude', magnitude, -30, 30);
|
|
64
|
+
validateRange('Altitude', altitude, -Math.PI / 2, Math.PI / 2);
|
|
65
|
+
validateRange('Sun altitude', sunAltitude, -Math.PI / 2, Math.PI / 2);
|
|
66
|
+
validateRange('Sun separation', sunSeparation, 0, Math.PI);
|
|
67
|
+
validateRange('Dark sky limiting magnitude', darkSkyLimitingMagnitude, -10, 15);
|
|
68
|
+
validateRange('Extinction', extinction, 0, 5);
|
|
69
|
+
validateRange('Minimum altitude', minimumAltitude, 0, Math.PI / 2);
|
|
70
|
+
validateRange('Minimum Sun separation', minimumSunSeparation, 0, Math.PI);
|
|
71
|
+
const degrees = 180 / Math.PI;
|
|
72
|
+
const elevation = Math.max(0, altitude);
|
|
73
|
+
const airMass =
|
|
74
|
+
1 / (Math.sin(elevation) + 0.50572 * Math.pow(elevation * degrees + 6.07995, -1.6364));
|
|
75
|
+
if (options.model !== undefined && options.model !== 'legacy' && options.model !== 'contrast')
|
|
76
|
+
throw new RangeError('Unknown visibility model');
|
|
77
|
+
const contrastModel = options.model === 'contrast';
|
|
78
|
+
const observerFactor = options.observerFactor ?? 2;
|
|
79
|
+
validateRange('Observer factor', observerFactor, 1, 100);
|
|
80
|
+
validateRange(
|
|
81
|
+
'Additional sky luminance',
|
|
82
|
+
options.additionalSkyLuminance ?? 0,
|
|
83
|
+
0,
|
|
84
|
+
Number.MAX_VALUE
|
|
85
|
+
);
|
|
86
|
+
const extinctedMagnitude = contrastModel
|
|
87
|
+
? magnitude -
|
|
88
|
+
2.5 * Math.log10(Math.max(1e-30, getSkyTransmission(altitude, options.atmosphere)))
|
|
89
|
+
: magnitude + extinction * airMass;
|
|
90
|
+
// Original illustrative anchors, not a fit to the cited visibility paper:
|
|
91
|
+
// Sun 0/-6/-12/-18 degrees -> limiting magnitude -4/1/4.5/6.
|
|
92
|
+
const sunDegrees = sunAltitude * degrees;
|
|
93
|
+
let twilightLimit: number;
|
|
94
|
+
if (sunDegrees >= -6) twilightLimit = -4 - (sunDegrees * 5) / 6;
|
|
95
|
+
else if (sunDegrees >= -12) twilightLimit = 1 + ((-sunDegrees - 6) * 3.5) / 6;
|
|
96
|
+
else if (sunDegrees >= -18)
|
|
97
|
+
twilightLimit = 4.5 + ((-sunDegrees - 12) * (darkSkyLimitingMagnitude - 4.5)) / 6;
|
|
98
|
+
else twilightLimit = darkSkyLimitingMagnitude;
|
|
99
|
+
// Crumey (2014), point-source Blackwell threshold. Original implementation:
|
|
100
|
+
// https://arxiv.org/abs/1405.4209 ; illuminance-to-magnitude zero point -13.99.
|
|
101
|
+
const background = Math.max(
|
|
102
|
+
1e-5,
|
|
103
|
+
getSkyLuminance(sunAltitude, altitude, sunSeparation, options.atmosphere) +
|
|
104
|
+
(options.additionalSkyLuminance ?? 0)
|
|
105
|
+
);
|
|
106
|
+
const threshold =
|
|
107
|
+
background <= 0.0708
|
|
108
|
+
? Math.pow(6.505e-4 * background ** 0.25 - 8.461e-4 * background ** 0.5, 2)
|
|
109
|
+
: Math.pow(1.772e-4 * background ** 0.25 + 7.167e-5 * background ** 0.5, 2);
|
|
110
|
+
const limitingMagnitude = Math.min(
|
|
111
|
+
darkSkyLimitingMagnitude,
|
|
112
|
+
contrastModel ? -2.5 * Math.log10(threshold * observerFactor) - 13.99 : twilightLimit
|
|
113
|
+
);
|
|
114
|
+
const brightnessMargin = limitingMagnitude - extinctedMagnitude;
|
|
115
|
+
const eligible =
|
|
116
|
+
(contrastModel || sunAltitude < 0) &&
|
|
117
|
+
altitude >= minimumAltitude &&
|
|
118
|
+
sunSeparation >= minimumSunSeparation;
|
|
119
|
+
const fade =
|
|
120
|
+
!contrastModel && sunAltitude >= 0
|
|
121
|
+
? 0
|
|
122
|
+
: smoothstep(-0.5, 0.5, brightnessMargin) *
|
|
123
|
+
smoothstep(minimumAltitude - Math.PI / 180, minimumAltitude + Math.PI / 180, altitude) *
|
|
124
|
+
smoothstep(
|
|
125
|
+
minimumSunSeparation - (2 * Math.PI) / 180,
|
|
126
|
+
minimumSunSeparation + (2 * Math.PI) / 180,
|
|
127
|
+
sunSeparation
|
|
128
|
+
) *
|
|
129
|
+
(contrastModel ? 1 : smoothstep(0, Math.PI / 360, -sunAltitude));
|
|
130
|
+
return {
|
|
131
|
+
visible: eligible && brightnessMargin >= 0,
|
|
132
|
+
fade,
|
|
133
|
+
limitingMagnitude,
|
|
134
|
+
extinctedMagnitude,
|
|
135
|
+
brightnessMargin,
|
|
136
|
+
sunAltitude
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function smoothstep(minimum: number, maximum: number, value: number): number {
|
|
141
|
+
const t = Math.max(0, Math.min(1, (value - minimum) / (maximum - minimum)));
|
|
142
|
+
return t * t * (3 - 2 * t);
|
|
143
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
export {getPlanetSkyInfo} from './planet-position';
|
|
5
|
+
export type {
|
|
6
|
+
PlanetName,
|
|
7
|
+
GalileanMoonName,
|
|
8
|
+
PlanetSkyOptions,
|
|
9
|
+
PlanetSkyBody
|
|
10
|
+
} from './planet-position';
|
|
11
|
+
export {getPlanetVisibility} from './planet-visibility';
|
|
12
|
+
export type {PlanetVisibility, PlanetVisibilityOptions} from './planet-visibility';
|
|
13
|
+
export {getPlanetVisibilityTimes} from './planet-times';
|
|
14
|
+
export type {
|
|
15
|
+
PlanetVisibilityTimes,
|
|
16
|
+
PlanetVisibilityTimesOptions,
|
|
17
|
+
PlanetVisibilityInterval
|
|
18
|
+
} from './planet-times';
|