@johnmorrisdotca/chikyu-earth 0.53.0 → 0.55.0

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.
@@ -0,0 +1,223 @@
1
+ // Which way a satellite is going over the ground, and whether the Sun lights it: from its place and velocity alone. Pure: no DOM, no clock and no dependency (not even satellite.js), so a page, a build step or a server can write "heading SE 128 degrees, in sunlight" from numbers it already has.
2
+ // `groundTrackState(elements, ms)` in `@johnmorrisdotca/chikyu-earth/passes` runs SGP4 for you and hands the result here.
3
+ import { greenwichSidereal, subsolarPoint } from "../realistic/sun.js";
4
+ const RAD = Math.PI / 180;
5
+ /** The Earth's equatorial radius, kilometres (WGS84). */
6
+ const A = 6378.137;
7
+ /** The Earth's flattening (WGS84). */
8
+ const F = 1 / 298.257223563;
9
+ const E2 = F * (2 - F);
10
+ /** The Earth's turn, radians a second. */
11
+ const OMEGA = 7.292115e-5;
12
+ /** One Earth radius of the package's scene units, kilometres (the satellites' places are in these). */
13
+ const SCENE_KM = 6371;
14
+ /**
15
+ * The radius of the Earth's shadow, kilometres: the Earth's equatorial radius (6,378.137 km). The shadow is a cylinder of this radius along the line from the Sun through the Earth's centre (the cylindrical model: the edge of a conical umbra
16
+ * leans in by about 0.26 degrees, so where a satellite at 400 km enters the shadow the cylinder's edge is about 11 km outside the cone's, a few seconds of an orbit, and no penumbra is drawn). A satellite is in shadow when it is on the night side of the centre and inside the cylinder.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import { SHADOW_RADIUS_KM } from "@johnmorrisdotca/chikyu-earth/flat";
21
+ *
22
+ * console.log(SHADOW_RADIUS_KM);
23
+ * ```
24
+ */
25
+ export const SHADOW_RADIUS_KM = A;
26
+ /**
27
+ * The Sun as a unit vector in the Earth-fixed axes (x through longitude 0 on the equator, y east, z north) at `ms`, from the same low-precision Sun as the night side of the maps.
28
+ *
29
+ * @param ms - A moment, in milliseconds since the Unix epoch.
30
+ * @returns The unit vector from the Earth's centre towards the Sun.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * import { sunDirection } from "@johnmorrisdotca/chikyu-earth/flat";
35
+ *
36
+ * const sun = sunDirection(Date.UTC(2026, 5, 21, 12));
37
+ * console.log(sun.map((n) => n.toFixed(2)));
38
+ * ```
39
+ */
40
+ export function sunDirection(ms) {
41
+ const sun = subsolarPoint(ms);
42
+ const lat = sun.lat * RAD;
43
+ const lon = sun.lon * RAD;
44
+ return [Math.cos(lat) * Math.cos(lon), Math.cos(lat) * Math.sin(lon), Math.sin(lat)];
45
+ }
46
+ /**
47
+ * Is a point in the Earth's shadow? Cylindrical model: behind the Earth's centre from the Sun and nearer the Sun-Earth line than {@link SHADOW_RADIUS_KM}.
48
+ *
49
+ * @param position - The point, kilometres from the Earth's centre, in any axes.
50
+ * @param sun - The unit vector towards the Sun, in the same axes.
51
+ * @returns True in shadow, false in sunlight (a point exactly on the terminator plane is sunlit).
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * import { inEarthShadow } from "@johnmorrisdotca/chikyu-earth/flat";
56
+ *
57
+ * // the Sun along +x: a satellite 7,000 km out on the far side is in shadow, one at the same distance beside the Earth is not
58
+ * console.log(inEarthShadow([-7000, 0, 0], [1, 0, 0]), inEarthShadow([0, 7000, 0], [1, 0, 0]));
59
+ * ```
60
+ */
61
+ export function inEarthShadow(position, sun) {
62
+ const along = position[0] * sun[0] + position[1] * sun[1] + position[2] * sun[2];
63
+ if (along >= 0)
64
+ return false;
65
+ const r2 = position[0] * position[0] + position[1] * position[1] + position[2] * position[2];
66
+ return r2 - along * along < A * A;
67
+ }
68
+ /**
69
+ * Where a satellite is over the ground, how it is going and whether the Sun lights it, from its place and velocity in the axes SGP4 uses (TEME: x to the vernal equinox, z north, y a quarter turn east of x) and the moment. The
70
+ * velocity is turned into the ground's frame by taking the Earth's turn out of it, so the bearing is the way the ground track runs, as a map draws it.
71
+ *
72
+ * @param position - Kilometres from the Earth's centre, TEME.
73
+ * @param velocity - Kilometres a second, TEME.
74
+ * @param ms - The moment, in milliseconds since the Unix epoch.
75
+ * @returns Latitude, longitude, height, bearing, ascending or descending, and sunlit.
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * import { trackStateOf } from "@johnmorrisdotca/chikyu-earth/flat";
80
+ *
81
+ * // 420 km over the equator going north at 7.66 km a second
82
+ * const at = Date.UTC(2026, 10, 3, 12);
83
+ * const state = trackStateOf([6798, 0, 0], [0, 0, 7.66], at);
84
+ * console.log(state.ascending, Math.round(state.heightKm));
85
+ * ```
86
+ */
87
+ export function trackStateOf(position, velocity, ms) {
88
+ const theta = greenwichSidereal(ms) * RAD;
89
+ const c = Math.cos(theta);
90
+ const s = Math.sin(theta);
91
+ // the Earth-fixed axes: turn by the sidereal angle about the pole
92
+ const x = c * position[0] + s * position[1];
93
+ const y = -s * position[0] + c * position[1];
94
+ const z = position[2];
95
+ // the velocity as the ground sees it: turned the same way, less the ground's own motion (omega x r)
96
+ const vx = c * velocity[0] + s * velocity[1] + OMEGA * y;
97
+ const vy = -s * velocity[0] + c * velocity[1] - OMEGA * x;
98
+ const vz = velocity[2];
99
+ const lon = Math.atan2(y, x);
100
+ const p = Math.hypot(x, y);
101
+ // the geodetic latitude and height, by iteration (a few steps settle it to well under a metre)
102
+ let lat = Math.atan2(z, p * (1 - E2));
103
+ let n = A;
104
+ for (let i = 0; i < 6; i += 1) {
105
+ const sin = Math.sin(lat);
106
+ n = A / Math.sqrt(1 - E2 * sin * sin);
107
+ lat = Math.atan2(z + E2 * n * sin, p);
108
+ }
109
+ const cosLat = Math.cos(lat);
110
+ const sinLat = Math.sin(lat);
111
+ const heightKm = Math.abs(cosLat) > 1e-9 ? p / cosLat - n : Math.abs(z) / Math.abs(sinLat) - n * (1 - E2);
112
+ const cosLon = Math.cos(lon);
113
+ const sinLon = Math.sin(lon);
114
+ const east = -sinLon * vx + cosLon * vy;
115
+ const north = -sinLat * cosLon * vx - sinLat * sinLon * vy + cosLat * vz;
116
+ const moving = Math.hypot(east, north) > 1e-9;
117
+ const bearing = moving ? ((Math.atan2(east, north) / RAD) % 360 + 360) % 360 : 0;
118
+ return {
119
+ lat: lat / RAD,
120
+ lon: ((((lon / RAD) % 360) + 540) % 360) - 180,
121
+ heightKm,
122
+ bearingDeg: bearing,
123
+ ascending: north > 0,
124
+ sunlit: !inEarthShadow([x, y, z], sunDirection(ms)),
125
+ };
126
+ }
127
+ /**
128
+ * The same as {@link trackStateOf}, for a place and velocity in the package's own satellite axes (what `createSatellites(...).exact` and the space view give): Earth radii of 6,371 km, x to the vernal equinox, y north, z the other way from TEME's y; the velocity in kilometres a second in the same axes.
129
+ *
130
+ * @param place - Earth radii from the Earth's centre.
131
+ * @param velocity - Kilometres a second.
132
+ * @param ms - The moment, in milliseconds since the Unix epoch.
133
+ * @returns Latitude, longitude, height, bearing, ascending or descending, and sunlit.
134
+ *
135
+ * @example
136
+ * ```ts
137
+ * import { trackStateOfScene } from "@johnmorrisdotca/chikyu-earth/flat";
138
+ *
139
+ * const state = trackStateOfScene([1.0665, 0, 0], [0, 7.66, 0], Date.UTC(2026, 10, 3, 12));
140
+ * console.log(state.ascending);
141
+ * ```
142
+ */
143
+ export function trackStateOfScene(place, velocity, ms) {
144
+ return trackStateOf([place[0] * SCENE_KM, -place[2] * SCENE_KM, place[1] * SCENE_KM], [velocity[0], -velocity[2], velocity[1]], ms);
145
+ }
146
+ /**
147
+ * The eight points of the compass, from north clockwise.
148
+ *
149
+ * @example
150
+ * ```ts
151
+ * import { COMPASS_POINTS } from "@johnmorrisdotca/chikyu-earth/flat";
152
+ *
153
+ * console.log(COMPASS_POINTS.join(" "));
154
+ * ```
155
+ */
156
+ export const COMPASS_POINTS = ["N", "NE", "E", "SE", "S", "SW", "W", "NW"];
157
+ /**
158
+ * The point of the compass a bearing is nearest to: 0 is N, 45 NE, 90 E, 135 SE, 180 S and so on, each point taking 45 degrees (22.5 either side).
159
+ *
160
+ * @param bearingDeg - Degrees clockwise from north.
161
+ * @returns N, NE, E, SE, S, SW, W or NW.
162
+ *
163
+ * @example
164
+ * ```ts
165
+ * import { compassPoint } from "@johnmorrisdotca/chikyu-earth/flat";
166
+ *
167
+ * console.log(compassPoint(128), compassPoint(350));
168
+ * ```
169
+ */
170
+ export function compassPoint(bearingDeg) {
171
+ return COMPASS_POINTS[Math.round((((bearingDeg % 360) + 360) % 360) / 45) % 8];
172
+ }
173
+ /**
174
+ * The Sun as a unit vector in the satellites' own axes (x to the vernal equinox, y north, z the other way from TEME's y: what `createSatellites` and the space view use) at `ms`.
175
+ *
176
+ * @param ms - A moment, in milliseconds since the Unix epoch.
177
+ * @returns The unit vector from the Earth's centre towards the Sun.
178
+ *
179
+ * @example
180
+ * ```ts
181
+ * import { sunDirectionScene } from "@johnmorrisdotca/chikyu-earth/flat";
182
+ *
183
+ * console.log(sunDirectionScene(Date.UTC(2026, 2, 20, 9)).map((n) => n.toFixed(2)));
184
+ * ```
185
+ */
186
+ export function sunDirectionScene(ms) {
187
+ const fixed = sunDirection(ms);
188
+ const theta = greenwichSidereal(ms) * RAD;
189
+ const c = Math.cos(theta);
190
+ const s = Math.sin(theta);
191
+ // Earth-fixed back to the stars (TEME), then into the satellites' axes
192
+ const x = c * fixed[0] - s * fixed[1];
193
+ const y = s * fixed[0] + c * fixed[1];
194
+ return [x, fixed[2], -y];
195
+ }
196
+ /**
197
+ * Which points of a path are in the Earth's shadow: 1 for in shadow, 0 for in sunlight (the cylindrical model, {@link SHADOW_RADIUS_KM}), for places in the satellites' own axes in Earth radii of 6,371 km. The Sun is taken as fixed over the path, which holds for the one revolution a path is (the Sun moves a quarter of a degree in that time).
198
+ *
199
+ * @param positions - Three numbers a point, Earth radii.
200
+ * @param count - How many points.
201
+ * @param sun - The unit vector towards the Sun in the same axes (`sunDirectionScene`).
202
+ * @param out - Where to put the flags, one a point.
203
+ * @returns `out`.
204
+ *
205
+ * @example
206
+ * ```ts
207
+ * import { shadowFlags } from "@johnmorrisdotca/chikyu-earth/flat";
208
+ *
209
+ * // the Sun along +x: the point behind the Earth is in shadow, the one in front of it is not
210
+ * console.log(shadowFlags(new Float32Array([-1.1, 0, 0, 1.1, 0, 0]), 2, [1, 0, 0], new Uint8Array(2)));
211
+ * ```
212
+ */
213
+ export function shadowFlags(positions, count, sun, out) {
214
+ const radius = SHADOW_RADIUS_KM / SCENE_KM;
215
+ for (let i = 0; i < count; i += 1) {
216
+ const x = positions[i * 3];
217
+ const y = positions[i * 3 + 1];
218
+ const z = positions[i * 3 + 2];
219
+ const along = x * sun[0] + y * sun[1] + z * sun[2];
220
+ out[i] = along < 0 && x * x + y * y + z * z - along * along < radius * radius ? 1 : 0;
221
+ }
222
+ return out;
223
+ }
@@ -35,6 +35,11 @@ export const FLAT_WORDS = {
35
35
  nothing: "No satellite to show.",
36
36
  help: "Arrow keys move from one satellite to the next, Enter chooses it, plus and minus zoom.",
37
37
  shown: "{count} satellites shown",
38
+ trackSunlit: "In sunlight",
39
+ trackShadow: "In the Earth's shadow",
40
+ trackKey: "Ground track colours",
41
+ sunlitNow: ", in sunlight",
42
+ shadowNow: ", in the Earth's shadow",
38
43
  },
39
44
  ja: {
40
45
  map: "世界の平面地図の上の衛星",
@@ -62,6 +67,11 @@ export const FLAT_WORDS = {
62
67
  nothing: "表示する衛星がありません。",
63
68
  help: "矢印キーで次の衛星へ移り、Enter キーで選びます。プラスとマイナスで拡大・縮小します。",
64
69
  shown: "{count} 機を表示中",
70
+ trackSunlit: "日なた",
71
+ trackShadow: "地球の影の中",
72
+ trackKey: "地上軌跡の色",
73
+ sunlitNow: "、日なた",
74
+ shadowNow: "、地球の影の中",
65
75
  },
66
76
  };
67
77
  /** The words with their `{name}` places filled in. */
@@ -1,3 +1,4 @@
1
- export { compassOf, findPasses, groundTrack, passPath, satelliteAt, skyAt, sunAltitude, type Compass, type GroundPoint, type Observer, type PassOptions, type PassPoint, type PassReason, type PassWindow, type PathPoint, type SatellitePass, type SkyName, type VisiblePart, } from "./passes.ts";
1
+ export { compassOf, findPasses, groundTrack, groundTrackState, passPath, satelliteAt, skyAt, sunAltitude, type Compass, type GroundPoint, type Observer, type PassOptions, type PassPoint, type PassReason, type PassWindow, type PathPoint, type SatellitePass, type SkyName, type VisiblePart, } from "./passes.ts";
2
2
  export { ESTIMATED_CROSS_SECTIONS, magnitude, standardMagnitude, STANDARD_MAGNITUDES } from "./magnitudes.ts";
3
3
  export { skySvg, type SkyLabels, type SkyOptions } from "./sky.ts";
4
+ export type { GroundTrackState } from "../flat/track-state.ts";
@@ -1,4 +1,4 @@
1
1
  // The passes' pure parts: when a satellite crosses the sky over a place, how it looks, and the sky dome that draws it. They need satellite.js (an optional peer) and import in a browser or on a server.
2
- export { compassOf, findPasses, groundTrack, passPath, satelliteAt, skyAt, sunAltitude, } from "./passes.js";
2
+ export { compassOf, findPasses, groundTrack, groundTrackState, passPath, satelliteAt, skyAt, sunAltitude, } from "./passes.js";
3
3
  export { ESTIMATED_CROSS_SECTIONS, magnitude, standardMagnitude, STANDARD_MAGNITUDES } from "./magnitudes.js";
4
4
  export { skySvg } from "./sky.js";
@@ -1,3 +1,4 @@
1
+ import { type GroundTrackState } from "../flat/track-state.ts";
1
2
  import type { ElementSet } from "../satellites/types.ts";
2
3
  /**
3
4
  * Where the watcher stands: degrees of latitude (north is positive) and longitude (east is positive), and the height above sea level in metres (0 by default).
@@ -363,6 +364,8 @@ export interface GroundPoint {
363
364
  lon: number;
364
365
  /** Height above the Earth's surface, kilometres. */
365
366
  altitudeKm: number;
367
+ /** True when the Sun lights the satellite there, false when it is in the Earth's shadow (the cylindrical model, as `satelliteAt` and `passPath` use). */
368
+ sunlit: boolean;
366
369
  }
367
370
  /**
368
371
  * The places straight under a satellite from one moment to another: its ground track. Use a pass's `start.ms` and `end.ms` for the track of one pass, to draw on a globe.
@@ -397,3 +400,34 @@ export interface GroundPoint {
397
400
  * ```
398
401
  */
399
402
  export declare function groundTrack(set: ElementSet, fromMs: number, toMs: number, stepSeconds?: number): GroundPoint[];
403
+ /**
404
+ * Where one satellite is over the ground at one moment, which way it is going and whether the Sun lights it: latitude, longitude, height, the bearing of its ground track (degrees clockwise from north, with the Earth's turn taken out), ascending or descending, and sunlit
405
+ * (the cylindrical shadow model). SGP4 places it; the rest is {@link trackStateOf}, which does the same from a place and a velocity you already have. Undefined where SGP4 gives no place.
406
+ *
407
+ * @param set - The satellite's elements.
408
+ * @param ms - The moment, milliseconds since the Unix epoch.
409
+ * @returns The state, or undefined.
410
+ *
411
+ * @example
412
+ * ```ts
413
+ * import { groundTrackState } from "@johnmorrisdotca/chikyu-earth/passes";
414
+ *
415
+ * const iss = {
416
+ * OBJECT_NAME: "ISS (ZARYA)",
417
+ * EPOCH: "2026-11-02T10:25:21.580320",
418
+ * MEAN_MOTION: 15.49150046,
419
+ * ECCENTRICITY: 0.0007139,
420
+ * INCLINATION: 51.6332,
421
+ * RA_OF_ASC_NODE: 335.9757,
422
+ * ARG_OF_PERICENTER: 339.3739,
423
+ * MEAN_ANOMALY: 20.6961,
424
+ * NORAD_CAT_ID: 25544,
425
+ * BSTAR: 0.00012,
426
+ * MEAN_MOTION_DOT: 0.0001,
427
+ * MEAN_MOTION_DDOT: 0,
428
+ * };
429
+ * const state = groundTrackState(iss, Date.UTC(2026, 10, 3, 12));
430
+ * console.log(state && `${state.bearingDeg.toFixed(0)} degrees, ${state.ascending ? "ascending" : "descending"}, ${state.sunlit ? "sunlit" : "in shadow"}`);
431
+ * ```
432
+ */
433
+ export declare function groundTrackState(set: ElementSet, ms: number): GroundTrackState | undefined;
@@ -1,6 +1,7 @@
1
1
  // When a satellite crosses the sky over a place. SGP4 (satellite.js, an optional peer) puts the satellite in the sky, this package's own Sun position says whether the watcher's sky is dark and whether
2
2
  // the satellite is in sunlight, and the brightness follows from the standard magnitude. Pure: no DOM, no clock (the window is given), no state; it imports on a server.
3
3
  import { ecfToLookAngles, eciToEcf, eciToGeodetic, geodeticToEcf, gstime, json2satrec, sgp4 } from "satellite.js";
4
+ import { inEarthShadow, trackStateOf } from "../flat/track-state.js";
4
5
  import { subsolarPoint } from "../realistic/sun.js";
5
6
  import { DEFAULT_DIM_AFTER_DAYS, DEFAULT_MAX_AGE_DAYS } from "../satellites/limits.js";
6
7
  import { magnitude, STANDARD_MAGNITUDES } from "./magnitudes.js";
@@ -459,11 +460,51 @@ export function groundTrack(set, fromMs, toMs, stepSeconds = 10) {
459
460
  const t = Math.min(ms, toMs);
460
461
  const sample = sgp4(rec, (t - epoch) / 60_000);
461
462
  if (sample && sample.position && Number.isFinite(sample.position.x)) {
462
- const place = eciToGeodetic(sample.position, gstime(new Date(t)));
463
- out.push({ ms: t, lat: place.latitude / RAD, lon: ((((place.longitude / RAD) % 360) + 540) % 360) - 180, altitudeKm: place.height });
463
+ const gmst = gstime(new Date(t));
464
+ const place = eciToGeodetic(sample.position, gmst);
465
+ const ecf = eciToEcf(sample.position, gmst);
466
+ out.push({ ms: t, lat: place.latitude / RAD, lon: ((((place.longitude / RAD) % 360) + 540) % 360) - 180, altitudeKm: place.height, sunlit: !inEarthShadow([ecf.x, ecf.y, ecf.z], sunVector(t)) });
464
467
  }
465
468
  if (t >= toMs)
466
469
  break;
467
470
  }
468
471
  return out;
469
472
  }
473
+ /**
474
+ * Where one satellite is over the ground at one moment, which way it is going and whether the Sun lights it: latitude, longitude, height, the bearing of its ground track (degrees clockwise from north, with the Earth's turn taken out), ascending or descending, and sunlit
475
+ * (the cylindrical shadow model). SGP4 places it; the rest is {@link trackStateOf}, which does the same from a place and a velocity you already have. Undefined where SGP4 gives no place.
476
+ *
477
+ * @param set - The satellite's elements.
478
+ * @param ms - The moment, milliseconds since the Unix epoch.
479
+ * @returns The state, or undefined.
480
+ *
481
+ * @example
482
+ * ```ts
483
+ * import { groundTrackState } from "@johnmorrisdotca/chikyu-earth/passes";
484
+ *
485
+ * const iss = {
486
+ * OBJECT_NAME: "ISS (ZARYA)",
487
+ * EPOCH: "2026-11-02T10:25:21.580320",
488
+ * MEAN_MOTION: 15.49150046,
489
+ * ECCENTRICITY: 0.0007139,
490
+ * INCLINATION: 51.6332,
491
+ * RA_OF_ASC_NODE: 335.9757,
492
+ * ARG_OF_PERICENTER: 339.3739,
493
+ * MEAN_ANOMALY: 20.6961,
494
+ * NORAD_CAT_ID: 25544,
495
+ * BSTAR: 0.00012,
496
+ * MEAN_MOTION_DOT: 0.0001,
497
+ * MEAN_MOTION_DDOT: 0,
498
+ * };
499
+ * const state = groundTrackState(iss, Date.UTC(2026, 10, 3, 12));
500
+ * console.log(state && `${state.bearingDeg.toFixed(0)} degrees, ${state.ascending ? "ascending" : "descending"}, ${state.sunlit ? "sunlit" : "in shadow"}`);
501
+ * ```
502
+ */
503
+ export function groundTrackState(set, ms) {
504
+ const rec = json2satrec(set);
505
+ const sample = sgp4(rec, (ms - epochOf(set.EPOCH)) / 60_000);
506
+ if (!sample || !sample.position || !sample.velocity || !Number.isFinite(sample.position.x))
507
+ return undefined;
508
+ const { position: p, velocity: v } = sample;
509
+ return trackStateOf([p.x, p.y, p.z], [v.x, v.y, v.z], ms);
510
+ }
@@ -0,0 +1,232 @@
1
+ /**
2
+ * The smallest side of a box, in kilometres: a `sizeKm` below it is held at it.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import { PHOTO_MIN_KM } from "@johnmorrisdotca/chikyu-earth/photos";
7
+ *
8
+ * console.log(PHOTO_MIN_KM);
9
+ * ```
10
+ */
11
+ export declare const PHOTO_MIN_KM = 1;
12
+ /**
13
+ * The largest side of a box, in kilometres: a `sizeKm` above it is held at it.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { PHOTO_MAX_KM } from "@johnmorrisdotca/chikyu-earth/photos";
18
+ *
19
+ * console.log(PHOTO_MAX_KM);
20
+ * ```
21
+ */
22
+ export declare const PHOTO_MAX_KM = 4000;
23
+ /**
24
+ * The width in pixels a picture has when a page does not say.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * import { PHOTO_DEFAULT_PX } from "@johnmorrisdotca/chikyu-earth/photos";
29
+ *
30
+ * console.log(PHOTO_DEFAULT_PX);
31
+ * ```
32
+ */
33
+ export declare const PHOTO_DEFAULT_PX = 512;
34
+ /**
35
+ * The most pixels a picture may have across (and up): a larger `widthPx` is held at it.
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * import { PHOTO_MAX_PX } from "@johnmorrisdotca/chikyu-earth/photos";
40
+ *
41
+ * console.log(PHOTO_MAX_PX);
42
+ * ```
43
+ */
44
+ export declare const PHOTO_MAX_PX = 2048;
45
+ /**
46
+ * How many days, counting the first, `photoFallbacks` goes back by default.
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * import { PHOTO_FALLBACK_DAYS } from "@johnmorrisdotca/chikyu-earth/photos";
51
+ *
52
+ * console.log(PHOTO_FALLBACK_DAYS);
53
+ * ```
54
+ */
55
+ export declare const PHOTO_FALLBACK_DAYS = 3;
56
+ /**
57
+ * What to ask for: a point, the side of the box in kilometres, and the day.
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * import type { PhotoOptions } from "@johnmorrisdotca/chikyu-earth/photos";
62
+ *
63
+ * const tokyo: PhotoOptions = { lat: 35.68, lon: 139.77, sizeKm: 200, date: "2026-11-10" };
64
+ * console.log(tokyo.sizeKm);
65
+ * ```
66
+ */
67
+ export interface PhotoOptions {
68
+ /** Degrees north (-90 to 90; a value outside is held at the pole). */
69
+ lat: number;
70
+ /** Degrees east (any number; it is wrapped into -180 to 180). */
71
+ lon: number;
72
+ /** The side of the box on the ground, in kilometres (held between `PHOTO_MIN_KM` and `PHOTO_MAX_KM`). */
73
+ sizeKm: number;
74
+ /** The UTC day as `yyyy-mm-dd`, or a Date or milliseconds since the epoch (its UTC day). */
75
+ date: string | number | Date;
76
+ /** The picture's width and height in pixels (a square). 512 when left out, and never more than `PHOTO_MAX_PX`. */
77
+ widthPx?: number;
78
+ }
79
+ /**
80
+ * A box in degrees. `west` may be below -180 or `east` above 180 when the box crosses the date line (`wraps`).
81
+ *
82
+ * @example
83
+ * ```ts
84
+ * import type { PhotoBox } from "@johnmorrisdotca/chikyu-earth/photos";
85
+ *
86
+ * const box: PhotoBox = { south: 34, north: 36, west: 138, east: 141, wraps: false };
87
+ * console.log(box.east - box.west);
88
+ * ```
89
+ */
90
+ export interface PhotoBox {
91
+ south: number;
92
+ north: number;
93
+ west: number;
94
+ east: number;
95
+ wraps: boolean;
96
+ }
97
+ /**
98
+ * One request for a picture: its box (inside -180 to 180), its address, and where it goes in the whole picture. A box that crosses the date line is two of these, side by side.
99
+ *
100
+ * @example
101
+ * ```ts
102
+ * import type { PhotoPiece } from "@johnmorrisdotca/chikyu-earth/photos";
103
+ *
104
+ * const place = (piece: PhotoPiece): string => `${piece.offsetPx},${piece.widthPx}`;
105
+ * console.log(typeof place);
106
+ * ```
107
+ */
108
+ export interface PhotoPiece {
109
+ url: string;
110
+ south: number;
111
+ north: number;
112
+ west: number;
113
+ east: number;
114
+ /** Pixels from the left of the whole picture. */
115
+ offsetPx: number;
116
+ widthPx: number;
117
+ heightPx: number;
118
+ }
119
+ /**
120
+ * One day to try: the day, the layer that has it, the one address of `photoUrl`, and the pieces of the exact box.
121
+ *
122
+ * @example
123
+ * ```ts
124
+ * import type { PhotoShot } from "@johnmorrisdotca/chikyu-earth/photos";
125
+ *
126
+ * const label = (shot: PhotoShot): string => `${shot.date} ${shot.layer}`;
127
+ * console.log(typeof label);
128
+ * ```
129
+ */
130
+ export interface PhotoShot {
131
+ date: string;
132
+ layer: string;
133
+ url: string;
134
+ pieces: PhotoPiece[];
135
+ }
136
+ /**
137
+ * The box a picture of `sizeKm` around a point covers, in degrees. The height is `sizeKm` of latitude; the width is as many degrees of longitude as make `sizeKm` at the box's middle latitude, so the picture is square on the ground.
138
+ * At a pole the box is moved down so it stays on the Earth (the point is then at its edge) and its width in longitude grows to about 115 degrees. Across the date line `west` is below -180 or `east` above 180 and `wraps` is true.
139
+ *
140
+ * @param options - The point and the size; the date and the width are not read.
141
+ * @returns The box.
142
+ *
143
+ * @example
144
+ * ```ts
145
+ * import { photoBox } from "@johnmorrisdotca/chikyu-earth/photos";
146
+ *
147
+ * const fiji = photoBox({ lat: -17.7, lon: 179.9, sizeKm: 200, date: "2026-11-10" });
148
+ * console.log(fiji.wraps, fiji.east > 180);
149
+ * ```
150
+ */
151
+ export declare function photoBox(options: PhotoOptions): PhotoBox;
152
+ /**
153
+ * The id of the layer `photoUrl` uses for a day: the first of NOAA-20 VIIRS, Suomi NPP VIIRS and MODIS Terra (all true colour) whose days include it, or null before 2000-02-24.
154
+ *
155
+ * @param day - The UTC day, `yyyy-mm-dd`.
156
+ * @returns The layer id, or null.
157
+ *
158
+ * @example
159
+ * ```ts
160
+ * import { photoLayer } from "@johnmorrisdotca/chikyu-earth/photos";
161
+ *
162
+ * console.log(photoLayer("2026-11-10"), photoLayer("2010-06-01"), photoLayer("1999-01-01"));
163
+ * ```
164
+ */
165
+ export declare function photoLayer(day: string): string | null;
166
+ /**
167
+ * The address of a NASA GIBS snapshot (a WMS GetMap request, EPSG:4326, JPEG) of the box around a point on a day, from the best true-colour layer that has the day (`photoLayer`: NOAA-20 VIIRS from 2018, then Suomi NPP VIIRS and MODIS Terra back to 2000-02-24). About 250 m a pixel, clouds left in.
168
+ * The picture is one request, so a box that would cross the date line or run off a pole is moved to stay inside the world: the point is then not in the middle. `photoPieces` gives the exact box in two requests.
169
+ *
170
+ * @param options - The point, the size of the box and the day.
171
+ * @returns The address, or null when no layer has a picture for the day (before 2000-02-24).
172
+ * @throws RangeError when a number is not finite or the date is not a day.
173
+ *
174
+ * @example
175
+ * ```ts
176
+ * import { photoUrl } from "@johnmorrisdotca/chikyu-earth/photos";
177
+ *
178
+ * const url = photoUrl({ lat: 35.68, lon: 139.77, sizeKm: 200, date: "2026-11-10", widthPx: 512 });
179
+ * console.log(url?.includes("TIME=2026-11-10"));
180
+ * ```
181
+ */
182
+ export declare function photoUrl(options: PhotoOptions): string | null;
183
+ /**
184
+ * The exact box of a point as one or two requests, left to right: two when it crosses the date line, so a page can lay them side by side and the point stays in the middle.
185
+ *
186
+ * @param options - The point, the size of the box and the day.
187
+ * @returns The pieces, or an empty list when no layer has a picture for the day.
188
+ * @throws RangeError when a number is not finite or the date is not a day.
189
+ *
190
+ * @example
191
+ * ```ts
192
+ * import { photoPieces } from "@johnmorrisdotca/chikyu-earth/photos";
193
+ *
194
+ * const pieces = photoPieces({ lat: -17.7, lon: 179.9, sizeKm: 200, date: "2026-11-10" });
195
+ * console.log(pieces.length, pieces.map((piece) => piece.widthPx));
196
+ * ```
197
+ */
198
+ export declare function photoPieces(options: PhotoOptions): PhotoPiece[];
199
+ /**
200
+ * The days to try, newest first: the day asked for, then each day before it, up to `days` of them, skipping a day no layer has. NASA has no picture for a day whose satellite passes it has not yet processed (and answers with a black one, not an error), so a page tries the next of these when one is blank.
201
+ *
202
+ * @param options - The point, the size of the box and the first day.
203
+ * @param days - How many days to count back, the first included (3 by default).
204
+ * @returns The shots, each with its day, layer, one address and pieces.
205
+ * @throws RangeError when a number is not finite or the date is not a day.
206
+ *
207
+ * @example
208
+ * ```ts
209
+ * import { photoFallbacks } from "@johnmorrisdotca/chikyu-earth/photos";
210
+ *
211
+ * const shots = photoFallbacks({ lat: 35.68, lon: 139.77, sizeKm: 200, date: "2026-11-10" }, 3);
212
+ * console.log(shots.map((shot) => shot.date));
213
+ * ```
214
+ */
215
+ export declare function photoFallbacks(options: PhotoOptions, days?: number): PhotoShot[];
216
+ /**
217
+ * The credit line to show with a picture, in English or Japanese. `full` gives NASA's own acknowledgement sentence for GIBS (the Japanese is this package's translation: NASA publishes none) instead of the short line.
218
+ * The short line names NASA as the source, as NASA asks, and says it is not an endorsement.
219
+ *
220
+ * @param lang - `en` or `ja`.
221
+ * @param full - True for the whole acknowledgement sentence.
222
+ * @returns The line.
223
+ *
224
+ * @example
225
+ * ```ts
226
+ * import { photoCredit } from "@johnmorrisdotca/chikyu-earth/photos";
227
+ *
228
+ * console.log(photoCredit("en"));
229
+ * console.log(photoCredit("ja", true).length > photoCredit("ja").length);
230
+ * ```
231
+ */
232
+ export declare function photoCredit(lang: "en" | "ja", full?: boolean): string;