@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.
- package/LICENSE +202 -0
- package/README.md +227 -2
- package/dist/angles.d.ts +51 -0
- package/dist/angles.d.ts.map +1 -0
- package/dist/angles.js +261 -0
- package/dist/angles.js.map +1 -0
- package/dist/constants.d.ts +35 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +44 -0
- package/dist/constants.js.map +1 -0
- package/dist/coordinates.d.ts +213 -0
- package/dist/coordinates.d.ts.map +1 -0
- package/dist/coordinates.js +474 -0
- package/dist/coordinates.js.map +1 -0
- package/dist/distance.d.ts +26 -0
- package/dist/distance.d.ts.map +1 -0
- package/dist/distance.js +54 -0
- package/dist/distance.js.map +1 -0
- package/dist/errors.d.ts +24 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +24 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/kinds.d.ts +86 -0
- package/dist/kinds.d.ts.map +1 -0
- package/dist/kinds.js +29 -0
- package/dist/kinds.js.map +1 -0
- package/dist/parse-unit.d.ts +11 -0
- package/dist/parse-unit.d.ts.map +1 -0
- package/dist/parse-unit.js +222 -0
- package/dist/parse-unit.js.map +1 -0
- package/dist/quantity.d.ts +150 -0
- package/dist/quantity.d.ts.map +1 -0
- package/dist/quantity.js +452 -0
- package/dist/quantity.js.map +1 -0
- package/dist/rounding.d.ts +18 -0
- package/dist/rounding.d.ts.map +1 -0
- package/dist/rounding.js +35 -0
- package/dist/rounding.js.map +1 -0
- package/dist/time.d.ts +100 -0
- package/dist/time.d.ts.map +1 -0
- package/dist/time.js +448 -0
- package/dist/time.js.map +1 -0
- package/dist/units.d.ts +394 -0
- package/dist/units.d.ts.map +1 -0
- package/dist/units.js +353 -0
- package/dist/units.js.map +1 -0
- package/package.json +44 -3
- package/src/angles.ts +286 -0
- package/src/constants.ts +51 -0
- package/src/coordinates.ts +591 -0
- package/src/distance.ts +58 -0
- package/src/errors.ts +27 -0
- package/src/index.ts +27 -0
- package/src/kinds.ts +110 -0
- package/src/parse-unit.ts +230 -0
- package/src/quantity.ts +539 -0
- package/src/rounding.ts +33 -0
- package/src/time.ts +511 -0
- package/src/units.ts +445 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,228 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @arcosmos/astronomy
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Units and quantities with uncertainties for astronomy, in TypeScript. It needs no key and no
|
|
4
|
+
network, and runs the same in a browser, Node, Deno, Bun or a Worker. Version 0.x: the surface
|
|
5
|
+
may still change.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @arcosmos/astronomy
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
So far it has units and quantities, angles as text, positions on the sky in Astropy's frames
|
|
12
|
+
with their distance and space motion, distances from parallaxes, and times in Astropy's time
|
|
13
|
+
scales, built on `@arcosmos/erfa`, a TypeScript translation of ERFA.
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { q, unit, fromMeasurement } from '@arcosmos/astronomy'
|
|
17
|
+
|
|
18
|
+
const d = q(4.2465, 'ly', { sigma: 0.0003 }).to('pc') // about 1.3020 ± 0.0001 pc
|
|
19
|
+
unit('mas/yr').kind // "angular speed"
|
|
20
|
+
|
|
21
|
+
q(1, 'pc').plus(q(1, 's')) // compile error: a length plus a time
|
|
22
|
+
q(1, 'pc').to('km/s') // compile error: a length to a speed
|
|
23
|
+
|
|
24
|
+
// A measurement from the Arcosmos API, uncertainty and limit included.
|
|
25
|
+
const mass = fromMeasurement({ value: 1.07, unit: 'M_jup', uncertainty: { kind: 'asymmetric', plus: 0.1, minus: -0.05 } })
|
|
26
|
+
mass.to('M_earth') // errors scaled exactly
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Angles and coordinates
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { formatAngle, parseAngle, q, skyCoord } from '@arcosmos/astronomy'
|
|
33
|
+
|
|
34
|
+
const m31 = skyCoord({ ra: '00h42m44.3s', dec: '+41d16m09s' })
|
|
35
|
+
m31.galactic.toString() // "121.174 -21.5729"
|
|
36
|
+
m31.transformTo('fk5', { equinox: 'J1975' })
|
|
37
|
+
m31.separation(skyCoord({ ra: q(10.6, 'deg'), dec: q(41.2, 'deg') })) // in degrees
|
|
38
|
+
m31.toString('hmsdms') // "00h42m44.3s +41d16m09s"
|
|
39
|
+
|
|
40
|
+
parseAngle('12:30:45.6', 'hourangle').to('deg') // 187.69 deg
|
|
41
|
+
formatAngle(q(187.69, 'deg'), { unit: 'hourangle', precision: 1 }) // "12h30m45.6s"
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
- **Frames:** ICRS, FK5 and the barycentric mean ecliptic at any equinox ("J1975", "B1950"),
|
|
45
|
+
Galactic and Supergalactic, each defined as Astropy defines it. Astropy's Galactic goes
|
|
46
|
+
through FK5 J2000; ERFA's own `icrs2g` uses the Hipparcos definition, up to about 25 mas away.
|
|
47
|
+
- **Agreement with Astropy:** within 0.0004 microarcseconds for every frame, which is
|
|
48
|
+
floating-point rounding.
|
|
49
|
+
- **Many positions at once:** `frameRotation('icrs', 'galactic')` is the matrix a SkyCoord is
|
|
50
|
+
turned by, for cartesian vectors on plain numbers, where a SkyCoord per star would cost too
|
|
51
|
+
much (a map of 300,000 stars). Its transpose turns back.
|
|
52
|
+
- **A coordinate may carry** a distance (or a parallax), proper motions, a radial velocity and
|
|
53
|
+
an `obstime`, as below. Not yet an uncertainty: a quantity with one is refused.
|
|
54
|
+
- **Angle text** follows Astropy's `Angle`: the same grammar, refusals and range checks when
|
|
55
|
+
reading, and `to_string`'s rounding, carrying and padding when writing, so a string
|
|
56
|
+
written here is the one Astropy writes. Separators longer than a character go in a list,
|
|
57
|
+
as Astropy's tuple: `{ sep: ['h ', 'm ', 's'] }` writes "14h 29m 34.16s".
|
|
58
|
+
|
|
59
|
+
## Space motion
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
import { moveStar, q, skyCoord, time } from '@arcosmos/astronomy'
|
|
63
|
+
|
|
64
|
+
const barnard = skyCoord({
|
|
65
|
+
ra: q(269.452077, 'deg'), dec: q(4.693365, 'deg'),
|
|
66
|
+
pmRaCosdec: q(-801.551, 'mas/yr'), pmDec: q(10362.394, 'mas/yr'),
|
|
67
|
+
parallax: q(546.9759, 'mas'), radialVelocity: q(-110.11, 'km/s'),
|
|
68
|
+
obstime: time('J2000'),
|
|
69
|
+
})
|
|
70
|
+
barnard.applySpaceMotion({ newObstime: time('J2016') }) // at Gaia DR3's epoch
|
|
71
|
+
barnard.applySpaceMotion({ dt: q(100, 'yr') }).pmDec // 10,491 mas/yr: it grows as the star nears
|
|
72
|
+
barnard.galactic.pmB // proper motions turn with the frame
|
|
73
|
+
|
|
74
|
+
// Many stars between the same two times, on plain numbers.
|
|
75
|
+
moveStar({ raDeg: 269.452077, decDeg: 4.693365, pmRaCosdecMasYr: -801.551, pmDecMasYr: 10362.394,
|
|
76
|
+
parallaxMas: 546.9759, radialVelocityKmS: -110.11 }, time('J2000'), time('J2016'))
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
- **As Astropy's `apply_space_motion`:** to ICRS, through ERFA's `pmsafe` with both times in
|
|
80
|
+
TDB, and back to the coordinate's frame. The star moves in a straight line in space, with the
|
|
81
|
+
light-time and perspective effects ERFA includes, so a star coming nearer speeds up on the sky.
|
|
82
|
+
- **Give the new time or the interval.** `newObstime` needs the coordinate's `obstime`. With
|
|
83
|
+
`dt` and no `obstime`, the interval is counted from J2000 (TT) and the result has no `obstime`,
|
|
84
|
+
as in Astropy.
|
|
85
|
+
- **What's missing is assumed as Astropy assumes it:** no parallax puts the star far away, no
|
|
86
|
+
radial velocity is zero. A coordinate with a distance and a radial velocity but no proper
|
|
87
|
+
motion moves along the line of sight.
|
|
88
|
+
- **pmsafe's safeguards apply.** A parallax too small for the proper motion is raised until the
|
|
89
|
+
speed across the sky is about 1% of light's (the result's distance is the raised one), and a
|
|
90
|
+
star faster than half the speed of light doesn't move.
|
|
91
|
+
- **One deliberate difference:** a radial velocity that wasn't given stays unknown. Astropy
|
|
92
|
+
reports pmsafe's, which comes from the distance pmsafe assumed (up to 1.3 km/s in the tests).
|
|
93
|
+
- **`moveStar`** does the same on plain numbers (degrees, mas/yr, mas, km/s), for moving many
|
|
94
|
+
stars without making a coordinate for each. A parallax of zero or less counts as unknown. The
|
|
95
|
+
Arcosmos API's cross-match moves SIMBAD's stars with it.
|
|
96
|
+
- **Agreement with Astropy:** positions within 1e-6 mas and proper motions within 1e-11 mas/yr
|
|
97
|
+
over 87 motions, frames and epochs from 1900 to 2100, and the same refusals. Where pmsafe
|
|
98
|
+
raises a parallax, distance and radial velocity agree within 1e-10 of themselves: the raised
|
|
99
|
+
value comes from the separation of two nearly equal directions, where V8's and MSVC's sine
|
|
100
|
+
and cosine differ in the last bit.
|
|
101
|
+
|
|
102
|
+
## Time
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
import { q, time } from '@arcosmos/astronomy'
|
|
106
|
+
|
|
107
|
+
const t = time('2016-12-31T23:59:59', { scale: 'utc' })
|
|
108
|
+
t.plus(q(1, 's')).isot // "2016-12-31T23:59:60.000", the leap second
|
|
109
|
+
t.tt.isot // "2017-01-01T00:01:07.184"
|
|
110
|
+
time('2017-01-01T00:00:00').minus(t) // 1.9999999999939178 s, counted in TAI, as Astropy gives it
|
|
111
|
+
time('J2000').jd // 2451545, in TT
|
|
112
|
+
time(2451545, { format: 'jd', scale: 'tdb' }).tcb.mjd
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
- **Held as Astropy holds a time:** two numbers whose sum is the Julian date, a whole day and a
|
|
116
|
+
fraction, renormalized after every step, so precision stays well under a nanosecond.
|
|
117
|
+
- **Scales:** UTC, TAI, TT, TDB, TCG and TCB, converted through ERFA along Astropy's paths. TDB
|
|
118
|
+
is computed at the geocenter, as Astropy does without a location. UT1, which needs Earth
|
|
119
|
+
orientation data, comes later.
|
|
120
|
+
- **Leap seconds** are ERFA's table, the last at the end of 2016. ERFA calls UTC after 2028
|
|
121
|
+
dubious, since a leap second could be announced; this carries on, as Astropy does.
|
|
122
|
+
- **Formats:** `jd`, `mjd`, `jyear`, `byear`, `unix`, `iso`, `isot`, and `jyear_str` and
|
|
123
|
+
`byear_str` ("J2000.5"), read and written as Astropy does, ISO text through ERFA's `d2dtf`.
|
|
124
|
+
- **Arithmetic** takes durations as quantities. On a UTC time it counts in TAI, so a leap second
|
|
125
|
+
counts as the second it is.
|
|
126
|
+
- **Agreement with Astropy:** of 726 conversions, 709 give Astropy's two numbers to the last bit
|
|
127
|
+
and the rest are within 10 picoseconds. All 3,200 formatted strings are identical, and so is
|
|
128
|
+
what is read and refused.
|
|
129
|
+
|
|
130
|
+
## Units
|
|
131
|
+
|
|
132
|
+
- Symbols, aliases and SI prefixes as Astropy writes them (`ly` and `lyr`, `R_sun` and `solRad`,
|
|
133
|
+
`km`, `Myr`, `mas`), plus `S_earth`, the flux Earth receives from the Sun.
|
|
134
|
+
- Products, quotients and powers: `km/s`, `erg/(cm^2 s)`, `m s-1`, `m^(1/2)`. After a `/`, a
|
|
135
|
+
product needs parentheses: `W/m^2 Hz` is refused rather than guessed.
|
|
136
|
+
- Logarithmic units: `mag`, `dex`, and `log10(X)` (Astropy's `dex(X)`). Magnitudes and dex
|
|
137
|
+
convert to each other, log10 of a unit to log10 of another of its kind, and log10 of a unit
|
|
138
|
+
to the unit and back (`q(5.25, "log10(L_sun)").to("L_sun")`), as do mag and dex and a plain
|
|
139
|
+
number. A value of zero or less has no logarithm, and is refused.
|
|
140
|
+
- Angles are a dimension of their own, as in Astropy: `rad` doesn't convert to a plain number.
|
|
141
|
+
- Units are defined from exact constants: IAU 2012 B2 (au), IAU 2015 B2 (pc) and B3 (nominal
|
|
142
|
+
solar and planetary values), and CODATA (G). Pi and G cancel exactly where they can, so
|
|
143
|
+
arcsec to deg is exactly 1/3600 and M_jup to M_earth is a ratio of GMs.
|
|
144
|
+
|
|
145
|
+
## Uncertainties
|
|
146
|
+
|
|
147
|
+
A quantity's uncertainty takes the forms the Arcosmos API publishes: a symmetric sigma,
|
|
148
|
+
asymmetric errors (plus >= 0, minus <= 0), 16th and 84th percentiles, or the error ellipse
|
|
149
|
+
SIMBAD gives a proper motion. It may also be an upper or lower limit.
|
|
150
|
+
|
|
151
|
+
- **None given means none known.** Anything computed from it has none either. An exact value
|
|
152
|
+
has `sigma: 0`.
|
|
153
|
+
- **Converting units and scaling by a number are exact**, for limits and for every form of
|
|
154
|
+
uncertainty, except that scaling refuses an error ellipse (below). A factor that reverses
|
|
155
|
+
order (mag to dex, negation) swaps plus and minus, and upper and lower.
|
|
156
|
+
- **Between log10 of a unit and the unit, each end of an error converts**, since the map
|
|
157
|
+
isn't linear: 5.25 ± 0.1 in log10(L_sun) is 177,828 L_sun +46,044 / -36,574, the interval
|
|
158
|
+
the error stands for, exactly. A symmetric error becomes an asymmetric one, wider on the
|
|
159
|
+
upper side than first order (L ln 10 sigma) would make it. Percentiles and limits convert
|
|
160
|
+
as points, and an end with no logarithm (2 ± 3 L_sun into log10) is refused.
|
|
161
|
+
- **Arithmetic between quantities propagates symmetric errors to first order**, treating the
|
|
162
|
+
operands as independent, so `a.minus(a)` has sigma × √2.
|
|
163
|
+
- **Asymmetric errors, percentiles and limits are refused in arithmetic.** First-order
|
|
164
|
+
propagation doesn't define them, so `symmetrized("larger")` or `symmetrized("mean")` says how
|
|
165
|
+
to turn them into one sigma first.
|
|
166
|
+
- **An error ellipse only follows a change of unit.** It is the error of a vector, a proper
|
|
167
|
+
motion's two components together, and both components carry it. What it means for one
|
|
168
|
+
component after scaling, arithmetic or symmetrizing depends on the other, so those refuse it.
|
|
169
|
+
Its axes are in the value's unit (`fromMeasurement` converts them from the unit the API
|
|
170
|
+
names), and `toJSON()` writes it back with that unit, as the API does.
|
|
171
|
+
|
|
172
|
+
## Distances
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
import { distanceFromParallax, distanceModulus, distanceModulusPc, parallaxDistancePc, q } from '@arcosmos/astronomy'
|
|
176
|
+
|
|
177
|
+
const d = distanceFromParallax(q(768.0665, 'mas', { sigma: 0.0499 })) // 1.30197 ± 0.00008 pc
|
|
178
|
+
const absoluteG = q(8.984749, 'mag').minus(distanceModulus(d)) // G less the distance modulus
|
|
179
|
+
|
|
180
|
+
parallaxDistancePc(768.0665) // the same on plain numbers, for many stars
|
|
181
|
+
distanceModulusPc(1.30197)
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
- **As Astropy's `Distance`:** `Distance(parallax=...)` and `Distance.distmod`, 5 log10(d / 10 pc).
|
|
185
|
+
- **Errors to first order**, as any computation here: d × sigma / parallax, and 5 / ln 10 ×
|
|
186
|
+
sigma / d. Limits, asymmetric errors and percentiles are refused, as in arithmetic.
|
|
187
|
+
- **A parallax or distance of zero or less** gives no distance or modulus: the quantity forms
|
|
188
|
+
throw, and the plain-number forms give NaN. Neither corrects for anything: 1 / parallax is
|
|
189
|
+
biased once the error passes about a tenth of the parallax, and Gaia's parallaxes carry a
|
|
190
|
+
zero-point offset.
|
|
191
|
+
|
|
192
|
+
## Printing a computed value
|
|
193
|
+
|
|
194
|
+
Published values are printed as published. A value computed from them is rounded to what
|
|
195
|
+
its uncertainty allows, as results are quoted: `roundToUncertainty(46.3523, 0.8641)` gives
|
|
196
|
+
`{ value: '46.35', error: '0.86' }`, the error to two significant digits and the value to the
|
|
197
|
+
same place. A value whose inputs had no errors gets `roundToSignificant(value, 3)`, to be
|
|
198
|
+
marked as approximate.
|
|
199
|
+
|
|
200
|
+
## Types
|
|
201
|
+
|
|
202
|
+
A quantity is typed by its kind where the type system knows its unit: `q(10, 'ly')` is a
|
|
203
|
+
`Quantity<'length'>`. It knows every symbol, every prefixed symbol and common compound units
|
|
204
|
+
(`COMPOUND_KINDS`). Any other unit works too, typed as any kind; `unit('au/yr', 'speed')` or
|
|
205
|
+
`.as('speed')` names its kind, checked when it runs.
|
|
206
|
+
|
|
207
|
+
## Tests
|
|
208
|
+
|
|
209
|
+
`pnpm test` checks everything against Astropy, from fixtures `oracle/` generates (see
|
|
210
|
+
`oracle/README.md`):
|
|
211
|
+
|
|
212
|
+
- `test/fixtures/astropy.json`: SI factors, kind names, conversion factors, refused
|
|
213
|
+
conversions, logarithmic conversions (between log10 of a unit and the unit too, each end of
|
|
214
|
+
an error converted), constants, distances from parallaxes and distance moduli, and
|
|
215
|
+
first-order propagation by the `uncertainties` package.
|
|
216
|
+
- `test/fixtures/astropy-coords.json`: every frame for 213 directions and back, 100
|
|
217
|
+
separations and position angles, 102 angle strings (21 of them refused) and 97 formatted
|
|
218
|
+
angles.
|
|
219
|
+
- `test/fixtures/astropy-time.json`: conversions between every scale and format, text read and
|
|
220
|
+
refused, and arithmetic across leap seconds.
|
|
221
|
+
- `test/fixtures/astropy-motion.json`: 93 calls to `apply_space_motion` (6 refused), on real
|
|
222
|
+
stars from SIMBAD and random ones, in every frame, with the inputs Astropy passed to `pmsafe`;
|
|
223
|
+
and proper motions, distances and radial velocities through every frame for 56 stars.
|
|
224
|
+
|
|
225
|
+
## License
|
|
226
|
+
|
|
227
|
+
Apache License 2.0, in `LICENSE`. The rest of the Arcosmos repository is under other licenses:
|
|
228
|
+
its `LICENSING.md` lists them.
|
package/dist/angles.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Quantity } from './quantity.ts';
|
|
2
|
+
/** A unit that may be given as a hint or a target: "deg", "hourangle", or another angle unit. */
|
|
3
|
+
export type AngleUnit = 'deg' | 'hourangle' | 'arcmin' | 'arcsec' | 'mas' | 'uas' | 'rad' | (string & {});
|
|
4
|
+
/**
|
|
5
|
+
* An angle from text, as Astropy's Angle reads it:
|
|
6
|
+
*
|
|
7
|
+
* - "12h30m45.6s", "12h30m", "12.5h", "12ʰ30ᵐ45ˢ" (hours);
|
|
8
|
+
* - "-12d30m45s", "+41d12m00s", "10d30.5m", "1.5 deg", "12°30′45″" (degrees);
|
|
9
|
+
* - "30m" and "45s" alone are arcminutes and arcseconds; "1.2 mas", "0.5 rad" and the like;
|
|
10
|
+
* - "12:30:45.6" or "12 30 45.6", which need `unit` to say whether they are hours or degrees;
|
|
11
|
+
* - a trailing W or S negates.
|
|
12
|
+
*
|
|
13
|
+
* The sign applies to the whole angle ("-0:30:00" is half a degree below zero). Minutes and
|
|
14
|
+
* seconds must be under 60 (60 itself is allowed, as in Astropy), and hours within 24. The
|
|
15
|
+
* angle is in the unit the text names, else in `unit`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function parseAngle(text: string, unit?: AngleUnit): Quantity<'angle'>;
|
|
18
|
+
export interface FormatAngleOptions {
|
|
19
|
+
/** The unit to write in: "deg" or "hourangle" give sexagesimal. Default: from `sep`, else the angle's own. */
|
|
20
|
+
readonly unit?: AngleUnit;
|
|
21
|
+
/** A decimal number rather than sexagesimal. */
|
|
22
|
+
readonly decimal?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* The separators: "dms" or "hms" (one per field), ":" or " " (between fields), or
|
|
25
|
+
* "fromunit", the default: dms for degrees, hms for hours. As in Astropy, a list gives
|
|
26
|
+
* separators longer than a character: `["h ", "m ", "s"]` writes "14h 29m 42.95s".
|
|
27
|
+
*/
|
|
28
|
+
readonly sep?: string | readonly string[];
|
|
29
|
+
/** Decimal places of the last field (or of the number, with `decimal`). Default: as needed, up to 8. */
|
|
30
|
+
readonly precision?: number;
|
|
31
|
+
/** A "+" on positive angles too. */
|
|
32
|
+
readonly alwaysSign?: boolean;
|
|
33
|
+
/** Leading zeros on the first field: "05d" rather than "5d". */
|
|
34
|
+
readonly pad?: boolean;
|
|
35
|
+
/** How many fields to write: 1 (degrees), 2 (and minutes) or 3 (and seconds, the default). */
|
|
36
|
+
readonly fields?: 1 | 2 | 3;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* An angle as text, as Astropy's Angle.to_string writes it: `formatAngle(q(187.69, "deg"),
|
|
40
|
+
* { unit: "hourangle" })` is "12h30m45.6s". Rounding that reaches 60 carries into the next
|
|
41
|
+
* field, and seconds always have two digits before the point.
|
|
42
|
+
*/
|
|
43
|
+
export declare function formatAngle(angle: Quantity<'angle'>, options?: FormatAngleOptions): string;
|
|
44
|
+
/**
|
|
45
|
+
* Python's "{:.pf}": x to p decimal places, an exact tie rounded to even (JavaScript's
|
|
46
|
+
* toFixed rounds it up), and -0 written "-0".
|
|
47
|
+
*/
|
|
48
|
+
export declare function pythonFixed(x: number, p: number): string;
|
|
49
|
+
/** Python's "{:g}": six significant digits, trailing zeros dropped, an exponent outside 1e-4 to 1e6. */
|
|
50
|
+
export declare function pythonG(x: number): string;
|
|
51
|
+
//# sourceMappingURL=angles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"angles.d.ts","sourceRoot":"","sources":["../src/angles.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAuExC,iGAAiG;AACjG,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,WAAW,GAAG,QAAQ,GAAG,QAAQ,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAA;AAQzG;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC,OAAO,CAAC,CAyC5E;AAQD,MAAM,WAAW,kBAAkB;IACjC,8GAA8G;IAC9G,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,CAAA;IACzB,gDAAgD;IAChD,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;IAC1B;;;;OAIG;IACH,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAA;IACzC,wGAAwG;IACxG,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;IAC3B,oCAAoC;IACpC,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAA;IAC7B,gEAAgE;IAChE,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAA;IACtB,8FAA8F;IAC9F,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;CAC5B;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,GAAE,kBAAuB,GAAG,MAAM,CAoB9F;AA4DD;;;GAGG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAaxD;AAED,wGAAwG;AACxG,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAWzC"}
|