コード例 #1
0
    def write(self):
        """
        Write lens and source n(z)s to fits file for tomographic and non-tomographic cases.
        """

        nz_source = twopoint.NumberDensity(
            NOFZ_NAMES[0], self.binlow, self.z, self.binhigh,
            [self.nofz[i, :] for i in range(self.tomobins)])

        nz_source.ngal = self.neff
        nz_source.sigma_e = self.sigma_e
        nz_source.area = self.area
        kernels = [nz_source]

        if 'colour_bins' in self.params.keys():
            filename = self.output_path("nz_source_txt").replace(
                "nofz/", "nofz_%s/" % self.samples[0])
        else:
            filename = self.output_path("nz_source_txt")
        np.savetxt(filename, np.vstack((self.binlow, self.nofz)).T)

        if self.params['lensfile'] != 'None':
            nz_lens = twopoint.NumberDensity(
                NOFZ_NAMES[1], self.binlow, self.z, self.binhigh,
                [self.lens_nofz[i, :] for i in range(self.lens_tomobins)])
            nz_lens.ngal = self.lens_neff
            nz_lens.area = self.area
            kernels.append(nz_lens)
            np.savetxt(self.output_path("nz_lens_txt"),
                       np.vstack((self.binlow, self.lens_nofz)).T)

        data = twopoint.TwoPointFile([], kernels, None, None)
        data.to_fits(self.output_path("2pt"), clobber=True)

        self.write_metadata()
コード例 #2
0
def nz_from_block(block, nz_name, prefix_nz_section):
    print()
    print()
    print(
        "*************************************************************************************"
    )
    print("Saving n(z) from the block to file.")
    print(
        "A quick warning - we are assuming things about the n(z) that may not be quite right."
    )
    print("Converting from splines to histograms.")
    print("To properly fix this I will have to do a bit more work.")
    print()
    print(
        "*************************************************************************************"
    )
    print(
        "ANOTHER WARNING: this has recently changed to hopefully be slightly better"
    )
    print("It may be different to your previous results.")
    print(
        "*************************************************************************************"
    )
    print()
    print()

    if prefix_nz_section:
        section_name = "nz_" + nz_name
    else:
        section_name = nz_name

    z = block[section_name, "z"]
    dz = 0.5 * (z[10] - z[9])
    zlow = z - dz
    zhigh = z + dz
    if zlow[0] < 0:
        zlow = zlow[1:]
        z = z[1:]
        zhigh = zhigh[1:]
        cut = True
    else:
        cut = False
    assert zlow[0] > 0
    nbin = block[section_name, "nbin"]
    nzs = []
    for i in range(nbin):
        nz = block[section_name, "bin_{}".format(i + 1)]
        if cut:
            nz = nz[1:]
        nzs.append(nz)

    return twopoint.NumberDensity(nz_name, zlow, z, zhigh, nzs)
コード例 #3
0
])
info_file = open(outdir + 'info.txt', 'w')
info_file.write(info_string)
info_file.close()

#n(z)
if make_nz == True:
    print('making n(z)')
    n_dz_bins = 200
    z_edges = np.linspace(0., 1.5, n_dz_bins + 1)
    z_low = z_edges[:-1]
    z_high = z_edges[1:]
    z_mid = (z_low + z_high) / 2.
    z_range = (z_low[0], z_high[-1])
    nz_table = highdens.makenz_table(binedges,
                                     bins=200,
                                     useweights=True,
                                     sample=False,
                                     normed=True,
                                     range=z_range,
                                     usecol='z_samp')
    assert (nz_table[0] == z_low).all()
    num_dens = twopoint.NumberDensity('nz_lens',
                                      zlow=z_low,
                                      z=z_mid,
                                      zhigh=z_high,
                                      nzs=nz_table[1:],
                                      ngal=num_dens)
    fits_hdu = num_dens.to_fits()
    fits_hdu.writeto(outdir + 'nz_{0}_z_samp.fits'.format(label), clobber=True)
コード例 #4
0
import numpy as np
import twopoint

filename_list = [
    'wz_sim_sample2_specz_hist.txt',
    'wz_sim_sample4_specz_hist.txt',
    'wz_sim_sample6_specz_hist.txt',
]

outfile = 'wz_sim_sample246_maglim_specz_hist.fits'

nzs = []
for ifile, filename in enumerate(filename_list):
    zmid1, nz = np.loadtxt(filename)
    if ifile == 0:
        zmid = zmid1
    assert (zmid == zmid1).all()

    nzs.append(nz)

dz = zmid[1] - zmid[0]
zlow = zmid - dz / 2.
zhigh = zmid + dz / 2.

k = twopoint.NumberDensity('nz_lens', zlow, zmid, zhigh, nzs)
tp = twopoint.TwoPointFile([], [k], [], None)
tp.to_fits(outfile)