# Path: skyfield/almanac.py
# def phase_angle(ephemeris, body, t):
# def fraction_illuminated(ephemeris, body, t):
# def seasons(ephemeris):
#     def season_at(t):
# def moon_phase(ephemeris, t):
# def moon_phases(ephemeris):
#     def moon_phase_at(t):
# def moon_nodes(ephemeris):
#     def moon_node_at(t):
# def oppositions_conjunctions(ephemeris, target):
#     def leading_or_trailing(t):
# def meridian_transits(ephemeris, target, topos):
#     def west_of_meridian_at(t):
# def sunrise_sunset(ephemeris, topos):
#     def is_sun_up_at(t):
# def dark_twilight_day(ephemeris, topos):
#     def is_it_dark_twilight_day_at(t):
# def risings_and_settings(ephemeris, target, topos,
#                          horizon_degrees=-34.0/60.0, radius_degrees=0): #?
#     def is_body_up_at(t):
# SEASONS = [
#     'Spring',
#     'Summer',
#     'Autumn',
#     'Winter',
# ]
# SEASON_EVENTS = [
#     'Vernal Equinox',
#     'Summer Solstice',
#     'Autumnal Equinox',
#     'Winter Solstice',
# ]
# SEASON_EVENTS_NEUTRAL = [
#     'March Equinox',
#     'June Solstice',
#     'September Equinox',
#     'December Solstice',
# ]
# MOON_PHASES = [
#     'New Moon',
#     'First Quarter',
#     'Full Moon',
#     'Last Quarter',
# ]
# MOON_NODES = [
#     'descending',
#     'ascending',
# ]
# CONJUNCTIONS = [
#     'conjunction',
#     'opposition',
# ]
# MERIDIAN_TRANSITS = ['Antimeridian transit', 'Meridian transit']
# TWILIGHTS = {
#     0: 'Night',
#     1: 'Astronomical twilight',
#     2: 'Nautical twilight',
#     3: 'Civil twilight',
#     4: 'Day',
# }
# 
# Path: skyfield/api.py
# N = E = +1.0
# S = W = -1.0
# 
# Path: skyfield/api.py
# N = E = +1.0
# S = W = -1.0


from skyfield import almanac, api
from skyfield.api import load, tau
from numpy import arccos, sin, cos
from time import time
import numpy as np
# f(ts.tt_jd(sunrise_t.tt - 1/24.0/3600.0), 'at sunrise - 1 second')
# f(ts.tt_jd(sunrise_t.tt + 1/24.0/3600.0), 'at sunrise + 1 second')

# http://slittlefair.staff.shef.ac.uk/teaching/phy115/session3/page4/page6/page6.html

# sin ALT = sin LAT * sin DEC + cos LAT * cos DEC * cos HA
# sin LAT * sin DEC + cos LAT * cos DEC * cos HA = sin ALT
# cos LAT * cos DEC * cos HA = sin ALT - sin LAT * sin DEC
# cos HA = (sin ALT - sin LAT * sin DEC) / (cos LAT * cos DEC)
# HA = arrcos((sin ALT - sin LAT * sin DEC) / (cos LAT * cos DEC))

#cos HA = (sin ALT - sin LAT sin DEC) / (cos LAT cos DEC)


# alt, az, _ = app.altaz()

# ALT =
# print('ALT', alt.radians)
# DEC = dec.radians
# print('DEC', dec.radians)
# LAT = bluffton.latitude.radians
# print('LAT', bluffton.latitude.radians)

def _sunrise_hour_angle_radians(latitude, declination, altitude_radians):
    lat = latitude.radians
    dec = declination.radians
    ha = arccos((sin(altitude_radians) - sin(lat) * sin(dec))
                / (cos(lat) * cos(dec)))
    return ha


# Path: skyfield/almanac.py
# def phase_angle(ephemeris, body, t):
# def fraction_illuminated(ephemeris, body, t):
# def seasons(ephemeris):
#     def season_at(t):
# def moon_phase(ephemeris, t):
# def moon_phases(ephemeris):
#     def moon_phase_at(t):
# def moon_nodes(ephemeris):
#     def moon_node_at(t):
# def oppositions_conjunctions(ephemeris, target):
#     def leading_or_trailing(t):
# def meridian_transits(ephemeris, target, topos):
#     def west_of_meridian_at(t):
# def sunrise_sunset(ephemeris, topos):
#     def is_sun_up_at(t):
# def dark_twilight_day(ephemeris, topos):
#     def is_it_dark_twilight_day_at(t):
# def risings_and_settings(ephemeris, target, topos,
#                          horizon_degrees=-34.0/60.0, radius_degrees=0): #?
#     def is_body_up_at(t):
# SEASONS = [
#     'Spring',
#     'Summer',
#     'Autumn',
#     'Winter',
# ]
# SEASON_EVENTS = [
#     'Vernal Equinox',
#     'Summer Solstice',
#     'Autumnal Equinox',
#     'Winter Solstice',
# ]
# SEASON_EVENTS_NEUTRAL = [
#     'March Equinox',
#     'June Solstice',
#     'September Equinox',
#     'December Solstice',
# ]
# MOON_PHASES = [
#     'New Moon',
#     'First Quarter',
#     'Full Moon',
#     'Last Quarter',
# ]
# MOON_NODES = [
#     'descending',
#     'ascending',
# ]
# CONJUNCTIONS = [
#     'conjunction',
#     'opposition',
# ]
# MERIDIAN_TRANSITS = ['Antimeridian transit', 'Meridian transit']
# TWILIGHTS = {
#     0: 'Night',
#     1: 'Astronomical twilight',
#     2: 'Nautical twilight',
#     3: 'Civil twilight',
#     4: 'Day',
# }
# 
# Path: skyfield/api.py
# N = E = +1.0
# S = W = -1.0
# 
# Path: skyfield/api.py
# N = E = +1.0
# S = W = -1.0


# Path: design/sunrise.py
from skyfield import almanac, api
from skyfield.api import load, tau
from numpy import arccos, sin, cos
from time import time
import numpy as np

# f(ts.tt_jd(sunrise_t.tt - 1/24.0/3600.0), 'at sunrise - 1 second')
# f(ts.tt_jd(sunrise_t.tt + 1/24.0/3600.0), 'at sunrise + 1 second')

# http://slittlefair.staff.shef.ac.uk/teaching/phy115/session3/page4/page6/page6.html

# sin ALT = sin LAT * sin DEC + cos LAT * cos DEC * cos HA
# sin LAT * sin DEC + cos LAT * cos DEC * cos HA = sin ALT
# cos LAT * cos DEC * cos HA = sin ALT - sin LAT * sin DEC
# cos HA = (sin ALT - sin LAT * sin DEC) / (cos LAT * cos DEC)
# HA = arrcos((sin ALT - sin LAT * sin DEC) / (cos LAT * cos DEC))

#cos HA = (sin ALT - sin LAT sin DEC) / (cos LAT cos DEC)


# alt, az, _ = app.altaz()

# ALT =
# print('ALT', alt.radians)
# DEC = dec.radians
# print('DEC', dec.radians)
# LAT = bluffton.latitude.radians
# print('LAT', bluffton.latitude.radians)

def _sunrise_hour_angle_radians(latitude, declination, altitude_radians):
    lat = latitude.radians
    dec = declination.radians
    ha = arccos((sin(altitude_radians) - sin(lat) * sin(dec))
                / (cos(lat) * cos(dec)))
    return ha


stdalt = -0.833 / 360.0 * tau