<p>My <a href="https://astronomy.stackexchange.com/a/46669/42349">other answer</a> was probably unnecessarily complicated and not at all <em>Straightforward</em>. I suggest you use instead the Gaia DR2 database, which contains 161,497,595 sources with an estimate of the effective temperature, according to <a href="https://www.cosmos.esa.int/web/gaia/dr2" rel="nofollow noreferrer">this documentation page</a>.</p>
<p>From the effective temperature, you can obtain the RGB values of the black body spectrum directly from the software you are using, as you have said.</p>

CC BY-SA 4.0
2021-09-10T15:35:34.877Z
This would definitely be simpler, but I still appreciate the complete answer you originally posted!
Niall
CC BY-SA 4.0
2021-09-09T18:44:26.250Z
2021-09-09T18:44:26.250Z
Prallax
<p>Color is a difficult matter. I anticipate that there is no unique solution to your question, and that things can get arbitrarily complicated the deeper you dig into the problem.</p>
<p>In order to present the correct color of the stars in your rendering, you have to account for many different &quot;layers&quot; of representation of the color.</p>
<ol>
<li>The spectrum of the star, which is a continuum function of the wavelength.</li>
<li>The Gaia filters, that transform the continuum spectrum in a finite set of magnitude values for some bands.</li>
<li>The RGB color, that describes the color with three real numbers.</li>
<li>The way a display converts an RGB color into an electromagnetic spectrum. Which will be utterly different than the original spectrum of the star.</li>
<li>The way your eye perceives the color (with three different receptors) and the way your brain processes this information.</li>
</ol>
<p>Each step encodes the color of the previous step in a different way. But each encoding loses information and you can't do anything about it. Additionally, you have direct control only on the step from 2 to 3. You can only (educately) guess what was the original spectrum of the star and guess what will be the perceived color at the end. Your task it to associate an RGB value to each Gaia filter measurement such that when a user looks at the monitor, they will perceive a similar color to the one they would have perceived if they had looked directly at the star. A daunting task! We'll have to make lots of approximations and assumptions.</p>
<p>Let's start by looking at Gaia's filters</p>
<p><a href="https://i.sstatic.net/JLt5m.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/JLt5m.png" alt="Gaia filters passband" /></a>
Credits: <a href="https://www.cosmos.esa.int/web/gaia/edr3-passbands" rel="nofollow noreferrer">ESA/Gaia/DPAC, P. Montegriffo, F. De Angeli, M. Bellazzini, E. Pancino, C. Cacciari, D. W. Evans, and CU5/PhotPipe team</a></p>
<p>This figure shows the transmissivity of the filters as a function of the wavelength. The green curve is the G filter. It encompasses all the visible range and also some near infrared (NIR). The blue curve is the BP filter, that covers all the visible range. The red curve is the RP filter, that covers the red part of the visible, but is mostly sensitive to near infrared. As you can see, <strong>G, BP and RP do not correspond to green, blue and red</strong>.</p>
<p>Let's compare this with the response function of the <a href="https://en.wikipedia.org/wiki/Color_vision" rel="nofollow noreferrer">human cone cells</a>:</p>
<p><a href="https://i.sstatic.net/mLvW4.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/mLvW4.png" alt="normalized response of the human cone cells" /></a></p>
<p>Credits: <a href="https://commons.wikimedia.org/wiki/User:BenRG" rel="nofollow noreferrer">BenRG</a></p>
<p>S (short) is usually associated with blue, M (medium) is often associated with green and L (long) with red. But as you can see this association is far from perfect. S actually peaks in the violet and both M and L span a large range from green to red.</p>
<p>They are totally different from Gaia's filters. This means that Gaia's &quot;eyes&quot; see color in a different way than human eyes. The two signals are not directly comparable.</p>
<p>What we could do instead, is estimate the shape of the original spectrum, from Gaia's data. Then we could calculate how such spectrum would be perceived by a human eye.</p>
<p><strong>Estimating the original spectrum</strong></p>
<p>The spectrum of a star can be complicated, full of absorption lines that depend on the temperature and composition. It can also be modified by radial motion (redshift), dust extinction and emission. I will ignore all the details and assume that the spectrum is a perfect <a href="https://en.wikipedia.org/wiki/Planck%27s_law" rel="nofollow noreferrer">black body</a>. This is nice, because a black body spectrum is determined from its temperature <span class="math-container">$T$</span> only, so we need to estimate just one parameter.</p>
<p>Given a transmission function <span class="math-container">$t_W(\lambda)$</span> (the ones in the first picture) of a filter <span class="math-container">$W$</span>, and the flux of a star <span class="math-container">$F(\lambda)$</span>, the flux registered in the telescope through the filter will be</p>
<p><span class="math-container">$$F_W = \frac{\int_0^\infty F(\lambda) t_W(\lambda)d\lambda}{\int_0^\infty t_W(\lambda)d\lambda}$$</span></p>
<p>From <a href="https://www.cosmos.esa.int/web/gaia/edr3-passbands" rel="nofollow noreferrer">this page</a> you can download a file that contains the shape of Gaia's transmission function. <em>Or you can just approximate them with a constant value inside an interval and with zero outside.</em></p>
<p>As I said, you can use Planck law for the source flux, where <span class="math-container">$T$</span> is the temperature and <span class="math-container">$\epsilon$</span> is a normalization constant that depends on the brightness of the source.</p>
<p><span class="math-container">$$F(\lambda; T, \epsilon) = {\epsilon \over \lambda^5} \frac{1}{\exp(\frac{hc}{\lambda k_B T})-1}$$</span></p>
<p>Let's say that a given filter <span class="math-container">$W$</span> measures a magnitude <span class="math-container">$m_W$</span> for a given star. You will first need to convert the magnitude to a flux <span class="math-container">$F_W$</span>, and then you will need to find the values of <span class="math-container">$T$</span> and <span class="math-container">$\epsilon$</span> that minimize the function
<span class="math-container">$$f_W(T,\epsilon) = \left| F_W - \frac{\int_0^\infty F(\lambda; T, \epsilon) t_W(\lambda)d\lambda}{\int_0^\infty t_W(\lambda)d\lambda} \right|$$</span></p>
<p>Feel free to use your favorite minimization algorithm :)</p>
<p>Actually, you have three values to minimize, not just one, because Gaia tells you the readings of three filters. At this point I suggest you keep it simple and just minimize the sum of the squares of the three function:</p>
<p><span class="math-container">$$f_G(T,\epsilon)^2 + f_{BP}(T,\epsilon)^2 + f_{RP}(T,\epsilon)^2$$</span></p>
<p>If the result is not satisfactory, then you can start to mess with maximum likelihood or Bayesian inference, but I'd leave it for another time.</p>
<p><strong>Finding the RGB values</strong></p>
<p>Now that you have the spectrum, things could get difficult. With a generic spectrum, you'd have to calculate the values of the XYZ coefficients of the <a href="https://en.wikipedia.org/wiki/CIE_1931_color_space" rel="nofollow noreferrer">CIE 1931 color space</a>, and then convert them to the RGB coefficients of the <a href="https://en.wikipedia.org/wiki/SRGB" rel="nofollow noreferrer">sRGB color space</a>.</p>
<p>But I have suggested to work with black bodies for a reason. This conversion from the spectrum to the RGB has already been done for the black body, and the results are tabulated. You can find the values for example <a href="http://www.vendian.org/mncharity/dir3/blackbody/UnstableURLs/bbr_color.html" rel="nofollow noreferrer">here</a>, or in many other places on the web.</p>
<p>You can even use the <span class="math-container">$\epsilon$</span> coefficient that you have found to set the brightness of the stars in your CGI software.</p>
<p>All is left to do is hope that layers 4 and 5 work as intended: e.g. that the monitor of your final users will display sRGB colors correctly and that your users won't be color blind ;)</p>
<p>I hope that this explanation has not discouraged you to the point of deciding to use the following algorithm, instead</p>
<pre><code>R = random.uniform(0,255)
G = random.uniform(0,255)
B = random.uniform(0,255)
</code></pre>
<p>If you want some clarifications, feel free to ask.</p>

CC BY-SA 4.0
2021-09-09T17:52:29.837Z
Thank you! The simulation and rendering software I use actually has a blackbody function that will convert a temperature in K to an RGB value. I've used it for rendering sparks, etc in the past, and it'll work perfectly for this. Unfortunately, the math in the "Estimating the original spectrum" section is a little bit beyond me, so any further clarification (or pointers to reference on the topic) you can provide there would be much appreciated!
Niall
CC BY-SA 4.0
2021-09-09T18:30:56.137Z
@Niall I think that the easiest way could be to use the 161,497,595 sources that already have a computed effective temperature inside [Gaia DR2 catalogue](https://www.cosmos.esa.int/web/gaia/dr2). I'm sorry, this answer was an overkill
Prallax
CC BY-SA 4.0
2021-09-09T18:48:25.700Z
@Niall I have posted another answer, but I will keep this one, just in case I am trapped on a desert island with an hard drive filled only with EDR3 photometry data and no precalculated effective temperatures. (And also a pc, electricity and this SE page cached in my browser)
Prallax
CC BY-SA 4.0
2021-09-09T14:02:41.530Z
2021-09-09T14:08:43.120Z
2021-09-09T14:08:43.120Z
Prallax
<p>I'm a non-astronomer, but I'm working on a project for which I need to produce CGI renderings of as complete a starfield as I can find. The latest Gaia catalogue release has an impressive 1.5 billion sources with photometry, so I'd like to use that. However, I'm struggling with figuring out how to convert the photometry data into rgb colour values. My understanding is that the sources are photographed through bandpass filters which each transmit a particular range of frequencies, and that this can be used to determine the colour temperature of the stars, but I don't know which pieces of data I need or what formula I need to convert them into colour values or temperatures.</p>
<p>I think that the following fields in the dataset are probably what I need:</p>
<ul>
<li>phot_g_mean_mag: G-band mean magnitude (float, Magnitude[mag])</li>
<li>phot_bp_mean_mag: Integrated BP mean magnitude (float,
Magnitude[mag])</li>
<li>phot_rp_mean_mag: Integrated RP mean magnitude (float,
Magnitude[mag])</li>
<li>bp_rp : BP - RP colour (float, Magnitude[mag])</li>
<li>bp_g : BP - G colour (float, Magnitude[mag])</li>
<li>g_rp : G - RP colour (float, Magnitude[mag])</li>
</ul>
<p>Is it as simple as stuffing the G mean magnitude into the green channel, the BP into the blue and the RP into the red?</p>
<p>I'd welcome any advice on how to go about doing this, or links to resources or code that does something similar. I don't need the results to be scientifically accurate, just visually plausible.</p>

CC BY-SA 4.0
2021-09-09T09:32:48.483Z
In this context, "G" means "Gaia", not "green". It's actually a "white light" band, meaning it's basically blue + green + yellow + orange + red + (a tiny bit of) near-infrared.
Peter Erwin
CC BY-SA 4.0
2021-09-09T14:52:00.390Z
@PeterErwin Thanks! I eventually figured that out after some more skimming of Gaia-related papers. 
So:
G = white light (absolute visible magnitude)
BP = Blue Photometry
RP = Red Photometry
?
Niall
<photometry><color-index><color>
Straightforward conversion from Gaia GDR3 photometry to RGB values
Niall
# Straightforward conversion from Gaia GDR3 photometry to RGB values

(Asked by: username_0 on 2021-09-09)

I'm a non-astronomer, but I'm working on a project for which I need to produce CGI renderings of as complete a starfield as I can find. The latest Gaia catalogue release has an impressive 1.5 billion sources with photometry, so I'd like to use that. However, I'm struggling with figuring out how to convert the photometry data into rgb colour values. My understanding is that the sources are photographed through bandpass filters which each transmit a particular range of frequencies, and that this can be used to determine the colour temperature of the stars, but I don't know which pieces of data I need or what formula I need to convert them into colour values or temperatures.

I think that the following fields in the dataset are probably what I need:

* phot\_g\_mean\_mag: G-band mean magnitude (float, Magnitude[mag])
* phot\_bp\_mean\_mag: Integrated BP mean magnitude (float,
  Magnitude[mag])
* phot\_rp\_mean\_mag: Integrated RP mean magnitude (float,
  Magnitude[mag])
* bp\_rp : BP - RP colour (float, Magnitude[mag])
* bp\_g : BP - G colour (float, Magnitude[mag])
* g\_rp : G - RP colour (float, Magnitude[mag])

Is it as simple as stuffing the G mean magnitude into the green channel, the BP into the blue and the RP into the red?

I'd welcome any advice on how to go about doing this, or links to resources or code that does something similar. I don't need the results to be scientifically accurate, just visually plausible.

**Tags:** photometry, color-index, color

> **Comments:**
> **username_1**: In this context, "G" means "Gaia", not "green". It's actually a "white light" band, meaning it's basically blue + green + yellow + orange + red + (a tiny bit of) near-infrared.  
> **username_0**: @PeterErwin Thanks! I eventually figured that out after some more skimming of Gaia-related papers.  So: G = white light (absolute visible magnitude) BP = Blue Photometry RP = Red Photometry ?  

---

## 2 answers

### Answer by username_2 on 2021-09-09. Score: 1

My [other answer](https://astronomy.stackexchange.com/a/46669/42349) was probably unnecessarily complicated and not at all *Straightforward*. I suggest you use instead the Gaia DR2 database, which contains 161,497,595 sources with an estimate of the effective temperature, according to [this documentation page](https://www.cosmos.esa.int/web/gaia/dr2).

From the effective temperature, you can obtain the RGB values of the black body spectrum directly from the software you are using, as you have said.

> **Comments:**
> **username_0**: This would definitely be simpler, but I still appreciate the complete answer you originally posted!  

---

### Answer by username_2 on 2021-09-09. Score: 0

Color is a difficult matter. I anticipate that there is no unique solution to your question, and that things can get arbitrarily complicated the deeper you dig into the problem.
In order to present the correct color of the stars in your rendering, you have to account for many different "layers" of representation of the color.

The spectrum of the star, which is a continuum function of the wavelength.
The Gaia filters, that transform the continuum spectrum in a finite set of magnitude values for some bands.
The RGB color, that describes the color with three real numbers.
The way a display converts an RGB color into an electromagnetic spectrum. Which will be utterly different than the original spectrum of the star.
The way your eye perceives the color (with three different receptors) and the way your brain processes this information.

Each step encodes the color of the previous step in a different way. But each encoding loses information and you can't do anything about it. Additionally, you have direct control only on the step from 2 to 3. You can only (educately) guess what was the original spectrum of the star and guess what will be the perceived color at the end. Your task it to associate an RGB value to each Gaia filter measurement such that when a user looks at the monitor, they will perceive a similar color to the one they would have perceived if they had looked directly at the star. A daunting task! We'll have to make lots of approximations and assumptions.
Let's start by looking at Gaia's filters

Credits: ESA/Gaia/DPAC, P. Montegriffo, F. De Angeli, M. Bellazzini, E. Pancino, C. Cacciari, D. W. Evans, and CU5/PhotPipe team
This figure shows the transmissivity of the filters as a function of the wavelength. The green curve is the G filter. It encompasses all the visible range and also some near infrared (NIR). The blue curve is the BP filter, that covers all the visible range. The red curve is the RP filter, that covers the red part of the visible, but is mostly sensitive to near infrared. As you can see, G, BP and RP do not correspond to green, blue and red.
Let's compare this with the response function of the human cone cells:

Credits: BenRG
S (short) is usually associated with blue, M (medium) is often associated with green and L (long) with red. But as you can see this association is far from perfect. S actually peaks in the violet and both M and L span a large range from green to red.
They are totally different from Gaia's filters. This means that Gaia's "eyes" see color in a different way than human eyes. The two signals are not directly comparable.
What we could do instead, is estimate the shape of the original spectrum, from Gaia's data. Then we could calculate how such spectrum would be perceived by a human eye.
Estimating the original spectrum
The spectrum of a star can be complicated, full of absorption lines that depend on the temperature and composition. It can also be modified by radial motion (redshift), dust extinction and emission. I will ignore all the details and assume that the spectrum is a perfect black body. This is nice, because a black body spectrum is determined from its temperature $T$ only, so we need to estimate just one parameter.
Given a transmission function $t_W(\lambda)$ (the ones in the first picture) of a filter $W$, and the flux of a star $F(\lambda)$, the flux registered in the telescope through the filter will be
$$F_W = \frac{\int_0^\infty F(\lambda) t_W(\lambda)d\lambda}{\int_0^\infty t_W(\lambda)d\lambda}$$
From this page you can download a file that contains the shape of Gaia's transmission function. Or you can just approximate them with a constant value inside an interval and with zero outside.
As I said, you can use Planck law for the source flux, where $T$ is the temperature and $\epsilon$ is a normalization constant that depends on the brightness of the source.
$$F(\lambda; T, \epsilon) = {\epsilon \over \lambda^5} \frac{1}{\exp(\frac{hc}{\lambda k_B T})-1}$$
Let's say that a given filter $W$ measures a magnitude $m_W$ for a given star. You will first need to convert the magnitude to a flux $F_W$, and then you will need to find the values of $T$ and $\epsilon$ that minimize the function
$$f_W(T,\epsilon) = \left| F_W - \frac{\int_0^\infty F(\lambda; T, \epsilon) t_W(\lambda)d\lambda}{\int_0^\infty t_W(\lambda)d\lambda} \right|$$
Feel free to use your favorite minimization algorithm :)
Actually, you have three values to minimize, not just one, because Gaia tells you the readings of three filters. At this point I suggest you keep it simple and just minimize the sum of the squares of the three function:
$$f_G(T,\epsilon)^2 + f_{BP}(T,\epsilon)^2 + f_{RP}(T,\epsilon)^2$$
If the result is not satisfactory, then you can start to mess with maximum likelihood or Bayesian inference, but I'd leave it for another time.
Finding the RGB values
Now that you have the spectrum, things could get difficult. With a generic spectrum, you'd have to calculate the values of the XYZ coefficients of the CIE 1931 color space, and then convert them to the RGB coefficients of the sRGB color space.
But I have suggested to work with black bodies for a reason. This conversion from the spectrum to the RGB has already been done for the black body, and the results are tabulated. You can find the values for example here, or in many other places on the web.
You can even use the $\epsilon$ coefficient that you have found to set the brightness of the stars in your CGI software.
All is left to do is hope that layers 4 and 5 work as intended: e.g. that the monitor of your final users will display sRGB colors correctly and that your users won't be color blind ;)
I hope that this explanation has not discouraged you to the point of deciding to use the following algorithm, instead
R = random.uniform(0,255)
G = random.uniform(0,255)
B = random.uniform(0,255)

If you want some clarifications, feel free to ask.

> **Comments:**
> **username_0**: Thank you! The simulation and rendering software I use actually has a blackbody function that will convert a temperature in K to an RGB value. I've used it for rendering sparks, etc in the past, and it'll work perfectly for this. Unfortunately, the math in the "Estimating the original spectrum" section is a little bit beyond me, so any further clarification (or pointers to reference on the topic) you can provide there would be much appreciated!  
> **username_2**: @username_0 I think that the easiest way could be to use the 161,497,595 sources that already have a computed effective temperature inside [Gaia DR2 catalogue](https://www.cosmos.esa.int/web/gaia/dr2). I'm sorry, this answer was an overkill  
> **username_2**: @username_0 I have posted another answer, but I will keep this one, just in case I am trapped on a desert island with an hard drive filled only with EDR3 photometry data and no precalculated effective temperatures. (And also a pc, electricity and this SE page cached in my browser)  

---

