skymap 0.2.0 → 0.4.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.
@@ -0,0 +1,334 @@
1
+ hr,name
2
+ 15,Alpheratz
3
+ 21,Caph
4
+ 39,Algenib
5
+ 99,Ankaa
6
+ 153,Fulu
7
+ 168,Schedar
8
+ 188,Diphda
9
+ 219,Achird
10
+ 265,Castula
11
+ 337,Mirach
12
+ 338,Wurren
13
+ 361,Revati
14
+ 390,Adhil
15
+ 403,Ruchbah
16
+ 424,Polaris
17
+ 437,Alpherg
18
+ 458,Titawin
19
+ 464,Nembus
20
+ 472,Achernar
21
+ 510,Torcular
22
+ 539,Baten Kaitos
23
+ 542,Segin
24
+ 544,Mothallah
25
+ 546,Mesarthim
26
+ 553,Sheratan
27
+ 596,Alrescha
28
+ 603,Almach
29
+ 617,Hamal
30
+ 681,Mira
31
+ 804,Kaffaljidhma
32
+ 824,Lilii Borea
33
+ 834,Miram
34
+ 838,Bharani
35
+ 850,Angetenar
36
+ 874,Azha
37
+ 897,Acamar
38
+ 911,Menkar
39
+ 936,Algol
40
+ 941,Misam
41
+ 951,Botein
42
+ 963,Dalim
43
+ 984,Zibal
44
+ 1017,Mirfak
45
+ 1084,Ran
46
+ 1131,Atik
47
+ 1136,Rana
48
+ 1140,Celaeno
49
+ 1142,Electra
50
+ 1145,Taygeta
51
+ 1149,Maia
52
+ 1151,Asterope
53
+ 1156,Merope
54
+ 1165,Alcyone
55
+ 1178,Atlas
56
+ 1180,Pleione
57
+ 1228,Menkib
58
+ 1231,Zaurak
59
+ 1298,Beid
60
+ 1325,Keid
61
+ 1346,Prima Hyadum
62
+ 1373,Secunda Hyadum
63
+ 1393,Beemim
64
+ 1409,Ain
65
+ 1412,Chamukuy
66
+ 1457,Aldebaran
67
+ 1464,Theemin
68
+ 1481,Sceptrum
69
+ 1543,Tabit
70
+ 1577,Hassaleh
71
+ 1605,Almaaz
72
+ 1612,Saclateni
73
+ 1641,Haedus
74
+ 1666,Cursa
75
+ 1708,Capella
76
+ 1713,Rigel
77
+ 1790,Bellatrix
78
+ 1791,Elnath
79
+ 1829,Nihal
80
+ 1852,Mintaka
81
+ 1865,Arneb
82
+ 1879,Meissa
83
+ 1899,Hatysa
84
+ 1903,Alnilam
85
+ 1910,Tianguan
86
+ 1948,Alnitak
87
+ 1956,Phact
88
+ 2004,Saiph
89
+ 2040,Wazn
90
+ 2061,Betelgeuse
91
+ 2088,Menkalinan
92
+ 2095,Mahasim
93
+ 2177,Elkurud
94
+ 2216,Propus
95
+ 2282,Furud
96
+ 2286,Tejat
97
+ 2294,Mirzam
98
+ 2326,Canopus
99
+ 2421,Alhena
100
+ 2473,Mebsuta
101
+ 2484,Alzirr
102
+ 2491,Sirius
103
+ 2618,Adhara
104
+ 2646,Nganurganity
105
+ 2650,Mekbuda
106
+ 2657,Muliphein
107
+ 2693,Wezen
108
+ 2777,Wasat
109
+ 2827,Aludra
110
+ 2845,Gomeisa
111
+ 2891,Castor
112
+ 2930,Jishui
113
+ 2943,Procyon
114
+ 2990,Pollux
115
+ 3045,Azmidi
116
+ 3165,Naos
117
+ 3185,Tureis
118
+ 3208,Tegmine
119
+ 3249,Tarf
120
+ 3268,Piautos
121
+ 3275,Alsciaukat
122
+ 3307,Avior
123
+ 3323,Muscida
124
+ 3418,Minchir
125
+ 3429,Meleph
126
+ 3449,Asellus Borealis
127
+ 3461,Asellus Australis
128
+ 3482,Ashlesha
129
+ 3485,Alsephina
130
+ 3522,Copernicus
131
+ 3569,Talitha
132
+ 3572,Acubens
133
+ 3594,Alkaphrah
134
+ 3627,Nahn
135
+ 3634,Suhail
136
+ 3685,Miaplacidus
137
+ 3699,Aspidiske
138
+ 3734,Markeb
139
+ 3743,Intercrus
140
+ 3748,Alphard
141
+ 3773,Alterf
142
+ 3845,Ukdah
143
+ 3852,Subra
144
+ 3903,Zhang
145
+ 3905,Rasalas
146
+ 3923,Felis
147
+ 3982,Regulus
148
+ 4031,Adhafera
149
+ 4033,Tania Borealis
150
+ 4057,Algieba
151
+ 4069,Tania Australis
152
+ 4247,Praecipua
153
+ 4277,Chalawan
154
+ 4287,Alkes
155
+ 4295,Merak
156
+ 4301,Dubhe
157
+ 4357,Zosma
158
+ 4359,Chertan
159
+ 4375,Alula Australis
160
+ 4377,Alula Borealis
161
+ 4434,Giausar
162
+ 4518,Taiyangshou
163
+ 4534,Denebola
164
+ 4540,Zavijava
165
+ 4554,Phecda
166
+ 4609,Tonatiuh
167
+ 4623,Alchiba
168
+ 4656,Imai
169
+ 4660,Megrez
170
+ 4662,Gienah
171
+ 4689,Zaniah
172
+ 4700,Ginan
173
+ 4730,Acrux
174
+ 4757,Algorab
175
+ 4763,Gacrux
176
+ 4785,Chara
177
+ 4786,Kraz
178
+ 4825,Porrima
179
+ 4846,La Superba
180
+ 4853,Mimosa
181
+ 4863,Tianyi
182
+ 4905,Alioth
183
+ 4910,Minelauva
184
+ 4915,Cor Caroli
185
+ 4916,Taiyi
186
+ 4932,Vindemiatrix
187
+ 4968,Diadem
188
+ 5054,Mizar
189
+ 5056,Spica
190
+ 5062,Alcor
191
+ 5107,Heze
192
+ 5191,Alkaid
193
+ 5235,Muphrid
194
+ 5267,Hadar
195
+ 5288,Menkent
196
+ 5291,Thuban
197
+ 5315,Kang
198
+ 5338,Syrma
199
+ 5340,Arcturus
200
+ 5351,Xuange
201
+ 5359,Khambalia
202
+ 5409,Elgafar
203
+ 5435,Seginus
204
+ 5459,Rigil Kentaurus
205
+ 5460,Toliman
206
+ 5506,Izar
207
+ 5531,Zubenelgenubi
208
+ 5533,Merga
209
+ 5563,Kochab
210
+ 5602,Nekkar
211
+ 5603,Brachium
212
+ 5685,Zubeneschamali
213
+ 5733,Alkalurops
214
+ 5735,Pherkad
215
+ 5744,Edasich
216
+ 5747,Nusakan
217
+ 5787,Zubenelhakrabi
218
+ 5793,Alphecca
219
+ 5854,Unukalhai
220
+ 5879,Gudja
221
+ 5928,Iklil
222
+ 5944,Fang
223
+ 5953,Dschubba
224
+ 5984,Acrab
225
+ 6008,Marsic
226
+ 6027,Jabbah
227
+ 6056,Yed Prior
228
+ 6075,Yed Posterior
229
+ 6084,Alniyat
230
+ 6117,Cujam
231
+ 6132,Athebyne
232
+ 6134,Antares
233
+ 6148,Kornephoros
234
+ 6149,Marfik
235
+ 6165,Paikauhale
236
+ 6217,Atria
237
+ 6241,Larawag
238
+ 6247,Xamidimura
239
+ 6252,Pipirima
240
+ 6370,Alrakis
241
+ 6378,Sabik
242
+ 6396,Aldhibah
243
+ 6402,Guniibuu
244
+ 6406,Rasalgethi
245
+ 6410,Sarin
246
+ 6508,Lesath
247
+ 6526,Maasym
248
+ 6527,Shaula
249
+ 6536,Rastaban
250
+ 6553,Sargas
251
+ 6556,Rasalhague
252
+ 6585,Cervantes
253
+ 6603,Cebalrai
254
+ 6618,Alruba
255
+ 6630,Fuyue
256
+ 6636,Dziban
257
+ 6688,Grumium
258
+ 6705,Eltanin
259
+ 6746,Alnasl
260
+ 6789,Yildun
261
+ 6812,Polis
262
+ 6859,Kaus Media
263
+ 6879,Kaus Australis
264
+ 6913,Kaus Borealis
265
+ 6945,Fafnir
266
+ 7001,Vega
267
+ 7106,Sheliak
268
+ 7116,Ainalrami
269
+ 7121,Nunki
270
+ 7141,Alya
271
+ 7178,Sulafat
272
+ 7194,Ascella
273
+ 7228,Polaris Australis
274
+ 7235,Okab
275
+ 7254,Meridiana
276
+ 7264,Albaldah
277
+ 7298,Aladfar
278
+ 7310,Altais
279
+ 7337,Arkab Prior
280
+ 7343,Arkab Posterior
281
+ 7348,Rukbat
282
+ 7405,Anser
283
+ 7417,Albireo
284
+ 7462,Alsafi
285
+ 7479,Sham
286
+ 7525,Tarazed
287
+ 7528,Fawaris
288
+ 7557,Altair
289
+ 7595,Libertas
290
+ 7597,Terebellum
291
+ 7602,Alshain
292
+ 7754,Algedi
293
+ 7773,Alshat
294
+ 7776,Dabih
295
+ 7790,Peacock
296
+ 7796,Sadr
297
+ 7852,Aldulfin
298
+ 7882,Rotanev
299
+ 7906,Sualocin
300
+ 7924,Deneb
301
+ 7949,Aljanah
302
+ 7950,Albali
303
+ 8030,Musica
304
+ 8131,Kitalpha
305
+ 8162,Alderamin
306
+ 8232,Sadalsuud
307
+ 8238,Alfirk
308
+ 8264,Bunda
309
+ 8278,Nashira
310
+ 8301,Azelfafage
311
+ 8308,Enif
312
+ 8322,Deneb Algedi
313
+ 8353,Aldhanab
314
+ 8414,Sadalmelik
315
+ 8417,Kurhah
316
+ 8425,Alnair
317
+ 8450,Biham
318
+ 8499,Ancha
319
+ 8518,Sadachbia
320
+ 8610,Situla
321
+ 8634,Homam
322
+ 8636,Tiaki
323
+ 8650,Matar
324
+ 8684,Sadalbari
325
+ 8709,Skat
326
+ 8728,Fomalhaut
327
+ 8729,Helvetios
328
+ 8773,Fumalsamakah
329
+ 8775,Scheat
330
+ 8781,Markab
331
+ 8880,Salm
332
+ 8905,Alkarab
333
+ 8930,Veritate
334
+ 8974,Errai
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
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "csv"
4
+
5
+ module Skymap
6
+ module Catalog
7
+ class StarNames
8
+ PATH = File.expand_path("../../../data/star_names.csv", __dir__)
9
+
10
+ def [](hr)
11
+ names[hr]
12
+ end
13
+
14
+ private
15
+
16
+ def names
17
+ @names ||= CSV
18
+ .read(PATH, headers: true, encoding: "UTF-8")
19
+ .to_h { |row| [row["hr"].to_i, row["name"]] }
20
+ end
21
+ end
22
+ end
23
+ 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
data/lib/skymap/chart.rb CHANGED
@@ -2,10 +2,11 @@
2
2
 
3
3
  module Skymap
4
4
  class Chart
5
- def initialize(observer:, instant:, canvas:)
5
+ def initialize(observer:, instant:, canvas:, theme: Theme.dark)
6
6
  @observer = observer
7
7
  @instant = instant
8
8
  @canvas = canvas
9
+ @theme = theme
9
10
  end
10
11
 
11
12
  def render(*layers)
@@ -16,7 +17,7 @@ module Skymap
16
17
  )
17
18
  elements = layers.flat_map { |layer| layer.elements(context) }
18
19
 
19
- Renderer::SVG.new(canvas: @canvas).render(elements)
20
+ Renderer::SVG.new(canvas: @canvas, theme: @theme).render(elements)
20
21
  end
21
22
  end
22
23
  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