示例#1
0
def calc_feed_feed_cross_spectrum(p):

    i = p // 19 + 1
    j = p % 19 + 1
    if i == 4 or i == 6 or i == 7:
        return p
    if j == 4 or j == 6 or j == 7:
        return p

    my_map = map_cosmo.MapCosmo(mapname, feed=i, jk='half', split=0)
    my_map2 = map_cosmo.MapCosmo(mapname, feed=j, jk='half', split=1)
    print(my_map.rms.shape)
    print(my_map.rms[28, 68, :])
    my_xs = power_spectrum.CrossSpectrum(my_map, my_map2)

    xs, k, nmodes = my_xs.calculate_xs()

    rms_mean, rms_sig = my_xs.run_noise_sims(100, seed=42)

    outname = 'spectra/xs_feeds_par' + my_map.save_string + '_' + my_map2.map_string + '_%02i.h5' % j
    my_xs.make_h5(outname=outname, save_noise_realizations=True)

    lim = np.mean(np.abs(xs[4:])) * 4
    #print(xs)
    fig = plt.figure()
    fig.suptitle('feed %02i x feed %02i' % (i, j))
    ax1 = fig.add_subplot(211)
    ax1.errorbar(k, xs, rms_sig, fmt='o', label=r'$\tilde{C}_{data}(k)$')
    ax1.plot(k, 0 * rms_mean, 'k', label=r'$\tilde{C}_{noise}(k)$', alpha=0.4)
    #ax1.plot(k, theory[1:] * 100, 'r--', label=r'$100 * P_{Theory}(k)$')
    #ax1.plot(k_th, ps_th * 10, 'r--', label=r'$10 * P_{Theory}(k)$')
    ax1.set_ylabel(r'$\tilde{C}(k)$ [$\mu$K${}^2$ Mpc${}^3$]')
    ax1.set_ylim(-lim, lim)  # ax1.set_ylim(0, 0.1)
    #ax1.set_yscale('log')
    ax1.set_xscale('log')
    ax1.grid()
    plt.legend()

    ax2 = fig.add_subplot(212)
    ax2.errorbar(k,
                 xs / rms_sig,
                 rms_sig / rms_sig,
                 fmt='o',
                 label=r'$\tilde{C}_{data}(k)$')
    ax2.plot(k, 0 * rms_mean, 'k', alpha=0.4)
    ax2.set_ylabel(r'$\tilde{C}(k) / \sigma_\tilde{C}$')
    ax2.set_xlabel(r'$k$ [Mpc${}^{-1}$]')
    ax2.set_ylim(-12, 12)
    ax2.set_xscale('log')
    ax2.grid()
    plt.legend()

    folder = '/mn/stornext/d16/www_cmb/comap/xs/'
    plt.savefig(folder + 'xs_co7_par_%02i_%02i' % (i, j) + my_map.map_string +
                '_' + my_map2.map_string + '.png',
                bbox_inches='tight')
    print('Done with %02i, %02i!' % (i, j))
    return p
示例#2
0
    def __init__(self,
                 name_of_my_map,
                 jk=False,
                 feed1=None,
                 feed2=None,
                 n_of_splits=2):
        self.feed_name1 = '_feed' + str(feed1)
        self.feed_name2 = '_feed' + str(feed2)

        self.name_of_map = name_of_my_map  #the names schould indicate which map and feed we take
        self.names = []
        self.maps = []

        n_list = list(range(n_of_splits))
        all_different_possibilities = list(itr.combinations(
            n_list,
            2))  #for n_of_splits = 3, it gives [(0, 1), (0, 2), (1, 2)]
        self.how_many_combinations = len(all_different_possibilities)

        self.name_of_map = self.name_of_map.split('/')[
            -1]  #get rid of the path, leave only the name of the map
        self.name_of_map = self.name_of_map.split('.')[
            0]  #get rid of the ".h5" part
        for u in range(self.how_many_combinations):
            current_combo = all_different_possibilities[
                u]  #there are two splits from mapmaker so far, can be more from simulations
            name1 = self.name_of_map + '_split' + str(
                current_combo[0]) + self.feed_name1
            #xs_co6_map_snup_elev_0_cesc_0_split0_feed11_and_co6_map_snup_elev_0_cesc_0_split1_feed8.h5

            name2 = self.name_of_map + '_split' + str(
                current_combo[1]) + self.feed_name2
            self.names.append(name1)
            self.names.append(name2)

        for u in range(self.how_many_combinations):
            current_combo = all_different_possibilities[
                u]  #there are two splits from mapmaker so far, can be more from simulations
            my_map_split_1 = map_cosmo.MapCosmo(name_of_my_map, feed1, jk,
                                                current_combo[0])
            my_map_split_2 = map_cosmo.MapCosmo(name_of_my_map, feed2, jk,
                                                current_combo[1])
            self.maps.append(my_map_split_1)
            self.maps.append(my_map_split_2)
示例#3
0
def get_feed_ps(feed):
    my_map = map_cosmo.MapCosmo(mapname, feed=feed)

    my_ps = power_spectrum.PowerSpectrum(my_map)

    ps, k, nmodes = my_ps.calculate_ps()

    rms_mean, rms_sig = my_ps.run_noise_sims(10)
    my_ps.make_h5()
    return ps, k, rms_mean, rms_sig
示例#4
0
import corner
import h5py
import sys

import tools
import map_cosmo
import power_spectrum

try:
    mappath = sys.argv[1]
except IndexError:
    print('Missing filepath!')
    print('Usage: python ps_script.py mappath')
    sys.exit(1)

my_map = map_cosmo.MapCosmo(mappath)

my_ps = power_spectrum.PowerSpectrum(my_map)

ps, k, nmodes = my_ps.calculate_ps()

rms_mean, rms_sig = my_ps.run_noise_sims(10)

my_ps.make_h5()

fig = plt.figure()

ax1 = fig.add_subplot(211)
ax1.errorbar(k, ps, rms_sig, fmt='o', label=r'$\tilde{P}_{data}(k)$')
ax1.plot(k, rms_mean, 'k', label=r'$\tilde{P}_{noise}(k)$', alpha=0.4)
# ax1.plot(k_th, ps_th * 10, 'r--', label=r'$10 * P_{Theory}(k)$')
示例#5
0
import tools
import map_cosmo
import power_spectrum

try:
    mapname = sys.argv[1]
except IndexError:
    print('Missing filename!')
    print('Usage: python ps_script.py mapname')
    sys.exit(1)

save_folder = '/mn/stornext/u3/haavarti/www_docs/diag/ps/'

prefix = mapname[:-6].rpartition("/")[-1]

my_map = map_cosmo.MapCosmo(mapname)

my_ps = power_spectrum.PowerSpectrum(my_map)

ps, k, _ = my_ps.calculate_ps()

rms_mean, rms_sig = my_ps.run_noise_sims(10)

my_ps.make_h5()

fig = plt.figure()

ax1 = fig.add_subplot(211)
ax1.errorbar(k, ps, rms_sig, fmt='o', label=r'$\tilde{P}_{data}(k)$')
ax1.plot(k, rms_mean, 'k', label=r'$\tilde{P}_{noise}(k)$', alpha=0.4)
ax1.set_ylabel(r'$\tilde{P}(k)$ [$\mu$K${}^2$ Mpc${}^3$]')
示例#6
0
    def __init__(self,
                 list_of_n_map_names,
                 jk=False,
                 feed=None,
                 feed1=None,
                 feed2=None,
                 n_of_splits=2):
        if feed == 30:
            feed = None
            self.feed_name = '_coadded'
        if feed != 30 and feed is not None:
            self.feed_name = '_feed' + str(feed)
        else:
            self.feed_name1 = '_feed' + str(feed1)
            self.feed_name2 = '_feed' + str(feed2)
        self.names_of_maps = list_of_n_map_names  #the names schould indicate which map and feed we take
        self.names = []
        for name in self.names_of_maps:
            name = name.rpartition('/')[
                -1]  #get rid of the path, leave only the name of the map
            name = name.rpartition('.')[0]  #get rid of the ".h5" part
            if jk == False:
                if feed1 == None and feed2 == None:
                    self.names.append(name + self.feed_name)
                else:
                    self.names.append(name + self.feed_name1)
                    self.names.append(name + self.feed_name2)
            if jk != False and jk != 'sim':
                if feed1 == None and feed2 == None:
                    self.names.append(name + '_1st_' + jk + self.feed_name)
                    self.names.append(name + '_2nd_' + jk + self.feed_name)
                else:
                    self.names.append(name + '_1st_' + jk + self.feed_name1)
                    self.names.append(name + '_2nd_' + jk + self.feed_name2)
            if jk != False and jk == 'sim':
                for g in range(n_of_splits):
                    map_split_number = g + 1
                    map_split_name = 'split%01i_' % (map_split_number) + name
                    self.names.append(map_split_name)

        self.maps = []
        for map_name in list_of_n_map_names:
            if jk != False:
                if feed1 == None and feed2 == None:
                    for split_no in range(
                            n_of_splits
                    ):  #there are two splits from mapmaker so far, can be more from simulations
                        my_map_split = map_cosmo.MapCosmo(
                            map_name, feed, jk, split_no)
                        self.maps.append(my_map_split)

                else:
                    my_map_first = map_cosmo.MapCosmo(map_name, feed1, jk, 0)
                    my_map_second = map_cosmo.MapCosmo(map_name, feed2, jk, 1)
                    self.maps.append(my_map_first)
                    self.maps.append(my_map_second)
            else:
                if feed1 == None and feed2 == None:
                    my_map = map_cosmo.MapCosmo(map_name, feed)
                    self.maps.append(my_map)
                else:
                    my_map1 = map_cosmo.MapCosmo(map_name, feed1)
                    my_map2 = map_cosmo.MapCosmo(map_name, feed2)
                    self.maps.append(my_map1)
                    self.maps.append(my_map2)
示例#7
0
import map_cosmo
import power_spectrum

try:
    mapname = sys.argv[1]
    mapname2 = sys.argv[2]
except IndexError:
    print('Missing filename!')
    print('Usage: python ps_script.py mapname mapname2')
    sys.exit(1)

feeds = [1, 2, 3, 5, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]

for i in feeds:
    for j in feeds:
        my_map = map_cosmo.MapCosmo(mapname, feed=i)
        my_map2 = map_cosmo.MapCosmo(mapname2, feed=j)

        tot_rms = np.zeros_like(my_map.rms)
        where = np.where((my_map.rms * my_map2.rms) != 0)
        tot_rms[where] = np.sqrt(my_map.rms[where]**2 + my_map2.rms[where]**2)

        summap = np.zeros_like(my_map.map)
        summap[where] = (my_map.map[where] + my_map2.map[where])
        diffmap = np.zeros_like(my_map.map)
        diffmap[where] = (my_map.map[where] - my_map2.map[where])

        my_map.rms = tot_rms
        my_map.map = summap

        sum_ps = power_spectrum.PowerSpectrum(my_map)