I'm in the opening stages of writing (yet another) star system generator, using Python. My goal is to be able to generate a plausible star and, if appropriate, planetary system around it - allowing for classic systems like are own but also for hot jovians and any thing else that pops up.

The approach I'm considering using is to generate a spectral type and then look up acceptable ranges for key parameters to generate a plausible star of that type before calculating the remaining parameters.

After some experimentation, it appears that mass alone is not enough but I'm not sure what would be better - mass and radius? Mass and luminosity?

In particular, I'm having issues differentiating the values for the different luminosity classes (it should be trivial to separate a hyper-giant from a giant!)

  • $\begingroup$ This is better up in Astronomy.SE $\endgroup$
    – Vylix
    Jun 25, 2017 at 2:51
  • 4
    $\begingroup$ While I agree that this question would also get a good response in Astronomy Stack Exchange, our sister site, I disagree with @Vylix because I think it should stay here. It's certainly not off-topic. $\endgroup$
    – HDE 226868
    Jun 25, 2017 at 3:15
  • 1
    $\begingroup$ I did consider dropping the question in to Astronomy but given that I'm looking at generating a fictional, albeit plausible, system and that felt more like world building to me. $\endgroup$
    – Andrew
    Jun 25, 2017 at 4:50

2 Answers 2


The spectral type of a star tells you, in general, its surface temperature. Unfortunately, there's one main issue here. Each spectral type can give way to a range of luminosities and properties (see any Hertzsprung–Russell diagram). This can be rectified if you just want to create a star as it enters the main sequence, in which case there is a rough one-to-one relationship between temperature and luminosity.

The mass of a main sequence star determines the rest of its properties. From it, you can calculate luminosity: $$\frac{L}{L_\odot}\simeq\left(\frac{M}{M_\odot}\right)^{\alpha}\tag{1}$$ where $\alpha$ ranges from $3$ to $4$ - the exponent is different over different mass ranges. Averaged over the entire range of main sequence masses, this generally works. We can do something similar for the radius of the star: $$\frac{R}{R_\odot}\simeq\left(\frac{M}{M_\odot}\right)^{\beta}\tag{2}$$ where $\beta$ is a little less than $1$ - maybe $0.8\text{-}0.9$.

We can then try to approximation the surface temperature using the Stefan Boltzmann law: $$L=4\pi\sigma R^2T^4\tag{3}$$ All we have to do is solve for $T$, but remember. In your case, it seems like we may want to plug $\text{(1)}$ and $\text{(2)}$ into $\text{(3)}$ after converting the radius and luminosity to SI units, giving temperature as a function of mass. Then, you can simply put in a temperature for a given spectral type and estimate the mass, then back-substitute to find the radius and luminosity (and other properties).

I'll just add that these are only approximations, although they work pretty well. I'd certainly be comfortable using them. I did go into more detail on the subject in another answer, but honestly, these equations are fine.

An even better way to get exact parameters would be to use pre-existing stellar models. Many astronomers have modeled stars and stellar evolutionary tracks, and the resulting models may be available online. I sometimes cite the Geneva grids as an example, and the MESA code as an evolutionary code that you can run yourself.

The great thing about all of these is that you can determine all the parameters by varying the mass of a star and its composition (see the Vogt-Russell theorem). Pick a mass that corresponds to your spectral type, and you should be able to get detailed results fairly easily. I've taken to doing this lately for some of my answers on Worldbuilding. Numerical models are often much better than approximations, and often, someone has already done the work of generating them!

Additional references:

  • $\begingroup$ Thanks for your detailed response! 2 further questions: You state that an IMF would be the best approach but my understanding is that it used to simulate a cluster of stars? Given that I'm generating 1 system at a time, would it be okto simply pick a value between certain ranges? Secondly, regarding back substitution: I threw a quick python script together to calculate luminosity and radius from mass: pastebin.com/zzerqyXa I've attempted to implement the solve for T with determined R and L but I'm find values ~40 which seems off and I'm not sure how to back substitute? $\endgroup$
    – Andrew
    Jun 25, 2017 at 4:48
  • $\begingroup$ @Andrew I had misread the question initially and thought you were generating multiple stars; I'll remove it. I think I know your issue for calculating $T$: You hadn't converted the luminosity and radius to SI units; you should have had them in watts and meters (not kilometers, by the way!), but you had them in solar luminosities and solar radii. I modified the code to do the conversions, and I'm now getting reasonable answers, $\sim5772\text{ K}$ for a $1.0M_\odot$ star. $\endgroup$
    – HDE 226868
    Jun 25, 2017 at 12:29
  • $\begingroup$ My apologies for not returning earlier, I'm afraid RL has had me by the scruff of neck. I've attempted to convert units but I'm afraid my results are still inaccurate (current code: pastebin.com/8hc3QFkw) - could you point me to where I'm going wrong? $\endgroup$
    – Andrew
    Jul 7, 2017 at 5:03

fellow star-system-generator-creator.

So HDE did answer your question as far as I can tell... but I want to offer an alternative, which may not be a direct answer to the question your placed up there, but instead is hooking into the "mass is not enough" sentence.

I once had a similar problem, wondering what I do need to get a plausible star (and its star system) with as less data available as possible. So, if you are interested into abandoning the premise of knowing the spectral class first, keep on reading. Otherwise, thank you for your attention and good luck with your work!

So... still here? Well, I'm going to be as bold as I can become and say, that all you need to get a "plausible" star is its mass and its age. Mass is required to determine what It will become once the fusion kicks in, how it will look, what the internal plasma flow will look alike, its surface color, its size and the duration of its states of life.

But you need at least one additional parameter: its age at the point of checking. Without this, it will be a giant... quantum-like state, being a proto plasma cloud, a mainline-star and a super massive black hole at the same time.

Wit mass, you know its potential parameters at each state of its life, and with its age you know, in what state of life it is at the moment you are looking at it.

Take a star with ten times the mass of our sun... okay? How does it look after 4.5 B... M... come one, what was a "Milliarde" in English again?... Billion? Anyway, how would it look if its as old as our sun? Pretty black, I assume. But how would it look after about 500 Million years? Pretty blue. White-bluish... I assume.

From this point, you might get the spectral you where starting with:

Know its mass, you will know the durations of its states of life -> Know a mass and a time when you look at it, you may go for its current state of life -> From its mass and state of life, you may get its size -> from its mass and size, you may get its surface temperature -> from its mass and surface temperature, you may go for its spectral class.

sigh Well, I went out of the topic when I realized that the star was the easy part of the work. As soon as I tried to apply different levels of pressure to the layers of all celestial bodies, my planets, stars and whatnot startet to go for abnormal values (I remeber one special "brown dwarf", which got to much non-fusion material during creation and ended up with a chronosspere as big as half of the star system... that was the point where I had to admit defeat because of a lack of knowledge).

So, you might want to rethink your approach, but if you really need to insert a spectral class and get a proper star, my approach will be a bit... hard to use, because you had to create a dozend star(systems) and hope to get one which may fit your needs.

Anyway, happy system-creation!

  • $\begingroup$ This is a good point, +1. I'd recommend maybe adding something about stellar models and evolutionary tracks. They're probably beyond the ability of most people to generate, but you can still look up isochrones to get good data - without having to write a program yourself! $\endgroup$
    – HDE 226868
    Jun 26, 2017 at 13:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .