Exemplo n.º 1
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)
Exemplo n.º 2
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)
Exemplo n.º 3
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
Exemplo n.º 4
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
Exemplo n.º 5
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
Exemplo n.º 6
0
 def assign_bin(self, bins, z_min, z_bin_size):
     """
     Function that assigns a Galaxy instance to the
     corresponding Z_bin instances.
     """
     self.bin = comp.find_bin(self.z, z_min, z_bin_size)
     bins[self.bin].count += 1
Exemplo n.º 7
0
def extract_psf(file_name, wavelength, radius, sigma):

    print " - Extracting PSF from file:", file_name

    # Read the FITS file Header/Data Units HDU.
    hdu = fits.open(file_name, memmap=True)[1:]

    # Set the minimum and maximum wavelengths (wl) available.
    wl_min = hdu[0].header["WLGTH0"]
    wl_max = hdu[-1].header["WLGTH0"]

    # Set the wavelength bin size.
    bin_size = hdu[1].header["WLGTH0"] - wl_min

    # Check that the requested wavelength is within the limits.
    if wl_min <= wavelength <= wl_max:

        # Find the corresponding bin number.
        hdu_bin = find_bin(wavelength, wl_min, bin_size)

        # Extract PSF.
        psf = downsample(hdu[hdu_bin].data, opts.factor)

        # Calculate PSF centroid.
        cent = np.array(Ellipticity(psf, sigma).centroid, dtype="int")

        # Crop PSF with a 20px radius.
        psf = window(psf, cent, radius)

        # Return the PSF.
        return psf

    else:

        print colored("WARNING", "yellow") + (
            ": File skipped because the "
            + "wavelength ("
            + str(opts.wavelength)
            + ") is not within the "
            + "available limits ("
            + str(wl_min)
            + ", "
            + str(wl_max)
            + ")."
        )

    # Close the HDU.
    hdu.close()