Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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():
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 ###
##################################
"""
On my laptop, this script shows that simply computing the positions and
the sunlit-ness of the ISS for each of the 381 seconds of this pass
takes roughly the same amount of time as mounting a full search for the
moment it passes into shadow. But the benefit is far greater, because
with almost no additional expense all altitudes and azimuths can also
be computed.
"""
import numpy as np
from skyfield import almanac, api
from skyfield.nutationlib import iau2000b
ts = api.load.timescale(builtin=True)
eph = api.load('de421.bsp')
sat = api.EarthSatellite(
'1 25544U 98067A 20150.54009403 .00000886 00000-0 23936-4 0 9992',
'2 25544 51.6447 80.7632 0002782 3.7438 167.9307 15.49399736229124',
)
topos = api.Topos('18.3368 N', '64.7281 W')
t0 = ts.utc(2020, 6, 5)
t1 = ts.utc(2020, 6, 6)
half_second = 0.5 / 24.0 / 3600.0
from time import time
T0 = time()
t, y = sat.find_events(topos, t0, t1, altitude_degrees=10.0)
from sqlalchemy import func
from model import User, MoonPhaseType, MoonPhaseOccurence, Solstice, FullMoonNickname, Alert, connect_to_db, db
from server import app
from datetime import datetime
from skyfield import api, almanac
import itertools
from seed_data.moon_phase_descriptions import moon_phases_dict
MOON_PHASE_TYPES = ['New Moon', 'First Quarter', 'Full Moon', 'Last Quarter']
FULL_MOON_NICKNAMES = ['Wolf Moon', 'Snow Moon', 'Worm Moon', 'Pink Moon', 'Flower Moon', 'Strawberry Moon', 'Buck Moon', 'Sturgeon Moon', 'Corn Moon', "Hunter's Moon", 'Beaver Moon', 'Cold Moon']
MOON_EMOJIS = ['🌚','🌛', '🌝','🌜']
TS = api.load.timescale(builtin=True)
E = api.load('seed_data/de421.bsp')
def load_moon_phase_types():
"""Adds moon phase types to moon phase types table"""
for moon_phase, moon_emoji in zip(MOON_PHASE_TYPES, MOON_EMOJIS):
moon_phase_type = MoonPhaseType(title=moon_phase, description=moon_phases_dict[moon_phase], emoji=moon_emoji)
db.session.add(moon_phase_type)
db.session.commit
def load_full_moon_nicknames():
"""Adds full moon nicknames to moon phase nicknames table"""
for (nickname, month) in zip(FULL_MOON_NICKNAMES, range(1, 13)):
def compute(target, kernel=de421, name=None, topo=None, t=None, planet=0,
precision_radec=15, precision_azalt=120, klass=None, json=None):
ts = sf.load.timescale()
if isinstance(target, str):
name = target
target = kernel[target]
if topo is None:
topo = ['33.7490 N', '84.3880 W'] # Atlanta.
topo = sf.Topos(*topo)
if t is None:
t = [2019, 9, 6, 17, 0, 0]
t = ts.utc(*t)
if name is None:
name = target.target_name
if not planet and isinstance(target.target, int):
planet = target.target
earth = de421['earth']
obs = (earth + topo).at(t)
pos = obs.observe(target)
geo = earth.at(t).observe(target)
radec = pos.radec(t)
altaz = pos.apparent().altaz()
# skyfield use JD, ephemeride uses Modified JD.
with almost no additional expense all altitudes and azimuths can also
be computed.
"""
import numpy as np
from skyfield import almanac, api
from skyfield.nutationlib import iau2000b
ts = api.load.timescale(builtin=True)
eph = api.load('de421.bsp')
sat = api.EarthSatellite(
'1 25544U 98067A 20150.54009403 .00000886 00000-0 23936-4 0 9992',
'2 25544 51.6447 80.7632 0002782 3.7438 167.9307 15.49399736229124',
)
topos = api.Topos('18.3368 N', '64.7281 W')
t0 = ts.utc(2020, 6, 5)
t1 = ts.utc(2020, 6, 6)
half_second = 0.5 / 24.0 / 3600.0
from time import time
T0 = time()
t, y = sat.find_events(topos, t0, t1, altitude_degrees=10.0)
print(time() - T0, 'seconds to find events:')
for ti, yi in zip(t, y):
print(' ', ti.utc_jpl(), yi)
offset = 0
assert list(y[offset:offset+3]) == [0, 1, 2]
df['mean_anomaly_degrees'] = (
sqrt(mu_au3_d2 / (row.semimajor_axis_au ** 3.0))
*
(ts.J2000.tt - t_perihelion.tt)
* 360.0 / tau
)
comet = df.iloc[0:1]
k = KeplerOrbit.from_comet_dataframe(ts, comet.ix[0])
from skyfield.data.spice import inertial_frames
from math import sqrt
eph = api.load('de421.bsp')
t = ts.utc(2020, 5, 31)
k._rotation = inertial_frames['ECLIPJ2000'].T
p = eph['earth'].at(t).observe(eph['sun'] + k)
ra, dec, distance = p.radec()
print(t.utc_iso(' '))
print(ra, ' ("23 59 16.6")')
print(dec, ' ("-84 46 58")')
print(distance)
"""
Below are the results of your request from the Minor Planet Center's Minor Planet Ephemeris Service. Ephemerides are for the geocenter.
import sys
from numpy import array, mean, std, zeros
from skyfield import earthlib, nutationlib, api, starlib
from skyfield.constants import T0
from skyfield.timelib import julian_date, Time
from timeit import default_timer
TA = julian_date(1969, 7, 20, 20., 18.)
TB = julian_date(2012, 12, 21)
D0 = 63.8285
DA = 39.707
DB = 66.8779
earth = api.earth
jupiter = api.jupiter
star = starlib.Star(
ra_hours=1.59132070233, dec_degrees=8.5958876464,
ra_mas_per_year=0.0, dec_mas_per_year=0.0,
parallax_mas=0.0, radial_km_per_s=0.0,
)
class BM(object):
def __init__(self, times, bm_fn, t):
self.name = bm_fn.__name__
self.times = times
self.bm_fn = bm_fn
self.t = t
def __call__(self):
from numpy import array, mean, std, zeros
from skyfield import earthlib, nutationlib, api, starlib
from skyfield.constants import T0
from skyfield.timelib import julian_date, Time
from timeit import default_timer
TA = julian_date(1969, 7, 20, 20., 18.)
TB = julian_date(2012, 12, 21)
D0 = 63.8285
DA = 39.707
DB = 66.8779
earth = api.earth
jupiter = api.jupiter
star = starlib.Star(
ra_hours=1.59132070233, dec_degrees=8.5958876464,
ra_mas_per_year=0.0, dec_mas_per_year=0.0,
parallax_mas=0.0, radial_km_per_s=0.0,
)
class BM(object):
def __init__(self, times, bm_fn, t):
self.name = bm_fn.__name__
self.times = times
self.bm_fn = bm_fn
self.t = t
def __call__(self):
self.bm_fn(self.times, self.t)
def __init__(self):
"""Create Alignment instance. See class documentation."""
self._target = None
self._rise_time = None
self._set_time = None
self._tle_line1 = None
self._tle_line2 = None
self._skyfield_ts = sf_api.Loader(_system_data_dir, expire=False).timescale()