@johnmorrisdotca/wakusei-planets 0.36.0 → 0.37.1

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,296 @@
1
+ import type { HostId } from "./facts.ts";
2
+ import { type Vec3 } from "./vec.ts";
3
+ import { type When } from "./when.ts";
4
+ export type { HostId } from "./facts.ts";
5
+ export type { When } from "./when.ts";
6
+ /**
7
+ * The dynamical group of a moon, by this package's rule on the mean orbit. A regular moon (close in, near its planet's equator) is `major` (150 km of radius or more: the Moon, the Galilean moons, Titan, Triton, Charon and
8
+ * the like), `inner` (a smaller one inside its planet's innermost major moon, near the rings) or `regular` (the others: Phobos, Deimos, Hyperion, Pluto's small moons). An irregular moon (one whose mean orbit JPL gives about
9
+ * the ecliptic, because the Sun's pull steers it, or one over 100 planet radii out) is in one of Jupiter's groups `themisto`, `himalia`, `carpo`, `valetudo`, `ananke`, `carme` and `pasiphae`, Saturn's `inuit`, `gallic` and
10
+ * `norse`, or, for Uranus and Neptune, `prograde` or `retrograde`. `none` is a moon with no mean orbit in the source. The guide "Every known moon" gives the numbers of the rule.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { MOON_GROUPS, type MoonGroup } from "@johnmorrisdotca/wakusei-planets/moon-catalogue";
15
+ *
16
+ * const group: MoonGroup = "carme";
17
+ * console.log(MOON_GROUPS.includes(group));
18
+ * ```
19
+ */
20
+ export type MoonGroup = "inner" | "major" | "regular" | "themisto" | "himalia" | "carpo" | "valetudo" | "ananke" | "carme" | "pasiphae" | "inuit" | "gallic" | "norse" | "prograde" | "retrograde" | "none";
21
+ /**
22
+ * Every group, in the order the guide lists them.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * import { MOON_GROUPS } from "@johnmorrisdotca/wakusei-planets/moon-catalogue";
27
+ *
28
+ * console.log(MOON_GROUPS.join(", "));
29
+ * ```
30
+ */
31
+ export declare const MOON_GROUPS: readonly MoonGroup[];
32
+ /**
33
+ * How well the catalogue places a moon, by the worst angle (seen from the planet's centre) between `catalogueMoonPosition` and JPL Horizons on 2025-07-02, 2026-07-02 and 2027-07-02, dates the orbit was not set from:
34
+ * `close` under 1 degree, `rough` under 10 degrees, `loose` 10 degrees or more (the moon is on the right orbit but not at the right place on it), `unmeasured` when Horizons has no position to measure against, and `none`
35
+ * when there is no orbit. Every grade is below the package's own 29 moons (`full`), which the main entry point places within arc-seconds to minutes (see the accuracy guide).
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * import { findCatalogueMoon, type MoonGrade } from "@johnmorrisdotca/wakusei-planets/moon-catalogue";
40
+ *
41
+ * const grade: MoonGrade = findCatalogueMoon("Himalia")!.grade;
42
+ * console.log(grade);
43
+ * ```
44
+ */
45
+ export type MoonGrade = "close" | "rough" | "loose" | "unmeasured" | "none";
46
+ /**
47
+ * A moon's mean orbit: JPL's "Planetary Satellite Mean Elements" (the ellipse, how fast its periapsis and node turn, and the plane it is measured from), carried at those rates to 2026-01-01 and with the mean anomaly set
48
+ * so the moon is where JPL Horizons puts it that day, and its rate along the orbit fitted to where Horizons puts it over the next three months. The shape, the plane and the turning of the periapsis and node are JPL's; the
49
+ * place along the orbit and the rate are from Horizons. Kilometres and degrees; the epoch is a Julian date (TDB).
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * import { findCatalogueMoon, type MoonOrbit } from "@johnmorrisdotca/wakusei-planets/moon-catalogue";
54
+ *
55
+ * const orbit: MoonOrbit = findCatalogueMoon("Carme")!.orbit!;
56
+ * console.log(orbit.frame, Math.round(orbit.a), "km,", orbit.periodDays.toFixed(1), "days");
57
+ * ```
58
+ */
59
+ export interface MoonOrbit {
60
+ /** The plane the angles are measured from: `ecliptic` (J2000), `equatorial` (the planet's equator) or `laplace` (the plane round which the orbit's pole turns, with its pole in `pole`). */
61
+ frame: "ecliptic" | "equatorial" | "laplace";
62
+ /** The pole of the plane, right ascension and declination in degrees (ICRF): the Laplace plane's as the source gives it, or the planet's pole (the one its moons go round, for Uranus the IAU's south pole) for `equatorial`. Not for `ecliptic`. */
63
+ pole?: readonly [number, number];
64
+ /** The epoch, a Julian date (TDB): 2461041.5 (2026-01-01) for every orbit set from Horizons. */
65
+ epochJd: number;
66
+ /** Semi-major axis, km. */
67
+ a: number;
68
+ /** Eccentricity. */
69
+ e: number;
70
+ /** Argument of periapsis, degrees. */
71
+ w: number;
72
+ /** Mean anomaly at the epoch, degrees (set from JPL Horizons). */
73
+ m: number;
74
+ /** Inclination to the plane, degrees; over 90 is a retrograde orbit. */
75
+ i: number;
76
+ /** Longitude of the ascending node, degrees, from where the plane crosses the ICRF equator (from the equinox for the ecliptic). */
77
+ node: number;
78
+ /** The sidereal period, days: the rate along the orbit as fitted to where JPL Horizons puts the moon on 2026-01-01, -02, 02-01 and 04-01, which this package uses in place of the period JPL's mean elements print. */
79
+ periodDays: number;
80
+ /** How many years the periapsis takes to turn once round, where the source gives it. */
81
+ apsisYears: number | null;
82
+ /** How many years the node takes to turn once round, where the source gives it. */
83
+ nodeYears: number | null;
84
+ /** The JPL satellite ephemeris the mean elements were taken from ("JUP347", "SAT459"). */
85
+ ephemeris: string;
86
+ }
87
+ /**
88
+ * Who found a moon, when, and where it was announced, as JPL's "Planetary Satellite Discovery Circumstances" lists it (the moons of the dwarf planets besides Pluto: the year and the reference of JPL's Small-Body Satellites
89
+ * service, which names no discoverers). `null` where the source gives nothing (the Moon has no discovery).
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * import { findCatalogueMoon, type MoonDiscovery } from "@johnmorrisdotca/wakusei-planets/moon-catalogue";
94
+ *
95
+ * const found: MoonDiscovery = findCatalogueMoon("Io")!.discovery;
96
+ * console.log(found.year, found.by);
97
+ * ```
98
+ */
99
+ export interface MoonDiscovery {
100
+ /** The year it was found. */
101
+ year: number | null;
102
+ /** The discoverers, or the spacecraft team, as the source writes them. */
103
+ by: string | null;
104
+ /** Where it was announced: an IAU Circular ("IAUC 8116"), a Minor Planet Electronic Circular ("MPEC 2023-A14"), a CBET, a paper, or "IAU WGPSN" for the long-named moons. */
105
+ reference: string | null;
106
+ }
107
+ /**
108
+ * Where a moon's size comes from: `measured` (JPL's "Planetary Satellite Physical Parameters", with its uncertainty), `sheet` (the radius on the moon's JPL Horizons data sheet) or `derived` (worked out here from the
109
+ * moon's V(1,0) magnitude and an albedo: the sheet's albedo where it gives one, else `ASSUMED_ALBEDO`, by D = 10^(3.1236 - 0.5 log10(albedo) - 0.2 V), the formula of NASA/JPL's asteroid size estimator).
110
+ *
111
+ * @example
112
+ * ```ts
113
+ * import { findCatalogueMoon, type MoonSizeSource } from "@johnmorrisdotca/wakusei-planets/moon-catalogue";
114
+ *
115
+ * const from: MoonSizeSource | null = findCatalogueMoon("Callirrhoe")!.radiusFrom;
116
+ * console.log(from);
117
+ * ```
118
+ */
119
+ export type MoonSizeSource = "measured" | "sheet" | "derived";
120
+ /**
121
+ * One moon of the catalogue. A number the sources do not give is `null`, never guessed.
122
+ *
123
+ * @example
124
+ * ```ts
125
+ * import { findCatalogueMoon, type CatalogueMoon } from "@johnmorrisdotca/wakusei-planets/moon-catalogue";
126
+ *
127
+ * const moon: CatalogueMoon = findCatalogueMoon("S/2003 J 18")!;
128
+ * console.log(moon.label, moon.host, moon.group, moon.retrograde, moon.discovery.year);
129
+ * ```
130
+ */
131
+ export interface CatalogueMoon {
132
+ /** A stable id: the name in lower case ("himalia"), or the designation ("s-2003-j-18"). The package's own moons keep their ids ("hiiaka"). */
133
+ id: string;
134
+ /** The IAU name, or `null` for a moon with only a designation. */
135
+ name: string | null;
136
+ /** The Japanese name, only for the moons the package draws in full (checked katakana); `null` for the others. */
137
+ ja: string | null;
138
+ /** The provisional designation, "S/2003 J 18", where it has one. */
139
+ designation: string | null;
140
+ /** What to print: the name, else the designation. */
141
+ label: string;
142
+ /** The IAU number in Roman numerals ("XIX"), where it has one. */
143
+ number: string | null;
144
+ /** The planet or dwarf planet it goes round. */
145
+ host: HostId;
146
+ /** The JPL (NAIF) id, as Horizons knows it (501 for Io), or `null` for a moon Horizons does not have. */
147
+ code: number | null;
148
+ /** Whether it has an IAU name. */
149
+ named: boolean;
150
+ /** `false` only for a moon its source marks as not confirmed. */
151
+ confirmed: boolean;
152
+ /** Who found it and when. */
153
+ discovery: MoonDiscovery;
154
+ /** The mean orbit, or `null` when the source gives none. */
155
+ orbit: MoonOrbit | null;
156
+ /** Whether it goes round against its planet's turn (an inclination over 90 degrees), or `null` with no orbit. */
157
+ retrograde: boolean | null;
158
+ /** The dynamical group. */
159
+ group: MoonGroup;
160
+ /** The mean radius in kilometres, or `null` when nothing gives it. */
161
+ radiusKm: number | null;
162
+ /** The radius's one-sigma uncertainty, km, when `measured`. */
163
+ radiusSigmaKm: number | null;
164
+ /** Where the radius comes from. */
165
+ radiusFrom: MoonSizeSource | null;
166
+ /** The geometric albedo, where the Horizons sheet gives one. */
167
+ albedo: number | null;
168
+ /** The V(1,0) magnitude (as bright as it would be 1 au from the Sun and from us), where the Horizons sheet gives one. */
169
+ magnitude: number | null;
170
+ /**
171
+ * How far `catalogueMoonPosition` was from JPL Horizons: the worst distance (km) and angle seen from the planet (degrees) on 2025-07-02, 2026-07-02 and 2027-07-02 (dates the orbit was not set from), and the worst angle
172
+ * decades away (1990, 2000 and 2040; `null` where Horizons has none of them). `null` when not measured.
173
+ */
174
+ accuracy: {
175
+ worstKm: number;
176
+ worstDegrees: number;
177
+ farDegrees: number | null;
178
+ } | null;
179
+ /** The grade of `accuracy`. */
180
+ grade: MoonGrade;
181
+ /** Whether the package draws it in full (a look, a size, its own fitted orbit or theory): then the main entry point's `moonVector` and `system` place it far better. */
182
+ full: boolean;
183
+ }
184
+ /**
185
+ * The albedo a `derived` size takes when the Horizons sheet gives none: 0.04, the albedo the sheet gives for Himalia, the largest of the irregular moons. The few other irregular moons with an albedo on their sheets have 0.03
186
+ * (Elara) to 0.081 (Phoebe), and Nereid 0.2; a darker moon is larger than the estimate and a brighter one smaller, so a derived radius is a guide to the size, not a measurement.
187
+ *
188
+ * @example
189
+ * ```ts
190
+ * import { ASSUMED_ALBEDO } from "@johnmorrisdotca/wakusei-planets/moon-catalogue";
191
+ *
192
+ * console.log(ASSUMED_ALBEDO);
193
+ * ```
194
+ */
195
+ export declare const ASSUMED_ALBEDO = 0.04;
196
+ /**
197
+ * Every known moon of the planets and the dwarf planets, as JPL lists them on `MOON_CATALOGUE_FETCHED`, in the order of the planets and, within a planet, of JPL's list (the long-known moons first, then by discovery).
198
+ *
199
+ * @example
200
+ * ```ts
201
+ * import { MOON_CATALOGUE } from "@johnmorrisdotca/wakusei-planets/moon-catalogue";
202
+ *
203
+ * console.log(MOON_CATALOGUE.length, "moons;", MOON_CATALOGUE.filter((m) => m.named).length, "with a name");
204
+ * ```
205
+ */
206
+ export declare const MOON_CATALOGUE: readonly CatalogueMoon[];
207
+ /**
208
+ * The day the catalogue was read from JPL. New moons are announced every year; `scripts/make-moon-catalogue.py --refresh` reads the sources again and prints what changed.
209
+ *
210
+ * @example
211
+ * ```ts
212
+ * import { MOON_CATALOGUE_FETCHED } from "@johnmorrisdotca/wakusei-planets/moon-catalogue";
213
+ *
214
+ * console.log("moons as of", MOON_CATALOGUE_FETCHED);
215
+ * ```
216
+ */
217
+ export declare const MOON_CATALOGUE_FETCHED: string;
218
+ /**
219
+ * How many moons a planet or dwarf planet has in the catalogue, and how many of those have a name.
220
+ *
221
+ * @example
222
+ * ```ts
223
+ * import { moonCounts, type MoonCount } from "@johnmorrisdotca/wakusei-planets/moon-catalogue";
224
+ *
225
+ * const saturn: MoonCount = moonCounts().saturn!;
226
+ * console.log(saturn.total, "moons of Saturn,", saturn.named, "named");
227
+ * ```
228
+ */
229
+ export interface MoonCount {
230
+ /** Every moon. */
231
+ total: number;
232
+ /** The moons with an IAU name. */
233
+ named: number;
234
+ /** The moons with a mean orbit, which `catalogueMoonPosition` can place. */
235
+ placed: number;
236
+ }
237
+ /**
238
+ * The counts for every planet and dwarf planet that has a moon in the catalogue.
239
+ *
240
+ * @returns A count for each host, in the catalogue's order.
241
+ *
242
+ * @example
243
+ * ```ts
244
+ * import { moonCounts } from "@johnmorrisdotca/wakusei-planets/moon-catalogue";
245
+ *
246
+ * for (const [host, count] of Object.entries(moonCounts())) console.log(host, count.total);
247
+ * ```
248
+ */
249
+ export declare function moonCounts(): Partial<Record<HostId, MoonCount>>;
250
+ /**
251
+ * The moons of one planet or dwarf planet, nearest first (by the mean orbit's semi-major axis; a moon with no orbit last), optionally of one group.
252
+ *
253
+ * @param host - The planet or dwarf planet: "jupiter", "eris".
254
+ * @param group - A group, to narrow the list.
255
+ * @returns The moons, which must not be changed.
256
+ *
257
+ * @example
258
+ * ```ts
259
+ * import { catalogueMoonsOf } from "@johnmorrisdotca/wakusei-planets/moon-catalogue";
260
+ *
261
+ * console.log(catalogueMoonsOf("jupiter", "himalia").map((m) => m.label).join(", "));
262
+ * ```
263
+ */
264
+ export declare function catalogueMoonsOf(host: HostId, group?: MoonGroup): readonly CatalogueMoon[];
265
+ /**
266
+ * Finds a moon by its id, name (English, or Japanese for the package's own moons), designation (spaces and slashes do not matter: "S/2003 J 18", "s2003j18") or JPL code (501). Ignores case and accents.
267
+ *
268
+ * @param query - The id, name, designation or code.
269
+ * @returns The moon, or `undefined`.
270
+ *
271
+ * @example
272
+ * ```ts
273
+ * import { findCatalogueMoon } from "@johnmorrisdotca/wakusei-planets/moon-catalogue";
274
+ *
275
+ * console.log(findCatalogueMoon("io")?.code, findCatalogueMoon(506)?.label, findCatalogueMoon("s2003j18")?.host, findCatalogueMoon("nothing"));
276
+ * ```
277
+ */
278
+ export declare function findCatalogueMoon(query: string | number): CatalogueMoon | undefined;
279
+ /**
280
+ * Where a moon is at a moment, from its planet's centre, in kilometres, in the J2000 ecliptic frame (the axes of `moonVector`): its mean orbit, turned for the precession of its periapsis and node, solved by Kepler's
281
+ * equation. How close that is to the moon's real place near 2026 is the moon's `accuracy` and `grade`; decades away it drifts much further (`accuracy.farDegrees`). A moon the package draws in full is placed far better
282
+ * by the main entry point's `moonVector`.
283
+ *
284
+ * @param moon - A moon of the catalogue, or its id, name, designation or code.
285
+ * @param when - A `Date` or milliseconds since 1970 (UTC).
286
+ * @returns x, y, z in kilometres, or `undefined` for a moon with no orbit.
287
+ *
288
+ * @example
289
+ * ```ts
290
+ * import { catalogueMoonPosition } from "@johnmorrisdotca/wakusei-planets/moon-catalogue";
291
+ *
292
+ * const [x, y, z] = catalogueMoonPosition("Himalia", new Date("2026-11-11T00:00:00Z"))!;
293
+ * console.log(Math.round(Math.hypot(x, y, z) / 1e6), "million km from Jupiter");
294
+ * ```
295
+ */
296
+ export declare function catalogueMoonPosition(moon: CatalogueMoon | string | number, when: When): Vec3 | undefined;
@@ -0,0 +1,234 @@
1
+ // Every known moon of the planets and the dwarf planets, as a light list: names and designations, who found each and when, the mean orbit, the size where it is known, and where each is on a date from that orbit,
2
+ // with how far that position was measured to be from JPL Horizons. The rows (scripts/make-moon-catalogue.py, src/data/moon-catalogue.ts) are imported by this entry point only, so a page that does not import
3
+ // `/moon-catalogue` does not carry them. Positions are from the planet's centre, in kilometres, in the J2000 ecliptic frame (the axes `moonVector` gives). Pure: no DOM, no clock reads, no three.js.
4
+ import { MOON_CATALOGUE_READ, MOON_CATALOGUE_ROWS } from "./data/moon-catalogue.js";
5
+ import { toTerrestrialTime } from "./clock.js";
6
+ import { kepler } from "./ephemeris.js";
7
+ import { cross, fromRaDec, RAD, toEcliptic } from "./vec.js";
8
+ import { moment } from "./when.js";
9
+ const DAY_MS = 86_400_000;
10
+ const UNIX_JD = 2_440_587.5;
11
+ const YEAR_DAYS = 365.25;
12
+ /**
13
+ * Every group, in the order the guide lists them.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { MOON_GROUPS } from "@johnmorrisdotca/wakusei-planets/moon-catalogue";
18
+ *
19
+ * console.log(MOON_GROUPS.join(", "));
20
+ * ```
21
+ */
22
+ export const MOON_GROUPS = ["inner", "major", "regular", "themisto", "himalia", "carpo", "valetudo", "ananke", "carme", "pasiphae", "inuit", "gallic", "norse", "prograde", "retrograde", "none"];
23
+ /**
24
+ * The albedo a `derived` size takes when the Horizons sheet gives none: 0.04, the albedo the sheet gives for Himalia, the largest of the irregular moons. The few other irregular moons with an albedo on their sheets have 0.03
25
+ * (Elara) to 0.081 (Phoebe), and Nereid 0.2; a darker moon is larger than the estimate and a brighter one smaller, so a derived radius is a guide to the size, not a measurement.
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * import { ASSUMED_ALBEDO } from "@johnmorrisdotca/wakusei-planets/moon-catalogue";
30
+ *
31
+ * console.log(ASSUMED_ALBEDO);
32
+ * ```
33
+ */
34
+ export const ASSUMED_ALBEDO = 0.04;
35
+ const FRAMES = ["ecliptic", "equatorial", "laplace"];
36
+ const SIZE_FROM = ["measured", "sheet"];
37
+ function moonOf(row) {
38
+ const [id, name, designation, number, host, code, year, by, reference, o, radius, sigma, from, albedo, magnitude, worstKm, worstDegrees, farDegrees, group, ja, confirmed] = row;
39
+ const orbit = o === null
40
+ ? null
41
+ : {
42
+ frame: FRAMES[o[0]],
43
+ ...(o[12] === undefined ? {} : { pole: [o[12], o[13]] }),
44
+ epochJd: o[1],
45
+ a: o[2],
46
+ e: o[3],
47
+ w: o[4],
48
+ m: o[5],
49
+ i: o[6],
50
+ node: o[7],
51
+ periodDays: o[8],
52
+ apsisYears: o[9],
53
+ nodeYears: o[10],
54
+ ephemeris: o[11],
55
+ };
56
+ let radiusKm = radius;
57
+ let radiusFrom = from === null ? null : SIZE_FROM[from];
58
+ if (radiusKm === null && magnitude !== null) {
59
+ radiusKm = Math.round(10 ** (3.1236 - 0.5 * Math.log10(albedo ?? ASSUMED_ALBEDO) - 0.2 * magnitude) * 5) / 10;
60
+ radiusFrom = "derived";
61
+ }
62
+ const grade = orbit === null ? "none" : worstDegrees === null ? "unmeasured" : worstDegrees < 1 ? "close" : worstDegrees < 10 ? "rough" : "loose";
63
+ return {
64
+ id,
65
+ name,
66
+ ja,
67
+ designation,
68
+ label: name ?? designation ?? id,
69
+ number,
70
+ host,
71
+ code,
72
+ named: name !== null,
73
+ confirmed: confirmed !== 0,
74
+ discovery: { year, by, reference },
75
+ orbit,
76
+ retrograde: orbit === null ? null : orbit.i > 90,
77
+ group,
78
+ radiusKm,
79
+ radiusSigmaKm: sigma,
80
+ radiusFrom,
81
+ albedo,
82
+ magnitude,
83
+ accuracy: worstKm === null || worstDegrees === null ? null : { worstKm, worstDegrees, farDegrees },
84
+ grade,
85
+ full: ja !== null,
86
+ };
87
+ }
88
+ /**
89
+ * Every known moon of the planets and the dwarf planets, as JPL lists them on `MOON_CATALOGUE_FETCHED`, in the order of the planets and, within a planet, of JPL's list (the long-known moons first, then by discovery).
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * import { MOON_CATALOGUE } from "@johnmorrisdotca/wakusei-planets/moon-catalogue";
94
+ *
95
+ * console.log(MOON_CATALOGUE.length, "moons;", MOON_CATALOGUE.filter((m) => m.named).length, "with a name");
96
+ * ```
97
+ */
98
+ export const MOON_CATALOGUE = MOON_CATALOGUE_ROWS.map(moonOf);
99
+ /**
100
+ * The day the catalogue was read from JPL. New moons are announced every year; `scripts/make-moon-catalogue.py --refresh` reads the sources again and prints what changed.
101
+ *
102
+ * @example
103
+ * ```ts
104
+ * import { MOON_CATALOGUE_FETCHED } from "@johnmorrisdotca/wakusei-planets/moon-catalogue";
105
+ *
106
+ * console.log("moons as of", MOON_CATALOGUE_FETCHED);
107
+ * ```
108
+ */
109
+ export const MOON_CATALOGUE_FETCHED = MOON_CATALOGUE_READ;
110
+ /**
111
+ * The counts for every planet and dwarf planet that has a moon in the catalogue.
112
+ *
113
+ * @returns A count for each host, in the catalogue's order.
114
+ *
115
+ * @example
116
+ * ```ts
117
+ * import { moonCounts } from "@johnmorrisdotca/wakusei-planets/moon-catalogue";
118
+ *
119
+ * for (const [host, count] of Object.entries(moonCounts())) console.log(host, count.total);
120
+ * ```
121
+ */
122
+ export function moonCounts() {
123
+ const out = {};
124
+ for (const moon of MOON_CATALOGUE) {
125
+ const count = (out[moon.host] ??= { total: 0, named: 0, placed: 0 });
126
+ count.total += 1;
127
+ if (moon.named)
128
+ count.named += 1;
129
+ if (moon.orbit !== null)
130
+ count.placed += 1;
131
+ }
132
+ return out;
133
+ }
134
+ /**
135
+ * The moons of one planet or dwarf planet, nearest first (by the mean orbit's semi-major axis; a moon with no orbit last), optionally of one group.
136
+ *
137
+ * @param host - The planet or dwarf planet: "jupiter", "eris".
138
+ * @param group - A group, to narrow the list.
139
+ * @returns The moons, which must not be changed.
140
+ *
141
+ * @example
142
+ * ```ts
143
+ * import { catalogueMoonsOf } from "@johnmorrisdotca/wakusei-planets/moon-catalogue";
144
+ *
145
+ * console.log(catalogueMoonsOf("jupiter", "himalia").map((m) => m.label).join(", "));
146
+ * ```
147
+ */
148
+ export function catalogueMoonsOf(host, group) {
149
+ return MOON_CATALOGUE.filter((m) => m.host === host && (group === undefined || m.group === group)).sort((a, b) => (a.orbit?.a ?? Infinity) - (b.orbit?.a ?? Infinity));
150
+ }
151
+ const plain = (text) => text.normalize("NFKD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/[^a-z0-9぀-ヿ一-鿿]/g, "");
152
+ /**
153
+ * Finds a moon by its id, name (English, or Japanese for the package's own moons), designation (spaces and slashes do not matter: "S/2003 J 18", "s2003j18") or JPL code (501). Ignores case and accents.
154
+ *
155
+ * @param query - The id, name, designation or code.
156
+ * @returns The moon, or `undefined`.
157
+ *
158
+ * @example
159
+ * ```ts
160
+ * import { findCatalogueMoon } from "@johnmorrisdotca/wakusei-planets/moon-catalogue";
161
+ *
162
+ * console.log(findCatalogueMoon("io")?.code, findCatalogueMoon(506)?.label, findCatalogueMoon("s2003j18")?.host, findCatalogueMoon("nothing"));
163
+ * ```
164
+ */
165
+ export function findCatalogueMoon(query) {
166
+ if (typeof query === "number")
167
+ return MOON_CATALOGUE.find((m) => m.code === query);
168
+ const q = plain(query);
169
+ if (q === "")
170
+ return undefined;
171
+ return MOON_CATALOGUE.find((m) => [m.id, m.name, m.ja, m.designation, m.code === null ? null : String(m.code)].some((v) => v !== null && plain(v) === q));
172
+ }
173
+ const basisCache = new Map();
174
+ function basisOf(pole) {
175
+ if (pole === null)
176
+ return [[1, 0, 0], [0, 1, 0], [0, 0, 1]];
177
+ const key = pole.join();
178
+ let basis = basisCache.get(key);
179
+ if (basis === undefined) {
180
+ const z = fromRaDec(pole[0], pole[1]);
181
+ const x = fromRaDec(pole[0] + 90, 0);
182
+ basis = [toEcliptic(x), toEcliptic(cross(z, x)), toEcliptic(z)];
183
+ basisCache.set(key, basis);
184
+ }
185
+ return basis;
186
+ }
187
+ /**
188
+ * The rates a mean orbit turns at, degrees a day: the mean anomaly's from the sidereal period (the mean longitude goes once round in it, so the mean anomaly runs slower by the turning of the other two); the periapsis turning forwards where 5 cos²i - 1 is positive and backwards where it is negative, and the node backwards on a prograde orbit
189
+ * and forwards on a retrograde one, as a planet's flattening and the Sun's pull turn them; each at the speed of the period the source gives (none where it gives none).
190
+ */
191
+ function ratesOf(orbit) {
192
+ const ci = Math.cos(orbit.i * RAD);
193
+ const dw = orbit.apsisYears ? (Math.sign(5 * ci * ci - 1) * 360) / (orbit.apsisYears * YEAR_DAYS) : 0;
194
+ const dn = orbit.nodeYears ? (-Math.sign(ci) * 360) / (orbit.nodeYears * YEAR_DAYS) : 0;
195
+ return [360 / orbit.periodDays - dw - dn, dw, dn];
196
+ }
197
+ /**
198
+ * Where a moon is at a moment, from its planet's centre, in kilometres, in the J2000 ecliptic frame (the axes of `moonVector`): its mean orbit, turned for the precession of its periapsis and node, solved by Kepler's
199
+ * equation. How close that is to the moon's real place near 2026 is the moon's `accuracy` and `grade`; decades away it drifts much further (`accuracy.farDegrees`). A moon the package draws in full is placed far better
200
+ * by the main entry point's `moonVector`.
201
+ *
202
+ * @param moon - A moon of the catalogue, or its id, name, designation or code.
203
+ * @param when - A `Date` or milliseconds since 1970 (UTC).
204
+ * @returns x, y, z in kilometres, or `undefined` for a moon with no orbit.
205
+ *
206
+ * @example
207
+ * ```ts
208
+ * import { catalogueMoonPosition } from "@johnmorrisdotca/wakusei-planets/moon-catalogue";
209
+ *
210
+ * const [x, y, z] = catalogueMoonPosition("Himalia", new Date("2026-11-11T00:00:00Z"))!;
211
+ * console.log(Math.round(Math.hypot(x, y, z) / 1e6), "million km from Jupiter");
212
+ * ```
213
+ */
214
+ export function catalogueMoonPosition(moon, when) {
215
+ const m = typeof moon === "object" ? moon : findCatalogueMoon(moon);
216
+ if (m === undefined)
217
+ throw new RangeError(`unknown moon ${JSON.stringify(moon)}; look one up with findCatalogueMoon`);
218
+ const orbit = m.orbit;
219
+ if (orbit === null)
220
+ return undefined;
221
+ const [n, dw, dn] = ratesOf(orbit);
222
+ const dt = toTerrestrialTime(moment(when)) / DAY_MS + UNIX_JD - orbit.epochJd;
223
+ const w = (orbit.w + dw * dt) * RAD;
224
+ const node = (orbit.node + dn * dt) * RAD;
225
+ const E = kepler((orbit.m + n * dt) * RAD, orbit.e);
226
+ const x = orbit.a * (Math.cos(E) - orbit.e);
227
+ const y = orbit.a * Math.sqrt(1 - orbit.e * orbit.e) * Math.sin(E);
228
+ const [cw, sw, cn, sn, ci, si] = [Math.cos(w), Math.sin(w), Math.cos(node), Math.sin(node), Math.cos(orbit.i * RAD), Math.sin(orbit.i * RAD)];
229
+ const px = (cw * cn - sw * sn * ci) * x + (-sw * cn - cw * sn * ci) * y;
230
+ const py = (cw * sn + sw * cn * ci) * x + (-sw * sn + cw * cn * ci) * y;
231
+ const pz = sw * si * x + cw * si * y;
232
+ const [bx, by, bz] = basisOf(orbit.frame === "ecliptic" ? null : (orbit.pole ?? null));
233
+ return [px * bx[0] + py * by[0] + pz * bz[0], px * bx[1] + py * by[1] + pz * bz[1], px * bx[2] + py * by[2] + pz * bz[2]];
234
+ }