Skip to content

Commit 26d94cb

Browse files
committed
more cleanup
- Added script to generate the diagrams. - Fixed various things in the maps.
1 parent 13161d7 commit 26d94cb

File tree

8 files changed

+1355
-1490
lines changed

8 files changed

+1355
-1490
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ scalar vector graphics (SVG) format. My original intent was to
55
generate diagrams showing the location of the Herschel 400 objects on
66
the Sky Atlas 2000 maps, something like the following:
77

8-
<img src="images/h400_22.svg" width="300">
8+
<img src="images/h400_9.svg">
99

1010
After discovering Diego Hernangomez's excellent repository of
1111
[celestial data](https://dieghernan.github.io/celestial_data/data) in
1212
geojson format, I expanded the tool to add more and more information
1313
layers. The end result looks like this:
1414

15-
<img src="images/map22.svg">
15+
<img src="images/map9.svg">
1616

genmap

+28-16
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ DSO_STROKE = 0.5
6868
# Utility functions
6969
###########################################################################
7070

71+
def parse_width(w)
72+
# Parse a width specification into its numeric part and its units, if any
73+
m = /^([\d.]+)(.*)$/.match(w)
74+
abort "Width expression should be <num><units>" unless m
75+
[m[1].to_f, m[2]]
76+
end
77+
7178
def g(x)
7279
# Convert a floating point number to a string, limiting the digits.
7380
"%.2f" % x
@@ -88,9 +95,11 @@ def deg_to_rad(dec)
8895
dec * Math::PI/180
8996
end
9097

91-
def project(ra, dec, phi1, phi2, ra0, dec0)
98+
def project(ra, dec, phi1, phi2, ra0, dec0, scale=Scale)
9299
# Project ra, dec onto a flat map using standard parallels phi1 and phi2
93-
# and centered on ra0, dec0. All parameters are in radians.
100+
# and centered on ra0, dec0. All parameters are in radians. The
101+
# returned x and y are scaled so that the map is 700 pixels wide. This
102+
# makes it easier to keep the line strokes an appropriate width.
94103

95104
# Normalize the cone/cylinder opposite ra0
96105
ra += 2*Math::PI if ra0-ra > Math::PI
@@ -110,7 +119,7 @@ def project(ra, dec, phi1, phi2, ra0, dec0)
110119
x = rho*Math.sin(theta)
111120
y = rho0 - rho*Math.cos(theta)
112121
end
113-
return Scale*x, -Scale*y
122+
return scale*x, -scale*y
114123
end
115124

116125
def parse_coord(coord)
@@ -250,7 +259,7 @@ end
250259
def draw_border_path(pts)
251260
# Draw a constellation border path.
252261
puts %Q[<polyline points="#{pts.map{|x| x.map{|y| g(y)}.join(",")}.join(" ")}"
253-
style="fill:none;stroke:grey;stroke-width:0.5;stroke-dasharray:3"/>]
262+
style="fill:none;stroke:grey;stroke-width:0.5"/>]
254263
end
255264

256265
def draw_grid_path(pts)
@@ -385,7 +394,7 @@ end
385394
def plot_border(bounds)
386395
# Print the map border.
387396
xmin, xmax, ymin, ymax = bounds
388-
puts %Q[<rect x=#{f(xmin)} y=#{f(ymin)} width=#{f(xmax-xmin)} height=#{f(ymax-ymin)} stroke="black" stroke-width="1" fill="none"/>]
397+
puts %Q[<rect x=#{f(xmin)} y=#{f(ymin)} width=#{f(xmax-xmin)} height=#{f(ymax-ymin)} stroke="black" stroke-width="0.5" fill="none"/>]
389398
end
390399

391400
def plot_map_number(bounds, map_number)
@@ -402,8 +411,8 @@ options = {}
402411
OptionParser.new do |opts|
403412
opts.banner = "Usage: test.rb [options]"
404413

405-
opts.on("-a", "--scale FACTOR", Integer, "Scale factor") do |v|
406-
options[:scale] = v
414+
opts.on("-w", "--width ", String, "Width of image") do |v|
415+
options[:width] = v
407416
end
408417
opts.on("-r", "--margin PIXELS", Integer, "Margin outside map") do |v|
409418
options[:margin] = v
@@ -417,7 +426,7 @@ OptionParser.new do |opts|
417426
opts.on("-l", "--lr DDDD.D+DDDD", String, "Lower-right coordinate") do |v|
418427
options[:lr] = v
419428
end
420-
opts.on("-s", "--stars MAG", Float, "Plot stars") do |v|
429+
opts.on("-S", "--stars MAG", Float, "Plot stars") do |v|
421430
options[:stars] = v
422431
end
423432
opts.on("-g", "--grid", "Plot grid") do |v|
@@ -435,20 +444,18 @@ OptionParser.new do |opts|
435444
opts.on("-D", "--dso MAG", Float, "Plot deep sky objects") do |v|
436445
options[:dso] = v
437446
end
438-
opts.on("-c", "--const", "Plot constellation lines") do |v|
447+
opts.on("-C", "--const", "Plot constellation lines") do |v|
439448
options[:const] = v
440449
end
441-
opts.on("-b", "--border", "Plot constellation borders") do |v|
450+
opts.on("-B", "--border", "Plot constellation borders") do |v|
442451
options[:border] = v
443452
end
444-
opts.on("-w", "--milkyway", "Plot milky way contours") do |v|
453+
opts.on("-W", "--milkyway", "Plot milky way contours") do |v|
445454
options[:milkyway] = v
446455
end
447456
end.parse!
448457

449-
# Fixme: we need a different solution than scale
450-
Scale = options[:scale] || 700
451-
458+
Width = options[:width] || "6in"
452459
Margin = options[:margin] || 0
453460

454461
# Establish some globals to specify the map to be generated.
@@ -474,17 +481,22 @@ else
474481

475482
# Approximate the map center.
476483
Ra0 = (Ra1+Ra2)/2
477-
Ra0_ha = (ra1+ra2)/2
484+
Ra0_ha = Ra0*24/(2*Math::PI)
478485
Dec0 = (Dec1+Dec2)/2
479486
end
480487

481488
# Determine the coordinates of the map boundary.
489+
xmin, ymin = project(Ra1, Dec1, Phi1, Phi2, Ra0, Dec0, 1.0)
490+
xmax, ymax = project(Ra2, Dec2, Phi1, Phi2, Ra0, Dec0, 1.0)
491+
Scale = 700.0/(xmax-xmin)
482492
xmin, ymin = project(Ra1, Dec1, Phi1, Phi2, Ra0, Dec0)
483493
xmax, ymax = project(Ra2, Dec2, Phi1, Phi2, Ra0, Dec0)
484494
bounds = [xmin, xmax, ymin, ymax]
495+
amt, units = parse_width(Width)
496+
Height = (amt*(ymax-ymin)/(xmax-xmin)).to_s + units
485497

486498
# Print the header material.
487-
puts %Q[<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 #{g(xmax-xmin+2*Margin)} #{g(ymax-ymin+2*Margin)}">]
499+
puts %Q[<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 #{g(xmax-xmin+2*Margin)} #{g(ymax-ymin+2*Margin)}" width="#{Width}" height="#{Height}">]
488500
puts %Q[<g transform="translate(#{g(-xmin+Margin)}, #{g(-ymin+Margin)})">]
489501
puts %Q[<clipPath id="CP">]
490502
puts %Q[<rect x=#{f(xmin)} y=#{f(ymin)} width=#{f(xmax-xmin)} height=#{f(ymax-ymin)} stroke="black" stroke-width="1" fill="white"/>]

images/h400_22.svg

-66
This file was deleted.

images/h400_9.svg

+60
Loading

images/map22.svg

-1,406
This file was deleted.

images/map9.svg

+1,257
Loading

scripts/gen_diagrams

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#
2+
3+
./genmap -m 9 -w 6in -S 7 -B -H -C -W > images/map9.svg
4+
./genmap -m 9 -w 3in -H -p > images/h400_9.svg

scripts/gen_diagrams~

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#
2+
3+
../genmap -m 9 -w 6in -S 7 -B -H -C -W > images/map9.svg
4+
../genmap -m 9 -w 3in -H -p > h400_9.svg

0 commit comments

Comments
 (0)