def postprocess_batch_read_fd(template_file, plots=True): cfg_file = utils.get_parFile(parfile=template_file) ref_cfg = osrio.ConfigFile(cfg_file) num = ref_cfg.radar.n_pulses - 1 Doppler_av = np.zeros((np.size(No)*np.size(Time), np.size(inc_s), np.size(azimuth_s), num), dtype=np.complex) coh_av = np.zeros((np.size(No)*np.size(Time), np.size(inc_s), np.size(azimuth_s), num), dtype=np.complex) for iii in range(np.size(No)): path_m = ref_cfg.sim.path + os.sep + 'SKIM_12deg_rar_%d'%(No[iii]) sim_path_ref = path_m + os.sep + 'Time%d_inc_s%d_azimuth_s%d' for ind_t in range(np.size(Time)): for ind_inc in range(np.size(inc_s)): for ind_azimuth in range(np.size(azimuth_s)): # Read data path = sim_path_ref % (Time[ind_t], inc_s[ind_inc], azimuth_s[ind_azimuth]) data = np.load(os.path.join(path, 'pp_data.nc.npz')) Doppler_av[iii*np.size(Time) + ind_t, ind_inc, ind_azimuth, :] = data['dop_pp_avg'] coh_av[iii*np.size(Time)+ind_t, ind_inc, ind_azimuth, :] = data['coh'] if ref_cfg.processing.Azi_img: np.save(os.path.join(ref_cfg.sim.path, 'Doppler_coherence_data_unfocus.npy'), [Doppler_av, coh_av, num]) else: np.save(os.path.join(ref_cfg.sim.path, 'Doppler_coherence_data.npy'), [Doppler_av, coh_av, num])
def sarsim(cfg_file=None): print( '-------------------------------------------------------------------', flush=True) print(time.strftime("OCEANSAR SAR Simulator [%Y-%m-%d %H:%M:%S]", time.localtime()), flush=True) # print('Copyright (c) Gerard Marull Paretas, Paco López-Dekker') print( '-------------------------------------------------------------------', flush=True) cfg_file = utils.get_parFile(parfile=cfg_file) cfg = osrio.ConfigFile(cfg_file) # Create output directory if it doesnt exist already os.makedirs(cfg.sim.path, exist_ok=True) src_path = os.path.dirname(os.path.abspath(__file__)) # RAW if cfg.sim.raw_run: print('Launching SAR RAW Generator...') sar_raw(cfg.cfg_file_name, os.path.join(cfg.sim.path, cfg.sim.raw_file), os.path.join(cfg.sim.path, cfg.sim.ocean_file), cfg.sim.ocean_reuse, os.path.join(cfg.sim.path, cfg.sim.errors_file), cfg.sim.errors_reuse, plot_save=True) # Processing if cfg.sim.proc_run: print('Launching SAR RAW Processor...') sar_focus(cfg.cfg_file_name, os.path.join(cfg.sim.path, cfg.sim.raw_file), os.path.join(cfg.sim.path, cfg.sim.proc_file)) if cfg.sim.insar_run: print('Launching InSAR L1b Processor...') insar_process(cfg.cfg_file_name, os.path.join(cfg.sim.path, cfg.sim.proc_file), os.path.join(cfg.sim.path, cfg.sim.ocean_file), os.path.join(cfg.sim.path, cfg.sim.insar_file)) if cfg.sim.ati_run: print('Launching SAR ATI Processor...') ati_process(cfg.cfg_file_name, os.path.join(cfg.sim.path, cfg.sim.insar_file), os.path.join(cfg.sim.path, cfg.sim.ocean_file), os.path.join(cfg.sim.path, cfg.sim.ati_file)) if cfg.sim.L2_wavespectrum_run: print('Launching L2 Wavespectrum Processor...') print('----------------------------------', flush=True) print(time.strftime("End of tasks [%Y-%m-%d %H:%M:%S]", time.localtime()), flush=True) print('----------------------------------', flush=True)
def skimsim(cfg_file=None): print('-------------------------------------------------------------------', flush=True) print(time.strftime("OCEANSAR SKIM Simulator [%Y-%m-%d %H:%M:%S]", time.localtime()), flush=True) # print('Copyright (c) Gerard Marull Paretas, Paco López-Dekker') print('-------------------------------------------------------------------', flush=True) cfg_file = utils.get_parFile(parfile=cfg_file) cfg = osrio.ConfigFile(cfg_file) # Create output directory if it doesnt exist already os.makedirs(cfg.sim.path, exist_ok=True) src_path = os.path.dirname(os.path.abspath(__file__)) # RAW if cfg.sim.raw_run: print('Launching SAR RAW Generator...') args = [cfg.sim.mpi_exec, '-np', str(cfg.sim.mpi_num_proc), sys.executable, src_path + os.sep + 'skim_raw.py', '-c', cfg.cfg_file_name, '-o', cfg.sim.path + os.sep + cfg.sim.raw_file, '-oc', cfg.sim.path + os.sep + cfg.sim.ocean_file, '-er', cfg.sim.path + os.sep + cfg.sim.errors_file] if cfg.sim.ocean_reuse: args.append('-ro') if cfg.sim.errors_reuse: args.append('-re') returncode = subprocess.call(args) if returncode != 0: raise Exception('Something went wrong with SAR RAW Generator (return code %d)...' % returncode) # Processing if cfg.sim.proc_run: print('Launching SAR RAW Processor...') returncode = subprocess.call([sys.executable, src_path + os.sep + 'skim_processor.py', '-c', cfg.cfg_file_name, '-r', cfg.sim.path + os.sep + cfg.sim.raw_file]) #, # '-o', cfg.sim.path + os.sep + cfg.sim.pp_file]) if returncode != 0: raise Exception('Something went wrong with SAR RAW Processor (return code %d)...' % returncode) print('----------------------------------', flush=True) print(time.strftime("End of tasks [%Y-%m-%d %H:%M:%S]", time.localtime()), flush=True) print('----------------------------------', flush=True)
def batch_sarsim(template_file): cfg_file = utils.get_parFile(parfile=template_file) ref_cfg = osrio.ConfigFile(cfg_file) step = 0 sim_path_ref = ref_cfg.sim.path + os.sep + 'sim_U%d_wdir%d_smag%d_sdir%d_inc%d_i%i' n_all = (np.size(v_wind_U) * np.size(v_wind_dir) * np.size(v_current_mag) * np.size(v_current_dir) * np.size(v_inc_angle) * n_rep) for wind_U in v_wind_U: for wind_dir in v_wind_dir: for current_mag in v_current_mag: for current_dir in v_current_dir: for inc_angle in v_inc_angle: for i_rep in np.arange(n_rep, dtype=np.int): step = step + 1 print("") print( 'CONFIGURATION AND LAUNCH OF SIMULATION %d of %d' % (step, n_all)) ### CONFIGURATION FILE ### # Load template cfg = ref_cfg # Modify template, create directory & save cfg.sim.path = sim_path_ref % ( wind_U, wind_dir, current_mag, current_dir, inc_angle, i_rep) cfg.ocean.wind_U = wind_U cfg.ocean.wind_dir = wind_dir cfg.ocean.current_mag = current_mag cfg.ocean.current_dir = current_dir cfg.sar.inc_angle = inc_angle if not os.path.exists(cfg.sim.path): os.makedirs(cfg.sim.path) # Save configuration file into an alternate file cfg.save(cfg.sim.path + os.sep + cfg_file_name) ### LAUNCH MACSAR ### subprocess.call([ sys.executable, osr_script, cfg.sim.path + os.sep + cfg_file_name ])
def batch_skimsim(template_file): for iii in range(np.size(No)): cfg_file = utils.get_parFile(parfile=template_file) ref_cfg = osrio.ConfigFile(cfg_file) path_m = ref_cfg.sim.path + os.sep + 'SKIM_12deg_rar_%d'%(No[iii]) sim_path_ref = path_m + os.sep + 'Time%d_inc_s%d_azimuth_s%d' for t in Time: for inc_angle in inc_s: for azimuth in azimuth_s: ### CONFIGURATION FILE ### # Load template cfg = ref_cfg # Modify template, create directory & save cfg.sim.path = sim_path_ref % (t, inc_angle, azimuth) cfg.batch_Loop.t = t cfg.radar.inc_angle = inc_angle cfg.radar.azimuth = azimuth if not os.path.exists(cfg.sim.path): os.makedirs(cfg.sim.path) # Save configuration file into an alternate file cfg.save(cfg.sim.path + os.sep + cfg_file_name) cfg_file = utils.get_parFile(parfile=template_file) ref_cfg = osrio.ConfigFile(cfg_file) step = 0 sim_path_ref = ref_cfg.sim.path + os.sep + 'Time%d_inc_s%d_azimuth_s%d_wavelength%1f' n_all = (np.size(Time) * np.size(inc_s) * np.size(azimuth_s) * np.size(wave_scale)*n_rep) for t in Time: for inc_angle in inc_s: for azimuth in azimuth_s: for wave_length in wave_scale: step = step + 1 print("") print('CONFIGURATION AND LAUNCH OF SIMULATION %d of %d' % (step, n_all)) ### CONFIGURATION FILE ### # Load template cfg = ref_cfg # Modify template, create directory & save cfg.sim.path = sim_path_ref % (t, inc_angle, azimuth, wave_length) cfg.batch_Loop.t = t cfg.radar.inc_angle = inc_angle cfg.radar.azimuth = azimuth cfg.processing.wave_scale = wave_length if not os.path.exists(cfg.sim.path): os.makedirs(cfg.sim.path) # Save configuration file into an alternate file cfg.save(cfg.sim.path + os.sep + cfg_file_name) ### LAUNCH MACSAR ### subprocess.call([sys.executable, osr_script, '-c', cfg.sim.path + os.sep + cfg_file_name])
def postprocess_batch_read(template_file, plots=True): cfg_file = utils.get_parFile(parfile=template_file) ref_cfg = osrio.ConfigFile(cfg_file) wave_scale = ref_cfg.processing.wave_scale path_m = ref_cfg.sim.path + os.sep + 'SKIM_12deg_rar_%d'%(No[0]) if ref_cfg.processing.Azi_img: sim_path_ref = path_m + os.sep + 'Time%d_inc_s%d_azimuth_s%d' + os.sep + 'wavelength%.1f_unfocus' else: sim_path_ref = path_m + os.sep + 'Time%d_inc_s%d_azimuth_s%d' + os.sep + 'wavelength%.1f' path = sim_path_ref % (Time[0], inc_s[0], azimuth_s[0], wave_scale[0]) + os.sep + 'delta_k_spectrum_plots' data = np.load(os.path.join(path, 'Angular_velocity.npy')) analyse_num = data[3] si = data[2] Angular_velocity_curves = np.zeros((np.size(No)*np.size(Time), np.size(inc_s), np.size(azimuth_s), np.size(wave_scale), int(data[2])), dtype=np.complex) Angular_velocity_av = np.zeros((np.size(No)*np.size(Time), np.size(inc_s), np.size(azimuth_s), np.size(wave_scale), 0), dtype=np.complex) Phase_velocity_curves = np.zeros((np.size(No)*np.size(Time), np.size(inc_s), np.size(azimuth_s), np.size(wave_scale), int(data[2])), dtype=np.complex) Phase_velocity_av = np.zeros((np.size(No)*np.size(Time), np.size(inc_s), np.size(azimuth_s), np.size(wave_scale), 0), dtype=np.complex) for iii in range(np.size(No)): path_m = ref_cfg.sim.path + os.sep + 'SKIM_12deg_rar_%d'%(No[iii]) if ref_cfg.processing.Azi_img: sim_path_ref = path_m + os.sep + 'Time%d_inc_s%d_azimuth_s%d' + os.sep + 'wavelength%.1f_unfocus' else: sim_path_ref = path_m + os.sep + 'Time%d_inc_s%d_azimuth_s%d' + os.sep + 'wavelength%.1f' for ind_t in range(np.size(Time)): for ind_inc in range(np.size(inc_s)): for ind_azimuth in range(np.size(azimuth_s)): for ind_wavelength in range(np.size(wave_scale)): # Read data path = sim_path_ref % (Time[ind_t], inc_s[ind_inc], azimuth_s[ind_azimuth], wave_scale[ind_wavelength]) + os.sep + 'delta_k_spectrum_plots' data = np.load(os.path.join(path, 'Angular_velocity.npy')) Angular_velocity_curves[iii*np.size(Time) + ind_t, ind_inc, ind_azimuth, ind_wavelength, :] = data[0] Angular_velocity_av[iii*np.size(Time)+ind_t, ind_inc, ind_azimuth, ind_wavelength, :] = data[1] data_p = np.load(os.path.join(path, 'Phase_velocity.npy')) Phase_velocity_curves[iii*np.size(Time)+ind_t, ind_inc, ind_azimuth, ind_wavelength, :] = data_p[0] Phase_velocity_av[iii*np.size(Time)+ind_t, ind_inc, ind_azimuth, ind_wavelength, :] = data_p[1] if ref_cfg.processing.Azi_img: np.save(os.path.join(ref_cfg.sim.path, 'Angular_velocity_data_unfocus.npy'), [Angular_velocity_curves, Angular_velocity_av, si, analyse_num]) np.save(os.path.join(ref_cfg.sim.path, 'Phase_velocity_data_unfocus.npy'), [Phase_velocity_curves, Phase_velocity_av, si, analyse_num]) else: np.save(os.path.join(ref_cfg.sim.path, 'Angular_velocity_data.npy'), [Angular_velocity_curves, Angular_velocity_av, si, analyse_num]) np.save(os.path.join(ref_cfg.sim.path, 'Phase_velocity_data.npy'), [Phase_velocity_curves, Phase_velocity_av, si, analyse_num])
def postprocess_batch_sim(template_file, plots=True): cfg_file = utils.get_parFile(parfile=template_file) ref_cfg = osrio.ConfigFile(cfg_file) if cfg.processing.Azi_img: sim_path_ref = ref_cfg.sim.path + os.sep + 'Time%d_inc_s%d_azimuth_s%d' + os.sep + 'wavelength%.1f_unfocus' else: sim_path_ref = ref_cfg.sim.path + os.sep + 'Time%d_inc_s%d_azimuth_s%d' + os.sep + 'wavelength%.1f' wave_scale = ref_cfg.processing.wave_scale sim_path_ref = ref_cfg.sim.path + os.sep + 'Time%d_inc_s%d_azimuth_s%d_wavelength%1f' n_all = (np.size(Time) * np.size(inc_s) * np.size(azimuth_s) * np.size(wave_scale) * n_rep) sim_path_ref = ref_cfg.sim.path + os.sep + 'Time%d_inc_s%d_azimuth_s%d_wavelength%1f' n_all = (np.size(Time) * np.size(inc_s) * np.size(azimuth_s) * np.size(wave_scale) * n_rep) path = sim_path_ref % (Time[0], inc_s[0], azimuth_s[0], wave_scale[0]) + os.sep + 'delta_k_spectrum_plots' # Angular velocity data = np.load(os.path.join(path, 'Angular_velocity.npy')) Angular_velocity_curves = np.zeros((np.size(Time), np.size(inc_s), np.size(azimuth_s), np.size(wave_scale), int(data[2])), dtype=np.complex) Angular_velocity_av = np.zeros((np.size(Time), np.size(inc_s), np.size(azimuth_s), np.size(wave_scale), 0), dtype=np.complex) analyse_num = data[3] # Phase velocity data_p = np.load(os.path.join(path, 'Phase_velocity.npy')) Phase_velocity_curves = np.zeros((np.size(Time), np.size(inc_s), np.size(azimuth_s), np.size(wave_scale), int(data_p[2])), dtype=np.complex) Phase_velocity_av = np.zeros((np.size(Time), np.size(inc_s), np.size(azimuth_s), np.size(wave_scale), 0), dtype=np.complex) for ind_t in range(np.size(Time)): for ind_inc in range(np.size(inc_s)): for ind_azimuth in range(np.size(azimuth_s)): for ind_wavelength in range(np.size(wave_scale)): # Read data path = sim_path_ref % (Time[ind_t], inc_s[ind_inc], azimuth_s[ind_azimuth], wave_scale[ind_wavelength]) + os.sep + 'delta_k_spectrum_plots' data = np.load(os.path.join(path, 'Angular_velocity.npy')) Angular_velocity_curves[ind_t, ind_inc, ind_azimuth, ind_wavelength, :] = data[0] Angular_velocity_av[ind_t, ind_inc, ind_azimuth, ind_wavelength, :] = data[1] data_p = np.load(os.path.join(path, 'Phase_velocity.npy')) Phase_velocity_curves[ind_t, ind_inc, ind_azimuth, ind_wavelength, :] = data_p[0] Phase_velocity_av[ind_t, ind_inc, ind_azimuth, ind_wavelength, :] = data_p[1] plot_path = sim_path_ref + os.sep + 'Averaging_through_time' for ind_inc in range(np.size(inc_s)): for ind_azimuth in range(np.size(azimuth_s)): for ind_wavelength in range(np.size(wave_scale)): value = np.mean(Angular_velocity_curves[:, ind_inc, ind_azimuth, ind_wavelength, :], axis=0) av_value = np.mean( Angular_velocity_av[ind_t, ind_inc, ind_azimuth, ind_wavelength, :],axis=0) value_p = np.mean(Phase_velocity_curves[:, ind_inc, ind_azimuth, ind_wavelength, :], axis=0) av_value_p = np.mean( Phase_velocity_av[ind_t, ind_inc, ind_azimuth, ind_wavelength, :],axis=0) print(inc_s[ind_inc],'deg') print(azimuth_s[ind_azimuth],'deg') print(wave_scale[ind_wavelength],'m') print(av_value,'rad/s') print(av_value,'m/s') if plots: plt.figure() plt.plot(analyse_num, value) plt.xlabel("Azimuth interval [Pixel]") plt.ylabel("Angular velocity (rad/s)") plt.title("Incidence angle = %d deg, Azimuth angle = %d deg, wave_length = %.1f m" % (inc_s[ind_inc], azimuth_s[ind_azimuth], wave_scale[ind_wavelength])) plt.savefig(os.path.join(ref_cfg.sim.path, 'Time_averaging_angular_velocity_%d_%d_%.1f.png' % (inc_s[ind_inc], azimuth_s[ind_azimuth], wave_scale[ind_wavelength]))) plt.close() plt.figure() plt.plot(analyse_num, value_p) plt.xlabel("Azimuth interval [Pixel]") plt.ylabel("Phase velocity (m/s)") plt.title("Incidence angle = %d deg, Azimuth angle = %d deg, wave_length = %.1f m" % (inc_s[ind_inc], azimuth_s[ind_azimuth], wave_scale[ind_wavelength])) plt.savefig(os.path.join(ref_cfg.sim.path, 'Time_averaging_angular_velocity_%d_%d_%.1f.png' % (inc_s[ind_inc], azimuth_s[ind_azimuth], wave_scale[ind_wavelength]))) plt.close()
def postprocess_batch_sim(template_file, plots=True, fontsize=14, pltsymb=['o', 'D', 's', '^', 'p']): cfg_file = utils.get_parFile(parfile=template_file) ref_cfg = osrio.ConfigFile(cfg_file) step = 0 npol = (2 if ref_cfg.sar.pol == 'DP' else 1) nch = int(ref_cfg.sar.num_ch) nim = nch * npol sim_path_ref = ref_cfg.sim.path + os.sep + 'sim_U%d_wdir%d_smag%d_sdir%d_inc%d_i%i' n_all = (np.size(v_wind_U) * np.size(v_wind_dir) * np.size(v_current_mag) * np.size(v_current_dir) * np.size(v_inc_angle) * n_rep) mean_cohs = np.zeros( (np.size(v_wind_U), np.size(v_wind_dir), np.size(v_current_mag), np.size(v_current_dir), np.size(v_inc_angle), n_rep, int((nim) * (nim - 1) / 2)), dtype=np.complex) mean_abscohs = np.zeros( (np.size(v_wind_U), np.size(v_wind_dir), np.size(v_current_mag), np.size(v_current_dir), np.size(v_inc_angle), n_rep, int((nim) * (nim - 1) / 2)), dtype=np.float) nrcs = np.zeros( (np.size(v_wind_U), np.size(v_wind_dir), np.size(v_current_mag), np.size(v_current_dir), np.size(v_inc_angle), n_rep, nch * npol), dtype=np.float) v_r_dop = np.zeros( (np.size(v_wind_U), np.size(v_wind_dir), np.size(v_current_mag), np.size(v_current_dir), np.size(v_inc_angle), n_rep, npol), dtype=np.float) for ind_w_U in range(np.size(v_wind_U)): for ind_w_dir in range(np.size(v_wind_dir)): for ind_c_mag in range(np.size(v_current_mag)): for ind_c_dir in range(np.size(v_current_dir)): for ind_inc in range(np.size(v_inc_angle)): for i_rep in range(n_rep): # Read data path = sim_path_ref % (v_wind_U[ind_w_U], v_wind_dir[ind_w_dir], v_current_mag[ind_c_mag], v_current_dir[ind_c_dir], v_inc_angle[ind_inc], i_rep) try: data_filename = os.path.join( path, 'ati_stats.npz') npzfile = np.load(data_filename) mean_cohs[ind_w_U, ind_w_dir, ind_c_mag, ind_c_dir, ind_inc, i_rep] = npzfile['coh_mean'] mean_abscohs[ind_w_U, ind_w_dir, ind_c_mag, ind_c_dir, ind_inc, i_rep] = npzfile['abscoh_mean'] nrcs[ind_w_U, ind_w_dir, ind_c_mag, ind_c_dir, ind_inc, i_rep] = npzfile['nrcs'] v_r_dop[ind_w_U, ind_w_dir, ind_c_mag, ind_c_dir, ind_inc, i_rep] = npzfile['v_r_dop'] coh_lut = npzfile['coh_lut'] except OSError: print("Issues with %s" % data_filename) mean_cohs[ind_w_U, ind_w_dir, ind_c_mag, ind_c_dir, ind_inc, i_rep] = np.NaN mean_abscohs[ind_w_U, ind_w_dir, ind_c_mag, ind_c_dir, ind_inc, i_rep] = np.NaN nrcs[ind_w_U, ind_w_dir, ind_c_mag, ind_c_dir, ind_inc, i_rep] = np.NaN v_r_dop[ind_w_U, ind_w_dir, ind_c_mag, ind_c_dir, ind_inc, i_rep] = np.NaN if plots: font = {'family': "Arial", 'weight': 'normal', 'size': fontsize} mpl.rc('font', **font) plt.figure() for ind in range(np.size(v_wind_U)): plt.plot(v_wind_dir, (mean_abscohs[ind, :, 0, 0, 0, 0, 4]), pltsymb[int(np.mod(ind, len(pltsymb)))], label=("U = %2.1f" % (v_wind_U[ind]))) plt.xlabel("Wind direction w.r.t. radar LOS [deg]") plt.ylabel("$\gamma$") plt.legend(loc=0) plt.grid(True) plt.tight_layout() plt.figure() for ind in range(np.size(v_wind_U)): plt.plot(v_wind_dir, v_r_dop[ind, :, 0, 0, 0, 0, 1], pltsymb[int(np.mod(ind, len(pltsymb)))], label=("U = %2.1f" % (v_wind_U[ind]))) plt.xlabel("Wind direction w.r.t. radar LOS [deg]") plt.ylabel("$v_{Dop} [m/s]$") plt.legend(loc=0) plt.grid(True) plt.tight_layout() plt.figure() for ind in range(np.size(v_wind_U)): plt.plot(v_wind_dir, nrcs[ind, :, 0, 0, 0, 0, 1], pltsymb[int(np.mod(ind, len(pltsymb)))], label=("U = %2.1f" % (v_wind_U[ind]))) plt.xlabel("Wind direction w.r.t. radar LOS [deg]") plt.ylabel("$NRCS [dB]$") plt.legend(loc=0) plt.grid(True) plt.tight_layout() return mean_cohs, mean_abscohs, v_r_dop, nrcs, coh_lut
def surface_S(cfg_file=None, inc_deg=None, ntimes=2, t_step=10e-3): """ This function generates a (short) time series of surface realizations. :param scf_file: the full path to the configuration with all OCEANSAR parameters :param inc_deg: the incident angle, in degree :param ntimes: number of time samples generated. :param t_step: spacing between time samples. This can be interpreted as the Pulse Repetition Interval :returns: a tuple with the configuration object, the surfaces, the radial velocities for each grid point, and the complex scattering coefficients """ cfg_file = utils.get_parFile(parfile=cfg_file) cfg = io.ConfigFile(cfg_file) use_hmtf = cfg.srg.use_hmtf scat_spec_enable = cfg.srg.scat_spec_enable scat_spec_mode = cfg.srg.scat_spec_mode scat_bragg_enable = cfg.srg.scat_bragg_enable scat_bragg_model = cfg.srg.scat_bragg_model scat_bragg_d = cfg.srg.scat_bragg_d scat_bragg_spec = cfg.srg.scat_bragg_spec scat_bragg_spread = cfg.srg.scat_bragg_spread # SAR inc_angle = np.deg2rad(cfg.sar.inc_angle) alt = cfg.sar.alt f0 = cfg.sar.f0 prf = cfg.sar.prf pol = cfg.sar.pol l0 = const.c / f0 k0 = 2. * np.pi * f0 / const.c if pol == 'DP': do_hh = True do_vv = True elif pol == 'hh': do_hh = True do_vv = False else: do_hh = False do_vv = True # OCEAN / OTHERS ocean_dt = cfg.ocean.dt surface = OceanSurface() compute = ['D', 'Diff', 'Diff2', 'V'] if use_hmtf: compute.append('hMTF') surface.init(cfg.ocean.Lx, cfg.ocean.Ly, cfg.ocean.dx, cfg.ocean.dy, cfg.ocean.cutoff_wl, cfg.ocean.spec_model, cfg.ocean.spread_model, np.deg2rad(cfg.ocean.wind_dir), cfg.ocean.wind_fetch, cfg.ocean.wind_U, cfg.ocean.current_mag, np.deg2rad(cfg.ocean.current_dir), cfg.ocean.swell_enable, cfg.ocean.swell_ampl, np.deg2rad(cfg.ocean.swell_dir), cfg.ocean.swell_wl, compute, cfg.ocean.opt_res, cfg.ocean.fft_max_prime, choppy_enable=cfg.ocean.choppy_enable) # Get a surface realization calculated surface.t = 0 if inc_deg is None: inc_deg = cfg.sar.inc_angle inc_angle = np.radians(inc_deg) sr0 = geosar.inc_to_sr(inc_angle, alt) gr0 = geosar.inc_to_gr(inc_angle, alt) gr = surface.x + gr0 sr, inc, _ = geosar.gr_to_geo(gr, alt) sr -= np.min(sr) inc = inc.reshape(1, inc.size) sr = sr.reshape(1, sr.size) gr = gr.reshape(1, gr.size) sin_inc = np.sin(inc) cos_inc = np.cos(inc) t_last_rcs_bragg = -1. last_progress = -1 NRCS_avg_vv = np.zeros(ntimes, dtype=np.float) NRCS_avg_hh = np.zeros(ntimes, dtype=np.float) # RCS MODELS # Specular if scat_spec_enable: if scat_spec_mode == 'kodis': rcs_spec = rcs.RCSKodis(inc, k0, surface.dx, surface.dy) elif scat_spec_mode == 'fa' or scat_spec_mode == 'spa': spec_ph0 = np.random.uniform(0., 2. * np.pi, size=[surface.Ny, surface.Nx]) rcs_spec = rcs.RCSKA(scat_spec_mode, k0, surface.x, surface.y, surface.dx, surface.dy) else: raise NotImplementedError( 'RCS mode %s for specular scattering not implemented' % scat_spec_mode) # Bragg if scat_bragg_enable: phase_bragg = np.zeros([2, surface.Ny, surface.Nx]) bragg_scats = np.zeros([2, surface.Ny, surface.Nx], dtype=np.complex) tau_c = closure.grid_coherence(cfg.ocean.wind_U, surface.dx, f0) rndscat_p = closure.randomscat_ts(tau_c, (surface.Ny, surface.Nx), prf) rndscat_m = closure.randomscat_ts(tau_c, (surface.Ny, surface.Nx), prf) # NOTE: This ignores slope, may be changed k_b = 2. * k0 * sin_inc c_b = sin_inc * np.sqrt(const.g / k_b + 0.072e-3 * k_b) if scat_bragg_model == 'romeiser97': current_dir = np.deg2rad(cfg.ocean.current_dir) current_vec = (cfg.ocean.current_mag * np.array( [np.cos(current_dir), np.sin(current_dir)])) U_dir = np.deg2rad(cfg.ocean.wind_dir) U_vec = (cfg.ocean.wind_U * np.array([np.cos(U_dir), np.sin(U_dir)])) U_eff_vec = U_vec - current_vec rcs_bragg = rcs.RCSRomeiser97( k0, inc, pol, surface.dx, surface.dy, linalg.norm(U_eff_vec), np.arctan2(U_eff_vec[1], U_eff_vec[0]), surface.wind_fetch, scat_bragg_spec, scat_bragg_spread, scat_bragg_d) else: raise NotImplementedError( 'RCS model %s for Bragg scattering not implemented' % scat_bragg_model) surface_area = surface.dx * surface.dy * surface.Nx * surface.Ny if do_hh: scene_hh = np.zeros([ntimes, surface.Ny, surface.Nx], dtype=np.complex) if do_vv: scene_vv = np.zeros([ntimes, surface.Ny, surface.Nx], dtype=np.complex) for az_step in range(ntimes): # AZIMUTH & SURFACE UPDATE t_now = az_step * t_step # az_now = (t_now - t_span/2.)*v_ground az_now = 0 # az = np.repeat((surface.y - az_now)[:, np.newaxis], surface.Nx, axis=1) az = (surface.y - az_now).reshape((surface.Ny, 1)) surface.t = t_now ## COMPUTE RCS FOR EACH MODEL # Note: SAR processing is range independent as slant range is fixed sin_az = az / sr0 az_proj_angle = np.arcsin(az / gr0) # Note: Projected displacements are added to slant range sr_surface = (sr - cos_inc * surface.Dz + az / 2 * sin_az + surface.Dx * sin_inc + surface.Dy * sin_az) # Specular if scat_spec_enable: if scat_spec_mode == 'kodis': Esn_sp = np.sqrt(4. * np.pi) * rcs_spec.field( az_proj_angle, sr_surface, surface.Diffx, surface.Diffy, surface.Diffxx, surface.Diffyy, surface.Diffxy) if do_hh: scene_hh[az_step] += Esn_sp if do_vv: scene_vv[az_step] += Esn_sp else: # FIXME if do_hh: pol_tmp = 'hh' Esn_sp = ( np.exp(-1j * (2. * k0 * sr_surface)) * (4. * np.pi)**1.5 * rcs_spec.field( 1, 1, pol_tmp[0], pol_tmp[1], inc, inc, az_proj_angle, az_proj_angle + np.pi, surface.Dz, surface.Diffx, surface.Diffy, surface.Diffxx, surface.Diffyy, surface.Diffxy)) scene_hh[az_step] += Esn_sp if do_vv: pol_tmp = 'vv' Esn_sp = ( np.exp(-1j * (2. * k0 * sr_surface)) * (4. * np.pi)**1.5 * rcs_spec.field( 1, 1, pol_tmp[0], pol_tmp[1], inc, inc, az_proj_angle, az_proj_angle + np.pi, surface.Dz, surface.Diffx, surface.Diffy, surface.Diffxx, surface.Diffyy, surface.Diffxy)) scene_vv[az_step] += Esn_sp NRCS_avg_hh[az_step] += (np.sum(np.abs(Esn_sp)**2) / surface_area) NRCS_avg_vv[az_step] += NRCS_avg_hh[az_step] # Bragg if scat_bragg_enable: if (t_now - t_last_rcs_bragg) > ocean_dt: if scat_bragg_model == 'romeiser97': if pol == 'DP': RCS_bragg_hh, RCS_bragg_vv = rcs_bragg.rcs( az_proj_angle, surface.Diffx, surface.Diffy) elif pol == 'hh': RCS_bragg_hh = rcs_bragg.rcs(az_proj_angle, surface.Diffx, surface.Diffy) else: RCS_bragg_vv = rcs_bragg.rcs(az_proj_angle, surface.Diffx, surface.Diffy) if use_hmtf: # Fix Bad MTF points surface.hMTF[np.where(surface.hMTF < -1)] = -1 if do_hh: RCS_bragg_hh[0] *= (1 + surface.hMTF) RCS_bragg_hh[1] *= (1 + surface.hMTF) if do_vv: RCS_bragg_vv[0] *= (1 + surface.hMTF) RCS_bragg_vv[1] *= (1 + surface.hMTF) t_last_rcs_bragg = t_now if do_hh: scat_bragg_hh = np.sqrt(RCS_bragg_hh) NRCS_bragg_hh_instant_avg = np.sum(RCS_bragg_hh) / surface_area NRCS_avg_hh[az_step] += NRCS_bragg_hh_instant_avg if do_vv: scat_bragg_vv = np.sqrt(RCS_bragg_vv) NRCS_bragg_vv_instant_avg = np.sum(RCS_bragg_vv) / surface_area NRCS_avg_vv[az_step] += NRCS_bragg_vv_instant_avg # Doppler phases (Note: Bragg radial velocity taken constant!) surf_phase = -(2 * k0) * sr_surface cap_phase = (2 * k0) * t_step * c_b * (az_step + 1) phase_bragg[0] = surf_phase - cap_phase # + dop_phase_p phase_bragg[1] = surf_phase + cap_phase # + dop_phase_m bragg_scats[0] = rndscat_m.scats(t_now) bragg_scats[1] = rndscat_p.scats(t_now) if do_hh: scene_hh[az_step] += ne.evaluate( 'sum(scat_bragg_hh * exp(1j*phase_bragg) * bragg_scats, axis=0)' ) if do_vv: scene_vv[az_step] += ne.evaluate( 'sum(scat_bragg_vv * exp(1j*phase_bragg) * bragg_scats, axis=0)' ) v_r = (surface.Vx * np.sin(inc) - surface.Vz * np.cos(inc)) if do_hh and do_vv: return (cfg, surface.Dz, v_r, scene_hh, scene_vv) elif do_hh: return (cfg, surface.Dz, v_r, scene_hh) else: return (cfg, surface.Dz, v_r, scene_vv)
def __init__(self, cfg_file=None, ntimes=2, t_step=10e-3, pol='DP', winddir=0, U10=None, po_model=None): """ This function generates a (short) time series of surface realizations. :param scf_file: the full path to the configuration with all OCEANSAR parameters :param ntimes: number of time samples generated. :param t_step: spacing between time samples. This can be interpreted as the Pulse Repetition Interval :param wind:dir: to force wind direction :param U10: to force wind force :param po_model: one of None, spa (stationary phase approximation, or facet approach) :returns: a tuple with the configuration object, the surfaces, the radial velocities for each grid point, and the complex scattering coefficients """ cfg_file = utils.get_parFile(parfile=cfg_file) cfg = ocs_io.ConfigFile(cfg_file) self.cfg = cfg self.use_hmtf = cfg.srg.use_hmtf self.scat_spec_enable = cfg.srg.scat_spec_enable if po_model is None: self.scat_spec_mode = cfg.srg.scat_spec_mode else: self.scat_spec_mode = po_model self.scat_bragg_enable = cfg.srg.scat_bragg_enable self.scat_bragg_model = cfg.srg.scat_bragg_model self.scat_bragg_d = cfg.srg.scat_bragg_d self.scat_bragg_spec = cfg.srg.scat_bragg_spec self.scat_bragg_spread = cfg.srg.scat_bragg_spread # SAR try: radcfg = cfg.sar except AttributeError: radcfg = cfg.radar self.inc_angle = np.deg2rad(radcfg.inc_angle) self.alt = radcfg.alt self.f0 = radcfg.f0 self.prf = radcfg.prf if pol is None: self.pol = radcfg.pol else: self.pol = pol l0 = const.c / self.f0 k0 = 2. * np.pi * self.f0 / const.c if self.pol == 'DP': self.do_hh = True self.do_vv = True elif self.pol == 'hh': self.do_hh = True self.do_vv = False else: self.do_hh = False self.do_vv = True # OCEAN / OTHERS ocean_dt = cfg.ocean.dt self.surface = OceanSurface() compute = ['D', 'Diff', 'Diff2', 'V'] print("Initializating surface") if winddir is not None: self.wind_dir = np.radians(winddir) else: self.wind_dir = np.deg2rad(cfg.ocean.wind_dir) if U10 is None: self.wind_u = cfg.ocean.wind_U else: self.wind_u = U10 if self.use_hmtf: compute.append('hMTF') self.surface.init(cfg.ocean.Lx, cfg.ocean.Ly, cfg.ocean.dx, cfg.ocean.dy, cfg.ocean.cutoff_wl, cfg.ocean.spec_model, cfg.ocean.spread_model, self.wind_dir, cfg.ocean.wind_fetch, self.wind_u, cfg.ocean.current_mag, np.deg2rad(cfg.ocean.current_dir), cfg.ocean.swell_enable, cfg.ocean.swell_ampl, np.deg2rad(cfg.ocean.swell_dir), cfg.ocean.swell_wl, compute, cfg.ocean.opt_res, cfg.ocean.fft_max_prime, choppy_enable=cfg.ocean.choppy_enable) # Get a surface realization calculated print("Computing surface realizations") self.surface.t = 0 self.ntimes = ntimes self.diffx = np.zeros((ntimes, self.surface.Ny, self.surface.Nx)) self.diffy = np.zeros((ntimes, self.surface.Ny, self.surface.Nx)) self.diffxx = np.zeros((ntimes, self.surface.Ny, self.surface.Nx)) self.diffxy = np.zeros((ntimes, self.surface.Ny, self.surface.Nx)) self.diffyy = np.zeros((ntimes, self.surface.Ny, self.surface.Nx)) self.dx = np.zeros((ntimes, self.surface.Ny, self.surface.Nx)) self.dy = np.zeros((ntimes, self.surface.Ny, self.surface.Nx)) self.dz = np.zeros((ntimes, self.surface.Ny, self.surface.Nx)) self.diffx[0, :, :] = self.surface.Diffx self.diffy[0, :, :] = self.surface.Diffy self.diffxx[0, :, :] = self.surface.Diffxx self.diffyy[0, :, :] = self.surface.Diffyy self.diffxy[0, :, :] = self.surface.Diffxy self.dx[0, :, :] = self.surface.Dx self.dy[0, :, :] = self.surface.Dy self.dz[0, :, :] = self.surface.Dz if self.use_hmtf: self.h_mtf = np.zeros((ntimes, self.surface.Ny, self.surface.Nx)) self.h_mtf[0, :, :] = self.surface.hMTF self.t_step = t_step for az_step in range(1, ntimes): t_now = az_step * t_step self.surface.t = t_now self.diffx[az_step, :, :] = self.surface.Diffx self.diffy[az_step, :, :] = self.surface.Diffy self.diffxx[az_step, :, :] = self.surface.Diffxx self.diffyy[az_step, :, :] = self.surface.Diffyy self.diffxy[az_step, :, :] = self.surface.Diffxy self.dx[az_step, :, :] = self.surface.Dx self.dy[az_step, :, :] = self.surface.Dy self.dz[az_step, :, :] = self.surface.Dz if self.use_hmtf: self.h_mtf[az_step, :, :] = self.surface.hMTF self.inc_is_set = False
def postprocess_batch_sim(template_file, plots=True): cfg_file = utils.get_parFile(parfile=template_file) ref_cfg = osrio.ConfigFile(cfg_file)
wave_scale = [100, 37.5, 25, 12.5] #wave_scale = [100, 37.5, 25, 12.5] <<<<<<< HEAD >>>>>>> parent of 60eb239... Delete oceansar_batchsarsim_skim.py ======= >>>>>>> parent of 60eb239... Delete oceansar_batchsarsim_skim.py n_rep = 1 cfg_file_name = 'config.cfg' def batch_skimsim(template_file): <<<<<<< HEAD <<<<<<< HEAD for iii in range(np.size(No)): cfg_file = utils.get_parFile(parfile=template_file) ref_cfg = osrio.ConfigFile(cfg_file) path_m = ref_cfg.sim.path + os.sep + 'SKIM_12deg_rar_%d'%(No[iii]) sim_path_ref = path_m + os.sep + 'Time%d_inc_s%d_azimuth_s%d' for t in Time: for inc_angle in inc_s: for azimuth in azimuth_s: ### CONFIGURATION FILE ### # Load template cfg = ref_cfg # Modify template, create directory & save cfg.sim.path = sim_path_ref % (t, inc_angle, azimuth) cfg.batch_Loop.t = t
def surface_rel(cfg_file=None, inc_deg=None, ntimes=2, t_step=10e-3): """ This function generates a (short) time series of surface realizations. :param scf_file: the full path to the configuration with all OCEANSAR parameters :param inc_deg: the incident angle, in degree :param ntimes: number of time samples generated. :param t_step: spacing between time samples. This can be interpreted as the Pulse Repetition Interval :returns: a tuple with the configuration object, the surfaces, the radial velocities for each grid point, and the complex scattering coefficients """ cfg_file = utils.get_parFile(parfile=cfg_file) cfg = ocs_io.ConfigFile(cfg_file) use_hmtf = cfg.srg.use_hmtf scat_spec_enable = cfg.srg.scat_spec_enable scat_spec_mode = cfg.srg.scat_spec_mode scat_bragg_enable = cfg.srg.scat_bragg_enable scat_bragg_model = cfg.srg.scat_bragg_model scat_bragg_d = cfg.srg.scat_bragg_d scat_bragg_spec = cfg.srg.scat_bragg_spec scat_bragg_spread = cfg.srg.scat_bragg_spread # SAR inc_angle = np.deg2rad(cfg.sar.inc_angle) alt = cfg.sar.alt f0 = cfg.sar.f0 prf = cfg.sar.prf pol = cfg.sar.pol l0 = const.c / f0 k0 = 2. * np.pi * f0 / const.c if pol == 'DP': do_hh = True do_vv = True elif pol == 'hh': do_hh = True do_vv = False else: do_hh = False do_vv = True # OCEAN / OTHERS ocean_dt = cfg.ocean.dt surface = OceanSurface() compute = ['D', 'Diff', 'Diff2', 'V', 'A'] if use_hmtf: compute.append('hMTF') surface.init(cfg.ocean.Lx, cfg.ocean.Ly, cfg.ocean.dx, cfg.ocean.dy, cfg.ocean.cutoff_wl, cfg.ocean.spec_model, cfg.ocean.spread_model, np.deg2rad(cfg.ocean.wind_dir), cfg.ocean.wind_fetch, cfg.ocean.wind_U, cfg.ocean.current_mag, np.deg2rad(cfg.ocean.current_dir), 0, 0, 0, 0, 0, False, cfg.ocean.swell_enable, cfg.ocean.swell_ampl, np.deg2rad(cfg.ocean.swell_dir), cfg.ocean.swell_wl, compute, cfg.ocean.opt_res, cfg.ocean.fft_max_prime, choppy_enable=cfg.ocean.choppy_enable) # Get a surface realization calculated surface.t = 0 return surface
cfg.ocean.dy, cfg.ocean.cutoff_wl, cfg.ocean.spec_model, cfg.ocean.spread_model, np.deg2rad(cfg.ocean.wind_dir), cfg.ocean.wind_fetch, cfg.ocean.wind_U, cfg.ocean.current_mag, np.deg2rad(cfg.ocean.current_dir), 0, 0, 0, 0, 0, False, cfg.ocean.swell_enable, cfg.ocean.swell_ampl, np.deg2rad(cfg.ocean.swell_dir), cfg.ocean.swell_wl, compute, cfg.ocean.opt_res, cfg.ocean.fft_max_prime, choppy_enable=cfg.ocean.choppy_enable) # Get a surface realization calculated surface.t = 0 return surface if __name__ == '__main__': cfg_file = utils.get_parFile(parfile=None) surface = surface_rel(cfg_file)