Wednesday, April 27, 2011


I wanted to be able to generate random but plausible celestial spheres of stars visible to the naked eye from the vantage point of a solar system like ours, situated in an arm of a spiral galaxy.

I grabbed all the stars in ESA's Hipparcos catalogue with apparent magnitudes below 6, which comes to a little over 5000 stars. Mapped out on a sphere according to apparent magnitude and color they look like:

Stars visible by naked eye from Earth

That's a sinusoidal projection of the whole sphere, as would be seen from inside of it (on the Earth, for example). I sanity-checked it by filtering out all but the stars of the Big Dipper and made sure it dipped in the right orientation and hemisphere.

Plotting their absolute magnitudes versus their color index looks like this:

Plot of each visible star's absolute magnitude versus color index

The hunk on the left is made of stars on the main sequence, and the other splotch of giants, with a spattering of others. Most of the stars around us are red dwarrows, but since they're too small and dim to see with the naked eye, I don't even care about those.

A histogram (excuse the rotation and scaled-up x-axis) looks like:

Histogram of visible stars' magnitudes and colors

I smoothened that out to make a probability distribution (scaled up, and apologies for yet another axis rotation):

Distribution for randomly generating stars of different magnitudes and colors

You can't see it, but outside the main globs there are big regions of "off-white" (grays 253 and 254) where there are small but nonzero probabilities of finding stars.

One thing I had not expected was that even without rendering a "milky way," the visible stars are noticeably more prevalent closer to the galactic disk. So I also found a best fit great circle and recorded each star's angular distance from that. Plotting those on the z-axis gives:

Distance of stars from galactic disk versus magnitude and color index

You sort of need to move it around to tell what's going on, but basically stars are more likely to be near the disk, and more so if they're brighter and whiter. I didn't even try to quantify this any better, just fudged it.

So I generate 6000 (or however many) stars with color and magnitude selected according to my smoothified histogram. Each star gets a random distance within visibility range (because my initial sample only included stars of a given color close enough to be visible to the naked eye, I can't create any too far away to see without throwing off the distribution) and is either randomly rotated away from the galactic plane or rotated according to a normal distribution, more likely the latter the brighter and whiter it is.

Results shown on the right, alongside plots of the Hipparcos data set on the left (and as shown above).

Plots of empirical and randomly generated star distributions

The results aren't too bad, though that lowest-probability shade in my smootherized histogram is too dark: it should probably be like gray 254.9 or something.

Finally the whole thing gets a random rotation from the galactic plane, and the results might look something like this:

Random starscape

So pretty good! Next step (after tweaking the distance-from-galactic-plane function) would be generating some realistic views from a planet according to axial tilt and times of day and season. And then inventing constellations?

Also maybe the possibility of a perspective from outside a galactic arm? Though how likely is that, if you're looking from a class G or K main sequence star?

I don't know. I think it's cool though.

Source here, requires pygame, numpy, and matplotlib.

No comments: