<jupyter_start><jupyter_text>Generate Truth Power Spectrum<jupyter_code># read n(z), and create the true C_ell
z1, nz1 = np.loadtxt('/Volumes/TimeMachine/data/DR9fnl/nz_qso_rfv2.txt').T # ext=1
z2, nz2 = np.loadtxt('/Volumes/TimeMachine/data/DR9fnl/nz_qso_rf.txt').T   # ext=0
b = 1.6*np.ones_like(z1)
plt.plot(z1, nz2-nz1)

plt.xlabel('z')
plt.ylabel('n(z|ext=0)-n(z|ext=1)')
ell = np.arange(1000)

cosmo = init_cosmology()

model1 = PNGModel(cosmo, has_rsd=True, has_fnl=True)
model1.add_tracer(z1, b, nz1)

#
cl_true = model1(ell, fnl=0.0)
cl_true[0] = 0.0              # set C(ell=0) = 0.0
ell = np.arange(1000)

cosmo = init_cosmology()

model2 = PNGModel(cosmo, has_rsd=True, has_fnl=True)
model2.add_tracer(z2, b, nz2)

cl_true2 = model2(ell, fnl=0.0)
cl_true2[0] = 0.0 # set C(ell=0) = 0.0
plt.loglog(ell, cl_true,  label='n(z|ext=1)')
plt.loglog(ell, cl_true2, '--', label='n(z|ext=0)')
plt.legend()
plt.xlabel(r'$\ell$')
plt.ylabel(r'C$_{\ell}$')
np.savetxt('/Volumes/TimeMachine/data/DR9fnl/cl_true_fnl0.txt', cl_true)<jupyter_output><empty_output><jupyter_text>Create Mock Realizations<jupyter_code># read c_ell
cl_true = np.loadtxt('/Volumes/TimeMachine/data/DR9fnl/cl_true_fnl0.txt')

# read mask
mask = hp.read_map('/Volumes/TimeMachine/data/DR9fnl/north_mask_hp256.hp.fits') > 0.0
maskf = np.ones_like(mask)
weight = maskf * 1.0 # all sky is the same
# run once
cls = {'full':[], 'masked':[]}

nside = 256
nmocks = 2000

np.random.seed(42)
seeds = np.random.randint(0, 2**32-1, size=nmocks)

print(np.unique(seeds).size)
af = AnaFast()

i = 0
for seed in tqdm(seeds):
    
    np.random.seed(seed)
    map1 = hp.synfast(cl_true, nside, pol=False, )
    
    map_f = map1 - map1.mean()       # full sky
    map_p = map1 - map1[mask].mean()  # partial sky
    
    
    filename = f'/Volumes/TimeMachine/data/DR9fnl/gaussian_mocks/mock_{i:04d}.fits'
    #print(filename, map_f[maskf].mean(), map_p[mask].mean())

    hp.write_map(filename, map1, fits_IDL=False, overwrite=True, dtype='float64')
    
    cls['full'].append(af.run(map_f, weight, maskf))
    cls['masked'].append(af.run(map_p, weight, mask))
    
    i += 1
np.savez('./cl_mocks_2k_qso.npz', **cls)    
np.array(cls['full']).shape
cl_data = np.load('/Volumes/TimeMachine/data/DR9fnl/cl_qso_north_rf.npz', allow_pickle=True)
cl_data.files
shotnoise = 1.017379567874895e-06


plt.plot(np.mean(cls['full'], axis=0))
plt.plot(np.mean(cls['masked'], axis=0))
plt.plot(cl_true, 'k--', zorder=-1)

for fl in cl_data.files:
    plt.plot((cl_data[fl]-shotnoise)/4.0)

# plt.xlim(-1, 5)
plt.ylim(1.0e-9, 1.0e-4)
plt.xscale('log')
plt.yscale('log')
cls_qso = np.load('./cl_mocks_2k_qso.npz', allow_pickle=True)
cls_fid = np.load('./cl_mocks_1k.npz', allow_pickle=True)
plt.plot(cl_true, 'k--', zorder=-1)
for fl in cl_data.files:
    plt.plot((cl_data[fl]-shotnoise))

for cls_i in [cls_qso, cls_fid]:
    plt.plot(np.mean(cls_i['full'], axis=0))
plt.loglog()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1897193101115996, 'fraction_numerical': 0.04463983767331755, 'mean_word_length': 4.591682419659735, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 10, '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}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '485724', 'license': 'MIT', 'n_tokens_mistral': 1438, 'n_tokens_neox': 1358, 'n_words': 200, 'path': 'notebook/MockCreate.ipynb', 'repo_name': 'mehdirezaie/FFTLog-and-beyond', 'size': '2957'}