示例#1
0
def test_jd_calendar():
    # Check a specific instance (using UNIX epoch here, though that's
    # an arbitrary choice)
    jd_unix = 2440587.5
    cal_unix = (1970, 1, 1, 0, 0, 0.0)

    cal = calendar_tuple(jd_unix)

    # Check that the returned value is correct
    assert cal == cal_unix

    # Check that all the return types are correct
    assert isinstance(cal[0], numbers.Integral)  # Year
    assert isinstance(cal[1], numbers.Integral)  # Month
    assert isinstance(cal[2], numbers.Integral)  # Day
    assert isinstance(cal[3], numbers.Integral)  # Hour
    assert isinstance(cal[4], numbers.Integral)  # Minute
    assert isinstance(cal[5], numbers.Real)  # Second

    # Check backward conversion
    assert julian_date(*cal) == jd_unix

    # Check array conversion components
    jd_array = jd_unix + np.arange(5.0)
    cal_array = calendar_tuple(jd_array)

    assert (cal_array[0] == 1970).all()
    assert (cal_array[1] == 1).all()
    assert (cal_array[2] == np.arange(1, 6)).all()
    assert (cal_array[3] == 0).all()
    assert (cal_array[4] == 0).all()
    assert (cal_array[5] == 0.0).all()

    # Check reversal of array
    assert (julian_date(*cal_array) == jd_array).all()
def test_appendix_c_conversion_from_TEME_to_ITRF():
    rTEME = array([5094.18016210, 6127.64465950, 6380.34453270])
    vTEME = array([-4.746131487, 0.785818041, 5.531931288])
    vTEME = vTEME * 24.0 * 60.0 * 60.0  # km/s to km/day

    jd_utc = julian_date(2004, 4, 6, 7, 51, 28.386)
    d_ut1 = -0.439961
    jd_ut1 = jd_utc + d_ut1 / 86400.0

    xp = -0.140682 * arcsecond
    yp = 0.333309 * arcsecond

    rITRF, vITRF = TEME_to_ITRF(jd_ut1, rTEME, vTEME, xp, yp)

    epsilon = 5e-8  # Why not 1e-8, which would match all of their digits?

    assert abs(-1033.47938300 - rITRF[0]) < epsilon
    assert abs(+7901.29527540 - rITRF[1]) < epsilon
    assert abs(+6380.35659580 - rITRF[2]) < epsilon

    vITRF_per_second = vITRF / seconds_per_day

    epsilon = 7e-8  # Why not 1e-9, which would match all of their digits?

    assert abs(-3.225636520 - vITRF_per_second[0]) < epsilon
    assert abs(-2.872451450 - vITRF_per_second[1]) < epsilon
    assert abs(+5.531924446 - vITRF_per_second[2]) < epsilon
示例#3
0
def main():
    thisdir = os.path.dirname(__file__)

    df = morrison_and_stephenson_2004_table()
    year = df.year.values
    jd = julian_date(year, 1, 1)
    delta_t = df.delta_t.values
    array = np.array((jd, delta_t))
    np.save(os.path.join(thisdir, 'morrison_stephenson_deltat.npy'), array)

    df = usno_historic_delta_t()
    year = df.year.values
    jd = julian_date(year, 1, 1)
    delta_t = df.delta_t.values
    array = np.array((jd, delta_t))
    np.save(os.path.join(thisdir, 'historic_deltat.npy'), array)
示例#4
0
def main():
    lines = open('../sat23839.txt','r').read().splitlines()

    satellite = twoline2rv(lines[7], lines[8], wgs72)

    times = []
    report = csv.DictReader(open('atsb-report.csv', 'r'))
    for r in report:
	time = r['Time']
	hours = int(time[0:2])
	minutes = int(time[3:5])
	seconds = int(time[6:8])
	day = 7 if (hours > 12) else 8
        times.append([2014, 3, day, hours, minutes, seconds])

    w = csv.writer(open('sgp4-positions.csv', 'w'), lineterminator='\n')
    w.writerow(['x', 'y','z', 'dx','dy', 'dz'])

    for time in times:
	position, velocity = satellite.propagate(*time)

	jd = julian_date(*time)
	velocity = numpy.asarray(velocity) * 24.0 * 60.0 * 60.0
	p,v = TEME_to_ITRF(jd, position, velocity.tolist())
	v = v / (24.0 * 60.0 * 60.0)
	p = ["%0.1f" % i for i in p]
	v = ["%0.5f" % i for i in v]
	w.writerow([ p[0],p[1],p[2],v[0],v[1],v[2] ])
示例#5
0
def main():
    lines = open('../sat23839.txt','r').read().splitlines()

    satellite = twoline2rv(lines[7], lines[8], wgs72)

    times = []
    report = csv.DictReader(open('../inmarsat-su-log-redacted.csv', 'r'))
    for r in report:
        if r['Frequency Offset (Hz)'] != '':
            t = datetime.datetime.now().strptime(r['Time'],"%d/%m/%Y %H:%M:%S.%f")
            times.append(t)

    w = csv.writer(open('python.csv', 'w'), lineterminator='\n')
    w.writerow(['Time','x', 'y','z', 'dx','dy', 'dz'])

    for t in times:
        time = [t.year, t.month, t.day, t.hour, t.minute, t.second]
	position, velocity = satellite.propagate(*time)

	jd = julian_date(*time)
	velocity = numpy.asarray(velocity) * 24.0 * 60.0 * 60.0
	p,v = TEME_to_ITRF(jd, position, velocity.tolist())
	v = v / (24.0 * 60.0 * 60.0)
#	p = ["%0.1f" % i for i in p]
#	v = ["%0.5f" % i for i in v]
	w.writerow([ t,p[0],p[1],p[2],v[0],v[1],v[2] ])
示例#6
0
def calibrate(records):
    c1_p,c1_v = adsb2ecef(2.74668, 101.71266, 0.021, 0, 0, 0)
    # http://web.acma.gov.au/pls/radcom/site_search.site_lookup?pSITE_ID=139331
    perth_p,perth_v = adsb2ecef(-31.804545,115.887337,0.056, 0, 0, 0)
    # http://web.acma.gov.au/pls/radcom/site_search.site_lookup?pSITE_ID=139331
    c = 299792.458
    a = []
    for r in records:
        t = r[0]
        time = [t.year, t.month, t.day, t.hour, t.minute, t.second]
	position, velocity = satellite.propagate(*time)

	jd = julian_date(*time)
	velocity = numpy.asarray(velocity) * 24.0 * 60.0 * 60.0
	p,v = TEME_to_ITRF(jd, position, velocity.tolist())
	v = v / (24.0 * 60.0 * 60.0)

        radius_a = p - c1_p
        radius_a = numpy.sqrt(radius_a.dot(radius_a))
        radius_p = p - perth_p
        radius_p = numpy.sqrt(radius_p.dot(radius_p))
        bias = int(r[1]) - (2000000 * (radius_a + radius_p) / c )
        a.append(bias)
    print 'Number of records:', len(a)
    print 'min:', numpy.amin(a)
    print 'max:', numpy.amax(a)
    print 'mean:', numpy.mean(a)
    print 'std:', numpy.std(a)
def main():
    thisdir = os.path.dirname(__file__)

    df = morrison_and_stephenson_2004_table()
    year = df.year.values
    jd = julian_date(year, 1, 1)
    delta_t = df.delta_t.values
    array = np.array((jd, delta_t))
    np.save(os.path.join(thisdir, 'morrison_stephenson_deltat.npy'),
            array)

    df = usno_historic_delta_t()
    year = df.year.values
    jd = julian_date(year, 1, 1)
    delta_t = df.delta_t.values
    array = np.array((jd, delta_t))
    np.save(os.path.join(thisdir, 'historic_deltat.npy'),
            array)
示例#8
0
def test_julian_date():
    epsilon = 0.0  # perfect
    for args in (
          (-4712, 1, 1, 0.0),
          (-4712, 3, 1, 0.0),
          (-4712, 12, 31, 0.5),
          (-241, 3, 25, 19.0),
          (530, 9, 27, 23.5),
          (1976, 3, 7, 12.5),
          (2000, 1, 1, 0.0),
          ):
        eq(c.julian_date(*args), timelib.julian_date(*args), epsilon)
示例#9
0
def test_jd_calendar():

    import numbers

    # Check a specific instance (using UNIX epoch here, though that's
    # an arbitrary choice)
    jd_unix = 2440587.5
    cal_unix = (1970, 1, 1, 0, 0, 0.0)

    cal = calendar_tuple(jd_unix)

    # Check that the returned value is correct
    assert cal == cal_unix

    # Check that all the return types are correct
    assert isinstance(cal[0], numbers.Integral)  # Year
    assert isinstance(cal[1], numbers.Integral)  # Month
    assert isinstance(cal[2], numbers.Integral)  # Day
    assert isinstance(cal[3], numbers.Integral)  # Hour
    assert isinstance(cal[4], numbers.Integral)  # Minute
    assert isinstance(cal[5], numbers.Real)  # Second

    # Check backward conversion
    assert julian_date(*cal) == jd_unix

    # Check array conversion components
    jd_array = jd_unix + np.arange(5.0)
    cal_array = calendar_tuple(jd_array)
    
    assert (cal_array[0] == 1970).all()
    assert (cal_array[1] == 1).all()
    assert (cal_array[2] == np.arange(1, 6)).all()
    assert (cal_array[3] == 0).all()
    assert (cal_array[4] == 0).all()
    assert (cal_array[5] == 0.0).all()

    # Check reversal of array
    assert (julian_date(*cal_array) == jd_array).all()
示例#10
0
def build_delta_t_table():
    # TODO: julian_date() is proleptic Gregorian - but is that the
    # calendar used by Morrison and Stephenson?

    s = morrison_and_stephenson_2004_table()
    s['tt'] = julian_date(s.pop('year'))

    h = usno_historic_delta_t()
    h['tt'] = julian_date(h.pop('year'))

    m = usno_monthly_delta_t()
    m['tt'] = julian_date(m.pop('year'), m.pop('month'), m.pop('day'))

    p = usno_predicted_delta_t()
    p['tt'] = julian_date(p.pop('year'))

    s = s[s.tt < h.tt.min()]
    h = h[h.tt < m.tt.min()]
    p = p[p.tt > m.tt.max()]

    # Generate an initial and final data point from the long-term
    # formula to avoid a discontinuity between numbers we interpolate
    # from the table and numbers we generate from the formula.

    f = delta_t_formula_morrison_and_stephenson_2004

    step = 36525.0  # Julian century

    import pandas as pd

    tt = s.tt.iloc[0] - step
    start = pd.DataFrame({'tt': [tt], 'delta_t': [f(tt)]})

    tt = p.tt.iloc[-1] + step
    end = pd.DataFrame({'tt': [tt], 'delta_t': [f(tt)]})

    return pd.concat([start, s, h, m, p, end])
def build_delta_t_table():
    # TODO: julian_date() is proleptic Gregorian - but is that the
    # calendar used by Morrison and Stephenson?

    s = morrison_and_stephenson_2004_table()
    s['tt'] = julian_date(s.pop('year'))

    h = usno_historic_delta_t()
    h['tt'] = julian_date(h.pop('year'))

    m = usno_monthly_delta_t()
    m['tt'] = julian_date(m.pop('year'), m.pop('month'), m.pop('day'))

    p = usno_predicted_delta_t()
    p['tt'] = julian_date(p.pop('year'))

    s = s[s.tt < h.tt.min()]
    h = h[h.tt < m.tt.min()]
    p = p[p.tt > m.tt.max()]

    # Generate an initial and final data point from the long-term
    # formula to avoid a discontinuity between numbers we interpolate
    # from the table and numbers we generate from the formula.

    f = delta_t_formula_morrison_and_stephenson_2004

    step = 36525.0  # Julian century

    import pandas as pd

    tt = s.tt.iloc[0] - step
    start = pd.DataFrame({'tt': [tt], 'delta_t': [f(tt)]})

    tt = p.tt.iloc[-1] + step
    end = pd.DataFrame({'tt': [tt], 'delta_t': [f(tt)]})

    return pd.concat([start, s, h, m, p, end])
示例#12
0
def main():
    times = []
    w = csv.writer(open('cpp.csv', 'w'), lineterminator='\n')
    w.writerow(['Time','x', 'y','z', 'dx','dy', 'dz'])
    cpp = csv.DictReader(open('cpp-teme.csv', 'r'))
    for r in cpp:
        t = datetime.datetime.now().strptime(r['time'],"%Y-%m-%dT%H:%M:%S")
	jd = julian_date(t.year, t.month, t.day, t.hour, t.minute, t.second)
        position = [float(r['x']),float(r['y']),float(r['z'])]
        velocity = [float(r['dx']),float(r['dy']),float(r['dz'])]
	velocity = numpy.asarray(velocity) * 24.0 * 60.0 * 60.0
	p,v = TEME_to_ITRF(jd, position, velocity.tolist())
	v = v / (24.0 * 60.0 * 60.0)
#	p = ["%0.1f" % i for i in p]
#	v = ["%0.5f" % i for i in v]
	w.writerow([ t,p[0],p[1],p[2],v[0],v[1],v[2] ])
def satrec_from_XML(root, satellite_id):
    #iss_segment = root.find(f".//*[OBJECT_NAME='{satname}']/..")
    iss_segment = root.find(f".//*[NORAD_CAT_ID='{satellite_id}']/../.."
                            )  # find the matching "segment" node
    meta = iss_segment.find("metadata")
    name = meta.find("OBJECT_NAME").text
    object_id = meta.find("OBJECT_ID").text
    ref_frame = meta.find("REF_FRAME").text
    mean_element_theory = meta.find("MEAN_ELEMENT_THEORY").text
    assert ref_frame == "TEME"
    assert mean_element_theory == "SGP4"
    # "data" node contains meanElements and tleParameters
    data = iss_segment.find("data")
    mean_elements = data.find("meanElements")
    tle_parameters = data.find("tleParameters")
    # Extract a subset of fields to create a Satrec
    epoch = mean_elements.find("EPOCH").text
    norad_cat_id = tle_parameters.find("NORAD_CAT_ID").text
    bstar = tle_parameters.find("BSTAR").text
    mm_dot = tle_parameters.find("MEAN_MOTION_DOT").text
    mm_ddot = tle_parameters.find("MEAN_MOTION_DDOT").text
    eccentricity = mean_elements.find("ECCENTRICITY").text
    arg_pericenter = mean_elements.find("ARG_OF_PERICENTER").text
    inclination = mean_elements.find("INCLINATION").text
    mean_anomaly = mean_elements.find("MEAN_ANOMALY").text
    mean_motion = mean_elements.find("MEAN_MOTION").text
    ra_asc_node = mean_elements.find("RA_OF_ASC_NODE").text
    # Per SGP calculate epoch from 1949 Dec 31
    base_epoch_julian = julian_date(1949, 12, 31)
    # Format of XML epoch is described in 6.5.9 of CCSDS Orbit Data Messages
    # (this does not cover all valid variations listed in the spec)
    dt = datetime.datetime.strptime(epoch, "%Y-%m-%dT%H:%M:%S.%f")
    epoch_julian = julian_date(dt.year, dt.month, dt.day, dt.hour, dt.minute,
                               dt.second + (dt.microsecond / 1E6))
    epoch_since_base = epoch_julian - base_epoch_julian
    # When MEAN_ELEMENT_THEORY is SGP4, convert revolutions per day -> radians/minute
    mean_motion_radians_per_minute = float(
        mean_motion) * 2 * pi / MINUTES_PER_DAY
    #
    # According to https://pypi.org/project/sgp4/
    # ndot and nddot are ignored by SGP4, so no further conversions are attempted here
    # sgp4.io processes them further, eg.
    # https://github.com/brandon-rhodes/python-sgp4/blob/4c13506a410f7fba17dbf38bd722a2ddb322f197/sgp4/io.py#L195
    #
    # "Build a satellite from orbital elements"
    # https://rhodesmill.org/skyfield/earth-satellites.html#from-satrec
    satrec = Satrec()
    satrec.sgp4init(
        WGS72,  # gravity model
        "i",  # 'a' = old AFSPC mode, 'i' = improved mode
        int(norad_cat_id),  # satnum: Satellite number
        epoch_since_base,  # epoch: days since 1949 December 31 00:00 UT
        float(bstar),  # bstar: drag coefficient (/earth radii)
        float(mm_dot),  # ndot: ballistic coefficient (revs/day)
        float(mm_ddot),  # nddot: second derivative of mean motion (revs/day^3)
        float(eccentricity),  # ecco: eccentricity
        radians(float(arg_pericenter)),  # argpo: argument of perigee (radians)
        radians(float(inclination)),  # inclo: inclination (radians)
        radians(float(mean_anomaly)),  # mo: mean anomaly (radians)
        mean_motion_radians_per_minute,  # no_kozai: mean motion (radians/minute)
        radians(float(ra_asc_node)
                ),  # nodeo: right ascension of ascending node (radians)
    )
    return satrec
示例#14
0
"""Run a series of timing tests on core Skyfield atoms."""

import gc
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):
示例#15
0
"""Run a series of timing tests on core Skyfield atoms."""

import gc
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, JulianDate
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