Esempio n. 1
0
def get_t_obs(o,
              radar,
              n_tracklets=1,
              track_length=600.0,
              n_points=3,
              debug=True,
              h0=0.0,
              h1=24.0):
    """
    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. 
    """
    e3d = rl.eiscat_3d(beam='gauss')

    # time in seconds after mjd0
    t_all = n.linspace(h0 * 3600, h1 * 3600.0, num=1000 * (h1 - h0))

    passes, _, _, _, _ = st.find_pass_interval(t_all, o, e3d)
    if debug:
        print("number of possible tracklets %d" % (len(passes[0])))

    if n_tracklets == None:
        n_tracklets = len(passes[0])

    tracklet_idx = n.arange(len(passes[0]))
    # seems like random shuffle doesn't use a random seed.
    import time
    n.random.seed(int(time.time()))
    n.random.shuffle(tracklet_idx)

    n_tracklets = n.min([n_tracklets, len(passes[0])])
    tracklet_idx = tracklet_idx[0:n_tracklets]

    t_obss = []
    t_means = []
    for pi in tracklet_idx:
        p = passes[0][pi]
        mean_t = 0.5 * (p[1] + p[0])
        t_means.append(mean_t)
        if debug:
            print("duration %1.2f" % (p[1] - p[0]))
        if p[1] - p[0] > 5.0:
            if n_points == 1:
                t_obs = n.array([mean_t])
            else:
                # maximize track length
                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)
            t_obss = n.concatenate([t_obss, t_obs])
    return (t_obss, n_tracklets, n.array(t_means))
def atmospheric_errors_rw(o,
                          n_tracklets=1,
                          n_points=1,
                          track_length=600.0,
                          error0=40.0):

    e3d = rlib.eiscat_3d(beam='gauss')
    t = n.linspace(-2 * 24 * 3600, 2 * 24 * 3600, num=1000)
    t_all = n.linspace(0, 2 * 24 * 3600, num=100000)
    passes, _, _, _, _ = st.find_pass_interval(t_all, o, e3d)
    print(len(passes[0]))
    if passes == None:
        return
    n_tracklets = n.min([n_tracklets, len(passes[0])])
    tracklet_idx = n.arange(n_tracklets)
    t_obs = []
    # randomize tracklet positions
    n.random.shuffle(tracklet_idx)
    for pi in tracklet_idx:
        p = passes[0][pi]
        mean_t = 0.5 * (p[1] + p[0])
        t_obs.append(mean_t)

    midx = []
    for to in t_obs:
        midx.append(n.argmin(n.abs(t - to)))

    N_p = len(t)
    n_meas = n_tracklets + n_tracklets * (N_p - 1)
    A = n.zeros([n_meas, N_p])

    row_idx = 0
    idx = n.arange(N_p)
    S = n.zeros(n_meas)
    for i in range(n_tracklets):
        A[row_idx, midx[i]] = 1.0
        S[row_idx] = error0**2.0
        row_idx += 1
        idx2 = n.setdiff1d(idx, midx[i])
        for j in idx2:
            A[row_idx, midx[i]] = 1.0
            A[row_idx, j] = -1.0
            dt = t[midx[i]] - t[j]
            #            print(dt)
            print(error_var(n.abs(dt)))
            S[row_idx] = error_var(n.abs(dt))
            row_idx += 1
    for i in range(n_meas):
        A[i, :] = A[i, :] / n.sqrt(S[i])
    Sp = n.linalg.inv(n.dot(n.transpose(A), A))
    plt.semilogy(t / 3600.0, n.sqrt(n.diag(Sp)), label="Position error stdev")
    plt.ylabel("Position error standard deviation (m)")
    for i in range(n_tracklets):
        plt.axvline(t_obs[i] / 3600.0, color="red", label="measurement")
    plt.xlabel("Time (hours)")
    plt.legend()
    plt.title("Atmospheric drag uncertainty related errors")
    plt.show()
Esempio n. 3
0
def find_passes(o, radar, n_tracklets=1, max_t=4 * 24 * 3600.0):
    t_all = n.linspace(0, max_t, num=100000)
    passes, _, _, _, _ = st.find_pass_interval(t_all, o, radar)

    if passes == None:
        return
    print(passes[0])
    print("n_tracklets %d" % (len(passes[0])))
    n_tracklets = n.min([n_tracklets, len(passes[0])])
    tracklet_idx = n.arange(n_tracklets)
    t_obs = []
    # randomize tracklet positions
    n.random.shuffle(tracklet_idx)

    for pi in tracklet_idx:
        p = passes[0][pi]
        mean_t = 0.5 * (p[1] + p[0])
        t_obs.append(mean_t)
    return (t_obs)
Esempio n. 4
0
    def test_find_pass_interval(self):

        passes, passes_id, idx_v, postx_v, posrx_v = simulate_tracking.find_pass_interval(
            self.full_t, self.o, self.radar)

        assert len(passes) == len(self.radar._tx)
        assert len(passes_id) == len(self.radar._tx)

        assert len(passes[0]) == 1
        assert len(passes_id[0]) == 1

        self.assertLess(n.abs(passes[0][0][0] - self.rise_T),
                        self.T / self.num * 20.0)
        self.assertLess(n.abs(passes[0][0][1] - self.fall_T),
                        self.T / self.num * 20.0)

        self.assertAlmostEqual(self.full_t[idx_v][passes_id[0][0][0]],
                               passes[0][0][0])
        self.assertAlmostEqual(self.full_t[idx_v][passes_id[0][0][1]],
                               passes[0][0][1])
Esempio n. 5
0
def get_t_obs(o,
              radar,
              n_tracklets=1,
              track_length=600.0,
              n_points=3,
              debug=False,
              h0=0.0,
              h1=24.0,
              half_track=False,
              sort_by_length=False,
              n_points0=50):
    """
    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. 
    """
    e3d = rl.eiscat_3d(beam='gauss')

    # time in seconds after mjd0
    t_all = n.linspace(h0 * 3600, h1 * 3600.0, num=1000 * (h1 - h0))

    passes, _, _, _, _ = st.find_pass_interval(t_all, o, e3d)
    if debug:
        print("number of possible tracklets %d" % (len(passes[0])))

    if n_tracklets == None:
        n_tracklets = len(passes[0])

    tracklet_idx = n.arange(len(passes[0]))

    n_tracklets = n.min([n_tracklets, len(passes[0])])

    tracklet_lengths = []
    for pi in tracklet_idx:
        p = passes[0][pi]
        tracklet_lengths.append(p[1] - p[0])
    tracklet_lengths = n.array(tracklet_lengths)

    if sort_by_length:
        idx = n.argsort(tracklet_lengths)[::-1]
    else:
        idx = n.arange(len(tracklet_lengths))
    # select n_tracklets longest tracklets
    tracklet_idx = tracklet_idx[idx[0:n_tracklets]]

    t_obss = []
    t_means = []
    for pii, pi in enumerate(tracklet_idx):
        p = passes[0][pi]
        mean_t = 0.5 * (p[1] + p[0])
        t_means.append(mean_t)
        if debug:
            print("duration %1.2f" % (p[1] - p[0]))
        if p[1] - p[0] > 5.0:
            if n_points == 1:
                t_obs = n.array([mean_t])
            elif pii == 0 and half_track:
                # maximize track length, but only observe half of the pass (simulate initial discovery follow-up measurments)
                t_obs = n.linspace(mean_t,
                                   n.min([p[1], mean_t + track_length / 2]),
                                   num=n_points0)
            else:
                # maximize track length
                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)
            t_obss = n.concatenate([t_obss, t_obs])
    return (t_obss, n_tracklets, n.array(t_means),
            tracklet_lengths[0:n_tracklets])
Esempio n. 6
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. 7
0
    taus = []
    offsets = []
    t1s = []
    alphas = []
    n_passes = []
    mean_time_between_passes = []
    t = n.linspace(0, 24 * 3600, num=10000)

    # objs= list(pop_e3d.object_generator())
    objs = []
    for o in pop_e3d.object_generator():
        objs.append(o)
        break
    for oi in range(comm.rank, len(objs), comm.size):
        o = objs[oi]
        passes, _, _, _, _ = st.find_pass_interval(t, o, radar_e3d)

        if passes[0] == None:
            n_pass = 0
        else:
            n_pass = len(passes[0])

        tau, offset, t1, alpha = atmospheric_errors(o,
                                                    a_err_std=0.05,
                                                    plot=True)
        print(
            "%d %d/%d oid %d number of passes %d mean_time %1.1f (h) tau %1.1f (h)"
            % (comm.rank, oi, len(objs), o.oid, n_pass, 24.0 /
               (n_pass + 1e-6), tau))
        plt.tight_layout()
        plt.show()
Esempio n. 8
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. 9
0
    import population_library as plib
    import radar_library as rlib
    import simulate_tracking

    m = plib.master_catalog()

    o = m.get_object(13)
    o.diam = 1.0

    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)

    t_mid = (passes[0][0][0] + passes[0][0][1]) * 0.5

    t_obs = n.arange(t_mid, t_mid + 2, 0.2)

    meas, fnames, ecef_stdevs = create_tracklet(
        o,
        e3d,
        t_obs,
        hdf5_out=True,
        ccsds_out=True,
        dname="/home/danielk/IRF/E3D_PA/tmp/test")
    print(ecef_stdevs)
    print(fnames)
    print(meas)
Esempio n. 10
0
def get_detections(obj,
                   radar,
                   t0,
                   t1,
                   max_dpos=10.0e3,
                   logger=None,
                   pass_dt=None):
    '''Find all detections of a object by input radar between two times relative the object Epoch.

    :param SpaceObject obj: Space object to find detections of.
    :param RadarSystem radar: Radar system that scans for the object.
    :param float t0: Start time for scan relative space object epoch.
    :param float t1: End time for scan relative space object epoch.
    :param float max_dpos: Maximum separation between evaluation points in meters for finding the pass interval.
    :param Logger logger: Logger object for logging the execution of the function.
    :param float pass_dt: The time step used when evaluating pass. Default is the scan-minimum dwell time but can be forces to a setting by this variable.
    :return: Detections data structure in form of a list of dictionaries, see description below.
    :rtype: list
    
    **Return data:**
    
        List of same length as radar system TX antennas. Each entry in the list is a dictionary with the following items:

        * t0: List of pass start times. Length is equal the number of detection but unique times are equal to the number of passes..
        * t1: List of pass end times, i.e. when the space object passes below the FOV. Same list configuration as "t0"
        * snr: List of lists of SNR's for each TX-RX pair for each detection. I.e. the top list length is equal the number of detections and the elements are lists of length equal to the number of TX-RX pairs.
        * tm: List of times corresponding to each detection, same length as "snr" item.
        * range: Same structure as the "snr" item but with ranges between the TX and the RX antenna trough the object, i.e. two way range. Unit is meters.
        * range_rate: Same structure as the "range" item but with range-rates, i.e. rate of change of two way range. Unit is meters per second.
        * tx_gain: List of gains from the TX antenna for the detection, length of list is equal the number of detections.
        * rx_gain: List of lists in the same structure as the "snr" item but with receiver gains instead of signal to noise ratios.
        * on_axis_angle: List of angles between the space object and the pointing direction for each detection, length of list is equal to the number of detections.
    
    '''

    # list of transmitters
    txs = radar._tx
    # list of receivers
    rxs = radar._rx

    zenith = n.array([0, 0, 1], dtype=n.float)

    # list of detections for each transmitter-receiver pair
    # return detections, and also r, rr, tx gain, and rx gain
    detections = []
    for tx in txs:
        detections.append({
            "t0": [],
            "t1": [],
            "snr": [],
            'tm': [],
            "range": [],
            "range_rate": [],
            "tx_gain": [],
            "rx_gain": [],
            "on_axis_angle": []
        })

    num_t = simulate_tracking.find_linspace_num(t0,
                                                t1,
                                                obj.a * 1e3,
                                                obj.e,
                                                max_dpos=max_dpos)

    if logger is not None:
        logger.debug("n_points {} at {} m resolution".format(num_t, max_dpos))

    # time vector
    t = n.linspace(t0, t1, num=num_t, dtype=n.float)

    passes, passes_id, _, _, _ = simulate_tracking.find_pass_interval(
        t, obj, radar)
    for txi, pas in enumerate(passes):
        if pas is None:
            passes[txi] = []
    for txi, pas in enumerate(passes_id):
        if pas is None:
            passes_id[txi] = []

    #format: passes
    # [tx num][pass num][0 = above, 1 = below]

    if logger is not None:
        for txi in range(len(txs)):
            logger.debug('passes cnt: {}'.format(len(passes[txi])))

    for txi, tx in enumerate(txs):

        for pas in passes[txi]:

            if pass_dt is None:
                num_pass = int((pas[1] - pas[0]) / tx.scan.min_dwell_time)
            else:
                num_pass = int((pas[1] - pas[0]) / pass_dt)

            t_pass = n.linspace(pas[0], pas[1], num=num_pass, dtype=n.float)

            if logger is not None:
                logger.debug('tx{} - pass{} - num_pass: {}'.format(
                    txi, len(detections[txi]["t0"]), num_pass))

            states = obj.get_state(t_pass)

            ecef = states[:3, :]
            vels = states[3:, :]

            pos_rel_tx = (ecef.T - tx.ecef).T

            snrs = n.empty((num_pass, len(rxs)), dtype=n.float)
            angles = n.empty((num_pass, ), dtype=n.float)
            ks_obj = n.empty((3, num_pass), dtype=n.float)
            ksr_obj = n.empty((3, num_pass, len(rxs)), dtype=n.float)
            k0s = n.empty((3, num_pass), dtype=n.float)
            range_tx = n.empty((num_pass, ), dtype=n.float)
            vel_tx = n.empty((num_pass, ), dtype=n.float)
            gain_tx = n.empty((num_pass, ), dtype=n.float)
            gain_rx = n.empty((num_pass, len(rxs)), dtype=n.float)
            r_rad = n.empty((num_pass, len(rxs)), dtype=n.float)
            v_rad = n.empty((num_pass, len(rxs)), dtype=n.float)
            snrs_mask = n.full(snrs.shape, False, dtype=n.bool)
            zenith_mask = n.full(snrs.shape, False, dtype=n.bool)

            inds_mask = n.full((num_pass, ), True, dtype=n.bool)
            inds = n.arange(num_pass, dtype=n.int)

            for I in range(num_pass):
                k0 = tx.get_scan(t_pass[I]).local_pointing(t_pass[I])
                k0s[:, I] = k0

                ks_obj[:, I] = coord.ecef2local(
                    lat=tx.lat,
                    lon=tx.lon,
                    alt=tx.alt,
                    x=pos_rel_tx[0, I],
                    y=pos_rel_tx[1, I],
                    z=pos_rel_tx[2, I],
                )

                angles[I] = coord.angle_deg(k0s[:, I], ks_obj[:, I])
                if angles[I] > radar.max_on_axis:
                    inds_mask[I] = False

            inds_tmp = inds[inds_mask]

            if logger is not None:
                logger.debug('f1 inds left {}/{}'.format(
                    inds_mask.shape, inds.shape))

            for rxi, rx in enumerate(rxs):
                pos_rel_rx = (ecef.T - rx.ecef).T

                for I in inds_tmp:
                    k_obj_rx = coord.ecef2local(
                        lat=rx.lat,
                        lon=rx.lon,
                        alt=rx.alt,
                        x=pos_rel_rx[0, I],
                        y=pos_rel_rx[1, I],
                        z=pos_rel_rx[2, I],
                    )

                    ksr_obj[:, I, rxi] = k_obj_rx

                    elevation_angle_rx = 90.0 - coord.angle_deg(
                        zenith, k_obj_rx)
                    if elevation_angle_rx < rx.el_thresh:
                        continue

                    zenith_mask[I, rxi] = True

                    rx_dist = n.linalg.norm(pos_rel_rx[:, I])
                    rx_vel = n.dot(vels[:, I], pos_rel_rx[:, I] / rx_dist)

                    r_rad[I, rxi] = rx_dist
                    v_rad[I, rxi] = rx_vel

            for I in inds:
                if n.any(zenith_mask[I, :]):
                    tx.beam.point_k0(k0s[:, I])
                    range_tx[I] = n.linalg.norm(pos_rel_tx[:, I])
                    vel_tx[I] = n.dot(vels[:, I],
                                      pos_rel_tx[:, I] / range_tx[I])
                    gain_tx[I] = tx.beam.gain(ks_obj[:, I])

            for rxi, rx in enumerate(rxs):
                if logger is not None:
                    logger.debug('f2_rx{} inds left {}/{}'.format(
                        rxi, inds.shape, inds[zenith_mask[:, rxi]].shape))

                for I in inds[zenith_mask[:, rxi]]:

                    # TODO: We need to change this
                    # Probably we need to define additional parameters in the RadarSystem class that defines the constraints on each receiver transmitter, and defines if any of them are at the same location.
                    # what we need to do is give the RX a scan also that describes the pointing for detections when there is no after the fact beam-steering to do grid searches
                    #
                    if rx.phased:
                        # point receiver towards object (post event beam forming)
                        rx.beam.point_k0(ksr_obj[:, I, rxi])
                    else:
                        #point according to receive pointing
                        k0 = rx.get_scan(t_pass[I]).local_pointing(t_pass[I])
                        rx.beam.point_k0(k0)

                    gain_rx[I, rxi] = rx.beam.gain(ksr_obj[:, I, rxi])

                    snr = debris.hard_target_enr(
                        gain_tx[I],
                        gain_rx[I, rxi],
                        rx.wavelength,
                        tx.tx_power,
                        range_tx[I],
                        r_rad[I, rxi],
                        diameter_m=obj.d,
                        bandwidth=tx.coh_int_bandwidth,
                        rx_noise_temp=rx.rx_noise,
                    )

                    #if logger is not None:
                    #    logger.debug('angles[{}] {} deg, gain_tx[{}] = {}, gain_rx[{}, {}] = {}'.format(
                    #        I, angles[I],
                    #        I, gain_tx[I],
                    #        I, rxi, gain_rx[I, rxi],
                    #    ))

                    snrs[I, rxi] = snr

                    if snr < tx.enr_thresh:
                        continue

                    snrs_mask[I, rxi] = True

            for I in inds:
                if n.any(snrs_mask[I, :]):
                    inst_snrs = snrs[I, snrs_mask[I, :]]
                    if 10.0 * n.log10(n.max(inst_snrs)) > radar.min_SNRdb:
                        if logger is not None:
                            logger.debug(
                                'adding detection at {} sec with {} SNR'.
                                format(t_pass[I], snrs[I, :]))

                        detections[txi]["t0"].append(pas[0])
                        detections[txi]["t1"].append(pas[1])
                        detections[txi]["snr"].append(snrs[I, :])
                        detections[txi]["range"].append(r_rad[I, :] +
                                                        range_tx[I])
                        detections[txi]["range_rate"].append(v_rad[I, :] +
                                                             vel_tx[I])
                        detections[txi]["tx_gain"].append(gain_tx[I])
                        detections[txi]["rx_gain"].append(gain_rx[I, :])
                        detections[txi]["tm"].append(t_pass[I])
                        detections[txi]["on_axis_angle"].append(angles[I])

    return detections
Esempio n. 11
0
def plot_scan_for_object(obj, radar, t0, t1, plot_full_scan=False):

    # list of transmitters
    txs = radar._tx
    # list of receivers
    rxs = radar._rx

    num_t = simulate_tracking.find_linspace_num(t0,
                                                t1,
                                                obj.a * 1e3,
                                                obj.e,
                                                max_dpos=10e3)

    # time vector
    t = n.linspace(t0, t1, num=num_t, dtype=n.float)

    passes, _, _, _, _ = simulate_tracking.find_pass_interval(t, obj, radar)
    #format: passes
    # [tx num][pass num][0 = above, 1 = below]

    fig = plt.figure(figsize=(15, 15))
    ax = fig.add_subplot(111, projection='3d')
    ax.grid(False)
    ax.view_init(15, 5)
    plothelp.draw_earth_grid(ax)
    plot_radar_earth(ax, radar)

    scan_range = 1200e3

    lab_done = False
    lab_done_so = False
    cycle_complete = False

    for txi, tx in enumerate(txs):

        for pas in passes[txi]:
            num_pass = int((pas[1] - pas[0]) / tx.scan.min_dwell_time)
            t_pass = n.linspace(pas[0], pas[1], num=num_pass, dtype=n.float)

            ecefs = obj.get_orbit(t_pass)

            if lab_done_so:
                ax.plot(ecefs[0, :], ecefs[1, :], ecefs[2, :], '-k')
            else:
                lab_done_so = True
                ax.plot(ecefs[0, :],
                        ecefs[1, :],
                        ecefs[2, :],
                        '-k',
                        label='Space Object')

            for I in range(num_pass):
                scan = tx.get_scan(t_pass[I])
                if scan._scan_time is not None:
                    if t_pass[I] - pas[0] > scan._scan_time:
                        cycle_complete = True

                txp0, k0 = scan.antenna_pointing(t_pass[I])

                if not plot_full_scan:
                    if cycle_complete:
                        continue

                if lab_done:
                    ax.plot(
                        [txp0[0], txp0[0] + k0[0] * scan_range],
                        [txp0[1], txp0[1] + k0[1] * scan_range],
                        [txp0[2], txp0[2] + k0[2] * scan_range],
                        '-g',
                        alpha=0.2,
                    )
                else:
                    ax.plot(
                        [txp0[0], txp0[0] + k0[0] * scan_range],
                        [txp0[1], txp0[1] + k0[1] * scan_range],
                        [txp0[2], txp0[2] + k0[2] * scan_range],
                        '-g',
                        alpha=0.01,
                        label='Scan',
                    )
                    lab_done = True

    max_range = 1500e3

    ax.set_xlim(txs[0].ecef[0] - max_range, txs[0].ecef[0] + max_range)
    ax.set_ylim(txs[0].ecef[1] - max_range, txs[0].ecef[1] + max_range)
    ax.set_zlim(txs[0].ecef[2] - max_range, txs[0].ecef[2] + max_range)
    plt.legend()
    plt.show()