def main(): # Verification 1 #file_root_name = 'raw/L1B/2015-02-11-H18' #group = '000139' #index = 839 # Verification 2 file_root_name = 'raw/L1B/2015-02-11-H18' group = '000139' index = 592 tds = tds_data(file_root_name) tds.set_group_index(group, index) tds.plot_ddm() datenum = tds.metagrp.groups[tds.group].variables['IntegrationMidPointTime'][tds.index] lat = tds.metagrp.groups[tds.group].variables['SpecularPointLat'][tds.index] lon = tds.metagrp.groups[tds.group].variables['SpecularPointLon'][tds.index] string = 'G: ' + group + ' I: ' + str(index) + ' - ' + \ str(datenum_to_pytime(float(datenum))) + \ ' - Lat: ' + str(lat) + ' Lon: ' + str(lon) + '\n' print(string) plt.show(block=False) plt.show()
def cdf4_search(file_root_name, target, search_error): filename = os.path.join(os.environ['TDS_ROOT'], file_root_name + '-metadata.nc') print(filename) search_output = filename + '\n' tds = tds_data(file_root_name) group_len = len(tds.metagrp.groups) for group in tds.metagrp.groups: step = 10 index_len = len( tds.metagrp.groups[group].variables['IntegrationMidPointTime']) for index in range(0, index_len, step): print( str(group) + '/' + str(group_len) + ' : ' + str(index) + '/' + str(index_len)) tds.set_group_index(group, index) datenum = tds.metagrp.groups[group].variables[ 'IntegrationMidPointTime'][index] # 0.5 deg error approx 55 km error if (angle_between(tds.r_r, tds.r_t) <= search_error): string = 'G: ' + group + ' I: ' + str(index) + ' - ' + \ str(datenum) + ' - ' + str(datenum_to_pytime(float(datenum))) + ' - Lat: ' + \ str(tds.lat_sp_tds) + ' Lon: ' + str(tds.lon_sp_tds) + \ 'Angle (deg): ' + str(angle_between(tds.r_r, tds.r_t)*180/np.pi) + '\n' print(string) search_output = search_output + string return search_output
def main(): # Di Simone Oil Platform Data file_root_name = 'raw/L1B/2015-04-01-H00' target = targets['hibernia'] group = '000095' index = 525 tds = tds_data(file_root_name) p = target_processor(); for i in range(index - 200, index + 10): ddm = tds.rootgrp.groups[group].variables['DDM'][i].data p.process_ddm(ddm)
def main(): # Di Simone file_root_name = '2015-04-01-H00' target = targets['hibernia'] group = '000095' index = 525 # Hibernia # Really good detection #file_root_name = 'raw/L1B/2017-03-12-H18' #target = targets['hibernia'] #group = '000035' #index = 681 # Devils Tower #file_root_name = 'raw/L1B/2015-12-04-H18' #target = targets['devils_tower'] #group = '000066' #index = 376 #file_root_name = 'raw/L1B/2016-11-14-H06' #target = targets['petronius'] #group = '000057' #index = 0 # 0.5 deg error approx 55 km error if index == 0: search_error = 0.7 cdf4_search(file_root_name, target, search_error) target_delay_increment = 4 target_doppler_increment = 2000 tds = tds_data(file_root_name, group, index) tds.set_group_index(group, index) tds.plot_ddm() print("t vel: {}".format(np.linalg.norm(tds.v_t))) r_sp, lat_sp, lon_sp = tds.find_sp() n_z = unit_vector(ellip_norm(r_sp)) n_x = unit_vector(np.cross(n_z, r_sp - tds.r_t)) n_y = unit_vector(np.cross(n_z, n_x)) #TODO: imporve sp auto calculation h_r = np.dot((tds.r_r - r_sp), n_z) print("h_r: {}".format(h_r)) h_t = np.dot((tds.r_t - r_sp), n_z) print("h_t: {}".format(h_t)) elev = angle_between(n_y, tds.r_t - r_sp) print("elev: {}".format(elev)) print("elev tds: {}".format(90 - tds.sp_incidence_tds)) print("elve: {0} elev: {1}".format( elev * 180 / np.pi, angle_between(-n_y, tds.r_r - r_sp) * 180 / np.pi)) print("h_r: {0} h_t: {1}".format(h_r, h_t)) def z_sp(x, y): R = np.linalg.norm(r_sp) print("r: {}".format(R)) return (R**2 - x**2 - y**2)**(1 / 2) - R light_speed = 299792458 # m/s def time_inc_eq(x, y): return (np.sqrt(x**2 + (y + h_r / np.tan(elev))**2 + h_r**2) - h_r / np.sin(elev) - y * np.cos(elev)) / light_speed def doppler_eq(x, y): # GPS L1 center frequency f_0 = 10.23e6 # Hz f_carrier = 154 * f_0 # 1575.42e6 Hz v_tx = np.dot(tds.v_t, n_x) v_ty = np.dot(tds.v_t, n_y) v_tz = np.dot(tds.v_t, n_z) v_rx = np.dot(tds.v_r, n_x) v_ry = np.dot(tds.v_r, n_y) v_rz = np.dot(tds.v_r, n_z) # With the very far way transmitter approximation: f_D_0 = f_carrier / light_speed * ( -v_ty * np.cos(elev) - v_tz * np.sin(elev) + (v_rx * x + v_ry * (y + h_r / np.tan(elev)) - v_rz * h_r) * (x**2 + (y + h_r / np.tan(elev))**2 + h_r**2)**(-0.1e1 / 0.2e1)) return f_D_0 def doppler_inc_eq(x, y): return doppler_eq(x, y) - doppler_eq(0, 0) extent = 200e3 extent_x0 = -extent extent_x1 = extent extent_y0 = -extent extent_y1 = extent linsapce_delta = 500 X, Y = np.meshgrid(np.linspace(extent_x0, extent_x1, linsapce_delta), np.linspace(extent_y0, extent_y1, linsapce_delta)) delay_chip = 1 / 1.023e6 # seconds Z_time_chip = time_inc_eq(X, Y) / delay_chip Z_doppler = doppler_inc_eq(X, Y) fig_surface, ax_surface = plt.subplots(1, figsize=(10, 4)) plt.xlabel('[km]') plt.ylabel('[km]') ticks_x = ticker.FuncFormatter(lambda x, pos: '{0:g}'.format(x / 1000)) ticks_y = ticker.FuncFormatter(lambda y, pos: '{0:g}'.format(y / 1000)) ax_surface.xaxis.set_major_formatter(ticks_x) ax_surface.yaxis.set_major_formatter(ticks_y) # Iso-Delay Contour ax_surface.set_title('Time Delay Contour') contour_delay = ax_surface.contour(X, Y, Z_time_chip, np.arange(0, 15, 0.5), cmap='viridis') fig_surface.colorbar(contour_delay, label='C/A chips') ax_surface.grid(c='k', ls='-', alpha=0.3) plt.show(block=False) # Iso-Doppler Contour ax_surface.set_title('Doppler Shift Contour') plt.xlabel('[km]') plt.ylabel('[km]') contour_doppler = ax_surface.contour(X, Y, Z_doppler, np.arange(-5000, 5000, 500), cmap='viridis') fig_surface.colorbar(contour_doppler, label='Hz') ax_surface.grid(c='k', ls='-', alpha=0.3) target_iso_delay = ax_surface.contour(X, Y, Z_time_chip, [target_delay_increment], colors='red', linewidths=2.5, linestyles='dashed', extent=(extent_x0, extent_x1, extent_y0, extent_y1)) target_iso_doppler = ax_surface.contour(X, Y, Z_doppler, [target_doppler_increment], colors='red', linewidths=2.5, linestyles='dashed', extent=(extent_x0, extent_x1, extent_y0, extent_y1)) # TDS specular point in local coordinates x_sp_tds = np.dot(n_x, (tds.r_sp_tds - r_sp)) y_sp_tds = np.dot(n_y, (tds.r_sp_tds - r_sp)) ax_surface.scatter(x_sp_tds, x_sp_tds, s=70, marker=(5, 2), zorder=4, color='green') # Target in ECEF coordinates target_lat = target.lat_deg * np.pi / 180 target_lon = target.lon_deg * np.pi / 180 r_target_x = np.linalg.norm(r_sp) * np.cos(target_lat) * np.cos(target_lon) r_target_y = np.linalg.norm(r_sp) * np.cos(target_lat) * np.sin(target_lon) r_target_z = np.linalg.norm(r_sp) * np.sin(target_lat) r_target = np.array([r_target_x, r_target_y, r_target_z]) # Target in local coordinates x_target = np.dot(n_x, (r_target - r_sp)) y_target = np.dot(n_y, (r_target - r_sp)) ax_surface.scatter(x_target, y_target, s=70, zorder=4, color='black') lon = np.arctan2(r_target[1], r_target[0]) * 180 / np.pi lat = np.arcsin(abs(r_target[2] / np.linalg.norm(r_target))) * 180 / np.pi print("lat target: {0} lon target: {1}".format(lat, lon)) # Intersection of target iso-delay and iso-doppler intersections intersections = find_contour_intersection(target_iso_delay, target_iso_doppler) try: for i in intersections: ax_surface.scatter(i.x, i.y, s=70, zorder=4, color='orange') r_i = np.array([i.x, i.y]) r_target = np.array([x_target, y_target]) print("error: {0}".format(np.linalg.norm(r_target - r_i) / 1e3)) r_sol = r_sp + n_x * i.x + n_y * i.y lon = np.arctan2(r_sol[1], r_sol[0]) * 180 / np.pi lat = np.arcsin(abs( r_sol[2] / np.linalg.norm(r_sol))) * 180 / np.pi print("lat: {0} lon: {1}".format(lat, lon)) except TypeError as te: print('No intersections') n_z = unit_vector(ellip_norm(tds.r_sp_tds)) n_x = unit_vector(np.cross(n_z, tds.r_sp_tds - tds.r_t)) n_y = unit_vector(np.cross(n_z, n_x)) v_tx = np.dot(tds.v_t, n_x) v_ty = np.dot(tds.v_t, n_y) v_tz = np.dot(tds.v_t, n_z) v_rx = np.dot(tds.v_r, n_x) v_ry = np.dot(tds.v_r, n_y) v_rz = np.dot(tds.v_r, n_z) sim_config = simulation_configuration() sim_config.set_scenario_local_ref( h_r=np.dot((tds.r_r - tds.r_sp_tds), n_z), h_t=np.dot((tds.r_t - tds.r_sp_tds), n_z), elevation=angle_between(n_y, tds.r_t - tds.r_sp_tds), v_t=np.array([v_tx, v_ty, v_tz]), v_r=np.array([v_rx, v_ry, v_rz])) doppler_specular_point = eq_doppler_absolute_shift(np.array([0, 0, 0]), sim_config) delay = np.array([4 * delay_chip]) f_doppler = np.array([doppler_specular_point + 1800]) r_1, r_2 = spherical.delay_doppler_to_local_surface( delay, f_doppler, sim_config) print(r_1) print(r_2) ax_surface.scatter(r_1[0], r_1[1], s=70, zorder=4, color='blue') ax_surface.scatter(r_2[0], r_2[1], s=70, zorder=4, color='blue') plt.show(block=False) plt.show()
def main(): sim_config = simulation_configuration() sim_config.jacobian_type = 'spherical' delay_chip = sim_config.delay_chip # Decent noise results file_root_name = '2017-03-12-H18' target = targets['hibernia'] group = '000035' index = 675 - 15 tds = tds_data(file_root_name, group, index) mean_wind = tds.get_wind() p = target_processor_power() n = 1 p.n = n for i in range(index - n, index + 2): tds.set_group_index(group, i) ddm_i = normalize(tds.rootgrp.groups[group].variables['DDM'] [i].data) * tds.peak_power() p.process_ddm(ddm_i) wind = tds.get_wind() if (wind != None): print("wind: {0}".format(wind)) mean_wind += wind mean_wind /= 2 ddm_tds = np.copy(p.sea_clutter) print("mean wind: {0}".format(mean_wind)) sim_config.u_10 = 15 sim_config.phi_0 = -200 * np.pi / 180 # Plot TDS DDM sea clutter tds.set_group_index(group, index) r_sp, lat_sp, lon_sp = tds.find_sp() datenum = tds.rootgrp.groups[ tds.group].variables['IntegrationMidPointTime'][tds.index] string = str(datenum_to_pytime(float(datenum))) \ + ' Lat: ' + "{0:.2f}".format(tds.lat_sp_tds) \ + ' Lon: ' + "{0:.2f}".format(tds.lon_sp_tds) tds_number_of_delay_pixels = tds.metagrp.groups[ tds.group].NumberOfDelayPixels tds_number_of_doppler_pixels = tds.metagrp.groups[ tds.group].NumberOfDopplerPixels tds_delay_start = tds.calculate_delay_increment_chips(0) tds_delay_end = tds.calculate_delay_increment_chips( tds_number_of_delay_pixels - 1) tds_delay_resolution = (tds_delay_end - tds_delay_start) / 128 tds_doppler_start = tds.calculate_doppler_increment( -np.floor(tds_number_of_doppler_pixels / 2)) tds_doppler_end = tds.calculate_doppler_increment( np.floor(tds_number_of_doppler_pixels / 2 - 0.5)) tds_doppler_resolution = 500 fig_tds, ax_tds = plt.subplots(1, figsize=(10, 4)) plt.title('TDS-1 Experimental Data') plt.xlabel('C/A chips') plt.ylabel('Hz') contour_tds = ax_tds.imshow( ddm_tds, cmap='jet', extent=(tds_delay_start, tds_delay_end, tds_doppler_end, tds_doppler_start), aspect=(tds_number_of_doppler_pixels / tds_number_of_delay_pixels) / np.abs(tds_doppler_start / tds_delay_start)) t = plt.text(0.01, 0.85, string, { 'color': 'w', 'fontsize': 12 }, transform=ax_tds.transAxes) cbar = fig_tds.colorbar(contour_tds, label='Power') # Load TDS Geometry in simulation configuration n_z = unit_vector(ellip_norm(tds.r_sp_tds)) n_x = unit_vector(np.cross(n_z, tds.r_sp_tds - tds.r_t)) n_y = unit_vector(np.cross(n_z, n_x)) v_tx = np.dot(tds.v_t, n_x) v_ty = np.dot(tds.v_t, n_y) v_tz = np.dot(tds.v_t, n_z) v_rx = np.dot(tds.v_r, n_x) v_ry = np.dot(tds.v_r, n_y) v_rz = np.dot(tds.v_r, n_z) sim_config.set_scenario_local_ref( h_r=np.dot((tds.r_r - tds.r_sp_tds), n_z), h_t=np.dot((tds.r_t - tds.r_sp_tds), n_z), elevation=angle_between(n_y, tds.r_t - tds.r_sp_tds), v_t=np.array([v_tx, v_ty, v_tz]), v_r=np.array([v_rx, v_ry, v_rz])) # DDM sim_config.delay_increment_start = tds_delay_start * delay_chip sim_config.delay_increment_end = tds_delay_end * delay_chip sim_config.delay_resolution = ( sim_config.delay_increment_end - sim_config.delay_increment_start) / tds_number_of_delay_pixels / 3 sim_config.doppler_increment_start = tds_doppler_start sim_config.doppler_increment_end = tds_doppler_end + tds_doppler_resolution sim_config.doppler_resolution = ( sim_config.doppler_increment_end - sim_config.doppler_increment_start) / tds_number_of_doppler_pixels / 3 ddm_sim = (simulate_ddm(sim_config)) fig_ddm, ax_ddm = plt.subplots(1, figsize=(10, 4)) plt.title('DDM original simulation') plt.xlabel('C/A chips') plt.ylabel('Hz') contour_ddm = ax_ddm.imshow(ddm_sim, cmap='jet', extent=(sim_config.delay_increment_start, sim_config.delay_increment_end, sim_config.doppler_increment_end, sim_config.doppler_increment_start), aspect="auto") cbar = fig_ddm.colorbar(contour_ddm, label='Normalized Power') # Image downscaling to desired resolution: fig_ddm_rescaled, ax_ddm_rescaled = plt.subplots(1, figsize=(10, 4)) plt.title('Simulation Rescaled') plt.xlabel('C/A chips') plt.ylabel('Hz') ddm_rescaled = rescale(ddm_sim, tds_number_of_doppler_pixels, tds_number_of_delay_pixels) ddm_rescaled[0, :] = ddm_rescaled[2, :] ddm_rescaled[1, :] = ddm_rescaled[2, :] ddm_rescaled[:, 0] = ddm_rescaled[:, 2] ddm_rescaled[:, 1] = ddm_rescaled[:, 2] # Noise waf_delay_increment_values = list( np.arange( -tds_delay_end * delay_chip, tds_delay_end * delay_chip + tds_delay_resolution * delay_chip, tds_delay_resolution * delay_chip)) waf_doppler_increment_values = list( np.arange(tds_doppler_start, tds_doppler_end + tds_doppler_resolution, tds_doppler_resolution)) waf_delay_grid, waf_doppler_grid = np.meshgrid( waf_delay_increment_values, waf_doppler_increment_values) waf_matrix = woodward_ambiguity_function(waf_delay_grid, waf_doppler_grid, sim_config)**2 T_noise_receiver = 225 k_b = 1.38e-23 # J/K y_noise = 1 / sim_config.coherent_integration_time * k_b * T_noise_receiver p1 = target_processor_power() n = 500 p1.n = n p1.tau = 0.08 ddm_noise = np.zeros(ddm_rescaled.shape) for i in range(n + 1): print("i: {0}".format(i)) noise_i = y_noise * (np.random.rand(ddm_rescaled.shape[0], ddm_rescaled.shape[1])) ddm_noise_i = np.abs( signal.convolve2d(noise_i, waf_matrix, mode='same')) p1.process_ddm(np.abs(ddm_rescaled + ddm_noise_i)) ddm_rescaled = p1.sea_clutter contour_res = ax_ddm_rescaled.imshow( ddm_rescaled, cmap='jet', extent=(tds_delay_start, tds_delay_end, tds_doppler_end, tds_doppler_start), aspect=(tds_number_of_doppler_pixels / tds_number_of_delay_pixels) / np.abs(tds_doppler_start / tds_delay_start)) cbar = fig_ddm_rescaled.colorbar(contour_res, label='Normalized Power', shrink=0.35) fig_diff, ax_diff = plt.subplots(1, figsize=(10, 4)) plt.title('Difference') plt.xlabel('C/A chips') plt.ylabel('Hz') ddm_diff = np.copy(ddm_rescaled) for row_i, row in enumerate(ddm_diff): for col_i, val in enumerate(row): val_tds = ddm_tds[row_i, col_i] val = ddm_rescaled[row_i, col_i] ddm_diff[row_i, col_i] = np.abs((val - val_tds) / val_tds) #np.place(ddm_diff, ddm_diff < 0, np.nan) im = ax_diff.imshow( ddm_diff, cmap='jet', extent=(tds_delay_start, tds_delay_end, tds_doppler_end, tds_doppler_start), aspect=(tds_number_of_doppler_pixels / tds_number_of_delay_pixels) / np.abs(tds_doppler_start / tds_delay_start)) cbar = fig_diff.colorbar(im, label='Normalized Power', shrink=0.35) plt.show()
def main(): sim_config = simulation_configuration() sim_config.jacobian_type = 'spherical' delay_chip = sim_config.delay_chip file_root_name = '2015-12-04-H18' target = targets['devils_tower'] group = '000066' index = 385 - 10 tds = tds_data(file_root_name, group, index) #sim_config.receiver_antenna_gain = lambda p1,p2: 12 ''' p = target_processor_power(); p.n = n for i in range(index - n, index + 2): tds.set_group_index(group, i) ddm_i = normalize(tds.rootgrp.groups[group].variables['DDM'][i].data)*tds.peak_power() p.process_ddm(ddm_i) wind = tds.get_wind() if (wind != None): print("wind: {0}".format(wind)) mean_wind += wind mean_wind /= 2 ddm_tds = np.copy(p.sea_clutter) print("mean wind: {0}".format(mean_wind)) ''' sim_config.fresnel_coefficient = 0.8 n_tds = 20 n = n_tds ddm_tds = np.zeros( tds.rootgrp.groups[group].variables['DDM'][index].data.shape) mean_wind = 0 n_wind = 0 noise_antenna_mean = 0 noise_rx_mean = 0 for i in range(n): print("i: {0}".format(i)) tds.set_group_index(group, index + i) power_i, noise_i = tds.peak_power() ddm_i = normalize( tds.rootgrp.groups[group].variables['DDM'][index + i].data) * power_i print("noise power estimate: {0}".format(noise_i)) ddm_tds += ddm_i wind = tds.get_wind() noise_antenna_mean_i = tds.metagrp.groups[group].variables[ 'AntennaTemperature'][tds.index].data if (np.isnan(noise_antenna_mean_i)): noise_antenna_mean_i = tds.metagrp.groups[group].variables[ 'AntennaTemperatureExtRef'][tds.index].data if (np.isnan(noise_antenna_mean_i)): noise_antenna_mean_i = 225.7 noise_rx_mean_i = tds.metagrp.variables['RxTemperature'][ tds.index_meta].data if (np.isnan(noise_rx_mean_i)): noise_rx_mean_i = 232.09 noise_antenna_mean += noise_antenna_mean_i noise_rx_mean += noise_rx_mean_i print("noise antenna : {}".format(noise_antenna_mean_i)) if (wind != None): print("wind: {0}".format(wind)) mean_wind += wind n_wind += 1 mean_wind /= n_wind ddm_tds /= n #np.flip(ddm_tds) noise_antenna_mean /= n noise_rx_mean /= n noise_antenna_mean = 246.85 noise_rx_mean = 252.09 print("noise_antenna_mean: {0}".format(noise_antenna_mean)) print("noise_rx_mean: {0}".format(noise_rx_mean)) print("mean wind: {0}".format(mean_wind)) sim_config.u_10 = 2.35 #sim_config.phi_0 = 130*np.pi/180 # 0.547 sim_config.phi_0 = 45 * np.pi / 180 # max power diff: 0.58 # Plot TDS DDM sea clutter tds.set_group_index(group, index) r_sp, lat_sp, lon_sp = tds.find_sp() datenum = tds.rootgrp.groups[ tds.group].variables['IntegrationMidPointTime'][tds.index] string = str(datenum_to_pytime(float(datenum))) \ + ' Lat: ' + "{0:.2f}".format(tds.lat_sp_tds) \ + ' Lon: ' + "{0:.2f}".format(tds.lon_sp_tds) tds_number_of_delay_pixels = tds.metagrp.groups[ tds.group].NumberOfDelayPixels tds_number_of_doppler_pixels = tds.metagrp.groups[ tds.group].NumberOfDopplerPixels tds_delay_start = tds.calculate_delay_increment_chips(0) tds_delay_end = tds.calculate_delay_increment_chips( tds_number_of_delay_pixels - 1) tds_delay_resolution = (tds_delay_end - tds_delay_start) / 128 tds_doppler_start = tds.calculate_doppler_increment( -np.floor(tds_number_of_doppler_pixels / 2)) tds_doppler_end = tds.calculate_doppler_increment( np.floor(tds_number_of_doppler_pixels / 2 - 0.5)) tds_doppler_resolution = 500 fig_tds, ax_tds = plt.subplots(1, figsize=(10, 4)) plt.title('TDS-1 Experimental Data') plt.xlabel('C/A chips') plt.ylabel('Hz') contour_tds = ax_tds.imshow( ddm_tds, cmap='jet', extent=(tds_delay_start, tds_delay_end, tds_doppler_end, tds_doppler_start), #aspect=(tds_number_of_doppler_pixels/tds_number_of_delay_pixels)/np.abs(tds_doppler_start/tds_delay_start) aspect='auto') t = plt.text(0.01, 0.85, string, { 'color': 'w', 'fontsize': 12 }, transform=ax_tds.transAxes) cbar = fig_tds.colorbar(contour_tds, label='Power') # Load TDS Geometry in simulation configuration n_z = unit_vector(ellip_norm(tds.r_sp_tds)) n_x = unit_vector(np.cross(n_z, tds.r_sp_tds - tds.r_t)) n_y = unit_vector(np.cross(n_z, n_x)) v_tx = np.dot(tds.v_t, n_x) v_ty = np.dot(tds.v_t, n_y) v_tz = np.dot(tds.v_t, n_z) v_rx = np.dot(tds.v_r, n_x) v_ry = np.dot(tds.v_r, n_y) v_rz = np.dot(tds.v_r, n_z) h_r = np.dot((tds.r_r - tds.r_sp_tds), n_z) h_t = np.dot((tds.r_t - tds.r_sp_tds), n_z) elevation = angle_between(n_y, tds.r_t - tds.r_sp_tds) v_t = np.array([v_tx, v_ty, v_tz]) v_r = np.array([v_rx, v_ry, v_rz]) print("h_r: {}".format(h_r)) print("h_t: {}".format(h_t)) print("elevation: {}".format(elevation)) print("v_r: {}".format(np.linalg.norm(v_r))) print("v_t: {}".format(np.linalg.norm(v_t))) sim_config.set_scenario_local_ref( h_r=np.dot((tds.r_r - tds.r_sp_tds), n_z), h_t=np.dot((tds.r_t - tds.r_sp_tds), n_z), elevation=angle_between(n_y, tds.r_t - tds.r_sp_tds), v_t=np.array([v_tx, v_ty, v_tz]), v_r=np.array([v_rx, v_ry, v_rz])) # DDM sim_config.delay_increment_start = tds_delay_start * delay_chip sim_config.delay_increment_end = tds_delay_end * delay_chip sim_config.delay_resolution = ( sim_config.delay_increment_end - sim_config.delay_increment_start) / tds_number_of_delay_pixels / 4 sim_config.doppler_increment_start = tds_doppler_start sim_config.doppler_increment_end = tds_doppler_end + tds_doppler_resolution sim_config.doppler_resolution = ( sim_config.doppler_increment_end - sim_config.doppler_increment_start) / tds_number_of_doppler_pixels / 4 ddm_sim = (simulate_ddm(sim_config)) fig_ddm, ax_ddm = plt.subplots(1, figsize=(10, 4)) plt.title('DDM original simulation') plt.xlabel('C/A chips') plt.ylabel('Hz') contour_ddm = ax_ddm.imshow(ddm_sim, cmap='jet', extent=(sim_config.delay_increment_start, sim_config.delay_increment_end, sim_config.doppler_increment_end, sim_config.doppler_increment_start), aspect="auto") cbar = fig_ddm.colorbar(contour_ddm, label='Correlated Power [Watts]') # DDM Rescaled fig_ddm_rescaled, ax_ddm_rescaled = plt.subplots(1, figsize=(10, 4)) plt.title('Simulation Rescaled') plt.xlabel('C/A chips') plt.ylabel('Hz') ddm_rescaled = rescale(ddm_sim, tds_number_of_doppler_pixels, tds_number_of_delay_pixels) # Noise waf_delay_increment_values = list( np.arange( -tds_delay_end * delay_chip, tds_delay_end * delay_chip + tds_delay_resolution * delay_chip, tds_delay_resolution * delay_chip)) waf_doppler_increment_values = list( np.arange(tds_doppler_start, tds_doppler_end + tds_doppler_resolution, tds_doppler_resolution)) waf_delay_grid, waf_doppler_grid = np.meshgrid( waf_delay_increment_values, waf_doppler_increment_values) waf_matrix = woodward_ambiguity_function(waf_delay_grid, waf_doppler_grid, sim_config)**2 noise_temperature = noise_antenna_mean + noise_rx_mean ddm_rescaled = add_thermal_noise(tds_number_of_doppler_pixels, tds_number_of_delay_pixels, 1 * 1000, noise_temperature, ddm_rescaled, sim_config) contour_res = ax_ddm_rescaled.imshow( ddm_rescaled, cmap='jet', extent=(tds_delay_start, tds_delay_end, tds_doppler_end, tds_doppler_start), #aspect=(tds_number_of_doppler_pixels/tds_number_of_delay_pixels)/np.abs(tds_doppler_start/tds_delay_start) aspect='auto') cbar = fig_ddm_rescaled.colorbar(contour_res, label='Correlated Power [Watts]') # Difference fig_diff, ax_diff = plt.subplots(1, figsize=(10, 4)) plt.title('Difference') plt.xlabel('C/A chips') plt.ylabel('Hz') ddm_diff = np.copy(ddm_rescaled) for row_i, row in enumerate(ddm_diff): for col_i, val in enumerate(row): col_i_shift = col_i row_i_shift = row_i col_shift = 1 row_shift = 0 if (col_i + col_shift) >= 0 and (col_i + col_shift) < 128: col_i_shift += col_shift if (row_i + row_shift) >= 0 and (row_i + row_shift) < 20: row_i_shift += row_shift val_tds = ddm_tds[row_i_shift, col_i_shift] val = ddm_rescaled[row_i, col_i] if row_i == 0: ddm_diff[row_i, col_i] = 0 elif col_i == 0: ddm_diff[row_i, col_i] = 0 else: rel = np.abs((val - val_tds) / val_tds) ddm_diff[row_i, col_i] = rel ddm_diff[:, -1] = 0 ddm_diff[0, 0] = 0 ddm_diff[0, 1] = 1 np.place(ddm_diff, np.abs(ddm_diff) > 2, 0.1) print(file_root_name) print("h_r: {}".format(h_r)) print("h_t: {}".format(h_t)) print("elevation: {}".format(elevation * 180 / np.pi)) print("v_r: {}".format(np.linalg.norm(v_r))) print("v_t: {}".format(np.linalg.norm(v_t))) print("max diff: {}".format(np.max(ddm_diff[1:, 1:]))) im = ax_diff.imshow( ddm_diff, cmap='jet', extent=(tds_delay_start, tds_delay_end, tds_doppler_end, tds_doppler_start), #aspect=(tds_number_of_doppler_pixels/tds_number_of_delay_pixels)/np.abs(tds_doppler_start/tds_delay_start) aspect='auto') cbar = fig_diff.colorbar(im, label='Relative error') # SNR fig_snr, ax_snr = plt.subplots(1, figsize=(10, 4)) plt.title('SNR') plt.xlabel('C/A chips') plt.ylabel('Hz') T_noise_receiver = noise_antenna_mean + noise_rx_mean k_b = 1.38e-23 # J/K y_noise = 4 / sim_config.coherent_integration_time * k_b * T_noise_receiver / np.sqrt( 1000) ddm_rescaled_snr = rescale(ddm_sim, tds_number_of_doppler_pixels, tds_number_of_delay_pixels) ddm_snr = np.copy(10 * np.log10(np.abs(ddm_rescaled_snr) / y_noise)) contour_snr = ax_snr.imshow( ddm_snr, cmap='jet', extent=(tds_delay_start, tds_delay_end, tds_doppler_end, tds_doppler_start), #aspect=(tds_number_of_doppler_pixels/tds_number_of_delay_pixels)/np.abs(tds_doppler_start/tds_delay_start) aspect='auto') cbar = fig_snr.colorbar(contour_snr, label='dB') plt.show()
def main(): sim_config = simulation_configuration() delay_chip = sim_config.delay_chip # Really good #sim_config.u_10 = 4 #sim_config.phi_0 = 35*np.pi/180 #sim_config.u_10 = 4 #sim_config.phi_0 = 38*np.pi/180 sim_config.u_10 = 14.04 sim_config.phi_0 = -83*np.pi/180 file_root_name = 'raw/L1B/2015-04-01-H00' target = targets['hibernia'] group = '000095' index = 515 tds = tds_data(file_root_name, group, index) # Sea clutter estimation. #p = target_processor(); #for i in range(index - 30, index + 5): # ddm = tds.rootgrp.groups[group].variables['DDM'][i].data # p.process_ddm(ddm) # Plot TDS DDM sea clutter datenum = tds.rootgrp.groups[tds.group].variables['IntegrationMidPointTime'][tds.index] string = str(datenum_to_pytime(float(datenum))) \ + ' Lat: ' + "{0:.2f}".format(tds.lat_sp_tds) \ + ' Lon: ' + "{0:.2f}".format(tds.lon_sp_tds) number_of_delay_pixels = tds.metagrp.groups[tds.group].NumberOfDelayPixels number_of_doppler_pixels = tds.metagrp.groups[tds.group].NumberOfDopplerPixels delay_start = tds.calculate_delay_increment_chips(0) delay_end = tds.calculate_delay_increment_chips(number_of_delay_pixels-1) doppler_start = tds.calculate_doppler_increment(-np.floor(number_of_doppler_pixels/2)) doppler_end = tds.calculate_doppler_increment(np.floor(number_of_doppler_pixels/2 - 0.5)) delay_increment_start = sim_config.delay_increment_start delay_increment_end = sim_config.delay_increment_end delay_resolution = sim_config.delay_resolution sim_config.delay_increment_start = delay_start*delay_chip + 2*delay_resolution sim_config.delay_increment_end = delay_end*delay_chip sim_config.doppler_increment_start = -5000 sim_config.doppler_increment_end = 5000 doppler_increment_start = sim_config.doppler_increment_start doppler_increment_end = sim_config.doppler_increment_end doppler_resolution = sim_config.doppler_resolution fig_tds, ax_tds = plt.subplots(1,figsize=(10, 4)) plt.title('TDS-1 Experimental Data') plt.xlabel('C/A chips') plt.ylabel('Hz') im = ax_tds.imshow(p.sea_clutter, cmap='jet', extent=(delay_start, delay_end, doppler_end, doppler_start), aspect=(number_of_doppler_pixels/number_of_delay_pixels)/np.abs(doppler_start/delay_start) ) t = plt.text(0.01, 0.85, string, {'color': 'w', 'fontsize': 12}, transform=ax_tds.transAxes) # Load TDS Geometry in simulation configuration r_sp, lat_sp, lon_sp = tds.find_sp(); n_z = unit_vector(ellip_norm(r_sp)) n_x = unit_vector(np.cross(n_z, r_sp-tds.r_t)) n_y = unit_vector(np.cross(n_z, n_x)) v_tx = np.dot(tds.v_t, n_x) v_ty = np.dot(tds.v_t, n_y) v_tz = np.dot(tds.v_t, n_z) v_rx = np.dot(tds.v_r, n_x) v_ry = np.dot(tds.v_r, n_y) v_rz = np.dot(tds.v_r, n_z) sim_config.set_scenario_local_ref( h_r = np.dot((tds.r_r - r_sp), n_z), h_t = np.dot((tds.r_t - r_sp), n_z), elevation = angle_between(n_y, tds.r_t-r_sp), v_t = np.array([v_tx,v_ty,v_tz]), v_r = np.array([v_rx,v_ry,v_rz]) ) # DDM ddm_sim = normalize(simulate_ddm(sim_config)) fig_ddm, ax_ddm = plt.subplots(1,figsize=(10, 4)) plt.title('DDM original simulation') plt.xlabel('C/A chips') plt.ylabel('Hz') im = ax_ddm.imshow(ddm_sim, cmap='jet', extent=(delay_start, delay_end, doppler_end, doppler_start), aspect="auto" ) # Image downscaling to desired resolution: # TODO: This is just an average of the pixels around the area # This is not valid, summation i srequired: # Di Simone > From a physical viewpoint, # such an approach should call for summation instead of averaging # https://stackoverflow.com/questions/48121916/numpy-resize-rescale-image fig_ddm_rescaled, ax_ddm_rescaled = plt.subplots(1,figsize=(10, 4)) plt.title('Simulation') plt.xlabel('C/A chips') plt.ylabel('Hz') rescaled_doppler_resolution = tds.doppler_resolution rescaled_delay_resolution_chips = tds.time_delay_resolution/delay_chip ddm_rescaled = cv2.resize(ddm_sim, dsize=( 128, 20 ), interpolation=cv2.INTER_AREA ) ddm_rescaled = ddm_rescaled + 0.02*np.max(ddm_rescaled)*np.random.rand(ddm_rescaled.shape[0],ddm_rescaled.shape[1]) im = ax_ddm_rescaled.imshow(ddm_rescaled, cmap='jet', extent=(delay_start, delay_end, doppler_end, doppler_start), aspect=(number_of_doppler_pixels/number_of_delay_pixels)/np.abs(doppler_start/delay_start) ) fig_diff, ax_diff = plt.subplots(1,figsize=(10, 4)) plt.title('Difference') plt.xlabel('C/A chips') plt.ylabel('Hz') ddm_diff = np.abs(ddm_rescaled-p.sea_clutter) ddm_diff[0,0] = 0.35 im = ax_diff.imshow(ddm_diff, cmap='jet', extent=(delay_start, delay_end, doppler_end, doppler_start), aspect=(number_of_doppler_pixels/number_of_delay_pixels)/np.abs(doppler_start/delay_start) ) cbar = fig_diff.colorbar(im, label='Normalized Power', shrink=0.35) plt.show()
def main(): # Petronius Oil Platform #file_dir = os.path.join(os.environ['TDS_ROOT'], 'raw/L1B/2017-11-26-H06-') #rootgrp = Dataset(file_dir+"DDMs.nc", "r", format="NETCDF4") #metagrp = Dataset(file_dir+"metadata.nc", "r", format="NETCDF4") #group = '000047' #start_0 = 590 file_root_name = 'raw/L1B/2015-04-01-H00' group = '000095' index = 525 tds = tds_data(file_root_name, group, index) rootgrp = tds.rootgrp metagrp = tds.metagrp # The region of interest lies between delay column 60 and delay column 80 min_col = 60 max_col = 85 def datenum_to_pytime(matlab_datenum): python_datetime = datetime.fromordinal( int(matlab_datenum)) + timedelta(days=matlab_datenum % 1) - timedelta(days=366) return python_datetime def normalize(mat): return (mat - np.min(mat)) / (np.max(mat) - np.min(mat)) def cut_noise_region(ddm, ddm_ref, new_value=0): """ For each pixel in ddm, replaces the pixel with new_value if the pixel with same indeces in ddm_ref is less than 0.3 cut_threshold is computed as the mean of the noise region of the ddm_ref (from column 0 to 40) """ ddm_cut = np.zeros(ddm.shape) + new_value cut_threshold = 0.15 for row_i, row in enumerate(ddm_cut): for col_i, val in enumerate(row): if (col_i >= min_col and col_i <= max_col): if (ddm_ref[row_i][col_i] >= cut_threshold): ddm_cut[row_i][col_i] = ddm[row_i][col_i] return ddm_cut # 1. Original ddm_original = normalize( np.array(rootgrp.groups[group].variables['DDM'][index].data)) # 2. Sea clutter estimation. # As target appear as bright spots, the initial estimation is based of the # composition of the minimum values for each pixel for the last n measurements n = 10 offset = 0 sea_clutter_0 = normalize( np.array(rootgrp.groups[group].variables['DDM'][index - offset].data)) for i in range(n): ddm_i = normalize( np.array(rootgrp.groups[group].variables['DDM'][index - offset - i].data)) sea_clutter_0 = normalize(sea_clutter_0) for row_i, row in enumerate(sea_clutter_0): for col_i, val in enumerate(row): val_i = ddm_i[row_i][col_i] val = sea_clutter_0[row_i][col_i] min, max = np.sort([val_i, val]) sea_clutter_0[row_i][col_i] = 0.5 * min + 0.5 * max sea_clutter_0 = normalize(sea_clutter_0) # Using the sea_clutter_0 as initial estimation a low pass filter that gives # more weight to the lower values is applied n = 200 tau = 0.08 sea_clutter = np.array(sea_clutter_0) for i in range(n): ddm_i = normalize( np.array(rootgrp.groups[group].variables['DDM'][index - offset - i].data)) sea_clutter = normalize(sea_clutter) for row_i, row in enumerate(sea_clutter): for col_i, val in enumerate(row): val_i = ddm_i[row_i][col_i] val = sea_clutter[row_i][col_i] #min,max = np.sort([val_i,val]) #new_val = 0.7*min + 0.3*max; sea_clutter[row_i][col_i] = val + tau * (val_i - val) sea_clutter = normalize(sea_clutter) # Only the region of the wake is relevant for detection, so we cut the # irrelevant region sea_clutter_cut = cut_noise_region(sea_clutter, sea_clutter) ddm_original_cut = cut_noise_region(ddm_original, sea_clutter) # 3. Sea clutter substracted Difference Map ddm_diff = ddm_original_cut - 0.85 * sea_clutter_cut if (np.min(ddm_diff) < 0): ddm_diff = ddm_diff - np.min(ddm_diff) cut_value_fig = np.min(ddm_diff) ddm_diff_fig = cut_noise_region(ddm_diff, sea_clutter, cut_value_fig) ddm_diff = cut_noise_region(ddm_diff, sea_clutter) # 4. Over threshold detection ddm_detections = np.zeros(ddm_diff.shape) threshold = 0.38 print(np.max(ddm_diff)) print(threshold) print(index) for row_i, row in enumerate(ddm_diff): for col_i, val in enumerate(row): if (col_i >= min_col and col_i <= max_col): if (ddm_diff[row_i][col_i] >= threshold): ddm_detections[row_i][col_i] = 1 # Plotting x_start = -6 x_end = 15 y_start = 4500 y_end = -4500 number_of_delay_pixels = tds.metagrp.groups[tds.group].NumberOfDelayPixels number_of_doppler_pixels = tds.metagrp.groups[ tds.group].NumberOfDopplerPixels delay_start = tds.calculate_delay_increment_chips(0) delay_end = tds.calculate_delay_increment_chips(number_of_delay_pixels - 1) doppler_start = tds.calculate_doppler_increment( -np.floor(number_of_doppler_pixels / 2)) doppler_end = tds.calculate_doppler_increment( np.floor(number_of_doppler_pixels / 2 - 0.5)) fig_original = plt.figure(figsize=(10, 4)) im_original = plt.imshow(ddm_original, cmap='viridis', extent=(delay_start, delay_end, doppler_end, doppler_start), aspect='auto') plt.xlim([x_start, x_end]) plt.ylim([y_start, y_end]) plt.xlabel('C/A chips') plt.ylabel('Hz') datenum = metagrp.groups[group].variables['IntegrationMidPointTime'][index] lat = metagrp.groups[group].variables['SpecularPointLat'][index] lon = metagrp.groups[group].variables['SpecularPointLon'][index] #string = 'G: ' + group + ' I: ' + str(index) + ' - ' + \ # str(datenum) + ' - ' + str(datenum_to_pytime(float(datenum))) + ' - Lat: ' + \ # str(lat) + ' Lon: ' + str(lon) + '\n' string = str(datenum_to_pytime(float(datenum))) \ + ' Lat: ' + "{0:.2f}".format(tds.lat_sp_tds) \ + ' Lon: ' + "{0:.2f}".format(tds.lon_sp_tds) t = plt.text(-5.3, -3200, string, {'color': 'w', 'fontsize': 12}) plt.show(block=False) fig_sea_clutter = plt.figure(figsize=(10, 4)) im_sea_clutter = plt.imshow(sea_clutter, cmap='viridis', extent=(delay_start, delay_end, doppler_end, doppler_start), aspect='auto') plt.xlim([x_start, x_end]) plt.ylim([y_start, y_end]) plt.xlabel('C/A chips') plt.ylabel('Hz') plt.show(block=False) fig_sub = plt.figure(figsize=(10, 4)) im_sub = plt.imshow(ddm_diff, cmap='viridis', extent=(delay_start, delay_end, doppler_end, doppler_start), aspect='auto') plt.xlim([x_start, x_end]) plt.ylim([y_start, y_end]) plt.xlabel('C/A chips') plt.ylabel('Hz') plt.show(block=False) fig_detections = plt.figure(figsize=(10, 4)) im_detections = plt.imshow(ddm_detections, cmap='viridis', extent=(delay_start, delay_end, doppler_end, doppler_start), aspect='auto') plt.xlim([x_start, x_end]) plt.ylim([y_start, y_end]) plt.xlabel('C/A chips') plt.ylabel('Hz') plt.show(block=False) all_labels = label(ddm_detections) fig_labels, ax_labels = plt.subplots(1, figsize=(10, 4)) ax_labels.imshow(ddm_original, cmap='viridis', aspect='auto') plt.show(block=False) for region in regionprops(all_labels): minr, minc, maxr, maxc = region.bbox l = 1 rect = mpatches.Rectangle((minc - l, minr - l), maxc - minc + 2 * l - 1, maxr - minr + 2 * l - 1, fill=False, edgecolor='red', linewidth=2) ax_labels.add_patch(rect) plt.show()
def main(): sim_config = simulation_configuration() #sim_config.jacobian_type = 'spherical' delay_chip = sim_config.delay_chip # Really good #sim_config.u_10 = 4 #sim_config.phi_0 = 35*np.pi/180 #sim_config.u_10 = 4 #sim_config.phi_0 = 38*np.pi/180 sim_config.u_10 = 3 sim_config.phi_0 = -83 * np.pi / 180 file_root_name = '2015-04-01-H00' target = targets['hibernia'] group = '000095' index = 415 tds = tds_data(file_root_name, group, index) # Load TDS Geometry in simulation configuration number_of_delay_pixels = tds.metagrp.groups[tds.group].NumberOfDelayPixels number_of_doppler_pixels = tds.metagrp.groups[ tds.group].NumberOfDopplerPixels delay_start = tds.calculate_delay_increment_chips(0) delay_end = tds.calculate_delay_increment_chips(number_of_delay_pixels - 1) doppler_start = tds.calculate_doppler_increment( -np.floor(number_of_doppler_pixels / 2)) doppler_end = tds.calculate_doppler_increment( np.floor(number_of_doppler_pixels / 2 - 0.5)) delay_increment_start = sim_config.delay_increment_start delay_increment_end = sim_config.delay_increment_end delay_resolution = sim_config.delay_resolution sim_config.delay_increment_start = delay_start * delay_chip + 2 * delay_resolution sim_config.delay_increment_end = delay_end * delay_chip sim_config.doppler_increment_start = -5000 sim_config.doppler_increment_end = 5000 doppler_increment_start = sim_config.doppler_increment_start doppler_increment_end = sim_config.doppler_increment_end doppler_resolution = sim_config.doppler_resolution r_sp, lat_sp, lon_sp = tds.find_sp() n_z = unit_vector(ellip_norm(r_sp)) n_x = unit_vector(np.cross(n_z, r_sp - tds.r_t)) n_y = unit_vector(np.cross(n_z, n_x)) v_tx = np.dot(tds.v_t, n_x) v_ty = np.dot(tds.v_t, n_y) v_tz = np.dot(tds.v_t, n_z) v_rx = np.dot(tds.v_r, n_x) v_ry = np.dot(tds.v_r, n_y) v_rz = np.dot(tds.v_r, n_z) #sim_config.set_scenario_local_ref( # h_r = np.dot((tds.r_r - r_sp), n_z), # h_t = np.dot((tds.r_t - r_sp), n_z), # elevation = angle_between(n_y, tds.r_t-r_sp), # v_t = np.array([v_tx,v_ty,v_tz]), # v_r = np.array([v_rx,v_ry,v_rz]) # ) # DDM ddm_sim = simulate_ddm(sim_config) fig_ddm, ax_ddm = plt.subplots(1, figsize=(10, 4)) plt.title('DDM simulation') plt.xlabel('C/A chips') plt.ylabel('Hz') contour = ax_ddm.imshow(ddm_sim, cmap='jet', extent=(delay_start, delay_end, doppler_end, doppler_start), aspect="auto") cbar = fig_ddm.colorbar(contour, label='Power [Watt]') T_noise_receiver = 225 k_b = 1.38e-23 # J/K y_noise = 1 / sim_config.coherent_integration_time * k_b * T_noise_receiver ddm_sim_snr = np.copy(10 * np.log10(np.abs(ddm_sim) / y_noise)) fig_ddm_snr, ax_ddm_snr = plt.subplots(1, figsize=(10, 4)) plt.title('DDM SNR simulation') plt.xlabel('C/A chips') plt.ylabel('Hz') contour_snr = ax_ddm_snr.imshow(ddm_sim_snr, cmap='jet', extent=(delay_start, delay_end, doppler_end, doppler_start), aspect="auto") cbar = fig_ddm_snr.colorbar(contour_snr, label='SNR [dB]') plt.show()