lunation 0.1.5 → 0.1.6

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.
@@ -5,11 +5,11 @@ module Lunation
5
5
  NUTATION_IN_OBLIQUITY_PERIODIC_TERMS_PATH = File.expand_path("../../../config/periodic_terms_earth_nutation.yml", __dir__)
6
6
  NUTATION_IN_OBLIQUITY_PERIODIC_TERMS = YAML.load_file(NUTATION_IN_OBLIQUITY_PERIODIC_TERMS_PATH).freeze
7
7
  ECLIPTIC_MEAN_OBLIQUITY_CONSTANTS = [21.448, -4680.93, -1.55, 1_999.25, -51.38, -249.67, -39.05, 7.12, 27.87, 5.79, 2.45].freeze
8
- MOON_MEAN_ELONGATION_FROM_SUN_CONSTANTS = [297.85036, 445_267.111480, -0.0019142, 1 / 189_474.0].freeze
9
- SUN_MEAN_ANOMALY_CONSTANTS = [357.52772, 35_999.050340, -0.0001603, -1 / 300_000.0].freeze
10
- MOON_MEAN_ANOMALY_CONSTANTS = [134.96298, 477_198.867398, 0.0086972, 1 / 56_250.0].freeze
11
- MOON_ARGUMENT_OF_LATITUDE_CONSTANTS = [93.27191, 483_202.017538, -0.0036825, 1 / 327_270.0].freeze
12
- LONGITUDE_OF_THE_ASCENDING_NODE_CONSTANTS = [125.04452, -1934.136261, 0.0020708, 1 / 450_000.0].freeze
8
+ MOON_MEAN_ELONGATION_FROM_SUN_CONSTANTS = [297.85036, 445_267.111480, -0.0019142, 1.fdiv(189_474)].freeze
9
+ SUN_MEAN_ANOMALY_CONSTANTS = [357.52772, 35_999.050340, -0.0001603, -1.fdiv(300_000)].freeze
10
+ MOON_MEAN_ANOMALY_CONSTANTS = [134.96298, 477_198.867398, 0.0086972, 1.fdiv(56_250)].freeze
11
+ MOON_ARGUMENT_OF_LATITUDE_CONSTANTS = [93.27191, 483_202.017538, -0.0036825, 1.fdiv(327_270)].freeze
12
+ LONGITUDE_OF_THE_ASCENDING_NODE_CONSTANTS = [125.04452, -1934.136261, 0.0020708, 1.fdiv(450_000)].freeze
13
13
  # rubocop:enable Layout/LineLength
14
14
 
15
15
  # (D) Mean elongation of the moon from the sun (A.A. p. 144)
@@ -64,13 +64,13 @@ module Lunation
64
64
  @nutation_in_longitude ||= begin
65
65
  result = NUTATION_IN_OBLIQUITY_PERIODIC_TERMS.inject(0.0) do |acc, elem|
66
66
  argument = Angle.from_decimal_degrees(
67
- elem["moon_mean_elongation"] * moon_mean_elongation_from_sun.decimal_degrees +
68
- elem["sun_mean_anomaly"] * sun_mean_anomaly.decimal_degrees +
69
- elem["moon_mean_anomaly"] * moon_mean_anomaly.decimal_degrees +
70
- elem["moon_argument_of_latitude"] * moon_argument_of_latitude.decimal_degrees +
71
- elem["longitude_of_ascending_node"] * longitude_of_ascending_node.decimal_degrees
67
+ elem[0] * moon_mean_elongation_from_sun.decimal_degrees +
68
+ elem[1] * sun_mean_anomaly.decimal_degrees +
69
+ elem[2] * moon_mean_anomaly.decimal_degrees +
70
+ elem[3] * moon_argument_of_latitude.decimal_degrees +
71
+ elem[4] * longitude_of_ascending_node.decimal_degrees
72
72
  )
73
- coefficient = elem["sine_coefficient_first_term"] + elem["sine_coefficient_second_term"] * time
73
+ coefficient = elem[5] + elem[6] * time
74
74
  acc + coefficient * argument.sin
75
75
  end / 10_000.0
76
76
  Angle.from_decimal_arcseconds(result)
@@ -83,13 +83,13 @@ module Lunation
83
83
  @nutation_in_obliquity ||= begin
84
84
  result = NUTATION_IN_OBLIQUITY_PERIODIC_TERMS.inject(0.0) do |acc, elem|
85
85
  argument = Angle.from_decimal_degrees(
86
- elem["moon_mean_elongation"] * moon_mean_elongation_from_sun.decimal_degrees +
87
- elem["sun_mean_anomaly"] * sun_mean_anomaly.decimal_degrees +
88
- elem["moon_mean_anomaly"] * moon_mean_anomaly.decimal_degrees +
89
- elem["moon_argument_of_latitude"] * moon_argument_of_latitude.decimal_degrees +
90
- elem["longitude_of_ascending_node"] * longitude_of_ascending_node.decimal_degrees
86
+ elem[0] * moon_mean_elongation_from_sun.decimal_degrees +
87
+ elem[1] * sun_mean_anomaly.decimal_degrees +
88
+ elem[2] * moon_mean_anomaly.decimal_degrees +
89
+ elem[3] * moon_argument_of_latitude.decimal_degrees +
90
+ elem[4] * longitude_of_ascending_node.decimal_degrees
91
91
  )
92
- coefficient = elem["cosine_coefficient_first_term"] + elem["cosine_coefficient_second_term"] * time
92
+ coefficient = elem[7] + elem[8] * time
93
93
  acc + coefficient * argument.cos
94
94
  end / 10_000.0
95
95
  Angle.from_decimal_arcseconds(result)
@@ -58,7 +58,10 @@ module Lunation
58
58
  # UNIT: Astronomical Units (AU)
59
59
  def distance_between_earth_and_sun_in_astronomical_units
60
60
  @distance_between_earth_and_sun_in_astronomical_units ||= begin
61
- result = 1.000001018 * (1 - earth_orbit_eccentricity**2) / (1 + earth_orbit_eccentricity * sun_anomaly.cos)
61
+ result = 1.000001018 *
62
+ (1 - earth_orbit_eccentricity**2) / (
63
+ (1 + earth_orbit_eccentricity * sun_anomaly.cos)
64
+ )
62
65
  result.round(7)
63
66
  end
64
67
  end
@@ -70,8 +73,8 @@ module Lunation
70
73
  (distance_between_earth_and_sun_in_astronomical_units * 149_597_870).floor
71
74
  end
72
75
 
73
- # (Ω) Longitude of the ascending node of the Moon's mean orbit on the ecliptic (low precision)
74
- # A.A. p. 164
76
+ # (Ω) Longitude of the ascending node of the Moon's mean orbit on the ecliptic
77
+ # (low precision) A.A. p. 164
75
78
  # UNIT: Angle
76
79
  def longitude_of_ascending_node_low_precision
77
80
  @longitude_of_ascending_node_low_precision ||=
@@ -7,14 +7,14 @@ module Lunation
7
7
  # rubocop:disable Layout/LineLength
8
8
  DELTA_T_500BC_500AD = [10_583.6, -1_014.41, 33.78311, -5.952053, -0.1798452, 0.022174192, 0.0090316521].freeze
9
9
  DELTA_T_500AD_1600AD = [1_574.2, -556.01, 71.23472, 0.319781, -0.8503463, -0.005050998, 0.0083572073].freeze
10
- DELTA_T_1600AD_1700AD = [120, -0.9808, -0.01532, 1 / 7_129.0].freeze
11
- DELTA_T_1700AD_1800AD = [8.83, 0.1603, -0.0059285, 0.00013336, -1 / 1_174_000.0].freeze
10
+ DELTA_T_1600AD_1700AD = [120, -0.9808, -0.01532, 1.fdiv(7_129)].freeze
11
+ DELTA_T_1700AD_1800AD = [8.83, 0.1603, -0.0059285, 0.00013336, -1.fdiv(1_174_000)].freeze
12
12
  DELTA_T_1800AD_1860AD = [13.72, -0.332447, 0.0068612, 0.0041116, -0.00037436, 0.0000121272, -0.0000001699, 0.000000000875].freeze
13
- DELTA_T_1860AD_1900AD = [7.62, 0.5737, -0.251754, 0.01680668, -0.0004473624, 1 / 233_174.0].freeze
13
+ DELTA_T_1860AD_1900AD = [7.62, 0.5737, -0.251754, 0.01680668, -0.0004473624, 1.fdiv(233_174)].freeze
14
14
  DELTA_T_1900AD_1920AD = [-2.79, 1.494119, -0.0598939, 0.0061966, -0.000197].freeze
15
15
  DELTA_T_1920AD_1941AD = [21.20, 0.84493, -0.076100, 0.0020936].freeze
16
- DELTA_T_1941AD_1961AD = [29.07, 0.407, -1 / 233.0, 1 / 2_547.0].freeze
17
- DELTA_T_1961AD_1986AD = [45.45, 1.067, -1 / 260.0, -1 / 718.0].freeze
16
+ DELTA_T_1941AD_1961AD = [29.07, 0.407, -1.fdiv(233), 1.fdiv(2_547)].freeze
17
+ DELTA_T_1961AD_1986AD = [45.45, 1.067, -1.fdiv(260), -1.fdiv(718)].freeze
18
18
  DELTA_T_1986AD_2005AD = [63.86, 0.3345, -0.060374, 0.0017275, 0.000651814, 0.00002373599].freeze
19
19
  DELTA_T_2005AD_2050AD = [62.92, 0.32217, 0.005589].freeze
20
20
  # rubocop:enable Layout/LineLength
@@ -23,7 +23,7 @@ module Lunation
23
23
  # UNIT: centuries from the Epoch J2000.0
24
24
  def time
25
25
  @time ||=
26
- ((julian_ephemeris_day - EPOCH_J2000_JDE) / JULIAN_CENTURY_IN_DAYS).round(12)
26
+ (julian_ephemeris_day - EPOCH_J2000_JDE).fdiv(JULIAN_CENTURY_IN_DAYS).round(12)
27
27
  end
28
28
 
29
29
  # ΔT Difference between Dynamical Time (TD) and Universal Time (UT, more commonly
@@ -36,12 +36,12 @@ module Lunation
36
36
  @delta_t ||= begin
37
37
  result = case datetime.year
38
38
  when -1_999...-500
39
- elapsed_years = (@decimal_year - 1_820) / 100
39
+ elapsed_years = (@decimal_year - 1_820).fdiv(100)
40
40
  -20 + 32 * elapsed_years**2
41
41
  when -500...500
42
- Horner.compute(@decimal_year / 100.0, DELTA_T_500BC_500AD)
42
+ Horner.compute(@decimal_year.fdiv(100), DELTA_T_500BC_500AD)
43
43
  when 500...1_600
44
- Horner.compute((@decimal_year - 1_000.0) / 100.0, DELTA_T_500AD_1600AD)
44
+ Horner.compute((@decimal_year - 1_000.0).fdiv(100), DELTA_T_500AD_1600AD)
45
45
  when 1_600...1_700
46
46
  Horner.compute(@decimal_year - 1_600.0, DELTA_T_1600AD_1700AD)
47
47
  when 1_700...1_800
@@ -63,7 +63,8 @@ module Lunation
63
63
  when 2_005...2_050
64
64
  Horner.compute(@decimal_year - 2_000, DELTA_T_2005AD_2050AD)
65
65
  when 2_050...2_150
66
- -20 + 32 * ((@decimal_year - 1_820) / 100)**2 - 0.5628 * (2_150 - @decimal_year)
66
+ -20 + 32 * ((@decimal_year - 1_820) / 100)**2 - 0.5628 *
67
+ (2_150 - @decimal_year)
67
68
  when 2_150..3_000
68
69
  -20 + 32 * @decimal_year**2
69
70
  end
@@ -74,7 +75,7 @@ module Lunation
74
75
  # (TD) Dynamical time (A.A. p. 77)
75
76
  # UNIT: ISO 8601 Date and time with offset
76
77
  def dynamical_time
77
- @dynamical_time ||= datetime + delta_t.round.to_f / SECONDS_PER_DAY
78
+ @dynamical_time ||= datetime + delta_t.round.fdiv(SECONDS_PER_DAY)
78
79
  end
79
80
 
80
81
  # (JDE) Julian ephemeris day (A.A. p. 59)
@@ -86,13 +87,13 @@ module Lunation
86
87
  # (t) time, measured in Julian millennia from the epoch J2000.0 (32.1, A.A. p. 218)
87
88
  # UNIT: millennia from the Epoch J2000.0
88
89
  def time_millennia
89
- @time_millennia ||= (time / 10.0).round(12)
90
+ @time_millennia ||= time.fdiv(10).round(12)
90
91
  end
91
92
 
92
93
  # (U) Time measured in units of 10_000 Julian years from J2000.0 (A.A. p. 147)
93
94
  # UNIT: 10_000 years (myriads) from the Epoch J2000.0
94
95
  def time_myriads
95
- @time_myriads ||= time / 100.0
96
+ @time_myriads ||= time.fdiv(100)
96
97
  end
97
98
  end
98
99
  end
@@ -25,11 +25,14 @@ module Lunation
25
25
 
26
26
  def to_h
27
27
  {
28
+ # rubocop:disable Layout/LineLength
28
29
  corrected_obliquity_of_ecliptic: corrected_obliquity_of_ecliptic,
29
30
  correction_eccentricity_of_earth: correction_eccentricity_of_earth,
30
31
  correction_jupiter: correction_jupiter,
31
32
  correction_latitude: correction_latitude,
32
33
  correction_venus: correction_venus,
34
+ datetime: datetime,
35
+ decimal_year: decimal_year,
33
36
  delta_t: delta_t,
34
37
  distance_between_earth_and_moon: distance_between_earth_and_moon,
35
38
  distance_between_earth_and_sun_in_astronomical_units: distance_between_earth_and_sun_in_astronomical_units,
@@ -78,11 +81,12 @@ module Lunation
78
81
  time_millennia: time_millennia,
79
82
  time_myriads: time_myriads,
80
83
  time: time,
84
+ # rubocop:enable Layout/LineLength
81
85
  }
82
86
  end
83
87
 
84
88
  def to_s
85
- <<-HEREDOC
89
+ <<~HEREDOC
86
90
  DATE AND TIME (UT): #{datetime}
87
91
  ----------------------------------------------------------------------------------
88
92
  DECIMAL YEAR: #{decimal_year}
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lunation
4
- VERSION = "0.1.5"
4
+ VERSION = "0.1.6"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lunation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivo Kalverboer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-12-30 00:00:00.000000000 Z
11
+ date: 2024-12-31 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Lunation offers a Ruby implementation of Meeus's Astronomical Algorithms.
14
14
  email:
@@ -59,7 +59,7 @@ licenses:
59
59
  metadata:
60
60
  homepage_uri: https://www.github.com/valerius/lunation
61
61
  source_code_uri: https://www.github.com/valerius/lunation
62
- changelog_uri: https://www.github.com/valerius/lunation/CHANGELOG.md
62
+ changelog_uri: https://github.com/valerius/lunation/blob/main/CHANGELOG.md
63
63
  post_install_message:
64
64
  rdoc_options: []
65
65
  require_paths: