Tronald/CoordinateSharp

Moon Phases List

jrahma opened this issue · 3 comments

Hi,

What are the moon Phases list returned from the PhaseName?

and Is there any code for them? for example if I want to check the Phase code and base on that I will show the correct phase image from my server?

Thank you

Thank you for checking out CoordinateSharp.

Here is what the developer guide lists regarding moon phases: https://coordinatesharp.com/DeveloperGuide#moon-illumination-and-phase

I will add a few notes however.

The phase name list does not list the "in between" names. Here is the complete list. Phases goes from .0-1 then reset.

Phase Name
.0 New Moon
Waxing Crescent
.25 First Quarter
Waxing Gibbous
.5 Full Moon
Waning Gibbous
.75 Last Quarter
Waning Crescent

The phase name returned is based on the specific date (not a specific night spanning 2 days). Because of this you may wish to use the Phase value vs the PhaseName and implement your own phase code that returns an image.

Here is the phase name code:

To extract phase or phase name:

//UTC Example
Coordinate c = new Coordinate(lat, lng, DateTime); 
c.CelestialInfo.MoonIllum.Phase;
c.CelestialInfo.MoonIllum.PhaseName; 

How about this:

switch (c.CelestialInfo.MoonIllum.Phase)
{
    case double n when (n == 0):
        phase_name = "new moon";
        moon_file = "new_moon";
        break;
    case double n when (n > 0 && n < 0.25):
        phase_name = "waxing crescent";
        moon_file = "waxing_crescent";
        break;
    case double n when (n == 0.25):
        phase_name = "first quarter";
        moon_file = "first_quarter";
        break;
    case double n when (n > 0.25 && n < 0.5):
        phase_name = "waxing gibbous";
        moon_file = "waxing_gibbous";
        break;
    case double n when (n == 0.5):
        phase_name = "full moon";
        moon_file = "full_moon";
        break;
    case double n when (n > 0.5 && n < 0.75):
        phase_name = "waning gibbous";
        moon_file = "waning_gibbous";
        break;
    case double n when (n == 0.75):
        phase_name = "last quarter";
        moon_file = "last_quarter";
        break;
    case double n when (n > 0.75 && n <= 1):
        phase_name = "waning crescent";
        moon_file = "waning_crescent";
        break;
}

With your current logic, the New, Quarter, Full and Last Quarter moons will rarely hit, as they will only show for a moment in time as the Phase is a long float point double. I edited my above comment for clarity as I misspoke a bit.

For example, while technically .5 is a Full Moon you may want it to show as Full Moon when the .5 triggers at any time during a date (or night spanning over 2 dates). CoordinateSharp gets the phase at the beginning and end of a date and then makes the determination as the which PhaseName to use. It prioritizes New, Quarter, Full and Last Quarter moons over Waxing and Waning.

Example Pseudo for getting a full moon:

//Trigger full moon if it occurs at any point during the day
if(phaseAtStartofDay <= .5 && phaseAtEndOfDay >=.5)
{
     phase_name = "full moon";
     moon_file = "full_moon";
}

You could also tap into the Phase Name string values (but these could change in theory). I will consider adding a PhaseName enum to the MoonIllum class to avoid breaking string changes in a future release.

switch (c.CelestialInfo.MoonIllum.PhaseName)
{
    .
    .
    .
    case string p when (p== "Full Moon")
       moon_file="full_moon";
       break;
    case string p when (p== "Waning Gibbous")   
       moon_file = "waning_gibbous";
       break;
    .
    .
    .
}

PhaseName string values returned are currently as follows.

  • New Moon
  • First Quarter
  • Full Moon
  • Last Quarter
  • Waxing Crescent
  • Waxing Gibbous
  • Waning Gibbous
  • Waning Crescent