File talk:Sky.svg
Jump to navigation
Jump to search
The Python script to generate this map (same license as the image). Expects the downloaded catalog in the same directory. The SVG template ./svg_template.svg
can be reverse-engineered easily from the compiled image.
#!/usr/bin/env python3 from math import sin import re southern_stars = northern_stars = catalog = open('./catalog') stars = ( { 'id': s[0:4].strip(), 'name': s[4:14].strip(), 'ra': (float(s[75:77])*15 + float(s[77:79])/4 + float(s[79:83])/240), 'dec': int(s[83]+'1') * (int(s[84:86]) + int(s[86:88])/60 + int(s[88:90])/360), 'mag': float(s[102:107]) if s[102:107].strip() else None, 'sptype': s[127:147].strip(), } for s in catalog if len(s) > 160 and s[83:86].strip() ) for star in stars: sptype = star['sptype'][0] if sptype == 'p': # Eta Car has spectral type "pec" sptype = 'O' ra = round(star['ra'], 4) if star['dec'] < 0: ra *= -1 dec = round( 10 * ( 90 - abs(star['dec']) ), 4 ) mag = 10 - 10*sin(star['mag']/20*3.1415) constellation = if re.search('[A-Z][a-z]{2}$', star['name']): constellation = star['name'][-3:] svg_star = ('<use xlink:href="#{sptype}"' ' transform="translate(0 -{dec}) rotate({ra} 0 {dec}) scale({mag} {mag})"' ' class="spec-{sptype} {constellation}"/>\n').format( sptype=sptype, mag=mag, ra=ra, dec=dec, constellation=constellation) if star['dec'] >= 0: northern_stars += svg_star else: southern_stars += svg_star catalog.close() svg_tpl = open('./sky_template.svg') svg = svg_tpl.read() svg_tpl.close() print(svg.format(northern_stars=northern_stars, southern_stars=southern_stars)) — Preceding unsigned comment added by Manuel Strehl (talk • contribs) 00:29, 25 March 2017 (UTC)