astronoby 0.7.0 → 0.9.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 (87) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/CHANGELOG.md +145 -3
  4. data/README.md +59 -33
  5. data/UPGRADING.md +75 -21
  6. data/docs/README.md +224 -0
  7. data/docs/angles.md +137 -0
  8. data/docs/configuration.md +98 -0
  9. data/docs/coordinates.md +167 -0
  10. data/docs/deep_sky_bodies.md +101 -0
  11. data/docs/ephem.md +85 -0
  12. data/docs/equinoxes_solstices_times.md +31 -0
  13. data/docs/glossary.md +152 -0
  14. data/docs/instant.md +139 -0
  15. data/docs/moon_phases.md +79 -0
  16. data/docs/observer.md +65 -0
  17. data/docs/reference_frames.md +138 -0
  18. data/docs/rise_transit_set_times.md +119 -0
  19. data/docs/solar_system_bodies.md +107 -0
  20. data/docs/twilight_times.md +123 -0
  21. data/lib/astronoby/angle.rb +6 -2
  22. data/lib/astronoby/angular_velocity.rb +76 -0
  23. data/lib/astronoby/bodies/deep_sky_object.rb +44 -0
  24. data/lib/astronoby/bodies/deep_sky_object_position.rb +127 -0
  25. data/lib/astronoby/bodies/earth.rb +12 -2
  26. data/lib/astronoby/bodies/jupiter.rb +17 -0
  27. data/lib/astronoby/bodies/mars.rb +17 -0
  28. data/lib/astronoby/bodies/mercury.rb +21 -0
  29. data/lib/astronoby/bodies/moon.rb +50 -36
  30. data/lib/astronoby/bodies/neptune.rb +21 -0
  31. data/lib/astronoby/bodies/saturn.rb +26 -0
  32. data/lib/astronoby/bodies/solar_system_body.rb +162 -27
  33. data/lib/astronoby/bodies/sun.rb +25 -2
  34. data/lib/astronoby/bodies/uranus.rb +5 -0
  35. data/lib/astronoby/bodies/venus.rb +25 -0
  36. data/lib/astronoby/cache.rb +189 -0
  37. data/lib/astronoby/configuration.rb +92 -0
  38. data/lib/astronoby/constants.rb +11 -3
  39. data/lib/astronoby/constellation.rb +12 -0
  40. data/lib/astronoby/constellations/data.rb +42 -0
  41. data/lib/astronoby/constellations/finder.rb +35 -0
  42. data/lib/astronoby/constellations/repository.rb +20 -0
  43. data/lib/astronoby/coordinates/equatorial.rb +5 -8
  44. data/lib/astronoby/data/constellations/constellation_names.dat +88 -0
  45. data/lib/astronoby/data/constellations/indexed_abbreviations.dat +88 -0
  46. data/lib/astronoby/data/constellations/radec_to_index.dat +238 -0
  47. data/lib/astronoby/data/constellations/sorted_declinations.dat +202 -0
  48. data/lib/astronoby/data/constellations/sorted_right_ascensions.dat +237 -0
  49. data/lib/astronoby/distance.rb +6 -0
  50. data/lib/astronoby/equinox_solstice.rb +2 -2
  51. data/lib/astronoby/events/extremum_calculator.rb +233 -0
  52. data/lib/astronoby/events/extremum_event.rb +15 -0
  53. data/lib/astronoby/events/moon_phases.rb +15 -14
  54. data/lib/astronoby/events/rise_transit_set_calculator.rb +39 -12
  55. data/lib/astronoby/events/twilight_calculator.rb +116 -61
  56. data/lib/astronoby/events/twilight_events.rb +28 -0
  57. data/lib/astronoby/instant.rb +34 -6
  58. data/lib/astronoby/julian_date.rb +78 -0
  59. data/lib/astronoby/mean_obliquity.rb +8 -10
  60. data/lib/astronoby/nutation.rb +11 -3
  61. data/lib/astronoby/observer.rb +1 -1
  62. data/lib/astronoby/precession.rb +48 -38
  63. data/lib/astronoby/reference_frame.rb +2 -1
  64. data/lib/astronoby/reference_frames/apparent.rb +1 -11
  65. data/lib/astronoby/reference_frames/mean_of_date.rb +1 -1
  66. data/lib/astronoby/reference_frames/topocentric.rb +2 -12
  67. data/lib/astronoby/stellar_propagation.rb +162 -0
  68. data/lib/astronoby/time/greenwich_apparent_sidereal_time.rb +22 -0
  69. data/lib/astronoby/time/greenwich_mean_sidereal_time.rb +64 -0
  70. data/lib/astronoby/time/greenwich_sidereal_time.rb +20 -58
  71. data/lib/astronoby/time/local_apparent_sidereal_time.rb +42 -0
  72. data/lib/astronoby/time/local_mean_sidereal_time.rb +42 -0
  73. data/lib/astronoby/time/local_sidereal_time.rb +35 -26
  74. data/lib/astronoby/time/sidereal_time.rb +42 -0
  75. data/lib/astronoby/true_obliquity.rb +2 -3
  76. data/lib/astronoby/util/time.rb +62 -44
  77. data/lib/astronoby/velocity.rb +5 -0
  78. data/lib/astronoby/version.rb +1 -1
  79. data/lib/astronoby.rb +19 -1
  80. metadata +71 -11
  81. data/Gemfile +0 -5
  82. data/Gemfile.lock +0 -102
  83. data/benchmark/README.md +0 -131
  84. data/benchmark/benchmark.rb +0 -259
  85. data/benchmark/data/imcce.csv.zip +0 -0
  86. data/benchmark/data/sun_calc.csv.zip +0 -0
  87. data/lib/astronoby/epoch.rb +0 -22
@@ -0,0 +1,101 @@
1
+ # Deep-sky Bodies
2
+
3
+ Deep-sky objects represent celestial object that are not part of the Solar
4
+ System, like stars, nebulae, clusters, galaxies. They are not affected by any
5
+ body of the Solar System.
6
+
7
+ Because we know billions of there objects, it is impossible for Astronoby to
8
+ store a comprehensive catalogue. Therefore, it is up to the developer to build
9
+ the object they need, based on equatorial coordinates from official catalogues
10
+ at J2000 epoch. The [SIMBAD Astronomical Database] is an example of database
11
+ where such coordinates can be found.
12
+
13
+ Astronoby makes the difference between the body and the position.
14
+ `Astronoby::DeepSkyObject` represent the body in itself, defined by fixed
15
+ coordinates. It can also be support proper motion parameters, also given from
16
+ official catalogues, which provides a bit more precision.
17
+
18
+ ```rb
19
+ vega_j2000 = Astronoby::Coordinates::Equatorial.new(
20
+ right_ascension: Astronoby::Angle.from_hms(18, 36, 56.33635),
21
+ declination: Astronoby::Angle.from_dms(38, 47, 1.2802),
22
+ epoch: Astronoby::JulianDate::J2000
23
+ )
24
+
25
+ vega = Astronoby::DeepSkyObject.new(equatorial_coordinates: vega_j2000)
26
+
27
+ vega_with_proper_motion = Astronoby::DeepSkyObject.new(
28
+ equatorial_coordinates: vega_j2000,
29
+ proper_motion_ra: Astronoby::AngularVelocity
30
+ .from_milliarcseconds_per_year(200.94),
31
+ proper_motion_dec: Astronoby::AngularVelocity
32
+ .from_milliarcseconds_per_year(286.23),
33
+ parallax: Astronoby::Angle.from_degree_arcseconds(130.23 / 1000.0),
34
+ radial_velocity: Astronoby::Velocity.from_kilometers_per_second(-13.5)
35
+ )
36
+ ```
37
+
38
+ From a `DeepSkyObject` instance, it is possible to instantiate the position
39
+ of the body at a given instant. If given the optional `ephem` parameter,
40
+ precision will increase as some astronomical corrections will be
41
+ applied.
42
+
43
+ A `DeepSkyPosition` object exposes `astrometric`, `apparent` and `topocentric`
44
+ reference frames.
45
+
46
+ ```rb
47
+ time = Time.utc(2025, 10, 1)
48
+ instant = Astronoby::Instant.from_time(time)
49
+
50
+ ephem = Astronoby::Ephem.load("inpop19a.bsp")
51
+
52
+ vega
53
+ .at(instant)
54
+ .apparent
55
+ .equatorial
56
+ .right_ascension
57
+ .str(:hms)
58
+ # => "18h 37m 48.2804s"
59
+
60
+ vega_with_proper_motion
61
+ .at(instant, ephem: ephem)
62
+ .apparent
63
+ .equatorial
64
+ .right_ascension
65
+ .str(:hms)
66
+ # => "18h 37m 48.7215s"
67
+ ```
68
+
69
+ You can learn more about [ephemerides] and [reference frames].
70
+
71
+ A deep-sky body object can also be used in calculators.
72
+
73
+ ```rb
74
+ observer = Astronoby::Observer.new(
75
+ latitude: Astronoby::Angle.from_degrees(51.5072),
76
+ longitude: Astronoby::Angle.from_degrees(-0.1276)
77
+ )
78
+ date = Date.new(2025, 10, 1)
79
+
80
+ body = Astronoby::DeepSkyObject.new(
81
+ equatorial_coordinates: Astronoby::Coordinates::Equatorial.new(
82
+ right_ascension: Astronoby::Angle.from_hms(6, 45, 8.917),
83
+ declination: Astronoby::Angle.from_dms(-16, 42, 58.02)
84
+ )
85
+ )
86
+
87
+ calculator = Astronoby::RiseTransitSetCalculator.new(
88
+ body: body,
89
+ observer: observer,
90
+ ephem: ephem
91
+ )
92
+
93
+ event = calculator.event_on(date)
94
+
95
+ event.rising_time
96
+ # => 2025-10-01 01:31:25 UTC
97
+ ```
98
+
99
+ [ephemerides]: ephem.md
100
+ [reference frames]: reference_frames.md
101
+ [SIMBAD Astronomical Database]: https://simbad.u-strasbg.fr/simbad/
data/docs/ephem.md ADDED
@@ -0,0 +1,85 @@
1
+ # `Ephem`
2
+
3
+ `Astronoby` depends on the gem [`ephem`] which provides a Ruby interface for
4
+ <abbr title="Jet Propulsion Laboratory">JPL</abbr> SPICE binary kernels.
5
+
6
+ These kernels are extremely precise ephemerides produced by the JPL and are the
7
+ foundation of the data provided by Astronoby. The [IMCCE] also produces
8
+ kernels in the same format for their
9
+ <abbr title="Intégrateur numérique planétaire de l'Observatoire de Paris">INPOP</abbr>
10
+ model.
11
+
12
+ ## Download an ephemeris
13
+
14
+ To download an ephemeris, you can either do it manually or use `ephem` by
15
+ providing the filename.
16
+
17
+ ### Manually
18
+
19
+ Ephemerides are available for download from:
20
+ * the JPL public FTP interface: https://ssd.jpl.nasa.gov/ftp/eph/planets/bsp/
21
+ * the INPOP releases page of the IMCCE: https://www.imcce.fr/inpop
22
+
23
+ You can download any `.bsp` file. For the moment, Astronoby only supports the
24
+ planets of the Solar System, and the Sun and the Moon, so you need to
25
+ download a _Development Ephemeris_, which starts with `de` (i.e. `de421.bsp`),
26
+ or any of the INPOP ephemeris files (i.e. `inpop19a.bsp`).
27
+
28
+ ### With `Ephem`
29
+
30
+ If you already know the ephemeris you want to use, you can use `Ephem` to
31
+ download and store it for you:
32
+
33
+ ```rb
34
+ Astronoby::Ephem.download(name: "de421.bsp", target: "tmp/de421.bsp")
35
+ ```
36
+
37
+ ## Load an ephemeris
38
+
39
+ To compute the position of a Solar System body, you need to provide an ephemeris
40
+ to extract the data from. You can use `Astronoby::Ephem` to load the file you
41
+ downloaded.
42
+
43
+ ```rb
44
+ ephem = Astronoby::Ephem.load("tmp/de421.bsp")
45
+ ```
46
+
47
+ ## How to choose the right ephemeris?
48
+
49
+ JPL produces many different kernels over the years, with different accuracy and
50
+ ranges of supported years. Here are some that we recommend to begin with:
51
+ - `de421.bsp`: from 1900 to 2050, 17 MB
52
+ - `de440s.bsp`: from 1849 to 2150, 32 MB
53
+ - `inpop19a.bsp`: from 1900 to 2100, 22 MB
54
+
55
+ ## How to limit weight and increase speed?
56
+
57
+ The `Ephem` library offers a <abbr title="Command-Line Interface">CLI</abbr> to
58
+ produce excerpt ephemerides in order to limit the range of dates or bodies.
59
+
60
+ Here is an example to produce an excerpt ephemeris for the year 2025:
61
+
62
+ ```
63
+ ruby-ephem excerpt 2024-12-31 2026-01-01 de440s.bsp de440s_2025_excerpt.bsp
64
+ ```
65
+
66
+ You can also specify which bodies of the Solar System (or "targets") you want to
67
+ include:
68
+
69
+ ```
70
+ ruby-ephem excerpt --targets 10,399 2024-12-31 2026-01-01 inpop19a.bsp inpop19a_2025_sun_earth.bsp
71
+ ```
72
+
73
+ You may want to check how bodies are handled between JPL DE and IMCCE INPOP. For
74
+ example, the excerpt file from a JPL DE kernel needs to include targets `3` and
75
+ `399` for the Earth, while the excerpt file from a IMCCE INPOP kernel only needs
76
+ the target `399`.
77
+
78
+ [`ephem`]: https://github.com/rhannequin/ruby-ephem
79
+ [IMCCE]: https://www.imcce.fr
80
+
81
+ ## See also
82
+ - [Solar System Bodies](solar_system_bodies.md) - for using ephemeris data
83
+ - [Reference Frames](reference_frames.md) - for coordinate calculations
84
+ - [Observer](observer.md) - for location-based calculations
85
+ - [Configuration](configuration.md) - for performance tuning
@@ -0,0 +1,31 @@
1
+ # Equinoxes and Solstice Times
2
+
3
+ The equinox and solstice are two precise events that each happen twice a year.
4
+
5
+ The equinox is the time when the Sun appears directly above the equator, the
6
+ solstice is the time when the Sun reaches its most northerly or southerly
7
+ excursion relative to the celestial equator on the celestial sphere.
8
+
9
+ Astronoby enables you to compute the time for each of these four events.
10
+
11
+ ```rb
12
+ ephem = Astronoby::Ephem.load("inpop19a.bsp")
13
+
14
+ Astronoby::EquinoxSolstice.march_equinox(2025, ephem)
15
+ # => 2025-03-20 09:01:29 UTC
16
+
17
+ Astronoby::EquinoxSolstice.june_solstice(2025, ephem)
18
+ # => 2025-06-21 02:42:19 UTC
19
+
20
+ Astronoby::EquinoxSolstice.september_equinox(2025, ephem)
21
+ # => 2025-09-22 18:19:22 UTC
22
+
23
+ Astronoby::EquinoxSolstice.december_solstice(2025, ephem)
24
+ # => 2025-12-21 15:03:03 UTC
25
+ ```
26
+
27
+ ## See also
28
+ - [Twilight Times](twilight_times.md) - for seasonal sun events
29
+ - [Moon Phases](moon_phases.md) - for lunar events
30
+ - [Ephemerides](ephem.md) - for data sources
31
+ - [Instant](instant.md) - for time handling
data/docs/glossary.md ADDED
@@ -0,0 +1,152 @@
1
+ # Glossary
2
+
3
+ This glossary defines key astronomical and technical terms used throughout the Astronoby documentation.
4
+
5
+ ## Astronomical Terms
6
+
7
+ ### **Aberration**
8
+ The apparent displacement of a celestial object due to the finite speed of light and the motion of the observer. In Astronoby, this is automatically corrected in apparent reference frames.
9
+
10
+ ### **Altitude**
11
+ The angular distance of a celestial object above the observer's local horizon, measured in degrees from 0° (horizon) to 90° (zenith).
12
+
13
+ ### **Apparent Position**
14
+ The position of a celestial object as it appears in the sky, corrected for light-time, aberration, and other effects. This is what you actually see when looking through a telescope.
15
+
16
+ ### **Arc Second**
17
+ A unit of angular measurement equal to 1/3600th of a degree. Often used to describe the precision of astronomical calculations.
18
+
19
+ ### **Azimuth**
20
+ The angular distance around the horizon from north, measured clockwise in degrees. North is 0°, east is 90°, south is 180°, and west is 270°.
21
+
22
+ ### **Barycentre**
23
+ The centre of mass of a system of bodies. In the Solar System, this is the point around which all planets orbit, which is usually close to but not exactly at the Sun's centre.
24
+
25
+ ### **Celestial Equator**
26
+ The projection of Earth's equator onto the celestial sphere. It's the reference plane for equatorial coordinates.
27
+
28
+ ### **Celestial Sphere**
29
+ An imaginary sphere surrounding Earth, on which all celestial objects appear to be located. Used as a reference system for astronomical coordinates.
30
+
31
+ ### **Constellation**
32
+ A region of the sky containing a group of stars that form a recognizable pattern. Astronoby can determine which constellation a celestial body appears to be in.
33
+
34
+ ### **Declination**
35
+ The angular distance north or south of the celestial equator, measured in degrees. Positive values are north, negative values are south.
36
+
37
+ ### **Ecliptic**
38
+ The apparent path of the Sun across the celestial sphere throughout the year. It's the plane of Earth's orbit around the Sun.
39
+
40
+ ### **Ephemeris**
41
+ A table or file containing the calculated positions of celestial objects at specific times. Astronoby uses ephemeris files from JPL and IMCCE for high-precision calculations.
42
+
43
+ ### **Equinox**
44
+ The two times each year when the Sun crosses the celestial equator, making day and night approximately equal in length. The March (vernal) and September (autumnal) equinoxes.
45
+
46
+ ### **Geocentric**
47
+ As seen from the centre of Earth. Geocentric coordinates are useful for calculations but don't account for an observer's specific location.
48
+
49
+ ### **Horizon**
50
+ The apparent boundary between Earth and sky as seen by an observer. The local horizon depends on the observer's location and elevation.
51
+
52
+ ### **Illuminated Fraction**
53
+ The portion of a celestial body's disk that appears illuminated as seen from Earth. For the Moon, this varies from 0 (new moon) to 1 (full moon).
54
+
55
+ ### **Julian Date**
56
+ A continuous count of days since January 1, 4713 BCE. Used in astronomy for precise time measurements and calculations.
57
+
58
+ ### **Light-Time Correction**
59
+ The adjustment made to account for the time it takes light to travel from a celestial object to Earth. Important for accurate position calculations.
60
+
61
+ ### **Magnitude**
62
+ A measure of a celestial object's brightness. Lower numbers indicate brighter objects (e.g., -4 is brighter than +2). Apparent magnitude is as seen from Earth, absolute magnitude is intrinsic brightness.
63
+
64
+ ### **Meridian**
65
+ An imaginary line passing through the observer's zenith and the north and south celestial poles. Objects transit (cross) the meridian when they reach their highest point in the sky.
66
+
67
+ ### **Nutation**
68
+ Small periodic variations in the orientation of Earth's rotation axis, caused by gravitational forces from the Sun and Moon.
69
+
70
+ ### **Obliquity**
71
+ The angle between Earth's equatorial plane and the ecliptic plane. Currently about 23.4° and slowly decreasing.
72
+
73
+ ### **Parallax**
74
+ The apparent shift in position of a nearby object when viewed from different locations. Important for calculating distances to nearby stars.
75
+
76
+ ### **Phase Angle**
77
+ The angle between the Sun, a celestial object, and Earth. For planets, this determines how much of the disk is illuminated.
78
+
79
+ ### **Precession**
80
+ The slow, continuous change in the orientation of Earth's rotation axis, causing the positions of the equinoxes to shift over time.
81
+
82
+ ### **Refraction**
83
+ The bending of light as it passes through Earth's atmosphere, causing celestial objects to appear slightly higher in the sky than they actually are.
84
+
85
+ ### **Right Ascension**
86
+ The angular distance eastward along the celestial equator from the vernal equinox, measured in hours (0-24h) or degrees (0-360°).
87
+
88
+ ### **Solstice**
89
+ The two times each year when the Sun reaches its northernmost (June) or southernmost (December) position relative to the celestial equator.
90
+
91
+ ### **Topocentric**
92
+ As seen from a specific location on Earth's surface. Topocentric positions account for the observer's latitude, longitude, and elevation.
93
+
94
+ ### **Transit**
95
+ The moment when a celestial object crosses the observer's meridian, reaching its highest point in the sky for that day.
96
+
97
+ ### **Twilight**
98
+ The period before sunrise and after sunset when the sky is partially illuminated by scattered sunlight. Civil, nautical, and astronomical twilight have different definitions based on the Sun's position below the horizon.
99
+
100
+ ### **Zenith**
101
+ The point directly above an observer on Earth, at an altitude of 90°.
102
+
103
+ ## Technical Terms
104
+
105
+ ### **API (Application Programming Interface)**
106
+ The set of methods and classes that programmers use to interact with the Astronoby library.
107
+
108
+ ### **Cache**
109
+ A temporary storage system that stores frequently used calculation results to improve performance.
110
+
111
+ ### **Coordinate System**
112
+ A system for specifying the position of objects in space. Astronoby supports equatorial, ecliptic, and horizontal coordinate systems.
113
+
114
+ ### **Ephemeris File**
115
+ A binary file (usually with .bsp extension) containing orbital data for Solar System bodies. These files are produced by JPL and IMCCE.
116
+
117
+ ### **Floating-Point Precision**
118
+ The accuracy of decimal number calculations. Higher precision values in Astronoby provide more accurate results but may be slower.
119
+
120
+ ### **Reference Frame**
121
+ A coordinate system used to specify positions. Astronoby provides geometric, astrometric, mean of date, apparent, and topocentric reference frames.
122
+
123
+ ### **SPICE**
124
+ A NASA toolkit for computing positions and orientations of Solar System bodies. Astronoby uses SPICE binary kernels (.bsp files) for ephemeris data.
125
+
126
+ ### **UTC (Coordinated Universal Time)**
127
+ The primary time standard used worldwide. All astronomical calculations in Astronoby are based on UTC.
128
+
129
+ ## Units and Measurements
130
+
131
+ ### **Angular Units**
132
+ - **Degree (°)**: 1/360th of a circle
133
+ - **Arc Minute (′)**: 1/60th of a degree
134
+ - **Arc Second (″)**: 1/60th of an arc minute
135
+ - **Hour (h)**: 15 degrees (used for right ascension)
136
+ - **Radian**: 180/π degrees (≈57.3°)
137
+
138
+ ### **Distance Units**
139
+ - **Astronomical Unit (AU)**: The average distance between Earth and Sun (≈149.6 million km)
140
+ - **Kilometre (km)**: Standard metric unit for distances
141
+ - **Metre (m)**: Standard metric unit for elevations
142
+
143
+ ### **Time Units**
144
+ - **Julian Day**: Continuous day count since 4713 BCE
145
+ - **Terrestrial Time (TT)**: Astronomical time scale used for calculations
146
+ - **UTC**: Coordinated Universal Time, the standard for civil time
147
+
148
+ ## See also
149
+ - [Quick Start Guide](README.md) - for getting started
150
+ - [Coordinates](coordinates.md) - for coordinate systems
151
+ - [Reference Frames](reference_frames.md) - for position calculations
152
+ - [Angles](angles.md) - for angular measurements
data/docs/instant.md ADDED
@@ -0,0 +1,139 @@
1
+ # `Instant`
2
+
3
+ Time in astronomy is usually a slightly different concept than in everyday
4
+ life. Today, the vast majority of people use the [Gregorian calendar] and a time
5
+ based on <abbr title="Coordinated Universal Time">UTC</abbr>. This timescale is
6
+ convenient for matching what we experience on Earth, but it is not static, it
7
+ includes leap days, leap seconds.
8
+
9
+ Also, most of us live in areas where the local legal time is not UTC, so we
10
+ have to deal with time zones that are arbitrary and constantly changing.
11
+
12
+ Astronomical calculations need a stable, uniform and linear time scale, free
13
+ from the irregularities in the rotation of Earth and the irregularly fluctuating
14
+ mean solar time.
15
+
16
+ Astronoby handles this situation by implementing an `Astronoby::Instant` class,
17
+ used in most calculations instead of `Time`.
18
+
19
+ `Astronoby::Instant` is a value object that stores an instant in time on Earth
20
+ in [Terrestrial Time], an astronomical time standard defined by the
21
+ International Astronomical Union, as a [Julian Date].
22
+
23
+ From this instant in <abbr title="Terrestrial Time">TT</abbr>, other time
24
+ standards can be expressed, such as the
25
+ <abbr title="International Atomic Time">TAI</abbr> or the
26
+ <abbr title="Barycentric Dynamic Time">TDB</abbr>.
27
+
28
+ ## Initialization
29
+
30
+ An `Astronoby::Instant` object can be instantiated from:
31
+ * Terrestrial time (`Numeric`): `.from_terrestrial_time`
32
+ * Ruby `Time` object: `.from_time`
33
+ * UTC Julian date (`Numeric`): `.from_utc_julian_date`
34
+
35
+ ```rb
36
+ Astronoby::Instant.from_terrestrial_time(2460796)
37
+ # => Represents UTC time 2025-04-30 11:58:51
38
+
39
+ Astronoby::Instant.from_time(Time.utc(2025, 5, 1))
40
+ # => Represents terrestrial time Julian Date 2460796.500798611
41
+
42
+ Astronoby::Instant.from_utc_julian_date(2460796)
43
+ # => Represents UTC time 2025-04-30 12:00:00
44
+ # => Represents terrestrial time Julian Date 2460796.000798611
45
+ ```
46
+
47
+ ## Time standards
48
+
49
+ From the same instant, it is possible to extract different time standards.
50
+
51
+ * Gregorian `Date`
52
+
53
+ ```rb
54
+ instant = Astronoby::Instant.from_terrestrial_time(2460796)
55
+
56
+ instant.to_date
57
+ # => #<Date: 2025-04-30 ((2460796j,0s,0n),+0s,2299161j)>
58
+ ```
59
+
60
+ * UTC `DateTime`
61
+
62
+ ```rb
63
+ instant = Astronoby::Instant.from_terrestrial_time(2460796)
64
+
65
+ instant.to_datetime
66
+ # => #<DateTime: 2025-04-30T11:58:51+00:00 ((2460796j,43131s,12159n),+0s,2299161j)>
67
+ ```
68
+
69
+ * UTC `Time`
70
+
71
+ ```rb
72
+ instant = Astronoby::Instant.from_terrestrial_time(2460796)
73
+
74
+ instant.to_datetime
75
+ # => 2025-04-30 11:58:51.000012159 UTC
76
+ ```
77
+
78
+ * Greenwich Sidereal Time
79
+
80
+ ```rb
81
+ instant = Astronoby::Instant.from_terrestrial_time(2460796)
82
+
83
+ instant.gmst
84
+ # => 2.5597425440141457
85
+ ```
86
+
87
+ * International Atomic Time
88
+
89
+ ```rb
90
+ instant = Astronoby::Instant.from_terrestrial_time(2460796)
91
+
92
+ instant.tai.to_f
93
+ # => 2460795.9996275003
94
+ ```
95
+
96
+ * UTC offset (difference with UTC in days)
97
+
98
+ ```rb
99
+ instant = Astronoby::Instant.from_terrestrial_time(2460796)
100
+
101
+ instant.utc_offset.to_f
102
+ # => 0.0007986109703819444
103
+ ```
104
+
105
+ * Barycentric Dynamic Time
106
+
107
+ ```rb
108
+ # This is not handled for now, and returns TT
109
+
110
+ instant = Astronoby::Instant.from_terrestrial_time(2460796)
111
+
112
+ instant.tdb
113
+ # => 2460796
114
+ ```
115
+
116
+ ## Value Equality
117
+
118
+ As a value object, it is possible to compare different instants.
119
+
120
+ ```rb
121
+ instant1 = Astronoby::Instant.from_terrestrial_time(2460796)
122
+ instant2 = Astronoby::Instant.from_terrestrial_time(2460797)
123
+
124
+ instant1.diff(instant2)
125
+ # => -1
126
+
127
+ instant1 < instant2
128
+ # => true
129
+ ```
130
+
131
+ [Gregorian calendar]: https://en.wikipedia.org/wiki/Gregorian_calendar
132
+ [Terrestrial Time]: https://en.wikipedia.org/wiki/Terrestrial_Time
133
+ [Julian Date]: https://en.wikipedia.org/wiki/Julian_day
134
+
135
+ ## See also
136
+ - [Ephemerides](ephem.md) - for time-based calculations
137
+ - [Solar System Bodies](solar_system_bodies.md) - for object positions
138
+ - [Reference Frames](reference_frames.md) - for coordinate systems
139
+ - [Configuration](configuration.md) - for performance settings
@@ -0,0 +1,79 @@
1
+ # Moon Phases
2
+
3
+ Astronoby lets you compute the current Moon phase, or when the major ones
4
+ happen.
5
+
6
+ ## Current Moon phase
7
+
8
+ `Astronoby::Moon` provides two pieces of information about the current Moon phase: the
9
+ illuminated fraction and the phase fraction.
10
+
11
+ ### `#illuminated_fraction`
12
+
13
+ As mentioned in the name, this method provides the illuminated fraction of the
14
+ Moon. It will not give precise information about the "age" of the Moon as the
15
+ same illumination happens twice in the same lunar month.
16
+
17
+ ```rb
18
+ ephem = Astronoby::Ephem.load("inpop19a.bsp")
19
+ time = Time.utc(2025, 5, 1)
20
+ instant = Astronoby::Instant.from_time(time)
21
+
22
+ moon = Astronoby::Moon.new(ephem: ephem, instant: instant)
23
+
24
+ moon.illuminated_fraction.round(2)
25
+ # => 0.15
26
+ # 15% of the Moon is illuminated as seen from Earth
27
+ ```
28
+
29
+ ### `#current_phase_fraction`
30
+
31
+ This method is more convenient for a user interested in how far we are into the
32
+ lunar month as it returns a fraction from 0 to 1 between two new Moons.
33
+
34
+ ```rb
35
+ ephem = Astronoby::Ephem.load("inpop19a.bsp")
36
+
37
+ time = Time.utc(2025, 5, 1)
38
+ instant = Astronoby::Instant.from_time(time)
39
+ moon = Astronoby::Moon.new(ephem: ephem, instant: instant)
40
+
41
+ moon.current_phase_fraction.round(2)
42
+ # => 0.11
43
+
44
+ time = Time.utc(2025, 5, 15)
45
+ instant = Astronoby::Instant.from_time(time)
46
+ moon = Astronoby::Moon.new(ephem: ephem, instant: instant)
47
+
48
+ moon.current_phase_fraction.round(2)
49
+ # => 0.59
50
+ ```
51
+
52
+ ## Major Moon phases in the month
53
+
54
+ If you are interested to know when the major Moon phases will happen during a
55
+ civil month, you can use `Astronoby::Events::MoonPhases` and its class method
56
+ `::phases_for` with the key arguments `year` and `month`, both `Integer`.
57
+
58
+ It returns an array of `Astronoby::MoonPhase` objects, which each expose a
59
+ `phase` (`Symbol`) and a `time` (`Time`).
60
+
61
+ Please note that because a lunar month is around 29 days, some months will have
62
+ the same phase twice.
63
+
64
+ ```rb
65
+ phases = Astronoby::Events::MoonPhases.phases_for(year: 2024, month: 5)
66
+
67
+ phases.each { puts "#{_1.phase}: #{_1.time}" }
68
+ # last_quarter: 2024-05-01 11:27:15 UTC
69
+ # new_moon: 2024-05-08 03:21:56 UTC
70
+ # first_quarter: 2024-05-15 11:48:02 UTC
71
+ # full_moon: 2024-05-23 13:53:12 UTC
72
+ # last_quarter: 2024-05-30 17:12:43 UTC
73
+ ```
74
+
75
+ ## See also
76
+ - [Twilight Times](twilight_times.md) - for sun-related events
77
+ - [Rise, Transit and Set Times](rise_transit_set_times.md) - for moon events
78
+ - [Solar System Bodies](solar_system_bodies.md) - for moon object details
79
+ - [Ephemerides](ephem.md) - for data sources
data/docs/observer.md ADDED
@@ -0,0 +1,65 @@
1
+ # Observer
2
+
3
+ `Astronoby::Observer` is the representation of an observer on Earth. Most of the
4
+ events computed by Astronoby are location and date based.
5
+
6
+ ## Initialization
7
+
8
+ The two required key arguments to instantiate an observer are:
9
+ * `latitude` (`Astronoby::Angle`): the angle from the equator to the observer,
10
+ from 90° to -90°, with positive angles for the Northern Hemisphere.
11
+ * `longitude` (`Astronoby::Angle`): the angle from the Greenwich meridian to the
12
+ observer, from 180° to -180°, with positive angles eastward of the Greenwich
13
+ meridian.
14
+
15
+ Latitude and longitude are defined according to the [World Geodetic System].
16
+ In other words, they are the same as those used for the [GPS].
17
+
18
+ It is also possible to give the following optional key arguments:
19
+ * `elevation` (`Astronoby::Distance`): the distance above or below the average
20
+ sea level
21
+ * `utc_offset`: local time difference with UTC. Check the [timezone specifiers]
22
+ for the format.
23
+
24
+ ```rb
25
+ # Location: Alhambra, Spain
26
+
27
+ observer = Astronoby::Observer.new(
28
+ latitude: Astronoby::Angle.from_degrees(37.176),
29
+ longitude: Astronoby::Angle.from_degrees(-3.588),
30
+ elevation: Astronoby::Distance.from_meters(792)
31
+ )
32
+ ```
33
+
34
+ You can learn more about angles on the [Angles page].
35
+
36
+ ## Value equality
37
+
38
+ `Astronoby::Observer` is a value object, which means it implements value
39
+ equality.
40
+
41
+ ```rb
42
+ observer1 = Astronoby::Observer.new(
43
+ latitude: Astronoby::Angle.from_degrees(90),
44
+ longitude: Astronoby::Angle.from_degrees(180)
45
+ )
46
+
47
+ observer2 = Astronoby::Observer.new(
48
+ latitude: Astronoby::Angle.from_hours(6),
49
+ longitude: Astronoby::Angle.from_hours(12)
50
+ )
51
+
52
+ observer1 == observer2
53
+ # => true
54
+ ```
55
+
56
+ [World Geodetic System]: https://en.wikipedia.org/wiki/World_Geodetic_System
57
+ [GPS]: https://en.wikipedia.org/wiki/GPS
58
+ [timezone specifiers]: https://ruby-doc.org/3.4.1/Time.html#class-Time-label-Timezone+Specifiers
59
+ [Angles page]: angles.md
60
+
61
+ ## See also
62
+ - [Angles](angles.md) - for working with latitude and longitude
63
+ - [Coordinates](coordinates.md) - for understanding position systems
64
+ - [Reference Frames](reference_frames.md) - for topocentric calculations
65
+ - [Solar System Bodies](solar_system_bodies.md) - for observing objects