astronoby 0.5.0 → 0.7.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 (68) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -0
  3. data/.standard.yml +1 -0
  4. data/CHANGELOG.md +162 -0
  5. data/Gemfile.lock +54 -34
  6. data/README.md +42 -272
  7. data/UPGRADING.md +238 -0
  8. data/benchmark/README.md +131 -0
  9. data/benchmark/benchmark.rb +259 -0
  10. data/benchmark/data/imcce.csv.zip +0 -0
  11. data/benchmark/data/sun_calc.csv.zip +0 -0
  12. data/lib/astronoby/aberration.rb +56 -31
  13. data/lib/astronoby/angle.rb +20 -16
  14. data/lib/astronoby/angles/dms.rb +2 -2
  15. data/lib/astronoby/angles/hms.rb +2 -2
  16. data/lib/astronoby/bodies/earth.rb +56 -0
  17. data/lib/astronoby/bodies/jupiter.rb +11 -0
  18. data/lib/astronoby/bodies/mars.rb +11 -0
  19. data/lib/astronoby/bodies/mercury.rb +11 -0
  20. data/lib/astronoby/bodies/moon.rb +50 -285
  21. data/lib/astronoby/bodies/neptune.rb +11 -0
  22. data/lib/astronoby/bodies/saturn.rb +11 -0
  23. data/lib/astronoby/bodies/solar_system_body.rb +122 -0
  24. data/lib/astronoby/bodies/sun.rb +16 -220
  25. data/lib/astronoby/bodies/uranus.rb +11 -0
  26. data/lib/astronoby/bodies/venus.rb +11 -0
  27. data/lib/astronoby/constants.rb +13 -1
  28. data/lib/astronoby/coordinates/ecliptic.rb +2 -37
  29. data/lib/astronoby/coordinates/equatorial.rb +25 -7
  30. data/lib/astronoby/coordinates/horizontal.rb +0 -46
  31. data/lib/astronoby/corrections/light_time_delay.rb +90 -0
  32. data/lib/astronoby/deflection.rb +187 -0
  33. data/lib/astronoby/distance.rb +9 -0
  34. data/lib/astronoby/ephem.rb +39 -0
  35. data/lib/astronoby/equinox_solstice.rb +21 -18
  36. data/lib/astronoby/errors.rb +4 -0
  37. data/lib/astronoby/events/moon_phases.rb +2 -1
  38. data/lib/astronoby/events/rise_transit_set_calculator.rb +352 -0
  39. data/lib/astronoby/events/rise_transit_set_event.rb +13 -0
  40. data/lib/astronoby/events/rise_transit_set_events.rb +13 -0
  41. data/lib/astronoby/events/twilight_calculator.rb +166 -0
  42. data/lib/astronoby/events/twilight_event.rb +28 -0
  43. data/lib/astronoby/instant.rb +171 -0
  44. data/lib/astronoby/mean_obliquity.rb +23 -10
  45. data/lib/astronoby/nutation.rb +227 -42
  46. data/lib/astronoby/observer.rb +66 -1
  47. data/lib/astronoby/precession.rb +91 -17
  48. data/lib/astronoby/reference_frame.rb +49 -0
  49. data/lib/astronoby/reference_frames/apparent.rb +60 -0
  50. data/lib/astronoby/reference_frames/astrometric.rb +21 -0
  51. data/lib/astronoby/reference_frames/geometric.rb +20 -0
  52. data/lib/astronoby/reference_frames/mean_of_date.rb +38 -0
  53. data/lib/astronoby/reference_frames/topocentric.rb +82 -0
  54. data/lib/astronoby/time/greenwich_sidereal_time.rb +1 -1
  55. data/lib/astronoby/true_obliquity.rb +2 -1
  56. data/lib/astronoby/util/maths.rb +68 -49
  57. data/lib/astronoby/util/time.rb +466 -32
  58. data/lib/astronoby/vector.rb +36 -0
  59. data/lib/astronoby/velocity.rb +116 -0
  60. data/lib/astronoby/version.rb +1 -1
  61. data/lib/astronoby.rb +26 -5
  62. metadata +81 -18
  63. data/.tool-versions +0 -1
  64. data/lib/astronoby/astronomical_models/ephemeride_lunaire_parisienne.rb +0 -143
  65. data/lib/astronoby/events/observation_events.rb +0 -259
  66. data/lib/astronoby/events/rise_transit_set_iteration.rb +0 -215
  67. data/lib/astronoby/events/twilight_events.rb +0 -121
  68. data/lib/astronoby/util/astrodynamics.rb +0 -60
data/lib/astronoby.rb CHANGED
@@ -5,31 +5,52 @@ require "astronoby/angle"
5
5
  require "astronoby/angles/dms"
6
6
  require "astronoby/angles/hms"
7
7
  require "astronoby/distance"
8
+ require "astronoby/ephem"
8
9
  require "astronoby/epoch"
9
- require "astronoby/astronomical_models/ephemeride_lunaire_parisienne"
10
+ require "astronoby/instant"
11
+ require "astronoby/vector"
12
+ require "astronoby/velocity"
10
13
  require "astronoby/astronomical_models/moon_phases_periodic_terms"
14
+ require "astronoby/bodies/solar_system_body"
11
15
  require "astronoby/bodies/moon"
12
16
  require "astronoby/bodies/sun"
17
+ require "astronoby/bodies/mercury"
18
+ require "astronoby/bodies/venus"
19
+ require "astronoby/bodies/earth"
20
+ require "astronoby/bodies/mars"
21
+ require "astronoby/bodies/jupiter"
22
+ require "astronoby/bodies/saturn"
23
+ require "astronoby/bodies/uranus"
24
+ require "astronoby/bodies/neptune"
13
25
  require "astronoby/coordinates/ecliptic"
14
26
  require "astronoby/coordinates/equatorial"
15
27
  require "astronoby/coordinates/horizontal"
28
+ require "astronoby/corrections/light_time_delay"
16
29
  require "astronoby/aberration"
30
+ require "astronoby/deflection"
17
31
  require "astronoby/equinox_solstice"
18
32
  require "astronoby/errors"
19
33
  require "astronoby/events/moon_phases"
20
- require "astronoby/events/observation_events"
21
- require "astronoby/events/rise_transit_set_iteration"
22
- require "astronoby/events/twilight_events"
34
+ require "astronoby/events/rise_transit_set_event"
35
+ require "astronoby/events/rise_transit_set_events"
36
+ require "astronoby/events/rise_transit_set_calculator"
37
+ require "astronoby/events/twilight_event"
38
+ require "astronoby/events/twilight_calculator"
23
39
  require "astronoby/geocentric_parallax"
24
40
  require "astronoby/mean_obliquity"
25
41
  require "astronoby/moon_phase"
26
42
  require "astronoby/nutation"
27
43
  require "astronoby/observer"
28
44
  require "astronoby/precession"
45
+ require "astronoby/reference_frame"
46
+ require "astronoby/reference_frames/geometric"
47
+ require "astronoby/reference_frames/astrometric"
48
+ require "astronoby/reference_frames/mean_of_date"
49
+ require "astronoby/reference_frames/apparent"
50
+ require "astronoby/reference_frames/topocentric"
29
51
  require "astronoby/refraction"
30
52
  require "astronoby/time/greenwich_sidereal_time"
31
53
  require "astronoby/time/local_sidereal_time"
32
- require "astronoby/util/astrodynamics"
33
54
  require "astronoby/util/maths"
34
55
  require "astronoby/util/time"
35
56
  require "astronoby/util/trigonometry"
metadata CHANGED
@@ -1,15 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: astronoby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rémy Hannequin
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-06-11 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: ephem
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '0.3'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '0.3'
13
26
  - !ruby/object:Gem::Dependency
14
27
  name: matrix
15
28
  requirement: !ruby/object:Gem::Requirement
@@ -31,7 +44,7 @@ dependencies:
31
44
  - - "~>"
32
45
  - !ruby/object:Gem::Version
33
46
  version: '13.0'
34
- type: :runtime
47
+ type: :development
35
48
  prerelease: false
36
49
  version_requirements: !ruby/object:Gem::Requirement
37
50
  requirements:
@@ -45,13 +58,41 @@ dependencies:
45
58
  - - "~>"
46
59
  - !ruby/object:Gem::Version
47
60
  version: '3.0'
48
- type: :runtime
61
+ type: :development
49
62
  prerelease: false
50
63
  version_requirements: !ruby/object:Gem::Requirement
51
64
  requirements:
52
65
  - - "~>"
53
66
  - !ruby/object:Gem::Version
54
67
  version: '3.0'
68
+ - !ruby/object:Gem::Dependency
69
+ name: rubyzip
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '2.3'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '2.3'
82
+ - !ruby/object:Gem::Dependency
83
+ name: simplecov
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '0.22'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '0.22'
55
96
  - !ruby/object:Gem::Dependency
56
97
  name: standard
57
98
  requirement: !ruby/object:Gem::Requirement
@@ -66,17 +107,16 @@ dependencies:
66
107
  - - "~>"
67
108
  - !ruby/object:Gem::Version
68
109
  version: '1.3'
69
- description: Ruby version of the calculations from various books like Celestial Calculations
70
- by J. L. Lawrence, Practical Astronomy with your Calculator or Spreadsheet by Peter
71
- Duffett-Smith and Jonathan Zwart, or Astronomical Algorithms by Jean Meeus
110
+ description: Astronomy and astrometry Ruby library for astronomical data and events.
72
111
  email:
73
- - hello@rhannequ.in
112
+ - remy.hannequin@gmail.com
74
113
  executables: []
75
114
  extensions: []
76
115
  extra_rdoc_files: []
77
116
  files:
78
117
  - ".rspec"
79
- - ".tool-versions"
118
+ - ".ruby-version"
119
+ - ".standard.yml"
80
120
  - CHANGELOG.md
81
121
  - CODE_OF_CONDUCT.md
82
122
  - CONTRIBUTING.md
@@ -86,41 +126,66 @@ files:
86
126
  - README.md
87
127
  - Rakefile
88
128
  - UPGRADING.md
129
+ - benchmark/README.md
130
+ - benchmark/benchmark.rb
131
+ - benchmark/data/imcce.csv.zip
132
+ - benchmark/data/sun_calc.csv.zip
89
133
  - lib/astronoby.rb
90
134
  - lib/astronoby/aberration.rb
91
135
  - lib/astronoby/angle.rb
92
136
  - lib/astronoby/angles/dms.rb
93
137
  - lib/astronoby/angles/hms.rb
94
- - lib/astronoby/astronomical_models/ephemeride_lunaire_parisienne.rb
95
138
  - lib/astronoby/astronomical_models/moon_phases_periodic_terms.rb
139
+ - lib/astronoby/bodies/earth.rb
140
+ - lib/astronoby/bodies/jupiter.rb
141
+ - lib/astronoby/bodies/mars.rb
142
+ - lib/astronoby/bodies/mercury.rb
96
143
  - lib/astronoby/bodies/moon.rb
144
+ - lib/astronoby/bodies/neptune.rb
145
+ - lib/astronoby/bodies/saturn.rb
146
+ - lib/astronoby/bodies/solar_system_body.rb
97
147
  - lib/astronoby/bodies/sun.rb
148
+ - lib/astronoby/bodies/uranus.rb
149
+ - lib/astronoby/bodies/venus.rb
98
150
  - lib/astronoby/constants.rb
99
151
  - lib/astronoby/coordinates/ecliptic.rb
100
152
  - lib/astronoby/coordinates/equatorial.rb
101
153
  - lib/astronoby/coordinates/horizontal.rb
154
+ - lib/astronoby/corrections/light_time_delay.rb
155
+ - lib/astronoby/deflection.rb
102
156
  - lib/astronoby/distance.rb
157
+ - lib/astronoby/ephem.rb
103
158
  - lib/astronoby/epoch.rb
104
159
  - lib/astronoby/equinox_solstice.rb
105
160
  - lib/astronoby/errors.rb
106
161
  - lib/astronoby/events/moon_phases.rb
107
- - lib/astronoby/events/observation_events.rb
108
- - lib/astronoby/events/rise_transit_set_iteration.rb
109
- - lib/astronoby/events/twilight_events.rb
162
+ - lib/astronoby/events/rise_transit_set_calculator.rb
163
+ - lib/astronoby/events/rise_transit_set_event.rb
164
+ - lib/astronoby/events/rise_transit_set_events.rb
165
+ - lib/astronoby/events/twilight_calculator.rb
166
+ - lib/astronoby/events/twilight_event.rb
110
167
  - lib/astronoby/geocentric_parallax.rb
168
+ - lib/astronoby/instant.rb
111
169
  - lib/astronoby/mean_obliquity.rb
112
170
  - lib/astronoby/moon_phase.rb
113
171
  - lib/astronoby/nutation.rb
114
172
  - lib/astronoby/observer.rb
115
173
  - lib/astronoby/precession.rb
174
+ - lib/astronoby/reference_frame.rb
175
+ - lib/astronoby/reference_frames/apparent.rb
176
+ - lib/astronoby/reference_frames/astrometric.rb
177
+ - lib/astronoby/reference_frames/geometric.rb
178
+ - lib/astronoby/reference_frames/mean_of_date.rb
179
+ - lib/astronoby/reference_frames/topocentric.rb
116
180
  - lib/astronoby/refraction.rb
117
181
  - lib/astronoby/time/greenwich_sidereal_time.rb
118
182
  - lib/astronoby/time/local_sidereal_time.rb
119
183
  - lib/astronoby/true_obliquity.rb
120
- - lib/astronoby/util/astrodynamics.rb
121
184
  - lib/astronoby/util/maths.rb
122
185
  - lib/astronoby/util/time.rb
123
186
  - lib/astronoby/util/trigonometry.rb
187
+ - lib/astronoby/vector.rb
188
+ - lib/astronoby/velocity.rb
124
189
  - lib/astronoby/version.rb
125
190
  homepage: https://github.com/rhannequin/astronoby
126
191
  licenses:
@@ -129,7 +194,6 @@ metadata:
129
194
  homepage_uri: https://github.com/rhannequin/astronoby
130
195
  source_code_uri: https://github.com/rhannequin/astronoby
131
196
  changelog_uri: https://github.com/rhannequin/astronoby/blob/main/CHANGELOG.md
132
- post_install_message:
133
197
  rdoc_options: []
134
198
  require_paths:
135
199
  - lib
@@ -144,8 +208,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
208
  - !ruby/object:Gem::Version
145
209
  version: '0'
146
210
  requirements: []
147
- rubygems_version: 3.5.3
148
- signing_key:
211
+ rubygems_version: 3.6.7
149
212
  specification_version: 4
150
213
  summary: Astronomical calculations
151
214
  test_files: []
data/.tool-versions DELETED
@@ -1 +0,0 @@
1
- ruby 3.2.2
@@ -1,143 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Astronoby
4
- class EphemerideLunaireParisienne
5
- # Lunar theory: Éphéméride Lunaire Parisienne
6
- # By Jean Chapront, Michelle Chapront-Touzé
7
- # https://en.wikipedia.org/wiki/Ephemeride_Lunaire_Parisienne
8
-
9
- DEGREES_UNIT = 10**-6
10
-
11
- # @return [Array] Periodic terms for the Moon's longitude and distance
12
- def self.periodic_terms_for_moon_longitude_and_distance
13
- [
14
- [0, 0, 1, 0, 6288774, -20905355],
15
- [2, 0, -1, 0, 1274027, -3699111],
16
- [2, 0, 0, 0, 658314, -2955968],
17
- [0, 0, 2, 0, 213618, -569925],
18
- [0, 1, 0, 0, -185116, 48888],
19
- [0, 0, 0, 2, -114332, -3149],
20
- [2, 0, -2, 0, 58793, 246158],
21
- [2, -1, -1, 0, 57066, -152138],
22
- [2, 0, 1, 0, 53322, -170733],
23
- [2, -1, 0, 0, 45758, -204586],
24
- [0, 1, -1, 0, -40923, -129620],
25
- [1, 0, 0, 0, -34720, 108743],
26
- [0, 1, 1, 0, -30383, 104755],
27
- [2, 0, 0, -2, 15327, 10321],
28
- [0, 0, 1, 2, -12528, 0],
29
- [0, 0, 1, -2, 10980, 79661],
30
- [4, 0, -1, 0, 10675, -34782],
31
- [0, 0, 3, 0, 10034, -23210],
32
- [4, 0, -2, 0, 8548, -21636],
33
- [2, 1, -1, 0, -7888, 24208],
34
- [2, 1, 0, 0, -6766, 30824],
35
- [1, 0, -1, 0, -5163, -8379],
36
- [1, 1, 0, 0, 4987, -16675],
37
- [2, -1, 1, 0, 4036, -12831],
38
- [2, 0, 2, 0, 3994, -10445],
39
- [4, 0, 0, 0, 3861, -11650],
40
- [2, 0, -3, 0, 3665, 14403],
41
- [0, 1, -2, 0, -2689, -7003],
42
- [2, 0, -1, 2, -2602, 0],
43
- [2, -1, -2, 0, 2390, 10056],
44
- [1, 0, 1, 0, -2348, 6322],
45
- [2, -2, 0, 0, 2236, -9884],
46
- [0, 1, 2, 0, -2120, 5751],
47
- [0, 2, 0, 0, -2069, 0],
48
- [2, -2, -1, 0, 2048, -4950],
49
- [2, 0, 1, -2, -1773, 4130],
50
- [2, 0, 0, 2, -1595, 0],
51
- [4, -1, -1, 0, 1215, -3958],
52
- [0, 0, 2, 2, -1110, 0],
53
- [3, 0, -1, 0, -892, 3258],
54
- [2, 1, 1, 0, -810, 2616],
55
- [4, -1, -2, 0, 759, -1897],
56
- [0, 2, -1, 0, -713, -2117],
57
- [2, 2, -1, 0, -700, 2354],
58
- [2, 1, -2, 0, 691, 0],
59
- [2, -1, 0, -2, 596, 0],
60
- [4, 0, 1, 0, 549, -1423],
61
- [0, 0, 4, 0, 537, -1117],
62
- [4, -1, 0, 0, 520, -1571],
63
- [1, 0, -2, 0, -487, -1739],
64
- [2, 1, 0, -2, -399, 0],
65
- [0, 0, 2, -2, -381, -4421],
66
- [1, 1, 1, 0, 351, 0],
67
- [3, 0, -2, 0, -340, 0],
68
- [4, 0, -3, 0, 330, 0],
69
- [2, -1, 2, 0, 327, 0],
70
- [0, 2, 1, 0, -323, 1165],
71
- [1, 1, -1, 0, 299, 0],
72
- [2, 0, 3, 0, 294, 0],
73
- [2, 0, -1, -2, 0, 8752]
74
- ]
75
- end
76
-
77
- # @return [Array] Periodic terms for the Moon's latitude
78
- def self.periodic_terms_for_moon_latitude
79
- [
80
- [0, 0, 0, 1, 5128122],
81
- [0, 0, 1, 1, 280602],
82
- [0, 0, 1, -1, 277693],
83
- [2, 0, 0, -1, 173237],
84
- [2, 0, -1, 1, 55413],
85
- [2, 0, -1, -1, 46271],
86
- [2, 0, 0, 1, 32573],
87
- [0, 0, 2, 1, 17198],
88
- [2, 0, 1, -1, 9266],
89
- [0, 0, 2, -1, 8822],
90
- [2, -1, 0, -1, 8216],
91
- [2, 0, -2, -1, 4324],
92
- [2, 0, 1, 1, 4200],
93
- [2, 1, 0, -1, -3359],
94
- [2, -1, -1, 1, 2463],
95
- [2, -1, 0, 1, 2211],
96
- [2, -1, -1, -1, 2065],
97
- [0, 1, -1, -1, -1870],
98
- [4, 0, -1, -1, 1828],
99
- [0, 1, 0, 1, -1794],
100
- [0, 0, 0, 3, -1749],
101
- [0, 1, -1, 1, -1565],
102
- [1, 0, 0, 1, -1491],
103
- [0, 1, 1, 1, -1475],
104
- [0, 1, 1, -1, -1410],
105
- [0, 1, 0, -1, -1344],
106
- [1, 0, 0, -1, -1335],
107
- [0, 0, 3, 1, 1107],
108
- [4, 0, 0, -1, 1021],
109
- [4, 0, -1, 1, 833],
110
- [0, 0, 1, -3, 777],
111
- [4, 0, -2, 1, 671],
112
- [2, 0, 0, -3, 607],
113
- [2, 0, 2, -1, 596],
114
- [2, -1, 1, -1, 491],
115
- [2, 0, -2, 1, -451],
116
- [0, 0, 3, -1, 439],
117
- [2, 0, 2, 1, 422],
118
- [2, 0, -3, -1, 421],
119
- [2, 1, -1, 1, -366],
120
- [2, 1, 0, 1, -351],
121
- [4, 0, 0, 1, 331],
122
- [2, -1, 1, 1, 315],
123
- [2, -2, 0, -1, 302],
124
- [0, 0, 1, 3, -283],
125
- [2, 1, 1, -1, -229],
126
- [1, 1, 0, -1, 223],
127
- [1, 1, 0, 1, 223],
128
- [0, 1, -2, -1, -220],
129
- [2, 1, -1, -1, -220],
130
- [1, 0, 1, 1, -185],
131
- [2, -1, -2, -1, 181],
132
- [0, 1, 2, 1, -177],
133
- [4, 0, -2, -1, 176],
134
- [4, -1, -1, -1, 166],
135
- [1, 0, 1, -1, -164],
136
- [4, 0, 1, -1, 132],
137
- [1, 0, -1, -1, -119],
138
- [4, -1, 0, -1, 115],
139
- [2, -2, 0, 1, 107]
140
- ]
141
- end
142
- end
143
- end
@@ -1,259 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Astronoby
4
- module Events
5
- class ObservationEvents
6
- STANDARD_ALTITUDE = Angle.from_dms(0, -34, 0)
7
- RISING_SETTING_HOUR_ANGLE_RATIO_RANGE = (-1..1)
8
- EARTH_SIDEREAL_ROTATION_RATE = 360.98564736629
9
- ITERATION_PRECISION = 0.0001
10
-
11
- attr_reader :rising_time,
12
- :rising_azimuth,
13
- :transit_time,
14
- :transit_altitude,
15
- :setting_time,
16
- :setting_azimuth
17
-
18
- # Source:
19
- # Title: Astronomical Algorithms
20
- # Author: Jean Meeus
21
- # Edition: 2nd edition
22
- # Chapter: 15 - Rising, Transit, and Setting
23
-
24
- # @param observer [Astronoby::Observer] Observer
25
- # @param date [Date] Date of the event
26
- # @param coordinates_of_the_previous_day [Astronoby::Coordinates::Equatorial]
27
- # Coordinates of the body of the previous day
28
- # @param coordinates_of_the_day [Astronoby::Coordinates::Equatorial]
29
- # Coordinates of the body of the day
30
- # @param coordinates_of_the_next_day [Astronoby::Coordinates::Equatorial]
31
- # Coordinates of the body of the next day
32
- # @param additional_altitude [Astronoby::Angle] Additional altitude to the
33
- # standard altitude adjustment
34
- def initialize(
35
- observer:,
36
- date:,
37
- coordinates_of_the_previous_day:,
38
- coordinates_of_the_day:,
39
- coordinates_of_the_next_day:,
40
- additional_altitude: Angle.zero
41
- )
42
- @observer = observer
43
- @date = date
44
- @coordinates_of_the_previous_day = coordinates_of_the_previous_day
45
- @coordinates_of_the_day = coordinates_of_the_day
46
- @coordinates_of_the_next_day = coordinates_of_the_next_day
47
- @standard_altitude = STANDARD_ALTITUDE
48
- @additional_altitude = additional_altitude
49
- compute
50
- end
51
-
52
- private
53
-
54
- def compute
55
- @initial_transit = initial_transit
56
- @transit_time = Util::Time.decimal_hour_to_time(@date, @initial_transit)
57
- @transit_altitude = local_horizontal_altitude_transit
58
-
59
- return if h0.nil?
60
-
61
- initial_rising = rationalize_decimal_time(
62
- @initial_transit - h0.degrees / Constants::DEGREES_PER_CIRCLE
63
- )
64
-
65
- initial_setting = rationalize_decimal_time(
66
- @initial_transit + h0.degrees / Constants::DEGREES_PER_CIRCLE
67
- )
68
-
69
- @final_rising, @final_transit, @final_setting =
70
- iterate(initial_rising, @initial_transit, initial_setting)
71
-
72
- rationalized_corrected_rising = rationalize_decimal_hours(
73
- Constants::HOURS_PER_DAY * @final_rising
74
- )
75
- rationalized_corrected_transit = rationalize_decimal_hours(
76
- Constants::HOURS_PER_DAY * @final_transit
77
- )
78
- rationalized_corrected_setting = rationalize_decimal_hours(
79
- Constants::HOURS_PER_DAY * @final_setting
80
- )
81
-
82
- @rising_time = Util::Time.decimal_hour_to_time(@date, rationalized_corrected_rising)
83
- @rising_azimuth = local_horizontal_azimuth_rising
84
- @transit_time = Util::Time.decimal_hour_to_time(@date, rationalized_corrected_transit)
85
- @transit_altitude = local_horizontal_altitude_transit
86
- @setting_time = Util::Time.decimal_hour_to_time(@date, rationalized_corrected_setting)
87
- @setting_azimuth = local_horizontal_azimuth_setting
88
- end
89
-
90
- def iterate(initial_rising, initial_transit, initial_setting)
91
- delta = 1
92
- corrected_rising = initial_rising
93
- corrected_transit = initial_transit
94
- corrected_setting = initial_setting
95
- until delta < ITERATION_PRECISION
96
- iterate = RiseTransitSetIteration.new(
97
- observer: @observer,
98
- date: @date,
99
- coordinates_of_the_next_day: @coordinates_of_the_next_day,
100
- coordinates_of_the_day: @coordinates_of_the_day,
101
- coordinates_of_the_previous_day: @coordinates_of_the_previous_day,
102
- shift: shift,
103
- initial_rising: corrected_rising,
104
- initial_transit: corrected_transit,
105
- initial_setting: corrected_setting
106
- ).iterate
107
- delta = iterate.sum
108
- corrected_rising = rationalize_decimal_time corrected_rising + iterate[0]
109
- corrected_transit = rationalize_decimal_time corrected_transit + iterate[1]
110
- corrected_setting = rationalize_decimal_time corrected_setting + iterate[2]
111
- end
112
- [corrected_rising, corrected_transit, corrected_setting]
113
- end
114
-
115
- def observer_longitude
116
- # Longitude must be treated positively westwards from the meridian of
117
- # Greenwich, and negatively to the east
118
- -@observer.longitude
119
- end
120
-
121
- def initial_transit
122
- rationalize_decimal_time(
123
- (
124
- @coordinates_of_the_day.right_ascension.degrees +
125
- observer_longitude.degrees -
126
- apparent_gst_at_midnight.degrees
127
- ) / Constants::DEGREES_PER_CIRCLE
128
- )
129
- end
130
-
131
- def h0
132
- @h0 ||= begin
133
- term1 = shift.sin -
134
- @observer.latitude.sin * @coordinates_of_the_day.declination.sin
135
- term2 = @observer.latitude.cos * @coordinates_of_the_day.declination.cos
136
- ratio = term1 / term2
137
- return nil unless RISING_SETTING_HOUR_ANGLE_RATIO_RANGE.cover?(ratio)
138
-
139
- Angle.acos(ratio)
140
- end
141
- end
142
-
143
- def apparent_gst_at_midnight
144
- Angle.from_hours(
145
- GreenwichSiderealTime.from_utc(
146
- Time.utc(@date.year, @date.month, @date.day)
147
- ).time
148
- )
149
- end
150
-
151
- def gst_transit
152
- Angle.from_degrees(
153
- apparent_gst_at_midnight.degrees +
154
- EARTH_SIDEREAL_ROTATION_RATE * (@final_transit || @initial_transit)
155
- )
156
- end
157
-
158
- def leap_day_portion
159
- leap_seconds = Util::Time.terrestrial_universal_time_delta(@date)
160
- leap_seconds / Constants::SECONDS_PER_DAY
161
- end
162
-
163
- def local_hour_angle_transit
164
- gst_transit - observer_longitude - right_ascension_transit
165
- end
166
-
167
- def local_horizontal_azimuth_rising
168
- term1 = declination_rising.sin + (-shift).sin * @observer.latitude.cos
169
- term2 = (-shift).cos * @observer.latitude.cos
170
- angle = term1 / term2
171
- Angle.acos(angle)
172
- end
173
-
174
- def local_horizontal_altitude_transit
175
- Angle.asin(
176
- @observer.latitude.sin * declination_transit.sin +
177
- @observer.latitude.cos * declination_transit.cos * local_hour_angle_transit.cos
178
- )
179
- end
180
-
181
- def local_horizontal_azimuth_setting
182
- term1 = declination_setting.sin + (-shift).sin * @observer.latitude.cos
183
- term2 = (-shift).cos * @observer.latitude.cos
184
- angle = term1 / term2
185
- Angle.from_degrees(
186
- Constants::DEGREES_PER_CIRCLE - Angle.acos(angle).degrees
187
- )
188
- end
189
-
190
- def rationalize_decimal_time(decimal_time)
191
- decimal_time += 1 if decimal_time.negative?
192
- decimal_time -= 1 if decimal_time > 1
193
- decimal_time
194
- end
195
-
196
- def rationalize_decimal_hours(decimal_hours)
197
- decimal_hours += Constants::HOURS_PER_DAY if decimal_hours.negative?
198
- decimal_hours -= Constants::HOURS_PER_DAY if decimal_hours > Constants::HOURS_PER_DAY
199
- decimal_hours
200
- end
201
-
202
- def right_ascension_transit
203
- Angle.from_degrees(
204
- Util::Maths.interpolate(
205
- [
206
- @coordinates_of_the_previous_day.right_ascension.degrees,
207
- @coordinates_of_the_day.right_ascension.degrees,
208
- @coordinates_of_the_next_day.right_ascension.degrees
209
- ],
210
- (@final_transit || @initial_transit) + leap_day_portion
211
- )
212
- )
213
- end
214
-
215
- def declination_rising
216
- Angle.from_degrees(
217
- Util::Maths.interpolate(
218
- [
219
- @coordinates_of_the_previous_day.declination.degrees,
220
- @coordinates_of_the_day.declination.degrees,
221
- @coordinates_of_the_next_day.declination.degrees
222
- ],
223
- @final_rising + leap_day_portion
224
- )
225
- )
226
- end
227
-
228
- def declination_transit
229
- Angle.from_degrees(
230
- Util::Maths.interpolate(
231
- [
232
- @coordinates_of_the_previous_day.declination.degrees,
233
- @coordinates_of_the_day.declination.degrees,
234
- @coordinates_of_the_next_day.declination.degrees
235
- ],
236
- (@final_transit || @initial_transit) + leap_day_portion
237
- )
238
- )
239
- end
240
-
241
- def declination_setting
242
- Angle.from_degrees(
243
- Util::Maths.interpolate(
244
- [
245
- @coordinates_of_the_previous_day.declination.degrees,
246
- @coordinates_of_the_day.declination.degrees,
247
- @coordinates_of_the_next_day.declination.degrees
248
- ],
249
- @final_setting + leap_day_portion
250
- )
251
- )
252
- end
253
-
254
- def shift
255
- @standard_altitude - @additional_altitude
256
- end
257
- end
258
- end
259
- end