jhurliman

jhurliman / SunMoonCalculator / 0.1.0

README.md

Overview

Calculate sun position, sunlight phases (times for sunrise, sunset, dusk, etc.), moon position and lunar phase for a given location and time. Based on code from the SunCalc.net project.

Usage

Input

ParameterDescription
timeDate used for calculations. Common date/time formats are accepted such as YYYY-MM-DD and ISO 8601
latLatitude. Valid values range from [-90, 90]
lonLongitude. Valid values range from [-180, 180]

Output

ParameterDescription
timeInput timestamp used for calculations
sunrisesunrise (top edge of the sun appears on the horizon)
sunrise_endsunrise ends (bottom edge of the sun touches the horizon)
golden_hour_endmorning golden hour (soft light, best time for photography) ends
solar_noonsolar noon (sun is in the highest position)
golden_hourevening golden hour starts
sunset_startsunset starts (bottom edge of the sun touches the horizon)
sunsetsunset (sun disappears below the horizon, evening civil twilight starts)
duskdusk (evening nautical twilight starts)
nautical_dusknautical dusk (evening astronomical twilight starts)
nightnight starts (dark enough for astronomical observations)
nadirnadir (darkest moment of the night, sun is in the lowest position)
night_endnight ends (morning astronomical twilight starts)
nautical_dawnnautical dawn (morning nautical twilight starts)
dawndawn (morning nautical twilight ends, morning civil twilight starts)
sun_altitudesun altitude above the horizon in radians, e.g. 0 at the horizon and PI/2 at the zenith (straight over your head)
sun_azimuthsun azimuth in radians (direction along the horizon, measured from south to west), e.g. 0 is south and Math.PI * 3/4 is northwest
moon_altitudemoon altitude above the horizon in radians
moon_azimuthmoon azimuth in radians
moon_distancedistance to moon in kilometers
moon_parallactic_angleparallactic angle of the moon in radians
moon_fractionilluminated fraction of the moon; varies from 0.0 (new moon) to 1.0 (full moon)
moon_phasemoon phase; varies from 0.0 to 1.0, described below
moon_anglemidpoint angle in radians of the illuminated limb of the moon reckoned eastward from the north point of the disk; the moon is waxing if the angle is negative, and waning if positive
moonrisemoonrise time
moonsetmoonset time
moon_always_uptrue if the moon never rises/sets and is always above the horizon during the day
moon_always_downtrue if the moon is always below the horizon

Moon phase should be interpreted as:

ValuePhase
0New Moon
Waxing Crescent
0.25First Quarter
Waxing Gibbous
0.5Full Moon
Waning Gibbous
0.75Last Quarter
Waning Crescent

Examples

Input:

{  
    "time":"2017-10-22T22:19:55.211Z",
    "lat":37.8044,
    "lon":122.2711
}

Output:

{  
    "dawn":"2017-10-22T21:41:10.750Z",
    "dusk":"2017-10-23T09:31:41.360Z",
    "golden_hour":"2017-10-23T08:28:52.002Z",
    "golden_hour_end":"2017-10-22T22:44:00.108Z",
    "moon_altitude":-0.5289480705057222,
    "moon_angle":-1.5180271321248809,
    "moon_azimuth":-1.6180776214866398,
    "moon_distance":403993.661224214,
    "moon_fraction":0.1000407737691863,
    "moon_parallactic_angle":-0.9658544274436652,
    "moon_phase":0.10243801154640608,
    "moonrise":"2017-10-23T01:03:02.037Z",
    "moonset":"2017-10-22T10:58:19.822Z",
    "nadir":"2017-10-22T15:36:26.055Z",
    "nautical_dawn":"2017-10-22T21:10:32.302Z",
    "nautical_dusk":"2017-10-23T10:02:19.808Z",
    "night":"2017-10-23T10:32:45.096Z",
    "night_end":"2017-10-22T20:40:07.013Z",
    "solar_noon":"2017-10-23T03:36:26.055Z",
    "sun_altitude":0.027987016697548253,
    "sun_azimuth":-1.2984399100983957,
    "sunrise":"2017-10-22T22:07:54.047Z",
    "sunset":"2017-10-23T09:04:58.063Z",
    "sunset_start":"2017-10-23T09:02:11.231Z",
    "time":"2017-10-22T22:19:55.211Z"
}