Ejemplo n.º 1
0
def get_phase_name(location: Optional[ephem.Observer] = None, wiggle_room: float = 1.5) -> str:
    """Return name of the phase of the moon."""
    if location:
        date = location.date
    else:
        date = ephem.now()
    if abs(ephem.next_first_quarter_moon(date) - date) < wiggle_room or \
            abs(ephem.previous_first_quarter_moon(date) - date) < wiggle_room:
        return 'first quarter moon'
    elif abs(ephem.next_full_moon(date) - date) < wiggle_room or \
            abs(ephem.previous_full_moon(date) - date) < wiggle_room:
        return 'full moon'
    elif abs(ephem.next_last_quarter_moon(date) - date) < wiggle_room or \
            abs(ephem.previous_last_quarter_moon(date) - date) < wiggle_room:
        return 'last quarter moon'
    elif abs(ephem.next_new_moon(date) - date) < wiggle_room or \
            abs(ephem.previous_new_moon(date) - date) < wiggle_room:
        return 'new moon'
    elif ephem.next_first_quarter_moon(date) - ephem.previous_new_moon(date) < 29:
        return 'waxing crescent'
    elif ephem.next_full_moon(date) - ephem.previous_first_quarter_moon(date) < 29:
        return 'waxing gibbous'
    elif ephem.next_last_quarter_moon(date) - ephem.previous_full_moon(date) < 29:
        return 'waning gibbous'
    elif ephem.next_new_moon(date) - ephem.previous_last_quarter_moon(date) < 29:
        return 'waning crescent'
    return ''
Ejemplo n.º 2
0
def moon_phases(start, end, output_format):
    d = ephem.previous_full_moon(start)
    d = ephem.previous_full_moon(d)
    print("Starting from", d)

    def output_moon_phase(d, phasename, img, attr):
        if output_format == "sql":
            print("('%s', 'astronomy', 'naked eye', '%s', '%s', '%s', "
                  "'%s', 240, 240, '%s')," %
                  (phasename + " moon", datestr(d), datestr(d),
                   phasename + " moon", img, attr))
        else:
            print(datestr(d), ":", phasename + " moon")

    while d <= end:
        d = ephem.next_first_quarter_moon(d)
        output_moon_phase(
            d, "First quarter", 'astronomy/Phase-088.jpg',
            '<a href=\"http://commons.wikimedia.org/wiki/'
            'File:Phase-088.jpg\">Jay Tanner</a>')
        d = ephem.next_full_moon(d)
        output_moon_phase(
            d, "Full", 'astronomy/Phase-180.jpg',
            '<a href=\"http://commons.wikimedia.org/wiki/'
            'File:Phase-180.jpg\">Jay Tanner</a>')
        d = ephem.next_last_quarter_moon(d)
        output_moon_phase(
            d, "Last quarter", 'astronomy/Phase-270.jpg',
            '<a href=\"http://commons.wikimedia.org/wiki/'
            'File:Phase-270.jpg\">Jay Tanner</a>')
        d = ephem.next_new_moon(d)
        output_moon_phase(
            d, "New", 'astronomy/New_Moon.jpg',
            '<a href="https://commons.wikimedia.org/wiki/'
            'File:New_Moon.jpg">QuimGil</a>')
Ejemplo n.º 3
0
def make_moon_stuff(outer_canv, inner_canv, begin_day, no_days, chart,
        obs):
    small_moon_rad = 0.12
    large_moon_rad = 0.16
    moon = ephem.Moon()
    moon2 = ephem.Moon()
    for doy in range(no_days) :
        obs.date = begin_day + doy
        mpc = obs.date + 0.5 # moon phase check
        moon_set = obs.next_setting(moon)
        moon2.compute(moon_set)
        X = moon2.moon_phase
        # Waxing moon (moonsets)
        x, y = to_chart_coord(moon_set, chart)
        if (fabs(ephem.next_full_moon(mpc) - mpc) < 0.5 or
            fabs(ephem.previous_full_moon(mpc) - mpc) < 0.5) :
            # full moon
            outer_canv.stroke(path.circle(x,y,large_moon_rad),[mooncolorlight,pyx.deco.filled([mooncolorlight])])
        elif ((X < 0.55 and X > 0.45) or 
              fabs(ephem.next_first_quarter_moon(mpc) - mpc) < 0.5 or
              fabs(ephem.previous_first_quarter_moon(mpc) - mpc) < 0.5) :
            # first quarter
            outer_canv.stroke(first_quarter_moon(large_moon_rad, x,y),[mooncolordark,pyx.deco.filled([mooncolordark])])
        elif (fabs(ephem.next_new_moon(mpc) - mpc) < 0.5 or
              fabs(ephem.previous_new_moon(mpc) - mpc) < 0.5):
            # new moon
            outer_canv.stroke(path.circle(x,y,large_moon_rad),[mooncolorlight,pyx.deco.filled([mooncolordark])])
        else :
            inner_canv.fill(waxing_moon(X, small_moon_rad, x, y),
                    [style.linejoin.bevel,mooncolordark])
        # Waning moon (moonrises)
        moon_rise = obs.next_rising(moon)
        moon2.compute(moon_rise)
        X = moon2.moon_phase
        x, y = to_chart_coord(moon_rise, chart)
        if (fabs(ephem.next_full_moon(mpc) - mpc) < 0.5 or
            fabs(ephem.previous_full_moon(mpc) - mpc) < 0.5) :
            # full moon
            outer_canv.stroke(path.circle(x,y,large_moon_rad),[mooncolorlight,pyx.deco.filled([mooncolorlight])])
        elif ((X < 0.55 and X > 0.45) or 
              fabs(ephem.next_last_quarter_moon(mpc) - mpc) < 0.5 or
              fabs(ephem.previous_last_quarter_moon(mpc) - mpc) < 0.5) :
            # last quarter
            outer_canv.stroke(last_quarter_moon(large_moon_rad, x,y),[mooncolorlight,pyx.deco.filled([mooncolorlight])])
        elif (fabs(ephem.next_new_moon(mpc) - mpc) < 0.5 or
              fabs(ephem.previous_new_moon(mpc) - mpc) < 0.5):
            # new moon
            outer_canv.stroke(path.circle(x,y,large_moon_rad),[mooncolorlight,pyx.deco.filled([mooncolordark])])
        else :
            inner_canv.fill(waning_moon(X, small_moon_rad, x, y),
                    [style.linejoin.bevel,mooncolorlight])
Ejemplo n.º 4
0
 def __init__(self):
     self.__logger = logging.getLogger(self.__class__.__name__)
     #find current moon phase
     now = ephem.now()
     new_date = ephem.next_new_moon(now)
     first_quarter_date = ephem.next_first_quarter_moon(now)
     full_date = ephem.next_full_moon(now)
     last_quarter_date = ephem.next_last_quarter_moon(now)
     delta = float('inf')
     if new_date - now < delta:
         delta = new_date - now
         self.__current_phase = MoonUpdater.LAST_QUARTER_MOON
         self.__current_phase_date = ephem.previous_last_quarter_moon(
             now).datetime()
     if first_quarter_date - now < delta:
         delta = first_quarter_date - now
         self.__current_phase = MoonUpdater.NEW_MOON
         self.__current_phase_date = ephem.previous_new_moon(now).datetime()
     if full_date - now < delta:
         delta = full_date - now
         self.__current_phase = MoonUpdater.FIRST_QUARTER_MOON
         self.__current_phase_date = ephem.previous_first_quarter_moon(
             now).datetime()
     if last_quarter_date - now < delta:
         delta = last_quarter_date - now
         self.__current_phase = MoonUpdater.FULL_MOON
         self.__current_phase_date = ephem.previous_full_moon(
             now).datetime()
Ejemplo n.º 5
0
def get_moon_phase(observer):
    target_date_utc = observer.date
    target_date_local = ephem.localtime(target_date_utc).date()
    next_full = ephem.localtime(ephem.next_full_moon(target_date_utc)).date()
    next_new = ephem.localtime(ephem.next_new_moon(target_date_utc)).date()
    next_last_quarter = ephem.localtime(
        ephem.next_last_quarter_moon(target_date_utc)).date()
    next_first_quarter = ephem.localtime(
        ephem.next_first_quarter_moon(target_date_utc)).date()
    previous_full = ephem.localtime(
        ephem.previous_full_moon(target_date_utc)).date()
    previous_new = ephem.localtime(
        ephem.previous_new_moon(target_date_utc)).date()
    previous_last_quarter = ephem.localtime(
        ephem.previous_last_quarter_moon(target_date_utc)).date()
    previous_first_quarter = ephem.localtime(
        ephem.previous_first_quarter_moon(target_date_utc)).date()

    if target_date_local in (next_full, previous_full):
        return 'Full'
    elif target_date_local in (next_new, previous_new):
        return 'New'
    elif target_date_local in (next_first_quarter, previous_first_quarter):
        return 'First Quarter'
    elif target_date_local in (next_last_quarter, previous_last_quarter):
        return 'Last Quarter'
    elif previous_new < next_first_quarter < next_full < next_last_quarter < next_new:
        return 'Waxing Crescent'
    elif previous_first_quarter < next_full < next_last_quarter < next_new < next_first_quarter:
        return 'Waxing Gibbous'
    elif previous_full < next_last_quarter < next_new < next_first_quarter < next_full:
        return 'Waning Gibbous'
    elif previous_last_quarter < next_new < next_first_quarter < next_full < next_last_quarter:
        return 'Waning Crescent'
Ejemplo n.º 6
0
def run():
    ''' Get the first fall sub 29 and when the nearest full moon was that year
    '''
    cursor.execute(''' SELECT year, min(day), min(extract(doy from day))
    from alldata_ia where
    station = 'IA0200' and low < 29 and month > 6 GROUP by year ORDER
    by year ASC''')
    juliandays = []
    moondiff = []
    for row in cursor:
        juliandays.append( row[2] )
        myloc.date = "%s/%s/%s" % (row[1].year, row[1].month, row[1].day)
        
        lastd = s2dt(ephem.previous_full_moon(myloc.date)).date()
        today = row[1]
        nextd = s2dt(ephem.next_full_moon(myloc.date)).date()
        forward = (nextd - today).days
        backward = (today - lastd).days
        if backward == forward:
            moondiff.append(backward)
        elif backward < forward:
            moondiff.append( backward )
        elif forward < backward:
            moondiff.append( 0 - forward)
            
    return moondiff, juliandays
Ejemplo n.º 7
0
def find_azimuths(observer):
    riseset = {}

    # Find sunrise and sunset:
    riseset['sun'] = find_rise_set(observer, ephem.Sun())

    # Now find the full moon closest to the date,
    # which may be the next full moon or the previous one.
    lastfull = ephem.previous_full_moon(observer.date)
    nextfull = ephem.next_full_moon(observer.date)
    now = ephem.now()
    if now - lastfull > nextfull - now:
        observer.date = nextfull
    else:
        observer.date = lastfull

    riseset['full moon'] = find_rise_set(observer, ephem.Moon())

    return riseset
Ejemplo n.º 8
0
def find_azimuths(observer):
    riseset = {}

    # Find sunrise and sunset:
    riseset['sun'] = find_rise_set(observer, ephem.Sun())

    # Now find the full moon closest to the date,
    # which may be the next full moon or the previous one.
    lastfull = ephem.previous_full_moon(observer.date)
    nextfull = ephem.next_full_moon(observer.date)
    now = ephem.now()
    if now - lastfull > nextfull - now:
        observer.date = nextfull
    else:
        observer.date = lastfull

    riseset['full moon'] = find_rise_set(observer, ephem.Moon())

    return riseset
Ejemplo n.º 9
0
def get_moon_ill(obs,time):
    obs2     = ephem.Observer()
    obs2.lat = obs.site_info.latitude
    if obs.site_info.longitude[0] == '-':
        obs2.lon = obs.site_info.longitude[1:]
    else:
        obs2.lon = '-'+obs.site_info.longitude
    obs2.elevation = obs.site_info.elevation
    m = ephem.Moon()
    obs2.date = time
    m.compute(obs2)

    pfm = ephem.previous_full_moon(obs2.date)  
    nfm = ephem.next_full_moon(obs2.date)  
    pnm = ephem.previous_new_moon(obs2.date)
    nnm = ephem.next_new_moon(obs2.date)
    if obs2.date - pnm < obs2.date - pfm:
        moon_state = 'crescent'
        lunation   = (obs2.date-pnm)/(nfm-pnm)
    else:
        moon_state = 'waning'
        lunation   = 1. - (obs2.date-pfm)/(nnm-pfm)

    return moon_state, lunation
Ejemplo n.º 10
0
def new_moon(bot, update):

    dfu = update.message.text

    moon = {
        "Предыдущий цикл": {
            "Последняя четверть луны": ephem.previous_last_quarter_moon(dfu),
            "Новолуние": ephem.previous_new_moon(dfu),
            "Первая четверть луны": ephem.previous_first_quarter_moon(dfu),
            "Полнолуние": ephem.previous_full_moon(dfu),
        },
        "Следующий цикл": {
            "Последняя четверть луны": ephem.next_last_quarter_moon(dfu),
            "Новолуние": ephem.next_new_moon(dfu),
            "Первая четверть луны": ephem.next_first_quarter_moon(dfu),
            "Полнолуние": ephem.next_full_moon(dfu),
        }
    }

    for key in moon:
        bot.sendMessage(update.message.chat_id, text=key)
        for row_key in moon[key]:
            bot.sendMessage(update.message.chat_id,
                            text=(row_key, ":", moon[key][row_key]))
Ejemplo n.º 11
0
data['sun']['azimuth'] = sun.az

# MOON DATA
moonrise = observer.previous_rising(ephem.Moon())
moonnoon    = observer.next_transit   (ephem.Moon())
moonset  = observer.next_setting   (ephem.Moon())
data['moon']['rise'] = calendar.timegm(moonrise.datetime().utctimetuple())
data['moon']['noon']    = calendar.timegm(moonnoon.datetime().utctimetuple())
data['moon']['set']  = calendar.timegm(moonset.datetime().utctimetuple())
data['moon']['radius'] = ephem.moon_radius

previous_new_moon = ephem.previous_new_moon(time)
next_new_moon = ephem.next_new_moon(time)
previous_first_quarter_moon = ephem.previous_first_quarter_moon(time)
next_first_quarter_moon = ephem.next_first_quarter_moon(time)
previous_full_moon = ephem.previous_full_moon(time)
next_full_moon = ephem.next_full_moon(time)
previous_last_quarter_moon = ephem.previous_last_quarter_moon(time)
next_last_quarter_moon = ephem.next_last_quarter_moon(time)

data['moon']['previous_new_moon'] = calendar.timegm(previous_new_moon.datetime().utctimetuple())
data['moon']['next_new_moon'] = calendar.timegm(next_new_moon.datetime().utctimetuple())
data['moon']['previous_first_quarter_moon'] = calendar.timegm(previous_first_quarter_moon.datetime().utctimetuple())
data['moon']['next_first_quarter_moon'] = calendar.timegm(next_first_quarter_moon.datetime().utctimetuple())
data['moon']['previous_full_moon'] = calendar.timegm(previous_full_moon.datetime().utctimetuple())
data['moon']['next_full_moon'] = calendar.timegm(next_full_moon.datetime().utctimetuple())
data['moon']['previous_last_quarter_moon'] = calendar.timegm(previous_last_quarter_moon.datetime().utctimetuple())
data['moon']['next_last_quarter_moon'] = calendar.timegm(next_last_quarter_moon.datetime().utctimetuple())

moon = ephem.Moon()
moon.compute(observer)
Ejemplo n.º 12
0
    def onHeartbeat(self):
        Domoticz.Debug("onHeartbeat")
        self.__runAgain -= 1
        if self.__runAgain <= 0:
            self.__runAgain = self.__HEARTBEATS2MIN * self.__MINUTES
            #
            utc_now = datetime.datetime.utcnow()
            target_date = datetime.datetime.now().date()
            #
            self.__observer.date = utc_now
            self.__sun.compute(self.__observer)
            #
            ################################################################################
            # Sun data
            ################################################################################
            #
            # -------------------------------------------------------------------------------
            # Sun altitude
            # -------------------------------------------------------------------------------
            value = round(deg(self.__sun.alt), 2)
            UpdateDevice(unit.SUN_ALT, int(value), str(value))
            #
            # -------------------------------------------------------------------------------
            # Sun azimuth
            # -------------------------------------------------------------------------------
            value = round(deg(self.__sun.az), 2)
            UpdateDevice(unit.SUN_AZ, int(value), str(value))
            #
            # -------------------------------------------------------------------------------
            # Sun distance
            # -------------------------------------------------------------------------------
            value = round(self.__sun.earth_distance * ephem.meters_per_au / 1000)
            UpdateDevice(unit.SUN_DIST, int(value), str(value))
            #
            # -------------------------------------------------------------------------------
            # Sun transit
            # -------------------------------------------------------------------------------
            value = (
                ephem.localtime(self.__observer.next_transit(self.__sun)) + self.__SEC30
            )
            UpdateDevice(
                unit.SUN_TRANSIT, 0, "{}".format(value.strftime(self.__DT_FORMAT))
            )
            #
            # -------------------------------------------------------------------------------
            # Sun rise & set today
            # -------------------------------------------------------------------------------
            self.__observer.date = target_date
            self.__sun.compute(self.__observer)
            i = 0
            for t in self.__TWILIGHTS:
                # Zero the horizon
                self.__observer.horizon = t[0]
                try:
                    next_rising = (
                        ephem.localtime(
                            self.__observer.next_rising(self.__sun, use_center=t[1])
                        )
                        + self.__SEC30
                    )
                    UpdateDevice(
                        unit.SUN_RISE + i,
                        0,
                        "{}".format(next_rising.strftime(self.__DT_FORMAT)),
                    )
                except:
                    UpdateDevice(
                        unit.SUN_RISE + i,
                        0,
                        "{}".format("No time available"),
                    )
                try:
                    next_setting = (
                        ephem.localtime(
                            self.__observer.next_setting(self.__sun, use_center=t[1])
                        )
                        + self.__SEC30
                    )
                    UpdateDevice(
                        unit.SUN_SET + i,
                        0,
                        "{}".format(next_setting.strftime(self.__DT_FORMAT)),
                    )
                except:
                    UpdateDevice(
                        unit.SUN_RISE + i,
                        0,
                        "{}".format("No time available"),
                    )
                if i == 0:
                    value = (next_setting - next_rising).total_seconds()
                    hh = divmod(value, 3600)
                    mm = divmod(hh[1], 60)
                    min = int(divmod(value, 60)[0])
                    UpdateDevice(
                        unit.DAY_LENGTH_M,
                        min,
                        "{}".format(min),
                    )
                    UpdateDevice(
                        unit.DAY_LENGTH_T,
                        0,
                        "{:02}:{:02}".format(int(hh[0]), int(mm[0])),
                    )

                i += 1
            #
            # Reset horizon for further calculations
            self.__observer.horizon = "0"
            #
            ################################################################################
            # Moon data
            ################################################################################
            #
            self.__observer.date = utc_now
            self.__moon.compute(self.__observer)
            #
            # -------------------------------------------------------------------------------
            # Moon rise
            # -------------------------------------------------------------------------------
            value = (
                ephem.localtime(self.__observer.next_rising(self.__moon)) + self.__SEC30
            )
            UpdateDevice(
                unit.MOON_RISE, 0, "{}".format(value.strftime(self.__DT_FORMAT))
            )
            #
            # -------------------------------------------------------------------------------
            # Moon set
            # -------------------------------------------------------------------------------
            value = (
                ephem.localtime(self.__observer.next_setting(self.__moon))
                + self.__SEC30
            )
            UpdateDevice(
                unit.MOON_SET, 0, "{}".format(value.strftime(self.__DT_FORMAT))
            )
            #
            # -------------------------------------------------------------------------------
            # Moon altitude
            # -------------------------------------------------------------------------------
            self.__moon.compute(self.__observer)
            #
            value = round(deg(self.__moon.alt), 2)
            UpdateDevice(unit.MOON_ALT, int(value), str(value))
            #
            # -------------------------------------------------------------------------------
            # Moon azimuth
            # -------------------------------------------------------------------------------
            value = round(deg(self.__moon.az), 2)
            UpdateDevice(unit.MOON_AZ, int(value), str(value))
            #
            # -------------------------------------------------------------------------------
            # Moon distance
            # -------------------------------------------------------------------------------
            value = round(self.__moon.earth_distance * ephem.meters_per_au / 1000)
            UpdateDevice(unit.MOON_DIST, int(value), str(value))
            #
            # -------------------------------------------------------------------------------
            # Next new moon
            # -------------------------------------------------------------------------------
            next_new = ephem.localtime(ephem.next_new_moon(utc_now))
            value = next_new + self.__SEC30
            UpdateDevice(
                unit.MOON_NEXT_NEW, 0, "{}".format(value.strftime(self.__DT_FORMAT))
            )
            #
            # -------------------------------------------------------------------------------
            # Next first quarter
            # -------------------------------------------------------------------------------
            next_first_quarter = ephem.localtime(ephem.next_first_quarter_moon(utc_now))
            value = next_first_quarter + self.__SEC30
            UpdateDevice(
                unit.MOON_NEXT_FIRST_QUARTER,
                0,
                "{}".format(value.strftime(self.__DT_FORMAT)),
            )
            #
            # -------------------------------------------------------------------------------
            # Next full moon
            # -------------------------------------------------------------------------------
            next_full = ephem.localtime(ephem.next_full_moon(utc_now))
            value = next_full + self.__SEC30
            UpdateDevice(
                unit.MOON_NEXT_FULL,
                0,
                "{}".format(value.strftime(self.__DT_FORMAT)),
            )
            #
            # -------------------------------------------------------------------------------
            # Next last quarter
            # -------------------------------------------------------------------------------
            next_last_quarter = ephem.localtime(ephem.next_last_quarter_moon(utc_now))
            value = next_last_quarter + self.__SEC30
            UpdateDevice(
                unit.MOON_NEXT_LAST_QUARTER,
                0,
                "{}".format(value.strftime(self.__DT_FORMAT)),
            )
            #
            # -------------------------------------------------------------------------------
            # Moon phase
            # -------------------------------------------------------------------------------
            next_full = next_full.date()
            next_new = next_new.date()
            next_last_quarter = next_last_quarter.date()
            next_first_quarter = next_first_quarter.date()
            previous_full = ephem.localtime(ephem.previous_full_moon(utc_now)).date()
            previous_new = ephem.localtime(ephem.previous_new_moon(utc_now)).date()
            previous_last_quarter = ephem.localtime(
                ephem.previous_last_quarter_moon(utc_now)
            ).date()
            previous_first_quarter = ephem.localtime(
                ephem.previous_first_quarter_moon(utc_now)
            ).date()
            #
            # Domoticz.Debug("target_date: {}".format(target_date))
            # Domoticz.Debug("next_full: {}".format(next_full))
            # Domoticz.Debug("next_new: {}".format(next_new))
            # Domoticz.Debug("next_last_quarter: {}".format(next_last_quarter))
            # Domoticz.Debug("next_first_quarter: {}".format(next_first_quarter))
            # Domoticz.Debug("previous_full: {}".format(previous_full))
            # Domoticz.Debug("previous_new: {}".format(previous_new))
            # Domoticz.Debug("previous_last_quarter: {}".format(previous_last_quarter))
            # Domoticz.Debug("previous_first_quarter: {}".format(previous_first_quarter))

            if target_date in (next_new, previous_new):
                phase = 0
            elif target_date in (next_first_quarter, previous_first_quarter):
                phase = 2
            elif target_date in (next_full, previous_full):
                phase = 4
            elif target_date in (next_last_quarter, previous_last_quarter):
                phase = 6
            elif (
                previous_new
                < next_first_quarter
                < next_full
                < next_last_quarter
                < next_new
            ):
                phase = 1
            elif (
                previous_first_quarter
                < next_full
                < next_last_quarter
                < next_new
                < next_first_quarter
            ):
                phase = 3
            elif (
                previous_full
                < next_last_quarter
                < next_new
                < next_first_quarter
                < next_full
            ):
                phase = 5
            elif (
                previous_last_quarter
                < next_new
                < next_first_quarter
                < next_full
                < next_last_quarter
            ):
                phase = 7
            else:
                phase = 4
            UpdateDevice(unit.MOON_PHASE, 0, self.__MOON_PHASE_DESCRIPTIONS[phase])
            UpdateDeviceImage(
                unit.MOON_PHASE, images.PREFIX_IMAGE + images.PREFIX_PHASE + str(phase)
            )
            #
            self.__moon.compute(self.__observer)
            #
            # -------------------------------------------------------------------------------
            # Moon illumination
            # -------------------------------------------------------------------------------
            value = round(deg(self.__moon.moon_phase), 2)
            UpdateDevice(unit.MOON_ILLUMINATION, int(value), str(value))
            UpdateDeviceImage(
                unit.MOON_ILLUMINATION,
                images.PREFIX_IMAGE + images.PREFIX_PHASE + str(phase),
            )
            #
        else:
            Domoticz.Debug(
                "onHeartbeat called, run again in {} heartbeats.".format(
                    self.__runAgain
                )
            )
Ejemplo n.º 13
0
def moonphase(year, month, day, do_print=False):
    h = year // 100  # integer division for the century
    yy = year % 100  # year within the century

    # The "golden number" for this year is the year modulo 19, but
    # adjusted to be centered around 0 -- i.e., -9 to 9 instead
    # of 0 to 19.  This improves the accuracy of the approximation
    # to within +/- 1 day.
    g = (yy + 9) % 19 - 9

    # There is an interesting 6 century near-repetition in the
    # century correction.  It would be interesting to find a
    # algorithm that handles the different corrections between
    # centuries 17|23|29, 20|26, 21|27, and 24|30.

    try:
        c = {
            17: 7,
            18: 1,
            19: -4,
            20: -8,
            21: 16,
            22: 11,
            23: 6,
            24: 1,
            25: -4,
            26: -9,
            27: 15,
            28: 11,
            29: 6,
            30: 0
        }[h]
    except KeyError:
        print("No century correction available for {}00-{}99".format(h, h))
        return

    # Golden number correction:  modulo 30, from -29 to 29.
    gc = g * 11
    while (gc < -29):
        gc += 30
    if (gc > 0): gc %= 30

    # January/February correction:
    if month < 3:
        mc = 2
    else:
        mc = 0

    phase = (month + mc + day + gc + c + 30) % 30

    if (do_print):
        # It's nice to see what the Golden correction for the year
        # plus the century correction is.  This lets us quickly calculate the
        # correction for any other date in the same year.
        gcpc = (gc + c) % 30
        if gcpc <= 0:
            gcpc_alt = gcpc + 30
        else:
            gcpc_alt = gcpc - 30

        print("yy =", yy)
        print("g =", g)
        print("month + day + mc =", month + day + mc)
        print("gc =", gc)
        print("c =", c)
        print("Dates in the year", year, "have moon phase correction gc + c =",
              gcpc, "or", gcpc_alt)
        print(("\n\t{:04}/{:02}/{:02} has "
               "estimated moon phase = {}\n").format(year, month, day, phase))
        if phase < 2:
            print("\tNew moon [or slightly after]")
        elif phase < 7:
            print("\tWaxing crescent")
        elif phase < 9:
            print("\tFirst quarter")
        elif phase < 14:
            print("\tWaxing gibbous")
        elif phase < 16:
            print("\tFull moon")
        elif phase < 22:
            print("\tWaning gibbous")
        elif phase < 24:
            print("\tLast quarter")
        elif phase < 29:
            print("\tWaning (de)crescent")
        elif phase < 31:
            print("\tNew moon [or slightly before]")

        try:
            # If you have the ephem package installed, you
            # can compare the estimate to the actual lunar phase
            import ephem
            thisdate = ephem.Date('{:04}/{:02}/{:02} 00:00:01'.format(
                year, month, day))
            prevmoon = ephem.previous_new_moon(thisdate)
            nextmoon = ephem.next_new_moon(thisdate)
            prevfull = ephem.previous_full_moon(thisdate)
            nextfull = ephem.next_full_moon(thisdate)
            prevymd = prevmoon.tuple()[:3]
            nextymd = nextmoon.tuple()[:3]
            pfymd = prevfull.tuple()[:3]
            nfymd = nextfull.tuple()[:3]
            print("\n\t{}".format(prevmoon), "UTC = Previous New Moon")
            print("\t{}".format(nextmoon), "UTC = Next New Moon")
            print("\t{}".format(prevfull), "UTC = Previous Full Moon")
            print("\t{}".format(nextfull), "UTC = Next Full Moon")
            try:
                from convertdate import julianday
                thisjdc = julianday.from_gregorian(year, month, day)
                prevjdc = julianday.from_gregorian(*prevymd)
                nextjdc = julianday.from_gregorian(*nextymd)
                pfjdc = julianday.from_gregorian(*pfymd)
                nfjdc = julianday.from_gregorian(*nfymd)
                print("\t{:2} days since prev new moon".format(
                    int(thisjdc - prevjdc)))
                print("\t{:2} days until next new moon".format(
                    int(nextjdc - thisjdc)))
                print("\t{:2} days since prev full moon".format(
                    int(thisjdc - pfjdc)))
                print("\t{:2} days until next full moon".format(
                    int(nfjdc - thisjdc)))
            except:
                print("julianday doesn't work")
                pass
        except:
            pass

        try:
            # If you have convertdate installed, you can compare the lunar
            # phase to the hebrew calendar date:
            from convertdate import hebrew
            hyear, hmonth, hday = hebrew.from_gregorian(year, month, day)
            print("\n\tHebrew date = {} {}, {}\n".format(
                hday, hmonths[hmonth], hyear))
        except:
            pass
    return phase
Ejemplo n.º 14
0
obs.lat, obs.lon = obsLat, obsLon
obs.date = datetime.datetime.utcnow()

# Get Moon phase info here as time will be changed for Moonrise/set times
moon = e.Moon()
moon.compute(obs)
# Illumination (%):
moonPhase = moon.moon_phase
moonPhase = round((moonPhase * 100), 1)
moonPhase = str(moonPhase)
# Determine Lunation and pick out Phase Image from List
nnm = e.next_new_moon(obs.date)
pnm = e.previous_new_moon(obs.date)
nfm = e.next_full_moon(obs.date)
pfm = e.previous_full_moon(obs.date)

lunation = (obs.date - pnm) / (nnm - pnm)

if (lunation < 0.5):
    moonStatus = 'Waxing'
else:
    moonStatus = 'Waning'

fileno = int(lunation * 713)

moonlist = open("../IMG/moonframes/aa_filelist.txt", "r")
for c, line in enumerate(moonlist):
    #print(c, value)
    if (c == fileno):
        phase = line
Ejemplo n.º 15
0
gatech.elevation = 320
gatech.date = '1984/5/30 16:22:56'
v = ephem.Venus(gatech)
print v.alt, v.az

m = ephem.Moon('1980/6/1')
print ephem.constellation(m)
print ephem.delta_t('1980')

ephem.julian_date('2000/1/1')

print ephem.previous_new_moon(ephem.now())
print ephem.next_new_moon(ephem.now())
# localtime
print ephem.localtime(ephem.next_new_moon(ephem.now()))

print ephem.previous_full_moon(ephem.now())
print ephem.next_full_moon(ephem.now())
# localtime
print ephem.localtime(ephem.next_full_moon(ephem.now()))

rigel = ephem.star('Rigel')
print rigel._ra, rigel._dec

# astronomical constants
print ephem.meters_per_au
print ephem.earth_radius
print ephem.moon_radius
print ephem.sun_radius
print ephem.c
Ejemplo n.º 16
0
def main():

    sun = ephem.Sun()
    moon = ephem.Moon()

    # define observer
    home = ephem.Observer()
    home.date = ephem.date(datetime.utcnow())
    home.lat, home.lon = '50.46', '9.61'

    sun.compute(home)
    sunrise, sunset = (home.next_rising(sun),
                       home.next_setting(sun))
    moon.compute(home)
    moonrise, moonset = (home.next_rising(moon),
                       home.next_setting(moon))
    home.horizon = '-6'
    m6_start, m6_end = (home.next_rising(sun, use_center=True),
                        home.next_setting(sun, use_center=True))
    home.horizon = '-12'
    m12_start, m12_end = (home.next_rising(sun, use_center=True),
                          home.next_setting(sun, use_center=True))
    home.horizon = '-18'
    m18_start, m18_end = (home.next_rising(sun, use_center=True),
                          home.next_setting(sun, use_center=True))

    print home.date

    e = {}
    e[sunrise] =   " Sunrise:                      "
    e[sunset] =    " Sunset:                       "
    e[moonrise] =  " Moonrise:                     "
    e[moonset] =   " Moonset:                      "
    e[m6_start] =  " Civil twilight starts:        "
    e[m6_end] =    " Civil twilight ends:          "
    e[m12_start] = " Nautical twilight starts:     "
    e[m12_end] =   " Nautical twilight ends:       "
    e[m18_start] = " Astronomical twilight starts: "
    e[m18_end] =   " Astronomical twilight ends:   "

    for time in sorted(e.keys()):
        print e[time], ephem.localtime(time).ctime()

    # Here start the moon specific data

    print " ---"
    print " Moon phase: %d%% " % moon.phase

    e = {}
    e1 = ephem.previous_new_moon(home.date)
    e[e1] = " Previous new moon:            "
    e1 = ephem.previous_first_quarter_moon(home.date)
    e[e1] = " Previous first quarter moon:  "
    e1 = ephem.previous_full_moon(home.date)
    e[e1] = " Previous full moon:           "
    e1 = ephem.previous_last_quarter_moon(home.date)
    e[e1] = " Previous last quarter moon:   "

    e1 = ephem.next_new_moon(home.date)
    e[e1] = " Next new moon:                "
    e1 = ephem.next_first_quarter_moon(home.date)
    e[e1] = " Next first quarter moon:      "
    e1 = ephem.next_full_moon(home.date)
    e[e1] = " Next full moon:               "
    e1 = ephem.next_last_quarter_moon(home.date)
    e[e1] = " Next last quarter moon:       "

    for time in sorted(e.keys()):
        print e[time], ephem.localtime(time).ctime()
Ejemplo n.º 17
0
next_new = ephem.next_new_moon(now)
next_first = ephem.next_first_quarter_moon(now)
next_full = ephem.next_full_moon(now)
next_last = ephem.next_last_quarter_moon(now)

phase = m.moon_phase
lunation = (now-prev_new)/(next_new-prev_new)
# Elaborate on most recent lunar phase

print "Current lunar illumination is {:0.1f}%, lunation is {:0.4f}".format(phase*100,lunation)
if lunation < 0.25:
    print "Was just New Moon at {} UT".format(fmt_date(ephem.previous_new_moon(now)))
elif lunation < 0.5:
    print "Was just First Quarter at {} UT".format(fmt_date(ephem.previous_first_quarter_moon(now)))
elif lunation < 0.75:
    print "Was just Full Moon at {} UT".format(fmt_date(ephem.previous_full_moon(now)))
else:
    print "Was just Last Quarter at {} UT".format(fmt_date(ephem.previous_last_quarter_moon(now)))

print "New Moon     : {} UT ({} Local time)".format(
    fmt_date(next_new),fmt_fulldatetime(ephem.localtime(next_new)))
print "First Quarter: {} UT ({} Local time)".format(
    fmt_date(next_first),fmt_fulldatetime(ephem.localtime(next_first)))
print "Full Moon    : {} UT ({} Local time)".format(
    fmt_date(next_full),fmt_fulldatetime(ephem.localtime(next_full)))
print "Last Quarter : {} UT ({} Local time)".format(
    fmt_date(next_last),fmt_fulldatetime(ephem.localtime(next_last)))

print "\n*** Planets ***"
mercury = ephem.Mercury()
venus   = ephem.Venus()
Ejemplo n.º 18
0
 def _get_moon(self):
     return min(
         (ephem.localtime(ephem.next_full_moon(self.day_as_dt)) -
          self.day_as_dt).days,
         (self.day_as_dt -
          ephem.localtime(ephem.previous_full_moon(self.day_as_dt))).days)
Ejemplo n.º 19
0
    ephem_data['civil_twilight_start'] = str(next_civil_tw_start_time)
    ephem_data['astro_twilight_start'] = str(next_astro_tw_start_time)

## moon

observer.horizon = '-0:34'

#next_full = ephem.localtime(ephem.next_full_moon(observer.date))
#previous_full = ephem.localtime(ephem.previous_full_moon(observer.date))

prev_moon_transit = ephem.localtime(observer.previous_transit(moon_ephem))
prev_moon_rising = ephem.localtime(observer.previous_rising(moon_ephem))
next_moon_transit = ephem.localtime(observer.next_transit(moon_ephem))
next_moon_setting = ephem.localtime(observer.next_setting(moon_ephem))

previous_full = ephem.localtime(ephem.previous_full_moon(observer.date))
next_full = ephem.localtime(ephem.next_full_moon(observer.date))

print 'prev_moon_rising', prev_moon_rising
#print prev_moon_transit
#print next_moon_transit
print 'next_moon_setting', next_moon_setting

#print '#'

#print previous_full
#print next_full

names = [
    'Waxing Crescent', 'Waxing Gibbous', 'Waning Gibbous', 'Waning Crescent'
]
Ejemplo n.º 20
0
# Berkeley Coordinates
# observatory.long = "-122.25803505"
# observatory.lat = "37.86934626"
observatory.elevation = 200

right_now = ephem.now()

observatory.date = right_now

sun = ephem.Sun()
sun.compute(observatory)
moon = ephem.Moon()
moon.compute(observatory)

# days since last full moon
last_full_moon_time = ephem.previous_full_moon(right_now) - right_now

# days until next full moon
next_full_moon_time = ephem.next_full_moon(right_now) - right_now

# observatory.date = right_now

events_list = []

sunset_time = observatory.next_setting(sun)
observatory.date = right_now
events_list.append(["Sunset: \t", ephem.localtime(sunset_time).strftime("%I:%M%p"), sunset_time - right_now])

sunnoon_time = observatory.next_transit(sun)
observatory.date = right_now
events_list.append(["Local Noon:", ephem.localtime(sunnoon_time).strftime("%I:%M%p"), sunnoon_time - right_now])
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 13 14:07:43 2020
https://rhodesmill.org/pyephem/quick.html#phases-of-the-moon
@author: PC
"""

import ephem

d1 = ephem.next_full_moon('1984')
print(d1)
d2 = ephem.next_new_moon(d1)
print(d2)

print(ephem.previous_new_moon('2020'))
print(ephem.next_new_moon('2020'))

print(ephem.previous_first_quarter_moon('2020'))
print(ephem.next_first_quarter_moon('2020'))

print(ephem.previous_full_moon('2020'))
print(ephem.next_full_moon('2020'))

print(ephem.previous_last_quarter_moon('2020'))
print(ephem.next_last_quarter_moon('2020'))
Ejemplo n.º 22
0
def post_save_night(sender, **kwargs):
    if not kwargs.get('raw', False):
        night = kwargs['instance']

        location = night.location
        astropy_time = Time(datetime.combine(night.date, time(12)))
        astropy_time_delta = TimeDelta(600.0, format='sec')

        # guess if the moon is waxing or waning
        if ephem.next_full_moon(night.date) - ephem.Date(night.date) < ephem.Date(night.date) - ephem.previous_full_moon(night.date):
            waxing_moon = True
        else:
            waxing_moon = False

        observer = Observer(
            longitude=location.longitude,
            latitude=location.latitude,
            timezone='UTC'
        )

        moon_phase = observer.moon_phase(astropy_time).value

        if waxing_moon:
            moon_phase = (math.pi - moon_phase) / (2 * math.pi)
        else:
            moon_phase = (math.pi + moon_phase) / (2 * math.pi)

        times = {
            'sunset': observer.sun_set_time(astropy_time, which='next'),
            'civil_dusk': observer.twilight_evening_civil(astropy_time, which='next'),
            'nautical_dusk': observer.twilight_evening_nautical(astropy_time, which='next'),
            'astronomical_dusk': observer.twilight_evening_astronomical(astropy_time, which='next'),
            'midnight': observer.midnight(astropy_time, which='next'),
            'astronomical_dawn': observer.twilight_morning_astronomical(astropy_time, which='next'),
            'nautical_dawn': observer.twilight_morning_nautical(astropy_time, which='next'),
            'civil_dawn': observer.twilight_morning_civil(astropy_time, which='next'),
            'sunrise': observer.sun_rise_time(astropy_time, which='next'),
        }

        night.mjd = int(astropy_time.mjd) + 1
        night.moon_phase = moon_phase
        for key in times:
            if times[key].jd > 0:
                setattr(night, key, times[key].to_datetime(timezone=utc))

        post_save.disconnect(post_save_night, sender=sender)
        night.save()
        post_save.connect(post_save_night, sender=sender)

        moon_positions = []
        for i in range(144):
            moon_altitude = observer.moon_altaz(astropy_time).alt.degree

            moon_position = MoonPosition(
                timestamp=astropy_time.to_datetime(timezone=utc),
                altitude=moon_altitude,
                location=location
            )

            moon_positions.append(moon_position)
            astropy_time += astropy_time_delta

        MoonPosition.objects.bulk_create(moon_positions)
Ejemplo n.º 23
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from datetime import datetime
import ephem

now = datetime.now()

#Past Moon phases
d5 = ephem.previous_new_moon(now)
d6 = ephem.previous_first_quarter_moon(now)
d7 = ephem.previous_full_moon(now)
d8 = ephem.previous_last_quarter_moon(now)
print
print (d5), "	| Previous new Moon"
print (d6), "	| Previous quarter Moon"
print (d7), "	| Previous full Moon"
print (d8), "	| Previous last quarter Moon"
print

#Next Moon phases
d1 = ephem.next_full_moon(now)
d2 = ephem.next_new_moon(now)
d3 = ephem.next_first_quarter_moon(now)
d4 = ephem.next_last_quarter_moon(now)
print (d2), "	| Next new Moon"
print (d3), "	| Next quarter Moon"
print (d1), "	| Next full Moon"
print (d4), "	| Next last quarter Moon"
print

m=ephem.Moon(now)
Ejemplo n.º 24
0
def moonphase(year, month, day, do_print=False):
    h = year // 100             # integer division for the century
    yy = year % 100             # year within the century

    # The "golden number" for this year is the year modulo 19, but
    # adjusted to be centered around 0 -- i.e., -9 to 9 instead
    # of 0 to 19.  This improves the accuracy of the approximation
    # to within +/- 1 day.
    g = (yy + 9) % 19 - 9

    # There is an interesting 6 century near-repetition in the
    # century correction.  It would be interesting to find a
    # algorithm that handles the different corrections between
    # centuries 17|23|29, 20|26, 21|27, and 24|30.

    try:
        c = {17:7,
             18:1, 19:-4, 20:-8, 21:16, 22:11, 23:6,
             24:1, 25:-4, 26:-9, 27:15, 28:11, 29:6,
             30:0}[h]
    except KeyError:
        print("No century correction available for {}00-{}99".format(h,h))
        return

    # Golden number correction:  modulo 30, from -29 to 29.
    gc = g * 11
    while ( gc < -29 ): gc += 30;
    if (gc > 0): gc %= 30;

    # January/February correction:
    if month < 3:
       mc = 2
    else:
       mc = 0

    phase = (month + mc + day + gc + c + 30 ) % 30

    if (do_print):
        # It's nice to see what the Golden correction for the year
        # plus the century correction is.  This lets us quickly calculate the
        # correction for any other date in the same year.
        gcpc = (gc + c) % 30
        if gcpc <= 0:
            gcpc_alt = gcpc + 30
        else:
            gcpc_alt = gcpc - 30

        print("yy =", yy)
        print("g =", g)
        print("month + day + mc =", month + day + mc)
        print("gc =", gc)
        print("c =", c)
        print("Dates in the year", year,
              "have moon phase correction gc + c =",
              gcpc, "or", gcpc_alt)
        print(("\n\t{:04}/{:02}/{:02} has "
               "estimated moon phase = {}\n").format(year,
                                                   month,
                                                   day,
                                                   phase))
        if phase < 2:
            print("\tNew moon [or slightly after]")
        elif phase < 7:
            print("\tWaxing crescent")
        elif phase < 9:
            print("\tFirst quarter")
        elif phase < 14:
            print("\tWaxing gibbous")
        elif phase < 16:
            print("\tFull moon")
        elif phase < 22:
            print("\tWaning gibbous")
        elif phase < 24:
            print("\tLast quarter")
        elif phase < 29:
            print("\tWaning (de)crescent")
        elif phase < 31:
            print("\tNew moon [or slightly before]")

        try:
            # If you have the ephem package installed, you
            # can compare the estimate to the actual lunar phase
            import ephem
            thisdate = ephem.Date('{:04}/{:02}/{:02} 00:00:01'.format(year, month, day))
            prevmoon = ephem.previous_new_moon(thisdate)
            nextmoon = ephem.next_new_moon(thisdate)
            prevfull = ephem.previous_full_moon(thisdate)
            nextfull = ephem.next_full_moon(thisdate)
            prevymd = prevmoon.tuple()[:3]
            nextymd = nextmoon.tuple()[:3]
            pfymd = prevfull.tuple()[:3]
            nfymd = nextfull.tuple()[:3]
            print("\n\t{}".format(prevmoon), "UTC = Previous New Moon")
            print("\t{}".format(nextmoon), "UTC = Next New Moon")
            print("\t{}".format(prevfull), "UTC = Previous Full Moon")
            print("\t{}".format(nextfull), "UTC = Next Full Moon")
            try:
                from convertdate import julianday
                thisjdc = julianday.from_gregorian(year, month, day)
                prevjdc = julianday.from_gregorian(*prevymd)
                nextjdc = julianday.from_gregorian(*nextymd)
                pfjdc = julianday.from_gregorian(*pfymd)
                nfjdc = julianday.from_gregorian(*nfymd)
                print("\t{:2} days since prev new moon".format(int(thisjdc - prevjdc)))
                print("\t{:2} days until next new moon".format(int(nextjdc - thisjdc)))
                print("\t{:2} days since prev full moon".format(int(thisjdc - pfjdc)))
                print("\t{:2} days until next full moon".format(int(nfjdc - thisjdc)))
            except:
                print("julianday doesn't work")
                pass
        except:
            pass

        try:
            # If you have convertdate installed, you can compare the lunar
            # phase to the hebrew calendar date:
            from convertdate import hebrew
            hyear, hmonth, hday = hebrew.from_gregorian(year, month, day)
            print("\n\tHebrew date = {} {}, {}\n".format( hday,
                                                          hmonths[hmonth],
                                                          hyear ))
        except:
            pass
    return phase
Ejemplo n.º 25
0
sunset  = observer.next_setting   (ephem.Sun()) #Sunset

data['sunrise'] = str(ephem.localtime(sunrise))
data['noon']    = str(ephem.localtime(noon))
data['sunset']  = str(ephem.localtime(sunset))

# observer.horizon = '-6' # civil twilight
# civilian_twilight_start = observer.previous_rising(ephem.Sun())
# civilian_twilight_end = observer.next_setting(ephem.Sun())

# observer.horizon = '-12' # nautical twilight
# nautical_twilight_start = observer.previous_rising(ephem.Sun())
# nautical_twilight_end = observer.next_setting(ephem.Sun())

# observer.horizon = '-18' # astronomical twilight
# astronomical_twilight_start = observer.previous_rising(ephem.Sun())
# astronomical_twilight_end = observer.next_setting(ephem.Sun())

data['moon'] = {}
data['moon']['radius'] = ephem.moon_radius
data['moon']['previous_new_moon'] = str(ephem.localtime(ephem.previous_new_moon(time)))
data['moon']['next_new_moon'] = str(ephem.localtime(ephem.next_new_moon(time)))
data['moon']['previous_first_quarter_moon'] = str(ephem.localtime(ephem.previous_first_quarter_moon(time)))
data['moon']['next_first_quarter_moon'] = str(ephem.localtime(ephem.next_first_quarter_moon(time)))
data['moon']['previous_full_moon'] = str(ephem.localtime(ephem.previous_full_moon(time)))
data['moon']['next_full_moon'] = str(ephem.localtime(ephem.next_full_moon(time)))
data['moon']['previous_last_quarter_moon'] = str(ephem.localtime(ephem.previous_last_quarter_moon(time)))
data['moon']['next_last_quarter_moon'] = str(ephem.localtime(ephem.next_last_quarter_moon(time)))

print json.dumps(data)
Ejemplo n.º 26
0
import ephem

while True:
    user_answer = (input("date: ").lower())

    moon = {
        "Предыдущий цикл": {
            "Последняя четверть луны":
            ephem.previous_last_quarter_moon(user_answer),
            "Новолуние":
            ephem.previous_new_moon(user_answer),
            "Первая четверть луны":
            ephem.previous_first_quarter_moon(user_answer),
            "Полнолуние":
            ephem.previous_full_moon(user_answer),
        },
        "Следующий цикл": {
            "Последняя четверть луны":
            ephem.next_last_quarter_moon(user_answer),
            "Новолуние": ephem.next_new_moon(user_answer),
            "Первая четверть луны": ephem.next_first_quarter_moon(user_answer),
            "Полнолуние": ephem.next_full_moon(user_answer),
        }
    }

    for key in moon:
        print(key)
        for row_key in moon[key]:
            print(row_key, ":", moon[key][row_key])

    if user_answer == "exit":
Ejemplo n.º 27
0
# python wilktype.py  1990 12 30 13

# 2019-07-20

import sys, datetime
import ephem

sh = False	# Southern hemisphere?

y, m, d, h = [int(q) for q in sys.argv[1:]]

timetuple = (y, m, d, h, 0, 0)
n = ephem.Date(timetuple)

nm = ephem.previous_new_moon(n)
fm = ephem.previous_full_moon(n)
moo = 2 * 99 / 29.530589

if fm > nm:
	#print(n, fm, n - fm)
	lunar = 100 - moo * (n - fm)
else:
	#print(n, nm, n - nm)
	lunar =   1 + moo * (n - nm)

ws = n - ephem.Date(datetime.date(y - 1, 12, 21))
solar = 1
diff = 200 / 365

for x in range(round(ws)):
	if (x / 365) % 1 < .5: