<commit_before>'''
testing the tpcf calculation with precomputed RRs
'''
from __future__ import division
import numpy as np
from multiprocessing import cpu_count
from halotools.empirical_models import PrebuiltHodModelFactory
from halotools.mock_observables import tpcf
from halotools.empirical_models.factories.mock_helpers import three_dim_pos_bundle
from halotools.mock_observables.pair_counters import npairs
from halotools.sim_manager import CachedHaloCatalog

def test_precomputed_rr(Nr, Mr = 21):
   
    '''
    Mr = Luminositty threshold
    Nr = Number of randoms
    '''

    rbins = np.logspace(-1, 1.25, 15)
    rmax = rbins.max()
    rbin_centers = (rbins[1:] + rbins[0:-1])/2.    

    halocat = CachedHaloCatalog(simname = 'bolshoi', redshift = 0)
    model = PrebuiltHodModelFactory("zheng07")
    model.populate_mock(halocat = halocat, enforce_PBC = False)
    data = three_dim_pos_bundle(model.mock.galaxy_table, 'x', 'y', 'z')
    print data.shape
    L = halocat.Lbox

    xmin , ymin , zmin = 0., 0., 0.
    xmax , ymax , zmax = L, L, L
   
    
    num_randoms = Nr
    xran = np.random.uniform(xmin, xmax, num_randoms)
    yran = np.random.uniform(ymin, ymax, num_randoms)
    zran = np.random.uniform(zmin, zmax, num_randoms)
    randoms = np.vstack((xran, yran, zran)).T
    

    verbose = False
    num_threads = cpu_count()

    period = np.array([L,L,L])
    #period = None
    rmax = L/10.
    approx_cell1_size = [rmax, rmax, rmax]
    approx_cell2_size = approx_cell1_size
    approx_cellran_size = [rmax, rmax, rmax]

    normal_result = tpcf(
            data, rbins, data, 
            randoms=randoms, period = period, 
            max_sample_size=int(1e4), estimator='Landy-Szalay', 
            approx_cell1_size=approx_cell1_size, 
            approx_cellran_size=approx_cellran_size)


    #count data pairs
    DD = npairs(
            data, data, rbins, period,
            verbose, num_threads,
            approx_cell1_size, approx_cell2_size)
    DD = np.diff(DD)
    #count random pairs
    RR = npairs(
            randoms, randoms, rbins, period,
            verbose, num_threads,
            approx_cell1_size, approx_cell2_size)
    RR = np.diff(RR)
    #count data random pairs <commit_msg>Update test_precomputedRR_feature.py<commit_after>'''
testing the tpcf calculation with precomputed RRs
'''
from __future__ import division
import numpy as np
from multiprocessing import cpu_count
from halotools.empirical_models import PrebuiltHodModelFactory
from halotools.mock_observables import tpcf
from halotools.empirical_models.factories.mock_helpers import three_dim_pos_bundle
from halotools.mock_observables.pair_counters import npairs
from halotools.sim_manager import CachedHaloCatalog

def test_precomputed_rr(Nr, Mr = 21):
   
    '''
    Mr = Luminositty threshold
    Nr = Number of randoms
    '''

    rbins = np.logspace(-1, 1.25, 15)
    rmax = rbins.max()
    rbin_centers = (rbins[1:] + rbins[0:-1])/2.    

    halocat = CachedHaloCatalog(simname = 'bolshoi', redshift = 0)
    model = PrebuiltHodModelFactory("zheng07")
    model.populate_mock(halocat = halocat, enforce_PBC = False)
    data = three_dim_pos_bundle(model.mock.galaxy_table, 'x', 'y', 'z')
    print data.shape
    L = halocat.Lbox

    xmin , ymin , zmin = 0., 0., 0.
    xmax , ymax , zmax = L, L, L
   
    
    num_randoms = Nr
    xran = np.random.uniform(xmin, xmax, num_randoms)
    yran = np.random.uniform(ymin, ymax, num_randoms)
    zran = np.random.uniform(zmin, zmax, num_randoms)
    randoms = np.vstack((xran, yran, zran)).T
    

    verbose = False
    num_threads = cpu_count()

    period = None
    approx_cell1_size = [rmax, rmax, rmax]
    approx_cell2_size = approx_cell1_size
    approx_cellran_size = [rmax, rmax, rmax]

    normal_result = tpcf(
            data, rbins, data, 
            randoms=randoms, period = period, 
            max_sample_size=int(1e4), estimator='Landy-Szalay', 
            approx_cell1_size=approx_cell1_size, 
            approx_cellran_size=approx_cellran_size)


    #count data pairs
    DD = npairs(
            data, data, rbins, period,
            verbose, num_threads,
            approx_cell1_size, approx_cell2_size)
    DD = np.diff(DD)
    #count random pairs
    RR = npairs(
            randoms, randoms, rbins, period,
            verbose, num_threads,
            approx_cell1_size, approx_cell2_size)
    RR = np.diff(RR)
    #count data random pairs 
{'fraction_non_alphanumeric': 0.09447935368043088, 'fraction_numerical': 0.013464991023339317, 'mean_word_length': 2.9794642857142857, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6599286', 'n_tokens_mistral': 1623, 'n_tokens_neox': 1571, 'n_words': 349}