Star Projections and plotting easily in Python


Projections were the biggest concept that I more or less ignored when I first started managing my own data for Topophile. I knew in concept what it did and treated it like a config value I just had to have agree across systems. When I had more of the system working it was pleasing to go back and better understand them, and correct a couple errors a long the way.

As I'm not currently using a mapping software for this new constellation project "coterie", I needed to implement or include a projection. As usual with my learning projects I chose to implement. Thankfully the internet provided me with the equations for an azimuthal projection, which I will center on the constellation in question.

Check out this great search hit, thank you "projectpluto".

The implementation:

    def project(self):
        Project points in this constellation from the 
        center of itself. Equation thanks to
        raC, decC = self.find_center()
        raC = radians(raC * 15) # hours -> degrees -> radians
        decC = radians(decC)

        for star in self.stars.values():
            ra = radians(star.ra * 15)
            dec = radians(star.dec)
            delta_ra = ra - raC
            x1 = -1 * cos(dec) * sin(delta_ra)
            y1 = sin(dec) * cos(decC) - \
                  cos(dec) * cos(delta_ra) * sin(decC)
            z1 = sin(dec) * sin(decC) + \
                  cos(dec) * cos(decC) * cos(delta_ra)
            if (z1 < -.9):
                d = 20. * sqrt((1. - .81) / \
                     (1.00001 - z1 * z1))
                d = 2. / (z1 + 1.)
            x = x1 * d
            y = y1 * d
            star.projected = (x, y)

I implemented the simple cylindrical projection and it got it working when my first attempt at the azimuthal projection failed.

Failed Azimuthal Projection of Orion

Working Cylindrical Projection of Orion

After sleeping on it and graphing the projection equations seeking insight I realized it was just a units issue. math.sin() and friends want radians. I'd naively shoved the hours in, then tried degrees. I also had to invert the x value since we are looking up at the inside of the sphere, instead of down onto it.

Working Azimuthal Projection of Orion


When I first implemented my projections I could see the values and I wanted a "quick and easy" way to see the points graphically. A search for just this led me to several rejections (plotly, matlab) and my third attempt seems good enough, bokeh. It took four lines of code to take my data and put it on a nice, interactive javascript chart. Bokeh has great defaults.

    p = figure(title='orion'), stars_y, size=10)

The only problem I've had so far is not finding an immediate solution to keeping the x and y ticks equal size, leading the Orion looking a little more squat than it appears in the sky. This would be important in other circumstances, but my current use is just a confirmation. Real rendering will happen with a different stack.


Having the visual representation of the data is great for quickly building out my model. Here's the mess I used to define the shapes of Orion in code.

Many of the stars of Orion, some selected and connected with lines