Exemplo n.º 1
0
    def hook(value):
        def fixdtype(dtype):
            if isinstance(dtype, list):
                true_dtype = []
                for field in dtype:
                    if len(field) == 3:
                        true_dtype.append(
                            (str(field[0]), str(field[1]), field[2]))
                    if len(field) == 2:
                        true_dtype.append((str(field[0]), str(field[1])))
                return true_dtype
            return dtype

        def fixdata(data, N, dtype):
            if not isinstance(dtype, list):
                return data

            # for structured array,
            # the last dimension shall be a tuple
            if N > 0:
                return [fixdata(i, N - 1, dtype) for i in data]
            else:
                assert len(data) == len(dtype)
                return tuple(data)

        d = None
        if '__dtype__' in value:
            dtype = fixdtype(value['__dtype__'])
            shape = value['__shape__']
            a = fixdata(value['__data__'], len(shape), dtype)
            d = numpy.array(a, dtype=dtype)

        if '__unit__' in value:
            if d is None:
                d = value['__data__']
            d = Quantity(d, Unit(value['__unit__']))

        if '__cosmo__' in value:
            d = Cosmology.from_dict(value['__cosmo__'])

        if d is not None:
            return d

        if '__complex__' in value:
            real, imag = value['__complex__']
            return real + 1j * imag

        return value
Exemplo n.º 2
0
    def hook(value):
        def fixdtype(dtype):
            if isinstance(dtype, list):
                true_dtype = []
                for field in dtype:
                    if len(field) == 3:
                        true_dtype.append((str(field[0]), str(field[1]), field[2]))
                    if len(field) == 2:
                        true_dtype.append((str(field[0]), str(field[1])))
                return true_dtype
            return dtype

        def fixdata(data, N, dtype):
            if not isinstance(dtype, list):
                return data

            # for structured array,
            # the last dimension shall be a tuple
            if N > 0:
                return [fixdata(i, N - 1, dtype) for i in data]
            else:
                assert len(data) == len(dtype)
                return tuple(data)

        d = None
        if '__dtype__' in value:
            dtype = fixdtype(value['__dtype__'])
            shape = value['__shape__']
            a = fixdata(value['__data__'], len(shape), dtype)
            d = numpy.array(a, dtype=dtype)

        if '__unit__' in value:
            if d is None:
                d = value['__data__']
            d = Quantity(d, Unit(value['__unit__']))

        if '__cosmo__' in value:
            d = Cosmology.from_dict(value['__cosmo__'])

        if d is not None:
            return d

        if '__complex__' in value:
            real, imag = value['__complex__']
            return real + 1j * imag

        return value
Exemplo n.º 3
0
def make_cosmo(param_names, param_vals):
    """
    Frequently, the parameters of our input will not align with what we need.
    So, we convert them to the appropriate format.
    :param param_names:
    :param param_vals:
    :return:
    """
    param_dict = dict([(pn, param_vals[pn]) for pn in param_names])
    # TODO it'd be nice if this could be somehow generalized.
    param_dict['N_ncdm'] = 3.0
    param_dict['N_ur'] = param_dict['Neff'] - 3.0
    del param_dict['Neff']

    #param_dict['h'] = param_dict['H0']/100
    #del param_dict['H0']
    param_dict['h'] = param_dict['h0']
    del param_dict['h0']

    #param_dict['w0_fld'] = param_dict['w']
    w = param_dict['w']
    del param_dict['w']

    param_dict['Omega_cdm'] = param_dict['Omega_m'] - param_dict['Omega_b']
    del param_dict['Omega_b']
    del param_dict['Omega_m']

    param_dict['Omega_ncdm'] = [
        param_dict['Omeganuh2'] / (param_dict['h']**2), 0.0, 0.0
    ]
    #param_dict['m_ncdm']=None
    #param_dict['omch2'] = (param_dict['Omega_m'] - param_dict['Omega_b'] - param_dict['Omega0_ncdm_tot'])*(param_dict['h']**2)
    del param_dict['Omeganuh2']

    #param_dict['A_s'] = 10**(np.log10(np.exp(param_dict['ln_1e10_A_s']))-10.0)
    param_dict['A_s'] = 10**(-10) * np.exp(param_dict['ln(10^{10}A_s)'])
    del param_dict['ln(10^{10}A_s)']

    #print param_dict
    # this is seriously what i have to do here.
    C = Cosmology()
    C2 = C.from_dict(param_dict)
    C3 = C2.clone(w0_fld=w)
    return C3  #Cosmology(**param_dict)
Exemplo n.º 4
0
from nbodykit.cosmology import Planck15, EHPower, Cosmology
from nbodykit.algorithms.fof import FOF
from nbodykit.lab import KDDensity, BigFileMesh, BigFileCatalog, ArrayCatalog, FieldMesh, FFTPower
import sys, os, json, yaml
from solve import solve
from getbiasparams import getbias, eval_bfit
sys.path.append('../')
sys.path.append('../utils/')
import HImodels

klin, plin = numpy.loadtxt('../../data/pklin_1.0000.txt', unpack=True)
ipk = interpolate(klin, plin)
#cosmo = Planck15.clone(Omega_cdm = 0.2685, h = 0.6711, Omega_b = 0.049)
cosmodef = {'omegam': 0.309167, 'h': 0.677, 'omegab': 0.048}
cosmo = Cosmology.from_dict(cosmodef)

#########################################

#Set parameters here
##
cfname = sys.argv[1]
upsample = bool(float(sys.argv[2]))
with open(cfname, 'r') as ymlfile:
    cfg = yaml.load(ymlfile)
for i in cfg['basep'].keys():
    locals()[i] = cfg['basep'][i]
zz = 1 / aa - 1

if upsample: ncd = nc * 2
else: ncd = nc