skymap 0.2.0 → 0.3.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: 2a51ef1b61aec62bb35240049a14adc40f006027f59fc30178eb973791901094
4
- data.tar.gz: 1f8a1488c057a526bf1eaa7f36cb24fa78fc903e0a957fd6c946a1189ddebad6
3
+ metadata.gz: 36a82d2da6f139662ddad63ac5f7a61d4228d2665106c7102a828710cf3da940
4
+ data.tar.gz: 446b8d777d47bc92fe8878247f61d45168f0e469180d779d304b3e66da5cb185
5
5
  SHA512:
6
- metadata.gz: 3151561266fea54c8845be6747e32d511da079ff8f0616bed97d359e39cadeddcb72d46e79f9f94a3dd8bbd27f00dd7598db65ef2a008ee68366978c1993537d
7
- data.tar.gz: 205fab1dc18044a3117bc7cdd291ff18aaf5c07e47cc77e72f306acbaf1166b2b34b0b0edacc8676340d6df8b6afe96e5e09f1ad6ed9d8e96966ab38a7b51ab4
6
+ metadata.gz: 3703c46d73bdad50017a6b00d06038ecb8876f7d7522b2699db3c1793d5e547e48511e372979be603ebf618bd6d0448140821e71e3397ec9c6b43eae58c18d88
7
+ data.tar.gz: e842f5ebbc50609e9904ac20a0f284286277b9d96eb3b24c82ed50764a3452412f6384bbb9e64592e25f54b3cc7bf5b40d2f772fb532fa1be4720f44e8e890a1
data/CHANGELOG.md CHANGED
@@ -7,6 +7,38 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.3.0] - 2026-11-01
11
+
12
+ ### Added
13
+
14
+ - `Skymap::Layers::Ecliptic` draws the ecliptic, the line the Sun follows in
15
+ the sky, stopping at the horizon
16
+ - `Skymap::Layers::Planets` draws the planets, from Mercury to Neptune, sized
17
+ by their magnitude, down to a `magnitude_limit:` (5 by default), from an
18
+ ephemeris given with `ephem:`, and writes their names with `labels: true`
19
+ or the names given with `names:`
20
+ - `Skymap::Layers::Sun` draws the Sun where it is in the sky, from an ephemeris
21
+ given with `ephem:`
22
+ - `Skymap::Layers::ConstellationNames` writes the name of each constellation in
23
+ the middle of its stars, from `Skymap::Catalog::ConstellationNames` or the
24
+ names given with `names:`
25
+ - `Skymap::Catalog::ConstellationNames` gives the English name of each of the
26
+ 88 IAU constellations
27
+
28
+ ### Changed
29
+
30
+ - `Skymap::Canvas` raises an `ArgumentError` when the padding is negative or
31
+ leaves no room for the sky
32
+ - Rendering is about 20 times faster: the precession, nutation and sidereal
33
+ time are computed once per chart instead of once per point, using
34
+ `Astronoby::HorizontalTransformation`
35
+ - Skymap requires Astronoby 0.11 or later
36
+
37
+ ### Fixed
38
+
39
+ - The catalogs give an enumerator when `each` is called without a block,
40
+ instead of raising a `LocalJumpError`
41
+
10
42
  ## [0.2.0] - 2026-10-27
11
43
 
12
44
  ### Added
@@ -47,7 +79,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
47
79
 
48
80
  - Initial release to reserve the gem name on RubyGems.org
49
81
 
50
- [Unreleased]: https://github.com/rhannequin/skymap/compare/v0.2.0...HEAD
82
+ [Unreleased]: https://github.com/rhannequin/skymap/compare/v0.3.0...HEAD
83
+ [0.3.0]: https://github.com/rhannequin/skymap/compare/v0.2.0...v0.3.0
51
84
  [0.2.0]: https://github.com/rhannequin/skymap/compare/v0.1.0...v0.2.0
52
85
  [0.1.0]: https://github.com/rhannequin/skymap/compare/v0.0.1...v0.1.0
53
86
  [0.0.1]: https://github.com/rhannequin/skymap/releases/tag/v0.0.1
data/README.md CHANGED
@@ -9,7 +9,7 @@ Skymap is a Ruby library for generating maps of the sky.
9
9
  <img
10
10
  src="https://raw.githubusercontent.com/rhannequin/skymap/main/sky_map.svg"
11
11
  width="480"
12
- alt="The sky over Paris on September 24, 2026 at 22:00 UTC, with the stars, the constellation lines, the constellation boundaries and the Moon"
12
+ alt="The sky over Paris on September 24, 2026 at 22:00 UTC, with the stars, the constellation lines, boundaries and names, the ecliptic, the Moon and Saturn"
13
13
  >
14
14
  </p>
15
15
 
@@ -133,6 +133,40 @@ end
133
133
  Skymap::Layers::ConstellationLines.new(lines: asterisms, stars: stars)
134
134
  ```
135
135
 
136
+ #### Constellation names
137
+
138
+ `Skymap::Layers::ConstellationNames` writes the name of each constellation in
139
+ the middle of its stars. It takes the same lines and stars as the
140
+ constellation lines layer, since the lines tell which stars belong to which
141
+ constellation:
142
+
143
+ ```ruby
144
+ lines = Skymap::Catalog::ConstellationLines.new.to_a
145
+
146
+ Skymap::Layers::ConstellationNames.new(lines: lines, stars: stars)
147
+ ```
148
+
149
+ Reading the lines into an array with `to_a`, once, saves the layers from
150
+ reading the file again each.
151
+
152
+ A constellation is named when more than half of its stars are above the
153
+ horizon. When its figure is in several parts, such as Serpens, the name goes in
154
+ the middle of the biggest part that is above the horizon. Mensa and
155
+ Microscopium have no lines, so they have no name on the map.
156
+
157
+ The names are in English, from `Skymap::Catalog::ConstellationNames`. Use
158
+ `names:` to write them differently: it takes anything that gives a name from
159
+ the IAU abbreviation of a constellation, such as a hash. A constellation
160
+ without a name is left out:
161
+
162
+ ```ruby
163
+ Skymap::Layers::ConstellationNames.new(
164
+ lines: lines,
165
+ stars: stars,
166
+ names: {"UMa" => "Grande Ourse", "UMi" => "Petite Ourse"}
167
+ )
168
+ ```
169
+
136
170
  #### Moon
137
171
 
138
172
  `Skymap::Layers::Moon` draws the Moon where it is in the sky, with its phase.
@@ -155,6 +189,70 @@ The Moon is drawn larger than it is, as on most sky maps: at its true size it
155
189
  would be a dot as small as the faintest stars. Its radius is 3% of the radius
156
190
  of the sky. When the center of the Moon is below the horizon, it is left out.
157
191
 
192
+ #### Sun
193
+
194
+ `Skymap::Layers::Sun` draws the Sun where it is in the sky. Like the Moon, it
195
+ needs an ephemeris (see [Moon](#moon)):
196
+
197
+ ```ruby
198
+ Skymap::Layers::Sun.new(ephem: ephem)
199
+ ```
200
+
201
+ The Sun is drawn larger than it is, at the same size as the Moon: 3% of the
202
+ radius of the sky. When the center of the Sun is below the horizon, it is left
203
+ out.
204
+
205
+ #### Planets
206
+
207
+ `Skymap::Layers::Planets` draws the planets, from Mercury to Neptune, where
208
+ they are in the sky. They need an ephemeris too (see [Moon](#moon)). A planet
209
+ is drawn as a star would be, bigger the brighter it is, with a warm tint so it
210
+ stands out from the stars:
211
+
212
+ ```ruby
213
+ Skymap::Layers::Planets.new(ephem: ephem)
214
+ ```
215
+
216
+ As for the stars, only planets of magnitude 5 or brighter are drawn by
217
+ default, which leaves out Uranus and Neptune. Use `magnitude_limit:` to draw
218
+ more or fewer planets. The magnitude of a planet changes over time, so a
219
+ planet can come in and out of the map:
220
+
221
+ ```ruby
222
+ Skymap::Layers::Planets.new(ephem: ephem, magnitude_limit: 6)
223
+ ```
224
+
225
+ Planets below the horizon are left out.
226
+
227
+ Use `labels: true` to write the name of each planet next to it, on the side of
228
+ the center of the map so it stays inside the sky:
229
+
230
+ ```ruby
231
+ Skymap::Layers::Planets.new(ephem: ephem, labels: true)
232
+ ```
233
+
234
+ The names are in English. Use `names:` to write them differently, with a hash
235
+ of the planets (`:mercury`, `:venus`, `:mars`, `:jupiter`, `:saturn`,
236
+ `:uranus` and `:neptune`). A planet without a name is drawn without it:
237
+
238
+ ```ruby
239
+ Skymap::Layers::Planets.new(
240
+ ephem: ephem,
241
+ labels: true,
242
+ names: {saturn: "Saturne", jupiter: "Jupiter"}
243
+ )
244
+ ```
245
+
246
+ #### Ecliptic
247
+
248
+ `Skymap::Layers::Ecliptic` draws the ecliptic, the line the Sun follows in the
249
+ sky over a year. The Moon and the planets are always close to it. It needs no
250
+ data, and it stops at the horizon:
251
+
252
+ ```ruby
253
+ Skymap::Layers::Ecliptic.new
254
+ ```
255
+
158
256
  #### Cardinal directions
159
257
 
160
258
  `Skymap::Layers::CardinalDirections` labels the cardinal directions (N, E, S,
@@ -205,6 +303,12 @@ The file was transcribed once from the vector PDF of each map, by matching the
205
303
  ends of the lines drawn on the maps to the stars of the catalog, and checked
206
304
  against the maps. It is not regenerated by a script.
207
305
 
306
+ ### Constellation names
307
+
308
+ `data/constellations/iau/names.csv` gives the English name of each of the 88
309
+ IAU constellations from its IAU abbreviation, as listed by the International
310
+ Astronomical Union.
311
+
208
312
  ### Constellation boundaries
209
313
 
210
314
  `data/constellations/iau/boundaries.csv` holds the borders between the 88 IAU
@@ -233,13 +337,13 @@ borders and precesses them to J2000 with Astronoby.
233
337
 
234
338
  ### Ephemeris of the tests
235
339
 
236
- The tests of the Moon use `spec/fixtures/de440s_moon_2025_2030_excerpt.bsp`, an
237
- excerpt of DE440s, the planetary and lunar ephemeris of the [Jet Propulsion
238
- Laboratory][jpl-ephemerides], distributed by [NAIF][naif]. It only keeps the
239
- Earth-Moon barycenter, the Sun, the Moon and the Earth, from 2025 to 2030. As
240
- NAIF asks for modified kernels, its comment area names this project as the
241
- last to modify it, and points to the original kernel. It is not part of the
242
- gem.
340
+ The tests of the Sun, the Moon and the planets use
341
+ `spec/fixtures/de440s_2025_2030_excerpt.bsp`, an excerpt of DE440s, the
342
+ planetary and lunar ephemeris of the [Jet Propulsion Laboratory][jpl-ephemerides],
343
+ distributed by [NAIF][naif]. It only keeps the barycenters of the planets, the
344
+ Sun, the Moon and the Earth, from 2025 to 2030. As NAIF asks for modified
345
+ kernels, its comment area names this project as the last to modify it, and
346
+ points to the original kernel. It is not part of the gem.
243
347
 
244
348
  > Park, R. S., Folkner, W. M., Williams, J. G., Boggs, D. H., 2021, _The JPL
245
349
  > Planetary and Lunar Ephemerides DE440 and DE441_, The Astronomical Journal,
@@ -0,0 +1,89 @@
1
+ constellation,name
2
+ And,Andromeda
3
+ Ant,Antlia
4
+ Aps,Apus
5
+ Aqr,Aquarius
6
+ Aql,Aquila
7
+ Ara,Ara
8
+ Ari,Aries
9
+ Aur,Auriga
10
+ Boo,Boötes
11
+ Cae,Caelum
12
+ Cam,Camelopardalis
13
+ Cnc,Cancer
14
+ CVn,Canes Venatici
15
+ CMa,Canis Major
16
+ CMi,Canis Minor
17
+ Cap,Capricornus
18
+ Car,Carina
19
+ Cas,Cassiopeia
20
+ Cen,Centaurus
21
+ Cep,Cepheus
22
+ Cet,Cetus
23
+ Cha,Chamaeleon
24
+ Cir,Circinus
25
+ Col,Columba
26
+ Com,Coma Berenices
27
+ CrA,Corona Australis
28
+ CrB,Corona Borealis
29
+ Crv,Corvus
30
+ Crt,Crater
31
+ Cru,Crux
32
+ Cyg,Cygnus
33
+ Del,Delphinus
34
+ Dor,Dorado
35
+ Dra,Draco
36
+ Equ,Equuleus
37
+ Eri,Eridanus
38
+ For,Fornax
39
+ Gem,Gemini
40
+ Gru,Grus
41
+ Her,Hercules
42
+ Hor,Horologium
43
+ Hya,Hydra
44
+ Hyi,Hydrus
45
+ Ind,Indus
46
+ Lac,Lacerta
47
+ Leo,Leo
48
+ LMi,Leo Minor
49
+ Lep,Lepus
50
+ Lib,Libra
51
+ Lup,Lupus
52
+ Lyn,Lynx
53
+ Lyr,Lyra
54
+ Men,Mensa
55
+ Mic,Microscopium
56
+ Mon,Monoceros
57
+ Mus,Musca
58
+ Nor,Norma
59
+ Oct,Octans
60
+ Oph,Ophiuchus
61
+ Ori,Orion
62
+ Pav,Pavo
63
+ Peg,Pegasus
64
+ Per,Perseus
65
+ Phe,Phoenix
66
+ Pic,Pictor
67
+ Psc,Pisces
68
+ PsA,Piscis Austrinus
69
+ Pup,Puppis
70
+ Pyx,Pyxis
71
+ Ret,Reticulum
72
+ Sge,Sagitta
73
+ Sgr,Sagittarius
74
+ Sco,Scorpius
75
+ Scl,Sculptor
76
+ Sct,Scutum
77
+ Ser,Serpens
78
+ Sex,Sextans
79
+ Tau,Taurus
80
+ Tel,Telescopium
81
+ Tri,Triangulum
82
+ TrA,Triangulum Australe
83
+ Tuc,Tucana
84
+ UMa,Ursa Major
85
+ UMi,Ursa Minor
86
+ Vel,Vela
87
+ Vir,Virgo
88
+ Vol,Volans
89
+ Vul,Vulpecula
data/lib/skymap/canvas.rb CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  module Skymap
4
4
  Canvas = Data.define(:size, :padding) do
5
+ def initialize(size:, padding:)
6
+ unless padding >= 0 && padding < size / 2.0
7
+ raise ArgumentError,
8
+ "padding must not be negative and must be less than half the size"
9
+ end
10
+
11
+ super
12
+ end
13
+
5
14
  def center
6
15
  Point.new(x: size / 2.0, y: size / 2.0)
7
16
  end
@@ -13,6 +13,8 @@ module Skymap
13
13
  )
14
14
 
15
15
  def each
16
+ return enum_for(:each) unless block_given?
17
+
16
18
  CSV.foreach(PATH, headers: true).chunk_while do |previous, row|
17
19
  previous["border"] == row["border"]
18
20
  end.each do |rows|
@@ -13,6 +13,8 @@ module Skymap
13
13
  )
14
14
 
15
15
  def each
16
+ return enum_for(:each) unless block_given?
17
+
16
18
  CSV.foreach(PATH, headers: true) do |row|
17
19
  yield line_from(row)
18
20
  end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "csv"
4
+
5
+ module Skymap
6
+ module Catalog
7
+ class ConstellationNames
8
+ PATH = File.expand_path(
9
+ "../../../data/constellations/iau/names.csv",
10
+ __dir__
11
+ )
12
+
13
+ def [](abbreviation)
14
+ names[abbreviation]
15
+ end
16
+
17
+ private
18
+
19
+ def names
20
+ @names ||= CSV
21
+ .read(PATH, headers: true, encoding: "UTF-8")
22
+ .to_h { |row| [row["constellation"], row["name"]] }
23
+ end
24
+ end
25
+ end
26
+ end
@@ -10,6 +10,8 @@ module Skymap
10
10
  PATH = File.expand_path("../../../data/stars.csv", __dir__)
11
11
 
12
12
  def each
13
+ return enum_for(:each) unless block_given?
14
+
13
15
  CSV.foreach(PATH, headers: true) do |row|
14
16
  yield star_from(row)
15
17
  end
@@ -8,6 +8,10 @@ module Skymap
8
8
  @observer = observer
9
9
  @instant = instant
10
10
  @canvas = canvas
11
+ @transformation = Astronoby::HorizontalTransformation.new(
12
+ observer: observer,
13
+ instant: instant
14
+ )
11
15
  @horizontal = {}
12
16
  @projections = {}
13
17
  end
@@ -23,11 +27,7 @@ module Skymap
23
27
  coordinates.epoch
24
28
  ]
25
29
 
26
- @horizontal[key] ||= Astronoby::DeepSkyObject
27
- .new(equatorial_coordinates: coordinates)
28
- .at(@instant)
29
- .observed_by(@observer)
30
- .horizontal
30
+ @horizontal[key] ||= @transformation.apply(coordinates)
31
31
  end
32
32
 
33
33
  def position(star)
@@ -28,5 +28,46 @@ module Skymap
28
28
  azimuth: Astronoby::Angle.from_radians(Math.atan2(y, x))
29
29
  )
30
30
  end
31
+
32
+ def visible_runs(context, coordinates)
33
+ horizontals = coordinates.map do |point|
34
+ context.horizontal_coordinates(point)
35
+ end
36
+ path = [position(context, horizontals.first)] +
37
+ horizontals.each_cons(2).flat_map do |from, to|
38
+ crossing_point(context, from, to) + [position(context, to)]
39
+ end
40
+
41
+ path.chunk { |point| !point.nil? }.filter_map do |visible, points|
42
+ points if visible && points.size > 1
43
+ end
44
+ end
45
+
46
+ def position(context, horizontal)
47
+ return if below?(horizontal)
48
+
49
+ context.project(
50
+ altitude: horizontal.altitude,
51
+ azimuth: horizontal.azimuth
52
+ )
53
+ end
54
+
55
+ def crossing_point(context, from, to)
56
+ return [] if below?(from) == below?(to)
57
+
58
+ above, below = below?(from) ? [to, from] : [from, to]
59
+ [
60
+ project(
61
+ context,
62
+ crossing(direction([above]), direction([below]))
63
+ )
64
+ ]
65
+ end
66
+
67
+ def below?(horizontal)
68
+ horizontal.altitude.negative?
69
+ end
70
+
71
+ private_class_method :position, :crossing_point, :below?
31
72
  end
32
73
  end
@@ -13,55 +13,11 @@ module Skymap
13
13
  width = LINE_WIDTH_RATIO * context.canvas.radius
14
14
 
15
15
  @boundaries.flat_map do |boundary|
16
- visible_runs(context, boundary.points).map do |points|
16
+ Horizon.visible_runs(context, boundary.points).map do |points|
17
17
  Renderer::Boundary.new(points: points, width: width)
18
18
  end
19
19
  end
20
20
  end
21
-
22
- private
23
-
24
- def visible_runs(context, coordinates)
25
- horizontals = coordinates.map do |point|
26
- context.horizontal_coordinates(point)
27
- end
28
- path = [position(context, horizontals.first)] +
29
- horizontals.each_cons(2).flat_map do |from, to|
30
- crossing(context, from, to) + [position(context, to)]
31
- end
32
-
33
- path.chunk { |point| !point.nil? }.filter_map do |visible, points|
34
- points if visible && points.size > 1
35
- end
36
- end
37
-
38
- def position(context, horizontal)
39
- return if below?(horizontal)
40
-
41
- context.project(
42
- altitude: horizontal.altitude,
43
- azimuth: horizontal.azimuth
44
- )
45
- end
46
-
47
- def crossing(context, from, to)
48
- return [] if below?(from) == below?(to)
49
-
50
- above, below = below?(from) ? [to, from] : [from, to]
51
- [
52
- Horizon.project(
53
- context,
54
- Horizon.crossing(
55
- Horizon.direction([above]),
56
- Horizon.direction([below])
57
- )
58
- )
59
- ]
60
- end
61
-
62
- def below?(horizontal)
63
- horizontal.altitude.negative?
64
- end
65
21
  end
66
22
  end
67
23
  end
@@ -11,7 +11,7 @@ module Skymap
11
11
  end
12
12
 
13
13
  def elements(context)
14
- stars_by_hr = @stars.to_h { |star| [star.hr, star] }
14
+ stars_by_hr = Star.by_hr(@stars)
15
15
 
16
16
  @lines.filter_map do |line|
17
17
  ends = [line.from, line.to].map { |hrs| stars_by_hr.values_at(*hrs) }
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Skymap
4
+ module Layers
5
+ class ConstellationNames
6
+ def initialize(lines:, stars:, names: Catalog::ConstellationNames.new)
7
+ @lines = lines
8
+ @stars = stars
9
+ @names = names
10
+ end
11
+
12
+ def elements(context)
13
+ stars_by_hr = Star.by_hr(@stars)
14
+
15
+ @lines.group_by(&:constellation).filter_map do |abbreviation, lines|
16
+ name = @names[abbreviation]
17
+ next unless name
18
+
19
+ parts = parts(lines).map { |hrs| stars_by_hr.values_at(*hrs).compact }
20
+ risen = parts.map do |stars|
21
+ stars.reject { |star| context.horizontal(star).altitude.negative? }
22
+ end
23
+ next if risen.sum(&:size) * 2 <= parts.sum(&:size)
24
+
25
+ biggest = risen.max_by(&:size)
26
+ Renderer::Caption.new(
27
+ position: Point.midpoint(biggest.map { |s| context.position(s) }),
28
+ text: name,
29
+ size: Renderer::Caption.size_for(context.canvas),
30
+ kind: :constellation
31
+ )
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def parts(lines)
38
+ lines.each_with_object([]) do |line, parts|
39
+ hrs = line.from + line.to
40
+ joined, others = parts.partition { |part| part.intersect?(hrs) }
41
+ parts.replace(others << (joined.flatten + hrs).uniq)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Skymap
4
+ module Layers
5
+ class Ecliptic
6
+ LINE_WIDTH_RATIO = 0.0025
7
+ STEP_IN_DEGREES = 1
8
+
9
+ def initialize
10
+ obliquity = Astronoby::MeanObliquity.obliquity_of_reference
11
+ points = (0...360).step(STEP_IN_DEGREES).map do |degrees|
12
+ point_at(Astronoby::Angle.from_degrees(degrees), obliquity)
13
+ end
14
+ @points = points + points.first(1)
15
+ end
16
+
17
+ def elements(context)
18
+ width = LINE_WIDTH_RATIO * context.canvas.radius
19
+
20
+ joined(Horizon.visible_runs(context, @points)).map do |points|
21
+ Renderer::Ecliptic.new(points: points, width: width)
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def point_at(longitude, obliquity)
28
+ Astronoby::Coordinates::Equatorial.new(
29
+ right_ascension: Astronoby::Angle.from_radians(
30
+ Math.atan2(longitude.sin * obliquity.cos, longitude.cos)
31
+ ),
32
+ declination: Astronoby::Angle.asin(longitude.sin * obliquity.sin),
33
+ epoch: Astronoby::JulianDate::J2000
34
+ )
35
+ end
36
+
37
+ def joined(runs)
38
+ return runs unless runs.size > 1 && runs.first.first == runs.last.last
39
+
40
+ [runs.last + runs.first.drop(1)] + runs[1...-1]
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Skymap
4
+ module Layers
5
+ class Planets
6
+ DEFAULT_MAGNITUDE_LIMIT = 5
7
+ BODIES = {
8
+ mercury: Astronoby::Mercury,
9
+ venus: Astronoby::Venus,
10
+ mars: Astronoby::Mars,
11
+ jupiter: Astronoby::Jupiter,
12
+ saturn: Astronoby::Saturn,
13
+ uranus: Astronoby::Uranus,
14
+ neptune: Astronoby::Neptune
15
+ }.freeze
16
+ NAMES = BODIES.keys.to_h { |planet| [planet, planet.to_s.capitalize] }
17
+ .freeze
18
+
19
+ def initialize(
20
+ ephem:,
21
+ magnitude_limit: DEFAULT_MAGNITUDE_LIMIT,
22
+ labels: false,
23
+ names: NAMES
24
+ )
25
+ @ephem = ephem
26
+ @magnitude_limit = magnitude_limit
27
+ @labels = labels
28
+ @names = names
29
+ end
30
+
31
+ def elements(context)
32
+ star_size = StarSize.for(
33
+ canvas: context.canvas,
34
+ magnitude_limit: @magnitude_limit
35
+ )
36
+
37
+ BODIES.flat_map do |planet, body_class|
38
+ body = body_class.at(context.instant, ephem: @ephem)
39
+ magnitude = body.apparent_magnitude
40
+ next [] if magnitude > @magnitude_limit
41
+
42
+ horizontal = body.observed_by(context.observer).horizontal
43
+ next [] if horizontal.altitude.negative?
44
+
45
+ center = context.project(
46
+ altitude: horizontal.altitude,
47
+ azimuth: horizontal.azimuth
48
+ )
49
+ radius = star_size.radius(magnitude)
50
+ caption = caption(planet, center, radius, context) if @labels
51
+ [Renderer::Planet.new(center: center, radius: radius), caption]
52
+ .compact
53
+ end
54
+ end
55
+
56
+ private
57
+
58
+ def caption(planet, center, radius, context)
59
+ name = @names[planet]
60
+ return unless name
61
+
62
+ size = Renderer::Caption.size_for(context.canvas)
63
+ towards_center = (center.y > context.canvas.center.y) ? -1 : 1
64
+
65
+ Renderer::Caption.new(
66
+ position: Point.new(
67
+ x: center.x,
68
+ y: center.y + towards_center * (radius + size)
69
+ ),
70
+ text: name,
71
+ size: size,
72
+ kind: :planet
73
+ )
74
+ end
75
+ end
76
+ end
77
+ end
@@ -4,10 +4,6 @@ module Skymap
4
4
  module Layers
5
5
  class Stars
6
6
  DEFAULT_MAGNITUDE_LIMIT = 5
7
- MAX_RADIUS_MAGNITUDE = -1.5
8
- MIN_STAR_RADIUS_RATIO = 0.0025
9
- MAX_STAR_RADIUS_RATIO = 0.02
10
- STAR_SIZE_EXPONENT = 1.5
11
7
 
12
8
  def initialize(stars:, magnitude_limit: DEFAULT_MAGNITUDE_LIMIT)
13
9
  @stars = stars
@@ -15,12 +11,9 @@ module Skymap
15
11
  end
16
12
 
17
13
  def elements(context)
18
- star_size = StarSize.new(
19
- brightest_magnitude: MAX_RADIUS_MAGNITUDE,
20
- faintest_magnitude: @magnitude_limit,
21
- min_radius: MIN_STAR_RADIUS_RATIO * context.canvas.radius,
22
- max_radius: MAX_STAR_RADIUS_RATIO * context.canvas.radius,
23
- exponent: STAR_SIZE_EXPONENT
14
+ star_size = StarSize.for(
15
+ canvas: context.canvas,
16
+ magnitude_limit: @magnitude_limit
24
17
  )
25
18
 
26
19
  @stars.filter_map do |star|
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Skymap
4
+ module Layers
5
+ class Sun
6
+ SUN_RADIUS_RATIO = 0.03
7
+
8
+ def initialize(ephem:)
9
+ @ephem = ephem
10
+ end
11
+
12
+ def elements(context)
13
+ sun = Astronoby::Sun.at(context.instant, ephem: @ephem)
14
+ horizontal = sun.observed_by(context.observer).horizontal
15
+ return [] if horizontal.altitude.negative?
16
+
17
+ [
18
+ Renderer::Sun.new(
19
+ center: context.project(
20
+ altitude: horizontal.altitude,
21
+ azimuth: horizontal.azimuth
22
+ ),
23
+ radius: SUN_RADIUS_RATIO * context.canvas.radius
24
+ )
25
+ ]
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Skymap
4
+ module Renderer
5
+ CAPTION_SIZE_RATIO = 0.028
6
+
7
+ Caption = Data.define(:position, :text, :size, :kind) do
8
+ def self.size_for(canvas)
9
+ CAPTION_SIZE_RATIO * canvas.radius
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Skymap
4
+ module Renderer
5
+ Ecliptic = Data.define(:points, :width)
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Skymap
4
+ module Renderer
5
+ Planet = Data.define(:center, :radius)
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Skymap
4
+ module Renderer
5
+ Sun = Data.define(:center, :radius)
6
+ end
7
+ end
@@ -12,9 +12,13 @@ module Skymap
12
12
  LINE_COLOR = "#46689c"
13
13
  BOUNDARY_COLOR = "#2b3f5e"
14
14
  BOUNDARY_DASH_RATIO = 4
15
+ ECLIPTIC_COLOR = "#8c7a3a"
16
+ PLANET_COLOR = "#ffe6b3"
17
+ SUN_COLOR = "#ffd34d"
15
18
  MOON_COLOR = "#f1ecd6"
16
19
  MOON_SHADOW_COLOR = "#232a35"
17
20
  MOON_SHADOW_OPACITY = 0.6
21
+ CAPTION_COLORS = {constellation: "#6f8fc2", planet: PLANET_COLOR}
18
22
  LABEL_COLOR = HORIZON_COLOR
19
23
  LABEL_FONT = "sans-serif"
20
24
 
@@ -41,10 +45,14 @@ module Skymap
41
45
  elements.each do |element|
42
46
  case element
43
47
  when Boundary then draw_boundary(svg, element)
48
+ when Caption then draw_caption(svg, element)
44
49
  when Line then draw_line(svg, element)
45
50
  when Dot then draw_dot(svg, element)
51
+ when Ecliptic then draw_ecliptic(svg, element)
46
52
  when Label then draw_label(svg, element)
47
53
  when Moon then draw_moon(svg, element)
54
+ when Planet then draw_planet(svg, element)
55
+ when Sun then draw_sun(svg, element)
48
56
  else raise ArgumentError, "unknown element: #{element.class}"
49
57
  end
50
58
  end
@@ -80,6 +88,18 @@ module Skymap
80
88
  )
81
89
  end
82
90
 
91
+ def draw_ecliptic(svg, ecliptic)
92
+ svg.polyline(
93
+ points: ecliptic.points.map { |point|
94
+ "#{point.x.round(2)},#{point.y.round(2)}"
95
+ }.join(" "),
96
+ fill: "none",
97
+ stroke: ECLIPTIC_COLOR,
98
+ stroke_width: ecliptic.width.round(2),
99
+ stroke_linejoin: "round"
100
+ )
101
+ end
102
+
83
103
  def draw_dot(svg, dot)
84
104
  svg.circle(
85
105
  cx: dot.center.x.round(2),
@@ -89,6 +109,24 @@ module Skymap
89
109
  )
90
110
  end
91
111
 
112
+ def draw_planet(svg, planet)
113
+ svg.circle(
114
+ cx: planet.center.x.round(2),
115
+ cy: planet.center.y.round(2),
116
+ r: planet.radius.round(2),
117
+ fill: PLANET_COLOR
118
+ )
119
+ end
120
+
121
+ def draw_sun(svg, sun)
122
+ svg.circle(
123
+ cx: sun.center.x.round(2),
124
+ cy: sun.center.y.round(2),
125
+ r: sun.radius.round(2),
126
+ fill: SUN_COLOR
127
+ )
128
+ end
129
+
92
130
  def draw_moon(svg, moon)
93
131
  x = moon.center.x.round(2)
94
132
  y = moon.center.y.round(2)
@@ -116,6 +154,14 @@ module Skymap
116
154
  end
117
155
 
118
156
  def draw_label(svg, label)
157
+ draw_text(svg, label, LABEL_COLOR)
158
+ end
159
+
160
+ def draw_caption(svg, caption)
161
+ draw_text(svg, caption, CAPTION_COLORS.fetch(caption.kind))
162
+ end
163
+
164
+ def draw_text(svg, label, fill)
119
165
  svg.text(
120
166
  label.text,
121
167
  x: label.position.x.round(2),
@@ -124,7 +170,7 @@ module Skymap
124
170
  font_family: LABEL_FONT,
125
171
  text_anchor: "middle",
126
172
  dominant_baseline: "central",
127
- fill: LABEL_COLOR
173
+ fill: fill
128
174
  )
129
175
  end
130
176
  end
data/lib/skymap/star.rb CHANGED
@@ -1,5 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Skymap
4
- Star = Data.define(:hr, :equatorial_coordinates, :magnitude)
4
+ Star = Data.define(:hr, :equatorial_coordinates, :magnitude) do
5
+ def self.by_hr(stars)
6
+ stars.to_h { |star| [star.hr, star] }
7
+ end
8
+ end
5
9
  end
@@ -2,6 +2,21 @@
2
2
 
3
3
  module Skymap
4
4
  class StarSize
5
+ MAX_RADIUS_MAGNITUDE = -1.5
6
+ MIN_RADIUS_RATIO = 0.0025
7
+ MAX_RADIUS_RATIO = 0.02
8
+ EXPONENT = 1.5
9
+
10
+ def self.for(canvas:, magnitude_limit:)
11
+ new(
12
+ brightest_magnitude: [MAX_RADIUS_MAGNITUDE, magnitude_limit - 1].min,
13
+ faintest_magnitude: magnitude_limit,
14
+ min_radius: MIN_RADIUS_RATIO * canvas.radius,
15
+ max_radius: MAX_RADIUS_RATIO * canvas.radius,
16
+ exponent: EXPONENT
17
+ )
18
+ end
19
+
5
20
  def initialize(
6
21
  brightest_magnitude:,
7
22
  faintest_magnitude:,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Skymap
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/skymap.rb CHANGED
@@ -5,6 +5,7 @@ require "astronoby"
5
5
  require_relative "skymap/canvas"
6
6
  require_relative "skymap/catalog/constellation_boundaries"
7
7
  require_relative "skymap/catalog/constellation_lines"
8
+ require_relative "skymap/catalog/constellation_names"
8
9
  require_relative "skymap/catalog/stars"
9
10
  require_relative "skymap/chart"
10
11
  require_relative "skymap/constellation_boundary"
@@ -14,15 +15,23 @@ require_relative "skymap/horizon"
14
15
  require_relative "skymap/layers/cardinal_directions"
15
16
  require_relative "skymap/layers/constellation_boundaries"
16
17
  require_relative "skymap/layers/constellation_lines"
18
+ require_relative "skymap/layers/constellation_names"
19
+ require_relative "skymap/layers/ecliptic"
17
20
  require_relative "skymap/layers/moon"
21
+ require_relative "skymap/layers/planets"
18
22
  require_relative "skymap/layers/stars"
23
+ require_relative "skymap/layers/sun"
19
24
  require_relative "skymap/point"
20
25
  require_relative "skymap/projection/stereographic"
21
26
  require_relative "skymap/renderer/boundary"
27
+ require_relative "skymap/renderer/caption"
22
28
  require_relative "skymap/renderer/dot"
29
+ require_relative "skymap/renderer/ecliptic"
23
30
  require_relative "skymap/renderer/label"
24
31
  require_relative "skymap/renderer/line"
25
32
  require_relative "skymap/renderer/moon"
33
+ require_relative "skymap/renderer/planet"
34
+ require_relative "skymap/renderer/sun"
26
35
  require_relative "skymap/renderer/svg"
27
36
  require_relative "skymap/star"
28
37
  require_relative "skymap/star_size"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skymap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rémy Hannequin
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: '0.10'
18
+ version: '0.11'
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
- version: '0.10'
25
+ version: '0.11'
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: csv
28
28
  requirement: !ruby/object:Gem::Requirement
@@ -147,11 +147,13 @@ files:
147
147
  - README.md
148
148
  - data/constellations/iau/boundaries.csv
149
149
  - data/constellations/iau/lines.csv
150
+ - data/constellations/iau/names.csv
150
151
  - data/stars.csv
151
152
  - lib/skymap.rb
152
153
  - lib/skymap/canvas.rb
153
154
  - lib/skymap/catalog/constellation_boundaries.rb
154
155
  - lib/skymap/catalog/constellation_lines.rb
156
+ - lib/skymap/catalog/constellation_names.rb
155
157
  - lib/skymap/catalog/stars.rb
156
158
  - lib/skymap/chart.rb
157
159
  - lib/skymap/constellation_boundary.rb
@@ -161,15 +163,23 @@ files:
161
163
  - lib/skymap/layers/cardinal_directions.rb
162
164
  - lib/skymap/layers/constellation_boundaries.rb
163
165
  - lib/skymap/layers/constellation_lines.rb
166
+ - lib/skymap/layers/constellation_names.rb
167
+ - lib/skymap/layers/ecliptic.rb
164
168
  - lib/skymap/layers/moon.rb
169
+ - lib/skymap/layers/planets.rb
165
170
  - lib/skymap/layers/stars.rb
171
+ - lib/skymap/layers/sun.rb
166
172
  - lib/skymap/point.rb
167
173
  - lib/skymap/projection/stereographic.rb
168
174
  - lib/skymap/renderer/boundary.rb
175
+ - lib/skymap/renderer/caption.rb
169
176
  - lib/skymap/renderer/dot.rb
177
+ - lib/skymap/renderer/ecliptic.rb
170
178
  - lib/skymap/renderer/label.rb
171
179
  - lib/skymap/renderer/line.rb
172
180
  - lib/skymap/renderer/moon.rb
181
+ - lib/skymap/renderer/planet.rb
182
+ - lib/skymap/renderer/sun.rb
173
183
  - lib/skymap/renderer/svg.rb
174
184
  - lib/skymap/star.rb
175
185
  - lib/skymap/star_size.rb