def plot_radecs_colorcode_decs(obs_info_file, save_loc): save_loc = format_save_loc(save_loc, 'radec_coverage_colorcode_plot') observations = surveyview.load_survey(obs_info_file) for obs in observations: if obs.ra > 250: obs.ra -= 360 # Round the declinations to the nearest 6th to clump them in 7 Dec bands decs_round = [int(obs.dec / 6.) * 6 for obs in observations] decs_set = list(set(decs_round)) decs_set.sort() plt.figure(figsize=(10, 5)) for i in range(len(decs_set)): use_ras = [] use_decs = [] for index in range(len(observations)): if decs_round[index] == decs_set[i]: use_ras.append(observations[index].ra) use_decs.append(observations[index].dec) plt.plot(use_ras, use_decs, 'o', markersize=10, mfc=use_colors[i], alpha=0.5) plt.xlabel('RA') plt.ylabel('Dec') plt.axis([-100, 200, -65, 15]) plt.grid(True) print 'Saving plot to {}'.format(save_loc) plt.savefig(save_loc) plt.close()
def plot_radec_pointings_coverage(obs_info_file, save_loc): def check_obsids(observations, ra_target, dec_target, radius, colorbar_max): number_pointings = 0 for i, obs in enumerate(observations): distance_2 = (obs.dec - dec_target)**2 + (obs.ra - ra_target)**2 if distance_2 <= radius**2: pointings.append(obs.pointing) number_pointings = len(set(pointings)) if number_pointings > colorbar_max: number_pointings = colorbar_max return number_pointings save_loc = format_save_loc(save_loc, 'pointings_coverage') ra_range = [-60, 160] dec_range = [-70, 20] resolution = 1 radius = 12 colorbar_max = 10 ra_vals = [ ra_range[0] + resolution * i for i in range(int((ra_range[1] - ra_range[0]) / resolution)) ] dec_vals = [ dec_range[0] + resolution * i for i in range(int((dec_range[1] - dec_range[0]) / resolution)) ] counts = [[0 for i in range(len(ra_vals))] for i in range(len(dec_vals))] observations = surveyview.load_survey(obs_info_file) observations = surveyview.get_pointings(observations) for i, ra_target in enumerate(ra_vals): for j, dec_target in enumerate(dec_vals): (counts[-(j + 1)])[-(i + 1)] = check_obsids( observations, ra_target, dec_target, radius, colorbar_max) plt.figure(figsize=(9, 3)) plt.imshow(counts, interpolation='none', extent=[ ra_range[1] / 360. * 24., ra_range[0] / 360. * 24., dec_range[0], dec_range[1] ], aspect=24 / 360., cmap=plt.get_cmap('Blues')) plt.xlabel('Right Ascension (hours)') plt.ylabel('Declination (degrees)') plt.tight_layout() cbar = plt.colorbar(extend='max') cbar.set_label('Number of Unique Pointings') print 'Saving plot to {}'.format(save_loc) plt.savefig(save_loc) plt.close()
def plot_nearest_data(): obs_list_file = '/Users/ruby/EoR/obs_lists/diffuse_survey_good_pointings_successful.txt' obs_info_file = '/Users/ruby/EoR/sidelobe_survey_obsinfo.txt' data_loc = '/Users/ruby/EoR/Healpix_fits' nside = 256 obs_list = open(obs_list_file, 'r').readlines() obs_list = [obs.strip() for obs in obs_list] # strip newline characters obs_list = list(set(obs_list)) # remove duplicates #obs_list = obs_list[:10] observations = surveyview.load_survey(obs_info_file) # get obs metadata observations = [obs for obs in observations if obs.obsid in obs_list] indices = [] signal_vals = [] distances = [] for i, obs in enumerate(observations): print 'Gathering data from obsid {} of {}'.format(i + 1, len(obs_list)) print 'Loading data' data, nside_old, nest = healpix_utils.load_map( '{}/{}_uniform_Residual_I_HEALPix.fits'.format( data_loc, obs.obsid)) data = healpix_utils.healpix_downsample(data, nside_old, nside, nest) for data_point in data: data_point.get_ra_dec(nside, nest) data_dist = hp.rotator.angdist([obs.ra, obs.dec], [data_point.ra, data_point.dec], lonlat=True)[0] / np.pi * 180. if data_point.pixelnum in indices: list_pos = indices.index(data_point.pixelnum) if data_dist < distances[list_pos]: signal_vals[list_pos] = data_point.signal distances[list_pos] = data_dist else: indices.append(data_point.pixelnum) signal_vals.append(data_point.signal) distances.append(data_dist) use_data = [ healpix_utils.HealpixPixel(indices[i], signal_vals[i]) for i in range(len(indices)) ] #healpix_utils.write_data_to_fits(data, nside, nest, '/Users/ruby/Desktop/nearest_data.fits') print 'Plotting' plot_filled_pixels(use_data, nside, nest, '/Users/ruby/Desktop/nearest_data_test.png')
def generate_radec_animation(obs_info_file, save_dir): if save_dir.endswith('.png'): # User doesn't get to set file name save_dir_split = save_dir.split('/') save_dir = '/'.join(save_dir_split[:-1]) if save_dir.endswith('/'): save_dir = save_dir[:-1] observations = surveyview.load_survey(obs_info_file) for obs in observations: if obs.ra > 250: obs.ra -= 360 ras = [obs.ra for obs in observations] decs = [obs.dec for obs in observations] for i, obs in enumerate(obsids): if i + 1 < 10: filepath_num = '00' + str(i + 1) else: if i + 1 < 100: filepath_num = '0' + str(i + 1) else: filepath_num = str(i + 1) save_loc = '{}/radec_plot{}.png'.format(save_dir, filepath_num) plt.figure(figsize=(17, 5)) plt.plot(ras[0:i + 1], decs[0:i + 1], 'o', markersize=90, mfc='blue', alpha=0.03) plt.plot(ras[i], decs[i], 'o', markersize=90, mfc='none', mec='red') plt.plot(ras[i], decs[i], 'x', markersize=10, mfc='red') plt.xticks(range(-100, 200, 10)) plt.xlabel('RA') plt.ylabel('Dec') plt.axis('equal') plt.axis([-100, 200, -65, 15]) plt.grid(which='both') plt.text(-80, 17, 'Obsid: ' + str(obs)) print 'Saving plot to {}'.format(save_loc) plt.savefig(save_loc) plt.close()
def plot_azels(obs_info_file, save_loc): # Plots the points in the Az/El plane that are covered by the survey # Az/El values are rounded to prevent redundancy # Data points are color-coded based on their declination save_loc = format_save_loc(save_loc, 'AzEls_plot') observations = surveyview.load_survey(obs_info_file) # Round the declinations to the nearest 6th to clump them in 7 Dec bands decs_round = [int(obs.dec / 6.) * 6 for obs in observations] decs_set = list(set(decs_round)) decs_set.sort() plt.figure() for i in range(len(decs_set)): use_az = [] use_el = [] for index in range(len(observations)): if decs_round[index] == decs_set[i]: use_az.append(observations[index].az) use_el.append(observations[index].el) use_azels = zip(use_az, use_el) use_azels_set = list(set(use_azels)) use_az_set = [term[0] for term in use_azels_set] use_el_set = [term[1] for term in use_azels_set] plt.plot(use_az_set, use_el_set, 'o', markersize=10, mfc=use_colors[i], alpha=1) plt.xlabel('Azimuth') plt.ylabel('Elevation') plt.axis([-10, 350, 60, 91]) plt.grid(True) print 'Saving plot to {}'.format(save_loc) plt.savefig(save_loc) plt.close()
def hist2d_datastat_plot(): obs_list_file = '/Users/ruby/EoR/obs_lists/diffuse_survey_good_pointings_successful.txt' data_loc = '/Users/ruby/EoR/Healpix_fits' obs_list = open(obs_list_file, 'r').readlines() obs_list = [obs.strip() for obs in obs_list] # strip newline characters obs_list = list(set(obs_list)) # remove duplicates #obs_list = obs_list[:4] observations = surveyview.load_survey( '/Users/ruby/EoR/sidelobe_survey_obsinfo.txt') observations = [obs for obs in observations if obs.obsid in obs_list] var_data, nside, nest = healpix_utils.load_map( '/Users/ruby/Desktop/data_var_nside256.fits') var_pixelvals = [data_point.pixelnum for data_point in var_data] data_diff = [] data_dist = [] for i, obs in enumerate(observations): print 'Gathering data from obsid {} of {}'.format(i + 1, len(obs_list)) print 'Loading data' data, nside_old, nest = healpix_utils.load_map( '{}/{}_uniform_Residual_I_HEALPix.fits'.format( data_loc, obs.obsid)) data = healpix_utils.healpix_downsample(data, nside_old, nside, nest) print 'Calculating data statistics' for data_point in data: data_diff.append( data_point.signal - var_data[var_pixelvals.index(data_point.pixelnum)].signal) data_point.get_ra_dec(nside, nest) data_dist.append( hp.rotator.angdist([obs.ra, obs.dec], [data_point.ra, data_point.dec], lonlat=True)[0] / np.pi * 180.) hist, dist_edges, diff_edges = np.histogram2d(data_dist, data_diff, bins=100) hist = hist.T for j in range(len(hist[0])): total = sum([hist[i][j] for i in range(len(hist))]) if total != 0: for i in range(len(hist)): hist[i][j] = hist[i][j] / total fig, ax = plt.subplots() plt.imshow( hist, origin='lower', interpolation='none', extent=[dist_edges[0], dist_edges[-1], diff_edges[0], diff_edges[-1]], vmin=0, vmax=0.1) ax.set_aspect( (dist_edges[-1] - dist_edges[0]) / (diff_edges[-1] - diff_edges[0])) plt.xlabel('Distance from Pointing Center (deg)') plt.ylabel('Difference from Mean (Jy/sr)') cbar = plt.colorbar() cbar.ax.set_ylabel('Counts, Normalized', rotation=270) # label colorbar plt.savefig('/Users/ruby/Desktop/data_var_2dhist_testing.png', format='png', dpi=500)
def plot_leakage_fits(): observations = surveyview.load_survey('/Users/ruby/EoR/sidelobe_survey_obsinfo.txt') observations = surveyview.get_pointings(observations) pol_leakage_params_file = open('/Users/ruby/EoR/pol_leakage_testing/plotting/pol_leakage_fit_params.csv', 'r') read_csv = csv.reader(pol_leakage_params_file) pol_leakage_params = [line for line in read_csv] pol_leakage_params_file.close() pol_leakage_params = pol_leakage_params[1:] # remove header obsids = [obs_params[0] for obs_params in pol_leakage_params] observations = [obs for obs in observations if obs.obsid in obsids] xvals = list(range(512, 1536, 8)) yvals = list(range(512, 1536, 8)) for obs in observations: params = (pol_leakage_params[obsids.index(obs.obsid)])[1:] params = [float(param) for param in params] leakage_surf_q = np.zeros((len(xvals), len(yvals))) leakage_surf_u = np.zeros((len(xvals), len(yvals))) for i, xval in enumerate(xvals): for j, yval in enumerate(yvals): leakage_surf_q[i, j] = ( params[0]*xval**2 + params[1]*yval**2 + params[2]*xval*yval + params[3]*xval + params[4]*yval + params[5] ) leakage_surf_u[i, j] = ( params[6]*xval**2 + params[7]*yval**2 + params[8]*xval*yval + params[9]*xval + params[10]*yval + params[11] ) pointing = obs.pointing pointing = re.split('\(|\)|, ||', pointing) pointing = list(filter(None, pointing)) fig, ax = plt.subplots() plt.imshow(leakage_surf_q, origin='lower', interpolation='none', #cmap='Greys_r', extent=[xvals[0], xvals[-1], yvals[0], yvals[-1]], vmin=-.3, vmax=.3, aspect='auto' ) plt.xlabel('x pixel') plt.ylabel('y pixel') plt.title('{} Q Leakage Fit (Pointing {}, {})'.format(obs.obsid, pointing[0], pointing[1])) plt.axis('equal') cbar = plt.colorbar() cbar.ax.set_ylabel('Fractional Leakage', rotation=270) # label colorbar plt.savefig('/Users/ruby/EoR/pol_leakage_testing/plotting/pointing_{}_{}/{}_q_leakage.png'.format(pointing[0], pointing[1], obs.obsid), format='png', dpi=500) plt.close() fig, ax = plt.subplots() plt.imshow(leakage_surf_u, origin='lower', interpolation='none', #cmap='Greys_r', extent=[xvals[0], xvals[-1], yvals[0], yvals[-1]], vmin=-.3, vmax=.3, aspect='auto' ) plt.xlabel('x pixel') plt.ylabel('y pixel') plt.title('{} U Leakage Fit (Pointing {}, {})'.format(obs.obsid, pointing[0], pointing[1])) plt.axis('equal') cbar = plt.colorbar() cbar.ax.set_ylabel('Fractional Leakage', rotation=270) # label colorbar plt.savefig('/Users/ruby/EoR/pol_leakage_testing/plotting/pointing_{}_{}/{}_u_leakage.png'.format(pointing[0], pointing[1], obs.obsid), format='png', dpi=500) plt.close()
def compare_observations(): obs_list_file = '/Users/ruby/EoR/obs_lists/diffuse_survey_good_pointings_successful.txt' data_loc = '/Users/ruby/EoR/Healpix_fits' save_path = '/Users/ruby/Documents/2018 Fall Quarter/phys576b/jackknife_assignment' obs_list = open(obs_list_file, 'r').readlines() obs_list = [obs.strip() for obs in obs_list] # strip newline characters obs_list = list(set(obs_list)) # remove duplicates observations = surveyview.load_survey( '/Users/ruby/EoR/sidelobe_survey_obsinfo.txt') center_ra = 40. center_dec = -35. use_observations = [] for obs in observations: if obs.obsid in obs_list: if (obs.ra - center_ra)**2. + (obs.dec - center_dec)**2. < 10**2.: use_observations.append(obs) all_data = [] for obs in use_observations: data, nside_old, nest = healpix_utils.load_map( '{}/{}_uniform_Residual_I_HEALPix.fits'.format( data_loc, obs.obsid)) #plot_filled_pixels(data, nside, nest, '{}/{}_residual_I.png'.format(save_path, obs.obsid)) nside = 256 data = healpix_utils.healpix_downsample(data, nside_old, nside, nest) all_data.append(data) print 'Calculating data average...' ave_data, var_data, nsamples_data, ston_data = healpix_utils.average_healpix_maps( all_data) max_intersect_pixels = set( [data_point.pixelnum for data_point in all_data[0]]) for data_set in all_data[1:]: max_intersect_pixels = max_intersect_pixels.intersection( [data_point.pixelnum for data_point in data_set]) ave_data_sum = np.sum([ data_point.signal for data_point in ave_data if data_point.pixelnum in max_intersect_pixels ]) all_data_norm = [] for i, data_set in enumerate(all_data): data_sum = np.sum([ data_point.signal for data_point in data_set if data_point.pixelnum in max_intersect_pixels ]) norm_factor = ave_data_sum / data_sum for point in data_set: point.signal = point.signal * norm_factor ave_data_norm, var_data_norm, nsamples_data, ston_data_norm = healpix_utils.average_healpix_maps( all_data) print 'Plotting data average...' plot_filled_pixels(ave_data_norm, nside, nest, '{}/ave_norm_residual_I.png'.format(save_path)) data_diff = healpix_utils.difference_healpix_maps(ave_data_norm, ave_data, nside, nest) plot_filled_pixels( data_diff, nside, nest, '{}/ave_norm_minus_orig_residual_I.png'.format(save_path))
def radec_reference_for_images(obs_info_file, image_filename, save_loc, reduced_obslist=''): save_loc = format_save_loc(save_loc, 'radec_reference') observations = surveyview.load_survey(obs_info_file) for obs in observations: if obs.ra > 250: obs.ra -= 360 if reduced_obslist != '': reduced_obslist = open(reduced_obslist, "r") obs_reduced = reduced_obslist.readlines() reduced_obslist.close() obs_reduced = [obs.strip() for obs in obs_reduced] observations = [ obs for obs in observations if obs.obsid in obs_reduced ] ras = [obs.ra for obs in observations] decs = [obs.dec for obs in observations] highlight_obs = (image_filename.split('/')[-1]).split('_')[0] i = [obs.obsid for obs in observations].index(highlight_obs) a_teams = surveyview.get_a_team_sources() for source in a_teams: if source.ra > 250: source.ra -= 360 plt.figure(figsize=(11, 14)) gs = gridspec.GridSpec(2, 3, height_ratios=[1, 4], width_ratios=[1, 50, 1]) plt.subplot(gs[0, 1]) plt.plot(ras, decs, 'o', markersize=90, mfc='0.9', mec='none', zorder=1) plt.plot(ras[i], decs[i], 'o', markersize=90, mfc='none', mec='red', zorder=11) plt.plot(ras[i], decs[i], 'x', markersize=10, mec='red', zorder=12) plt.plot([source.ra for source in a_teams], [source.dec for source in a_teams], 'o', markersize=5, mfc='orange', mec='none') for index in range(len(a_teams)): plt.annotate(a_teams[index].name, (a_teams[index].ra, a_teams[index].dec)) plt.plot([0, 60], [-27, -27], 'o', markersize=90, mfc='cyan', alpha=0.2, mec='none', zorder=2) plt.annotate('EoR-0', (0, -27)) plt.annotate('EoR-1', (60, -27)) plt.xticks(range(-100, 200, 10)) plt.xlabel('RA') plt.ylabel('Dec') plt.axis('equal') plt.axis([200, -100, -65, 15]) plt.grid(which='both', zorder=10) plt.subplot(gs[1, :]) img = mpimg.imread(image_filename) plt.imshow(img) plt.tight_layout() print 'Saving plot to {}'.format(save_loc) plt.savefig(save_loc, dpi=300) plt.close()