Exemple #1
0
def mo_matrix(mock, obs, opts):

    """
    Function to determine the mass-observable matrix.
    """

    n_mass_bins = comp.num_bins(opts.mass_bin[0], opts.mass_bin[1], opts.mass_bin[2])
    n_proxy_bins = comp.num_bins(opts.proxy_bin[0], opts.proxy_bin[1], opts.proxy_bin[2])

    mass_x = comp.x_vals(n_mass_bins, opts.mass_bin[0], opts.mass_bin[2])
    proxy_x = comp.x_vals(n_proxy_bins, opts.proxy_bin[0], opts.proxy_bin[2])
    
    matrix = np.zeros((n_proxy_bins, n_mass_bins))

    clusters = find_matches(mock, obs, opts)

    for cluster in clusters:
    
        proxy_bin = n_proxy_bins - 1 - \
          comp.find_bin(np.log10(cluster.proxy), opts.proxy_bin[0], opts.proxy_bin[2])

        for i in range(n_proxy_bins):
            if proxy_bin == i and opts.z_bin[0] <= cluster.z < opts.z_bin[1]:
                matrix[proxy_bin] += comp.scale(cluster.hist, min(cluster.hist),
                                                np.sum(cluster.hist))
                   
    for i in range(n_proxy_bins):
        matrix[i] = comp.scale(matrix[i], min(matrix[i]), np.sum(matrix[i]))

    return matrix, mass_x, proxy_x
Exemple #2
0
def get_completeness(mock, matches, opts):

    index, weights, mock_index = matches

    n_mass_bins = comp.num_bins(opts.mass_bin[0], opts.mass_bin[1],
                                opts.mass_bin[2])
    n_z_bins = comp.num_bins(opts.z_bin[0], opts.z_bin[1], opts.z_bin[2])
    n_ngal_bins = comp.num_bins(opts.proxy_bin[0], opts.proxy_bin[1],
                                opts.proxy_bin[2])

    mass_index = np.floor(
        (mock.mass - opts.mass_bin[0]) / opts.mass_bin[2]).astype('int')
    z_index = np.floor((mock.z - opts.z_bin[0]) / opts.z_bin[2]).astype('int')
    ngal_index = np.floor(
        (mock.ngal - opts.proxy_bin[0]) / opts.proxy_bin[2]).astype('int')

    mass_count = np.zeros((n_mass_bins, n_z_bins)).astype('float')
    match_count = np.zeros((n_mass_bins, n_z_bins)).astype('float')

    mass_count2 = np.zeros((n_ngal_bins, n_z_bins)).astype('float')
    match_count2 = np.zeros((n_ngal_bins, n_z_bins)).astype('float')

    for i in range(len(z_index)):
        mass_count[mass_index[i], z_index[i]] += 1.0
        mass_count2[ngal_index[i], z_index[i]] += 1.0
    for i in mock_index:
        match_count[mass_index[i], z_index[i]] += 1.0
        match_count2[ngal_index[i], z_index[i]] += 1.0

    return np.flipud(match_count / mass_count), np.flipud(match_count2 /
                                                          mass_count2)
def mo_matrix(mock, obs, opts):
    """
    Function to determine the mass-observable matrix.
    """

    n_mass_bins = comp.num_bins(opts.mass_bin[0], opts.mass_bin[1],
                                opts.mass_bin[2])
    n_proxy_bins = comp.num_bins(opts.proxy_bin[0], opts.proxy_bin[1],
                                 opts.proxy_bin[2])

    mass_x = comp.x_vals(n_mass_bins, opts.mass_bin[0], opts.mass_bin[2])
    proxy_x = comp.x_vals(n_proxy_bins, opts.proxy_bin[0], opts.proxy_bin[2])

    matrix = np.zeros((n_proxy_bins, n_mass_bins))

    clusters = find_matches(mock, obs, opts)

    for cluster in clusters:

        proxy_bin = n_proxy_bins - 1 - \
          comp.find_bin(np.log10(cluster.proxy), opts.proxy_bin[0], opts.proxy_bin[2])

        for i in range(n_proxy_bins):
            if proxy_bin == i and opts.z_bin[0] <= cluster.z < opts.z_bin[1]:
                matrix[proxy_bin] += comp.scale(cluster.hist,
                                                min(cluster.hist),
                                                np.sum(cluster.hist))

    for i in range(n_proxy_bins):
        matrix[i] = comp.scale(matrix[i], min(matrix[i]), np.sum(matrix[i]))

    return matrix, mass_x, proxy_x
Exemple #4
0
def get_completeness(mock, matches, opts):

    index, weights, mock_index = matches

    n_mass_bins = comp.num_bins(opts.mass_bin[0], opts.mass_bin[1], opts.mass_bin[2])
    n_z_bins = comp.num_bins(opts.z_bin[0], opts.z_bin[1], opts.z_bin[2])
    n_ngal_bins = comp.num_bins(opts.ngal_bin[0], opts.ngal_bin[1], opts.ngal_bin[2])

    mass_index = np.floor((mock.mass - opts.mass_bin[0]) / opts.mass_bin[2]).astype("int")
    z_index = np.floor((mock.z - opts.z_bin[0]) / opts.z_bin[2]).astype("int")
    ngal_index = np.floor((mock.ngal - opts.ngal_bin[0]) / opts.ngal_bin[2]).astype("int")

    mass_count = np.zeros((n_mass_bins, n_z_bins)).astype("float")
    match_count = np.zeros((n_mass_bins, n_z_bins)).astype("float")

    mass_count2 = np.zeros((n_ngal_bins, n_z_bins)).astype("float")
    match_count2 = np.zeros((n_ngal_bins, n_z_bins)).astype("float")

    for i in range(len(z_index)):
        mass_count[mass_index[i], z_index[i]] += 1.0
        mass_count2[ngal_index[i], z_index[i]] += 1.0
    for i in mock_index:
        match_count[mass_index[i], z_index[i]] += 1.0
        match_count2[ngal_index[i], z_index[i]] += 1.0

    return np.flipud(match_count / mass_count), np.flipud(match_count2 / mass_count2)
def mo_matrix(mock, obs, opts):

    n_mass_bins = comp.num_bins(opts.mass_bin[0], opts.mass_bin[1], opts.mass_bin[2])
    n_proxy_bins = comp.num_bins(opts.proxy_bin[0], opts.proxy_bin[1], opts.proxy_bin[2])
    
    mass_index = np.floor((mock.mass - opts.mass_bin[0]) / opts.mass_bin[2]).astype('int')
    proxy_index = np.floor((obs.proxy - opts.proxy_bin[0]) / opts.proxy_bin[2]).astype('int')

    mass_hist = np.zeros(n_mass_bins)
    for i in mass_index:
        mass_hist[i] += 1
    
    mass_x = comp.x_vals(n_mass_bins, opts.mass_bin[0], opts.mass_bin[2])
    proxy_x = comp.x_vals(n_proxy_bins, opts.proxy_bin[0], opts.proxy_bin[2])

    matrix = np.zeros((n_proxy_bins, n_mass_bins))
    
    index, dists = find_matches(mock, obs, 2.0 * opts.delta_z)

    tag_index = halo_tag(mock, np.copy(index))

    mass_hist2 = np.zeros(n_mass_bins)
    for i in mass_index[tag_index]:
        mass_hist2[i] += 1

    print_matches(mock, obs, index, opts)

    for i in range(obs.size):
        for j in range(len(index[i])):
            matrix[proxy_index[i], mass_index[index[i][j]]] += dists[i][j]
            
    return np.nan_to_num(np.flipud(matrix)), mass_hist, mass_hist2, mass_x, proxy_x
Exemple #6
0
def mo_matrix(mock, obs, matches, opts):

    index, weights, mock_index = matches

    n_z_bins = comp.num_bins(opts.z_bin[0], opts.z_bin[1], opts.z_bin[2])
    n_mass_bins = comp.num_bins(opts.mass_bin[0], opts.mass_bin[1], opts.mass_bin[2])
    n_proxy_bins = comp.num_bins(opts.proxy_bin[0], opts.proxy_bin[1], opts.proxy_bin[2])

    z_index = np.floor((mock.z - opts.z_bin[0]) / opts.z_bin[2]).astype('int')
    mass_index = np.floor((mock.mass - opts.mass_bin[0]) / opts.mass_bin[2]).astype('int')
    proxy_index = np.floor((obs.proxy - opts.proxy_bin[0]) / opts.proxy_bin[2]).astype('int')

    z_x = comp.x_vals(n_z_bins, opts.z_bin[0], opts.z_bin[2])
    mass_x = comp.x_vals(n_mass_bins, opts.mass_bin[0], opts.mass_bin[2])
    proxy_x = comp.x_vals(n_proxy_bins, opts.proxy_bin[0], opts.proxy_bin[2])

    matrix = np.zeros((n_z_bins, n_mass_bins, n_proxy_bins))
    hm_matrix = np.zeros((n_z_bins, n_mass_bins))

    for i in range(len(mass_index)):
        hm_matrix[z_index[i], mass_index[i]] += 1
        
    mock_matched = mock[mock_index]
    
    for i in range(mock_matched.size):
        if opts.unique:
            matrix[z_index[i], mass_index[i], proxy_index[index[i]]] += 1
        else:
            for j in range(len(index[i])):
                matrix[z_index[i], mass_index[i], proxy_index[index[i][j]]] += weights[i][j]

    return matrix, hm_matrix, (z_x, mass_x, proxy_x)
Exemple #7
0
def get_hist(data, bin_vals):
    """
    Generate histogram.
    """

    n_bins = comp.num_bins(bin_vals[0], bin_vals[1], bin_vals[2])
    hist = np.histogram(data, bins=n_bins, range=(bin_vals[0], bin_vals[1]))
    return np.array(hist[0], dtype='float')
Exemple #8
0
def get_hist(data, bin_vals):
    
    """
    Generate histogram.
    """
    
    n_bins = comp.num_bins(bin_vals[0], bin_vals[1], bin_vals[2])
    hist = np.histogram(data, bins = n_bins,
                        range = (bin_vals[0], bin_vals[1]))
    return np.array(hist[0], dtype = 'float')
Exemple #9
0
def get_purity(obs, matches, opts):

    index, weights, mock_index = matches

    n_proxy_bins = comp.num_bins(opts.proxy_bin[0], opts.proxy_bin[1], opts.proxy_bin[2])
    n_z_bins = comp.num_bins(opts.z_bin[0], opts.z_bin[1], opts.z_bin[2])

    proxy_index = np.floor((obs.proxy - opts.proxy_bin[0]) / opts.proxy_bin[2]).astype("int")
    z_index = np.floor((obs.z - opts.z_bin[0]) / opts.z_bin[2]).astype("int")

    proxy_count = np.zeros((n_proxy_bins, n_z_bins)).astype("float")
    match_count = np.zeros((n_proxy_bins, n_z_bins)).astype("float")

    for i in range(len(z_index)):
        proxy_count[proxy_index[i], z_index[i]] += 1.0
    for i in index:
        match_count[proxy_index[i], z_index[i]] += 1.0

    return np.flipud(match_count / proxy_count)
Exemple #10
0
def get_purity(obs, matches, opts):

    index, weights, mock_index = matches

    n_proxy_bins = comp.num_bins(opts.proxy_bin[0], opts.proxy_bin[1],
                                 opts.proxy_bin[2])
    n_z_bins = comp.num_bins(opts.z_bin[0], opts.z_bin[1], opts.z_bin[2])

    proxy_index = np.floor(
        (obs.proxy - opts.proxy_bin[0]) / opts.proxy_bin[2]).astype('int')
    z_index = np.floor((obs.z - opts.z_bin[0]) / opts.z_bin[2]).astype('int')

    proxy_count = np.zeros((n_proxy_bins, n_z_bins)).astype('float')
    match_count = np.zeros((n_proxy_bins, n_z_bins)).astype('float')

    for i in range(len(z_index)):
        proxy_count[proxy_index[i], z_index[i]] += 1.0
    for i in index:
        match_count[proxy_index[i], z_index[i]] += 1.0

    return np.flipud(match_count / proxy_count)
Exemple #11
0
 def assign_bin(self, bins):
     """
     Function that assigns a Galaxy instance to the
     corresponding Z_bin instances.
     """
     self.bin = comp.find_bin(self.z, opts.z_min, opts.z_bin_size)        
     bins[self.bin].count += 1
     if opts.mode == 'phot':
         min_z = comp.find_bin(round(self.z - self.dz * opts.link_z, 2), opts.z_min, opts.z_bin_size) #can be changed
         max_z = comp.find_bin((self.z + self.dz * opts.link_z), opts.z_min, opts.z_bin_size)            
         num_bins = comp.num_bins(min_z, max_z, 1) + 1
         for i in range(num_bins):
             self.photoz_bins.append(min_z + i)
Exemple #12
0
 def assign_bin(self, bins):
     """
     Function that assigns a Galaxy instance to the
     corresponding Z_bin instances.
     """
     self.bin = comp.find_bin(self.z, opts.z_min, opts.z_bin_size)
     bins[self.bin].count += 1
     if opts.mode == 'phot':
         min_z = comp.find_bin(round(self.z - self.dz * opts.link_z, 2),
                               opts.z_min, opts.z_bin_size)  #can be changed
         max_z = comp.find_bin((self.z + self.dz * opts.link_z), opts.z_min,
                               opts.z_bin_size)
         num_bins = comp.num_bins(min_z, max_z, 1) + 1
         for i in range(num_bins):
             self.photoz_bins.append(min_z + i)
Exemple #13
0
# READ FILE

file_name = sys.argv[1]

data = np.genfromtxt(file_name, dtype = "float", unpack = True)

z = data[0,:]
mass = data[1,:]
rich_log = np.log10(data[2,:])

# BIN

min_z = min(z)
max_z = max(z)
z_bin_size = 0.2
n_z_bins = comp.num_bins(min_z, max_z, z_bin_size)

min_rich = min(rich_log)
max_rich = max(rich_log)
rich_bin_size = 0.2
n_rich_bins = comp.num_bins(min_rich, max_rich, rich_bin_size)

print 'min rich:', min_rich
print 'max rich:', max_rich
print 'n bins:', n_rich_bins

# DEFAULTS

min_mass = 13.0
max_mass = 15.0
Exemple #14
0
# READ FILE

file_name = sys.argv[1]

data = np.genfromtxt(file_name, dtype="float", unpack=True)

z = data[0, :]
mass = data[1, :]
rich_log = np.log10(data[2, :])

# BIN

min_z = min(z)
max_z = max(z)
z_bin_size = 0.2
n_z_bins = comp.num_bins(min_z, max_z, z_bin_size)

min_rich = min(rich_log)
max_rich = max(rich_log)
rich_bin_size = 0.2
n_rich_bins = comp.num_bins(min_rich, max_rich, rich_bin_size)

print 'min rich:', min_rich
print 'max rich:', max_rich
print 'n bins:', n_rich_bins

# DEFAULTS

min_mass = 13.0
max_mass = 15.0