Пример #1
0
def subsample_parameters(filename, equal_width=False):
    ''' print the number of matched and isolated lobes, and the distribution of PA
		whether it is random according to the KStest etc. '''

    tdata = Table(fits.open('../%s.fits' % filename)[1].data)
    filename_original = filename
    tdata_original = tdata

    print_parameters(tdata, filename)

    if equal_width:
        fluxbins = select_flux_bins1(tdata_original)
    else:
        fluxbins = select_flux_bins_cuts_biggest_selection(tdata_original)

    for key in sorted(fluxbins):
        tdata = fluxbins[key]
        filename = filename_original + 'flux%s' % key

        print_parameters(tdata, filename)

    if equal_width:
        sizebins = select_size_bins1(tdata_original)
    else:
        sizebins = select_size_bins_cuts_biggest_selection(tdata_original)

    for key in sorted(sizebins):
        tdata = sizebins[key]
        filename = filename_original + 'size%s' % key

        print_parameters(tdata, filename)
Пример #2
0
def di_vs_right_ascension_declination():
    n = 60
    n = 140

    file = '/data1/osinga/value_added_catalog_1_1b_thesis_cutoff069/value_added_selection_MG.fits'

    # ############################################ VA selection MG only redshift sources, flux bin 3
    tdata = Table(fits.open(file)[1].data)
    # # With redshift
    print('Using redshift..')  ## edited for not actually using z
    z_available = np.invert(np.isnan(tdata['z_best']))
    z_zero = tdata['z_best'] == 0  #
    # also remove sources with redshift 0, these dont have 3D positions
    z_available = np.logical_xor(z_available, z_zero)
    print('Number of sources with available redshift:', np.sum(z_available))
    tdata = tdata[z_available]
    tdata_original = tdata  # use redshift data for power bins and size bins !!!
    # #########################################  VA selection MG only redshift sources, flux bin 3
    tdata['final_PA'] = tdata['position_angle']
    print('Using flux bin 3')
    tdata['RA'], tdata['DEC'] = tdata['RA_2'], tdata['DEC_2']
    # tdata = only redshift sources flux bin 3
    tdata = select_flux_bins_cuts_biggest_selection(tdata)['3']

    # array of N,n for all sources N, with nearest neighbour n
    di_max = dispersion_vectorized_n(tdata, n, redshift=False)

    # index 0 = 1
    di_max_n = di_max[:, n - 1]

    ra, dec = tdata['RA'], tdata['DEC']

    if n == 140:
        cutoff = 0.17
    else:
        cutoff = 0.25

    less_than_25 = np.where(di_max_n < cutoff)
    more_than_25 = np.where(di_max_n > cutoff)

    plt.scatter(ra[less_than_25],
                dec[less_than_25],
                c='k',
                s=10,
                label=r'$d_i$<%.2f' % cutoff)
    plt.scatter(ra[more_than_25],
                dec[more_than_25],
                c='r',
                s=10,
                label=r'$d_i$>%.2f' % cutoff)
    plt.xlabel('Righ ascension (degrees)', fontsize=14)
    plt.ylabel('Declination (degrees)', fontsize=14)
    # ax.legend(fontsize=14)
    # plt.title(title,fontsize=16)
    plt.tight_layout()
    plt.ylim(45.058947246972785, 59)
    plt.legend(loc='upper left')
    plt.gca().set_aspect('equal', adjustable='box')
    plt.show()
Пример #3
0
    def helper_func(filename):
        tdata = Table(fits.open('../%s.fits' % filename)[1].data)
        # Take only the available redshift sources
        z_available = np.invert(np.isnan(tdata['z_best']))
        z_zero = tdata['z_best'] == 0  #
        # also remove sources with redshift 0, these dont have 3D positions
        z_available = np.logical_xor(z_available, z_zero)
        tdata = tdata[z_available]

        spectro_where = np.where(tdata['z_source'] == 1)
        tdata = tdata[spectro_where]

        fluxbin3 = select_flux_bins_cuts_biggest_selection(tdata)['3']
        fluxbin3 = len(fluxbin3)

        return fluxbin3
Пример #4
0
def plot_VA_MG_redshift_dist():
    filename = 'value_added_selection_MG'
    print(filename)
    tdata = Table(fits.open('../%s.fits' % filename)[1].data)

    print tdata['z_best_source']
    # With redshift
    print('Using redshift..')  ## edited for not actually using z
    z_available = np.invert(np.isnan(tdata['z_best']))
    z_zero = tdata['z_best'] == 0  #
    # also remove sources with redshift 0, these dont have 3D positions
    z_available = np.logical_xor(z_available, z_zero)
    print('Number of sources with available redshift:', np.sum(z_available))
    tdata = tdata[z_available]
    tdata_original = tdata  # use redshift data for power bins and size bins !!!
    #########################################  VA selection MG only redshift sources, flux bin 3

    # tdata['RA_2'], tdata['DEC_2'] = tdata['RA'], tdata['DEC']
    tdata['final_PA'] = tdata['position_angle']

    tdata = select_flux_bins_cuts_biggest_selection(tdata)['3']

    spectroscopic = np.where(tdata['z_best_source'] == 1)
    photometric = np.where(tdata['z_best_source'] == 0)
    tdata_spec = tdata[spectroscopic]
    tdata_phot = tdata[photometric]
    print(' flux bin 3 VA MG')

    print(len(tdata_spec), len(tdata_phot), len(tdata))

    # Use fancy algorithms to determine the bins
    from astropy import visualization
    # visualization.hist(tdata_phot['z_best'],bins='scott',histtype=u'step',label='Photometric')
    # visualization.hist(tdata_spec['z_best'],bins='scott',histtype=u'step',label='Spectroscopic')

    plt.hist(tdata_phot['z_best'], histtype=u'step', label='Photometric')
    plt.hist(tdata_spec['z_best'], histtype=u'step', label='Spectroscopic')

    # plt.yscale('log')
    plt.legend(fontsize=14)
    plt.xlabel(r'Redshift', fontsize=14)
    plt.ylabel('Counts', fontsize=14)
    plt.tight_layout()

    plt.show()
Пример #5
0
    def helper_func(filename):
        tdata = Table(fits.open('../%s.fits' % filename)[1].data)
        # Take only the available redshift sources
        z_available = np.invert(np.isnan(tdata['z_best']))
        z_zero = tdata['z_best'] == 0  #
        # also remove sources with redshift 0, these dont have 3D positions
        z_available = np.logical_xor(z_available, z_zero)
        tdata = tdata[z_available]

        powerbin1 = select_power_bins_cuts_VA_selection(tdata)['1']
        powerbin1 = len(powerbin1)

        fluxbin3 = select_flux_bins_cuts_biggest_selection(tdata)['3']
        fluxbin3 = len(fluxbin3)
        print(fluxbin3)

        sizebin0 = select_size_bins_cuts_biggest_selection(tdata)['0']
        sizebin0 = len(sizebin0)

        return powerbin1, fluxbin3, sizebin0
Пример #6
0
def investigate_strong_alignment_sources():
    n = 60
    n = 140

    file = '/data1/osinga/value_added_catalog_1_1b_thesis_cutoff069/value_added_selection_MG.fits'

    # ############################################ VA selection MG only redshift sources, flux bin 3
    tdata = Table(fits.open(file)[1].data)
    # # With redshift
    print('Using redshift..')  ## edited for not actually using z
    z_available = np.invert(np.isnan(tdata['z_best']))
    z_zero = tdata['z_best'] == 0  #
    # also remove sources with redshift 0, these dont have 3D positions
    z_available = np.logical_xor(z_available, z_zero)
    print('Number of sources with available redshift:', np.sum(z_available))
    tdata = tdata[z_available]
    tdata_original = tdata  # use redshift data for power bins and size bins !!!
    # #########################################  VA selection MG only redshift sources, flux bin 3
    tdata['final_PA'] = tdata['position_angle']
    print('Using flux bin 3')
    tdata['RA'], tdata['DEC'] = tdata['RA_2'], tdata['DEC_2']
    # tdata = only redshift sources flux bin 3
    tdata = select_flux_bins_cuts_biggest_selection(tdata)['3']

    ra, dec = tdata['RA'], tdata['DEC']
    pa = tdata['final_PA']

    where = np.where((tdata['RA'] < 230) & (tdata['RA'] > 210)
                     & (tdata['DEC'] < 50) & (tdata['DEC'] > 45))

    tdata_region = tdata[where]

    plt.hist(pa[where], bins=180 / 5)
    plt.ylabel('Counts', fontsize=14)
    plt.xlabel('Position angle (degrees)', fontsize=14)
    # ax.legend(fontsize=14)
    # plt.title(title,fontsize=16)
    plt.tight_layout()
    plt.show()
Пример #7
0
def di_vs_right_ascension():
    n = 60
    n = 140

    file = '/data1/osinga/value_added_catalog_1_1b_thesis_cutoff069/value_added_selection_MG.fits'

    # ############################################ VA selection MG only redshift sources, flux bin 3
    tdata = Table(fits.open(file)[1].data)
    # # With redshift
    print('Using redshift..')  ## edited for not actually using z
    z_available = np.invert(np.isnan(tdata['z_best']))
    z_zero = tdata['z_best'] == 0  #
    # also remove sources with redshift 0, these dont have 3D positions
    z_available = np.logical_xor(z_available, z_zero)
    print('Number of sources with available redshift:', np.sum(z_available))
    tdata = tdata[z_available]
    tdata_original = tdata  # use redshift data for power bins and size bins !!!
    # #########################################  VA selection MG only redshift sources, flux bin 3
    tdata['final_PA'] = tdata['position_angle']
    print('Using flux bin 3')
    tdata['RA'], tdata['DEC'] = tdata['RA_2'], tdata['DEC_2']
    # tdata = only redshift sources flux bin 3
    tdata = select_flux_bins_cuts_biggest_selection(tdata)['3']

    # array of N,n for all sources N, with nearest neighbour n
    di_max = dispersion_vectorized_n(tdata, n, redshift=False)

    # index 0 = 1
    di_max_n = di_max[:, n - 1]

    plt.scatter(tdata['RA'], di_max_n, c='k', s=10)
    plt.xlabel('Righ ascension (degrees)', fontsize=14)
    plt.ylabel('Dispersion', fontsize=14)
    # ax.legend(fontsize=14)
    # plt.title(title,fontsize=16)
    plt.tight_layout()
    plt.show()
Пример #8
0
def plot_all_position_angles():
    def plot_position_angle(i, color):
        """
		Plots the position angle for source (i) on the sky as a line with a radius proportional 
		to either the nearest neighbour distance or the major axis of a source.
		"""

        RA = tdata['RA_2'][i]
        DEC = tdata['DEC_2'][i]

        position_angle = tdata['final_PA'][i]
        NN_dist = tdata['new_NN_distance(arcmin)'][i]
        size = 160  # 80  #set fixed X*4 arcsec
        # size = tdata['size_thesis'][i]

        z_best = tdata['z_best'][i]

        radius = size / 3600.  # convert arcsec to deg

        radius *= 4  # enhance radius by a factor

        origin = (RA, DEC)  # (coordinates of the source)

        up_point = (RA, DEC + radius)  # point above the origin (North)
        down_point = (RA, DEC - radius)  # point below the origin (South)

        # rotate the line according to the position angle North through East (counterclockwise)
        x_rot_up, y_rot_up = rotate_point(origin, up_point, position_angle)
        x_rot_down, y_rot_down = rotate_point(origin, down_point,
                                              position_angle)

        x = x_rot_down
        y = y_rot_down
        dx = x_rot_up - x_rot_down
        dy = y_rot_up - y_rot_down

        # ax.arrow(x,y,dx,dy)

        if color:
            # make colorbar with the redshift data
            plt.plot((x_rot_down, x_rot_up), (y_rot_down, y_rot_up),
                     c=color,
                     linewidth=0.4)
        else:
            plt.plot((x_rot_down, x_rot_up), (y_rot_down, y_rot_up),
                     linewidth=0.4,
                     c='k')

    file = '/data1/osinga/value_added_catalog_1_1b_thesis_cutoff069/value_added_selection_MG.fits'
    tdata = Table(fits.open(file)[1].data)

    # With redshift
    tdata = use_only_redshift(tdata)
    tdata_original = tdata

    tdata['final_PA'] = tdata['position_angle']
    print('Using flux bin 3')
    tdata = select_flux_bins_cuts_biggest_selection(tdata)['3']

    f = plt.figure(figsize=(7, 7))

    for i in range(len(tdata)):
        plot_position_angle(i, color=False)

    print('Number of sources in final plot: %i' % len(tdata))

    plt.xlim(160, 250)  #160,240
    plt.ylim(45, 58)
    print('Position angle distribution of ' + file[38:] + '')
    # plt.title('Position angle distribution of ' + file[38:] + '')
    # plt.xlabel('Right Ascension (degrees)',fontsize=14)
    # plt.ylabel('Declination (degrees)',fontsize=14)
    plt.gca().set_aspect('equal', adjustable='box')

    # put spectro sources in same plot
    spectroscopic = np.where(tdata['z_source'] == 1)
    tdata = tdata[spectroscopic]
    tdata_original = tdata
    print('Using spectroscopic redshift only')

    for i in range(len(tdata)):
        # j = np.where(tdata['Mosaic_ID_2'][i].strip() == np.asarray(all_mosaicIDs))[0][0]
        color = 'r'
        plot_position_angle(i, color=color)

    # for the legend
    plt.plot((0, 0), (1, 1), c='r', linewidth=0.4, label='Spectroscopic-z')
    plt.plot((0, 0), (1, 1), c='k', linewidth=0.4, label='Photometric-z')
    plt.legend()
Пример #9
0
    # also remove sources with redshift 0, these dont have 3D positions
    z_available = np.logical_xor(z_available, z_zero)
    print('Number of sources with available redshift:', np.sum(z_available))
    # filename += '_only_redshift_sources_' ## edited for not actually using z
    if position_angle: filename += '_PA'  # only when using 'position_angle'
    filename += '_redshift_'
    filename += '10k'

    tdata_original = tdata
    filename_original = filename

    tdata = tdata[z_available]

    tdata_original = tdata  # use redshift data for power bins and size bins !!

    fluxbins = select_flux_bins_cuts_biggest_selection(tdata_original)
    for key in fluxbins:
        tdata = fluxbins[key]
        # flux and redshift omg
        filename = filename_original + 'flux%s' % key

        z_available = np.invert(np.isnan(tdata['z_best']))
        z_zero = tdata['z_best'] == 0  #
        # also remove sources with redshift 0, these dont have 3D positions
        z_available = np.logical_xor(z_available, z_zero)
        print('Number of sources with available redshift:',
              np.sum(z_available))
        assert np.sum(np.invert(
            z_available)) == 0, "These sources should all have redshift.."
        tdata = tdata[z_available]
Пример #10
0
# also remove sources with redshift 0, these dont have 3D positions
z_available = np.logical_xor(z_available, z_zero)
print('Number of sources with available redshift:', np.sum(z_available))
tdata = tdata[z_available]
tdata_original = tdata  # use redshift data for power bins and size bins !!!
# #########################################  VA selection MG only redshift sources, flux bin 3

try:
    tdata['RA_2'], tdata['DEC_2'] = tdata['RA'], tdata['DEC']
except:
    pass

tdata['final_PA'] = tdata['position_angle']

print('Using flux bin 3')
tdata = select_flux_bins_cuts_biggest_selection(tdata)['3']

# spectroscopic = np.where(tdata['z_source'] == 1)
# tdata = tdata[spectroscopic]
# tdata_original = tdata
# print ('Using spectroscopic redshift only')

# RAs, DECs, position_angles, Majs, NN_dists = load_in(file,'RA_2','DEC_2',
# 'final_PA','Maj_1','new_NN_distance(arcmin)')

# fluxbins11 = select_flux_bins11(tdata)
# RAs, DECs, position_angles, Majs, NN_dists = load_in_table(fluxbins11,'RA_2','DEC_2',
# 'final_PA','Maj_1','new_NN_distance(arcmin)')

# fluxbins = select_flux_bins1(tdata)
# tdata = fluxbins['0']