def _func_all_year_uv(self): # generated 12 all year time, and calculate u,v date = ut.mjd_2_time(self.start_mjd) year = date[1] month = date[2] for _ in range(0, 12): # generate time if month > 13: year += 1 month -= 12 temp_start = ut.time_2_mjd(year, month, 1, 0, 0, 0, 0) temp_end = ut.time_2_mjd(year, month, 2, 0, 0, 0, 0) else: temp_start = ut.time_2_mjd(year, month, 1, 0, 0, 0, 0) temp_end = ut.time_2_mjd(year, month, 2, 0, 0, 0, 0) month += 1 temp_u, temp_v, temp_max = self._get_reset_time_info( temp_start, temp_end, self.time_step) self.result_time_u.append(temp_u) self.result_time_v.append(temp_v) # calculate max {u,v} if self.max_range_time_uv < temp_max: self.max_range_time_uv = temp_max
def run_muiltisrc_survey(): # 1. initialize parse args = parse_args() # for test in ide # args.show_info = True # 1.1 config file if args.config != '': my_config_parser = SurveyConfigParser(args.config) else: my_config_parser = SurveyConfigParser() # 1.2 img type img_type = 'pdf' if args.img_fmt in ['eps', 'png', 'pdf', 'svg', 'ps']: img_type = args.img_fmt # 1.3 output path path_dir_out_pre = os.path.join(os.path.join(os.getcwd(), 'OUTPUT'), 'survey_all') path_dir_out = os.path.join(path_dir_out_pre, time.ctime()) if not os.path.exists(path_dir_out): os.mkdir(path_dir_out) # 1.4 print parameters or not is_show_para = False if args.show_info: is_show_para = True # 1.5 save uv data or not is_save_uv = False if args.save_uv: is_save_uv = True # 1.6 specify process num num_procs = 0 args_num_procs = str(args.num_procs) if args_num_procs.isdigit(): num_procs = int(args_num_procs) # 1.7 colormap # colormap = 'viridis' # if args.color_map in ['viridis', 'hot', 'jet', 'rainbow', 'Greys', 'cool', 'nipy_spectral']: # colormap = args.color_map colormap = my_config_parser.color_map_name # 2. config objects start_time = ut.time_2_mjd(*my_config_parser.time_start, 0) stop_time = ut.time_2_mjd(*my_config_parser.time_end, 0) time_step = ut.time_2_day(*my_config_parser.time_step) myFuncSurvey = FuncSurvey( start_time, stop_time, time_step, my_config_parser.pos_mat_src[0], my_config_parser.pos_mat_src, my_config_parser.pos_mat_sat, my_config_parser.pos_mat_vlbi, my_config_parser.pos_mat_telemetry, my_config_parser.obs_freq, my_config_parser.baseline_type, my_config_parser.unit_flag, my_config_parser.cutoff_angle, my_config_parser.precession_mode, my_config_parser.source_model, my_config_parser.n_pix, True, my_config_parser.clean_gain, my_config_parser.clean_threshold, my_config_parser.clean_niter, path_dir_out, is_show_para, is_save_uv, num_procs, colormap, img_type) # 3. run survey myFuncSurvey.run_survey_all()
def _prepare_args_for_multiprocess(self): # 1. prepare args for subprocess # 1.1 for multi src self.sp_args_srcs = [] for i in range(self.myFuncUv.src_num): tmp_name = self.myFuncUv.pos_multi_src[i][0] tmp_ra = self.myFuncUv.pos_multi_src[i][1] tmp_dec = self.myFuncUv.pos_multi_src[i][2] self.sp_args_srcs.append([tmp_name, tmp_ra, tmp_dec]) # 1.2 for all sky self.sp_args_sky = [] index = 0 for i in (2, 6, 10, 14, 18, 22): # dra for j in (-60, -30, 0, 30, 60): # dra ra = ut.time_2_rad(i, 0, 0) dec = ut.angle_2_rad(j, 0, 0) pos_src = ['source-%d' % (index), ra, dec] index = index + 1 self.sp_args_sky.append(pos_src) # 1.3 for all year self.sp_args_year = [] date = ut.mjd_2_time(self.myFuncUv.start_mjd) year, month = date[1], date[2] for i in range(0, 12): # generate time if month > 13: year += 1 month -= 12 temp_start = ut.time_2_mjd(year, month, 1, 0, 0, 0, 0) temp_end = ut.time_2_mjd(year, month, 2, 0, 0, 0, 0) else: temp_start = ut.time_2_mjd(year, month, 1, 0, 0, 0, 0) temp_end = ut.time_2_mjd(year, month, 2, 0, 0, 0, 0) month += 1 time_id_str = "year-{}".format(i) self.sp_args_year.append( [temp_start, temp_end, self.myFuncUv.time_step, time_id_str])
def run_obs(): # 1. initialize parse and config objects args = parse_args() # args.save_az_el = True # args.obs_info = True # args.show_gui = True if args.config != '': my_config_parser = ObsConfigParser(args.config) else: my_config_parser = ObsConfigParser() # output file path img_type = 'pdf' if args.img_fmt in ['eps', 'png', 'pdf', 'svg', 'ps']: img_type = args.img_fmt save_az_el_name = "az-el:" + time.asctime() + '.' + img_type path_az_el = os.path.join(os.path.join(os.getcwd(), 'OUTPUT'), 'obs_ability') path_az_el = os.path.join(path_az_el, save_az_el_name) save_sky_name = "sky-survey:" + time.asctime() + '.' + img_type path_sky_survey = os.path.join(os.path.join(os.getcwd(), 'OUTPUT'), 'obs_ability') path_sky_survey = os.path.join(path_sky_survey, save_sky_name) # mjd time start_time = ut.time_2_mjd(*my_config_parser.time_start, 0) stop_time = ut.time_2_mjd(*my_config_parser.time_end, 0) time_step = ut.time_2_day(*my_config_parser.time_step) cutoff_dict = { "flag": lc.cutoff_mode["flag"], "CutAngle": my_config_parser.cutoff_angle } myFuncObs = FuncObs( start_time, stop_time, time_step, my_config_parser.pos_mat_src[0], my_config_parser.pos_mat_vlbi, my_config_parser.pos_mat_sat, my_config_parser.pos_mat_telemetry, my_config_parser.baseline_type, cutoff_dict, my_config_parser.precession_mode) # 2. calculate az - el azimuth, elevation, hour_lst = myFuncObs.get_result_az_el_with_update() gs_lst = myFuncObs.get_result_name_gs() x_hour_lmt = max(hour_lst[0]) if x_hour_lmt > 24: x_hour_lmt = 24 # save az-el data if args.save_az_el: name = "el-data:" + time.asctime() + '.txt' data_path = os.path.join(os.path.join(os.getcwd(), 'OUTPUT'), 'obs_ability') data_path = os.path.join(data_path, name) # np.savetxt(data_path, [azimuth, elevation], fmt='%0.4f') np.savetxt(data_path, elevation) # 3. calculate optimal interval optimal_inter, sta_best_inters, sta_best_durations, sta_all_inter = myFuncObs.get_result_best_obs_time_el( ) optimal_time_str = myFuncObs.get_result_best_time_string_after_func_best_obs( ) # 4. show optimal observation time if args.obs_info: print("optimal observation interval is :", optimal_inter) print(optimal_time_str) # 5. draw az-el fig1 = plt.figure(num=1, figsize=(8, 8)) # draw az ax1_1 = fig1.add_subplot(211) for i in np.arange(0, len(azimuth)): az1 = azimuth[i] h1 = hour_lst[i] ax1_1.plot(h1, az1, '.-', markersize=1, label=gs_lst[i]) ax1_1.set_xlim(0, x_hour_lmt) ax1_1.set_xlabel("Time(h)") ax1_1.set_ylabel("Azimuth($^\circ$)") ax1_1.set_title("The azimuth of source in VLBI stations") # draw el ax1_2 = fig1.add_subplot(212) for i in np.arange(0, len(elevation)): el1 = elevation[i] h1 = hour_lst[i] ax1_2.plot(h1, el1, '.-', markersize=1, label=gs_lst[i]) ax1_2.set_xlim(0, x_hour_lmt) ax1_2.set_xlabel("Time(h)") ax1_2.set_ylabel("Elevation($^\circ$)") ax1_2.set_title("The elevation of source in VLBI stations") plt.legend(loc="best") tmp_cut = myFuncObs.get_cutoff_angle() ax1_2.plot([hour_lst[0][0], hour_lst[0][-1]], [tmp_cut, tmp_cut], '--k') # draw optimal time interval rect = plt.Rectangle((optimal_inter[0], 0), optimal_inter[1] - optimal_inter[0], 90, color='r', alpha=0.5) ax1_2.add_patch(rect) # plt.gca().add_patch(rect) fig1.tight_layout() # save img plt.savefig(path_az_el) # 6. calculate sky survey pos_sun, pos_moon, num_array = myFuncObs.get_result_sky_survey_with_update( ) # 7. draw survey fig2 = plt.figure(num=2, figsize=(10, 8)) fig2.add_subplot(111) array_max = np.max(num_array) bounds = np.arange(0, array_max + 1, 1) ax = pl.pcolor(num_array, edgecolors=(0.5, 0.5, 0.5), linewidths=1) fig2.colorbar(ax, ticks=bounds, shrink=1) plt.yticks([0, 24, 36, 48, 72], [-90, -30, 0, 30, 90]) plt.xticks([0, 16, 32, 48, 64, 80, 96], [0, 4, 8, 12, 16, 20, 24]) plt.plot([48, 48], [0, 72], color='black', linewidth=0.8, linestyle='-.', alpha=0.4) plt.plot([0, 96], [36, 36], color='black', linewidth=0.8, linestyle='-.', alpha=0.4) plt.xlabel("RA(H)") plt.ylabel(r'Dec ($^\circ$)') plt.title("SKY SURVEY") # draw soon, moon plt.plot(pos_sun[0], pos_sun[1], color='red', marker='o', markerfacecolor=(1, 0, 0), alpha=1, markersize=20) plt.plot(pos_moon[0], pos_moon[1], color='blue', marker='o', markerfacecolor='w', alpha=1, markersize=10) # save img plt.savefig(path_sky_survey) if args.show_gui: plt.show()
def run_img(): # 1.initialize parse and config objects args = parse_args() # for test in ide # args.show_img = True # args.group_img = True # args.show_info = True if args.config != '': my_config_parser = ImgConfigParser(args.config) else: my_config_parser = ImgConfigParser() # 2. show-image parameters # colormap = 'viridis' # if args.color_map in ['viridis', 'hot', 'jet', 'rainbow', 'Greys', 'cool', 'nipy_spectral']: # colormap = args.color_map colormap = my_config_parser.color_map_name gamma = 0.3 set_clean_window = True # norm = mpl.colors.Normalize(vmin=0, vmax=1) # 3. results data data_u, data_v = [], [] max_uv = 0 data_img_src, data_img_bm, data_img_map, data_img_cbm, data_img_cmap = 0, 0, 0, 0, 0 data_img_range = 0 # 4. u,v use_uv_file = False uv_file_path = '' if args.uv_file != "": uv_file_name = args.uv_file uv_file_path = os.path.join(os.getcwd(), uv_file_name) if os.path.exists(uv_file_path): use_uv_file = True if use_uv_file: read_in = np.loadtxt(uv_file_path, dtype=np.float32) # my Func_uv.py will save u,v data in row fashion data_u, data_v = read_in[0], read_in[1] max_uv = max(np.max(np.abs(data_u)), np.max(np.abs(data_v))) else: start_time = ut.time_2_mjd(*my_config_parser.time_start, 0) stop_time = ut.time_2_mjd(*my_config_parser.time_end, 0) time_step = ut.time_2_day(*my_config_parser.time_step) cutoff_dict = { "flag": lc.cutoff_mode["flag"], "CutAngle": my_config_parser.cutoff_angle } myFuncUV = FuncUv( start_time, stop_time, time_step, my_config_parser.pos_mat_src[0], my_config_parser.pos_mat_src, my_config_parser.pos_mat_sat, my_config_parser.pos_mat_vlbi, my_config_parser.pos_mat_telemetry, my_config_parser.obs_freq, my_config_parser.baseline_type, my_config_parser.unit_flag, cutoff_dict, my_config_parser.precession_mode) data_u, data_v, max_uv = myFuncUV.get_result_single_uv_with_update() # 5. img calculation if len(data_u) == 0 or len(data_v) == 0: print("U,V data is not properly configured!") return # 5.1 initialize FuncImg object myFuncImg = FuncImg(my_config_parser.source_model, my_config_parser.n_pix, data_u, data_v, max_uv, my_config_parser.obs_freq, set_clean_window, my_config_parser.clean_gain, my_config_parser.clean_threshold, my_config_parser.clean_niter, my_config_parser.unit_flag) # 5.2 src model data_img_src, data_img_range = myFuncImg.get_result_src_model_with_update() # 5.3 dirty beam data_img_bm = myFuncImg.get_result_dirty_beam_with_update() # 5.4 dirty map data_img_map = myFuncImg.get_result_dirty_map_with_update() # 5.5 clean map, resual map, clean beam data_img_cmap, data_img_res, data_pure_point, data_img_cbm = myFuncImg.get_result_clean_map_with_update( ) data_img_range = myFuncImg.get_result_img_range() show_range = data_img_range // 2 # 7. show parameter info if args.show_info: print(myFuncImg.show_result_para_cal()) # 8. Imaging img_type = 'pdf' if args.img_fmt in ['eps', 'png', 'pdf', 'svg', 'ps']: img_type = args.img_fmt # 8.1 specify img type and output directory img_out_path = os.path.join(os.path.join(os.getcwd(), 'OUTPUT'), 'imaging') path_time_str = time.asctime() path_save_uv = os.path.join(img_out_path, "uv-{}.{}".format(path_time_str, img_type)) path_save_bm = os.path.join( img_out_path, "dirty-beam-{}.{}".format(path_time_str, img_type)) path_save_cbm = os.path.join( img_out_path, "clean-beam-{}.{}".format(path_time_str, img_type)) path_save_src = os.path.join( img_out_path, "src-model-{}.{}".format(path_time_str, img_type)) path_save_map = os.path.join( img_out_path, "dirty-map-{}.{}".format(path_time_str, img_type)) path_save_cmap = os.path.join( img_out_path, "clean-map-{}.{}".format(path_time_str, img_type)) path_save_integrate = os.path.join( img_out_path, "Integrated-all-{}.{}".format(path_time_str, img_type)) # 8.2 draw imgs if args.group_img: figs = plt.figure(figsize=(8, 4)) # 1) u,v fig_uv = figs.add_subplot(231, aspect='equal') x = np.array(data_u) y = np.array(data_v) max_range = max_uv * 1.1 fig_uv.scatter(x, y, s=1, marker='.', color='brown') fig_uv.set_xlim([-max_range, max_range]) fig_uv.set_ylim([-max_range, max_range]) fig_uv.set_title("UV Plot: %s" % my_config_parser.str_source[0]) if my_config_parser.unit_flag == 'km': fig_uv.set_xlabel("u$(km)$") fig_uv.set_ylabel("v$(km)$") else: fig_uv.set_xlabel("u$(\lambda)$") fig_uv.set_ylabel("v$(\lambda)$") fig_uv.grid() # set science fig_uv.yaxis.get_major_formatter().set_powerlimits((0, 1)) fig_uv.xaxis.get_major_formatter().set_powerlimits((0, 1)) # 2) dirty beam fig_bm = figs.add_subplot(232, aspect='equal') plot_beam = fig_bm.imshow(data_img_bm, origin='lower', aspect='equal', picker=True, interpolation='nearest', cmap=colormap, norm=norm) plt.setp(plot_beam, extent=(-show_range, show_range, -show_range, show_range)) fig_bm.set_xlabel('Relative RA (mas)') fig_bm.set_ylabel('Relative DEC (mas)') fig_bm.set_title('DIRTY BEAM') # 3) clean beam fig_cbm = figs.add_subplot(233, aspect='equal') plot_cbeam = fig_cbm.imshow(data_img_cbm, origin='lower', aspect='equal', picker=True, interpolation='nearest', cmap=colormap, norm=norm) plt.setp(plot_cbeam, extent=(-show_range, show_range, -show_range, show_range)) fig_cbm.set_xlabel('Relative RA (mas)') fig_cbm.set_ylabel('Relative DEC (mas)') fig_cbm.set_title('CLEAN BEAM') figs.colorbar(plot_cbeam, shrink=0.9) # 4) src model fig_model = figs.add_subplot(234, aspect='equal') plot_model = fig_model.imshow(np.power(data_img_src, gamma), origin='lower', aspect='equal', picker=True, cmap=colormap, norm=norm) plt.setp(plot_model, extent=(-show_range, show_range, -show_range, show_range)) fig_model.set_xlabel('Relative RA (mas)') fig_model.set_ylabel('Relative DEC (mas)') fig_model.set_title('MODEL IMAGE') # 5) dirty map fig_map = figs.add_subplot(235, aspect='equal') plot_map = fig_map.imshow(data_img_map, origin='lower', aspect='equal', cmap=colormap, norm=norm) plt.setp(plot_map, extent=(-show_range, show_range, -show_range, show_range)) fig_map.set_xlabel('Relative RA (mas)') fig_map.set_ylabel('Relative DEC (mas)') fig_map.set_title('DIRTY IMAGE') # 6) clean map fig_cmap = figs.add_subplot(236, aspect='equal') plot_cmap = fig_cmap.imshow(data_img_cmap, origin='lower', aspect='equal', picker=True, interpolation='nearest', cmap=colormap, norm=norm) plt.setp(plot_cmap, extent=(-show_range, show_range, -show_range, show_range)) fig_cmap.set_xlabel('Relative RA (mas)') fig_cmap.set_ylabel('Relative DEC (mas)') fig_cmap.set_title('CLEAN IMAGE') figs.colorbar(plot_cmap, shrink=0.9) figs.tight_layout() plt.savefig(path_save_integrate) else: # 1) u,v fig1 = plt.figure(figsize=(4, 4)) fig_uv = fig1.add_subplot(111, aspect='equal') x = np.array(data_u) y = np.array(data_v) max_range = max_uv * 1.1 fig_uv.scatter(x, y, s=1, marker='.', color='brown') fig_uv.set_xlim([-max_range, max_range]) fig_uv.set_ylim([-max_range, max_range]) fig_uv.set_title("UV Plot: %s" % my_config_parser.str_source[0]) if my_config_parser.unit_flag == 'km': fig_uv.set_xlabel("u$(km)$") fig_uv.set_ylabel("v$(km)$") else: fig_uv.set_xlabel("u$(\lambda)$") fig_uv.set_ylabel("v$(\lambda)$") fig_uv.grid() # set science fig_uv.yaxis.get_major_formatter().set_powerlimits((0, 1)) fig_uv.xaxis.get_major_formatter().set_powerlimits((0, 1)) # save uv plt.savefig(path_save_uv) # 2) dirty beam fig2 = plt.figure(figsize=(4, 4)) fig_bm = fig2.add_subplot(111, aspect='equal') # plot_beam = fig_bm.imshow(data_img_bm, origin='lower', aspect='equal', vmin=-0, vmax=1.0, cmap=colormap) # plot_beam = fig_bm.imshow(data_img_bm, picker=True, cmap=colormap, norm=norm) # interpolation='nearest', plot_beam = fig_bm.imshow(data_img_bm, origin='lower', aspect='equal', cmap=colormap, norm=norm) plt.setp(plot_beam, extent=(-show_range, show_range, -show_range, show_range)) fig_bm.set_xlabel('Relative RA (mas)') fig_bm.set_ylabel('Relative DEC (mas)') fig_bm.set_title('DIRTY BEAM') fig2.colorbar(plot_beam, shrink=0.9) plt.savefig(path_save_bm) # 3) clean beam fig3 = plt.figure(figsize=(4, 4)) fig_cbm = fig3.add_subplot(111, aspect='equal') plot_cbeam = fig_cbm.imshow(data_img_cbm, origin='lower', aspect='equal', picker=True, interpolation='nearest', cmap=colormap, norm=norm) plt.setp(plot_cbeam, extent=(-show_range, show_range, -show_range, show_range)) fig_cbm.set_xlabel('Relative RA (mas)') fig_cbm.set_ylabel('Relative DEC (mas)') fig_cbm.set_title('CLEAN BEAM') fig3.colorbar(plot_cbeam, shrink=0.9) plt.savefig(path_save_cbm) # 4) src model fig4 = plt.figure(figsize=(4, 4)) fig_model = fig4.add_subplot(111, aspect='equal') plot_model = fig_model.imshow(np.power(data_img_src, gamma), origin='lower', aspect='equal', picker=True, cmap=colormap, norm=norm) plt.setp(plot_model, extent=(-show_range, show_range, -show_range, show_range)) fig_model.set_xlabel('Relative RA (mas)') fig_model.set_ylabel('Relative DEC (mas)') fig_model.set_title('MODEL IMAGE') fig4.colorbar(plot_model, shrink=0.9) plt.savefig(path_save_src) # 5) dirty map fig5 = plt.figure(figsize=(4, 4)) fig_map = fig5.add_subplot(111, aspect='equal') plot_map = fig_map.imshow(data_img_map, origin='lower', aspect='equal', cmap=colormap, norm=norm) plt.setp(plot_map, extent=(-show_range, show_range, -show_range, show_range)) fig_map.set_xlabel('Relative RA (mas)') fig_map.set_ylabel('Relative DEC (mas)') fig_map.set_title('DIRTY IMAGE') fig5.colorbar(plot_map, shrink=0.9) plt.savefig(path_save_map) # 6) clean map fig6 = plt.figure(figsize=(4, 4)) fig_cmap = fig6.add_subplot(111, aspect='equal') plot_cmap = fig_cmap.imshow(data_img_cmap, origin='lower', aspect='equal', picker=True, interpolation='nearest', cmap=colormap, norm=norm) plt.setp(plot_cmap, extent=(-show_range, show_range, -show_range, show_range)) fig_cmap.set_xlabel('Relative RA (mas)') fig_cmap.set_ylabel('Relative DEC (mas)') fig_cmap.set_title('CLEAN IMAGE') fig6.colorbar(plot_cmap, shrink=0.9) plt.savefig(path_save_cmap) if args.show_img: plt.show()
def run_uv_basic(): # initialize parse and config objects args = parse_args() # for test in ide # args.img_info = True # args.show_gui = True if args.config != '': my_config_parser = UVConfigParser(args.config) else: my_config_parser = UVConfigParser() # print(my_config_parser.show_info()) start_time = ut.time_2_mjd(*my_config_parser.time_start, 0) stop_time = ut.time_2_mjd(*my_config_parser.time_end, 0) time_step = ut.time_2_day(*my_config_parser.time_step) # invoke the calculation functions cutoff_dict = { "flag": lc.cutoff_mode["flag"], "CutAngle": my_config_parser.cutoff_angle } myFuncUV = FuncUv( start_time, stop_time, time_step, my_config_parser.pos_mat_src[0], my_config_parser.pos_mat_src, my_config_parser.pos_mat_sat, my_config_parser.pos_mat_vlbi, my_config_parser.pos_mat_telemetry, my_config_parser.obs_freq, my_config_parser.baseline_type, my_config_parser.unit_flag, cutoff_dict, my_config_parser.precession_mode) # calculate u and v x, y, max_xy = myFuncUV.get_result_single_uv_with_update() # create the imgs fig = plt.figure(figsize=(8, 8)) ax = plt.subplot(111, aspect='equal') if x is not None and y is not None: x = np.array(x) y = np.array(y) max_range = max_xy * 1.1 ax.scatter(x, y, s=1, marker='.', color='brown') ax.set_xlim([-max_range, max_range]) ax.set_ylim([-max_range, max_range]) ax.set_title("UV Plot: %s" % my_config_parser.str_source[0]) if my_config_parser.unit_flag == 'km': ax.set_xlabel("u$(km)$") ax.set_ylabel("v$(km)$") else: ax.set_xlabel("u$(\lambda)$") ax.set_ylabel("v$(\lambda)$") ax.grid() # set science ax.yaxis.get_major_formatter().set_powerlimits((0, 1)) ax.xaxis.get_major_formatter().set_powerlimits((0, 1)) # save uv data if args.save_uv: name = "uvdata" + time.asctime() + '.txt' uv_path = os.path.join(os.path.join(os.getcwd(), 'OUTPUT'), 'uv_basic') uv_path = os.path.join(uv_path, name) np.savetxt(uv_path, [x, y], fmt='%0.4f') # read_in = np.loadtxt(uv_path,dtype=np.float32) # show calculating info if args.img_info: e_bpa, e_bmin, max_bl = myFuncUV._calculate_beam_size() print('e_bpa={} degree, e_bmin = {} mas, max_baseline = {}'.format( e_bpa, e_bmin, max_bl)) # save uv img img_type = 'pdf' if args.img_fmt in ['eps', 'png', 'pdf', 'svg', 'ps']: img_type = args.img_fmt if args.img_name == "bytime": name = "uv-" + time.asctime() + '.' + img_type uv_path = os.path.join(os.path.join(os.getcwd(), 'OUTPUT'), 'uv_basic') uv_path = os.path.join(uv_path, name) plt.savefig(uv_path) else: name = args.img_name + '.' + img_type uv_path = os.path.join(os.path.join(os.getcwd(), 'OUTPUT'), 'uv_basic') uv_path = os.path.join(uv_path, name) plt.savefig(uv_path) # show uv img if args.show_gui: plt.show()
def run_uv_advanced_single_process(is_show_gui=True): # 1. initialize parse and config objects args = parse_args() if args.config != '': my_config_parser = UVConfigParser(args.config) else: my_config_parser = UVConfigParser() start_time = ut.time_2_mjd(*my_config_parser.time_start, 0) stop_time = ut.time_2_mjd(*my_config_parser.time_end, 0) time_step = ut.time_2_day(*my_config_parser.time_step) # invoke the calculation functions cutoff_dict = { "flag": lc.cutoff_mode["flag"], "CutAngle": my_config_parser.cutoff_angle } myFuncUV = FuncUv( start_time, stop_time, time_step, my_config_parser.pos_mat_src[0], my_config_parser.pos_mat_src, my_config_parser.pos_mat_sat, my_config_parser.pos_mat_vlbi, my_config_parser.pos_mat_telemetry, my_config_parser.obs_freq, my_config_parser.baseline_type, my_config_parser.unit_flag, cutoff_dict, my_config_parser.precession_mode) # do calculations run_time_start = time.time() run_result_sky_u, run_result_sky_v, run_result_sky_max_range = myFuncUV.get_result_sky_uv_with_update( ) run_result_src_name, run_result_src_u, run_result_src_v, run_result_src_max_range = myFuncUV.get_result_multi_src_with_update( ) run_time_end = time.time() # draw sky uv plt.figure() if len(run_result_sky_u) != 0 and len(run_result_sky_v) != 0: k = 0 # print(len(result_mat_u)) for i in (2, 6, 10, 14, 18, 22): for j in (-60, -30, 0, 30, 60): if len(run_result_sky_u[k]) > 0 and len( run_result_sky_v[k]) > 0: temp_u = np.array( run_result_sky_u[k]) / run_result_sky_max_range temp_v = np.array( run_result_sky_v[k]) / run_result_sky_max_range * 10 temp_u += i temp_v += j plt.scatter(temp_u, temp_v, s=3, marker='.', color='b') k += 1 # plot sun position sun_ra, sun_dec = me.sun_ra_dec_cal(start_time, stop_time, time_step) plt.plot(np.array(sun_ra), np.array(sun_dec), '.k', linewidth=2) plt.plot(sun_ra[0], sun_dec[0], 'or', alpha=0.5, markersize=20) # ticks plt.title("All Sky UV Plot") plt.xlabel(r"Ra($H$)") plt.ylabel(r'Dec ($^\circ$)') plt.xticks([0, 2, 6, 10, 14, 18, 22, 24]) plt.yticks([-90, -60, -30, 0, 30, 60, 90]) plt.xlim(0, 24) plt.ylim(-90, +90) plt.grid() # draw multi src plt.figure() num_src = len(run_result_src_name) if num_src > 0: num_col = int(np.ceil(np.sqrt(num_src))) num_row = int(np.ceil(num_src / num_col)) # num_col, num_row= 4, 7 for k in range(num_src): plt.subplot(num_row, num_col, k + 1, aspect='equal') if len(run_result_src_u[k]) > 0 and len(run_result_src_v[k]) > 0: plt.scatter(run_result_src_u[k], run_result_src_v[k], s=1, marker='.', color='brown') plt.xlim([-run_result_src_max_range, run_result_src_max_range]) plt.ylim([-run_result_src_max_range, run_result_src_max_range]) plt.title(run_result_src_name[k]) plt.xlabel('u') plt.ylabel('v') plt.tight_layout() if is_show_gui: plt.show() return run_time_end - run_time_start
def run_uv_advanced(): # 1. initialize parse and config objects args = parse_args() # for test in ide # args.show_gui = True # args.separate_srcs = True if args.config != '': my_config_parser = UVConfigParser(args.config) else: my_config_parser = UVConfigParser() # print(my_config_parser.show_info()) # 2. parse config file start_time = ut.time_2_mjd(*my_config_parser.time_start, 0) stop_time = ut.time_2_mjd(*my_config_parser.time_end, 0) time_step = ut.time_2_day(*my_config_parser.time_step) run_type_str = "src+sky" if args.run_type in ['src', 'sky', 'time', 'src+sky', 'all']: run_type_str = args.run_type run_type = 0 if run_type_str == 'src': run_type = RUN_FUNC_UV_SRCS elif run_type_str == 'sky': run_type = RUN_FUNC_UV_SKY elif run_type_str == 'time': run_type = RUN_FUNC_UV_YEAR elif run_type_str == 'src+sky': run_type = RUN_FUNC_UV_SRCS | RUN_FUNC_UV_SKY elif run_type_str == "all": run_type = RUN_FUNC_UV_SRCS | RUN_FUNC_UV_SKY | RUN_FUNC_UV_YEAR else: pass img_type = 'pdf' time_str = time.ctime() path_out = os.path.join(os.path.join(os.getcwd(), 'OUTPUT'), 'uv_advance') if args.img_fmt in ['eps', 'png', 'pdf', 'svg', 'ps']: img_type = args.img_fmt path_dir_sky = os.path.join(path_out, "sky-uv-{}.{}".format(time_str, img_type)) path_dir_year = os.path.join(path_out, "year-uv-{}.{}".format(time_str, img_type)) path_dir_srcs_all = os.path.join( path_out, "multi-uv-all-{}.{}".format(time_str, img_type)) if args.show_funcs: print(_design_idea) # 3. invoke the calculation functions cutoff_dict = { "flag": lc.cutoff_mode["flag"], "CutAngle": my_config_parser.cutoff_angle } myFuncUvMore = FuncUvMore( start_time, stop_time, time_step, my_config_parser.pos_mat_src[0], my_config_parser.pos_mat_src, my_config_parser.pos_mat_sat, my_config_parser.pos_mat_vlbi, my_config_parser.pos_mat_telemetry, my_config_parser.obs_freq, my_config_parser.baseline_type, my_config_parser.unit_flag, cutoff_dict, my_config_parser.precession_mode, run_type) myFuncUvMore.run_uv_more() # 4. draw sky uv if run_type & RUN_FUNC_UV_SKY == RUN_FUNC_UV_SKY: run_result_sky_u, run_result_sky_v, run_result_sky_max_range = myFuncUvMore.get_run_result_sky( ) if len(run_result_sky_u) != 0 and len(run_result_sky_v) != 0: plt.figure() k = 0 for i in (2, 6, 10, 14, 18, 22): for j in (-60, -30, 0, 30, 60): if len(run_result_sky_u[k]) > 0 and len( run_result_sky_v[k]) > 0: temp_u = np.array( run_result_sky_u[k]) / run_result_sky_max_range temp_v = np.array(run_result_sky_v[k] ) / run_result_sky_max_range * 10 temp_u += i temp_v += j plt.scatter(temp_u, temp_v, s=3, marker='.', color='b') k += 1 # plot sun position sun_ra, sun_dec = me.sun_ra_dec_cal(start_time, stop_time, time_step) plt.plot(np.array(sun_ra), np.array(sun_dec), '.k', linewidth=2) plt.plot(sun_ra[0], sun_dec[0], 'or', alpha=0.5, markersize=20) # ticks plt.title("All Sky UV Plot") plt.xlabel(r"Ra($H$)") plt.ylabel(r'Dec ($^\circ$)') plt.xticks([0, 2, 6, 10, 14, 18, 22, 24]) plt.yticks([-90, -60, -30, 0, 30, 60, 90]) plt.xlim(0, 24) plt.ylim(-90, +90) plt.grid() plt.savefig(path_dir_sky) # 5. draw year uv if run_type & RUN_FUNC_UV_YEAR == RUN_FUNC_UV_YEAR: run_result_time_u, run_result_time_v, run_result_time_max_range = myFuncUvMore.get_run_result_year( ) if len(run_result_time_u) != 0 and len(run_result_time_v) != 0: plt.figure() k = 0 for irow in (21, 15, 9, 3): for icol in (20, 12, 4): if len(run_result_time_u[k]) > 0 and len( run_result_time_v[k]) > 0: temp_u = np.array(run_result_time_u[k] ) / run_result_time_max_range * 4 temp_v = np.array(run_result_time_v[k] ) / run_result_time_max_range * 3 temp_u += icol temp_v += irow plt.scatter(temp_u, temp_v, s=3, marker='.', color='b') k += 1 plt.title("All Year Round UV Plot") plt.xlim(0, 24) plt.ylim(0, 24) plt.xticks([4, 12, 20], [1, 2, 3]) plt.yticks([3, 9, 15, 21], [4, 3, 2, 1]) plt.xlabel(r"$i_{th}$\ month") plt.ylabel(r"Quarter") plt.grid() plt.savefig(path_dir_year) # 6. draw multisrc num_src = 0 if run_type & RUN_FUNC_UV_SRCS == RUN_FUNC_UV_SRCS: run_result_src_name, run_result_src_u, run_result_src_v, run_result_mrange_src, run_result_src_max_range = myFuncUvMore.get_run_result_srcs( ) num_src = len(run_result_src_name) if not args.separate_srcs: if num_src > 0: plt.figure() num_col = int(np.ceil(np.sqrt(num_src))) num_row = int(np.ceil(num_src / num_col)) # num_col, num_row= 4, 7 for k in range(num_src): plt.subplot(num_row, num_col, k + 1, aspect='equal') if len(run_result_src_u[k]) > 0 and len( run_result_src_v[k]) > 0: plt.scatter(run_result_src_u[k], run_result_src_v[k], s=1, marker='.', color='brown') plt.xlim([ -run_result_src_max_range, run_result_src_max_range ]) plt.ylim([ -run_result_src_max_range, run_result_src_max_range ]) plt.title(run_result_src_name[k]) # science ax = plt.gca() ax.yaxis.get_major_formatter().set_powerlimits((0, 1)) ax.xaxis.get_major_formatter().set_powerlimits((0, 1)) plt.xlabel('u') plt.ylabel('v') plt.tight_layout() plt.savefig(path_dir_srcs_all) else: if num_src > 0: for k in range(num_src): if len(run_result_src_u[k]) > 0 and len( run_result_src_v[k]) > 0: plt.figure() plt.scatter(run_result_src_u[k], run_result_src_v[k], s=1, marker='.', color='brown') plt.xlim([ -run_result_src_max_range, run_result_src_max_range ]) plt.ylim([ -run_result_src_max_range, run_result_src_max_range ]) plt.title(run_result_src_name[k]) plt.xlabel('u') plt.ylabel('v') temp_dir_src = os.path.join( path_out, "multi-uv-{}-{}.{}".format(run_result_src_name[k], time_str, img_type)) # science ax = plt.gca() ax.yaxis.get_major_formatter().set_powerlimits((0, 1)) ax.xaxis.get_major_formatter().set_powerlimits((0, 1)) plt.savefig(temp_dir_src) # 7.show uv img if args.show_gui: if args.separate_srcs: if run_type & RUN_FUNC_UV_SRCS == RUN_FUNC_UV_SRCS and num_src > 5: print( "There are too many figures, please check the output file instead of show them directly" ) else: plt.show() else: plt.show()