I realized it makes much more sense to emulate in s8 than in ln10As. I'm going to convert the emulators over to that and re fit them.


In [1]:
import numpy as np
import h5py
from os import path, rename
from shutil import copyfile
from glob import glob
import pandas as pd

In [2]:
orig_param_fname = '~swmclau2/des/LH_eigenspace_lnA_np7_n40_s556.dat'

In [3]:
cosmo_params = pd.read_csv(orig_param_fname, sep = ' ', index_col = None)

In [4]:
cosmo_params.columns


Out[4]:
Index([u'ombh2', u'omch2', u'w0', u'ns', u'ln10As', u'H0', u'Neff'], dtype='object')

In [5]:
cosmo_params.iloc[0]


Out[5]:
ombh2      0.022683
omch2      0.114060
w0        -0.816597
ns         0.975589
ln10As     3.092918
H0        63.365690
Neff       2.918750
Name: 0, dtype: float64

In [6]:
new_param_fname = '/afs/slac.stanford.edu/u/ki/jderose/public_html/aemulus/phase1/cosmos.txt'
new_test_param_fname = '/afs/slac.stanford.edu/u/ki/jderose/public_html/aemulus/phase1/test_cosmos.txt'

In [7]:
new_cosmo_params = pd.read_csv(new_param_fname, sep = ' ', index_col=0)
new_test_cosmo_params = pd.read_csv(new_test_param_fname, sep = ' ', index_col=0)

In [8]:
%matplotlib inline
from matplotlib import pyplot as plt
plt.scatter(new_cosmo_params['sigma8'].as_matrix(), new_cosmo_params['ln10As'].as_matrix()) plt.scatter(new_test_cosmo_params['sigma8'].as_matrix(), new_test_cosmo_params['ln10As'].as_matrix()) plt.xlabel(r'$\sigma_8$') plt.ylabel(r'$\log 10^{10} A_s$')
plt.scatter(new_cosmo_params['sigma8'].as_matrix(), new_cosmo_params['omch2'].as_matrix()) plt.scatter(new_test_cosmo_params['sigma8'].as_matrix(), new_test_cosmo_params['omch2'].as_matrix()) plt.xlabel(r'$\sigma_8$') plt.ylabel(r'$\Omega_c h^2$')

In [8]:
new_cosmo_params.iloc[0]


Out[8]:
ombh2      0.022683
omch2      0.114060
w0        -0.816597
ns         0.975589
ln10As     3.092918
H0        63.365690
Neff       2.918750
sigma8     0.773072
Name: 0, dtype: float64

In [9]:
new_cosmo_params = new_cosmo_params.drop('ln10As', axis = 1)

In [10]:
new_test_cosmo_params = new_test_cosmo_params.drop('ln10As', axis = 1)

In [11]:
new_cosmo_params['sigma8'].as_matrix()


/afs/slac.stanford.edu/u/ki/swmclau2/.local/lib/python2.7/site-packages/ipykernel/__main__.py:1: FutureWarning: Method .as_matrix will be removed in a future version. Use .values instead.
  if __name__ == '__main__':
Out[11]:
array([0.7730715, 0.8954628, 0.6929467, 0.6715524, 0.749058 , 0.9339844,
       0.7103632, 0.7778608, 0.8919908, 0.7220269, 0.8497577, 0.8055318,
       0.7851298, 0.8660544, 0.9232811, 0.9078274, 0.8069646, 0.8695022,
       0.7356345, 0.8083719, 0.8378528, 0.7617592, 0.880451 , 0.5746315,
       0.6918467, 0.7900302, 0.9043988, 0.7285257, 0.9644551, 0.9344431,
       0.8682105, 0.9417921, 0.7208264, 0.7771575, 0.8576372, 0.6845285,
       0.9050606, 0.7255155, 0.7368773, 0.7613921])

In [12]:
np.repeat(new_test_cosmo_params['sigma8'].as_matrix(), (5,))


/afs/slac.stanford.edu/u/ki/swmclau2/.local/lib/python2.7/site-packages/ipykernel/__main__.py:1: FutureWarning: Method .as_matrix will be removed in a future version. Use .values instead.
  if __name__ == '__main__':
Out[12]:
array([0.694428 , 0.694428 , 0.694428 , 0.694428 , 0.694428 , 0.7542319,
       0.7542319, 0.7542319, 0.7542319, 0.7542319, 0.8087561, 0.8087561,
       0.8087561, 0.8087561, 0.8087561, 0.8596132, 0.8596132, 0.8596132,
       0.8596132, 0.8596132, 0.9077866, 0.9077866, 0.9077866, 0.9077866,
       0.9077866, 0.8177121, 0.8177121, 0.8177121, 0.8177121, 0.8177121,
       0.7981356, 0.7981356, 0.7981356, 0.7981356, 0.7981356])

In [13]:
base_dir = '/u/ki/swmclau2/des/'
orig_fnames = ['wp_zheng07/PearceWpCosmo.hdf5',      'wp_zheng07_test/PearceWpCosmoTest.hdf5',
               'wp_hsab/PearceWpHSABCosmo.hdf5',     'wp_hsab_test/PearceWpHSABCosmoTest.hdf5',
               'wp_cab/PearceWpCABCosmo.hdf5',       'wp_cab_test/PearceWpCABCosmoTest.hdf5',
               'wp_corrab/PearceWpCorrABCosmo.hdf5', 'wp_corrab_test/PearceWpCorrABCosmoTest.hdf5',
               'ds_zheng07/PearceDsCosmo.hdf5',      'ds_zheng07_test/PearceDsCosmoTest.hdf5',
               'ds_hsab/PearceDsHSABCosmo.hdf5',     'ds_hsab_test/PearceDsHSABCosmoTest.hdf5',
               'ds_cab/PearceDsCABCosmo.hdf5',       'ds_cab_test/PearceDsCABCosmoTest.hdf5',
               'ds_corrab/PearceDsCorrABCosmo.hdf5', 'ds_corrab_test/PearceDsCorrABCosmoTest.hdf5']

In [14]:
tmp_fname = 'tmp.hdf5'
for fname in orig_fnames: print fname orig_fname = path.join(base_dir, fname) dirname = path.dirname(orig_fname) new_fname = path.join(dirname, tmp_fname) copyfile(orig_fname, new_fname) with h5py.File(orig_fname, 'r') as orig_f, h5py.File(new_fname, 'a') as new_f: new_f.attrs['cosmo_param_names'] = np.array(list(new_cosmo_params.columns)) #cpv = new_f.attrs['cosmo_param_vals'] if 'test' in orig_fname: cpv = np.repeat(new_test_cosmo_params.as_matrix(), (5,), axis = 0) else: #cpv[:, insert_idx] = new_cosmo_params[new_key].as_matrix() cpv = new_cosmo_params.as_matrix() new_f.attrs['cosmo_param_vals'] = cpv if 'attrs' in new_f.keys(): new_f['attrs']['cosmo_param_vals'][()] = cpv rename(orig_fname, orig_fname + '_as') copyfile(new_fname, orig_fname)

In [ ]:


In [ ]: