示例#1
0
def compute_xi2(x,
                y,
                z,
                L,
                s_min,
                s_max,
                n_sbins,
                fn_save,
                nmubins=15,
                nthreads=1):
    print("Computing xi_2")
    # Set up bins (log)
    sbins = np.logspace(np.log10(smin), np.log10(smax),
                        nsbins + 1)  # note the + 1 to nbins
    s_avg = 10**(0.5 * (np.log10(sbins)[1:] + np.log10(sbins)[:-1]))

    # Use halotools to compute the quadrupole, as in this example:
    # https://halotools.readthedocs.io/en/latest/api/halotools.mock_observables.tpcf_multipole.html
    sample = np.vstack((x, y, z)).T
    mu_bins = np.linspace(0, 1, nmubins)
    xi_s_mu = s_mu_tpcf(sample, sbins, mu_bins, period=L)
    xi_2 = tpcf_multipole(xi_s_mu, mu_bins, order=1)  # Order 1 is quadrupole

    print("Saving")
    os.makedirs(os.path.dirname(savename), exist_ok=True)
    results = np.array([s_avg, xi_2])
    np.savetxt(savename, results.T, delimiter=',', fmt=['%f', '%e'])
示例#2
0
文件: test_2d.py 项目: bccp/nbodykit
def reference_sim_tpcf(pos1, redges, Nmu, BoxSize, randoms=None, pos2=None):
    """Refernce 2D 2PCF using halotools"""
    from halotools.mock_observables import s_mu_tpcf

    mu_bins = numpy.linspace(0, 1, Nmu+1)
    estimator = 'Natural' if randoms is None else 'Landy-Szalay'
    do_auto = True if pos2 is None else False
    return s_mu_tpcf(pos1, redges, mu_bins, period=BoxSize, sample2=pos2,
                    randoms=randoms, estimator=estimator, do_auto=do_auto)
示例#3
0
def reference_sim_tpcf(pos1, redges, Nmu, BoxSize, randoms=None, pos2=None):
    """Refernce 2D 2PCF using halotools"""
    from halotools.mock_observables import s_mu_tpcf

    mu_bins = numpy.linspace(0, 1, Nmu+1)
    estimator = 'Natural' if randoms is None else 'Landy-Szalay'
    do_auto = True if pos2 is None else False
    return s_mu_tpcf(pos1, redges, mu_bins, period=BoxSize, sample2=pos2,
                    randoms=randoms, estimator=estimator, do_auto=do_auto)
示例#4
0
    def tpcf_s(
        pos: np.ndarray,
        vel: np.ndarray,
        chi_range: np.array,
        mu_range: np.array,
        los: int = 2,
        boxsize: float = 500.,
        nthreads: int = 1,
    ) -> np.ndarray:
        """
        TPCF in redshift space

        Args:
        
        Note: halotools tpcf_s_mu assumes the line of sight is always the z direction
        """

        # convert real- into redshift-space coord.
        pos_s = pos.copy()
        pos_s[:, los] += vel[:, los] / 100.  #[Mpc/h]

        # enforce periodic boundary condition
        pos_s[:, los] = np.where(
            pos_s[:, los] > boxsize,
            pos_s[:, los] - boxsize,
            pos_s[:, los],
        )
        pos_s[:, los] = np.where(
            pos_s[:, los] < 0.,
            pos_s[:, los] + boxsize,
            pos_s[:, los],
        )

        if (los != 2):
            # rotate coords. to ensure los=2 as it is required by halotools
            pos_s_old = pos_s.copy()
            pos_s[:, 2] = pos_s_old[:, los]
            pos_s[:, los] = pos_s_old[:, 2]

        # compute TPCF in redshift space
        tpcf = s_mu_tpcf(
            sample1=pos_s,
            s_bins=chi_range,
            mu_bins=mu_range,
            period=boxsize,
            estimator="Landy-Szalay",
            num_threads=nthreads,
        )

        return tpcf
示例#5
0
文件: xi.py 项目: kstoreyf/clust
def xi_rsd(x, y, z, L, smin, smax, nsbins, savename, nthreads=1, order=1):
    print("Computing xi_2")
    #LOG
    sbins = np.logspace(np.log10(smin), np.log10(smax),
                        nsbins + 1)  # note the + 1 to nbins
    s_avg = 10**(0.5 * (np.log10(sbins)[1:] + np.log10(sbins)[:-1]))
    #LINEAR
    #sbins = np.linspace(smin, smax, sbins + 1) # note the + 1 to nbins
    #s_avg = 0.5*(sbins[1:] + sbins[:-1])

    sample = np.vstack((x, y, z)).T
    nmubins = 15
    mu_bins = np.linspace(0, 1, nmubins)
    xi_s_mu = s_mu_tpcf(sample, sbins, mu_bins, period=L)
    xi_2 = tpcf_multipole(xi_s_mu, mu_bins, order=order)

    print("Saving")
    os.makedirs(os.path.dirname(savename), exist_ok=True)

    print(xi_2)
    results = np.array([s_avg, xi_2])
    np.savetxt(savename, results.T, delimiter=',', fmt=['%f', '%e'])
示例#6
0
def compute_tpcf_s_mu(s,
                      mu,
                      pos,
                      vel,
                      los_direction,
                      cosmology,
                      boxsize,
                      num_threads=1):
    '''

	Computes the redshift space two point correlation function

	Args:
		s: np.array
			binning in redshift space pair distances.
		mu: np.array
			 binning in the cosine of the angle respect to the line of sight.
		pos: np.ndarray
			3-D array with the position of the tracers, in Mpc/h.
		vel: np.ndarray
			 3-D array with the velocities of the tracers, in km/s.
		los_direction: int
			line of sight direction either 0(=x), 1(=y), 2(=z)
		cosmology: dict
			dictionary containing the simulatoin's cosmological parameters.
		boxsize:  float
			size of the simulation's box.
		num_threads: int 
			number of threads to use.

	Returns:

		tpcf_s_mu: np.ndarray
			2-D array with the redshift space tpcf.

	'''

    s_pos = pos.copy()

    # Move tracers to redshift space
    s_pos[:, los_direction] += vel[:, los_direction] / 100.  # to Mpc/h

    # Apply periodic boundary conditions
    s_pos[:, los_direction] = np.where(s_pos[:, los_direction] > boxsize,
                                       s_pos[:, los_direction] - boxsize,
                                       s_pos[:, los_direction])
    s_pos[:, los_direction] = np.where(s_pos[:, los_direction] < 0.,
                                       s_pos[:, los_direction] + boxsize,
                                       s_pos[:, los_direction])

    assert np.prod((s_pos > 0) & (s_pos < boxsize))

    # Halotools tpcf_s_mu assumes the line of sight is always the z direction

    if (los_direction != 2):
        s_pos_old = s_pos.copy()
        s_pos[:, 2] = s_pos_old[:, los_direction]
        s_pos[:, los_direction] = s_pos_old[:, 2]

    tpcf_s_mu = s_mu_tpcf(s_pos,
                          s,
                          mu,
                          period=boxsize,
                          estimator=u'Landy-Szalay',
                          num_threads=num_threads)

    return tpcf_s_mu
示例#7
0
import numpy as np
from halotools.mock_observables import tpcf, s_mu_tpcf, tpcf_multipole
import matplotlib.pyplot as plt

h = 0.6726
b = 2.23
pos = np.fromfile('sample_input_gal_mx3_float32_0-1100_mpc.dat',
                  dtype=np.float32).reshape(-1, 4)[:, 1:4]*h
s_bins, mu_bins = np.arange(5, 155, 5), np.arange(0, 1.05, 0.05)
r = (s_bins[:-1] + s_bins[1:])/2
xi = tpcf(pos, s_bins, period=1100)
xi_s_mu = s_mu_tpcf(pos, s_bins, mu_bins, period=1100)
xi_0 = tpcf_multipole(xi_s_mu, mu_bins, order=0)
xi_2 = tpcf_multipole(xi_s_mu, mu_bins, order=2)
fig, ax = plt.subplots()
ax.plot(r, xi*np.square(r), 'o:', label='xi')
ax.plot(r, xi_0*np.square(r), '+:', label='xi_0')
ax.plot(r, xi_2*np.square(r), 'x-.', label='xi_2')
fig.legend()
fig.savefig('correlation.pdf')