Exemple #1
0
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')
Exemple #2
0
def calculate_mean_and_var():

    obs_list_file = '/Users/ruby/EoR/obs_lists/diffuse_survey_good_pointings_successful.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

    all_data = []
    for i, obs in enumerate(obs_list):
        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))
        data = healpix_utils.healpix_downsample(data, nside_old, nside, nest)

        print 'Assembling data'
        # Convert to implicit indexing
        signal_vals_implicit = [hp.pixelfunc.UNSEEN] * 12 * nside**2
        for j in range(len(data)):
            signal_vals_implicit[data[j].pixelnum] = data[j].signal

        all_data.append(signal_vals_implicit)

    print 'Calculating data statistics'
    data_ave = []
    data_var = []
    data_npoints = []
    for i in range(12 * nside**2):
        use_data = [
            data_set[i] for data_set in all_data
            if data_set[i] != hp.pixelfunc.UNSEEN
        ]
        n_points = len(use_data)
        if n_points > 0:
            data_npoints.append(healpix_utils.HealpixPixel(i, n_points))
            data_ave.append(healpix_utils.HealpixPixel(i, np.mean(use_data)))
            data_var.append(healpix_utils.HealpixPixel(i, np.var(use_data)))

    print 'Saving data statistics'
    healpix_utils.write_data_to_fits(data_ave, nside, nest,
                                     '/Users/ruby/Desktop/data_ave.fits')
    healpix_utils.write_data_to_fits(data_var, nside, nest,
                                     '/Users/ruby/Desktop/data_var.fits')
    healpix_utils.write_data_to_fits(data_npoints, nside, nest,
                                     '/Users/ruby/Desktop/data_npoints.fits')
Exemple #3
0
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)
Exemple #4
0
def plot_healpix_tiling():

    #data_type = 'Residual_I'
    data_type = 'Dirty_I'
    normalization = 'uniform'
    #data_dir = '/Users/ruby/EoR/Healpix_fits'
    data_dir = '/Users/ruby/EoR/Healpix_fits/haslam_sim'

    tile_center_ras = [
        100, 100, 100, 100, 100, 90, 90, 90, 90, 90, 80, 80, 80, 80, 80, 70,
        70, 70, 70, 70, 60, 60, 60, 60, 60, 50, 50, 50, 50, 50, 40, 40, 40, 40,
        40, 30, 30, 30, 30, 30, 20, 20, 20, 20, 20, 10, 10, 10, 10, 10, 0, 0,
        0, 0, 0, -10, -10, -10, -10, -10, -20, -20, -20, -20, -20
    ]

    tile_center_decs = [
        -5, -15, -25, -35, -45, -5, -15, -25, -35, -45, -5, -15, -25, -35, -45,
        -5, -15, -25, -35, -45, -5, -15, -25, -35, -45, -5, -15, -25, -35, -45,
        -5, -15, -25, -35, -45, -5, -15, -25, -35, -45, -5, -15, -25, -35, -45,
        -5, -15, -25, -35, -45, -5, -15, -25, -35, -45, -5, -15, -25, -35, -45,
        -5, -15, -25, -35, -45
    ]

    obsids = [
        1131478056, 1131564464, 1131477936, 1130787784, 1131477816, 1131733672,
        1131562544, 1131733552, 1130785864, 1131475896, 1131559064, 1131558944,
        1131731752, 1130782264, 1130783824, 1131470736, 1131557144, 1131470616,
        1130780464, 1131470496, 1131468936, 1131553544, 1131726352, 1130778664,
        1131468696, 1131724672, 1131551744, 1131465216, 1130776864, 1130776624,
        1131463536, 1131549944, 1131463416, 1130773264, 1131463296, 1131461616,
        1131548024, 1131461496, 1130773144, 1131461376, 1131717352, 1131544424,
        1131717232, 1131459696, 1131459576, 1131456216, 1131542624, 1131456096,
        1131715432, 1131715312, 1131711952, 1131540824, 1131454296, 1131713632,
        1131454176, 1131710152, 1131537224, 1131710032, 1131710032, 1131709912,
        1131535544, 1131535424, 1131535304, 1131710032, 1131709912
    ]

    data = []
    #nside = 512
    nside = 256
    for i, obs in enumerate(obsids):
        print 'Gathering pixels from obsid {} of {}.'.format(
            i + 1, len(obsids))
        obs_data, nside_old, nest = healpix_utils.load_map(
            '{}/{}_{}_{}_HEALPix.fits'.format(data_dir, obs, normalization,
                                              data_type))
        obs_data = healpix_utils.healpix_downsample(obs_data, nside_old, nside,
                                                    nest)
        tile_bounds_radec = [[tile_center_ras[i] - 5, tile_center_decs[i] - 5],
                             [tile_center_ras[i] - 5, tile_center_decs[i] + 5],
                             [tile_center_ras[i] + 5, tile_center_decs[i] + 5],
                             [tile_center_ras[i] + 5, tile_center_decs[i] - 5]]
        tile_bounds_vec = np.array([
            hp.pixelfunc.ang2vec(corner[0], corner[1], lonlat=True)
            for corner in tile_bounds_radec
        ])
        use_pixels = hp.query_polygon(nside, tile_bounds_vec, nest=nest)
        data.extend([
            data_point for data_point in obs_data
            if data_point.pixelnum in use_pixels
        ])

    #healpix_utils.write_data_to_fits(data, nside, nest, '/Users/ruby/EoR/mosaic_data.fits')

    # Define Healpix pixels to plot
    patches = []
    colors = []
    for point in data:
        point.get_pixel_corners(nside, nest)
        polygon = Polygon(zip(point.pix_corner_ras, point.pix_corner_decs))
        patches.append(polygon)
        colors.append(point.signal)

    collection = PatchCollection(patches, cmap='Greys_r', lw=0.04)
    collection.set_array(np.array(colors))  # set the data colors
    collection.set_edgecolor('face')  # make the face and edge colors match

    fig, ax = plt.subplots(figsize=(24, 8), dpi=1000)
    ax.add_collection(collection)  # plot data

    # plot lines between tiles
    line_width = 2.0
    color = 'gray'
    order = 8
    plt.plot([130, -45], [0, 0], lw=line_width, c=color, zorder=order)
    plt.plot([130, -45], [-10, -10], lw=line_width, c=color, zorder=order)
    plt.plot([130, -45], [-20, -20], lw=line_width, c=color, zorder=order)
    plt.plot([130, -45], [-30, -30], lw=line_width, c=color, zorder=order)
    plt.plot([130, -45], [-40, -40], lw=line_width, c=color, zorder=order)
    plt.plot([130, -45], [-50, -50], lw=line_width, c=color, zorder=order)
    plt.plot([105, 105], [-75, 20], lw=line_width, c=color, zorder=order)
    plt.plot([95, 95], [-75, 20], lw=line_width, c=color, zorder=order)
    plt.plot([85, 85], [-75, 20], lw=line_width, c=color, zorder=order)
    plt.plot([75, 75], [-75, 20], lw=line_width, c=color, zorder=order)
    plt.plot([65, 65], [-75, 20], lw=line_width, c=color, zorder=order)
    plt.plot([55, 55], [-75, 20], lw=line_width, c=color, zorder=order)
    plt.plot([45, 45], [-75, 20], lw=line_width, c=color, zorder=order)
    plt.plot([35, 35], [-75, 20], lw=line_width, c=color, zorder=order)
    plt.plot([25, 25], [-75, 20], lw=line_width, c=color, zorder=order)
    plt.plot([15, 15], [-75, 20], lw=line_width, c=color, zorder=order)
    plt.plot([5, 5], [-75, 20], lw=line_width, c=color, zorder=order)
    plt.plot([-5, -5], [-75, 20], lw=line_width, c=color, zorder=order)
    plt.plot([-15, -15], [-75, 20], lw=line_width, c=color, zorder=order)
    plt.plot([-25, -25], [-75, 20], lw=line_width, c=color, zorder=order)

    plt.xlabel('RA (deg)')
    plt.ylabel('Dec (deg)')
    plt.axis('equal')
    ax.set_facecolor('gray')  # make plot background gray
    plt.axis([110, -30, -50, 0])
    cbar = fig.colorbar(collection, ax=ax, extend='both')  # add colorbar
    cbar.ax.set_ylabel('Flux Density (Jy/sr)', rotation=270)  # label colorbar

    plt.savefig(
        '/Users/ruby/Desktop/haslam_mosaicplot_nside{}.png'.format(nside),
        format='png',
        dpi=1000)
Exemple #5
0
def overplot_haslam_contour():

    data, nside, nest = healpix_utils.load_map(
        '/Users/ruby/EoR/mosaic_data.fits')

    fig, ax = plt.subplots(figsize=(24, 8), dpi=1000)

    # Define Healpix pixels to plot
    patches = []
    colors = []
    for point in data:
        point.get_pixel_corners(nside, nest)
        polygon = Polygon(zip(point.pix_corner_ras, point.pix_corner_decs))
        patches.append(polygon)
        colors.append(point.signal)

    collection = PatchCollection(patches, cmap='Greys_r', lw=0.04)
    collection.set_array(np.array(colors))  # set the data colors
    collection.set_edgecolor('face')  # make the face and edge colors match
    ax.add_collection(collection)  # plot data

    # plot lines between tiles
    line_width = 2.0
    color = 'gray'
    order = 8
    plt.plot([130, -45], [-10, -10], lw=line_width, c=color, zorder=order)
    plt.plot([130, -45], [-20, -20], lw=line_width, c=color, zorder=order)
    plt.plot([130, -45], [-30, -30], lw=line_width, c=color, zorder=order)
    plt.plot([130, -45], [-40, -40], lw=line_width, c=color, zorder=order)
    plt.plot([130, -45], [-50, -50], lw=line_width, c=color, zorder=order)
    plt.plot([95, 95], [-75, -20], lw=line_width, c=color, zorder=order)
    plt.plot([85, 85], [-75, -20], lw=line_width, c=color, zorder=order)
    plt.plot([75, 75], [-75, -20], lw=line_width, c=color, zorder=order)
    plt.plot([65, 65], [-75, -20], lw=line_width, c=color, zorder=order)
    plt.plot([55, 55], [-75, -20], lw=line_width, c=color, zorder=order)
    plt.plot([45, 45], [-75, -20], lw=line_width, c=color, zorder=order)
    plt.plot([35, 35], [-75, -20], lw=line_width, c=color, zorder=order)
    plt.plot([25, 25], [-75, -20], lw=line_width, c=color, zorder=order)
    plt.plot([15, 15], [-75, -20], lw=line_width, c=color, zorder=order)
    plt.plot([5, 5], [-75, -20], lw=line_width, c=color, zorder=order)
    plt.plot([-5, -5], [-75, -20], lw=line_width, c=color, zorder=order)
    plt.plot([-15, -15], [-75, -20], lw=line_width, c=color, zorder=order)

    plt.xlabel('RA (deg)')
    plt.ylabel('Dec (deg)')
    plt.axis('equal')
    ax.set_facecolor('gray')  # make plot background gray
    plt.axis([110, -30, -50, 0])
    cbar = fig.colorbar(collection, ax=ax, extend='both')  # add colorbar
    cbar.ax.set_ylabel('Flux Density (Jy/sr)', rotation=270)  # label colorbar

    data, nside, nest = healpix_utils.load_global_map(
        '/Users/ruby/EoR/Healpix_fits/lambda_haslam408_dsds.fits')
    data = healpix_utils.healpix_downsample(data, nside, 512, nest)
    for point in data:
        point.get_ra_dec(nside, nest, coords='galactic')

    plt.tricontour([point.ra for point in data], [point.dec for point in data],
                   [point.signal for point in data],
                   500,
                   linewidths=0.5,
                   colors='cyan')

    plt.savefig('/Users/ruby/EoR/haslam_overplot.png', format='png', dpi=1000)
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))