Пример #1
0
def compute_shear_EB_spec_from_plus_cross(plus_map,
                                          cross_map,
                                          fov,
                                          spec='EE',
                                          binsize=10):
    nside = plus_map.shape[0]
    fov_rad = fov * pi / 180

    f_plus = np.fft.fft2(plus_map)
    f_cross = np.fft.fft2(cross_map)
    lx_array, ly_array = map_making_functions.make_lxy_arrays(
        nside, fov)  #fov in degrees
    cos_2phi_l = (lx_array**2 - ly_array**2) / (lx_array**2 + ly_array**2)
    sin_2phi_l = (2 * lx_array * ly_array) / (lx_array**2 + ly_array**2)
    cos_2phi_l[0, 0] = 0  #1
    sin_2phi_l[0, 0] = 0  #1

    f_E = cos_2phi_l * f_plus + sin_2phi_l * f_cross
    f_B = -1 * sin_2phi_l * f_plus + cos_2phi_l * f_cross

    if spec == 'EE':
        a_l_1 = a_l_2 = f_E * (fov_rad / nside)**2
    elif spec == 'EB':
        a_l_1 = f_E * (fov_rad / nside)**2
        a_l_2 = f_B * (fov_rad / nside)**2
    elif spec == 'BB':
        a_l_1 = a_l_2 = f_B * (fov_rad / nside)**2

    result = get_c_l(a_l_1, a_l_2, fov_rad, nside, binsize)
    return (result)
Пример #2
0
if exp == 'advact':  #150 GHz channel from Henderson et al
    delta_T = 7
    delta_P = delta_T * np.sqrt(2)
    theta = 1.4

elif (exp[0:3] == 'ref'):
    delta_T = float(exp[3:])
    delta_P = delta_T * np.sqrt(2)
    theta = 15  #sigma_am_ref

exp_print = exp + '_noise_' + str(round(delta_T, 2)) + '_' + 'beam_' + str(
    round(theta, 2))
map_print = '_' + str(nside_lens) + '_' + str(int(fov_deg))

l_array_lens = map_making_functions.make_l_array(nside_lens, fov_deg)
lx_lens, ly_lens = map_making_functions.make_lxy_arrays(nside_lens, fov_deg)

phi_l_lens = np.arctan(ly_lens / lx_lens)
phi_l_lens[0, 0] = 0.
phi_l_lens = -phi_l_lens

l_array_cmb = map_making_functions.make_l_array(nside_cmb, fov_deg)
lx_cmb, ly_cmb = map_making_functions.make_lxy_arrays(nside_cmb, fov_deg)

phi_l_cmb = np.arctan(ly_cmb / lx_cmb)
phi_l_cmb[0, 0] = 0.
phi_l_cmb = -phi_l_cmb

print(sadasd)

if make_maps:
Пример #3
0
def compute_deflection_spectrum(alpha_x, alpha_y, fov, binsize=20):
    nside = alpha_x.shape[0]
    fov_rad = fov * pi / 180

    a_l_x = np.fft.fft2(alpha_x) * (fov_rad / nside)**2
    a_l_y = np.fft.fft2(alpha_y) * (fov_rad / nside)**2

    c_l_xy = np.abs(np.conj(a_l_x) * a_l_y)
    c_l_x = np.abs(a_l_x)**2
    c_l_y = np.abs(a_l_y)**2

    l_arr = map_making_functions.make_l_array(nside, fov)
    lx, ly = map_making_functions.make_lxy_arrays(nside, fov)

    c_l_alpha = 1 / l_arr**2 * (lx**2 * c_l_x + ly**2 * c_l_y
                                )  # + 2*lx*ly*c_l_xy)
    c_l_x_rescaled = lx**2 * c_l_x / l_arr**2
    c_l_y_rescaled = ly**2 * c_l_y / l_arr**2
    c_l_xy_rescaled = 2 * lx * ly * c_l_xy / l_arr**2

    ##print 'alpha x spec:', c_l_x
    ##print 'alpha spec:', c_l_alpha

    ls = np.arange(3, lmax, binsize)
    c_l_binned = np.zeros(ls.shape)
    c_l_x_binned = np.zeros(ls.shape)
    c_l_y_binned = np.zeros(ls.shape)
    c_l_xy_binned = np.zeros(ls.shape)
    for i, l in enumerate(ls):
        c_l_binned[i] = np.average(
            c_l_alpha[np.where((l_arr > l) & (l_arr < l + binsize))])
        c_l_x_binned[i] = np.average(
            c_l_x_rescaled[np.where((l_arr > l) & (l_arr < l + binsize))])
        c_l_y_binned[i] = np.average(
            c_l_y_rescaled[np.where((l_arr > l) & (l_arr < l + binsize))])
        c_l_xy_binned[i] = np.average(
            c_l_xy_rescaled[np.where((l_arr > l) & (l_arr < l + binsize))])
        ##print l, 'has', ((l_arr>l)&(l_arr<l+binsize)).sum(),'bins'
    ls += binsize / 2

    patch_to_sky_factor = 2 * pi * fov_rad**2 / (4 * pi)
    c_l_binned /= patch_to_sky_factor
    c_l_x_binned /= patch_to_sky_factor
    c_l_y_binned /= patch_to_sky_factor
    c_l_xy_binned /= patch_to_sky_factor

    def_mag = np.sqrt(alpha_x**2 + alpha_y**2)
    c_l_mag = np.abs(np.fft.fft2(def_mag) * (fov_rad / nside)**2)**2
    c_l_mag_binned = np.zeros(ls.shape)
    for i, l in enumerate(ls):
        c_l_mag_binned[i] = np.average(
            c_l_mag[np.where((l_arr > l) & (l_arr < l + binsize))])
    c_l_mag_binned /= patch_to_sky_factor

    plt.plot(ls,
             np.sqrt(ls * (ls + 1) / (2 * pi) * c_l_binned),
             label='x and y combined from map')
    #plt.plot(ls, np.sqrt(ls*(ls+1)/(2*pi)*c_l_mag_binned), label='from map')
    #plt.plot(ls, np.sqrt(ls*(ls+1)/(2*pi)*c_l_x_binned), label=r'$\left(\frac{l_x}{l}\right)^2 c_l^{\alpha_x}$ from map')
    #plt.plot(ls, np.sqrt(ls*(ls+1)/(2*pi)*c_l_y_binned), label=r'$\left(\frac{l_x}{l}\right)^2 c_l^{\alpha_y}$ from map')
    #plt.plot(ls, np.sqrt(ls*(ls+1)/(2*pi)*np.abs(c_l_xy_binned)), label=r'$2\frac{l_x l_y}{l^2} c_l^{\alpha_x\alpha_y}$ from map')
    plt.plot(l_vec,
             np.sqrt(l_vec * (l_vec + 1) / (2 * pi) * cl_dd),
             label='from camb')
    plt.legend(loc='lower center')
    plt.xlim(1, 10000)
    plt.xscale('log')
    plt.yscale('log')
    plt.xlabel('L')
    plt.ylabel(r'$[l(l+1)C^{\alpha\alpha}_L/2\pi]^{1/2}$')
    plt.title('deflection angle power spec')
    plt.show()

    result = (ls, c_l_binned)
    return (result)
Пример #4
0
def get_c_l_with_error(a_l_1,
                       a_l_2,
                       fov_rad,
                       nside,
                       binsize,
                       shear=False,
                       spec=False):
    fov = fov_rad * 180 / pi
    c_l = np.conj(a_l_1) * a_l_2
    ##print 'power spectrum (should be real)',c_l
    c_l = abs(c_l)
    l_arr = map_making_functions.make_l_array(nside, fov)

    plt.imshow(c_l)

    ##print spec
    ##print shear

    lx_array, ly_array = map_making_functions.make_lxy_arrays(nside, fov)
    cos_2theta_array = (lx_array**2 - ly_array**2) / (lx_array**2 +
                                                      ly_array**2)
    sin_2theta_array = (2 * lx_array * ly_array) / (lx_array**2 + ly_array**2)

    if shear == 'shear_plus' and (spec == 'tb' or spec == 'eb'):
        #print 'tb/eb shear plus'
        c_for_err = c_l / sin_2theta_array**2
        fac = sin_2theta_array**2
    elif shear == 'shear_cross' and (spec == 'tb' or spec == 'eb'):
        c_for_err = c_l / cos_2theta_array**2
        fac = cos_2theta_array**2
    elif shear == 'shear_plus':
        c_for_err = c_l / cos_2theta_array**2
        fac = cos_2theta_array**2
    elif shear == 'shear_cross':
        c_for_err = c_l / sin_2theta_array**2
        fac = sin_2theta_array**2
    """
    plt.imshow(np.fft.fftshift(l_arr))
    plt.colorbar()
    plt.show()

    plt.title(spec+' '+shear)
    plt.subplot(131)
    plt.imshow(np.fft.fftshift(l_arr*(l_arr+1)*c_l))
    plt.colorbar(shrink=0.6)
    plt.title('2D spectrum')
    plt.subplot(132)
    plt.imshow(np.fft.fftshift(fac))
    plt.colorbar(shrink=0.6)
    plt.title('cos/sin')
    plt.subplot(133)
    plt.imshow(np.isfinite(np.fft.fftshift((c_for_err))))#, vmin=0, vmax=4)
    plt.colorbar(shrink=0.6)
    plt.title('2D spec to use for error')
    plt.show()
    """
    """
    c_l=np.reshape(c_l,newshape=(nside**2,))
    c_for_err=np.reshape(c_for_err,newshape=(nside**2,))
    l_arr.shape =(nside**2,)
    ind_list=l_arr.argsort()
    l_arr=l_arr[ind_list]
    c_l=c_l[ind_list]
    c_for_err=c_for_err[ind_list]
    """
    #c_l=smooth.smooth(c_l,500,"flat")

    ls = np.arange(3, lmax, binsize)
    c_l_binned = np.zeros(ls.shape)
    error = np.zeros(ls.shape)
    for i, l in enumerate(ls):
        c_l_binned[i] = np.nanmean(
            c_l[np.where((l_arr > l) & (l_arr < l + binsize)
                         & (np.isfinite(c_l)))])
        """
        if i==5 or i==20:
            plt.subplot(131)
            plt.imshow(c_l)
            plt.colorbar()
            plt.subplot(132)
            plt.imshow(2*c_l_binned[i]*cos_2theta_array**2)
            plt.colorbar()
            plt.subplot(133)
            plt.imshow((c_l-2*c_l_binned[i]*cos_2theta_array**2))
            plt.colorbar()
            plt.show()
            #print 'max=',np.amax((c_l-2*c_l_binned[i]*cos_2theta_array**2)[np.where((l_arr>l)&(l_arr<l+binsize))])
            #print 'min=', np.amin((c_l-2*c_l_binned[i]*cos_2theta_array**2)[np.where((l_arr>l)&(l_arr<l+binsize))])
            #print 'mean=', np.mean((c_l-2*c_l_binned[i]*cos_2theta_array**2)[np.where((l_arr>l)&(l_arr<l+binsize))])"""
        if shear == 'shear_plus' and (spec == 'tb' or spec == 'eb'):
            error[i] = np.nanstd(
                (c_l - 2 * c_l_binned[i] * sin_2theta_array**2)[np.where(
                    (l_arr > l)
                    & (l_arr < l + binsize))])  #&(np.isfinite(c_for_err))
            if False:  #l<200:
                plt.hist((c_l - 2 * c_l_binned[i] * sin_2theta_array**2
                          )[np.where((l_arr > l) & (l_arr < l + binsize))],
                         bins=31)
                plt.title('c-2*cbin*sin^2(2phi)')
                plt.show()

        elif shear == 'shear_cross' and (spec == 'tb' or spec == 'eb'):
            error[i] = np.nanstd(
                (c_l - 2 * c_l_binned[i] * cos_2theta_array**2
                 )[np.where((l_arr > l) & (l_arr < l + binsize))])
            if False:
                plt.hist((c_l - 2 * c_l_binned[i] * cos_2theta_array**2
                          )[np.where((l_arr > l) & (l_arr < l + binsize))],
                         bins=101)
                plt.title('c-2*cbin*cos^2(2phi)')
                plt.show()
        elif shear == 'shear_plus':
            error[i] = np.nanstd(
                (c_l - 2 * c_l_binned[i] * cos_2theta_array**2
                 )[np.where((l_arr > l) & (l_arr < l + binsize))])
            if False:
                plt.hist((c_l - 2 * c_l_binned[i] * cos_2theta_array**2
                          )[np.where((l_arr > l) & (l_arr < l + binsize))],
                         bins=101)
                plt.title('c-2*cbin*cos^2(2phi)')
                plt.show()
        elif shear == 'shear_cross':
            error[i] = np.nanstd(
                (c_l - 2 * c_l_binned[i] * sin_2theta_array**2
                 )[np.where((l_arr > l) & (l_arr < l + binsize))])
            if False:
                plt.hist((c_l - 2 * c_l_binned[i] * sin_2theta_array**2
                          )[np.where((l_arr > l) & (l_arr < l + binsize))],
                         bins=101)
                plt.title('c-2*cbin*sin^2(2phi)')
                plt.show()
        else:
            error[i] = np.nanstd(c_l[np.where((l_arr > l)
                                              & (l_arr < l + binsize))])
            if False:  # l<200:
                plt.hist(c_l[np.where((l_arr > l) & (l_arr < l + binsize))],
                         bins=31)
                plt.title('Pixel histogram for power in annulus for ' + spec +
                          ' conv for l=' + str(l))
                plt.show()

                plt.hist(np.absolute(a_l_1[np.where((l_arr > l)
                                                    & (l_arr < l + binsize))]),
                         bins=31)
                plt.title('Pixel histogram for amplitude in annulus for ' +
                          spec + ' conv for l=' + str(l))
                plt.show()

    ##print l, 'has', ((l_arr>l)&(l_arr<l+binsize)).sum(),'bins'
    ls += binsize / 2
    if shear == 'shear_plus' or shear == 'shear_cross':
        error /= 2  #is this def legit?
    ##print c_l_binned.shape

    patch_to_sky_factor = 2 * pi * fov_rad**2 / (4 * pi)
    c_l_binned /= patch_to_sky_factor
    error /= patch_to_sky_factor

    #c_l_binned*=2*pi    #I think this has to go here because of my Fourier conventions, but it is only needed for reconstructed spectra??
    result = (
        ls, c_l_binned, error
    )  #multiply by 2pi**2 coz using Hu&Okamoto's Fourier conventions??
    return (result)
print 'fov', fov_deg


#This band-pass function defines which l-modes we plot for the convergence or shear map plots at the end.
def band_pass_fun(l):
    lmin = 30  #>>15#15#60#15 * 15./fov_deg
    lmax = 200  #>>100#150#100#200 * 15./fov_deg
    if l < lmin:
        return (0.)
    if l > lmax:
        return (0.)
    return (1.)


l_array = map_making_functions.make_l_array(nside, fov_deg)
lx, ly = map_making_functions.make_lxy_arrays(nside, fov_deg)

exp_print = exp + '_noise_' + str(round(delta_t_am, 2)) + '_' + 'beam_' + str(
    round(sigma_am, 2))
spec_print = spec + '_' + str(nside) + '_' + str(int(fov_deg))

# Load in the filter for the chosen estimator, sort out code to make plus and minus filters
if spec == 'plus':
    spec_filt = 'ee'
elif spec == 'minus' and est == 'conv':
    spec_filt = 'ee'
elif spec == 'cross':
    spec_filt = 'te'  #Not actually used
else:
    spec_filt = spec
if est == 'conv':