How to use skyfield - 10 common examples

To help you get started, we’ve selected a few skyfield examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github skyfielders / python-skyfield / skyfield / almanac.py View on Github external
def season_at(t):
        """Return season 0 (Spring) through 3 (Winter) at time `t`."""
        t._nutation_angles_radians = iau2000b_radians(t)
        e = earth.at(t)
        _, slon, _ = e.observe(sun).apparent().ecliptic_latlon('date')
        return (slon.radians // (tau / 4) % 4).astype(int)
github avpeery / Moon-Phase-Tracker / testing_seed_data.py View on Github external
def test_solstices():
    """Creates seasonal solstices in test database"""

    t0 = TS.utc(2020, 1, 1)
    t1 = TS.utc(2020, 12, 31)
    t, y = almanac.find_discrete(t0, t1, almanac.seasons(E))

    dates = t.utc_iso()
    solstice_names = [almanac.SEASON_EVENTS[yi] for yi in y]

    for (date, solstice_name) in zip(dates, solstice_names):
        date = date[:10]
        date = datetime.strptime(date, '%Y-%m-%d')

        solstice_occurence = Solstice(title = solstice_name, start = date)      
        
        db.session.add(solstice_occurence)

    db.session.commit()
github avpeery / Moon-Phase-Tracker / testing_seed_data.py View on Github external
def test_solstices():
    """Creates seasonal solstices in test database"""

    t0 = TS.utc(2020, 1, 1)
    t1 = TS.utc(2020, 12, 31)
    t, y = almanac.find_discrete(t0, t1, almanac.seasons(E))

    dates = t.utc_iso()
    solstice_names = [almanac.SEASON_EVENTS[yi] for yi in y]

    for (date, solstice_name) in zip(dates, solstice_names):
        date = date[:10]
        date = datetime.strptime(date, '%Y-%m-%d')

        solstice_occurence = Solstice(title = solstice_name, start = date)      
        
        db.session.add(solstice_occurence)

    db.session.commit()
github avpeery / Moon-Phase-Tracker / testing_seed_data.py View on Github external
from sqlalchemy import func
from model import *
from server import app

from datetime import datetime
from skyfield import api, almanac
import itertools

TS = api.load.timescale(builtin=True)
E = api.load('seed_data/de421.bsp')


def test_data():
    test_moon_phase_type()
    test_full_moon_nickname()
    test_solstices()
    test_moon_phase_occurences()
    test_user()


##################################
### TEST DATA HELPER FUNCTIONS ###
##################################


def test_moon_phase_type():
github avpeery / Moon-Phase-Tracker / testing_seed_data.py View on Github external
def test_moon_phase_occurences():
    """Creates moon phase occurences in test database"""

    t0 = TS.utc(2020, 1, 1)
    t1 = TS.utc(2020, 12, 31)
    t, y = almanac.find_discrete(t0, t1, almanac.moon_phases(E))

    dates = t.utc_iso()
    moon_phase_names = [almanac.MOON_PHASES[yi] for yi in y]

    moon_phase_type = MoonPhaseType.query.first()
    full_moon_nickname = FullMoonNickname.query.first()

    for (date, moon_phase_name) in zip(dates, moon_phase_names):
        if moon_phase_name == 'Full Moon':
            date = date[:10]
            date = datetime.strptime(date, '%Y-%m-%d')
            if date.month == 1:
                moon_phase_occurence = MoonPhaseOccurence(start = date, moon_phase_type_id = moon_phase_type.moon_phase_type_id, full_moon_nickname_id = full_moon_nickname.full_moon_nickname_id)
            else:
                moon_phase_occurence = MoonPhaseOccurence(start = date, moon_phase_type_id = moon_phase_type.moon_phase_type_id)
            db.session.add(moon_phase_occurence)
github avpeery / Moon-Phase-Tracker / testing_seed_data.py View on Github external
from sqlalchemy import func
from model import *
from server import app

from datetime import datetime
from skyfield import api, almanac
import itertools

TS = api.load.timescale(builtin=True)
E = api.load('seed_data/de421.bsp')


def test_data():
    test_moon_phase_type()
    test_full_moon_nickname()
    test_solstices()
    test_moon_phase_occurences()
    test_user()


##################################
### TEST DATA HELPER FUNCTIONS ###
##################################
github consensys-space / trusat-orbit / iod_db_gooding_analyze.py View on Github external
try: 
                dbpassword = getpass() 
            except Exception as error: 
                log.warning('ERROR: password must be specified {}'.format(error))

    # Set up database connection
    db = database.Database(dbname,dbtype,dbhostname,dbusername,dbpassword)

    ts = load.timescale()

    # 408821	"2019-08-24 13:38:39"	"leobarhorst@gmail.com"	37162	"2010-046A  "	4172	"E"	"20190824031442326"	"2019-08-24 03:14:42.3260"	0.1	NULL	"2"	"5"	2000	105.828	59.80349999999999	0	0	0.30000000000000004	"S"	NULL	NULL	NULL	NULL	NULL	NULL	"IOD"	"37162 10 046A   4172 E 20190824031442326 17 25 0703312+594821 37 S"	1	NULL	"370139ccab6591ba36c6fc2c33081a76"	"2019-08-25 17:44:27"
    # 408820	"2019-08-24 13:38:39"	"leobarhorst@gmail.com"	37162	"2010-046A  "	4172	"E"	"20190824031438341"	"2019-08-24 03:14:38.3410"	0.1	NULL	"2"	"5"	2000	106.752	58.856833333333334	0	0	0.30000000000000004	"S"	NULL	NULL	NULL	NULL	NULL	NULL	"IOD"	"37162 10 046A   4172 E 20190824031438341 17 25 0707008+585141 37 S"	1	NULL	"c24602b9fd0d66538baa8256813ec371"	"2019-08-25 17:44:26"
    # 408819	"2019-08-24 13:38:39"	"leobarhorst@gmail.com"	37162	"2010-046A  "	4172	"E"	"20190824031434357"	"2019-08-24 03:14:34.3570"	0.1	NULL	"2"	"5"	2000	107.57825	57.9475	0	0	0.30000000000000004	"S"	NULL	NULL	NULL	NULL	NULL	NULL	"IOD"	"37162 10 046A   4172 E 20190824031434357 17 25 0710313+575685 37 S"	1	NULL	"9a097ee7bb889d01b0eb43452018e510"	"2019-08-25 17:44:26"

    # For Alt/Az conversions
    planets = load('de421.bsp')
    earth = planets['earth']
    # iod_obs_id = input("IOD db ID: ")
    while(True):
        try:
            iod_obs_id = input("\nEnter 3 IOD Obs IDs: ")
            iod_obs_id = iod_obs_id.strip()
            iod_obs = iod_obs_id.split(' ')
        except:
            break

        if (len(iod_obs)==1):
            query_tmp = """SELECT obs_id, object_number, station_number, user_string, obs_time, ra, declination FROM ParsedIOD 
                WHERE obs_id >= {OBS_ID}
                ORDER BY obs_id ASC
                LIMIT 10;""".format(OBS_ID=iod_obs[0])
            db.c.execute(query_tmp)
github consensys-space / trusat-orbit / iod_db_gooding_analyze.py View on Github external
if (dbtype == "sqlserver"):
        if dbusername == None:
            try: 
                dbusername = input("Username: ") 
            except Exception as error: 
                log.warning('ERROR: password must be specified {}'.format(error))
        if dbpassword == None:
            try: 
                dbpassword = getpass() 
            except Exception as error: 
                log.warning('ERROR: password must be specified {}'.format(error))

    # Set up database connection
    db = database.Database(dbname,dbtype,dbhostname,dbusername,dbpassword)

    ts = load.timescale()

    # 408821	"2019-08-24 13:38:39"	"leobarhorst@gmail.com"	37162	"2010-046A  "	4172	"E"	"20190824031442326"	"2019-08-24 03:14:42.3260"	0.1	NULL	"2"	"5"	2000	105.828	59.80349999999999	0	0	0.30000000000000004	"S"	NULL	NULL	NULL	NULL	NULL	NULL	"IOD"	"37162 10 046A   4172 E 20190824031442326 17 25 0703312+594821 37 S"	1	NULL	"370139ccab6591ba36c6fc2c33081a76"	"2019-08-25 17:44:27"
    # 408820	"2019-08-24 13:38:39"	"leobarhorst@gmail.com"	37162	"2010-046A  "	4172	"E"	"20190824031438341"	"2019-08-24 03:14:38.3410"	0.1	NULL	"2"	"5"	2000	106.752	58.856833333333334	0	0	0.30000000000000004	"S"	NULL	NULL	NULL	NULL	NULL	NULL	"IOD"	"37162 10 046A   4172 E 20190824031438341 17 25 0707008+585141 37 S"	1	NULL	"c24602b9fd0d66538baa8256813ec371"	"2019-08-25 17:44:26"
    # 408819	"2019-08-24 13:38:39"	"leobarhorst@gmail.com"	37162	"2010-046A  "	4172	"E"	"20190824031434357"	"2019-08-24 03:14:34.3570"	0.1	NULL	"2"	"5"	2000	107.57825	57.9475	0	0	0.30000000000000004	"S"	NULL	NULL	NULL	NULL	NULL	NULL	"IOD"	"37162 10 046A   4172 E 20190824031434357 17 25 0710313+575685 37 S"	1	NULL	"9a097ee7bb889d01b0eb43452018e510"	"2019-08-25 17:44:26"

    # For Alt/Az conversions
    planets = load('de421.bsp')
    earth = planets['earth']
    # iod_obs_id = input("IOD db ID: ")
    while(True):
        try:
            iod_obs_id = input("\nEnter 3 IOD Obs IDs: ")
            iod_obs_id = iod_obs_id.strip()
            iod_obs = iod_obs_id.split(' ')
        except:
            break
github skyfielders / python-skyfield / builders / build_constellations.py View on Github external
def main():
    with api.load.open(URL) as f:
        lines = list(f)

    unique_ra = set()
    unique_dec = set()
    fracs = set()
    boundaries = []

    for line in lines:
        fields = line.split()
        ra_low = extend(fields[0])
        ra_up = extend(fields[1])
        de_low = extend(fields[2])
        const = fields[3].decode('ascii')

        print(ra_low, const)
github skyfielders / python-skyfield / design / satellite_passes.py View on Github external
print(' ', ti.utc_jpl(), yi)

offset = 0
assert list(y[offset:offset+3]) == [0, 1, 2]

pass_start, pass_end = t[offset+0], t[offset+2]

def f(t):
    length = t.tt.shape[0]
    t._nutation_angles = iau2000b(t.tt)
    return sat.at(t).is_sunlit(eph)

f.rough_period = 0.001

T0 = time()
t2, y2 = almanac.find_discrete(pass_start, pass_end, f, epsilon=half_second)
print(time() - T0, 'seconds to find moment of entering shadow:')

for ti, yi in zip(t2, y2):
    print(' ', ti.utc_jpl(), 'entered sunlight' if yi else 'entered shadow')

one_second = 1.0 / 24.0 / 3600.0
tt = np.arange(pass_start.tt, pass_end.tt, one_second)

T0 = time()
t = ts.tt_jd(tt)
t._nutation_angles = iau2000b(t.tt)
satpos = (sat - topos).at(t)
is_sunlit = satpos.is_sunlit(eph)
DT = time() - T0

print(DT, 'to compute is_sunlit() for every second of {}-second pass'