Esempio n. 1
0
def linearized_errors(
        ot,
        radar,
        t_obs,
        plot=True,
        debug=False,
        t0s=n.linspace(0, 2 * 3600, num=50),
        debug_output=False,
        change_epoch=False,
        log10_A_to_m_std=0.59,  # estimated from detectable population in master 2009
        time_vector=False,
        dx=0.0001,
        dv=1e-6,
        dcd=0.01,
        include_drag=False):
    """ 
    Use numerical differences to estimate the measurement error covariance matrix using
    cartesian state vector at epoch plus area-to-mass ratio (7 orbital parameters)

    Use a prior for area-to-mass ratio, to allow also estimating covariance with one tri-static measurement.
    """
    n_tx = len(radar._tx)
    n_rx = len(radar._rx)

    o = ot.copy()

    Am = o.A / o.m
    o.m = 1.0
    o.A = Am

    o0 = o.copy()

    o_dx0 = o.copy()
    o_dx0.update(x=o.x + dx)

    o_dx1 = o.copy()
    o_dx1.update(y=o.y + dx)

    o_dx2 = o.copy()
    o_dx2.update(z=o.z + dx)

    o_dv0 = o.copy()
    o_dv0.update(vx=o.vx + dv)

    o_dv1 = o.copy()
    o_dv1.update(vy=o.vy + dv)

    o_dv2 = o.copy()
    o_dv2.update(vz=o.vz + dv)

    # area to mass ratio
    o_dcd = o.copy()

    AmL = n.log10(Am)
    AmL2 = AmL + dcd
    o_dcd.A = 10**(AmL2)

    # create measurements
    meas0, fnames, e = stra.create_tracklet(o0,
                                            radar,
                                            t_obs,
                                            dt=0.01,
                                            hdf5_out=False,
                                            ccsds_out=False,
                                            dname="./tracklets",
                                            noise=False,
                                            ignore_elevation_thresh=True)

    n_rows = 0
    # figure out how many measurements we have
    for txi in range(n_tx):
        for rxi in range(n_rx):
            n_meas = len(meas0[txi][rxi]["m_time"])
            if debug:
                print("n_meas %d" % (n_meas))
            n_rows += n_meas

    # one range and one range rate measurement
    n_meas = n_rows * 2

    if debug:
        print("number of measurements %d" % (n_meas))

    # create jacobian
    if include_drag:
        # include prior for A/m, and one extra parameter for log10(A/m)
        J = n.zeros([n_meas + 1, 7])
        Sigma_m_inv = n.zeros([n_meas + 1, n_meas + 1])
    else:
        # only a cartesian state
        J = n.zeros([n_meas, 6])
        Sigma_m_inv = n.zeros([n_meas, n_meas])

    # perturb elements in each of the six parameters
    meas_dx0, fnames, e = stra.create_tracklet(o_dx0,
                                               radar,
                                               t_obs,
                                               hdf5_out=False,
                                               ccsds_out=False,
                                               noise=False,
                                               ignore_elevation_thresh=True)
    meas_dx1, fnames, e = stra.create_tracklet(o_dx1,
                                               radar,
                                               t_obs,
                                               hdf5_out=False,
                                               ccsds_out=False,
                                               noise=False,
                                               ignore_elevation_thresh=True)
    meas_dx2, fnames, e = stra.create_tracklet(o_dx2,
                                               radar,
                                               t_obs,
                                               hdf5_out=False,
                                               ccsds_out=False,
                                               noise=False,
                                               ignore_elevation_thresh=True)
    meas_dv0, fnames, e = stra.create_tracklet(o_dv0,
                                               radar,
                                               t_obs,
                                               hdf5_out=False,
                                               ccsds_out=False,
                                               noise=False,
                                               ignore_elevation_thresh=True)
    meas_dv1, fnames, e = stra.create_tracklet(o_dv1,
                                               radar,
                                               t_obs,
                                               hdf5_out=False,
                                               ccsds_out=False,
                                               noise=False,
                                               ignore_elevation_thresh=True)
    meas_dv2, fnames, e = stra.create_tracklet(o_dv2,
                                               radar,
                                               t_obs,
                                               hdf5_out=False,
                                               ccsds_out=False,
                                               noise=False,
                                               ignore_elevation_thresh=True)
    meas_dcd, fnames, e = stra.create_tracklet(o_dcd,
                                               radar,
                                               t_obs,
                                               hdf5_out=False,
                                               ccsds_out=False,
                                               noise=False,
                                               ignore_elevation_thresh=True)

    # Populate Jacobian
    # m = Jx + f(x_map) + \xi
    row_idx = 0
    range_0 = 0.0
    for txi in range(n_tx):
        for rxi in range(n_rx):
            n_meas0 = len(meas0[txi][rxi]["m_time"])
            # save initial range
            if txi == 0 and txi == 0:
                if debug:
                    print("range std %f (m) range-rate std %f (m/s)" %
                          (meas0[txi][rxi]["m_range_std"][0] * 1e3,
                           meas0[txi][rxi]["m_range_rate_std"][0] * 1e3))
                range_0 = meas0[txi][rxi]["m_range"][0]

            n_meas1 = len(meas_dx0[txi][rxi]["m_time"])
            n_meas2 = len(meas_dx1[txi][rxi]["m_time"])
            n_meas3 = len(meas_dx2[txi][rxi]["m_time"])
            n_meas4 = len(meas_dv0[txi][rxi]["m_time"])
            n_meas5 = len(meas_dv1[txi][rxi]["m_time"])
            n_meas6 = len(meas_dv2[txi][rxi]["m_time"])
            n_meas7 = len(meas_dcd[txi][rxi]["m_time"])

            if debug:
                print("n_meas %d measurement %d" % (n_meas0, row_idx))

            for mi in range(n_meas0):
                # range and range-rate error
                range_std = meas0[txi][rxi]["m_range_std"][mi]
                range_rate_std = meas0[txi][rxi]["m_range_rate_std"][mi]

                #                print("range_std %1.1f range_rate_std %1.1f"%(range_std*1e3,range_rate_std*1e3))
                #               print("range %1.1f range_rate %1.1f"%(meas0[txi][rxi]["m_range"][mi],meas0[txi][rxi]["m_range_rate"][mi]))

                # range and range rate error variance
                Sigma_m_inv[2 * row_idx, 2 * row_idx] = 1.0 / range_std**2.0
                Sigma_m_inv[2 * row_idx + 1,
                            2 * row_idx + 1] = 1.0 / range_rate_std**2.0

                # siple first order difference derivate estimate
                m_range_dx0 = (meas_dx0[txi][rxi]["m_range"][mi] -
                               meas0[txi][rxi]["m_range"][mi]) / dx
                m_range_rate_dx0 = (meas_dx0[txi][rxi]["m_range_rate"][mi] -
                                    meas0[txi][rxi]["m_range_rate"][mi]) / dx

                m_range_dx1 = (meas_dx1[txi][rxi]["m_range"][mi] -
                               meas0[txi][rxi]["m_range"][mi]) / dx
                m_range_rate_dx1 = (meas_dx1[txi][rxi]["m_range_rate"][mi] -
                                    meas0[txi][rxi]["m_range_rate"][mi]) / dx

                m_range_dx2 = (meas_dx2[txi][rxi]["m_range"][mi] -
                               meas0[txi][rxi]["m_range"][mi]) / dx
                m_range_rate_dx2 = (meas_dx2[txi][rxi]["m_range_rate"][mi] -
                                    meas0[txi][rxi]["m_range_rate"][mi]) / dx

                m_range_dv0 = (meas_dv0[txi][rxi]["m_range"][mi] -
                               meas0[txi][rxi]["m_range"][mi]) / dv
                m_range_rate_dv0 = (meas_dv0[txi][rxi]["m_range_rate"][mi] -
                                    meas0[txi][rxi]["m_range_rate"][mi]) / dv

                m_range_dv1 = (meas_dv1[txi][rxi]["m_range"][mi] -
                               meas0[txi][rxi]["m_range"][mi]) / dv
                m_range_rate_dv1 = (meas_dv1[txi][rxi]["m_range_rate"][mi] -
                                    meas0[txi][rxi]["m_range_rate"][mi]) / dv

                m_range_dv2 = (meas_dv2[txi][rxi]["m_range"][mi] -
                               meas0[txi][rxi]["m_range"][mi]) / dv
                m_range_rate_dv2 = (meas_dv2[txi][rxi]["m_range_rate"][mi] -
                                    meas0[txi][rxi]["m_range_rate"][mi]) / dv

                m_range_dcd = (meas_dcd[txi][rxi]["m_range"][mi] -
                               meas0[txi][rxi]["m_range"][mi]) / dcd
                m_range_rate_dcd = (meas_dcd[txi][rxi]["m_range_rate"][mi] -
                                    meas0[txi][rxi]["m_range_rate"][mi]) / dcd

                J[2 * row_idx, 0] = m_range_dx0
                J[2 * row_idx, 1] = m_range_dx1
                J[2 * row_idx, 2] = m_range_dx2
                J[2 * row_idx, 3] = m_range_dv0
                J[2 * row_idx, 4] = m_range_dv1
                J[2 * row_idx, 5] = m_range_dv2
                if include_drag:
                    J[2 * row_idx, 6] = m_range_dcd

                J[2 * row_idx + 1, 0] = m_range_rate_dx0
                J[2 * row_idx + 1, 1] = m_range_rate_dx1
                J[2 * row_idx + 1, 2] = m_range_rate_dx2
                J[2 * row_idx + 1, 3] = m_range_rate_dv0
                J[2 * row_idx + 1, 4] = m_range_rate_dv1
                J[2 * row_idx + 1, 5] = m_range_rate_dv2
                if include_drag:
                    J[2 * row_idx + 1, 6] = m_range_rate_dcd
                row_idx += 1
    #
    # Prior information about log10(A/m) parameter
    # This is achieved by adding a virtual measurement:
    # - we've measured log10(A/m) with 0.77 standard deviation
    #
    # Bayesian statistics, but with linear regression.
    #
    if include_drag:
        J[n_meas, 6] = 1.0

        Sigma_m_inv[n_meas, n_meas] = 1.0 / (log10_A_to_m_std**2.0)

    # linearized error covariance
    # \Sigma_post = (A^T \Sigma^{-1} A)^{-1}
    Sigma_pos = n.linalg.inv(n.dot(n.dot(n.transpose(J), Sigma_m_inv), J))

    if debug_output:
        print("ECEF error stdev")
        print(n.sqrt(n.diag(Sigma_pos))[0:6] * 1e3)
        if include_drag:
            print("Drag coefficient error")
            print(n.sqrt(n.diag(Sigma_pos))[6])

    return (Sigma_pos, range_0)
Esempio n. 2
0
#
import numpy as n
import matplotlib.pyplot as plt
from mpi4py import MPI

# SORTS imports
import population
import simulate_scan as ss
import simulate_tracklet as st
import radar_config as r

m = master.master_catalog()

t_obs = n.arange(0, 24 * 60 * 4) * 15

comm = MPI.COMM_WORLD
for oid in range(comm.rank, len(m), comm.size):
    o = m.get_object(oid)
    #  try:
    print("object %d id=%d diam=%1.2g a=%1.2f e=%1.2f i=%1.2f raan=%1.2f aop=%1.2f mu0=%1.2f mass=%1.2g A=%1.2g factor=%1.2f"% \
     (oid,o.oid,o.diam,o.a,o.e,o.i,o.raan,o.aop,o.mu0,o.m,o.A,o.factor))

    if o.a < 10000.0 and o.i > 40.0:
        meas = st.create_tracklet(o,
                                  r,
                                  t_obs,
                                  dt=0.01,
                                  hdf5_out=True,
                                  ccsds_out=True,
                                  dname="./repeat_tracklets")
Esempio n. 3
0
def test_tracklets():
    # Unit test
    #
    # Create tracklets and perform orbit determination
    #
    import population_library as plib
    import radar_library as rlib
    import simulate_tracking
    import simulate_tracklet as st
    import os

    os.system("rm -Rf /tmp/test_tracklets")
    os.system("mkdir /tmp/test_tracklets")
    m = plib.master_catalog(sort=False)

    # Envisat
    o = m.get_object(145128)
    print(o)

    e3d = rlib.eiscat_3d(beam='gauss')

    # time in seconds after mjd0
    t_all = n.linspace(0, 24 * 3600, num=1000)

    passes, _, _, _, _ = simulate_tracking.find_pass_interval(t_all, o, e3d)
    print(passes)

    for p in passes[0]:
        # 100 observations of each pass
        mean_t = 0.5 * (p[1] + p[0])
        print("duration %1.2f" % (p[1] - p[0]))
        if p[1] - p[0] > 10.0:
            t_obs = n.linspace(mean_t - 10, mean_t + 10, num=10)
            print(t_obs)
            meas, fnames, ecef_stdevs = st.create_tracklet(
                o,
                e3d,
                t_obs,
                hdf5_out=True,
                ccsds_out=True,
                dname="/tmp/test_tracklets")

    fl = glob.glob("/tmp/test_tracklets/*")
    for f in fl:
        print(f)
        fl2 = glob.glob("%s/*.h5" % (f))
        print(fl2)
        fl2.sort()
        start_times = []
        for f2 in fl2:
            start_times.append(re.search("(.*/track-.*)-._..h5", f2).group(1))
        start_times = n.unique(start_times)
        print("n_tracks %d" % (len(start_times)))

        for t_pref in start_times[0:1]:
            fl2 = glob.glob("%s*.h5" % (t_pref))
            n_static = len(fl2)
            if n_static == 3:
                print("Fitting track %s" % (t_pref))

                f0 = "%s-0_0.h5" % (t_pref)
                f1 = "%s-0_1.h5" % (t_pref)
                f2 = "%s-0_2.h5" % (t_pref)

                print(f0)
                print(f1)
                print(f2)

                h0 = h5py.File(f0, "r")
                h1 = h5py.File(f1, "r")
                h2 = h5py.File(f2, "r")

                r_meas0 = h0["m_range"].value
                rr_meas0 = h0["m_range_rate"].value
                r_meas1 = h1["m_range"].value
                rr_meas1 = h1["m_range_rate"].value
                r_meas2 = h2["m_range"].value
                rr_meas2 = h2["m_range_rate"].value

                n_t = len(r_meas0)
                if len(r_meas1) != n_t or len(r_meas2) != n_t:
                    print(
                        "non-overlapping measurements, tbd, align measurement")
                    continue

                p_rx = n.zeros([3, 3])
                p_rx[:, 0] = h0["rx_loc"].value / 1e3
                p_rx[:, 1] = h1["rx_loc"].value / 1e3
                p_rx[:, 2] = h2["rx_loc"].value / 1e3

                for ti in range(n_t):
                    if h0["m_time"][ti] != h1["m_time"][ti] or h2["m_time"][
                            ti] != h0["m_time"][ti]:
                        print("non-aligned measurement")
                        continue
                    m_r = n.array([r_meas0[ti], r_meas1[ti], r_meas2[ti]])
                    m_rr = n.array([rr_meas0[ti], rr_meas1[ti], rr_meas2[ti]])
                    ecef_state = orbital_estimation.estimate_state(
                        m_r, m_rr, p_rx)
                    true_state = h0["true_state"].value[ti, :]
                    r_err = 1e3 * n.linalg.norm(ecef_state[0:3] -
                                                true_state[0:3])
                    v_err = 1e3 * n.linalg.norm(ecef_state[3:6] -
                                                true_state[3:6])
                    print("pos error %1.3f (m) vel error %1.3f (m/s)" %
                          (1e3 * n.linalg.norm(ecef_state[0:3] -
                                               true_state[0:3]), 1e3 *
                           n.linalg.norm(ecef_state[3:6] - true_state[3:6])))
                    assert r_err < 100.0
                    assert v_err < 50.0

                h0.close()
                h1.close()
                h2.close()

    os.system("rm -Rf /tmp/test_tracklets")
Esempio n. 4
0
def plot_measurements(o, r, tracklets):
    n_tx = len(r._tx)
    n_rx = len(r._rx)

    # plot range meas
    plt.subplot(231)
    plt.ylabel("Range (km)")
    plt.xlabel("Time (s)")
    for ti, t_obs in enumerate(tracklets):
        print("Plotting tracklet %d" % (ti))
        meas, fnames, e = s.create_tracklet(o,
                                            r,
                                            t_obs,
                                            hdf5_out=False,
                                            ccsds_out=False,
                                            noise=False)

        for txi in range(n_tx):
            for rxi in range(n_rx):
                plt.plot(meas[txi][rxi]["m_time"], meas[txi][rxi]["m_range"],
                         ".")

    plt.subplot(232)
    plt.ylabel("Range-rate (km/s)")
    plt.xlabel("Time (s)")
    for ti, t_obs in enumerate(tracklets):
        print("Tracklet %d" % (ti))
        meas, fnames, e = s.create_tracklet(o,
                                            r,
                                            t_obs,
                                            hdf5_out=False,
                                            ccsds_out=False,
                                            noise=False)

        for txi in range(n_tx):
            for rxi in range(n_rx):
                plt.plot(meas[txi][rxi]["m_time"],
                         meas[txi][rxi]["m_range_rate"], ".")

    plt.subplot(233)
    plt.xlabel("Ground longitude (deg)")
    plt.ylabel("Ground latitude (deg)")
    for ti, t_obs in enumerate(tracklets):
        meas, fnames, e = s.create_tracklet(o,
                                            r,
                                            t_obs,
                                            hdf5_out=False,
                                            ccsds_out=False,
                                            noise=False)
        for txi in range(n_tx):
            for rxi in range(n_rx):
                plt.plot(meas[txi][rxi]["g_lon"], meas[txi][rxi]["g_lat"], ".")

    plt.subplot(234)
    plt.ylabel("Range error (m)")
    plt.xlabel("Time (s)")
    for ti, t_obs in enumerate(tracklets):
        meas, fnames, e = s.create_tracklet(o,
                                            r,
                                            t_obs,
                                            hdf5_out=False,
                                            ccsds_out=False,
                                            noise=False)

        for txi in range(n_tx):
            for rxi in range(n_rx):
                plt.plot(meas[txi][rxi]["m_time"],
                         n.array(meas[txi][rxi]["m_range_std"]) * 1e3, ".")
    plt.subplot(235)
    plt.ylabel("Range-rate error (m/s)")
    plt.xlabel("Time (s)")
    for ti, t_obs in enumerate(tracklets):
        meas, fnames, e = s.create_tracklet(o,
                                            r,
                                            t_obs,
                                            hdf5_out=False,
                                            ccsds_out=False,
                                            noise=False)

        for txi in range(n_tx):
            for rxi in range(n_rx):
                plt.plot(meas[txi][rxi]["m_time"],
                         n.array(meas[txi][rxi]["m_range_rate_std"]) * 1e3,
                         ".")

    plt.subplot(236)
    plt.ylabel("SNR (dB)")
    plt.xlabel("Time (s)")
    for ti, t_obs in enumerate(tracklets):
        meas, fnames, e = s.create_tracklet(o,
                                            r,
                                            t_obs,
                                            hdf5_out=False,
                                            ccsds_out=False,
                                            noise=False)

        for txi in range(n_tx):
            for rxi in range(n_rx):
                plt.plot(meas[txi][rxi]["m_time"],
                         10.0 * n.log10(n.array(meas[txi][rxi]["enr"])), ".")

    plt.tight_layout()
    # tdb, add covariance ellipse
    plt.show()
Esempio n. 5
0
def linearized_errors(o,
                      radar,
                      tracklets,
                      plot=True,
                      debug=False,
                      t0s=n.linspace(0, 2 * 3600, num=50),
                      time_vector=False):

    n_tx = len(radar._tx)
    n_rx = len(radar._rx)

    # calculate a Jacobian
    a = o.a
    e = o.e
    i = o.i
    raan = o.raan
    aop = o.aop
    mu0 = o.mu0

    da = 1e-3  # 1 m
    de = 1e-6
    di = 1e-6
    daop = 1e-6
    draan = 1e-6
    dmu0 = 1e-6

    o0 = so.space_object(o.a, o.e, o.i, o.raan, o.aop, o.mu0, o.diam)
    o_da = so.space_object(o.a + da, o.e, o.i, o.raan, o.aop, o.mu0, o.diam)
    o_de = so.space_object(o.a, o.e + de, o.i, o.raan, o.aop, o.mu0, o.diam)
    o_di = so.space_object(o.a, o.e, o.i + di, o.raan, o.aop, o.mu0, o.diam)
    o_daop = so.space_object(o.a, o.e, o.i, o.raan, o.aop + daop, o.mu0,
                             o.diam)
    o_draan = so.space_object(o.a, o.e, o.i, o.raan + draan, o.aop, o.mu0,
                              o.diam)
    o_dmu0 = so.space_object(o.a, o.e, o.i, o.raan, o.aop, o.mu0 + dmu0,
                             o.diam)

    # calculate the number of rows in the theory matrix
    n_rows = 0
    for ti, t_obs in enumerate(tracklets):
        if debug:
            print("tracklet %d" % (ti))
            print(t_obs)

        meas0, fnames, e = s.create_tracklet(o0,
                                             radar,
                                             t_obs,
                                             dt=0.01,
                                             hdf5_out=False,
                                             ccsds_out=False,
                                             dname="./tracklets",
                                             noise=False)

        for txi in range(n_tx):
            for rxi in range(n_rx):
                n_meas = len(meas0[txi][rxi]["m_time"])
                if debug:
                    print("n_meas %d" % (n_meas))
                n_rows += n_meas

    # one range and one range rate measurement
    n_meas = n_rows * 2
    if debug:
        print("number of measurements %d" % (n_meas))
    # error covariance matrix of measurements
    Sigma_m_inv = n.zeros([n_meas, n_meas])
    # jacobian
    J = n.zeros([n_meas, 6])

    row_idx = 0
    # perturb elements in each of the six parameters
    for ti, t_obs in enumerate(tracklets):
        if debug:
            print("Tracklet %d" % (ti))
        meas0, fnames, e = s.create_tracklet(o0,
                                             radar,
                                             t_obs,
                                             hdf5_out=False,
                                             ccsds_out=False,
                                             noise=False)
        meas_da, fnames, e = s.create_tracklet(o_da,
                                               radar,
                                               t_obs,
                                               hdf5_out=False,
                                               ccsds_out=False,
                                               noise=False)
        meas_de, fnames, e = s.create_tracklet(o_de,
                                               radar,
                                               t_obs,
                                               hdf5_out=False,
                                               ccsds_out=False,
                                               noise=False)
        meas_di, fnames, e = s.create_tracklet(o_di,
                                               radar,
                                               t_obs,
                                               hdf5_out=False,
                                               ccsds_out=False,
                                               noise=False)
        meas_daop, fnames, e = s.create_tracklet(o_daop,
                                                 radar,
                                                 t_obs,
                                                 hdf5_out=False,
                                                 ccsds_out=False,
                                                 noise=False)
        meas_draan, fnames, e = s.create_tracklet(o_draan,
                                                  radar,
                                                  t_obs,
                                                  hdf5_out=False,
                                                  ccsds_out=False,
                                                  noise=False)
        meas_dmu0, fnames, e = s.create_tracklet(o_dmu0,
                                                 radar,
                                                 t_obs,
                                                 hdf5_out=False,
                                                 ccsds_out=False,
                                                 noise=False)

        for txi in range(n_tx):
            for rxi in range(n_rx):
                n_meas = len(meas0[txi][rxi]["m_time"])
                if debug:
                    print("n_meas %d measurement %d" % (n_meas, row_idx))
                for mi in range(n_meas):
                    # range and range-rate error
                    range_std = meas0[txi][rxi]["m_range_std"][mi]
                    range_rate_std = meas0[txi][rxi]["m_range_rate_std"][mi]

                    # range and range rate error variance
                    Sigma_m_inv[2 * row_idx,
                                2 * row_idx] = 1.0 / range_std**2.0
                    Sigma_m_inv[2 * row_idx + 1,
                                2 * row_idx + 1] = 1.0 / range_rate_std**2.0

                    # apogee
                    m_range_da = (meas_da[txi][rxi]["m_range"][mi] -
                                  meas0[txi][rxi]["m_range"][mi]) / da
                    m_range_rate_da = (
                        meas_da[txi][rxi]["m_range_rate"][mi] -
                        meas0[txi][rxi]["m_range_rate"][mi]) / da
                    # e
                    m_range_de = (meas_de[txi][rxi]["m_range"][mi] -
                                  meas0[txi][rxi]["m_range"][mi]) / de
                    m_range_rate_de = (
                        meas_de[txi][rxi]["m_range_rate"][mi] -
                        meas0[txi][rxi]["m_range_rate"][mi]) / de
                    # inc
                    m_range_di = (meas_di[txi][rxi]["m_range"][mi] -
                                  meas0[txi][rxi]["m_range"][mi]) / di
                    m_range_rate_di = (
                        meas_di[txi][rxi]["m_range_rate"][mi] -
                        meas0[txi][rxi]["m_range_rate"][mi]) / di
                    # aop
                    m_range_daop = (meas_daop[txi][rxi]["m_range"][mi] -
                                    meas0[txi][rxi]["m_range"][mi]) / daop
                    m_range_rate_daop = (
                        meas_daop[txi][rxi]["m_range_rate"][mi] -
                        meas0[txi][rxi]["m_range_rate"][mi]) / daop
                    # raan
                    m_range_draan = (meas_draan[txi][rxi]["m_range"][mi] -
                                     meas0[txi][rxi]["m_range"][mi]) / draan
                    m_range_rate_draan = (
                        meas_draan[txi][rxi]["m_range_rate"][mi] -
                        meas0[txi][rxi]["m_range_rate"][mi]) / draan
                    # mu0
                    m_range_dmu0 = (meas_dmu0[txi][rxi]["m_range"][mi] -
                                    meas0[txi][rxi]["m_range"][mi]) / dmu0
                    m_range_rate_dmu0 = (
                        meas_dmu0[txi][rxi]["m_range_rate"][mi] -
                        meas0[txi][rxi]["m_range_rate"][mi]) / dmu0
                    if debug:
                        print(
                            "r da %1.2f di %1.2f de %1.2f daop %1.2f draan %1.2f dmu0 %1.2f"
                            % (m_range_da, m_range_di, m_range_de,
                               m_range_daop, m_range_draan, m_range_dmu0))
                        print(
                            "rr da %1.2f di %1.2f de %1.2f daop %1.2f draan %1.2f dmu0 %1.2f"
                            % (m_range_rate_da, m_range_rate_di,
                               m_range_rate_de, m_range_rate_daop,
                               m_range_rate_draan, m_range_rate_dmu0))

                    J[2 * row_idx, 0] = m_range_da
                    J[2 * row_idx, 1] = m_range_de
                    J[2 * row_idx, 2] = m_range_di
                    J[2 * row_idx, 3] = m_range_daop
                    J[2 * row_idx, 4] = m_range_draan
                    J[2 * row_idx, 5] = m_range_dmu0

                    J[2 * row_idx + 1, 0] = m_range_rate_da
                    J[2 * row_idx + 1, 1] = m_range_rate_de
                    J[2 * row_idx + 1, 2] = m_range_rate_di
                    J[2 * row_idx + 1, 3] = m_range_rate_daop
                    J[2 * row_idx + 1, 4] = m_range_rate_draan
                    J[2 * row_idx + 1, 5] = m_range_rate_dmu0
                    row_idx += 1

    # linearized error covariance
    Sigma_pos = n.linalg.inv(n.dot(n.dot(n.transpose(J), Sigma_m_inv), J))

    # linear transformation
    Sigma_ecef = kep_cov2cart_cov(o, Sigma_pos, t0s=t0s)

    return (Sigma_pos, Sigma_ecef)
Esempio n. 6
0
lt_correction = r_obs / scipy.constants.c * 1e3
t_obs -= lt_correction

#print(lt_correction)
'''
states = obj.get_orbit(t_obs)
ax = dpt.orbit3D(states)
radar.draw3d(ax)
plt.show()
'''

meas, fnames, ecef_stdevs = simulate_tracklet.create_tracklet(
    obj,
    radar,
    t_obs,
    hdf5_out=True,
    ccsds_out=True,
    dname="./tests/tmp_test_data",
    noise=False,
)

out_h5 = fnames[0] + '.h5'
out_ccsds = fnames[0] + '.tdm'

print('FILES: ', fnames)

with h5py.File(out_h5, 'r') as h_det:
    pass
    #h_det['m_range']
    #h_det['m_range_rate']
Esempio n. 7
0
def wls_state_est(mcmc=False, n_tracklets=1, track_length=600.0, n_points=3, oid=145128, N_samples=5000):
    """
    Weighted linear least squares estimation of orbital elements
    
    Simulate measurements using create tracklet and estimate 
    orbital parameters, which include six keplerian and area to mass ratio. 

    Use fmin search. 
    Optionally utilize MCMC to sample the distribution of parameters.
    
    number of tracklets, tracklet length, and number of tracklet points per tracklet are
    user definable, allowing one to try out different measurement strategies. 
    """
    # first we shall simulate some measurement
    # Envisat

    m = plib.master_catalog(sort=False)
    o = m.get_object(oid)

    dname="./test_tracklets_%d"%(oid)
    print(o)

    # figure out epoch in unix seconds
    t0_unix = dpt.jd_to_unix(dpt.mjd_to_jd(o.mjd0))

    if rank == 0:
        os.system("rm -Rf %s"%(dname))
        os.system("mkdir %s"%(dname))    
        
        e3d = rlib.eiscat_3d(beam='gauss')

        # time in seconds after mjd0
        t_all = n.linspace(0, 24*3600, num=1000)
    
        passes, _, _, _, _ = simulate_tracking.find_pass_interval(t_all, o, e3d)
        print(passes)
        if n_tracklets == None:
            n_tracklets = len(passes[0])
        n_tracklets = n.min([n_tracklets,len(passes[0])])

        for pi in range(n_tracklets):
            p = passes[0][pi]
            mean_t=0.5*(p[1]+p[0])
            print("duration %1.2f"%(p[1]-p[0]))
            if p[1]-p[0] > 50.0:
                if n_points == 1:
                    t_obs=n.array([mean_t])
                else:
                    t_obs=n.linspace(n.max([p[0],mean_t-track_length/2]), n.min([p[1],mean_t+track_length/2]),num=n_points)
                
                print(t_obs)
                meas, fnames, ecef_stdevs = st.create_tracklet(o, e3d, t_obs, hdf5_out=True, ccsds_out=True, dname=dname)

    # then we read these measurements
    comm.Barrier()
    
    fl=glob.glob("%s/*"%(dname))
    for f in fl:
        print(f)
        fl2=glob.glob("%s/*.h5"%(f))
        print(fl2)
        fl2.sort()
        
        true_states=[]
        all_r_meas=[]
        all_rr_meas=[]
        all_t_meas=[]
        all_true_states=[]
        tx_locs=[]
        rx_locs=[]
        range_stds=[]
        range_rate_stds=[]        
        
        for mf in fl2:
            h=h5py.File(mf,"r")
            all_r_meas.append(n.copy(h["m_range"].value))
            all_rr_meas.append(n.copy(h["m_range_rate"].value))
            all_t_meas.append(n.copy(h["m_time"].value-t0_unix))
            all_true_states.append(n.copy(h["true_state"].value))
            tx_locs.append(n.copy(h["tx_loc"].value))
            rx_locs.append(n.copy(h["rx_loc"].value))
            range_stds.append(n.copy(h["m_range_rate_std"].value))
            range_rate_stds.append(h["m_range_std"].value)
            h.close()
            
        # determine orbital elements
        o_prior = m.get_object(oid)

        # get best fit space object
        o_fit=mcmc_od(all_t_meas, all_r_meas, all_rr_meas, range_stds, range_rate_stds, tx_locs, rx_locs, o_prior, mcmc=mcmc, odir=dname, N_samples=N_samples)
Esempio n. 8
0
    def test_create_tracklet(self):

        radar = rlib.eiscat_uhf()
        radar.set_FOV(30.0, 25.0)

        #tle files for envisat in 2016-09-05 to 2016-09-07 from space-track.
        TLEs = [
            ('1 27386U 02009A   16249.14961597  .00000004  00000-0  15306-4 0  9994',
             '2 27386  98.2759 299.6736 0001263  83.7600 276.3746 14.37874511760117'
             ),
            ('1 27386U 02009A   16249.42796553  .00000002  00000-0  14411-4 0  9997',
             '2 27386  98.2759 299.9417 0001256  82.8173 277.3156 14.37874515760157'
             ),
            ('1 27386U 02009A   16249.77590267  .00000010  00000-0  17337-4 0  9998',
             '2 27386  98.2757 300.2769 0001253  82.2763 277.8558 14.37874611760201'
             ),
            ('1 27386U 02009A   16250.12384028  .00000006  00000-0  15974-4 0  9995',
             '2 27386  98.2755 300.6121 0001252  82.5872 277.5467 14.37874615760253'
             ),
            ('1 27386U 02009A   16250.75012691  .00000017  00000-0  19645-4 0  9999',
             '2 27386  98.2753 301.2152 0001254  82.1013 278.0311 14.37874790760345'
             ),
        ]

        pop = population_library.tle_snapshot(TLEs, sgp4_propagation=True)

        #it seems to around 25m^2 area
        d = n.sqrt(25.0 * 4 / n.pi)
        pop.add_column('d', space_object_uses=True)
        pop['d'] = d

        ccsds_file = './data/uhf_test_data/events/2002-009A-1473150428.tdm'

        obs_data = ccsds_write.read_ccsds(ccsds_file)
        jd_obs = dpt.mjd_to_jd(dpt.npdt2mjd(obs_data['date']))

        date_obs = obs_data['date']
        sort_obs = n.argsort(date_obs)
        date_obs = date_obs[sort_obs]
        r_obs = obs_data['range'][sort_obs]

        jd_sort = jd_obs.argsort()
        jd_obs = jd_obs[jd_sort]

        jd_det = jd_obs[0]

        jd_pop = dpt.mjd_to_jd(pop['mjd0'])

        pop_id = n.argmin(n.abs(jd_pop - jd_det))
        obj = pop.get_object(pop_id)

        print(obj)

        jd_obj = dpt.mjd_to_jd(obj.mjd0)

        print('Day difference detection - TLE: {}'.format(jd_det - jd_obj))

        t_obs = (jd_obs - jd_obj) * (3600.0 * 24.0)

        meas, fnames, ecef_stdevs = simulate_tracklet.create_tracklet(
            obj,
            radar,
            t_obs,
            hdf5_out=True,
            ccsds_out=True,
            dname="./tests/tmp_test_data",
            noise=False,
        )

        out_h5 = fnames[0] + '.h5'
        out_ccsds = fnames[0] + '.tdm'

        print('FILES: ', fnames)

        with h5py.File(out_h5, 'r') as h_det:
            assert 'm_range' in h_det
            assert 'm_range_rate' in h_det
            assert 'm_time' in h_det

        sim_data = ccsds_write.read_ccsds(out_ccsds)

        date_sim = sim_data['date']
        sort_sim = n.argsort(date_sim)
        date_sim = date_sim[sort_sim]

        r_sim = sim_data['range'][sort_sim]
        v_sim = sim_data['doppler_instantaneous'][sort_sim]

        lt_correction = n.round(r_sim / scipy.constants.c * 1e6).astype(
            n.int64).astype('timedelta64[us]')

        date_sim_cor = date_sim + lt_correction

        t_sim = dpt.jd_to_unix(dpt.mjd_to_jd(dpt.npdt2mjd(date_sim_cor)))

        for ind in range(len(date_sim)):
            time_df = (dpt.npdt2mjd(date_sim_cor[ind]) -
                       dpt.npdt2mjd(date_obs[ind])) * 3600.0 * 24.0
            assert time_df < 0.01

        assert len(r_obs) == len(r_sim)

        dat = {
            't': t_sim,
            'r': r_sim * 1e3,
            'v': v_sim * 1e3,
        }

        cdat = correlator.correlate(
            data=dat,
            station=radar._rx[0],
            population=pop,
            metric=correlator.residual_distribution_metric,
            n_closest=1,
            out_file=None,
            verbose=False,
            MPI_on=False,
        )

        self.assertLess(n.abs(cdat[0]['stat'][0]), 5.0)
        self.assertLess(n.abs(cdat[0]['stat'][1]), 50.0)
        self.assertLess(n.abs(cdat[0]['stat'][2]), 5.0)
        self.assertLess(n.abs(cdat[0]['stat'][3]), 50.0)

        nt.assert_array_less(n.abs(r_sim - r_obs), 1.0)

        os.remove(out_h5)
        print('removed "{}"'.format(out_h5))

        os.remove(out_ccsds)
        print('removed "{}"'.format(out_ccsds))

        sat_folder = os.sep.join(fnames[0].split(os.sep)[:-1])
        os.rmdir(sat_folder)
        print('removed "{}"'.format(sat_folder))