<jupyter_start><jupyter_text>3D log-normal mock  Demo of a 3D mock<jupyter_code>%matplotlib inline
import matplotlib.pyplot as plt
# plt.style.use('dark_background')
plt.rc('font', family='fantasy', size=15)
import numpy as np
import nbodykit.lab as nb
from   glob import glob
import json

#plt.rc('font', family='serif', size=18)
#plt.rc('axes.spines', right=False, top=False)
import nbodykit 
nbodykit.__version__
# cosmology
redshift = 0.85     
cosmo    = nb.cosmology.Planck15
Plin     = nb.cosmology.LinearPower(cosmo, redshift, transfer='CLASS')
print('Input cosmology ', cosmo.parameter_file)
# np.savetxt('pk.txt', np.column_stack([k, 1.5**2*Plin(k)]), header='k - P(k)')
# to load the FFTPOWER output
class loadjson(object):
    def __init__(self, file):
        with open(file) as jsonfile:
            data = json.load(jsonfile)
            self.poles = {'k':[], 'power_0':[]}
            self.attrs = data['attrs']
            
            for i in range(len(data['poles']['data']['__data__'])):
                self.poles['k'].append(data['poles']['data']['__data__'][i][0])
                self.poles['power_0'].append(data['poles']['data']['__data__'][i][1]['__complex__'][0])
            for keyi in self.poles.keys():
                self.poles[keyi] = np.array(self.poles[keyi])

# to load the FFTpower output                
from nbodykit.lab import FFTPower          
path = glob('/Volumes/TimeMachine/data/mocks_hj/3dbox_nmesh512_L5274.0_bias1.5_seed42/power*v2.json')
path
labels = ['1024', '256', '512']
plt.figure()
k = np.logspace(-3, 0, 512)
for i,pathi in enumerate(path):
    print(pathi)
    #data = loadjson(pathi)
    data = FFTPower.load(pathi)
    print(data.attrs['shotnoise'])
    plt.loglog(data.poles['k'], data.poles['power_0']-data.attrs['shotnoise'],\
               alpha=0.5, ls='-', label='nmesh=%s'%labels[i])
plt.loglog(k, 1.5**2*Plin(k), ls='--', color='k', label=r'$b^{2}P_{dm}(k)$')

# plt.axis([0.002, 0.2, 1.0e3, 5.0e4])
plt.ylabel(r'$P_{0}(k)$  $[(Mpc/h)^{3}]$')
plt.xlabel(r'$k[h/Mpc]$')
plt.legend(frameon=False)
#plt.savefig('pkmocks.pdf', bbox_inches='tight', dpi=300)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19405756731662024, 'fraction_numerical': 0.033426183844011144, 'mean_word_length': 3.810267857142857, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '585419', 'license': 'MIT', 'n_tokens_mistral': 883, 'n_tokens_neox': 827, 'n_words': 142, 'path': 'notebooks/one_3dmock.ipynb', 'repo_name': 'mehdirezaie/SYSNet', 'size': '2154'}