<p>The WeatherBit <a href="https://www.weatherbit.io/api/weather-forecast-16-day" rel="noreferrer">16-day forecast documentation</a> gives these output field descriptions:</p>
<blockquote>
<ul>
<li><code>moon_phase</code>: Moon phase illumination fraction (0-1)</li>
<li><code>moon_phase_lunation</code>: Moon lunation fraction (0 = New moon, 0.50 = Full Moon, 0.75 = Last quarter moon)</li>
</ul>
</blockquote>
<p>The illuminated fraction doesn't help you distinguish waxing and waning phases, so <code>moon_phase_lunation</code> is the value to use.
One possible mapping is:</p>
<p>0.0  0.06  0.19  0.31  0.44  0.56  0.69  0.81  0.94  1.0</p>

CC BY-SA 4.0
2020-12-13T19:57:31.613Z
Ah, that's great.  bonus thanks for using the character codes.  i also considered them but found them too yellow for me.  luckily my backgfround is non-white so actual white moon work and look better to me
Michael Durrant
CC BY-SA 4.0
2020-12-13T19:57:59.623Z
then ii considered some sort of blacfk and whote overlay but that seemed silly too
Michael Durrant
CC BY-SA 4.0
2020-12-13T19:58:43.453Z
i also figured the change was a sine(/) wave which your numbers reflect so that is helpful
Michael Durrant
CC BY-SA 4.0
2020-12-13T20:07:42.750Z
I expect that $\text{moon_phase} \approx \frac{1 - \cos 2 \pi ~ \text{moon_phase_lunation}}{2}$
Mike G
CC BY-SA 4.0
2020-12-13T19:52:29.537Z
2020-12-13T19:52:29.537Z
Mike G
<p>It looks to me like these numbers from 0 to 1 are the amount of the moon showing, so a number near 0 is a new moon and a number near 1 is the full moon.  Try</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Min value</th>
<th>Max value</th>
<th>Phase name</th>
</tr>
</thead>
<tbody>
<tr>
<td>0</td>
<td>0.05</td>
<td>New Moon</td>
</tr>
<tr>
<td>0.05</td>
<td>0.45</td>
<td>Waxing/Waning crescent</td>
</tr>
<tr>
<td>0.45</td>
<td>0.55</td>
<td>First/Third Quarter</td>
</tr>
<tr>
<td>0.55</td>
<td>0.95</td>
<td>Waxing/Waning gibbous</td>
</tr>
<tr>
<td>0.95</td>
<td>1.0</td>
<td>Full</td>
</tr>
</tbody>
</table>
</div>
<p>If the numbers are going up, then use Waxing and First.  If the numbers are going down, use Waning and Third.  If it ends up that the numbers are instead the amount of moon in shadow, just reverse the order in the first two columns above.</p>

CC BY-SA 4.0
2020-12-13T19:46:05.860Z
Yeah I was thinking about seeing if numebr is increasing or decreasing.  However that's a bit tricky programming that.  I am now hoiping the lumation will help as shown. seeing if u have thoughts on that approach and use
Michael Durrant
CC BY-SA 4.0
2020-12-13T19:48:43.300Z
I am not familiar with 'lumation', but it sure looks like your code is working correctly now!
Connor Garcia
CC BY-SA 4.0
2020-12-14T06:40:29.763Z
It's not lumation, it's lunation. As in moon.
hobbs
CC BY-SA 4.0
2020-12-14T13:14:45.177Z
Yes, lunation is the term, thanks
Michael Durrant
CC BY-SA 4.0
2020-12-13T19:44:13.843Z
2020-12-14T12:25:18.600Z
2020-12-14T12:25:18.600Z
Connor Garcia
<p>I am querying an API (weatherbit) which returns a moon phase number which looks like this:</p>
<p>0.9594168</p>
<p>For the 16 days I look at the numbers vary from 0.006 to 0.99.
I have 8 &quot;moon phase&quot; icons for the full, crescent, gibbous, etc. phases.  Filenames are the phase names.</p>
<p>How can I map the moon phase number to the phase names so I can use images with those names appropriately.</p>
<p>Final Update: <strong>Use moon_phase_lunation (instead of moon phase number) only</strong></p>
<p>Here is the final js-react code which seems to be working well so far:</p>
<pre><code>import React from 'react';
const Moon = ( data ) =&gt; {
  const lunation = Number(data.moon_phase_lunation);
  let imageToUse;
  if (lunation &lt;= .06) imageToUse = 'new';
  if (lunation &gt; 0.06 &amp;&amp; lunation &lt;= .19) imageToUse = 'waxing_crescent';
  if (lunation &gt; 0.19 &amp;&amp; lunation &lt;= .31) imageToUse = 'third_quarter';
  if (lunation &gt; 0.31 &amp;&amp; lunation &lt;= .44) imageToUse = 'waxing_gibbous';
  if (lunation &gt; 0.44 &amp;&amp; lunation &lt;= .56) imageToUse = 'full';
  if (lunation &gt; 0.56 &amp;&amp; lunation &lt;= .69) imageToUse = 'waning_gibbous';
  if (lunation &gt; 0.69 &amp;&amp; lunation &lt;= .81) imageToUse = 'first_quarter';
  if (lunation &gt; 0.81 &amp;&amp; lunation &lt;= .94) imageToUse = 'waning_crescent';
  if (lunation &gt; 0.94 ) imageToUse = 'new';
  const imageURL = `/moonIcons/${imageToUse}.png`;
  return (
    &lt;&gt;
      &lt;img src= { imageURL } width=&quot;20px&quot; height=&quot;20px&quot; /&gt;
    &lt;/&gt;
  );
};

export default Moon;
</code></pre>

CC BY-SA 4.0
2020-12-13T17:42:23.233Z
Could you provide a link to the API you're using? Another number might help you distinguish waxing and waning phases.
Mike G
CC BY-SA 4.0
2020-12-13T18:12:23.877Z
they also give "moon_phase_lunation" which for one value just checked was 0.95, but sure what values are used for that.  url  is https://rapidapi.com/weatherbit/api/weather and then 16 day forecast
Michael Durrant
CC BY-SA 4.0
2020-12-13T23:46:36.870Z
Different but related question, you may find the question and answer posts and the comments under them *illuminating* (pun intended) [Mapping illumination to moon phase (font) icon](https://astronomy.stackexchange.com/q/39720/7982)
uhoh
CC BY-SA 4.0
2020-12-14T16:17:51.950Z
Looks good, but I think you have first and third quarters swapped.
Mike G
CC BY-SA 4.0
2020-12-14T16:21:34.777Z
Yeah that kept confusing me. Ui looks right so maybe I got images right but names for those swapped.
Michael Durrant
<the-moon><moon-phases>
How to map moon phase number + "lunation" to moon phase name?
Michael Durrant
# How to map moon phase number + "lunation" to moon phase name?

(Asked by: username_0 on 2020-12-13)

I am querying an API (weatherbit) which returns a moon phase number which looks like this:
0.9594168
For the 16 days I look at the numbers vary from 0.006 to 0.99.
I have 8 "moon phase" icons for the full, crescent, gibbous, etc. phases.  Filenames are the phase names.
How can I map the moon phase number to the phase names so I can use images with those names appropriately.
Final Update: Use moon_phase_lunation (instead of moon phase number) only
Here is the final js-react code which seems to be working well so far:
import React from 'react';
const Moon = ( data ) => {
  const lunation = Number(data.moon_phase_lunation);
  let imageToUse;
  if (lunation <= .06) imageToUse = 'new';
  if (lunation > 0.06 && lunation <= .19) imageToUse = 'waxing_crescent';
  if (lunation > 0.19 && lunation <= .31) imageToUse = 'third_quarter';
  if (lunation > 0.31 && lunation <= .44) imageToUse = 'waxing_gibbous';
  if (lunation > 0.44 && lunation <= .56) imageToUse = 'full';
  if (lunation > 0.56 && lunation <= .69) imageToUse = 'waning_gibbous';
  if (lunation > 0.69 && lunation <= .81) imageToUse = 'first_quarter';
  if (lunation > 0.81 && lunation <= .94) imageToUse = 'waning_crescent';
  if (lunation > 0.94 ) imageToUse = 'new';
  const imageURL = `/moonIcons/${imageToUse}.png`;
  return (
    <>
      
    
  );
};

export default Moon;

**Tags:** the-moon, moon-phases

> **Comments:**
> **username_1**: Could you provide a link to the API you're using? Another number might help you distinguish waxing and waning phases.  
> **username_0**: they also give "moon_phase_lunation" which for one value just checked was 0.95, but sure what values are used for that.  url  is https://rapidapi.com/weatherbit/api/weather and then 16 day forecast  
> **username_2**: Different but related question, you may find the question and answer posts and the comments under them *illuminating* (pun intended) [Mapping illumination to moon phase (font) icon](https://astronomy.stackexchange.com/q/39720/7982)  
> **username_1**: Looks good, but I think you have first and third quarters swapped.  
> **username_0**: Yeah that kept confusing me. Ui looks right so maybe I got images right but names for those swapped.  

---

## 2 answers

### Answer by username_1 on 2020-12-13. Score: 6

The WeatherBit [16-day forecast documentation](https://www.weatherbit.io/api/weather-forecast-16-day) gives these output field descriptions:

> * `moon_phase`: Moon phase illumination fraction (0-1)
> * `moon_phase_lunation`: Moon lunation fraction (0 = New moon, 0.50 = Full Moon, 0.75 = Last quarter moon)

The illuminated fraction doesn't help you distinguish waxing and waning phases, so `moon_phase_lunation` is the value to use.
One possible mapping is:

0.0 0.06 0.19 0.31 0.44 0.56 0.69 0.81 0.94 1.0

> **Comments:**
> **username_0**: Ah, that's great.  bonus thanks for using the character codes.  i also considered them but found them too yellow for me.  luckily my backgfround is non-white so actual white moon work and look better to me  
> **username_0**: then ii considered some sort of blacfk and whote overlay but that seemed silly too  
> **username_0**: i also figured the change was a sine(/) wave which your numbers reflect so that is helpful  
> **username_1**: I expect that $\text{moon_phase} \approx \frac{1 - \cos 2 \pi ~ \text{moon_phase_lunation}}{2}$  

---

### Answer by username_3 on 2020-12-13. Score: 4

It looks to me like these numbers from 0 to 1 are the amount of the moon showing, so a number near 0 is a new moon and a number near 1 is the full moon. Try

| Min value | Max value | Phase name |
| --- | --- | --- |
| 0 | 0.05 | New Moon |
| 0.05 | 0.45 | Waxing/Waning crescent |
| 0.45 | 0.55 | First/Third Quarter |
| 0.55 | 0.95 | Waxing/Waning gibbous |
| 0.95 | 1.0 | Full |

If the numbers are going up, then use Waxing and First. If the numbers are going down, use Waning and Third. If it ends up that the numbers are instead the amount of moon in shadow, just reverse the order in the first two columns above.

> **Comments:**
> **username_0**: Yeah I was thinking about seeing if numebr is increasing or decreasing.  However that's a bit tricky programming that.  I am now hoiping the lumation will help as shown. seeing if u have thoughts on that approach and use  
> **username_3**: I am not familiar with 'lumation', but it sure looks like your code is working correctly now!  
> **username_4**: It's not lumation, it's lunation. As in moon.  
> **username_0**: Yes, lunation is the term, thanks  

---

