コード例 #1
0
def PAPER_32_all():
    '''
    Results from  PAPER 32  Jacobs et.al 2014

    outputs results[z] = n.array([k, Delta^2, 2-sigma upper, 2-sigma lower])
    '''

    PAPER_RESULTS_FILES = glob.glob(os.path.dirname(__file__)+'/data/psa32_apj/pspec_*.npz')
    PAPER_RESULTS_FILES.sort()
    PAPER_RESULTS_FILES = [f for f in PAPER_RESULTS_FILES if '110_149' not in f]
    freqs= []
    for filename in PAPER_RESULTS_FILES:
        try:
            freqs.append(n.load(filename)['freq']*1e3)
        except(KeyError):
            try:
                dchan = int(filename.split('/')[-1].split('.')[0].split('_')[2])-int(filename.split('/')[-1].split('.')[0].split('_')[1])
                chan = int(filename.split('/')[-1].split('.')[0].split('_')[1]) + dchan/2.
                freqs.append(chan/2. + 100) #a pretty good apprximation of chan 2 freq for 500kHz channels
            except: continue
    freqs = n.array(freqs)
    zs = cosmo_units.f212z(freqs*1e6)
    results = {}
    for files,z in zip(PAPER_RESULTS_FILES,zs):
        f=n.load(files)
        results[z] = n.array([f['k'],f['k3pk'],f['k3pk']+f['k3err'],f['k3pk']-f['k3err']]).T
    return results
コード例 #2
0
def get_k3pk_from_npz(files=None, verbose=False):
    """
    Load output from plot_pk_k3pk.npz and returns Delta^2 spectrum.

    Return lists of k, Delta^2, Delta^2_err ordered by  decreasing redshift
    Return format: z, k_magnitude, Delta^2, Delta^2_err
    """
    if files is None:  # check that files are passed
        print 'No Files given for loading'
        return [], [], [], []

    if len(n.shape(files)) == 0:
        files = [files]

    freqs = []
    if verbose:
        print "parsing npz file frequencies"
    for filename in files:
        if verbose:
            print filename,
        try:
            if verbose:
                print "npz..",
            freqs.append(n.load(filename)['freq'] * 1e3)  # load freq in MHz
            if verbose:
                print "[Success]"
        except (KeyError):
            if verbose:
                print "[FAIL]"
            try:
                if verbose:
                    print "looking for path like RUNNAME/chan_chan/I/pspec.npz"
                dchan = (int(filename.split('/')[1].split('_')[1]) -
                         int(filename.split('/')[1].split('_')[0]))
                chan = int(filename.split('/')[1].split('_')[0]) + dchan / 2
                freqs.append(chan / 2. + 100)
                # a pretty good apprximation of chan 2 freq for 500kHz channels
            except (IndexError):
                if verbose:
                    print "[FAIL] no freq found. Skipping..."

    if len(freqs) == 0:  # check if any files were loaded correctly
        print 'No parsable frequencies found'
        print 'Exiting'
        return [], [], [], []

    if verbose:
        print "sorting input files by frequency"
    files = n.array(files)
    files = files[n.argsort(freqs)]
    freqs = n.sort(freqs)

    if verbose:
        print "found freqs"
    freqs = n.array(freqs)
    if verbose:
        print freqs

    z = f212z(freqs * 1e6)
    if verbose:
        print "processing redshifts:", z
    k3Pk = []
    k3err = []
    kmags = []
    for i, FILE in enumerate(files):
        F = n.load(FILE)
        if verbose:
            print FILE.split('/')[-1], z[i]
        k3Pk.append(F['k3pk'])
        k3err.append(F['k3err'])
        kmags.append(F['k'])
    return z, kmags, k3Pk, k3err
コード例 #3
0
def load_pspecs(files, verbose=False):
    """
        Load output from plot_pk_k3pk.npz and returns Delta^2 spectrum.

        Return lists of k, Delta^2, Delta^2_err ordered by  decreasing redshift
        Return standard dict format {z:np.array([k,delta2,ulim,llim])}
        files : list of pspec npz files
    """

    freqs = []
    if verbose:
        print "parsing npz file frequencies"
    for filename in files:
        if verbose:
            print filename,
        try:
            if verbose:
                print "npz..",
            freqs.append(n.load(filename)['freq'] * 1e3)  # load freq in MHz
            if verbose:
                print "[Success]"
        except (KeyError):
            if verbose:
                print "[FAIL]"
            try:
                if verbose:
                    print "looking for path like RUNNAME/chan_chan/I/pspec.npz"
                dchan = (int(filename.split('/')[1].split('_')[1]) -
                         int(filename.split('/')[1].split('_')[0]))
                chan = int(filename.split('/')[1].split('_')[0]) + dchan / 2
                freqs.append(chan / 2. + 100)
                # a pretty good apprximation of chan 2 freq for 500kHz channels
            except (IndexError):
                if verbose:
                    print "[FAIL] no freq found."
                    print " You can't do science without freqs. Exiting"
                    return None

    if verbose:
        print "sorting input files by frequency"
    files = n.array(files)
    files = files[n.argsort(freqs)]
    freqs = np.array(n.sort(freqs))

    if verbose:
        print "found freqs"
        print freqs

    redshifts = f212z(freqs * 1e6)
    if verbose:
        print "processing redshifts:", redshifts
    data = {}
    for i, FILE in enumerate(files):
        F = n.load(FILE)
        if verbose:
            print FILE.split('/')[-1], redshifts[i]
        k = F['k']
        Delta2 = k**3 / (2 * np.pi**2) * F['pCv_fold']
        Delta2_err = k**3 / (2 * np.pi**2) * F['pCv_fold_err']
        data[redshifts[i]] = np.array(
            [k, Delta2, Delta2 + Delta2_err, Delta2 - Delta2_err]).T
    return data