ephem 0.5.2 → 0.6.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +185 -0
- data/README.md +171 -15
- data/bin/ruby-ephem +1 -2
- data/lib/ephem/cli.rb +174 -100
- data/lib/ephem/computation/chebyshev_polynomial.rb +82 -110
- data/lib/ephem/core/calendar_calculations.rb +17 -26
- data/lib/ephem/core/constants/bodies.rb +2 -0
- data/lib/ephem/core/constants/time.rb +1 -1
- data/lib/ephem/core/orientation.rb +23 -7
- data/lib/ephem/core/state.rb +48 -13
- data/lib/ephem/core/vector.rb +92 -24
- data/lib/ephem/download.rb +77 -14
- data/lib/ephem/error.rb +3 -3
- data/lib/ephem/excerpt.rb +126 -105
- data/lib/ephem/io/binary_reader.rb +29 -8
- data/lib/ephem/io/daf.rb +1 -4
- data/lib/ephem/io/endianness_manager.rb +5 -18
- data/lib/ephem/io/record_data.rb +2 -20
- data/lib/ephem/io/record_parser.rb +1 -1
- data/lib/ephem/io/summary_manager.rb +24 -15
- data/lib/ephem/pck.rb +24 -7
- data/lib/ephem/segments/base_segment.rb +38 -20
- data/lib/ephem/segments/chebyshev_type2.rb +105 -58
- data/lib/ephem/segments/coverage.rb +66 -0
- data/lib/ephem/segments/orientation_segment.rb +17 -15
- data/lib/ephem/segments/orientation_source.rb +4 -2
- data/lib/ephem/segments/position_chain.rb +124 -0
- data/lib/ephem/segments/position_group.rb +24 -0
- data/lib/ephem/segments/segment.rb +87 -18
- data/lib/ephem/segments/segment_group.rb +19 -5
- data/lib/ephem/spk.rb +134 -11
- data/lib/ephem/version.rb +1 -1
- data/lib/ephem.rb +5 -3
- metadata +4 -10
- data/.rspec +0 -3
- data/.standard.yml +0 -3
- data/.tool-versions +0 -1
- data/CODE_OF_CONDUCT.md +0 -132
- data/Rakefile +0 -12
- data/benchmarks/run.rb +0 -431
- data/bin/console +0 -11
- data/bin/setup +0 -8
- data/lib/tasks/validate_accuracy.rake +0 -47
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3f71821338a136e21834f6da3746211ab496079bf93f07b3523db7c9e32a1151
|
|
4
|
+
data.tar.gz: 9257ecdcaf79356aa88ce4c52839489ac02eb807bd5f84d71fa038e77b14bafe
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ef54d18bc6eb3e4990c2de55b6598e43fb6860bece8cd66891c1f936f443143eaa3f9a5fd7ea490d8dda69daae81a050d3d1444f86cf56269d16f7b99e953338
|
|
7
|
+
data.tar.gz: a50d433da5e8d862355af80b281eb2ef9a52c43a4edeba639d05acc9d14acf1a119c4800d2658f675f51408e40eb3ba348caaca077994d362766caad5959e02b
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,190 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.6.0] - 2026-11-30
|
|
4
|
+
|
|
5
|
+
### Breaking changes
|
|
6
|
+
|
|
7
|
+
- Remove `Ephem::IO::DAF#map_array`, an alias of `#read_array` kept from
|
|
8
|
+
jplephem. Call `#read_array` instead ([#106], [#115])
|
|
9
|
+
- `Ephem::OutOfRangeError` now inherits from `Ephem::Error`, so `rescue
|
|
10
|
+
Ephem::Error` catches it ([#94], [#120])
|
|
11
|
+
- `SPK.open` and `PCK.open` raise `Ephem::FileFormatError` instead of
|
|
12
|
+
`ArgumentError` when given the wrong kind of kernel, and no longer turn
|
|
13
|
+
`Errno::EACCES` into `ArgumentError` ([#94], [#120])
|
|
14
|
+
- Unsupported SPK segment types and position queries on orientation segments
|
|
15
|
+
raise `Ephem::UnsupportedError` instead of `NotImplementedError` ([#94],
|
|
16
|
+
[#120])
|
|
17
|
+
- Remove `Ephem::IndexError`. `Vector#[]` and `Orientation#[]` raise Ruby's
|
|
18
|
+
`IndexError` ([#94], [#120])
|
|
19
|
+
- `Ephem::OutOfRangeError#out_of_range_times` is always an Array of every
|
|
20
|
+
uncovered time, as Julian Dates. It used to be a single number, in seconds
|
|
21
|
+
since J2000 or in Julian Date depending on the source ([#127], [#128])
|
|
22
|
+
- More errors inherit from `Ephem::Error` ([#129], [#138]):
|
|
23
|
+
- `position_at` and `state_at` on PCK segments and groups raise
|
|
24
|
+
`Ephem::UnsupportedError` instead of `NoMethodError`
|
|
25
|
+
- Reading from a kernel or one of its segments after `close` raises the new
|
|
26
|
+
`Ephem::ClosedKernelError` instead of `IOError`
|
|
27
|
+
- `Ephem::Download` wraps network, TLS and archive errors in
|
|
28
|
+
`Ephem::DownloadError`, keeping the original error as `cause`
|
|
29
|
+
- `Ephem::Download` no longer accepts `de431.bsp`, which JPL has removed and
|
|
30
|
+
now answers with a 404. Use `de431t.bsp` instead ([#131], [#135])
|
|
31
|
+
- Unsupported SPK data types in `Segment` raise `Ephem::UnsupportedError`
|
|
32
|
+
instead of a `RuntimeError` ([#106], [#115])
|
|
33
|
+
- `State` instances are frozen ([#108], [#121])
|
|
34
|
+
- `Vector#eql?` and `Orientation#eql?` compare components strictly, consistent
|
|
35
|
+
with `hash`, so `Vector[1, 2, 3].eql?(Vector[1.0, 2.0, 3.0])` is now false
|
|
36
|
+
([#99], [#123])
|
|
37
|
+
- `Excerpt` raises errors instead of printing them and skipping the segment, and
|
|
38
|
+
raises `Ephem::UnsupportedError` for segment types it cannot excerpt ([#98],
|
|
39
|
+
[#113])
|
|
40
|
+
- `ruby-ephem excerpt` converts dates to the Julian Date at midnight instead of
|
|
41
|
+
noon, so an excerpt starts and ends 12 hours earlier than before ([#95],
|
|
42
|
+
[#114])
|
|
43
|
+
- `require "ephem"` no longer loads `net/http`, `optparse`, `date`, `tempfile`
|
|
44
|
+
or `zlib`. Code that used them without requiring them must now require them
|
|
45
|
+
itself ([#105], [#119])
|
|
46
|
+
- Remove unused code: `ChebyshevPolynomial.evaluate_derivative` (use
|
|
47
|
+
`.evaluate_with_derivative`), `SPK::TYPES` (`SPK::INPOP` and `SPK::JPL_DE`
|
|
48
|
+
remain), the `IO::RecordData` readers for the backward and free record
|
|
49
|
+
pointers, format, FTP string and reserved areas, and the
|
|
50
|
+
`Excerpt::DAFWriter` readers other than `summary_format` ([#142])
|
|
51
|
+
- Rename `Excerpt::DAFWriter#fward=` and `#bward=` to `#forward_record=` and
|
|
52
|
+
`#backward_record=`, and the `:n_summaries` key returned by
|
|
53
|
+
`IO::RecordParser#parse_summary_control` to `:summary_count` ([#142])
|
|
54
|
+
|
|
55
|
+
### Deprecations
|
|
56
|
+
|
|
57
|
+
- `Ephem::SPK::TYPES` is deprecated. Compare `SPK#type` with `SPK::INPOP` or
|
|
58
|
+
`SPK::JPL_DE` instead ([#144])
|
|
59
|
+
|
|
60
|
+
### Features
|
|
61
|
+
|
|
62
|
+
- Add `Vector#*` and `Vector#/` with a scalar and unary `Vector#-@`, and give
|
|
63
|
+
`State` `==`, `eql?` and `hash` ([#108], [#121])
|
|
64
|
+
- `SPK.open` and `PCK.open` take a block, like `File.open`: the kernel is closed
|
|
65
|
+
when the block returns or raises, and the block's value is returned ([#100],
|
|
66
|
+
[#116])
|
|
67
|
+
- Add `SPK#position_at` and `SPK#state_at` to get the position or state of any
|
|
68
|
+
target relative to any center, chaining the stored pairs that link them
|
|
69
|
+
([#107], [#112])
|
|
70
|
+
- `Download` fetches the lunar orientation kernel (`inpop21a.bpc`) and the
|
|
71
|
+
TT-TDB time ephemeris (`inpop21a_time.bsp`) that IMCCE ships with each INPOP
|
|
72
|
+
kernel. Segments of the time ephemeris are described as "Time Center" ->
|
|
73
|
+
"TT-TDB" ([#134])
|
|
74
|
+
- `Ephem::Download` can download `de431t.bsp`, `de442.bsp` and `de442t.bsp`
|
|
75
|
+
from JPL ([#131], [#135])
|
|
76
|
+
|
|
77
|
+
### Improvements
|
|
78
|
+
|
|
79
|
+
- Fix documentation errors: broken README links, an undefined variable in the
|
|
80
|
+
rotation example, wrong constant names in YARD examples, and the J2000 epoch
|
|
81
|
+
and accuracy wording ([#106], [#115])
|
|
82
|
+
- Document how to enable YJIT, which makes computations about 2 to 2.5 times
|
|
83
|
+
faster ([#104], [#110])
|
|
84
|
+
- Ship only runtime files in the gem and require MFA to publish it. The
|
|
85
|
+
`validate_accuracy` rake task is defined in `rakelib/`, and its code under
|
|
86
|
+
`lib/ephem/tasks/` is left out of the gem ([#109], [#124])
|
|
87
|
+
- Load `Ephem::CLI`, `Ephem::Download` and `Ephem::Excerpt` on first use, so
|
|
88
|
+
`require "ephem"` no longer loads `net/http`, `optparse`, `date`, `tempfile`
|
|
89
|
+
or `zlib` ([#105], [#119])
|
|
90
|
+
- Out-of-range errors name the requested Julian Date and calendar date, the pair
|
|
91
|
+
or body, and the range it covers, instead of a time in seconds since J2000
|
|
92
|
+
([#127], [#128])
|
|
93
|
+
- Validate INPOP21a against the IMCCE `testpo` file with
|
|
94
|
+
`rake validate_accuracy:testpo`, also run by `validate_accuracy:all` in CI
|
|
95
|
+
([#143])
|
|
96
|
+
- Add a `CITATION.cff`, so GitHub shows how to cite ruby-ephem and Zenodo
|
|
97
|
+
can archive releases ([#145])
|
|
98
|
+
|
|
99
|
+
### Bug fixes
|
|
100
|
+
|
|
101
|
+
- Show body names as written, so segment descriptions say "Earth-Moon
|
|
102
|
+
Barycenter" instead of "Earth-moon Barycenter" ([#101], [#126])
|
|
103
|
+
- Read DAF summary integers as signed, so segments with a negative NAIF ID
|
|
104
|
+
(spacecraft, some small bodies) can be looked up and excerpted ([#93], [#117])
|
|
105
|
+
- Raise `Ephem::FileFormatError` when a kernel file is truncated, instead of
|
|
106
|
+
failing later with an unrelated `NoMethodError` ([#103], [#122])
|
|
107
|
+
- Fix a race in the cached interval lookup that could return a wrong position
|
|
108
|
+
when the same segment is queried from several threads ([#97], [#125])
|
|
109
|
+
- Raise `Ephem::FileFormatError` instead of looping forever when the summary
|
|
110
|
+
record chain of a malformed kernel points back to an earlier record ([#102],
|
|
111
|
+
[#118])
|
|
112
|
+
- Evaluate the velocity of SPK type 3 segments from their stored velocity
|
|
113
|
+
coefficients, as SPICE does, instead of differentiating the position ([#96],
|
|
114
|
+
[#111])
|
|
115
|
+
- `Vector#==` and `Orientation#==` return false for objects of another class,
|
|
116
|
+
including `nil`, instead of raising `Ephem::InvalidInputError` ([#99], [#123])
|
|
117
|
+
- `Excerpt` writes the excerpt to a temporary file and renames it into place,
|
|
118
|
+
so a failure leaves no partial file ([#98], [#113])
|
|
119
|
+
- `ruby-ephem` writes errors to stderr and exits with status 1 when a command
|
|
120
|
+
fails, and rejects invalid `--targets` values instead of reading them as `0`
|
|
121
|
+
([#95], [#114])
|
|
122
|
+
- `Vector#/` always returns Float components, so `Vector[1, 2, 3] / 2` is
|
|
123
|
+
`Vector[0.5, 1.0, 1.5]` instead of `Vector[0, 1, 1]`. Dividing by `0` gives
|
|
124
|
+
Infinity or NaN components instead of raising `ZeroDivisionError` ([#130],
|
|
125
|
+
[#136])
|
|
126
|
+
- Raise `Ephem::FileFormatError` naming the missing record when a kernel is
|
|
127
|
+
empty or ends inside one of its file, comment, summary or name records,
|
|
128
|
+
instead of an `IOError` or a record silently padded with null bytes.
|
|
129
|
+
`SPK.open`, `PCK.open` and the `ruby-ephem` command also close the file when
|
|
130
|
+
the kernel cannot be read ([#133], [#137])
|
|
131
|
+
- Fix a race where clearing a segment's data, or closing its kernel, while
|
|
132
|
+
another thread queries it raised `NoMethodError` ([#132], [#139])
|
|
133
|
+
|
|
134
|
+
[#93]: https://github.com/rhannequin/ruby-ephem/issues/93
|
|
135
|
+
[#94]: https://github.com/rhannequin/ruby-ephem/issues/94
|
|
136
|
+
[#95]: https://github.com/rhannequin/ruby-ephem/issues/95
|
|
137
|
+
[#96]: https://github.com/rhannequin/ruby-ephem/issues/96
|
|
138
|
+
[#97]: https://github.com/rhannequin/ruby-ephem/issues/97
|
|
139
|
+
[#98]: https://github.com/rhannequin/ruby-ephem/issues/98
|
|
140
|
+
[#99]: https://github.com/rhannequin/ruby-ephem/issues/99
|
|
141
|
+
[#100]: https://github.com/rhannequin/ruby-ephem/issues/100
|
|
142
|
+
[#101]: https://github.com/rhannequin/ruby-ephem/issues/101
|
|
143
|
+
[#102]: https://github.com/rhannequin/ruby-ephem/issues/102
|
|
144
|
+
[#103]: https://github.com/rhannequin/ruby-ephem/issues/103
|
|
145
|
+
[#104]: https://github.com/rhannequin/ruby-ephem/issues/104
|
|
146
|
+
[#105]: https://github.com/rhannequin/ruby-ephem/issues/105
|
|
147
|
+
[#106]: https://github.com/rhannequin/ruby-ephem/issues/106
|
|
148
|
+
[#107]: https://github.com/rhannequin/ruby-ephem/issues/107
|
|
149
|
+
[#108]: https://github.com/rhannequin/ruby-ephem/issues/108
|
|
150
|
+
[#109]: https://github.com/rhannequin/ruby-ephem/issues/109
|
|
151
|
+
[#110]: https://github.com/rhannequin/ruby-ephem/pull/110
|
|
152
|
+
[#111]: https://github.com/rhannequin/ruby-ephem/pull/111
|
|
153
|
+
[#112]: https://github.com/rhannequin/ruby-ephem/pull/112
|
|
154
|
+
[#113]: https://github.com/rhannequin/ruby-ephem/pull/113
|
|
155
|
+
[#114]: https://github.com/rhannequin/ruby-ephem/pull/114
|
|
156
|
+
[#115]: https://github.com/rhannequin/ruby-ephem/pull/115
|
|
157
|
+
[#116]: https://github.com/rhannequin/ruby-ephem/pull/116
|
|
158
|
+
[#117]: https://github.com/rhannequin/ruby-ephem/pull/117
|
|
159
|
+
[#118]: https://github.com/rhannequin/ruby-ephem/pull/118
|
|
160
|
+
[#119]: https://github.com/rhannequin/ruby-ephem/pull/119
|
|
161
|
+
[#120]: https://github.com/rhannequin/ruby-ephem/pull/120
|
|
162
|
+
[#121]: https://github.com/rhannequin/ruby-ephem/pull/121
|
|
163
|
+
[#122]: https://github.com/rhannequin/ruby-ephem/pull/122
|
|
164
|
+
[#123]: https://github.com/rhannequin/ruby-ephem/pull/123
|
|
165
|
+
[#124]: https://github.com/rhannequin/ruby-ephem/pull/124
|
|
166
|
+
[#125]: https://github.com/rhannequin/ruby-ephem/pull/125
|
|
167
|
+
[#126]: https://github.com/rhannequin/ruby-ephem/pull/126
|
|
168
|
+
[#127]: https://github.com/rhannequin/ruby-ephem/issues/127
|
|
169
|
+
[#128]: https://github.com/rhannequin/ruby-ephem/pull/128
|
|
170
|
+
[#129]: https://github.com/rhannequin/ruby-ephem/issues/129
|
|
171
|
+
[#130]: https://github.com/rhannequin/ruby-ephem/issues/130
|
|
172
|
+
[#131]: https://github.com/rhannequin/ruby-ephem/issues/131
|
|
173
|
+
[#132]: https://github.com/rhannequin/ruby-ephem/issues/132
|
|
174
|
+
[#133]: https://github.com/rhannequin/ruby-ephem/issues/133
|
|
175
|
+
[#134]: https://github.com/rhannequin/ruby-ephem/pull/134
|
|
176
|
+
[#135]: https://github.com/rhannequin/ruby-ephem/pull/135
|
|
177
|
+
[#136]: https://github.com/rhannequin/ruby-ephem/pull/136
|
|
178
|
+
[#137]: https://github.com/rhannequin/ruby-ephem/pull/137
|
|
179
|
+
[#138]: https://github.com/rhannequin/ruby-ephem/pull/138
|
|
180
|
+
[#139]: https://github.com/rhannequin/ruby-ephem/pull/139
|
|
181
|
+
[#142]: https://github.com/rhannequin/ruby-ephem/pull/142
|
|
182
|
+
[#143]: https://github.com/rhannequin/ruby-ephem/pull/143
|
|
183
|
+
[#144]: https://github.com/rhannequin/ruby-ephem/pull/144
|
|
184
|
+
[#145]: https://github.com/rhannequin/ruby-ephem/pull/145
|
|
185
|
+
|
|
186
|
+
**Full Changelog**: https://github.com/rhannequin/ruby-ephem/compare/v0.5.2...v0.6.0
|
|
187
|
+
|
|
3
188
|
## [0.5.2] - 2026-11-24
|
|
4
189
|
|
|
5
190
|
### Bug fixes
|
data/README.md
CHANGED
|
@@ -12,7 +12,7 @@ These files are a collection of numerical integrations of the equations of
|
|
|
12
12
|
motion of the Solar System, used to calculate the positions of the planets,
|
|
13
13
|
the Moon, and other celestial bodies with high precision.
|
|
14
14
|
|
|
15
|
-
Ephem supports planetary ephemerides like DE421, DE430,
|
|
15
|
+
Ephem supports planetary ephemerides like DE421, DE430, INPOP21A, etc. (SPK),
|
|
16
16
|
as well as binary PCK orientation kernels such as the lunar orientation kernel
|
|
17
17
|
`moon_pa_de440_200625.bpc`.
|
|
18
18
|
|
|
@@ -43,7 +43,7 @@ begin with:
|
|
|
43
43
|
|
|
44
44
|
* `de421.bsp`: from 1900 to 2050, 17 MB
|
|
45
45
|
* `de440s.bsp`: from 1849 to 2150, 32 MB
|
|
46
|
-
* `
|
|
46
|
+
* `inpop21a.bsp`: from 1900 to 2100, 22 MB
|
|
47
47
|
|
|
48
48
|
## Usage
|
|
49
49
|
|
|
@@ -59,7 +59,7 @@ puts spk
|
|
|
59
59
|
# => SPK file with 15 segments:
|
|
60
60
|
# 1899-07-29..2053-10-09 Type 2 Solar System Barycenter (0) -> Mercury Barycenter (1)
|
|
61
61
|
# 1899-07-29..2053-10-09 Type 2 Solar System Barycenter (0) -> Venus Barycenter (2)
|
|
62
|
-
# 1899-07-29..2053-10-09 Type 2 Solar System Barycenter (0) -> Earth-
|
|
62
|
+
# 1899-07-29..2053-10-09 Type 2 Solar System Barycenter (0) -> Earth-Moon Barycenter (3)
|
|
63
63
|
# 1899-07-29..2053-10-09 Type 2 Solar System Barycenter (0) -> Mars Barycenter (4)
|
|
64
64
|
# 1899-07-29..2053-10-09 Type 2 Solar System Barycenter (0) -> Jupiter Barycenter (5)
|
|
65
65
|
# 1899-07-29..2053-10-09 Type 2 Solar System Barycenter (0) -> Saturn Barycenter (6)
|
|
@@ -67,8 +67,8 @@ puts spk
|
|
|
67
67
|
# 1899-07-29..2053-10-09 Type 2 Solar System Barycenter (0) -> Neptune Barycenter (8)
|
|
68
68
|
# 1899-07-29..2053-10-09 Type 2 Solar System Barycenter (0) -> Pluto Barycenter (9)
|
|
69
69
|
# 1899-07-29..2053-10-09 Type 2 Solar System Barycenter (0) -> Sun (10)
|
|
70
|
-
# 1899-07-29..2053-10-09 Type 2 Earth-
|
|
71
|
-
# 1899-07-29..2053-10-09 Type 2 Earth-
|
|
70
|
+
# 1899-07-29..2053-10-09 Type 2 Earth-Moon Barycenter (3) -> Moon (301)
|
|
71
|
+
# 1899-07-29..2053-10-09 Type 2 Earth-Moon Barycenter (3) -> Earth (399)
|
|
72
72
|
# 1899-07-29..2053-10-09 Type 2 Mercury Barycenter (1) -> Mercury (199)
|
|
73
73
|
# 1899-07-29..2053-10-09 Type 2 Venus Barycenter (2) -> Venus (299)
|
|
74
74
|
# 1899-07-29..2053-10-09 Type 2 Mars Barycenter (4) -> Mars (499)
|
|
@@ -98,8 +98,44 @@ puts "Position: #{state.position}"
|
|
|
98
98
|
puts "Velocity: #{state.velocity}"
|
|
99
99
|
# => Velocity: Vector[-1117315.1437825128, 254177.26336095092, 136149.03901534996]
|
|
100
100
|
# The velocity is expressed in km/day
|
|
101
|
+
|
|
102
|
+
# Close the kernel when you are done with it
|
|
103
|
+
spk.close
|
|
104
|
+
|
|
105
|
+
# Or pass a block: the kernel is closed when the block finishes, even if it
|
|
106
|
+
# raises, and the block's value is returned
|
|
107
|
+
position = Ephem::SPK.open("tmp/de421.bsp") do |kernel|
|
|
108
|
+
kernel[0, 5].position_at(2460676.5)
|
|
109
|
+
end
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Positions between any two bodies
|
|
113
|
+
|
|
114
|
+
`spk[center, target]` only returns pairs stored in the kernel. A JPL DE
|
|
115
|
+
kernel, for instance, stores the Earth relative to the Earth-Moon
|
|
116
|
+
barycenter (3), not relative to the Solar System Barycenter (0) or to the
|
|
117
|
+
Moon. `SPK#position_at` and `SPK#state_at` find the stored pairs linking
|
|
118
|
+
any two bodies and add or subtract them for you:
|
|
119
|
+
|
|
120
|
+
```rb
|
|
121
|
+
time = 2460676.5
|
|
122
|
+
|
|
123
|
+
# Earth relative to the Solar System Barycenter: (0 -> 3) + (3 -> 399)
|
|
124
|
+
spk.position_at(target: 399, center: 0, tdb: time)
|
|
125
|
+
|
|
126
|
+
# Moon relative to the Earth: (3 -> 301) - (3 -> 399)
|
|
127
|
+
state = spk.state_at(target: 301, center: 399, tdb: time)
|
|
128
|
+
state.position # km
|
|
129
|
+
state.velocity # km/day
|
|
130
|
+
|
|
131
|
+
# Arrays of times and a split Julian Date are supported too
|
|
132
|
+
spk.position_at(target: 301, center: 399, tdb: [time, time + 1])
|
|
133
|
+
spk.position_at(target: 301, center: 399, tdb: 2460676, tdb2: 0.5)
|
|
101
134
|
```
|
|
102
135
|
|
|
136
|
+
A `KeyError` is raised when no chain of stored pairs links the two
|
|
137
|
+
bodies.
|
|
138
|
+
|
|
103
139
|
## Orientation kernels (binary PCK)
|
|
104
140
|
|
|
105
141
|
Binary PCK (`DAF/PCK`) kernels store the orientation of a body frame over time
|
|
@@ -139,6 +175,32 @@ angles = frame.angles_at(2451545.0)
|
|
|
139
175
|
pck.close
|
|
140
176
|
```
|
|
141
177
|
|
|
178
|
+
### INPOP companion kernels
|
|
179
|
+
|
|
180
|
+
IMCCE ships two more kernels next to each INPOP planetary kernel, and Ephem
|
|
181
|
+
can download them under the same name with another suffix:
|
|
182
|
+
|
|
183
|
+
* `inpop21a.bpc`: the lunar orientation of INPOP21a, frame `1900301`
|
|
184
|
+
* `inpop21a_time.bsp`: the TT-TDB time ephemeris, from INPOP13c onwards
|
|
185
|
+
|
|
186
|
+
The time ephemeris stores TT-TDB in seconds as the `x` component of the pair
|
|
187
|
+
`TIME_CENTER` (`1000000000`) -> `TT_MINUS_TDB` (`1000000001`). Its derivative
|
|
188
|
+
is in seconds per day.
|
|
189
|
+
|
|
190
|
+
```rb
|
|
191
|
+
Ephem::Download.call(name: "inpop21a_time.bsp", target: "tmp/time.bsp")
|
|
192
|
+
|
|
193
|
+
Ephem::SPK.open("tmp/time.bsp") do |spk|
|
|
194
|
+
bodies = Ephem::Core::Constants::Bodies
|
|
195
|
+
spk.position_at(
|
|
196
|
+
target: bodies::TT_MINUS_TDB,
|
|
197
|
+
center: bodies::TIME_CENTER,
|
|
198
|
+
tdb: 2451545.0
|
|
199
|
+
).x
|
|
200
|
+
end
|
|
201
|
+
# => 9.928893069898121e-05
|
|
202
|
+
```
|
|
203
|
+
|
|
142
204
|
### Building the body-fixed frame
|
|
143
205
|
|
|
144
206
|
The orientation maps the reference frame into the body-fixed frame through the
|
|
@@ -152,8 +214,15 @@ matrix = frame.matrix_at(2451545.0)
|
|
|
152
214
|
# ...or from an Orientation you already have
|
|
153
215
|
matrix = orientation.to_matrix
|
|
154
216
|
|
|
155
|
-
#
|
|
217
|
+
# Geocentric Earth->Moon vector (km) from the SPK kernel used above, in the
|
|
218
|
+
# same inertial frame (J2000) as the orientation
|
|
219
|
+
spk = Ephem::SPK.open("tmp/de421.bsp")
|
|
220
|
+
earth_to_moon = spk.position_at(target: 301, center: 399, tdb: 2451545.0)
|
|
221
|
+
|
|
222
|
+
# Project it into the body-fixed frame
|
|
156
223
|
body_fixed = Ephem::Core::Rotation.apply(matrix, earth_to_moon)
|
|
224
|
+
|
|
225
|
+
spk.close
|
|
157
226
|
```
|
|
158
227
|
|
|
159
228
|
`Ephem::Core::Rotation` also exposes the lower-level, kernel-agnostic building
|
|
@@ -161,6 +230,47 @@ blocks (`about_x`, `about_y`, `about_z`, `multiply`, `apply`) if you need a
|
|
|
161
230
|
different axis order or an additional fixed rotation (such as the PA -> ME
|
|
162
231
|
offset, whose constants the consumer supplies).
|
|
163
232
|
|
|
233
|
+
## Errors
|
|
234
|
+
|
|
235
|
+
Errors about kernels, coverage and downloads inherit from `Ephem::Error`, so
|
|
236
|
+
a single `rescue Ephem::Error` catches them. The most common ones are:
|
|
237
|
+
|
|
238
|
+
- `Ephem::OutOfRangeError`: a requested time is outside the kernel's
|
|
239
|
+
coverage. The message names the time, the pair or body and the covered
|
|
240
|
+
range, and `#out_of_range_times` returns every uncovered time as a Julian
|
|
241
|
+
Date:
|
|
242
|
+
|
|
243
|
+
```
|
|
244
|
+
JD 2400000.5 (1858-11-17) is outside the coverage of Solar System
|
|
245
|
+
Barycenter (0) -> Earth-Moon Barycenter (3), which covers
|
|
246
|
+
JD 2451536.5..2451920.5 (1999-12-24..2001-01-11)
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
- `Ephem::FileFormatError`: the file is not a valid kernel, is empty or
|
|
250
|
+
truncated, or is the wrong kind (an SPK passed to `Ephem::PCK.open`, or the
|
|
251
|
+
other way round).
|
|
252
|
+
- `Ephem::UnsupportedError`: the kernel uses a segment or data type the gem
|
|
253
|
+
does not implement.
|
|
254
|
+
- `Ephem::InvalidInputError`: a `Vector` or `Orientation` was given
|
|
255
|
+
non-numeric values, or a `Vector` was multiplied or divided by a
|
|
256
|
+
non-number.
|
|
257
|
+
- `Ephem::ClosedKernelError`: a kernel, or a segment taken from it, was
|
|
258
|
+
queried after the kernel was closed, including after the block given to
|
|
259
|
+
`SPK.open` or `PCK.open` returned.
|
|
260
|
+
- `Ephem::DownloadError`: `Ephem::Download` could not fetch a kernel. The
|
|
261
|
+
server answered with an error, the connection failed or timed out, or the
|
|
262
|
+
IMCCE archive is invalid or lacks the kernel. `#cause` holds the original
|
|
263
|
+
error when there is one.
|
|
264
|
+
|
|
265
|
+
Some errors are Ruby's own and are not `Ephem::Error`:
|
|
266
|
+
|
|
267
|
+
- `KeyError`: `SPK#[]` or `PCK#[]` was asked for a pair or body the kernel
|
|
268
|
+
does not contain.
|
|
269
|
+
- `IndexError`: `Vector#[]` or `Orientation#[]` was given an index other
|
|
270
|
+
than 0, 1 or 2.
|
|
271
|
+
- `Errno::ENOENT`, `Errno::EACCES` and other file system errors, which are
|
|
272
|
+
not wrapped.
|
|
273
|
+
|
|
164
274
|
## CLI
|
|
165
275
|
|
|
166
276
|
The gem also provides a CLI to generate an excerpt from an original kernel file.
|
|
@@ -169,6 +279,10 @@ The gem also provides a CLI to generate an excerpt from an original kernel file.
|
|
|
169
279
|
ruby-ephem excerpt [options] START_DATE END_DATE INPUT_FILE OUTPUT_FILE
|
|
170
280
|
```
|
|
171
281
|
|
|
282
|
+
`START_DATE` and `END_DATE` are read in the Gregorian calendar and converted
|
|
283
|
+
to the Julian Date at midnight of that day. Errors are written to stderr and
|
|
284
|
+
the command exits with a non-zero status.
|
|
285
|
+
|
|
172
286
|
For example, generate an excerpt from DE440s for the year 2025 only supporting
|
|
173
287
|
the Sun, the Earth, the Moon and the Earth-Moon Barycenter:
|
|
174
288
|
|
|
@@ -201,12 +315,13 @@ The following kernels have been used:
|
|
|
201
315
|
* DE430t
|
|
202
316
|
* DE440s
|
|
203
317
|
|
|
204
|
-
The times tested are noon
|
|
205
|
-
2050-01-01. Vectors tested are always with `center` 0
|
|
206
|
-
and `target` from `1` (Mercury Barycenter) to `10`
|
|
318
|
+
The times tested are integer Julian Dates in TDB (noon TDB) for every day
|
|
319
|
+
between 2000-01-01 and 2050-01-01. Vectors tested are always with `center` 0
|
|
320
|
+
(Solar System Barycenter), and `target` from `1` (Mercury Barycenter) to `10`
|
|
321
|
+
(Sun).
|
|
207
322
|
|
|
208
323
|
Rake tasks ensure data from this library match with `jplephem`. Positions match
|
|
209
|
-
exactly and velocities are within
|
|
324
|
+
exactly and velocities are within 2e-9 km/day (about 2e-11 m/s).
|
|
210
325
|
|
|
211
326
|
You can run them by following this pattern:
|
|
212
327
|
|
|
@@ -222,12 +337,47 @@ If you wish to test them all in parallel, you can run:
|
|
|
222
337
|
rake validate_accuracy:all
|
|
223
338
|
```
|
|
224
339
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
usage time.
|
|
340
|
+
`validate_accuracy:all` also runs the IMCCE `testpo` validation below. CI runs
|
|
341
|
+
it on every push to `main` and every pull request.
|
|
228
342
|
|
|
229
343
|
[jplephem]: https://pypi.org/project/jplephem/
|
|
230
344
|
|
|
345
|
+
### IMCCE testpo files
|
|
346
|
+
|
|
347
|
+
IMCCE publishes a `testpo` file with each INPOP release. Each row gives one
|
|
348
|
+
position or velocity component, in AU or AU/day, of a body relative to
|
|
349
|
+
another, computed by IMCCE from its own ephemeris files. Unlike `jplephem`, it
|
|
350
|
+
does not read the same kernel as this library, so it is an independent
|
|
351
|
+
reference.
|
|
352
|
+
|
|
353
|
+
INPOP21a is checked against the 18,263 rows of `testpo.INPOP21A_TDB` between
|
|
354
|
+
2000 and 2050. They cover pairs among the Sun, the planets, Pluto, the Moon,
|
|
355
|
+
the Earth, the Earth-Moon Barycenter and the Solar System Barycenter, so they
|
|
356
|
+
also exercise positions chained across several pairs. Every value matches
|
|
357
|
+
within 1e-13 AU or AU/day, the tolerance of JPL's `testeph`. The largest
|
|
358
|
+
differences are about 1e-14.
|
|
359
|
+
|
|
360
|
+
```
|
|
361
|
+
rake validate_accuracy:testpo
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
## YJIT
|
|
365
|
+
|
|
366
|
+
Run Ephem with [YJIT] enabled: computations are about 2 to 2.5 times faster.
|
|
367
|
+
|
|
368
|
+
| Benchmark | Interpreter | YJIT |
|
|
369
|
+
|-------------------------------------|-------------|---------|
|
|
370
|
+
| `compute` (Earth-Moon barycenter) | 2.7 µs | 1.1 µs |
|
|
371
|
+
| `compute_and_differentiate` (EMB) | 4.8 µs | 2.2 µs |
|
|
372
|
+
| `angles_at` (Moon PCK) | 2.3 µs | 0.96 µs |
|
|
373
|
+
|
|
374
|
+
Measured with `benchmarks/run.rb` on Ruby 4.0.5.
|
|
375
|
+
|
|
376
|
+
Enable it with `ruby --yjit`, `RUBY_YJIT_ENABLE=1`, or `RubyVM::YJIT.enable`
|
|
377
|
+
(for example in a Rails initializer).
|
|
378
|
+
|
|
379
|
+
[YJIT]: https://docs.ruby-lang.org/en/3.4/yjit/yjit_md.html
|
|
380
|
+
|
|
231
381
|
## Benchmarks
|
|
232
382
|
|
|
233
383
|
Run the benchmark suite to measure performance across the computation pipeline:
|
|
@@ -236,6 +386,12 @@ Run the benchmark suite to measure performance across the computation pipeline:
|
|
|
236
386
|
bundle exec ruby benchmarks/run.rb
|
|
237
387
|
```
|
|
238
388
|
|
|
389
|
+
Add `--yjit` to compare with [YJIT](#yjit) enabled:
|
|
390
|
+
|
|
391
|
+
```bash
|
|
392
|
+
bundle exec ruby --yjit benchmarks/run.rb
|
|
393
|
+
```
|
|
394
|
+
|
|
239
395
|
## Development
|
|
240
396
|
|
|
241
397
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
@@ -326,7 +482,7 @@ to the [code of conduct].
|
|
|
326
482
|
|
|
327
483
|
The gem is available as open source under the terms of the [MIT License].
|
|
328
484
|
|
|
329
|
-
[MIT License]:
|
|
485
|
+
[MIT License]: https://opensource.org/licenses/MIT
|
|
330
486
|
|
|
331
487
|
## Code of Conduct
|
|
332
488
|
|
|
@@ -334,4 +490,4 @@ Everyone interacting in the Ephem project's codebases, issue trackers, chat
|
|
|
334
490
|
rooms and mailing lists is expected to follow
|
|
335
491
|
the [code of conduct].
|
|
336
492
|
|
|
337
|
-
[code of conduct]:
|
|
493
|
+
[code of conduct]: https://github.com/rhannequin/ruby-ephem/blob/main/CODE_OF_CONDUCT.md
|