def snr_func(rang): snrs = [] for txi, tx in enumerate(radar._tx): for rxi, rx in enumerate(radar._rx): snr_tmp = debris.hard_target_enr( tx.beam.I_0, tx.beam.I_0, rx.wavelength, tx.tx_power, rang, rang, diameter_m = d, bandwidth = tx.coh_int_bandwidth, rx_noise_temp = rx.rx_noise, ) snrs.append(snr_tmp) return np.max(np.array(snrs))
def get_passes_simple(o,radar,t0,t1,max_dpos=100e3,debug=False, sanity_check=False): '''Follow object and find peak SNR. Assume that this occurs for minimum zenith angle of each TX. :param SpaceObject o: The object in space to be followed. :param RadarSystem radar: The radar system used for tracking. :param float t0: Start time for tracking :param float t1: End time for tracking :param float max_dpos: Maximum separation in m between orbital evaluation points, used to calculate time-step size by approximating orbits as circles :param bool debug: Verbose output :param bool sanity_check: Even more verbose output :return: Tuple of (Peak SNR for tracking, Number of receivers that can observe, time of best detection) ''' # figure out the number of time points we need to evaluate to meet the max_dpos criteria num_t = simulate_tracking.find_linspace_num(t0, t1, o.a*1e3, o.e, max_dpos=max_dpos) # time vector t=n.linspace(t0,t1,num=num_t) dt = (t1-t0)/num_t # propagate object for all time points requested ecef=o.get_orbit(t) # zenith angles zenith = [] # tx and rx site locations in ecef tx_ecef = [] rx_ecef = [] # zenith directions for each tx and rx site zenith_tx = [] zenith_tx = [] for tx in radar._tx: tx_ecef.append( tx.ecef ) zenith_tx.append( coord.azel_ecef(tx.lat, tx.lon, 0.0, 0.0, 90.0) ) zenith_rx = [] for rx in radar._rx: rx_ecef.append( rx.ecef ) zenith_rx.append( coord.azel_ecef(rx.lat, rx.lon, 0.0, 0.0, 90.0) ) # position vectors between tx and rx pos_rx = [] for rxp0 in rx_ecef: pos_vec=(ecef.T-rxp0).T pos_rx.append(pos_vec) n_tx=len(radar._tx) n_rx=len(radar._rx) # peak snr for tx->rx combo peak_snr=n.zeros([n_tx,n_rx]) # number of receivers that can observe TX n_rx_detections=n.zeros(n_tx) # for each transmitter for txi,txp0 in enumerate(tx_ecef): # tx tx = radar._tx[txi] # zenith direction vector for this TX zenith = zenith_tx[txi] # position vector pos_tx=(ecef.T-txp0).T # unit vector for tx->target position vector pos_tx0=pos_tx/n.sqrt(pos_tx[0,:]**2.0+pos_tx[1,:]**2.0+pos_tx[2,:]**2.0) # zenith -> target angle z_angles_tx=180.0*n.arccos(pos_tx0[0,:]*zenith[0]+pos_tx0[1,:]*zenith[1]+pos_tx0[2,:]*zenith[2])/n.pi # peak elevation angle min_z=n.min(z_angles_tx) det_idx=n.argmin(z_angles_tx) if min_z < (90.0-radar._tx[txi].el_thresh): # object possibly detectable pos_vec=pos_rx[txi][:,det_idx] tx_dist=n.linalg.norm(pos_vec) # point tx antenna towards target k0 = tx.point_ecef(pos_vec) gain_tx = tx.beam.gain(k0) # for all receivers for rxi,rx in enumerate(radar._rx): # position vector pos_rx_now=pos_rx[rxi][:,det_idx] # distance rx_dist=n.linalg.norm(pos_rx_now) # unit vector pos_rx_now0=pos_rx_now/rx_dist if sanity_check: pos = radar._rx[rxi].ecef + pos_rx_now0*rx_dist print("diff %d"%(rxi)) print((ecef[:,det_idx] - pos)) zenith = zenith_rx[rxi] # rx zenith -> target angle z_angle_rx=180.0*n.arccos(pos_rx_now0[0]*zenith[0]+pos_rx_now0[1]*zenith[1]+pos_rx_now0[2]*zenith[2])/n.pi # point towards object k0 = rx.point_ecef(pos_rx_now) gain_rx = rx.beam.gain(k0) snr=debris.hard_target_enr(gain_tx, gain_rx, rx.wavelength, tx.tx_power, tx_dist, rx_dist, diameter_m=o.diam, bandwidth=tx.coh_int_bandwidth, rx_noise_temp=rx.rx_noise) peak_snr[txi,rxi]=snr if snr >= tx.enr_thresh: n_rx_detections[txi]+=1.0 print("oid %d inc %1.2f diam %1.2f tx %d rx %d snr %1.2g min_range %1.2f (km) tx_dist %1.2f (km) rx_dist %1.2f (km) tx_zenith angle %1.2f rx zenith angle %1.2f"%(o.oid,o.i,o.diam,txi,rxi,snr,((1.0-o.e)*o.a)-6371.0,tx_dist/1e3,rx_dist/1e3,min_z,z_angle_rx)) else: print("oid {} not detected, SNR = {}".format(o.oid, snr)) return peak_snr, n_rx_detections, t[det_idx]
def create_tracklet(o, radar, t_obs, hdf5_out=True, ccsds_out=True, dname="./tracklets", noise=False, dx=10.0, dv=10.0, dt=0.01, ignore_elevation_thresh=False): '''Simulate tracks of objects. ionospheric limit is a lower limit on precision after ionospheric corrections ''' if noise: noise = 1.0 else: noise = 0.0 # TDB, kludge, this should be allowed to change as a function of time bw = radar._tx[0].tx_bandwidth txlen = radar._tx[0].pulse_length * 1e6 # pulse length in microseconds ipp = radar._tx[0].ipp # pulse length in microseconds n_ipp = int(radar._tx[0].n_ipp) # pulse length in microseconds rfun, dopfun = debris.precalculate_dr(txlen, bw, ipp=ipp, n_ipp=n_ipp) t0_unix = dpt.jd_to_unix(dpt.mjd_to_jd(o.mjd0)) if debug_low: for tx in radar._tx: print("TX %s" % (tx.name)) for rx in radar._tx: print("RX %s" % (rx.name)) rx_p = [] tx_p = [] for tx in radar._tx: tx_p.append(coord.geodetic2ecef(tx.lat, tx.lon, tx.alt)) for rxi, rx in enumerate(radar._rx): rx_p.append(coord.geodetic2ecef(rx.lat, rx.lon, rx.alt)) ecefs = o.get_orbit(t_obs) state = o.get_state(t_obs) ecefs_p_dt = o.get_orbit(t_obs + dt) ecefs_m_dt = o.get_orbit(t_obs - dt) # velocity in ecef ecef_vel = (0.5 * ((ecefs_p_dt - ecefs) + (ecefs - ecefs_m_dt)) / dt) # linearized error estimates for ecef state vector error std_dev, when three or more # delays and doppl er shifts are measured ecef_stdevs = [] meas = [] for tx in radar._tx: ecef_stdevs.append({"time_idx": [], "m_time": [], "ecef_stdev": []}) for tx in radar._tx: m_rx = [] for rx in radar._rx: m_rx.append({ "time_idx": [], "m_time": [], "m_delay": [], "m_delay_std": [], "m_range": [], "m_range_std": [], "m_range_rate": [], "m_range_rate_std": [], "m_doppler": [], "m_doppler_std": [], "gain_tx": [], "gain_rx": [], "enr": [], "true_state": [], "true_time": [], "g_lat": [], "g_lon": [] }) meas.append(m_rx) # largest possible number of state vector measurements n_state_meas = len(radar._tx) * len(radar._rx) # jacobian for error covariance calc J = n.zeros([2 * n_state_meas, 6]) Sigma_Lin = n.zeros([2 * n_state_meas, 2 * n_state_meas]) # error standard deviation for state vector estimates at each position state_vector_errors = n.zeros([6, len(t_obs)]) # go through all times for ti, t in enumerate(t_obs): p = n.array([ecefs[0, ti], ecefs[1, ti], ecefs[2, ti]]) p_p = n.array( [ecefs_p_dt[0, ti], ecefs_p_dt[1, ti], ecefs_p_dt[2, ti]]) p_m = n.array( [ecefs_m_dt[0, ti], ecefs_m_dt[1, ti], ecefs_m_dt[2, ti]]) # for linearized state vector error determination p_dx0 = n.array([ecefs[0, ti] + dx, ecefs[1, ti], ecefs[2, ti]]) p_dx1 = n.array([ecefs[0, ti], ecefs[1, ti] + dx, ecefs[2, ti]]) p_dx2 = n.array([ecefs[0, ti], ecefs[1, ti], ecefs[2, ti] + dx]) # doppler error comes from linear least squares # initialize jacobian J[:, :] = 0.0 Sigma_Lin[:, :] = 0.0 state_meas_idx = 0 # go through all transmitters for txi, tx in enumerate(radar._tx): pos_vec_tx = -tx_p[txi] + p pos_vec_tx_p = -tx_p[txi] + p_p pos_vec_tx_m = -tx_p[txi] + p_m # for linearized errors pos_vec_tx_dx0 = -tx_p[txi] + p_dx0 pos_vec_tx_dx1 = -tx_p[txi] + p_dx1 pos_vec_tx_dx2 = -tx_p[txi] + p_dx2 # incident k-vector k_inc = -2.0 * n.pi * pos_vec_tx / n.linalg.norm( pos_vec_tx) / tx.wavelength elevation_tx = 90.0 - coord.angle_deg(tx_p[txi], pos_vec_tx) if elevation_tx > tx.el_thresh or ignore_elevation_thresh: k0 = tx.point_ecef( pos_vec_tx) # we are pointing at the object when tracking gain_tx = tx.beam.gain(k0) # get antenna gain range_tx = n.linalg.norm(pos_vec_tx) range_tx_p = n.linalg.norm(pos_vec_tx_p) range_tx_m = n.linalg.norm(pos_vec_tx_m) range_tx_dx0 = n.linalg.norm(pos_vec_tx_dx0) range_tx_dx1 = n.linalg.norm(pos_vec_tx_dx1) range_tx_dx2 = n.linalg.norm(pos_vec_tx_dx2) tx_to_target_time = range_tx / c.c # go through all receivers for rxi, rx in enumerate(radar._rx): pos_vec_rx = -rx_p[rxi] + p pos_vec_rx_p = -rx_p[rxi] + p_p pos_vec_rx_m = -rx_p[rxi] + p_m # rx k-vector k_rec = 2.0 * n.pi * pos_vec_rx / n.linalg.norm( pos_vec_rx) / tx.wavelength # scattered k-vector k_scat = k_rec - k_inc # for linearized pos error pos_vec_rx_dx0 = -rx_p[rxi] + p_dx0 pos_vec_rx_dx1 = -rx_p[rxi] + p_dx1 pos_vec_rx_dx2 = -rx_p[rxi] + p_dx2 elevation_rx = 90.0 - coord.angle_deg( rx_p[rxi], pos_vec_rx) if elevation_rx > rx.el_thresh or ignore_elevation_thresh: k0 = rx.point_ecef( pos_vec_rx ) # we are pointing at the object when tracking gain_rx = rx.beam.gain(k0) # get antenna gain range_rx = n.linalg.norm(pos_vec_rx) range_rx_p = n.linalg.norm(pos_vec_rx_p) range_rx_m = n.linalg.norm(pos_vec_rx_m) range_rx_dx0 = n.linalg.norm(pos_vec_rx_dx0) range_rx_dx1 = n.linalg.norm(pos_vec_rx_dx1) range_rx_dx2 = n.linalg.norm(pos_vec_rx_dx2) target_to_rx_time = range_rx / c.c # SNR of object at measured location enr_rx = debris.hard_target_enr( gain_tx, gain_rx, tx.wavelength, tx.tx_power, range_tx, range_rx, o.diam, bandwidth=tx. coh_int_bandwidth, # coherent integration bw rx_noise_temp=rx.rx_noise) if enr_rx > 1e8: enr_rx = 1e8 if enr_rx < 0.1: enr_rx = 0.1 #print("snr %1.2f"%(enr_rx)) dr = 10.0**(rfun(n.log10(enr_rx))) ddop = 10.0**(dopfun(n.log10(enr_rx))) # Unknown doppler shift due to ionosphere can be up to 0.1 Hz, # estimate based on typical GNU Ionospheric tomography receiver phase curves. if ddop < 0.1: ddop = 0.1 dr = n.sqrt(dr**2.0 + iono_errfun(range_tx / 1e3)** 2.0) # add ionospheric error if dr < o.diam: # if object diameter is larger than range error, make it at least as big as target dr = o.diam r0 = range_tx + range_rx rp = range_tx_p + range_rx_p rm = range_tx_m + range_rx_m range_rate_d = 0.5 * ( (rp - r0) + (r0 - rm)) / dt # symmetric numerical derivative # doppler (m/s) using scattering k-vector range_rate = n.dot( pos_vec_rx / range_rx, state[3:6, ti]) + n.dot( pos_vec_tx / range_tx, state[3:6, ti]) doppler = range_rate / tx.wavelength # print("rr1 %1.1f rr2 %1.1f"%(range_rate_d,range_rate)) doppler_k = n.dot(k_scat, ecef_vel[:, ti]) / 2.0 / n.pi range_rate_k = doppler_k * tx.wavelength # for linearized errors, range rate at small perturbations to state vector velocity parameters range_rate_k_dv0 = tx.wavelength * n.dot( k_scat, ecef_vel[:, ti] + n.array([dv, 0, 0])) / 2.0 / n.pi range_rate_k_dv1 = tx.wavelength * n.dot( k_scat, ecef_vel[:, ti] + n.array([0, dv, 0])) / 2.0 / n.pi range_rate_k_dv2 = tx.wavelength * n.dot( k_scat, ecef_vel[:, ti] + n.array([0, 0, dv])) / 2.0 / n.pi # full range for error calculation, with small perturbations to position state full_range_dx0 = range_rx_dx0 + range_tx_dx0 full_range_dx1 = range_rx_dx1 + range_tx_dx1 full_range_dx2 = range_rx_dx2 + range_tx_dx2 if enr_rx > tx.enr_thresh: # calculate jacobian row for state vector errors # range J[2 * state_meas_idx, 0:3] = n.array([(full_range_dx0 - r0) / dx, (full_range_dx1 - r0) / dx, (full_range_dx2 - r0) / dx]) # range inverse variance Sigma_Lin[2 * state_meas_idx, 2 * state_meas_idx] = 1.0 / dr**2.0 # range-rate J[2 * state_meas_idx + 1, 3:6] = n.array([ (range_rate_k_dv0 - range_rate_k) / dv, (range_rate_k_dv1 - range_rate_k) / dv, (range_rate_k_dv2 - range_rate_k) / dv ]) # range-rate inverse variance Sigma_Lin[2 * state_meas_idx + 1, 2 * state_meas_idx + 1] = 1.0 / (tx.wavelength * ddop)**2.0 state_meas_idx += 1 # detection! if debug_low: print( "rx %d tx el %1.2f rx el %1.2f gain_tx %1.2f gain_rx %1.2f enr %1.2f rr %1.2f prop time %1.6f dr %1.2f" % (rxi, elevation_tx, elevation_rx, gain_tx, gain_rx, enr_rx, range_rate, tx_to_target_time, dr)) # ground foot point in geodetic llh = coord.ecef2geodetic(p[0], p[1], p[2]) # time is time of transmit pulse meas[txi][rxi]["time_idx"].append(ti) meas[txi][rxi]["m_time"].append(t + t0_unix) meas[txi][rxi]["m_range"].append( (range_tx + range_rx) / 1e3 + noise * n.random.randn() * dr / 1e3) meas[txi][rxi]["m_range_std"].append(dr / 1e3) rr_std = c.c * ddop / radar._tx[ txi].freq / 2.0 / 1e3 meas[txi][rxi]["m_range_rate"].append( range_rate / 1e3 + noise * n.random.randn() * rr_std) # 0.1 m/s error due to ionosphere meas[txi][rxi]["m_range_rate_std"].append(rr_std) meas[txi][rxi]["m_doppler"].append( doppler + noise * n.random.randn() * ddop / 1e3) meas[txi][rxi]["m_doppler_std"].append(ddop) meas[txi][rxi]["m_delay"].append( tx_to_target_time + target_to_rx_time) meas[txi][rxi]["g_lat"].append(llh[0]) meas[txi][rxi]["g_lon"].append(llh[1]) meas[txi][rxi]["enr"].append(enr_rx) meas[txi][rxi]["gain_tx"].append(gain_tx) meas[txi][rxi]["gain_rx"].append(gain_rx) true_state = n.zeros(6) true_state[3:6] = (0.5 * ((p_p - p) + (p - p_m)) / dt) / 1e3 true_state[0:3] = p / 1e3 meas[txi][rxi]["true_state"].append(true_state) meas[txi][rxi]["true_time"].append(t_obs[ti] + t0_unix) else: if debug_high: print("not detected: enr_rx {}".format(enr_rx)) else: if debug_high: print("not detected: elevation_rx {}".format( elevation_rx)) else: if debug_high: print("not detected: elevation_tx {}".format(elevation_tx)) # if more than three measurements of range and range-rate, then we maybe able to # observe true state. if so, calculate the linearized covariance matrix if state_meas_idx > 2: # use only the number of measurements that were good JJ = J[0:(2 * state_meas_idx), :] try: Sigma_post = n.linalg.inv( n.dot(n.dot(n.transpose(JJ), Sigma_Lin), JJ)) ecef_stdevs[txi]["time_idx"].append(ti) ecef_stdevs[txi]["m_time"].append(t) ecef_stdevs[txi]["ecef_stdev"].append(Sigma_post) except: print("Singular posterior covariance...") if debug_low: print(meas) fnames = write_tracklets(o, meas, radar, dname, hdf5_out=hdf5_out, ccsds_out=ccsds_out) return (meas, fnames, ecef_stdevs)
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
def get_passes(o, radar, t0, t1, max_dpos=1e3, logger=None, plot=False, t_samp=None): '''Follow object and determine possible maintenance track window. I.e. get all passes of the object inside the radar system FOV. :param SpaceObject o: Space object to find passes for. :param RadarSystem radar: Radar system that defines the FOV. :param float t0: Start time for passes search in seconds relative space object epoch. :param float t1: Stop time for passes search in seconds relative space object epoch. :param float max_dpos: Maximum separation in km between orbital evaluation points. :param Logger logger: Logger object for logging the execution of the function. :param float t_samp: If not None, overrides the "max_dpos" variable and fixes a time-sampling. :return: Dictionary containing information about all passes of the space object inside the radar system FOV. :rtype: dict **Output dictionary:** * t: Three layers of lists where first layer is a list corresponding to every RX antenna of the radar system. Second layer is the a entry in the list for every pass. Last layer of lists is a list of two elements where the first is the time in seconds when object enters the FOV and second is the time in seconds when the object leaves the FOV. I.e. :code:`pass_start_time = passes["t"][tx_index][pass_index][0]` and :code:`pass_end_time = passes["t"][tx_index][pass_index][1]`. * snr: This structure has the same format as the "t" item but with an extra layer of lists of receivers before the bottom. Then instead of the bottom layer of lists being start and stop times it records the peak SNR at the first item and the time of that peak SNR in the second item. I.e. :code:`pass_peak_snr = passes["snr"][tx_index][pass_index][rx_index][0]` and :code:`pass_peak_snr_time = passes["snr"][tx_index][pass_index][rx_index][1]`. ''' pass_struct = {"t": [], "snr": []} if t_samp is None: num_t = find_linspace_num(t0, t1, o.a * 1e3, o.e, max_dpos=max_dpos) t = n.linspace(t0, t1, num=num_t, dtype=n.float64) else: t = n.arange(t0, t1, t_samp, dtype=n.float64) num_t = len(t) if logger is not None: logger.debug("n_points %d %1.2f" % (num_t, max_dpos)) # time vector if logger is not None: date0_y, date0_m, date0_d = dpt.jd_to_date(dpt.mjd_to_jd(o.mjd0)) logger.debug( '--> Getting {} orbit location between: {:.5f} h and {:.5f} h relative {}-{}-{}' .format( num_t, t[0] / (3600), t[-1] / (3600), date0_y, date0_m, date0_d, )) passes, passes_id, idx_v, postx_v, posrx_v = find_pass_interval( t, o, radar, logger=logger) if logger is not None: logger.debug("passes:\n {}".format(passes)) tx_dets = 0 for idx in idx_v: if len(idx) > 0: tx_dets += 1 if tx_dets == 0: if logger is not None: logger.debug("no passes visible from any RX station") return pass_struct if logger is not None: logger.debug("--> List of passes constructed") logger.debug("{}".format(passes)) snrs = [None] * len(radar._tx) for txi, idx in enumerate(idx_v): if len(idx) > 0: snrs[txi] = [None] * len(passes[txi]) tx = radar._tx[txi] for pid, pass_ids in enumerate(passes_id[txi]): idx_p = idx[pass_ids[0]:pass_ids[1]] if logger is not None: logger.debug("{}".format(idx_p)) logger.debug("{}".format(pass_ids)) snrs[txi][pid] = [None] * len(radar._rx) rx_dets = 0 for rxi, rx in enumerate(radar._rx): snr_curve = [] for I in idx_p: tx_dist = n.linalg.norm(postx_v[txi][:, I]) k0 = coord.ecef2local( lat=tx.lat, lon=tx.lon, alt=tx.alt, x=postx_v[txi][0, I], y=postx_v[txi][1, I], z=postx_v[txi][2, I], ) tx.beam.point_k0(k0) gain_tx = tx.beam.gain(k0) rx_dist = n.linalg.norm(posrx_v[rxi][:, I]) # point towards object k0 = coord.ecef2local( lat=rx.lat, lon=rx.lon, alt=rx.alt, x=posrx_v[txi][0, I], y=posrx_v[txi][1, I], z=posrx_v[txi][2, I], ) rx.beam.point_k0(k0) gain_rx = rx.beam.gain(k0) snr = debris.hard_target_enr( gain_tx, gain_rx, rx.wavelength, tx.tx_power, tx_dist, rx_dist, diameter_m=o.d, bandwidth=tx.coh_int_bandwidth, rx_noise_temp=rx.rx_noise) if logger is not None: logger.debug( '\n--> TX-d: %.2f km | TX-g: %.2f dB' % (tx_dist * 1e-3, 10.0 * n.log10(gain_tx))) logger.debug( '--> RX-d: %.2f km | RX-g: %.2f dB' % (rx_dist * 1e-3, 10.0 * n.log10(gain_rx))) logger.debug('--> SNR: %.2f dB ' % (10.0 * n.log10(snr))) snr_curve.append(snr) snr_curve = n.array(snr_curve) if plot: snr_curve_dB = 10.0 * n.log10(snr_curve) snr_curve_dB[snr_curve_dB < 0] = 0 plt.plot(t[idx_p], snr_curve_dB) plt.plot(t[idx_p[n.argmax(snr_curve)]], n.max(snr_curve_dB), 'or') plt.title("tx %i, pass %i, rx %i" % (txi, pid, rxi)) plt.show() print('SNR max: %.2f @ %.2f h' % (n.max(snr_curve_dB), t[idx_p[n.argmax(snr_curve)]] / 3600.0)) if len(snr_curve) > 0: snr_max = n.max(snr_curve) else: snr_max = 0.0 if snr_max >= tx.enr_thresh: rx_dets += 1 snrs[txi][pid][rxi] = [ snr_max, t[idx_p[n.argmax(snr_curve)]] ] else: snrs[txi][pid][rxi] = [0, 0] if rx_dets == 0: snrs[txi][pid] = None if plot: fig = plt.figure(figsize=(15, 15)) ax = fig.add_subplot(111, projection='3d') plothelp.draw_earth_grid(ax) ax.plot(ecef[0, :], ecef[1, :], ecef[2, :], alpha=1, color="black") for I in idx_p: ax.plot([tx.ecef[0], tx.ecef[0] + postx_v[txi][0, I]], [tx.ecef[1], tx.ecef[1] + postx_v[txi][1, I]], [tx.ecef[2], tx.ecef[2] + postx_v[txi][2, I]], alpha=0.5, color="red") for rxi, rx in enumerate(radar._rx): ax.plot( [rx.ecef[0], rx.ecef[0] + posrx_v[rxi][0, I]], [rx.ecef[1], rx.ecef[1] + posrx_v[rxi][1, I]], [rx.ecef[2], rx.ecef[2] + posrx_v[rxi][2, I]], alpha=0.5, color="red") delta = 1000e3 ax.set_xlim([tx.ecef[0] - delta, tx.ecef[0] + delta]) ax.set_ylim([tx.ecef[1] - delta, tx.ecef[1] + delta]) ax.set_zlim([tx.ecef[2] - delta, tx.ecef[2] + delta]) plt.show() passes[txi] = [ x for ix, x in enumerate(passes[txi]) if snrs[txi][ix] is not None ] #remove tracks that were not above detection tresholds at any pair snrs[txi] = [ x for x in snrs[txi] if x is not None ] #remove tracks that were not above detection tresholds at any pair for txi, tx_snr in enumerate(snrs): if tx_snr is None: snrs[txi] = [] for txi, tx_pass in enumerate(passes): if tx_pass is None: passes[txi] = [] pass_struct['snr'] = snrs pass_struct['t'] = passes return pass_struct
def get_track_snr(t, o, radar): '''Takes a series of times, a space object and a radar system and calculates the SNR for that space object measured by that radar over the given times. :param numpy.ndarray t: Times in seconds relative space object epoch over witch SNR should be evaluated. :param SpaceObject o: Space object to be measured. :param RadarSystem radar: Radar system that performs the measurement. :return: List of lists of numpy.ndarray's corresponding to TX antenna index, RX antenna index and SNR-array in that order of list depth. ''' ecef = o.get_orbit(t) tx_ecef = [] rx_ecef = [] for tx in radar._tx: tx_ecef.append(tx.ecef) for rx in radar._rx: rx_ecef.append(rx.ecef) postx_v = [] posrx_v = [] for rxp0 in rx_ecef: pos_vecs = (ecef.T - rxp0).T posrx_v.append(pos_vecs) for txi, txp0 in enumerate(tx_ecef): pos_vecs = (ecef.T - txp0).T postx_v.append(pos_vecs) snrs = [None] * len(radar._tx) for txi, tx in enumerate(radar._tx): snrs[txi] = [None] * len(radar._rx) for rxi, rx in enumerate(radar._rx): snr_curve = [] for I in range(len(t)): tx_dist = n.linalg.norm(postx_v[txi][:, I]) k0 = coord.ecef2local( lat=tx.lat, lon=tx.lon, alt=tx.alt, x=postx_v[txi][0, I], y=postx_v[txi][1, I], z=postx_v[txi][2, I], ) tx.beam.point_k0(k0) gain_tx = tx.beam.gain(k0) rx_dist = n.linalg.norm(posrx_v[rxi][:, I]) # point towards object k0 = coord.ecef2local( lat=rx.lat, lon=rx.lon, alt=rx.alt, x=posrx_v[txi][0, I], y=posrx_v[txi][1, I], z=posrx_v[txi][2, I], ) rx.beam.point_k0(k0) gain_rx = rx.beam.gain(k0) snr = debris.hard_target_enr(gain_tx, gain_rx, rx.wavelength, tx.tx_power, tx_dist, rx_dist, diameter_m=o.d, bandwidth=tx.coh_int_bandwidth, rx_noise_temp=rx.rx_noise) snr_curve.append(snr) snr_curve = n.array(snr_curve) snrs[txi][rxi] = snr_curve return snrs