Пример #1
0
def main():
    args = sys.argv[1:]
    if not args:
        print('usage: deprecations.py (a|b...)')
        sys.exit(2)
    arg = args[0]
    if arg == 'a':
        from skyfield.api import earth, mars, now
        earth(now()).observe(mars).radec()
    elif arg == 'b':
        from skyfield.api import earth
        earth.topos('42.3583 N', '71.0636 W')
    elif arg == 'c':
        from skyfield.api import load
        eph = load('de421.bsp')
        earth = eph['earth']
        earth(100)
    elif arg == 'd':
        from skyfield.api import JulianDate
        JulianDate(utc=(1980, 1, 1))
    elif arg == 'e':
        from skyfield.api import load
        eph = load('de421.bsp')
        earth = eph['earth']
        earth.at(utc=(1980, 1, 1))
Пример #2
0
def current():
    'Current positions of the Sun, Moon, Planets and some other interesting stuff.'
    t = now()
    print('The current time is', t.astimezone(timezone).strftime('%H:%M %Z on %A %d %B %Y'))

    # Generate positions for all the interesting stuff.
    def generate_positions(jd):
        symbols = get_symbols()

        for body in (sun, moon) + nine_planets:
            if body != earth:
                alt, azi, _ = home(jd).observe(body).apparent().altaz()
                name = body.jplname.capitalize()
                yield Position(name, alt._degrees, azi._degrees, symbols.get(name.upper(), ' '))

        # Now the stars
        for name, star in STARS.items():
            alt, azi, _ = home(jd).observe(star).apparent().altaz()
            yield Position(name, alt._degrees, azi._degrees, symbols['BLACK STAR'])

        # Earth satellites are special.
        satellites = get_satellites()
        sat = satellites['ISS (ZARYA)']
        alt, azi, _ = home(jd).observe(sat).altaz()
        yield Position('ISS', alt._degrees, azi._degrees, ' ')

    for p in sorted(generate_positions(t), key=attrgetter('azi')):
        if p.alt > 0:
            prefix = '↑' if p.azi <= 180 else '↓'  # TODO: might not be correct for ISS.
        else:
            prefix = ' '
        print('{1:2s} {0.symbol} {0.name:10s} {0.alt:3.0f}° at {0.azi:03.0f}°'.format(p, prefix))
Пример #3
0
    def position(wave=None):
        """
        calculate position
        """
        if wave is None:
            time = now()
        else:
            time = wave.time.tt

        diff = time - JulianDate(utc=datetime(2001, 1,
                                              1, tzinfo=timezone.utc)).tt
        days = floor(diff)
        lunations = decimal.Decimal(
            "0.20439731") + (days * decimal.Decimal("0.03386319269"))

        return lunations % decimal.Decimal(1)
Пример #4
0
 def prepare(time, f, target, url):
     ensure_dir(f)
     ensure_dir(target)
     p = pathlib.Path(target)
     if p.exists():
         os.remove(target)
     if (int(time.utc_datetime().strftime("%Y%m%d")) > 20150118) \
         and (int(time.utc_datetime().strftime("%Y%m%d")) <=
              int(now().utc_datetime().strftime("%Y%m%d"))):
         p = pathlib.Path(f)
         if not p.exists():
             with urllib.request.urlopen(url) as item:
                 item = item.read().decode('utf-8')
                 this = open(f, 'w')
                 this.write(item)
                 this.close()
         if int(time.utc_datetime().strftime("%H%M")) == 1800:
             os.symlink(f, target)
Пример #5
0
    def setup(cls, argv):

        opt_short_args = "h"
        opt_short_args_description = ""
        opt_long_args = ["help="]
        opt_long_args_description = ""

        for the_method in sorted(dir_attributes(Defaults)):
            # print(the_method)
            this = getattr(Defaults, the_method)
            #setattr(Settings, the_method, this[0])
            # if the_method == "adate":
            #    print(the_method)
            #    print(this)
            #    print(this[1])
            if not this[1] is None:
                opt_short_args = opt_short_args + this[1] + ":"

                opt_short_args_description = opt_short_args_description + \
                    "-" + this[1] + " <" + this[2] + "> "

                opt_long_args.extend([the_method + "="])

                opt_long_args_description = opt_long_args_description + "\n--" +\
                    the_method + " <" + str(this[2]) + "> or " +\
                    "-" + this[1] + " <" + str(this[2]) + "> "
            else:
                opt_long_args.extend([the_method + "="])

                opt_long_args_description = opt_long_args_description + \
                    "\n--" + the_method + " <" + str(this[2]) + ">"

        # print(inspect_class(Settings))
        set_methods = []
        settings = ""
        try:
            opts, args = getopt.getopt(argv, opt_short_args, opt_long_args)
        except getopt.GetoptError:
            print('sun_latlon.py ' + opt_short_args_description)
            sys.exit(2)
        for opt, arg in opts:
            # print(opt)
            # print(arg)
            if opt == "-h":
                print('sun_latlon.py' + opt_long_args_description)
                sys.exit()

            for the_method in dir_attributes(Defaults):
                this = getattr(Defaults, the_method)
                #print(the_method+" = "+str(this))
                # print(this[1].__class__.__name__)
                # print(this[1])
                # if the_method == "adate":
                #    print(the_method)
                #    print(this)
                #    print(this[1])
                if not this[1] is None:
                    if opt in ("-" + str(this[1]), "--" + the_method):
                        classname = this[0].__class__.__name__
                        if classname == "bool":
                            set_methods.extend(
                                [[the_method, ast.literal_eval(arg)]])
                        else:
                            set_methods.extend(
                                [[the_method, eval(classname)(arg)]])
                        if the_method == "juliandate":
                            if not arg == "":
                                settings = "juliandate"
                        elif the_method == "adate":
                            if not arg == "":
                                settings = "adate"
                else:
                    if opt == ("--" + the_method):
                        #                        print(the_method+" = "+str(arg))
                        classname = this[0].__class__.__name__
                        if classname == "bool":
                            set_methods.extend(
                                [[the_method, ast.literal_eval(arg)]])
                        else:
                            set_methods.extend(
                                [[the_method, eval(classname)(arg)]])

        # print(set_methods)

        for the_method in sorted(dir_attributes(Defaults)):
            this = getattr(Defaults, the_method)
            classname = this[0].__class__.__name__
            #print(the_method+" = "+str(this))
            setattr(Settings, the_method, eval(classname)(this[0]))

        for this in set_methods:
            # delattr(Settings,this[0])
            setattr(Settings, this[0], this[1])

        # print(inspect_class(Settings))
        if Settings().pulse <= 0:
            setattr(Settings, "pulse", 1)

        if Settings().interval <= 0:
            setattr(Settings, "interval", 1)

        if settings == "juliandate":
            time = JulianDate(tt=Settings().juliandate)
        elif settings == "adate":
            d_y, d_m, d_d = Settings().adate.split("/")
            d_h, d_mi = Settings().atime.split(":")
            this = datetime(
                int(d_y),
                int(d_m),
                int(d_d),
                int(d_h),
                int(d_mi),
                tzinfo=timezone.utc)
            time = JulianDate(utc=this)
        else:
            time = now()

        setattr(Settings, "time", time)

        if Settings().auntildate == "":
            setattr(Settings, "auntildate", Settings().time)
        else:
            d_y, d_m, d_d = Settings().auntildate.split("/")
            d_h, d_mi = Settings().atime.split(":")
            this = datetime(
                int(d_y),
                int(d_m),
                int(d_d),
                int(d_h),
                int(d_mi),
                tzinfo=timezone.utc)
            setattr(Settings, "auntildate", JulianDate(utc=this))

        setattr(
            Settings,
            "wave",
            TimeWave(
                Settings().time,
                Settings().pulse,
                Settings().interval))
# the 2 files are about 1 GB in size, please refer to the project
# description at the following url for more information on how to
# download them directly

# your geographical position and timezone should be previously set in file:  radioConfig.py

from skyfield.api import load
from datetime import datetime
from pytz import timezone
from skyfield.api import now
import radioConfig

planets = load('de421.bsp')
earth, jupiter = planets['earth'], planets['jupiter barycenter']

jd = now()
rome = timezone(radioConfig.stationTimezone)
dt = jd.astimezone(rome)

print('\nUTC:  ' + str(jd.utc_datetime()))
print('Local: ' + str(dt))

print('\nJupiter position from my lat-long:')
myposition = earth.topos(radioConfig.stationLat, radioConfig.stationLon)
position = myposition.at(utc=(2015, 12, 14, 21, 0, 0)).observe(jupiter)
print(position.apparent().radec())

# 1) the central meridian longitude of Jupiter that faces us
# 2) the position of the inner-most moon Io in its orbit around Jupiter
# 3) the Jovicentric declination of the Earth
#! /usr/bin/env python

from skyfield.api import load, JulianDate, utc, now
from pytz import timezone
import radioConfig

print
print "Configured time zone: %s" % (radioConfig.stationTimezone)

mytz = timezone(radioConfig.stationTimezone)
jd = now()
jdutc = jd.utc_datetime()
print "UTC         : %s" % (jdutc)

jd = JulianDate(utc=jdutc)
dt = jd.astimezone(mytz)
print "My timezone : %s" % (dt)
print

Пример #8
0
def main():
    """
    print moon phase
    """
    wave = TimeWave.TimeWave(now(), 1, 1)
    print(Moon().now(wave))