astronoby 0.11.1 → 0.12.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ad9c9bd7a2b518f7ac3429fa7836b5c34f459c8907c2057bd0d63165648ef017
4
- data.tar.gz: ccb5c59b9b830a8eeb5b6880a2f00da2dc5cf634d272b87edff6dad603e0f331
3
+ metadata.gz: 1d889751128d1bbc5138f9f95f906dc1d70ad5d9406171e8dc9c26aa7427b70b
4
+ data.tar.gz: 88074a91d68e385fb8a16cc22c6d4dd4c5615fe14ad2cc8326dda2bd1fb1798a
5
5
  SHA512:
6
- metadata.gz: b487bd81b65c1ab8606b8a623283a079d4f2fbcc961f1c1b945e5047e081a20a7a95fb4b6888d0fec2c8687612ca3301148105eec3be19c4da459a88a08eeb74
7
- data.tar.gz: 782717b15239216c27b5b9a24b177815aabe9622fa23309fb7fe8ad05fb4088fe5a98bd21fb26b3035724fb9771357bdc314a81bbb6b655817ad7ad3d5bd8a85
6
+ metadata.gz: 4279f3e1f44f211bd8620ffaf2026b148f8ada8d556b8cbf778a7296aa2cb9f1c08f806eb27ac50e2204fe35391ba0c2ccd8309dcc18c471c0898abe23e9cd45
7
+ data.tar.gz: b5c2ff39b33310a95fa10c3591c6434b2ea0663cbec618c45b95f91cbc325e399e48e8948003038f57aea0decf32179398d250f2041560ffa27fa99b07b409a3
data/CHANGELOG.md CHANGED
@@ -1,5 +1,64 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.12.0 - 2026-11-24
4
+
5
+ _If you are upgrading: please see [UPGRADING.md]._
6
+
7
+ ### Bug fixes
8
+
9
+ * Compute atmospheric refraction with Bennett's formula, inverted to start
10
+ from the true altitude that Astronoby gives it, as NOVAS does. The
11
+ low-altitude formula used until now expects the apparent altitude but was
12
+ given the true one, so refraction was too large near the horizon, by 5′ at a
13
+ true altitude of 0° and 2.4′ at 1°, and the apparent horizon fell at a true
14
+ altitude of -47′ instead of the -34′ that rise and set times use. Below -1°
15
+ the refraction is now kept constant instead of growing up to 79′ ([#324])
16
+ * Refract the limb rather than the centre in `AltitudeCrossingCalculator` with
17
+ `refraction: true` and a limb reference. Near the horizon, refraction changes
18
+ by a few arcminutes across the Sun's semi-diameter, which put upper-limb
19
+ crossings 20 to 30 seconds away from sunrise and sunset ([#324])
20
+ * Raise the minimum `ephem` version from 0.5.1 to 0.5.2. Downloading IMCCE
21
+ kernels with `Ephem.download` or `Orientation.download` failed when
22
+ `Encoding.default_internal` was set, as it is in Rails apps ([#330])
23
+
24
+ ### Features
25
+
26
+ * Add `Temperature` and `Pressure` value objects, used for the observer's
27
+ atmospheric conditions ([#324])
28
+ * Add `Horizontal#refracted?` and `Horizontal#refract` ([#324])
29
+ * Add `Airmass`, with `Horizontal#airmass` and `AltitudeExtreme#airmass`. It
30
+ uses Young (1994) for a true altitude and Kasten and Young (1989) for an
31
+ apparent one ([#323], [#329])
32
+ * Add `AltitudeExtreme#refracted?` ([#329])
33
+
34
+ ### Improvements
35
+
36
+ * Document refraction in `docs/refraction.md` ([#324])
37
+
38
+ ### Backward-incompatible changes
39
+
40
+ * Refracted altitudes are lower than before near the horizon, by up to 5′ at a
41
+ true altitude of 0°. Above 5° they move by less than 10″, and rise, set and
42
+ twilight times are unchanged ([#324])
43
+ * `Observer` takes a `Temperature` for `temperature:` and a `Pressure` for
44
+ `pressure:`, and returns them from `#temperature` and `#pressure`. Passing a
45
+ number raises `IncompatibleArgumentsError` ([#324])
46
+ * Remove `Observer::PRESSURE_AT_SEA_LEVEL`, `PASCAL_PER_MILLIBAR`,
47
+ `EARTH_GRAVITATIONAL_ACCELERATION`, `MOLAR_MASS_OF_AIR` and
48
+ `UNIVERSAL_GAS_CONSTANT` ([#324])
49
+ * `Refraction` is a module with a single method,
50
+ `Refraction.angle(altitude:, observer:)`. `Refraction.new`, `#refract`,
51
+ `#refraction_angle`, `.correct_horizontal_coordinates` and the
52
+ `LOW_ALTITUDE_BODY_ANGLE` and `ZENITH` constants are removed ([#324])
53
+
54
+ **Full Changelog**: https://github.com/rhannequin/astronoby/compare/v0.11.1...v0.12.0
55
+
56
+ [#323]: https://github.com/rhannequin/astronoby/issues/323
57
+ [#324]: https://github.com/rhannequin/astronoby/pull/324
58
+ [#329]: https://github.com/rhannequin/astronoby/pull/329
59
+ [#330]: https://github.com/rhannequin/astronoby/pull/330
60
+ [UPGRADING.md]: https://github.com/rhannequin/astronoby/blob/main/UPGRADING.md
61
+
3
62
  ## 0.11.1 - 2026-11-24
4
63
 
5
64
  _If you are upgrading: please see [UPGRADING.md]._
data/UPGRADING.md CHANGED
@@ -7,6 +7,73 @@ changes to it as long as a major version has not been released.
7
7
  If you are already using Astronoby and wish to follow the changes to its
8
8
  public API, please read the upgrading notes for each release.
9
9
 
10
+ ## Upgrading from 0.11.1 to 0.12.0
11
+
12
+ ### Refraction has changed near the horizon
13
+
14
+ Atmospheric refraction is now computed with Bennett's formula, inverted to
15
+ start from the true altitude, as NOVAS does. The formula used until now
16
+ expected the apparent altitude below 15° but was given the true one.
17
+
18
+ Refracted altitudes above 5° move by less than 10″. Closer to the horizon they
19
+ are lower than before, by up to 5′ at a true altitude of 0°, and below the
20
+ horizon the refraction is now kept at its value at -1°. This affects
21
+ `Topocentric#horizontal(refraction: true)`,
22
+ `HorizontalTransformation#apply(refraction: true)` and
23
+ `AltitudeCrossingCalculator` with `refraction: true`. Rise, set and twilight
24
+ times are unchanged.
25
+
26
+ ### `Observer` takes value objects for the temperature and the pressure
27
+
28
+ `temperature:` is now an `Astronoby::Temperature` and `pressure:` an
29
+ `Astronoby::Pressure`, and `Observer#temperature` and `#pressure` return them.
30
+ Passing a number raises `Astronoby::IncompatibleArgumentsError`, and so does a
31
+ temperature at or below absolute zero or a negative pressure.
32
+
33
+ ```rb
34
+ # Before
35
+ Astronoby::Observer.new(
36
+ latitude: latitude,
37
+ longitude: longitude,
38
+ temperature: 283.15,
39
+ pressure: 1013.25
40
+ )
41
+
42
+ # After
43
+ Astronoby::Observer.new(
44
+ latitude: latitude,
45
+ longitude: longitude,
46
+ temperature: Astronoby::Temperature.from_celsius(10),
47
+ pressure: Astronoby::Pressure.from_millibars(1013.25)
48
+ )
49
+ ```
50
+
51
+ `Observer::DEFAULT_TEMPERATURE` is now a `Temperature`. The constants used for
52
+ the default pressure, `Observer::PRESSURE_AT_SEA_LEVEL`,
53
+ `PASCAL_PER_MILLIBAR`, `EARTH_GRAVITATIONAL_ACCELERATION`, `MOLAR_MASS_OF_AIR`
54
+ and `UNIVERSAL_GAS_CONSTANT`, have been removed. The default pressure is
55
+ `Pressure.at_elevation(elevation, temperature:)`.
56
+
57
+ ### `Refraction` has a single method
58
+
59
+ `Astronoby::Refraction` is now a module with one method,
60
+ `Refraction.angle(altitude:, observer:)`, which takes the true altitude as an
61
+ `Angle` instead of horizontal coordinates.
62
+
63
+ `Refraction.correct_horizontal_coordinates(coordinates:)` has been removed. Use
64
+ `Horizontal#refract` instead:
65
+
66
+ ```rb
67
+ # Before
68
+ Astronoby::Refraction.correct_horizontal_coordinates(coordinates: horizontal)
69
+
70
+ # After
71
+ horizontal.refract
72
+ ```
73
+
74
+ `Refraction.new`, `#refract` and `#refraction_angle` have been removed as well,
75
+ along with the `LOW_ALTITUDE_BODY_ANGLE` and `ZENITH` constants.
76
+
10
77
  ## Upgrading from 0.11.0 to 0.11.1
11
78
 
12
79
  ### Downloads raise on failure
data/docs/README.md CHANGED
@@ -292,6 +292,7 @@ horizontal coordinates at once with `HorizontalTransformation`, on the
292
292
 
293
293
  - [Glossary](glossary.md) - for astronomical and technical terms
294
294
  - [IERS Data](iers.md) - for Delta T and GMST data management
295
+ - [Refraction](refraction.md) - for apparent altitudes and atmospheric conditions
295
296
  - [Configuration](configuration.md) - for performance tuning
296
297
  - [Performance Benchmarks](../benchmarks/README.md) - for testing improvements
297
298
 
data/docs/coordinates.md CHANGED
@@ -157,6 +157,54 @@ horizontal.azimuth.str(:dms)
157
157
  # => "+171° 19′ 38.2567″"
158
158
  ```
159
159
 
160
+ ### Refraction
161
+
162
+ The altitude is the true, geometric one by default. `horizontal(refraction:
163
+ true)` gives the apparent altitude instead, with atmospheric refraction, and
164
+ `#refracted?` tells which one a `Horizontal` holds. You can learn more on the
165
+ [Refraction page].
166
+
167
+ ### Airmass
168
+
169
+ The length of the path light travels through the atmosphere, relative to the
170
+ path at the zenith. It is 1 at the zenith, about 2 at 30° of altitude and about
171
+ 38 for a body that appears on the horizon. `#airmass` returns an
172
+ `Astronoby::Airmass`, or `nil` when the body appears below the horizon.
173
+
174
+ ```rb
175
+ horizontal.airmass.value
176
+ # => 2.0678174512396987
177
+ ```
178
+
179
+ It uses the formula that matches the altitude: Young (1994) for the true
180
+ altitude, and Kasten and Young (1989) for the apparent altitude of a refracted
181
+ `Horizontal`. For the same body, the two agree to within 1% down to the horizon.
182
+
183
+ A body can be up to about half a degree below the true horizon and still appear
184
+ above it, lifted by refraction. Young (1994) does not cover these altitudes, so
185
+ for them the altitude is refracted with the observer's temperature and pressure
186
+ and Kasten and Young (1989) is used.
187
+
188
+ An airmass can also be computed from any altitude:
189
+
190
+ ```rb
191
+ altitude = Astronoby::Angle.from_degrees(30)
192
+
193
+ Astronoby::Airmass.from_true_altitude(altitude).value
194
+ # => 1.9917307558359632
195
+
196
+ Astronoby::Airmass.from_apparent_altitude(altitude).value
197
+ # => 1.9942928525292503
198
+ ```
199
+
200
+ Airmasses can be compared with each other or with a number, for example to
201
+ check an observation limit:
202
+
203
+ ```rb
204
+ horizontal.airmass < 2
205
+ # => false
206
+ ```
207
+
160
208
  ## Geodetic
161
209
 
162
210
  Geodetic coordinates describe a position on or above the Earth's surface using
@@ -218,6 +266,7 @@ The forward direction (geodetic → ECEF) is handled by
218
266
  [Wikipedia]: https://en.wikipedia.org/wiki/Equatorial_coordinate_system
219
267
  [Angle page]: angles.md
220
268
  [topocentric position]: reference_frames.md#topocentric
269
+ [Refraction page]: refraction.md
221
270
 
222
271
  ## See also
223
272
 
data/docs/glossary.md CHANGED
@@ -8,6 +8,10 @@ This glossary defines key astronomical and technical terms used throughout the A
8
8
 
9
9
  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.
10
10
 
11
+ ### **Airmass**
12
+
13
+ The length of the path light travels through Earth's atmosphere, relative to the path at the zenith. It is 1 at the zenith and grows towards the horizon, and drives how much a body is dimmed and blurred by the atmosphere. See the [Coordinates page](coordinates.md#airmass).
14
+
11
15
  ### **Altitude**
12
16
 
13
17
  The angular distance of a celestial object above the observer's local horizon, measured in degrees from 0° (horizon) to 90° (zenith).
@@ -106,7 +110,7 @@ The slow, continuous change in the orientation of Earth's rotation axis, causing
106
110
 
107
111
  ### **Refraction**
108
112
 
109
- 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.
113
+ 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. See the [Refraction page](refraction.md).
110
114
 
111
115
  ### **Right Ascension**
112
116
 
data/docs/observer.md CHANGED
@@ -32,6 +32,13 @@ It is also possible to give the following optional key arguments:
32
32
  sea level
33
33
  - `utc_offset`: local time difference with UTC. Check the [timezone specifiers]
34
34
  for the format.
35
+ - `temperature` (`Astronoby::Temperature`): the temperature of the air, 10 °C by
36
+ default
37
+ - `pressure` (`Astronoby::Pressure`): the atmospheric pressure, by default the
38
+ standard atmosphere brought to the observer's elevation
39
+
40
+ The temperature and the pressure are only used for atmospheric refraction, see
41
+ the [Refraction page].
35
42
 
36
43
  ```rb
37
44
  # Location: Alhambra, Spain
@@ -70,6 +77,7 @@ observer1 == observer2
70
77
  [timezone specifiers]: https://ruby-doc.org/3.4.1/Time.html#class-Time-label-Timezone+Specifiers
71
78
  [Angles page]: angles.md
72
79
  [Coordinates page]: coordinates.md#geodetic
80
+ [Refraction page]: refraction.md
73
81
 
74
82
  ## See also
75
83
 
@@ -0,0 +1,111 @@
1
+ # Refraction
2
+
3
+ The atmosphere bends the light of a body on its way to the observer, so the body appears higher in the sky than its true, geometric altitude. The difference is about half a degree at the horizon, five arcminutes at 10° of altitude and one arcminute at 45°, and it vanishes at the zenith.
4
+
5
+ Astronoby gives true altitudes by default. Refraction is applied on request, with the temperature and the pressure of the observer.
6
+
7
+ ## Requesting refraction
8
+
9
+ The places that return or search altitudes take a `refraction:` option, `false` by default:
10
+
11
+ ```rb
12
+ ephem = Astronoby::Ephem.load("inpop19a.bsp")
13
+ instant = Astronoby::Instant.from_time(Time.utc(2025, 10, 1, 20))
14
+ saturn = Astronoby::Saturn.new(ephem: ephem, instant: instant)
15
+
16
+ observer = Astronoby::Observer.new(
17
+ latitude: Astronoby::Angle.from_degrees(48.8566),
18
+ longitude: Astronoby::Angle.from_degrees(2.3522)
19
+ )
20
+
21
+ horizontal = saturn.observed_by(observer).horizontal(refraction: true)
22
+
23
+ horizontal.refracted?
24
+ # => true
25
+ ```
26
+
27
+ `HorizontalTransformation#apply` takes the same option, as described on the [Deep-sky Bodies page], and so does `AltitudeCrossingCalculator.new`, on the [Altitude crossings page]. With it, the altitudes the calculator searches for and returns are apparent ones.
28
+
29
+ ## Refracting horizontal coordinates
30
+
31
+ `Astronoby::Coordinates::Horizontal` knows whether its altitude is true or apparent, with `#refracted?`. `#refract` returns the same coordinates seen through the atmosphere, with the same azimuth and observer:
32
+
33
+ ```rb
34
+ true_horizontal = saturn.observed_by(observer).horizontal
35
+ true_horizontal.refracted?
36
+ # => false
37
+
38
+ apparent_horizontal = true_horizontal.refract
39
+ apparent_horizontal.refracted?
40
+ # => true
41
+ ```
42
+
43
+ Refracting coordinates that are already refracted raises an `Astronoby::IncompatibleArgumentsError`, as the refraction would be counted twice.
44
+
45
+ ## Atmospheric conditions
46
+
47
+ Refraction grows with the density of the air: it is larger when the air is cold and the pressure high. Both are read from the observer:
48
+
49
+ - `temperature` (`Astronoby::Temperature`): 10 °C by default
50
+ - `pressure` (`Astronoby::Pressure`): by default, the standard atmosphere of 1013.25 hPa brought to the observer's elevation with the barometric formula
51
+
52
+ ```rb
53
+ observer = Astronoby::Observer.new(
54
+ latitude: Astronoby::Angle.from_degrees(19.8207),
55
+ longitude: Astronoby::Angle.from_degrees(-155.4681),
56
+ elevation: Astronoby::Distance.from_meters(4205),
57
+ temperature: Astronoby::Temperature.from_celsius(-2),
58
+ pressure: Astronoby::Pressure.from_millibars(615)
59
+ )
60
+ ```
61
+
62
+ `Astronoby::Temperature` is built with `.from_celsius` or `.from_kelvins`, and `Astronoby::Pressure` with `.from_millibars`, `.from_hectopascals` or `.from_pascals`. With a pressure of zero there is no atmosphere and no refraction.
63
+
64
+ ## Refraction angle
65
+
66
+ `Astronoby::Refraction.angle` returns the refraction itself, to add to a true altitude:
67
+
68
+ ```rb
69
+ Astronoby::Refraction.angle(
70
+ altitude: Astronoby::Angle.from_degrees(10),
71
+ observer: observer
72
+ )
73
+ ```
74
+
75
+ ## Model
76
+
77
+ The refraction is computed with Bennett's formula, the one given by the Explanatory Supplement to the Astronomical Almanac and by Meeus in Astronomical Algorithms (chapter 16), and used by the USNO's NOVAS. It is scaled by the temperature and the pressure.
78
+
79
+ Bennett's formula takes the apparent altitude, while Astronoby computes the true one, so it is inverted. The inversion starts from Sæmundsson's formula, Meeus's direct inverse of Bennett's, and two Newton steps then land on the exact inverse to within a microarcsecond.
80
+
81
+ The formulas are fitted down to the horizon and are meaningless far below it, so below a true altitude of -1° the refraction is kept at its value there. The apparent altitude then always grows with the true altitude, which the altitude crossing search relies on.
82
+
83
+ From a high place the horizon is lower than the astronomical horizon, by about 0.5° at 300 m, 1° at 1100 m and 2° at 4000 m, so from above about 1100 m bodies can be seen below -1°. Their refraction is then kept at its value at -1°, and their apparent altitude can be too low by several arcminutes.
84
+
85
+ ## Accuracy
86
+
87
+ At 10 °C and 1013.25 hPa, compared with Skyfield, which inverts Bennett's formula the same way:
88
+
89
+ | True altitude | Astronoby | Skyfield |
90
+ |---|---|---|
91
+ | 0° | 28′ 59.98″ | 28′ 59.75″ |
92
+ | 1° | 21′ 48.78″ | 21′ 48.60″ |
93
+ | 5° | 9′ 39.63″ | 9′ 39.55″ |
94
+ | 10° | 5′ 21.66″ | 5′ 21.61″ |
95
+ | 45° | 59.82″ | 59.81″ |
96
+
97
+ The two agree to within 0.3″ from the horizon to the zenith, from -30 °C to 40 °C and from 600 hPa to 1050 hPa.
98
+
99
+ IMCCE's Miriade service uses another model. Brought to the same temperature and pressure, its refraction is 3 to 5% larger below 10° of altitude.
100
+
101
+ Near the horizon, the real refraction also depends on the temperature profile of the air along the line of sight, which no formula from ground conditions can know. It commonly differs from the computed value by several arcminutes there.
102
+
103
+ ## Rising, setting and twilight
104
+
105
+ Rise and set times do not use this model. They follow the usual convention of a body's centre being 34′ below the horizon, or 50′ for the Sun, whatever the weather, as described on the [Rise, transit and setting times page]. The model puts the apparent horizon at a true altitude of -34.6′ at the standard conditions, in line with that convention.
106
+
107
+ Twilight is defined on the Sun's true altitude, so it is computed without refraction.
108
+
109
+ [Deep-sky Bodies page]: deep_sky_bodies.md
110
+ [Altitude crossings page]: altitude_crossings.md
111
+ [Rise, transit and setting times page]: rise_transit_set_times.md
@@ -0,0 +1,126 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Astronoby
4
+ # The relative airmass, the length of the path light travels through the
5
+ # atmosphere, relative to the path at the zenith. It is 1 at the zenith and
6
+ # about 38 for a body that appears on the horizon.
7
+ #
8
+ # From a true, unrefracted altitude it follows A. T. Young, "Air mass and
9
+ # refraction", Applied Optics 33 (6), 1994. From an apparent altitude it
10
+ # follows F. Kasten and A. T. Young, "Revised optical air mass tables and
11
+ # approximation formula", Applied Optics 28 (22), 1989.
12
+ #
13
+ # @example Airmass of a body 30° above the horizon
14
+ # altitude = Astronoby::Angle.from_degrees(30)
15
+ # Astronoby::Airmass.from_true_altitude(altitude).value # => 1.9917...
16
+ #
17
+ class Airmass
18
+ include Comparable
19
+
20
+ # Young (1994) gives the airmass as a ratio of two polynomials of s, the
21
+ # sine of the true altitude:
22
+ #
23
+ # X = (1.002432 s² + 0.148386 s + 0.0096467) /
24
+ # (s³ + 0.149864 s² + 0.0102963 s + 0.000303978)
25
+ #
26
+ # Coefficients are listed from the constant term up.
27
+ YOUNG_NUMERATOR = [0.0096467, 0.148386, 1.002432].freeze
28
+ YOUNG_DENOMINATOR = [0.000303978, 0.0102963, 0.149864, 1.0].freeze
29
+
30
+ # Kasten and Young (1989) give the airmass from h, the apparent altitude in
31
+ # degrees, with their constants a, b and c:
32
+ #
33
+ # X = 1 / (sin h + a (h + b)^-c)
34
+ KASTEN_YOUNG_A = 0.50572
35
+ KASTEN_YOUNG_B = 6.07995
36
+ KASTEN_YOUNG_C = 1.6364
37
+
38
+ class << self
39
+ # Young's formula only covers true altitudes down to the horizon, but a
40
+ # body slightly below it is still seen above it, lifted by refraction.
41
+ # Given an observer, such an altitude is refracted with the observer's
42
+ # temperature and pressure and its airmass taken from the apparent
43
+ # altitude.
44
+ #
45
+ # @param altitude [Astronoby::Angle] true altitude, without refraction
46
+ # @param observer [Astronoby::Observer, nil] the observer, whose
47
+ # atmosphere tells whether a body below the true horizon is visible
48
+ # @return [Astronoby::Airmass, nil] the airmass, or nil below the
49
+ # horizon, the apparent one when an observer is given
50
+ def from_true_altitude(altitude, observer: nil)
51
+ if altitude.negative?
52
+ return unless observer
53
+
54
+ return from_apparent_altitude(
55
+ altitude + Refraction.angle(altitude: altitude, observer: observer)
56
+ )
57
+ end
58
+
59
+ sine = altitude.sin
60
+ new(
61
+ polynomial(YOUNG_NUMERATOR, sine) /
62
+ polynomial(YOUNG_DENOMINATOR, sine)
63
+ )
64
+ end
65
+
66
+ # @param altitude [Astronoby::Angle] apparent altitude, with refraction
67
+ # @return [Astronoby::Airmass, nil] the airmass, or nil below the horizon
68
+ def from_apparent_altitude(altitude)
69
+ return if altitude.negative?
70
+
71
+ new(
72
+ 1.0 / (
73
+ altitude.sin +
74
+ KASTEN_YOUNG_A *
75
+ (altitude.degrees + KASTEN_YOUNG_B)**-KASTEN_YOUNG_C
76
+ )
77
+ )
78
+ end
79
+
80
+ private
81
+
82
+ def polynomial(coefficients, variable)
83
+ coefficients.reverse.reduce(0.0) do |sum, coefficient|
84
+ sum * variable + coefficient
85
+ end
86
+ end
87
+ end
88
+
89
+ # @return [Float] the relative airmass
90
+ attr_reader :value
91
+
92
+ # @param value [Numeric] the relative airmass
93
+ # @raise [Astronoby::IncompatibleArgumentsError] if the value is not a
94
+ # positive number
95
+ def initialize(value)
96
+ unless value.is_a?(Numeric) && value.positive?
97
+ raise IncompatibleArgumentsError,
98
+ "Expected a positive airmass, got #{value.inspect}"
99
+ end
100
+
101
+ @value = value.to_f
102
+ freeze
103
+ end
104
+
105
+ # @return [Integer] hash value
106
+ def hash
107
+ [value, self.class].hash
108
+ end
109
+
110
+ # @param other [Astronoby::Airmass, Numeric] airmass or plain number to
111
+ # compare with
112
+ # @return [Integer, nil] -1, 0, or 1; nil if not comparable
113
+ def <=>(other)
114
+ case other
115
+ when self.class then value <=> other.value
116
+ when Numeric then value <=> other
117
+ end
118
+ end
119
+
120
+ # @param other [Object] object to compare with
121
+ # @return [Boolean] true if other is an Airmass of the same value
122
+ def eql?(other)
123
+ other.is_a?(self.class) && value == other.value
124
+ end
125
+ end
126
+ end
@@ -8,7 +8,8 @@ module Astronoby
8
8
  # @return [Astronoby::Angle] azimuth (measured from north, clockwise)
9
9
  attr_reader :azimuth
10
10
 
11
- # @return [Astronoby::Angle] altitude above the horizon
11
+ # @return [Astronoby::Angle] altitude above the horizon, true or
12
+ # apparent depending on {#refracted?}
12
13
  attr_reader :altitude
13
14
 
14
15
  # @return [Astronoby::Observer] the observer
@@ -17,14 +18,56 @@ module Astronoby
17
18
  # @param azimuth [Astronoby::Angle] azimuth
18
19
  # @param altitude [Astronoby::Angle] altitude
19
20
  # @param observer [Astronoby::Observer] the observer
21
+ # @param refracted [Boolean] whether the altitude includes atmospheric
22
+ # refraction
20
23
  def initialize(
21
24
  azimuth:,
22
25
  altitude:,
23
- observer:
26
+ observer:,
27
+ refracted: false
24
28
  )
25
29
  @azimuth = azimuth
26
30
  @altitude = altitude
27
31
  @observer = observer
32
+ @refracted = refracted ? true : false
33
+ end
34
+
35
+ # @return [Boolean] true if the altitude is the apparent one, with
36
+ # atmospheric refraction, false if it is the true, geometric one
37
+ def refracted?
38
+ @refracted
39
+ end
40
+
41
+ # @return [Astronoby::Airmass, nil] the airmass at this altitude, or nil
42
+ # below the apparent horizon
43
+ def airmass
44
+ if refracted?
45
+ Airmass.from_apparent_altitude(@altitude)
46
+ else
47
+ Airmass.from_true_altitude(@altitude, observer: @observer)
48
+ end
49
+ end
50
+
51
+ # Returns the same coordinates as seen through the atmosphere, with the
52
+ # refraction for the observer's temperature and pressure added to the
53
+ # altitude.
54
+ #
55
+ # @return [Astronoby::Coordinates::Horizontal] refracted coordinates
56
+ # @raise [Astronoby::IncompatibleArgumentsError] if the coordinates are
57
+ # already refracted
58
+ def refract
59
+ if refracted?
60
+ raise IncompatibleArgumentsError,
61
+ "The horizontal coordinates are already refracted"
62
+ end
63
+
64
+ self.class.new(
65
+ azimuth: @azimuth,
66
+ altitude: @altitude +
67
+ Refraction.angle(altitude: @altitude, observer: @observer),
68
+ observer: @observer,
69
+ refracted: true
70
+ )
28
71
  end
29
72
  end
30
73
  end
@@ -202,7 +202,9 @@ module Astronoby
202
202
  AltitudeExtreme.new(
203
203
  kind: culmination.kind,
204
204
  instant: Instant.from_terrestrial_time(culmination.tt),
205
- altitude: Angle.from_radians(altitude_at(culmination.tt))
205
+ altitude: Angle.from_radians(altitude_at(culmination.tt)),
206
+ refracted: @refraction,
207
+ observer: @observer
206
208
  )
207
209
  end
208
210
  end
@@ -232,19 +234,14 @@ module Astronoby
232
234
  latitude = @observer.latitude
233
235
  sin_altitude = latitude.sin * declination.sin +
234
236
  latitude.cos * declination.cos * hour_angle.cos
235
- altitude = Angle.asin(sin_altitude.clamp(-1.0, 1.0))
237
+ altitude = Angle.asin(sin_altitude.clamp(-1.0, 1.0)) +
238
+ Angle.from_radians(limb_offset(body))
236
239
 
237
240
  if @refraction
238
- altitude += Refraction.angle(
239
- coordinates: Coordinates::Horizontal.new(
240
- azimuth: Angle.zero,
241
- altitude: altitude,
242
- observer: @observer
243
- )
244
- )
241
+ altitude += Refraction.angle(altitude: altitude, observer: @observer)
245
242
  end
246
243
 
247
- altitude.radians + limb_offset(body)
244
+ altitude.radians
248
245
  end
249
246
 
250
247
  def limb_offset(body)
@@ -16,16 +16,40 @@ module Astronoby
16
16
  # @return [Astronoby::Instant] when the body crosses the meridian
17
17
  attr_reader :instant
18
18
 
19
- # @return [Astronoby::Angle] the altitude at that instant
19
+ # @return [Astronoby::Angle] the altitude at that instant, true or
20
+ # apparent depending on {#refracted?}
20
21
  attr_reader :altitude
21
22
 
22
23
  # @param kind [Symbol] +:upper_culmination+ or +:lower_culmination+
23
24
  # @param instant [Astronoby::Instant] when the body crosses the meridian
24
25
  # @param altitude [Astronoby::Angle] the altitude at that instant
25
- def initialize(kind:, instant:, altitude:)
26
+ # @param refracted [Boolean] whether the altitude includes atmospheric
27
+ # refraction
28
+ # @param observer [Astronoby::Observer, nil] the observer, whose
29
+ # atmosphere tells whether a body below the true horizon is visible
30
+ def initialize(kind:, instant:, altitude:, refracted: false, observer: nil)
26
31
  @kind = kind
27
32
  @instant = instant
28
33
  @altitude = altitude
34
+ @refracted = refracted ? true : false
35
+ @observer = observer
36
+ end
37
+
38
+ # @return [Boolean] true if the altitude is the apparent one, with
39
+ # atmospheric refraction, false if it is the true, geometric one
40
+ def refracted?
41
+ @refracted
42
+ end
43
+
44
+ # @return [Astronoby::Airmass, nil] the airmass at {#altitude}, so at the
45
+ # calculator's reference point, the limb when one is used, or nil below
46
+ # the apparent horizon
47
+ def airmass
48
+ if refracted?
49
+ Airmass.from_apparent_altitude(@altitude)
50
+ else
51
+ Airmass.from_true_altitude(@altitude, observer: @observer)
52
+ end
29
53
  end
30
54
  end
31
55
  end
@@ -64,11 +64,7 @@ module Astronoby
64
64
  observer: @observer
65
65
  )
66
66
 
67
- if refraction
68
- Refraction.correct_horizontal_coordinates(coordinates: horizontal)
69
- else
70
- horizontal
71
- end
67
+ refraction ? horizontal.refract : horizontal
72
68
  end
73
69
 
74
70
  private
@@ -3,12 +3,7 @@
3
3
  module Astronoby
4
4
  class Observer
5
5
  DEFAULT_ELEVATION = Distance.zero
6
- DEFAULT_TEMPERATURE = 283.15
7
- PRESSURE_AT_SEA_LEVEL = 1013.25
8
- PASCAL_PER_MILLIBAR = 0.01
9
- EARTH_GRAVITATIONAL_ACCELERATION = 9.80665
10
- MOLAR_MASS_OF_AIR = 0.0289644
11
- UNIVERSAL_GAS_CONSTANT = 8.31432
6
+ DEFAULT_TEMPERATURE = Temperature.from_celsius(10)
12
7
 
13
8
  # @return [Astronoby::Angle] geographic latitude
14
9
  attr_reader :latitude
@@ -22,10 +17,12 @@ module Astronoby
22
17
  # @return [Numeric, String] offset from Coordinated Universal Time
23
18
  attr_reader :utc_offset
24
19
 
25
- # @return [Numeric] temperature in kelvins
20
+ # @return [Astronoby::Temperature] temperature of the air at the observer's
21
+ # location
26
22
  attr_reader :temperature
27
23
 
28
- # @return [Numeric] atmospheric pressure in millibars
24
+ # @return [Astronoby::Pressure] atmospheric pressure at the observer's
25
+ # location
29
26
  attr_reader :pressure
30
27
 
31
28
  # @param latitude [Astronoby::Angle] geographic latitude of the observer
@@ -33,10 +30,13 @@ module Astronoby
33
30
  # @param elevation [Astronoby::Distance] geographic elevation (or altitude)
34
31
  # of the observer above sea level
35
32
  # @param utc_offset [Numeric, String] offset from Coordinated Universal Time
36
- # @param temperature [Numeric] temperature at the observer's location in
37
- # kelvins
38
- # @param pressure [Numeric] atmospheric pressure at the observer's
39
- # location in millibars
33
+ # @param temperature [Astronoby::Temperature] temperature of the air at the
34
+ # observer's location, 10 °C by default
35
+ # @param pressure [Astronoby::Pressure, nil] atmospheric pressure at the
36
+ # observer's location, derived from the elevation and the temperature by
37
+ # default
38
+ # @raise [Astronoby::IncompatibleArgumentsError] if the temperature or the
39
+ # pressure is not a value object
40
40
  def initialize(
41
41
  latitude:,
42
42
  longitude:,
@@ -49,8 +49,12 @@ module Astronoby
49
49
  @longitude = longitude
50
50
  @elevation = elevation
51
51
  @utc_offset = utc_offset
52
- @temperature = temperature
53
- @pressure = pressure || compute_pressure
52
+ @temperature = ensure_value_object!(:temperature, temperature, Temperature)
53
+ @pressure = ensure_value_object!(
54
+ :pressure,
55
+ pressure || Pressure.at_elevation(elevation, temperature: temperature),
56
+ Pressure
57
+ )
54
58
  end
55
59
 
56
60
  # Returns the observer's ECEF position vector (WGS-84 geodetic to ECEF).
@@ -118,20 +122,11 @@ module Astronoby
118
122
 
119
123
  private
120
124
 
121
- def compute_pressure
122
- @pressure ||= PRESSURE_AT_SEA_LEVEL * pressure_ratio
123
- end
124
-
125
- # Source:
126
- # Barometric formula
127
- # https://en.wikipedia.org/wiki/Barometric_formula
128
- def pressure_ratio
129
- term1 = EARTH_GRAVITATIONAL_ACCELERATION *
130
- MOLAR_MASS_OF_AIR *
131
- @elevation.meters
132
- term2 = UNIVERSAL_GAS_CONSTANT * @temperature
125
+ def ensure_value_object!(name, value, klass)
126
+ return value if value.is_a?(klass)
133
127
 
134
- Math.exp(-term1 / term2)
128
+ raise IncompatibleArgumentsError,
129
+ "Expected #{name} to be an #{klass}, got #{value.inspect}"
135
130
  end
136
131
 
137
132
  def polar_motion_matrix_for(instant)
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Astronoby
4
+ # Represents an atmospheric pressure with pascals as its internal
5
+ # representation.
6
+ #
7
+ # @example Create a pressure from millibars
8
+ # pressure = Astronoby::Pressure.from_millibars(1013.25)
9
+ # pressure.pascals # => 101325.0
10
+ #
11
+ class Pressure
12
+ include Comparable
13
+
14
+ PASCALS_PER_HECTOPASCAL = 100
15
+ STANDARD_ATMOSPHERE_IN_PASCALS = 101_325
16
+
17
+ EARTH_GRAVITATIONAL_ACCELERATION = 9.80665
18
+ MOLAR_MASS_OF_AIR = 0.0289644
19
+ UNIVERSAL_GAS_CONSTANT = 8.31432
20
+
21
+ class << self
22
+ # @param pascals [Numeric] the pressure in pascals
23
+ # @return [Astronoby::Pressure] a new Pressure
24
+ def from_pascals(pascals)
25
+ new(pascals)
26
+ end
27
+
28
+ # @param hectopascals [Numeric] the pressure in hectopascals
29
+ # @return [Astronoby::Pressure] a new Pressure
30
+ def from_hectopascals(hectopascals)
31
+ new(hectopascals * PASCALS_PER_HECTOPASCAL)
32
+ end
33
+ alias_method :from_millibars, :from_hectopascals
34
+
35
+ # @return [Astronoby::Pressure] the standard atmosphere at sea level,
36
+ # 1013.25 hPa
37
+ def standard_atmosphere
38
+ new(STANDARD_ATMOSPHERE_IN_PASCALS)
39
+ end
40
+
41
+ # The pressure of an isothermal atmosphere at an elevation above sea
42
+ # level, starting from the standard atmosphere.
43
+ #
44
+ # Source:
45
+ # Barometric formula
46
+ # https://en.wikipedia.org/wiki/Barometric_formula
47
+ #
48
+ # @param elevation [Astronoby::Distance] elevation above sea level
49
+ # @param temperature [Astronoby::Temperature] temperature of the air
50
+ # @return [Astronoby::Pressure] the pressure at that elevation
51
+ def at_elevation(elevation, temperature:)
52
+ exponent = -EARTH_GRAVITATIONAL_ACCELERATION *
53
+ MOLAR_MASS_OF_AIR *
54
+ elevation.meters /
55
+ (UNIVERSAL_GAS_CONSTANT * temperature.kelvins)
56
+
57
+ new(STANDARD_ATMOSPHERE_IN_PASCALS * Math.exp(exponent))
58
+ end
59
+ end
60
+
61
+ # @return [Numeric] the pressure in pascals
62
+ attr_reader :pascals
63
+
64
+ # @param pascals [Numeric] the pressure in pascals
65
+ # @raise [Astronoby::IncompatibleArgumentsError] if the pressure is
66
+ # negative
67
+ def initialize(pascals)
68
+ if pascals.negative?
69
+ raise IncompatibleArgumentsError,
70
+ "Expected a pressure of zero or more, got #{pascals} Pa"
71
+ end
72
+
73
+ @pascals = pascals
74
+ freeze
75
+ end
76
+
77
+ # @return [Float] the pressure in hectopascals
78
+ def hectopascals
79
+ @pascals / PASCALS_PER_HECTOPASCAL.to_f
80
+ end
81
+ alias_method :millibars, :hectopascals
82
+
83
+ # @return [Integer] hash value
84
+ def hash
85
+ [pascals.to_f, self.class].hash
86
+ end
87
+
88
+ # @param other [Astronoby::Pressure] pressure to compare with
89
+ # @return [Integer, nil] -1, 0, or 1; nil if not comparable
90
+ def <=>(other)
91
+ return unless other.is_a?(self.class)
92
+
93
+ pascals <=> other.pascals
94
+ end
95
+ alias_method :eql?, :==
96
+ end
97
+ end
@@ -94,11 +94,7 @@ module Astronoby
94
94
  observer: @observer
95
95
  )
96
96
 
97
- if refraction
98
- Refraction.correct_horizontal_coordinates(coordinates: horizontal)
99
- else
100
- horizontal
101
- end
97
+ refraction ? horizontal.refract : horizontal
102
98
  end
103
99
  end
104
100
  end
@@ -1,92 +1,94 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Astronoby
4
- # Computes atmospheric refraction corrections for horizontal coordinates.
4
+ # Atmospheric refraction: how much higher a body appears than its true,
5
+ # geometric altitude, because its light is bent through the atmosphere.
6
+ #
7
+ # It uses Bennett's formula, scaled for the temperature and the pressure of
8
+ # the air at the observer's location, as the Explanatory Supplement to the
9
+ # Astronomical Almanac and the USNO's NOVAS do. Bennett's formula
10
+ # takes the apparent altitude, so it is inverted to start from the true one.
11
+ #
12
+ # The inversion starts from Saemundsson's formula, Meeus's direct inverse of
13
+ # Bennett's, which is within a few arcseconds of it. Two Newton steps then
14
+ # land on the exact inverse to within a microarcsecond, from -30 °C to 40 °C
15
+ # and from 600 hPa to 1050 hPa. A fixed number of steps keeps the result a
16
+ # smooth function of the altitude, which the search for altitude crossings
17
+ # relies on.
18
+ #
19
+ # Below {LOWEST_ALTITUDE} the refraction is kept at its value there, as the
20
+ # formulas are meaningless far below the horizon. The apparent altitude then
21
+ # still grows with the true altitude, with no gap.
22
+ #
23
+ # Source:
24
+ # Title: Astronomical Algorithms
25
+ # Author: Jean Meeus
26
+ # Edition: 2nd edition
27
+ # Chapter: 16 - Atmospheric Refraction
5
28
  #
6
29
  # Source:
7
- # Title: Practical Astronomy with your Calculator or Spreadsheet
8
- # Authors: Peter Duffett-Smith and Jonathan Zwart
9
- # Edition: Cambridge University Press
10
- # Chapter: 37 - Refraction
11
- class Refraction
12
- LOW_ALTITUDE_BODY_ANGLE = Angle.from_degrees(15)
13
- ZENITH = Angle.from_degrees(90)
30
+ # Title: The Calculation of Astronomical Refraction in Marine Navigation
31
+ # Author: G. G. Bennett
32
+ # Edition: Journal of Navigation, 35, 1982, pp. 255-259
33
+ module Refraction
34
+ LOWEST_ALTITUDE = Angle.from_degrees(-1)
14
35
 
15
- # Computes the refraction angle for the given horizontal coordinates.
16
- #
17
- # @param coordinates [Astronoby::Coordinates::Horizontal] horizontal
18
- # coordinates
19
- # @return [Astronoby::Angle] the refraction angle
20
- def self.angle(coordinates:)
21
- new(coordinates).refraction_angle
22
- end
36
+ REFERENCE_PRESSURE = Pressure.from_millibars(1010)
37
+ REFERENCE_TEMPERATURE = Temperature.from_kelvins(283)
23
38
 
24
- # Returns horizontal coordinates corrected for atmospheric refraction.
25
- #
26
- # @param coordinates [Astronoby::Coordinates::Horizontal] horizontal
27
- # coordinates
28
- # @return [Astronoby::Coordinates::Horizontal] corrected coordinates
29
- def self.correct_horizontal_coordinates(coordinates:)
30
- new(coordinates).refract
31
- end
39
+ NEWTON_STEPS = 2
32
40
 
33
- # @param coordinates [Astronoby::Coordinates::Horizontal] horizontal
34
- # coordinates
35
- def initialize(coordinates)
36
- @coordinates = coordinates
37
- end
41
+ class << self
42
+ # @param altitude [Astronoby::Angle] true, unrefracted altitude
43
+ # @param observer [Astronoby::Observer] the observer, whose temperature
44
+ # and pressure scale the refraction
45
+ # @return [Astronoby::Angle] the refraction to add to the true altitude
46
+ # to get the apparent one
47
+ def angle(altitude:, observer:)
48
+ true_altitude = [altitude.degrees, LOWEST_ALTITUDE.degrees].max
49
+ factor = atmospheric_factor(observer)
50
+ refraction = factor * saemundsson(true_altitude)
38
51
 
39
- # Returns horizontal coordinates with refraction applied to the altitude.
40
- #
41
- # @return [Astronoby::Coordinates::Horizontal] corrected coordinates
42
- def refract
43
- Coordinates::Horizontal.new(
44
- azimuth: @coordinates.azimuth,
45
- altitude: @coordinates.altitude + refraction_angle,
46
- observer: @coordinates.observer
47
- )
48
- end
52
+ NEWTON_STEPS.times do
53
+ refraction = newton_step(refraction, true_altitude, factor)
54
+ end
49
55
 
50
- # Computes the refraction angle based on the observer's atmospheric
51
- # conditions and the body's altitude.
52
- #
53
- # @return [Astronoby::Angle] the refraction angle
54
- def refraction_angle
55
- if @coordinates.altitude > LOW_ALTITUDE_BODY_ANGLE
56
- high_altitude_angle
57
- else
58
- low_altitude_angle
56
+ Angle.from_degrees(refraction)
59
57
  end
60
- end
61
58
 
62
- private
59
+ private
63
60
 
64
- def pressure
65
- @_pressure ||= @coordinates.observer.pressure
66
- end
67
-
68
- def temperature
69
- @_temperature ||= @coordinates.observer.temperature
70
- end
61
+ # One Newton step towards the refraction R, in degrees, that solves
62
+ # R = factor * Bennett(true altitude + R).
63
+ def newton_step(refraction, true_altitude, factor)
64
+ apparent_altitude = true_altitude + refraction
65
+ shifted_altitude = apparent_altitude + 4.4
66
+ cotangent = 1.0 / tan_of_degrees(
67
+ apparent_altitude + 7.31 / shifted_altitude
68
+ )
69
+ bennett = cotangent / Constants::ARCMINUTES_PER_DEGREE
70
+ bennett_slope = -(1 + cotangent**2) *
71
+ (1 - 7.31 / shifted_altitude**2) *
72
+ Math::PI / Constants::PI_IN_DEGREES /
73
+ Constants::ARCMINUTES_PER_DEGREE
71
74
 
72
- def altitude_in_degrees
73
- @_altitude_in_degrees ||= @coordinates.altitude.degrees
74
- end
75
+ residual = refraction - factor * bennett
76
+ refraction - residual / (1 - factor * bennett_slope)
77
+ end
75
78
 
76
- def high_altitude_angle
77
- zenith_angle = ZENITH - @coordinates.altitude
78
- Angle.from_degrees(0.00452 * pressure * zenith_angle.tan / temperature)
79
- end
79
+ def saemundsson(true_altitude)
80
+ argument = true_altitude + 10.3 / (true_altitude + 5.11)
81
+ 1.02 / tan_of_degrees(argument) / Constants::ARCMINUTES_PER_DEGREE
82
+ end
80
83
 
81
- def low_altitude_angle
82
- term1 = pressure * (
83
- 0.1594 + 0.0196 * altitude_in_degrees + 0.00002 * altitude_in_degrees**2
84
- )
85
- term2 = temperature * (
86
- 1 + 0.505 * altitude_in_degrees + 0.0845 * altitude_in_degrees**2
87
- )
84
+ def tan_of_degrees(degrees)
85
+ Math.tan(degrees * Math::PI / Constants::PI_IN_DEGREES)
86
+ end
88
87
 
89
- Angle.from_degrees(term1 / term2)
88
+ def atmospheric_factor(observer)
89
+ observer.pressure.pascals.fdiv(REFERENCE_PRESSURE.pascals) *
90
+ REFERENCE_TEMPERATURE.kelvins.fdiv(observer.temperature.kelvins)
91
+ end
90
92
  end
91
93
  end
92
94
  end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Astronoby
4
+ # Represents a temperature with kelvins as its internal representation.
5
+ #
6
+ # @example Create a temperature from degrees Celsius
7
+ # temperature = Astronoby::Temperature.from_celsius(10)
8
+ # temperature.kelvins # => 283.15
9
+ #
10
+ class Temperature
11
+ include Comparable
12
+
13
+ ZERO_CELSIUS_IN_KELVINS = 273.15
14
+
15
+ class << self
16
+ # @param kelvins [Numeric] the temperature in kelvins
17
+ # @return [Astronoby::Temperature] a new Temperature
18
+ def from_kelvins(kelvins)
19
+ new(kelvins)
20
+ end
21
+
22
+ # @param celsius [Numeric] the temperature in degrees Celsius
23
+ # @return [Astronoby::Temperature] a new Temperature
24
+ def from_celsius(celsius)
25
+ new(celsius + ZERO_CELSIUS_IN_KELVINS)
26
+ end
27
+ end
28
+
29
+ # @return [Numeric] the temperature in kelvins
30
+ attr_reader :kelvins
31
+
32
+ # @param kelvins [Numeric] the temperature in kelvins
33
+ # @raise [Astronoby::IncompatibleArgumentsError] if the temperature is not
34
+ # above absolute zero
35
+ def initialize(kelvins)
36
+ unless kelvins.positive?
37
+ raise IncompatibleArgumentsError,
38
+ "Expected a temperature above absolute zero, got #{kelvins} K"
39
+ end
40
+
41
+ @kelvins = kelvins
42
+ freeze
43
+ end
44
+
45
+ # @return [Numeric] the temperature in degrees Celsius
46
+ def celsius
47
+ @kelvins - ZERO_CELSIUS_IN_KELVINS
48
+ end
49
+
50
+ # @return [Integer] hash value
51
+ def hash
52
+ [kelvins.to_f, self.class].hash
53
+ end
54
+
55
+ # @param other [Astronoby::Temperature] temperature to compare with
56
+ # @return [Integer, nil] -1, 0, or 1; nil if not comparable
57
+ def <=>(other)
58
+ return unless other.is_a?(self.class)
59
+
60
+ kelvins <=> other.kelvins
61
+ end
62
+ alias_method :eql?, :==
63
+ end
64
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Astronoby
4
- VERSION = "0.11.1"
4
+ VERSION = "0.12.0"
5
5
  end
data/lib/astronoby.rb CHANGED
@@ -13,6 +13,9 @@ require "astronoby/constellations/data"
13
13
  require "astronoby/constellations/finder"
14
14
  require "astronoby/distance"
15
15
  require "astronoby/duration"
16
+ require "astronoby/pressure"
17
+ require "astronoby/temperature"
18
+ require "astronoby/airmass"
16
19
  require "astronoby/center"
17
20
  require "astronoby/body"
18
21
  require "astronoby/position"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: astronoby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.1
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rémy Hannequin
@@ -18,7 +18,7 @@ dependencies:
18
18
  version: '0.5'
19
19
  - - ">="
20
20
  - !ruby/object:Gem::Version
21
- version: 0.5.1
21
+ version: 0.5.2
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -28,7 +28,7 @@ dependencies:
28
28
  version: '0.5'
29
29
  - - ">="
30
30
  - !ruby/object:Gem::Version
31
- version: 0.5.1
31
+ version: 0.5.2
32
32
  - !ruby/object:Gem::Dependency
33
33
  name: horologium
34
34
  requirement: !ruby/object:Gem::Requirement
@@ -215,11 +215,13 @@ files:
215
215
  - docs/observer.md
216
216
  - docs/planetary_phenomena.md
217
217
  - docs/reference_frames.md
218
+ - docs/refraction.md
218
219
  - docs/rise_transit_set_times.md
219
220
  - docs/solar_system_bodies.md
220
221
  - docs/twilight_times.md
221
222
  - lib/astronoby.rb
222
223
  - lib/astronoby/aberration.rb
224
+ - lib/astronoby/airmass.rb
223
225
  - lib/astronoby/angle.rb
224
226
  - lib/astronoby/angles/dms.rb
225
227
  - lib/astronoby/angles/hms.rb
@@ -303,6 +305,7 @@ files:
303
305
  - lib/astronoby/orientation.rb
304
306
  - lib/astronoby/position.rb
305
307
  - lib/astronoby/precession.rb
308
+ - lib/astronoby/pressure.rb
306
309
  - lib/astronoby/reference_frame.rb
307
310
  - lib/astronoby/reference_frames/apparent.rb
308
311
  - lib/astronoby/reference_frames/astrometric.rb
@@ -314,6 +317,7 @@ files:
314
317
  - lib/astronoby/root_finder.rb
315
318
  - lib/astronoby/rotation.rb
316
319
  - lib/astronoby/stellar_propagation.rb
320
+ - lib/astronoby/temperature.rb
317
321
  - lib/astronoby/time/greenwich_apparent_sidereal_time.rb
318
322
  - lib/astronoby/time/greenwich_mean_sidereal_time.rb
319
323
  - lib/astronoby/time/greenwich_sidereal_time.rb