@arcosmos/astronomy 0.0.0-stage → 0.1.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.
Files changed (63) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +227 -2
  3. package/dist/angles.d.ts +51 -0
  4. package/dist/angles.d.ts.map +1 -0
  5. package/dist/angles.js +261 -0
  6. package/dist/angles.js.map +1 -0
  7. package/dist/constants.d.ts +35 -0
  8. package/dist/constants.d.ts.map +1 -0
  9. package/dist/constants.js +44 -0
  10. package/dist/constants.js.map +1 -0
  11. package/dist/coordinates.d.ts +213 -0
  12. package/dist/coordinates.d.ts.map +1 -0
  13. package/dist/coordinates.js +474 -0
  14. package/dist/coordinates.js.map +1 -0
  15. package/dist/distance.d.ts +26 -0
  16. package/dist/distance.d.ts.map +1 -0
  17. package/dist/distance.js +54 -0
  18. package/dist/distance.js.map +1 -0
  19. package/dist/errors.d.ts +24 -0
  20. package/dist/errors.d.ts.map +1 -0
  21. package/dist/errors.js +24 -0
  22. package/dist/errors.js.map +1 -0
  23. package/dist/index.d.ts +13 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +15 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/kinds.d.ts +86 -0
  28. package/dist/kinds.d.ts.map +1 -0
  29. package/dist/kinds.js +29 -0
  30. package/dist/kinds.js.map +1 -0
  31. package/dist/parse-unit.d.ts +11 -0
  32. package/dist/parse-unit.d.ts.map +1 -0
  33. package/dist/parse-unit.js +222 -0
  34. package/dist/parse-unit.js.map +1 -0
  35. package/dist/quantity.d.ts +150 -0
  36. package/dist/quantity.d.ts.map +1 -0
  37. package/dist/quantity.js +452 -0
  38. package/dist/quantity.js.map +1 -0
  39. package/dist/rounding.d.ts +18 -0
  40. package/dist/rounding.d.ts.map +1 -0
  41. package/dist/rounding.js +35 -0
  42. package/dist/rounding.js.map +1 -0
  43. package/dist/time.d.ts +100 -0
  44. package/dist/time.d.ts.map +1 -0
  45. package/dist/time.js +448 -0
  46. package/dist/time.js.map +1 -0
  47. package/dist/units.d.ts +394 -0
  48. package/dist/units.d.ts.map +1 -0
  49. package/dist/units.js +353 -0
  50. package/dist/units.js.map +1 -0
  51. package/package.json +44 -3
  52. package/src/angles.ts +286 -0
  53. package/src/constants.ts +51 -0
  54. package/src/coordinates.ts +591 -0
  55. package/src/distance.ts +58 -0
  56. package/src/errors.ts +27 -0
  57. package/src/index.ts +27 -0
  58. package/src/kinds.ts +110 -0
  59. package/src/parse-unit.ts +230 -0
  60. package/src/quantity.ts +539 -0
  61. package/src/rounding.ts +33 -0
  62. package/src/time.ts +511 -0
  63. package/src/units.ts +445 -0
@@ -0,0 +1,452 @@
1
+ // Quantities: a value, its unit, its uncertainty and whether it is a limit.
2
+ //
3
+ // Uncertainties take the forms the Arcosmos API publishes: a symmetric one-sigma error,
4
+ // asymmetric errors (plus >= 0, minus <= 0), 16th and 84th percentiles, or the error ellipse
5
+ // SIMBAD gives a proper motion. Missing (null) means none is known, and anything computed
6
+ // from it has none either; an exact value has sigma 0.
7
+ //
8
+ // - Converting units and scaling by a number are exact, and carry every form of uncertainty
9
+ // (but scaling an ellipse, below) and any limit along. A negative factor swaps plus and
10
+ // minus, and upper and lower. Between log10 of a unit and the unit itself, which isn't
11
+ // linear, each end of an error is converted, so a symmetric error becomes an asymmetric one.
12
+ // - Arithmetic between quantities propagates symmetric errors to first order, treating the
13
+ // operands as independent: `a.minus(a)` has sigma times sqrt(2), not 0. Asymmetric errors,
14
+ // percentiles and limits are refused there, since first-order propagation doesn't define
15
+ // them: call `symmetrized()` first, saying how.
16
+ // - An error ellipse belongs to a vector, a proper motion's two components together, so it
17
+ // only follows a change of unit. Scaling by a number, arithmetic and `symmetrized()` refuse
18
+ // it: what it means for one component depends on what is done to the other.
19
+ import { QuantityParseError, UncertaintyError, UnitConversionError } from './errors.js';
20
+ import { parseUnit } from './parse-unit.js';
21
+ import { DIMENSIONLESS, Unit } from './units.js';
22
+ const symmetric = (value) => ({ kind: 'symmetric', value });
23
+ /** Normalizes -0 to 0, which would otherwise print as "-0". */
24
+ const plain = (x) => x + 0;
25
+ function checkUncertainty(u, unit) {
26
+ if (!u)
27
+ return;
28
+ const bad = (message) => new RangeError(`Invalid uncertainty: ${message}`);
29
+ if (u.kind === 'error_ellipse') {
30
+ for (const axis of [u.major, u.minor]) {
31
+ if (axis !== null && (!(axis >= 0) || !Number.isFinite(axis)))
32
+ throw bad(`an axis must be a finite number >= 0, not ${axis}`);
33
+ }
34
+ if (u.angle_deg !== null && !Number.isFinite(u.angle_deg))
35
+ throw bad(`the angle must be finite, not ${u.angle_deg}`);
36
+ if (unit.log)
37
+ throw bad(`an error ellipse can't be in a logarithmic unit (${unit})`);
38
+ }
39
+ else if (u.kind === 'symmetric') {
40
+ if (!(u.value >= 0) || !Number.isFinite(u.value))
41
+ throw bad(`sigma must be a finite number >= 0, not ${u.value}`);
42
+ }
43
+ else if (u.kind === 'asymmetric') {
44
+ if (u.plus !== null && (!(u.plus >= 0) || !Number.isFinite(u.plus)))
45
+ throw bad(`plus must be >= 0, not ${u.plus}`);
46
+ if (u.minus !== null && (!(u.minus <= 0) || !Number.isFinite(u.minus)))
47
+ throw bad(`minus must be <= 0, not ${u.minus}`);
48
+ }
49
+ else if (u.kind === 'percentiles') {
50
+ for (const p of [u.p16, u.p84])
51
+ if (p !== null && !Number.isFinite(p))
52
+ throw bad(`a percentile must be finite, not ${p}`);
53
+ if (u.p16 !== null && u.p84 !== null && u.p16 > u.p84)
54
+ throw bad(`p16 (${u.p16}) is above p84 (${u.p84})`);
55
+ }
56
+ else {
57
+ throw bad(`unknown kind "${u.kind}"`);
58
+ }
59
+ }
60
+ /**
61
+ * The quantity under a linear map: `map` for values, `scale` for differences (errors), and
62
+ * `flip` when the map reverses order, swapping plus and minus, p16 and p84, upper and lower.
63
+ */
64
+ function transform(q, unit, map, scale, flip) {
65
+ const u = q.uncertainty;
66
+ const side = (x) => (x === null ? null : plain(scale(x)));
67
+ const point = (x) => (x === null ? null : map(x));
68
+ let uncertainty = null;
69
+ if (u?.kind === 'symmetric')
70
+ uncertainty = symmetric(Math.abs(scale(u.value)));
71
+ else if (u?.kind === 'asymmetric') {
72
+ uncertainty = flip
73
+ ? { kind: 'asymmetric', plus: side(u.minus), minus: side(u.plus) }
74
+ : { kind: 'asymmetric', plus: side(u.plus), minus: side(u.minus) };
75
+ }
76
+ else if (u?.kind === 'percentiles') {
77
+ uncertainty = flip
78
+ ? { kind: 'percentiles', p16: point(u.p84), p84: point(u.p16) }
79
+ : { kind: 'percentiles', p16: point(u.p16), p84: point(u.p84) };
80
+ }
81
+ else if (u?.kind === 'error_ellipse') {
82
+ // Only a change of unit reaches here (scaled() refuses an ellipse), which keeps its angle.
83
+ const axis = (x) => (x === null ? null : plain(Math.abs(scale(x))));
84
+ uncertainty = { kind: 'error_ellipse', major: axis(u.major), minor: axis(u.minor), angle_deg: u.angle_deg };
85
+ }
86
+ const limit = q.limit && flip ? (q.limit === 'upper' ? 'lower' : 'upper') : q.limit;
87
+ return new Quantity(map(q.value), unit, uncertainty, limit);
88
+ }
89
+ /** The linear map from one logarithmic unit to another: x_to = a x + b. 1 mag is -0.4 dex. */
90
+ function logConversion(from, to) {
91
+ const factor = from.physical.to(to.physical);
92
+ const toDex = from.type === 'mag' ? -0.4 : 1;
93
+ const fromDex = to.type === 'mag' ? -2.5 : 1;
94
+ const a = from.type === to.type ? 1 : toDex * fromDex;
95
+ return { a, b: fromDex * Math.log10(factor) };
96
+ }
97
+ /**
98
+ * Between a logarithmic unit and the linear unit it is the logarithm of: log10(X) and X (Astropy's
99
+ * dex(X) and X), or mag and dex and a plain number. value = factor × 10^(k x), k = 1 for dex and
100
+ * -0.4 for mag. The map isn't linear, so an error's size doesn't convert: each end of the
101
+ * interval it stands for does, as do percentiles, and a symmetric error becomes an asymmetric
102
+ * one. mag runs the other way, swapping plus and minus, p16 and p84, upper and lower.
103
+ */
104
+ function logLinear(q, unit) {
105
+ const toLinear = q.unit.log !== null;
106
+ const log = (toLinear ? q.unit.log : unit.log);
107
+ const linear = toLinear ? unit : q.unit;
108
+ if (!log.physical.isEquivalent(linear)) {
109
+ throw new UnitConversionError(`${String(q.unit) || 'dimensionless'} can't be converted to ${String(unit) || 'dimensionless'}`);
110
+ }
111
+ const k = log.type === 'mag' ? -0.4 : 1;
112
+ let map;
113
+ if (toLinear) {
114
+ const factor = log.physical.to(linear);
115
+ map = (x) => factor * 10 ** (k * x);
116
+ }
117
+ else {
118
+ const factor = linear.to(log.physical);
119
+ map = (x) => Math.log10(factor * x) / k;
120
+ }
121
+ const flip = k < 0;
122
+ if (!toLinear && !(q.value > 0)) {
123
+ throw new RangeError(`${q} has no logarithm: only a positive value converts to ${unit}`);
124
+ }
125
+ const center = map(q.value);
126
+ /** Where value + dx lands, less where the value does. */
127
+ const end = (dx) => {
128
+ if (dx === null)
129
+ return null;
130
+ if (dx === 0)
131
+ return 0;
132
+ if (!toLinear && !(q.value + dx > 0)) {
133
+ throw new UncertaintyError(`${q} reaches ${q.value + dx} ${linear}, which has no logarithm: its errors can't follow it into ${unit}`);
134
+ }
135
+ return plain(map(q.value + dx) - center);
136
+ };
137
+ const point = (x) => {
138
+ if (x === null)
139
+ return null;
140
+ if (!toLinear && !(x > 0)) {
141
+ throw new UncertaintyError(`${q} has a percentile at ${x} ${linear}, which has no logarithm`);
142
+ }
143
+ return map(x);
144
+ };
145
+ const u = q.uncertainty;
146
+ let uncertainty = null;
147
+ if (u?.kind === 'error_ellipse') {
148
+ throw new UncertaintyError(`${q} has an error ellipse, which can't be in a logarithmic unit`);
149
+ }
150
+ else if (u?.kind === 'symmetric') {
151
+ uncertainty = u.value === 0 ? symmetric(0) : {
152
+ kind: 'asymmetric',
153
+ plus: flip ? end(-u.value) : end(u.value),
154
+ minus: flip ? end(u.value) : end(-u.value),
155
+ };
156
+ }
157
+ else if (u?.kind === 'asymmetric') {
158
+ uncertainty = flip
159
+ ? { kind: 'asymmetric', plus: end(u.minus), minus: end(u.plus) }
160
+ : { kind: 'asymmetric', plus: end(u.plus), minus: end(u.minus) };
161
+ }
162
+ else if (u?.kind === 'percentiles') {
163
+ uncertainty = flip
164
+ ? { kind: 'percentiles', p16: point(u.p84), p84: point(u.p16) }
165
+ : { kind: 'percentiles', p16: point(u.p16), p84: point(u.p84) };
166
+ }
167
+ const limit = q.limit && flip ? (q.limit === 'upper' ? 'lower' : 'upper') : q.limit;
168
+ return new Quantity(center, unit, uncertainty, limit);
169
+ }
170
+ /** The square root of the sum of squares, or null if any term is unknown. */
171
+ function quadrature(...terms) {
172
+ return terms.some((t) => t === null) ? null : Math.hypot(...terms);
173
+ }
174
+ /**
175
+ * A value with a unit, and its uncertainty if known. `K` is its kind, such as "length", where
176
+ * the type system can tell. Make one with `q(10, "ly")`. Immutable: every operation returns a
177
+ * new quantity.
178
+ */
179
+ export class Quantity {
180
+ value;
181
+ unit;
182
+ /** Null when no uncertainty is known. */
183
+ uncertainty;
184
+ /** Set when the value is an upper or lower limit rather than a measurement. */
185
+ limit;
186
+ constructor(value, unit, uncertainty = null, limit = null) {
187
+ if (!Number.isFinite(value))
188
+ throw new RangeError(`A quantity's value must be a finite number, not ${value}`);
189
+ checkUncertainty(uncertainty, unit);
190
+ if (limit !== null && limit !== 'upper' && limit !== 'lower')
191
+ throw new RangeError(`Invalid limit "${limit}"`);
192
+ this.value = value;
193
+ this.unit = unit;
194
+ this.uncertainty = uncertainty;
195
+ this.limit = limit;
196
+ }
197
+ /** The kind of quantity, such as "length". */
198
+ get kind() {
199
+ return this.unit.kind;
200
+ }
201
+ /** The one-sigma error when the uncertainty is symmetric; null otherwise. */
202
+ get sigma() {
203
+ return this.uncertainty?.kind === 'symmetric' ? this.uncertainty.value : null;
204
+ }
205
+ // Methods that take a quantity or unit of the same kind read the kind from `this`, rather
206
+ // than from K, so a Quantity<"length"> is still a Quantity<string> wherever any is accepted.
207
+ /**
208
+ * The quantity in another unit of the same kind: `q(10, "ly").to("pc")`. Exact, uncertainty
209
+ * included. Magnitudes and dex convert to each other, and log10 of a unit to the unit
210
+ * (`q(5.25, "log10(L_sun)").to("L_sun")`) and back, each end of an error converted.
211
+ */
212
+ to(target) {
213
+ const unit = typeof target === 'string' ? parseUnit(target) : target;
214
+ let result;
215
+ if (!this.unit.log !== !unit.log) {
216
+ result = logLinear(this, unit);
217
+ }
218
+ else if (this.unit.log && unit.log) {
219
+ const { a, b } = logConversion(this.unit.log, unit.log);
220
+ result = transform(this, unit, (x) => a * x + b, (dx) => a * dx, a < 0);
221
+ }
222
+ else {
223
+ const factor = this.unit.to(unit);
224
+ result = transform(this, unit, (x) => x * factor, (dx) => dx * factor, false);
225
+ }
226
+ return result;
227
+ }
228
+ /** The value in another unit: `q(10, "ly").valueIn("pc")`. */
229
+ valueIn(target) {
230
+ return this.to(target).value;
231
+ }
232
+ /** The same quantity typed as kind K2, checked when it runs: `a.div(b).as("speed")`. */
233
+ as(kind) {
234
+ if (this.kind !== kind)
235
+ throw new UnitConversionError(`${this} is a quantity of ${this.kind}, not ${kind}`);
236
+ return this;
237
+ }
238
+ /** The sum, in this quantity's unit. Sigmas add in quadrature. */
239
+ plus(other) {
240
+ return add(this, other, 1);
241
+ }
242
+ /** The difference, in this quantity's unit. Sigmas add in quadrature. */
243
+ minus(other) {
244
+ return add(this, other, -1);
245
+ }
246
+ times(other) {
247
+ if (typeof other === 'number')
248
+ return this.scaled(other, (x) => x * other);
249
+ requireArithmetic(this, 'multiplied');
250
+ requireArithmetic(other, 'multiplied');
251
+ const unit = this.unit.times(other.unit);
252
+ const [a, b] = [this.value, other.value];
253
+ const sa = this.sigma;
254
+ const sb = other.sigma;
255
+ const sigma = sa === null || sb === null ? null : Math.hypot(b * sa, a * sb);
256
+ return new Quantity(a * b, unit, sigma === null ? null : symmetric(sigma));
257
+ }
258
+ div(other) {
259
+ if (typeof other === 'number') {
260
+ if (!Number.isFinite(other))
261
+ throw new RangeError(`A quantity can only be divided by a finite number, not ${other}`);
262
+ if (other === 0)
263
+ throw new RangeError('Division by zero');
264
+ return this.scaled(1 / other, (x) => x / other);
265
+ }
266
+ requireArithmetic(this, 'divided');
267
+ requireArithmetic(other, 'divided');
268
+ const unit = this.unit.div(other.unit);
269
+ const [a, b] = [this.value, other.value];
270
+ if (b === 0)
271
+ throw new RangeError('Division by zero');
272
+ const sa = this.sigma;
273
+ const sb = other.sigma;
274
+ const sigma = sa === null || sb === null ? null : Math.hypot(sa / b, (a / b) * (sb / b));
275
+ return new Quantity(a / b, unit, sigma === null ? null : symmetric(sigma));
276
+ }
277
+ /** To a power, with first-order propagation: sigma times |n a^(n-1)|. */
278
+ pow(n) {
279
+ requireArithmetic(this, 'raised to a power');
280
+ const unit = this.unit.pow(n);
281
+ const s = this.sigma;
282
+ const sigma = s === null ? null : s === 0 || n === 0 ? 0 : Math.abs(n * this.value ** (n - 1)) * s;
283
+ return new Quantity(this.value ** n, unit, sigma === null ? null : symmetric(sigma));
284
+ }
285
+ /** The negative of the quantity. Plus and minus swap, as do upper and lower limits. */
286
+ negate() {
287
+ return this.scaled(-1, (x) => -x);
288
+ }
289
+ /**
290
+ * The quantity with a symmetric sigma in place of asymmetric errors or percentiles: the
291
+ * larger side (the API's rule for its derived values), or the mean of the two. Null when
292
+ * either side is unknown. An error ellipse is refused: its error along one component
293
+ * depends on which component this is, which the quantity doesn't know.
294
+ */
295
+ symmetrized(rule = 'larger') {
296
+ const u = this.uncertainty;
297
+ if (!u || u.kind === 'symmetric')
298
+ return this;
299
+ if (u.kind === 'error_ellipse')
300
+ throw ellipseError(this, 'symmetrized');
301
+ const [up, down] = u.kind === 'asymmetric'
302
+ ? [u.plus, u.minus === null ? null : -u.minus]
303
+ : [u.p84 === null ? null : u.p84 - this.value, u.p16 === null ? null : this.value - u.p16];
304
+ const sigma = up === null || down === null ? null : rule === 'larger' ? Math.max(up, down) : (up + down) / 2;
305
+ return new Quantity(this.value, this.unit, sigma === null ? null : symmetric(sigma), this.limit);
306
+ }
307
+ /**
308
+ * -1, 0 or 1 as this quantity is less than, equal to or greater than the other, uncertainties
309
+ * aside. A magnitude and a dex don't compare: mag runs the other way, so neither order would
310
+ * be the obvious one.
311
+ */
312
+ compare(other) {
313
+ const a = this.unit.log;
314
+ const b = other.unit.log;
315
+ if (a && b && a.type !== b.type)
316
+ throw new UnitConversionError('A magnitude and a dex don\'t compare: convert one first');
317
+ return Math.sign(this.value - other.to(this.unit).value);
318
+ }
319
+ /** "1.2 ± 0.1 mas", "0.5 +0.2 -0.1 M_jup", "< 3 M_earth". */
320
+ toString() {
321
+ const u = this.uncertainty;
322
+ let error = '';
323
+ if (u?.kind === 'symmetric')
324
+ error = ` ± ${u.value}`;
325
+ else if (u?.kind === 'asymmetric')
326
+ error = ` +${u.plus ?? '?'} ${u.minus === null ? '-?' : plain(u.minus) === 0 ? '-0' : u.minus}`;
327
+ else if (u?.kind === 'percentiles')
328
+ error = ` (p16 ${u.p16 ?? '?'}, p84 ${u.p84 ?? '?'})`;
329
+ else if (u?.kind === 'error_ellipse') {
330
+ error = ` (error ellipse ${u.major ?? '?'} × ${u.minor ?? '?'} at ${u.angle_deg ?? '?'} deg)`;
331
+ }
332
+ const limit = this.limit === 'upper' ? '< ' : this.limit === 'lower' ? '> ' : '';
333
+ const unit = this.unit.toString();
334
+ return `${limit}${this.value}${error}${unit ? ` ${unit}` : ''}`;
335
+ }
336
+ /** The quantity in the API's shape. An error ellipse names its unit, the value's. */
337
+ toJSON() {
338
+ const text = this.unit.toString();
339
+ const unit = text === '' ? null : text;
340
+ const u = this.uncertainty;
341
+ return {
342
+ value: this.value,
343
+ unit,
344
+ uncertainty: u?.kind === 'error_ellipse' ? { ...u, unit } : u,
345
+ ...(this.limit ? { limit: this.limit } : {}),
346
+ };
347
+ }
348
+ /** Scaled by a number: exact, carrying every form of uncertainty but an ellipse, and the limit. */
349
+ scaled(factor, map) {
350
+ if (!Number.isFinite(factor))
351
+ throw new RangeError(`A quantity can only be scaled by a finite number, not ${factor}`);
352
+ if (this.unit.log)
353
+ throw new UnitConversionError(`${this.unit} is logarithmic: scaling it by a number isn't defined`);
354
+ if (this.uncertainty?.kind === 'error_ellipse')
355
+ throw ellipseError(this, 'scaled by a number');
356
+ return transform(this, this.unit, map, (dx) => map(dx), factor < 0);
357
+ }
358
+ }
359
+ /**
360
+ * An ellipse describes a vector: scaling or combining one of its components distorts it in a
361
+ * way that depends on the other, so only a change of unit keeps it.
362
+ */
363
+ function ellipseError(q, verb) {
364
+ return new UncertaintyError(`${q} has an error ellipse and can't be ${verb}: the ellipse is the error of a vector (a proper motion's two `
365
+ + 'components), so its error along this one depends on which it is. Make a quantity with the sigma you take for it');
366
+ }
367
+ /**
368
+ * Refuses limits, asymmetric errors, percentiles and error ellipses, which first-order
369
+ * propagation doesn't define. @internal Not part of the package's API (distance.ts uses it).
370
+ */
371
+ export function requireArithmetic(q, verb) {
372
+ if (q.limit) {
373
+ throw new UncertaintyError(`${q} is ${q.limit === 'upper' ? 'an upper' : 'a lower'} limit and can't be ${verb}: `
374
+ + 'only unit conversion and scaling by a number keep a limit');
375
+ }
376
+ const u = q.uncertainty;
377
+ if (u?.kind === 'error_ellipse')
378
+ throw ellipseError(q, verb);
379
+ if (u && u.kind !== 'symmetric') {
380
+ throw new UncertaintyError(`${q} has ${u.kind === 'asymmetric' ? 'asymmetric errors' : 'percentiles'} and can't be ${verb}: `
381
+ + 'first-order propagation needs a symmetric sigma. Call symmetrized("larger") or symmetrized("mean") first');
382
+ }
383
+ }
384
+ /** a + sign × b, in a's unit. */
385
+ function add(a, b, sign) {
386
+ const verb = sign > 0 ? 'added' : 'subtracted';
387
+ requireArithmetic(a, verb);
388
+ requireArithmetic(b, verb);
389
+ if (a.unit.log || b.unit.log)
390
+ return addLogarithmic(a, b, sign);
391
+ const factor = b.unit.to(a.unit);
392
+ const sb = b.sigma;
393
+ const sigma = quadrature(a.sigma, sb === null ? null : factor * sb);
394
+ return new Quantity(a.value + sign * factor * b.value, a.unit, sigma === null ? null : symmetric(sigma));
395
+ }
396
+ /**
397
+ * mag ± mag (a color) and dex ± dex, the second converted to the first's scale. log10 of a unit
398
+ * with a dimension isn't added yet: its sum is log10 of a product.
399
+ */
400
+ function addLogarithmic(a, b, sign) {
401
+ const la = a.unit.log;
402
+ const lb = b.unit.log;
403
+ if (!la || !lb)
404
+ throw new UnitConversionError(`A logarithmic and a linear quantity can't be added: ${a} and ${b}`);
405
+ if (la.physical.kind !== 'dimensionless' || lb.physical.kind !== 'dimensionless') {
406
+ throw new UnitConversionError(`Adding or subtracting ${a.unit} and ${b.unit} isn't built yet: only mag and dex`);
407
+ }
408
+ // b in plain mag or dex, as a is written, so a ratio inside b's unit (log10(R_sun/R_earth)) counts.
409
+ const plainB = b.to(Unit.logarithmic(la.type, DIMENSIONLESS));
410
+ const sigma = quadrature(a.sigma, plainB.sigma);
411
+ return new Quantity(a.value + sign * plainB.value, a.unit, sigma === null ? null : symmetric(sigma));
412
+ }
413
+ export function q(value, unit, options = {}) {
414
+ if (options.sigma !== undefined && options.uncertainty !== undefined) {
415
+ throw new TypeError('Give sigma or uncertainty, not both');
416
+ }
417
+ const uncertainty = options.sigma !== undefined ? symmetric(options.sigma) : options.uncertainty ?? null;
418
+ return new Quantity(value, typeof unit === 'string' ? parseUnit(unit) : unit, uncertainty, options.limit ?? null);
419
+ }
420
+ /**
421
+ * A quantity from one of the API's measurements, with its uncertainty and limit. An error
422
+ * ellipse (SIMBAD's proper motions) is kept, its axes in the value's unit. A label (such as a
423
+ * spectral type) isn't a quantity, and throws.
424
+ */
425
+ export function fromMeasurement(measurement) {
426
+ if (typeof measurement.value !== 'number') {
427
+ throw new TypeError(`"${measurement.value}" is a label, not a number`);
428
+ }
429
+ const unit = parseUnit(measurement.unit ?? '');
430
+ let u = measurement.uncertainty ?? null;
431
+ if (u?.kind === 'error_ellipse') {
432
+ const axes = 'unit' in u && typeof u.unit === 'string' ? parseUnit(u.unit) : unit;
433
+ const factor = axes.to(unit);
434
+ const axis = (x) => (x === null ? null : x * factor);
435
+ u = { kind: 'error_ellipse', major: axis(u.major), minor: axis(u.minor), angle_deg: u.angle_deg };
436
+ }
437
+ return new Quantity(measurement.value, unit, u, measurement.limit ?? null);
438
+ }
439
+ const NUMBER = String.raw `(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?`;
440
+ const QUANTITY = new RegExp(String.raw `^\s*([-+]?${NUMBER})(?:\s*(?:±|\+/-|\+-)\s*(${NUMBER}))?\s*(.*?)\s*$`);
441
+ /**
442
+ * A quantity from text: "10 ly", "-1.46 mag", "1.2 ± 0.1 mas" (or "+/-"). A number alone is
443
+ * dimensionless. Throws a QuantityParseError, or a UnitParseError for an unknown unit.
444
+ */
445
+ export function parseQuantity(text) {
446
+ const match = QUANTITY.exec(text);
447
+ if (!match)
448
+ throw new QuantityParseError(`"${text}" isn't a number and a unit, such as "10 ly"`);
449
+ const [, value, sigma, unitText] = match;
450
+ return q(Number(value), parseUnit(unitText ?? ''), sigma === undefined ? {} : { sigma: Number(sigma) });
451
+ }
452
+ //# sourceMappingURL=quantity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quantity.js","sourceRoot":"","sources":["../src/quantity.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,EAAE;AACF,wFAAwF;AACxF,6FAA6F;AAC7F,0FAA0F;AAC1F,uDAAuD;AACvD,EAAE;AACF,4FAA4F;AAC5F,0FAA0F;AAC1F,yFAAyF;AACzF,+FAA+F;AAC/F,2FAA2F;AAC3F,6FAA6F;AAC7F,2FAA2F;AAC3F,kDAAkD;AAClD,2FAA2F;AAC3F,8FAA8F;AAC9F,8EAA8E;AAC9E,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAEvF,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,aAAa,EAA2B,IAAI,EAAE,MAAM,YAAY,CAAA;AAoEzE,MAAM,SAAS,GAAG,CAAC,K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A;IACxC,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC,QAAQ,IAAI,EAAE,CAAC,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;AACzG,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * A computed value and its one-sigma error, rounded as results are usually quoted: the error
3
+ * to two significant digits and the value to the same place. 46.3523 ± 0.8641 becomes
4
+ * "46.35" and "0.86", 694.01 ± 88.20 becomes "694" and "88", 1234.5 ± 156 becomes "1230" and
5
+ * "160", and 2 ± 0.0996 becomes "2.00" and "0.10". Trailing zeros are kept: they say how
6
+ * precise the value is. Null when the error isn't a positive finite number, for the caller to
7
+ * print the value in full.
8
+ */
9
+ export declare function roundToUncertainty(value: number, error: number): {
10
+ value: string;
11
+ error: string;
12
+ } | null;
13
+ /**
14
+ * A computed value with no error to round to, to a few significant digits: for a value whose
15
+ * inputs were published without errors. 2158.38 becomes "2160". Mark it as approximate.
16
+ */
17
+ export declare function roundToSignificant(value: number, digits?: number): string;
18
+ //# sourceMappingURL=rounding.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rounding.d.ts","sourceRoot":"","sources":["../src/rounding.ts"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAYxG;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,SAAI,GAAG,MAAM,CAEpE"}
@@ -0,0 +1,35 @@
1
+ // How a computed value is printed: rounded to what its uncertainty allows, as results are
2
+ // usually quoted. Published values are printed as published; these are for values computed
3
+ // from them, so every client rounds a derived value the same way.
4
+ /**
5
+ * A computed value and its one-sigma error, rounded as results are usually quoted: the error
6
+ * to two significant digits and the value to the same place. 46.3523 ± 0.8641 becomes
7
+ * "46.35" and "0.86", 694.01 ± 88.20 becomes "694" and "88", 1234.5 ± 156 becomes "1230" and
8
+ * "160", and 2 ± 0.0996 becomes "2.00" and "0.10". Trailing zeros are kept: they say how
9
+ * precise the value is. Null when the error isn't a positive finite number, for the caller to
10
+ * print the value in full.
11
+ */
12
+ export function roundToUncertainty(value, error) {
13
+ if (!Number.isFinite(value) || !Number.isFinite(error) || !(error > 0))
14
+ return null;
15
+ // The place of the error's second significant digit: 0.86 -> 2 decimals, 88 -> 0, 156 -> -1.
16
+ let decimals = 1 - Math.floor(Math.log10(error));
17
+ // An error that rounds up to a third digit (0.0996 to 0.100) has two at the next place up.
18
+ if (Math.round(error * 10 ** decimals) >= 100)
19
+ decimals -= 1;
20
+ const round = (x) => {
21
+ if (decimals >= 0)
22
+ return x.toFixed(decimals);
23
+ const step = 10 ** -decimals;
24
+ return String(Math.round(x / step) * step);
25
+ };
26
+ return { value: round(value), error: round(error) };
27
+ }
28
+ /**
29
+ * A computed value with no error to round to, to a few significant digits: for a value whose
30
+ * inputs were published without errors. 2158.38 becomes "2160". Mark it as approximate.
31
+ */
32
+ export function roundToSignificant(value, digits = 3) {
33
+ return String(Number(value.toPrecision(digits)));
34
+ }
35
+ //# sourceMappingURL=rounding.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rounding.js","sourceRoot":"","sources":["../src/rounding.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAC1F,2FAA2F;AAC3F,kEAAkE;AAElE;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAa,EAAE,KAAa;IAC7D,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,GAAG,CAAC,CAA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