Пример #1
0
def read_cutsky_power_poles(filename, skiprows=31, **kwargs):
    """
    Return a list of `Power1dDataSet` objects for each multipole in
    the input data file
    """
    data = np.loadtxt(filename, skiprows=skiprows, comments=None)
    
    # make the edges
    dk = 0.005
    lower = data[:,0]-dk/2.
    upper = data[:,0]+dk/2.
    edges = np.array(list(zip(lower, upper)))
    edges = np.concatenate([edges.ravel()[::2], [edges[-1,-1]]])

    toret = []
    columns = ['k', 'mono', 'quad', 'hexadec', 'modes']
    meta = {'edges':edges}
    d = data[:,[1, 2, 3, 4, -1]]
    
    return Power1dDataSet.from_nbkit(d, meta, columns=columns, **kwargs)
Пример #2
0
def load_power(filename, mode, usecols=[], mapcols={}, **kwargs):
    """
    Load a 1D or 2D power measurement and return a `DataSet`
    """
    if mode not in ['1d', '2d']:
        raise ValueError("`mode` must be on of '1d' or '2d'")

    if mode == '1d':
        toret = Power1dDataSet.from_nbkit(*files.Read1DPlainText(filename), **kwargs)
    else:
        toret = Power2dDataSet.from_nbkit(*files.Read2DPlainText(filename), **kwargs)
    
    # rename any variables
    if len(mapcols):
        for old_name in mapcols:
            toret.rename_variable(old_name, mapcols[old_name])
    
    # only return certain variables
    if len(usecols):
        toret = toret[usecols]

    return toret
Пример #3
0
def load_momentum(filename, ell, ell_prime, **kwargs):
    """
    Return a list of mu powers as measured from momentum correlators
    """
    allowed = [(0, 0), (1, 1), (2, 2), (0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (0, 4)]
    moments = (ell, ell_prime)
    if moments not in allowed:
        raise ValueError("(ell, ell_prime) must be one of %s" %str(allowed))
    
    # load the multipoles
    poles = Power1dDataSet.from_nbkit(*files.Read1DPlainText(filename), **kwargs)
    k = poles['k']
    power = []
    
    # P00
    if moments == (0, 0):
        P_mu0 = poles['power']
        power += [P_mu0, np.nan, np.nan, np.nan, np.nan]
    
    # P01
    elif moments == (0, 1):
        P_mu2 = k * poles['power_1.imag']
        power += [np.nan, P_mu2, np.nan, np.nan, np.nan]
        
    # P11 or P02
    elif moments == (1, 1) or moments == (0, 2):
        P0 = poles['power_0.real']
        P2 = poles['power_2.real']

        P_mu2 = k**2 * (P0 - 0.5 * P2)
        P_mu4 = k**2 * 1.5 * P2
        power += [np.nan, P_mu2, P_mu4, np.nan, np.nan]
    
    # P12 or P03
    elif moments == (1, 2) or moments == (0, 3):
        
        P1 = poles['power_1.imag']
        P3 = poles['power_3.imag']
            
        P_mu4 = k**3 * (P1 - 1.5 * P3)
        P_mu6 = k**3 * 5./2 * P3
        power += [np.nan, np.nan, P_mu4, P_mu6, np.nan]
        
    # P22 or P13 or P04
    else:
        
        P0 = poles['power_0.real']
        P2 = poles['power_2.real']
        P4 = poles['power_4.real']
        
        P_mu4 = k**4 * (P0 - 0.5*P2 + 3./8*P4)
        P_mu6 = k**4 * (1.5*P2 - 15./4*P4)
        P_mu8 = k**4 * 35./8 * P4
        power += [np.nan, np.nan, P_mu4, P_mu6, P_mu8]
        
    usecols = ['k', 'modes']
    new_poles = []
    for P in power:
        if np.isscalar(P) and np.isnan(P):
            new_poles.append(np.nan)
        else:
            copy = poles.copy()
            copy = copy[usecols]
            copy['power'] = P
            new_poles.append(copy)
    
    return new_poles