Example #1
0
def test_noiseless():
    sampling = create_random_pointings([0, 90], 100, 10)
    acq_qubic = QubicAcquisition(150, sampling)
    acq_planck = PlanckAcquisition(150, acq_qubic.scene, true_sky=SKY)
    acq_fusion = QubicPlanckAcquisition(acq_qubic, acq_planck)
    np.random.seed(0)
    y1 = acq_fusion.get_observation()
    np.random.seed(0)
    y2 = acq_fusion.get_observation(noiseless=True) + acq_fusion.get_noise()
    assert_same(y1, y2)
Example #2
0
def test_noiseless():
    sampling = create_random_pointings([0, 90], 100, 10)
    acq_qubic = QubicAcquisition(150, sampling)
    acq_planck = PlanckAcquisition(150, acq_qubic.scene, true_sky=SKY)
    acq_fusion = QubicPlanckAcquisition(acq_qubic, acq_planck)
    np.random.seed(0)
    y1 = acq_fusion.get_observation()
    np.random.seed(0)
    y2 = acq_fusion.get_observation(noiseless=True) + acq_fusion.get_noise()
    assert_same(y1, y2)
Example #3
0
def get_qubic_map(instrument, sampling, scene, input_maps, withplanck=True, covlim=0.1):
    acq = QubicAcquisition(instrument, sampling, scene, photon_noise=True, effective_duration=1)
    C = acq.get_convolution_peak_operator()
    coverage = acq.get_coverage()
    observed = coverage > covlim * np.max(coverage)
    acq_restricted = acq[:, :, observed]
    H = acq_restricted.get_operator()
    x0_convolved = C(input_maps)
    if not withplanck:
        pack = PackOperator(observed, broadcast='rightward')
        y_noiseless = H(pack(x0_convolved))
        noise = acq.get_noise()
        y = y_noiseless + noise
        invntt = acq.get_invntt_operator()
        A = H.T * invntt * H
        b = (H.T * invntt)(y)
        preconditioner = DiagonalOperator(1 / coverage[observed], broadcast='rightward')
        solution_qubic = pcg(A, b, M=preconditioner, disp=True, tol=1e-3, maxiter=1000)
        maps = pack.T(solution_qubic['x'])
        maps[~observed] = 0
    else:
        acq_planck = PlanckAcquisition(150, acq.scene, true_sky=x0_convolved)#, fix_seed=True)
        acq_fusion = QubicPlanckAcquisition(acq, acq_planck)
        map_planck_obs=acq_planck.get_observation()
        H = acq_fusion.get_operator()
        invntt = acq_fusion.get_invntt_operator()
        y = acq_fusion.get_observation()
        A = H.T * invntt * H
        b = H.T * invntt * y
        solution_fusion = pcg(A, b, disp=True, maxiter=1000, tol=1e-3)
        maps = solution_fusion['x']
        maps[~observed] = 0
    x0_convolved[~observed] = 0
    return(maps, x0_convolved, observed)    
Example #4
0
maxiter = 1000
tol = 5e-6

sky = read_map(PATH + 'syn256_pol.fits')
nside = 256
sampling = create_random_pointings([racenter, deccenter], 1000, 10)
scene = QubicScene(nside)

acq_qubic = QubicAcquisition(150, sampling, scene, effective_duration=1)
convolved_sky = acq_qubic.instrument.get_convolution_peak_operator()(sky)
acq_planck = PlanckAcquisition(150, acq_qubic.scene, true_sky=convolved_sky)
acq_fusion = QubicPlanckAcquisition(acq_qubic, acq_planck)

H = acq_fusion.get_operator()
invntt = acq_fusion.get_invntt_operator()
y = acq_fusion.get_observation()

A = H.T * invntt * H
b = H.T * invntt * y

solution_fusion = pcg(A, b, disp=True, maxiter=maxiter, tol=tol)

acq_qubic = QubicAcquisition(150, sampling, scene, effective_duration=1)
H = acq_qubic.get_operator()
invntt = acq_qubic.get_invntt_operator()
y, sky_convolved = acq_qubic.get_observation(sky, convolution=True)

A = H.T * invntt * H
b = H.T * invntt * y

solution_qubic = pcg(A, b, disp=True, maxiter=maxiter, tol=tol)
Example #5
0
sampling = create_random_pointings([racenter, deccenter], 1000, 10)
scene = QubicScene(nside)

acq_qubic = QubicAcquisition(150, sampling, scene, effective_duration=1)
convolved_sky = acq_qubic.instrument.get_convolution_peak_operator()(sky)
cov = acq_qubic.get_coverage()
mask = cov < cov.max() * 0.2
acq_planck = PlanckAcquisition(150,
                               acq_qubic.scene,
                               true_sky=convolved_sky,
                               mask=mask)
acq_fusion = QubicPlanckAcquisition(acq_qubic, acq_planck)

H = acq_fusion.get_operator()
invntt = acq_fusion.get_invntt_operator()
y = acq_fusion.get_observation()

A = H.T * invntt * H
b = H.T * invntt * y

solution_fusion = pcg(A, b, disp=True, maxiter=maxiter, tol=tol)

acq_qubic = QubicAcquisition(150, sampling, scene, effective_duration=1)
H = acq_qubic.get_operator()
invntt = acq_qubic.get_invntt_operator()
y, sky_convolved = acq_qubic.get_observation(sky, convolution=True)

A = H.T * invntt * H
b = H.T * invntt * y

solution_qubic = pcg(A, b, disp=True, maxiter=maxiter, tol=tol)
Example #6
0
def reconstruction(racenter, deccenter, NPOINTS, NFREQS, filter_name, scene,
                   maxiter, tol, rank, n, start):
    sampling = create_random_pointings([racenter, deccenter], 1000, 10)
    detector_nep = 4.7e-17 * np.sqrt(
        len(sampling) * sampling.period / (365 * 86400))

    #x0 = read_map(PATH + 'syn256_pol.fits')
    x0 = np.zeros((12 * nside**2, 3))
    q = MultiQubicInstrument(NPOINTS=NPOINTS,
                             NFREQS=NFREQS,
                             filter_name=filter_name,
                             detector_nep=detector_nep)

    C_nf = q.get_convolution_peak_operator()
    conv_sky_ = C_nf(x0)

    fwhm_t = np.sqrt(q.synthbeam.peak150.fwhm**2 - C_nf.fwhm**2)
    C_transf = HealpixConvolutionGaussianOperator(fwhm=fwhm_t)

    acq = MultiQubicAcquisition(q, sampling, scene=scene)
    H = acq.get_operator()
    coverage = acq.get_coverage(H)

    acq_planck = MultiPlanckAcquisition(np.int(filter_name / 1e9),
                                        scene,
                                        true_sky=conv_sky_)
    acq_fusion = QubicPlanckAcquisition(acq, acq_planck)

    H = acq_fusion.get_operator()
    y = acq_fusion.get_observation()
    invntt = acq_fusion.get_invntt_operator()

    A = H.T * invntt * H
    b = H.T * invntt * y

    solution_fusion = pcg(A, b, disp=True, maxiter=maxiter, tol=tol)
    x_rec_fusion_ = solution_fusion['x']
    x_rec_fusion = C_transf(x_rec_fusion_)

    #H = acq.get_operator()
    #COV = acq.get_coverage(H)
    #y = acq.get_observation(conv_sky_)
    #invntt = acq.get_invntt_operator()

    # A = H.T * invntt * H
    # b = H.T * invntt * y

    # solution_qubic = pcg(A, b, disp=True, maxiter=maxiter, tol=tol)
    # x_rec_qubic_ = solution_qubic['x']
    # x_rec_qubic = C_transf(x_rec_qubic_)

    # conv_sky = C_transf(conv_sky_)

    path = '/home/fincardona/Qubic/map_making/maps/montecarlo'
    if rank == 0:
        hp.write_map(
            '%s/fusion_n{}_N{}_s{}_mi{}_niter{}.fits'.format(
                NFREQS, NPOINTS, len(sampling), maxiter, n + start) % path,
            x_rec_fusion.T)
        #hp.write_map('maps_test/qubic_n{}_N{}_s{}_mi{}.fits'.format(
        #    NFREQS, NPOINTS, len(sampling), maxiter), x_rec_qubic.T)
    gc.collect()
    return coverage, sampling, path
Example #7
0
def reconstruction(
        racenter, deccenter, NPOINTS, NFREQS, filter_name, scene, 
        maxiter, tol, rank, n, start):
    sampling = create_random_pointings([racenter, deccenter], 1000, 10)
    detector_nep = 4.7e-17 * np.sqrt(
        len(sampling) * sampling.period / (365 * 86400))

    #x0 = read_map(PATH + 'syn256_pol.fits')
    x0 = np.zeros((12*nside**2, 3))
    q = MultiQubicInstrument(
        NPOINTS=NPOINTS, NFREQS=NFREQS, filter_name=filter_name, 
        detector_nep=detector_nep)
    
    C_nf = q.get_convolution_peak_operator()
    conv_sky_ = C_nf(x0)
    
    fwhm_t = np.sqrt(q.synthbeam.peak150.fwhm**2 - C_nf.fwhm**2)
    C_transf = HealpixConvolutionGaussianOperator(fwhm=fwhm_t)
    
    acq = MultiQubicAcquisition(q, sampling, scene=scene)
    H = acq.get_operator()
    coverage = acq.get_coverage(H)
    
    acq_planck = MultiPlanckAcquisition(
        np.int(filter_name/1e9), scene, true_sky=conv_sky_) 
    acq_fusion = QubicPlanckAcquisition(acq, acq_planck)
    
    H = acq_fusion.get_operator()
    y = acq_fusion.get_observation()
    invntt = acq_fusion.get_invntt_operator()
    
    A = H.T * invntt * H
    b = H.T * invntt * y
    
    solution_fusion = pcg(A, b, disp=True, maxiter=maxiter, tol=tol)
    x_rec_fusion_ = solution_fusion['x']
    x_rec_fusion = C_transf(x_rec_fusion_)

    #H = acq.get_operator()
    #COV = acq.get_coverage(H)
    #y = acq.get_observation(conv_sky_)
    #invntt = acq.get_invntt_operator()
    
    # A = H.T * invntt * H
    # b = H.T * invntt * y
    
    # solution_qubic = pcg(A, b, disp=True, maxiter=maxiter, tol=tol)
    # x_rec_qubic_ = solution_qubic['x']
    # x_rec_qubic = C_transf(x_rec_qubic_)

    # conv_sky = C_transf(conv_sky_)
    
    path = '/home/fincardona/Qubic/map_making/maps/montecarlo'
    if rank==0:
        hp.write_map('%s/fusion_n{}_N{}_s{}_mi{}_niter{}.fits'.format(
            NFREQS, NPOINTS, len(sampling), maxiter, n+start) % path, 
            x_rec_fusion.T)
        #hp.write_map('maps_test/qubic_n{}_N{}_s{}_mi{}.fits'.format(
        #    NFREQS, NPOINTS, len(sampling), maxiter), x_rec_qubic.T)
    gc.collect()
    return coverage, sampling, path
    acq_qubic = acq_qubic[:ndet]
    ## acq_qubic.comm = acq_qubic.comm.Dup()
    ## acq_qubic.sampling.__dict__['comm'] = acq_qubic.sampling.comm.Dup()
    ## acq_qubic.scene.__dict__['comm'] = acq_qubic.scene.comm.Dup()
    ## acq_qubic.instrument.detector.__dict__['comm'] = acq_qubic.instrument.detector.comm.Dup()
    coverage = acq_qubic.get_coverage()
    if rank == 0:
        file_name = 'coverage_angspeed{}_delta_az{}.fits'.format(angspeed, delta_az)
        with open(directory + '/cov_map_' + file_name, 'w') as f:
            write_map(f, coverage)

    input_map = np.zeros((hp.nside2npix(nside), 3))
    acq_planck = PlanckAcquisition(band, acq_qubic.scene, true_sky=input_map)
    acq_fusion = QubicPlanckAcquisition(acq_qubic, acq_planck)

    obs_noiseless = acq_fusion.get_observation(noiseless=True)
    H = acq_fusion.get_operator()
    invntt = acq_fusion.get_invntt_operator()
    A = H.T * invntt * H

    for realization in xrange(nrealizations):
        print 'rank={}: realization {} / {}'.format(rank, realization + 1, nrealizations)

        obs = obs_noiseless + acq_fusion.get_noise()
        b = H.T * invntt * obs

        solution = pcg(A, b, disp=True, maxiter=maxiter)
        rec_map = solution['x']

        if rank == 0:
            file_name = 'angspeed{}_delta_az{}_realization{}.fits'.format(angspeed,