def write_reference():
    np.random.seed(0)
    p = create_random_pointings([0, 90], NPTG, ANGLE)
    FitsArray([p.azimuth, p.elevation, p.pitch, p.angle_hwp]).save(FILEPTG)
    for kind, map, filename in zip(['I', 'IQU'], [MAPIQU[..., 0], MAPIQU],
                                   [FILETODI, FILETODIQU]):
        acq = QubicAcquisition(INSTRUMENT, p, nside=256, kind=kind)
        tod = acq.get_observation(map, noiseless=True)
        FitsArray(tod).save(filename)
Exemple #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)
Exemple #3
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)
Exemple #4
0
def test():
    kinds = 'I', 'IQU'
    instrument = QubicInstrument(synthbeam_dtype=float)[:400]
    np.random.seed(0)
    sampling = create_random_pointings([0, 90], 30, 5)
    skies = np.ones(12 * 256**2), np.ones((12 * 256**2, 3))

    def func(sampling, kind, sky, ref1, ref2, ref3, ref4, ref5, ref6):
        nprocs_instrument = max(size // 2, 1)
        acq = QubicAcquisition(instrument,
                               sampling,
                               kind=kind,
                               nprocs_instrument=nprocs_instrument)
        assert_equal(acq.comm.size, size)
        assert_equal(acq.instrument.detector.comm.size, nprocs_instrument)
        assert_equal(acq.sampling.comm.size, size / nprocs_instrument)
        H = acq.get_operator()
        invntt = acq.get_invntt_operator()
        tod = H(sky)
        #actual1 = acq.unpack(H(sky))
        #assert_same(actual1, ref1, atol=20)
        actual2 = H.T(invntt(tod))
        assert_same(actual2, ref2, atol=20)
        actual2 = (H.T * invntt * H)(sky)
        assert_same(actual2, ref2, atol=20)
        actual3, actual4 = tod2map_all(acq, tod, disp=False, maxiter=2)
        assert_same(actual3, ref3, atol=20)
        assert_same(actual4, ref4, atol=20)
        #actual5, actual6 = tod2map_each(acq, tod, disp=False)
        #assert_same(actual5, ref5, atol=1000)
        #assert_same(actual6, ref6)

    for kind, sky in zip(kinds, skies):
        acq = QubicAcquisition(instrument,
                               sampling,
                               kind=kind,
                               comm=MPI.COMM_SELF)
        assert_equal(acq.comm.size, 1)
        H = acq.get_operator()
        invntt = acq.get_invntt_operator()
        tod = H(sky)
        ref1 = acq.unpack(tod)
        ref2 = H.T(invntt(tod))
        ref3, ref4 = tod2map_all(acq, tod, disp=False, maxiter=2)
        ref5, ref6 = None, None  #tod2map_each(acq, tod, disp=False)
        yield (func, sampling, kind, sky, ref1, ref2, ref3, ref4, ref5, ref6)
Exemple #5
0
 def _get_average_instrument_acq(self):
     q0 = self[0].instrument
     nu_min = q0.filter.nu
     nu_max = self[-1].instrument.filter.nu
     nep = q0.detector.nep
     fknee = q0.detector.fknee
     fslope = q0.detector.fslope
     q = QubicInstrument(
         filter_nu=(nu_max + nu_min) / 2.0,
         filter_relative_bandwidth=(nu_max - nu_min) / ((nu_max + nu_min) / 2.0),
         detector_nep=nep,
         detector_fknee=fknee,
         detector_fslope=fslope,
     )
     s_ = self[0].sampling
     nsamplings = self[0].comm.allreduce(len(s_))
     s = create_random_pointings([0.0, 0.0], nsamplings, 10.0, period=s_.period)
     a = QubicAcquisition(q, s, self[0].scene, photon_noise=True, effective_duration=self[0].effective_duration)
     return a
Exemple #6
0
def test():
    kinds = 'I', 'IQU'
    instrument = QubicInstrument(synthbeam_dtype=float)[:400]
    np.random.seed(0)
    sampling = create_random_pointings([0, 90], 30, 5)
    skies = np.ones(12 * 256**2), np.ones((12 * 256**2, 3))

    def func(sampling, kind, sky, ref1, ref2, ref3, ref4, ref5, ref6):
        nprocs_instrument = max(size // 2, 1)
        acq = QubicAcquisition(instrument, sampling, kind=kind,
                               nprocs_instrument=nprocs_instrument)
        assert_equal(acq.comm.size, size)
        assert_equal(acq.instrument.detector.comm.size, nprocs_instrument)
        assert_equal(acq.sampling.comm.size, size / nprocs_instrument)
        H = acq.get_operator()
        invntt = acq.get_invntt_operator()
        tod = H(sky)
        #actual1 = acq.unpack(H(sky))
        #assert_same(actual1, ref1, atol=20)
        actual2 = H.T(invntt(tod))
        assert_same(actual2, ref2, atol=20)
        actual2 = (H.T * invntt * H)(sky)
        assert_same(actual2, ref2, atol=20)
        actual3, actual4 = tod2map_all(acq, tod, disp=False, maxiter=2)
        assert_same(actual3, ref3, atol=20)
        assert_same(actual4, ref4, atol=20)
        #actual5, actual6 = tod2map_each(acq, tod, disp=False)
        #assert_same(actual5, ref5, atol=1000)
        #assert_same(actual6, ref6)

    for kind, sky in zip(kinds, skies):
        acq = QubicAcquisition(instrument, sampling, kind=kind,
                               comm=MPI.COMM_SELF)
        assert_equal(acq.comm.size, 1)
        H = acq.get_operator()
        invntt = acq.get_invntt_operator()
        tod = H(sky)
        ref1 = acq.unpack(tod)
        ref2 = H.T(invntt(tod))
        ref3, ref4 = tod2map_all(acq, tod, disp=False, maxiter=2)
        ref5, ref6 = None, None #tod2map_each(acq, tod, disp=False)
        yield (func, sampling, kind, sky, ref1, ref2, ref3, ref4, ref5, ref6)
Exemple #7
0
def test():
    instrument = QubicInstrument()[:10]
    sampling = create_random_pointings([0, 90], 30, 5)
    nside = 64
    scenes = QubicScene(nside, kind='I'), QubicScene(nside)

    def func(scene, max_nbytes, ref1, ref2, ref3, ref4, ref5, ref6):
        acq = QubicAcquisition(instrument,
                               sampling,
                               scene,
                               max_nbytes=max_nbytes)
        sky = np.ones(scene.shape)
        H = acq.get_operator()
        actual1 = H(sky)
        assert_same(actual1, ref1, atol=10)
        actual2 = H.T(actual1)
        assert_same(actual2, ref2, atol=10)
        actual2 = (H.T * H)(sky)
        assert_same(actual2, ref2, atol=10)
        actual3, actual4 = tod2map_all(acq, ref1, disp=False)
        assert_same(actual3, ref3, atol=10000)
        assert_same(actual4, ref4)
        actual5, actual6 = tod2map_each(acq, ref1, disp=False)
        assert_same(actual5, ref5, atol=1000)
        assert_same(actual6, ref6)

    for scene in scenes:
        acq = QubicAcquisition(instrument, sampling, scene)
        sky = np.ones(scene.shape)
        nbytes_per_sampling = acq.get_operator_nbytes() // len(acq.sampling)
        H = acq.get_operator()
        ref1 = H(sky)
        ref2 = H.T(ref1)
        ref3, ref4 = tod2map_all(acq, ref1, disp=False)
        ref5, ref6 = tod2map_each(acq, ref1, disp=False)
        for max_sampling in 10, 29, 30:
            max_nbytes = None if max_sampling is None \
                              else max_sampling * nbytes_per_sampling
            yield (func, scene, max_nbytes, ref1, ref2, ref3, ref4, ref5, ref6)
Exemple #8
0
def test():
    instrument = QubicInstrument()[:10]
    sampling = create_random_pointings([0, 90], 30, 5)
    nside = 64
    scenes = QubicScene(nside, kind='I'), QubicScene(nside)

    def func(scene, max_nbytes, ref1, ref2, ref3, ref4, ref5, ref6):
        acq = QubicAcquisition(instrument, sampling, scene,
                               max_nbytes=max_nbytes)
        sky = np.ones(scene.shape)
        H = acq.get_operator()
        actual1 = H(sky)
        assert_same(actual1, ref1, atol=10)
        actual2 = H.T(actual1)
        assert_same(actual2, ref2, atol=10)
        actual2 = (H.T * H)(sky)
        assert_same(actual2, ref2, atol=10)
        actual3, actual4 = tod2map_all(acq, ref1, disp=False)
        assert_same(actual3, ref3, atol=10000)
        assert_same(actual4, ref4)
        actual5, actual6 = tod2map_each(acq, ref1, disp=False)
        assert_same(actual5, ref5, atol=1000)
        assert_same(actual6, ref6)

    for scene in scenes:
        acq = QubicAcquisition(instrument, sampling, scene)
        sky = np.ones(scene.shape)
        nbytes_per_sampling = acq.get_operator_nbytes() // len(acq.sampling)
        H = acq.get_operator()
        ref1 = H(sky)
        ref2 = H.T(ref1)
        ref3, ref4 = tod2map_all(acq, ref1, disp=False)
        ref5, ref6 = tod2map_each(acq, ref1, disp=False)
        for max_sampling in 10, 29, 30:
            max_nbytes = None if max_sampling is None \
                              else max_sampling * nbytes_per_sampling
            yield (func, scene, max_nbytes, ref1, ref2, ref3, ref4, ref5, ref6)
thgal, phgal = hp.pix2ang(nsmap, np.arange(12 * nsmap**2))
llgal = np.degrees(phgal) - 180
bbgal = 90 - np.degrees(thgal)
ra, dec = gal2equ(llgal, bbgal)

mp.clf()
mp.subplot(211, projection='mollweide')
mp.plot(np.radians(llgal),np.radians(bbgal), '.')
mp.title('Galactic')
mp.subplot(212, projection='mollweide')
mp.plot(np.radians(ra-180), np.radians(dec), '.')
mp.title('Equatorial')

#### create pointings at the center of each healpix pixel
npointings = 12 * nsmap**2
initpointing = create_random_pointings([ra[0], dec[0]], npointings, 0.001)
bar = progress_bar(npointings)
for i in np.arange(npointings):
    bla = create_random_pointings([ra[i], dec[i]], 2, 0.01)
    initpointing[i] = bla[0]
    bar.update()

fracvals = [0.3, 0.5, 0.9, 0.999]
mapmean_cmb = np.zeros((len(fracvals), npointings))
mapmean_dust = np.zeros((len(fracvals), npointings))
mapmean_all = np.zeros((len(fracvals), npointings))
maprms_cmb = np.zeros((len(fracvals), npointings))
maprms_dust = np.zeros((len(fracvals), npointings))
maprms_all = np.zeros((len(fracvals), npointings))
for j in np.arange(len(fracvals)):
    frac = fracvals[j]
Exemple #10
0



############# Parameters ##########################################################
racenter = 0.0      # deg
deccenter = -57.0   # deg
center = equ2gal(racenter, deccenter)
duration = 24       # hours
ts = 30.            # seconds
ang = 20            # degrees
##################################################################################


############## True Pointing #####################################################
pointing = create_random_pointings([racenter, deccenter], duration*3600/ts, ang, period=ts)
hwp_angles = np.random.random_integers(0, 7, len(pointing)) * 11.25 
pointing.pitch = 0
pointing.angle_hwp = hwp_angles
npoints = len(pointing)
##################################################################################


############# Instrument with Alternative Primary Beam ###########################
inst = QubicInstrument(detector_tau=0.0001,
                    detector_sigma=noise,
                    detector_fknee=0.,
                    detector_fslope=1)
if hornprofile != 0:
    pb = AltPrimaryBeam(14,hornprofile)
    inst.primary_beam=pb
Exemple #11
0
from pyquad import pyquad

from pyoperators import pcg, DiagonalOperator, UnpackOperator
from pysimulators import ProjectionInMemoryOperator
from qubic import QubicConfiguration, QubicInstrument, create_random_pointings

path = os.path.dirname('/Users/hamilton/idl/pro/Qubic/People/pierre/qubic/script/script_ga.py')

nside=1024
input_map=np.zeros(12*nside**2)
input_map[0]=1

#### QUBIC Instrument
kmax = 2
qubic = QubicInstrument('monochromatic,nopol',nside=nside)
pointings = create_random_pointings(10000, 20)

#### configure observation
obs = QubicConfiguration(qubic, pointings)
C = obs.get_convolution_peak_operator()
P = obs.get_projection_peak_operator(kmax=kmax)
H = P * C

# Produce the Time-Ordered data
tod = H(input_map)

# map-making
coverage = P.T(np.ones_like(tod))
mask = coverage < 10
P.matrix.pack(mask)
P_packed = ProjectionInMemoryOperator(P.matrix)
Exemple #12
0
from __future__ import division
import numpy as np
from pyoperators.utils import settingerr
from pyoperators.utils.testing import assert_equal, assert_same, assert_is_type
from pysimulators import BeamGaussian, BeamUniformHalfSpace, FitsArray
from qubic import (
    create_random_pointings, QubicAcquisition, QubicInstrument, QubicSampling,
    QubicScene)

q = QubicInstrument()
s = create_random_pointings([0, 90], 5, 10.)


def test_detector_indexing():
    expected = FitsArray('test/data/detector_indexing.fits')
    assert_same(q.detector.index, expected)


def test_beams():
    assert_is_type(q.primary_beam, BeamGaussian)
    assert_is_type(q.secondary_beam, BeamGaussian)
    a = QubicAcquisition(150, s, primary_beam=BeamUniformHalfSpace(),
                         secondary_beam=BeamUniformHalfSpace())
    assert_is_type(a.instrument.primary_beam, BeamUniformHalfSpace)
    assert_is_type(a.instrument.secondary_beam, BeamUniformHalfSpace)


def test_primary_beam():
    def primary_beam(theta, phi):
        import numpy as np
        with settingerr(invalid='ignore'):
from __future__ import division
import numpy as np
from pyoperators.utils import settingerr
from pyoperators.utils.testing import assert_equal, assert_same, assert_is_type
from pysimulators import BeamGaussian, BeamUniformHalfSpace, FitsArray
from qubic import (create_random_pointings, QubicAcquisition, QubicInstrument,
                   QubicSampling, QubicScene)

q = QubicInstrument()
s = create_random_pointings([0, 90], 5, 10.)


def test_detector_indexing():
    expected = FitsArray('test/data/detector_indexing.fits')
    assert_same(q.detector.index, expected)


def test_beams():
    assert_is_type(q.primary_beam, BeamGaussian)
    assert_is_type(q.secondary_beam, BeamGaussian)
    a = QubicAcquisition(150,
                         s,
                         primary_beam=BeamUniformHalfSpace(),
                         secondary_beam=BeamUniformHalfSpace())
    assert_is_type(a.instrument.primary_beam, BeamUniformHalfSpace)
    assert_is_type(a.instrument.secondary_beam, BeamUniformHalfSpace)


def test_primary_beam():
    def primary_beam(theta, phi):
        import numpy as np
    create_random_pointings, equ2gal, QubicAcquisition, PlanckAcquisition,
    QubicPlanckAcquisition, QubicScene)
from qubic.data import PATH
from qubic.io import read_map
import healpy as hp
import matplotlib.pyplot as mp
import numpy as np

racenter = 0.0      # deg
deccenter = -57.0   # deg
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)
Exemple #15
0
################### Make a MC: make various maps useful later
from pysimulators import FitsArray
dtheta=15.
npointings=5000
calerror=1e-2
nbmc=1000
for n in np.arange(nbmc):
    print(' ')
    print(' ')
    print(' ')
    print('#############################')
    print('####### mc '+str(n))
    print('#############################')
    mapi,mapq,mapu=hp.synfast(spectra[1:],nside,fwhm=fwhmrad,pixwin=True,new=True)
    rnd_pointing=create_random_pointings([racenter, deccenter],npointings,dtheta)
    tod=mm.map2tod(maps,rnd_pointing,qubic)
    tod_spoiled=tod.copy()
    rndcal=np.random.normal(loc=1.,scale=calerror,size=(len(detectors),2))
    for i in np.arange(len(detectors)):
        for j in np.arange(2):
            tod_spoiled[i,:,j]=rndcal[i,j]*tod[i,:,j]

    output_maps_all,call=mm.tod2map(tod,rnd_pointing,qubic,disp=False)
    output_maps_all_spoiled,call_spoiled=mm.tod2map(tod_spoiled,rnd_pointing,qubic,disp=False)
    output_maps_det,cdet=mm.tod2map_perdet(tod,rnd_pointing,qubic,disp=False)
    output_maps_det_spoiled,cdet_spoiled=mm.tod2map_perdet(tod_spoiled,rnd_pointing,qubic,disp=False)
    covmin=np.arange(12*nside**2)
    for i in np.arange(12*nside**2):
        covmin[i]=np.min([call[i],call_spoiled[i],cdet[i],cdet_spoiled[i]])
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
Exemple #17
0
#nsweeps_el = 300
#duration = 24   # hours
#ts = 10         # seconds
#pointing = create_sweeping_pointings(
#    [racenter, deccenter], duration, ts, angspeed, delta_az, nsweeps_el,
#    angspeed_psi, maxpsi)
#pointing.angle_hwp = np.random.random_integers(0, 7, pointing.size) * 22.5
#ntimes = len(pointing)
##### Random pointing ######
racenter = 0.0
deccenter = -57.0
delta_az = 25.
duration = 1   # hours
ts = 10         # seconds
npointings = duration * 3600 / ts
pointing = create_random_pointings([racenter, deccenter], npointings, delta_az)

#### Conversion en RA DEC
import pysimulators
from astropy.time import Time, TimeDelta
DOMECLAT = -(75 + 6 / 60)
DOMECLON = 123 + 20 / 60
t0 = pointing.date_obs
dt = TimeDelta(pointing.time, format='sec')
op = (pysimulators.SphericalHorizontal2EquatorialOperator('NE', t0 + dt, DOMECLAT, DOMECLON, degrees=True))
radec = op(np.array([pointing.azimuth, pointing.elevation]).T)

clf()
subplot(2,1,1)
plot(((radec[:,0]+180 + 360) % 360) -180,radec[:,1],',')
subplot(2,1,2,projection='mollweide')
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
import healpy as hp
import matplotlib.pyplot as mp
import numpy as np
import qubic

# read the input map
x0 = qubic.io.read_map(qubic.data.PATH + 'syn256_pol.fits', field='I_STOKES')
nside = 256

# let's take the galactic north pole as the center of the observation field
center_gal = 0, 90
center = gal2equ(center_gal[0], center_gal[1])

# sampling model
np.random.seed(0)
sampling = create_random_pointings(center, 1000, 10)
scene = QubicScene(nside, kind='I')

# acquisition model
acq = QubicAcquisition(150, sampling, scene)
y, x0_convolved = acq.get_observation(x0, convolution=True, noiseless=True)

# map-making
x, coverage = tod2map_all(acq, y, disp=True, tol=1e-4, coverage_threshold=0)
mask = coverage > 0


# some display
def display(x, title):
    x = x.copy()
    x[~mask] = np.nan
Exemple #20
0
from __future__ import print_function
from multi_process import parallel_for, parallel_for_chunk
from qubic import create_random_pointings, QubicAcquisition, QubicScene
import numpy as np
import time

sampling = create_random_pointings([0, 90], 1000, 10)
scene = QubicScene()
acq = QubicAcquisition(150, sampling, scene)


def test(argument):
    #print(argument)
    time.sleep(np.random.rand()/100)
    return acq[argument].instrument.detector.center[0]

individual_arguments = np.arange(992)
#common_arguments = [scene]

#### test scalar version
def scalar_for(funct, args):
    out = []
    for a in args:
        out.append(funct(a))
    return out

res = scalar_for(test, individual_arguments)    
resp = parallel_for(test, individual_arguments,nprocs=8)

result = np.array(parallel_for(test, individual_arguments, nprocs=8))
Exemple #21
0
center = gal2equ(center_gal[0], center_gal[1])

band = 150
tol = 1e-4

# Compute frequencies at which we sample the TOD.
# As input we set 150 [GHz] - the central frequency of the band and
# the relative bandwidth -- 0.25.
# The bandwidth is assumed to be uniform.
# The number of frequencies is set by an optional parameter Nfreq, 
# which is, by default, 15 for 150 GHz band
# and 20 for 220 GHz band.
Nbfreq, nus_edge, nus, deltas, Delta, Nbbands = compute_freq(band, 0.25)

# Use random pointings for the test
p = create_random_pointings(center, 1000, 10)

# Polychromatic instrument model
q = QubicMultibandInstrument(filter_nus=nus * 1e9,
                             filter_relative_bandwidths=nus / deltas,
                             ripples=True) # The peaks of the synthesized beam are modeled with "ripples"

s = QubicScene(nside=nside, kind='IQU')

# Polychromatic acquisition model
a = QubicPolyAcquisition(q, p, s, effective_duration=2)

sp = read_spectra(0)
x0 = np.array(hp.synfast(sp, nside, new=True, pixwin=True)).T

TOD, maps_convolved = a.get_observation(x0)
Exemple #22
0
    create_random_pointings, equ2gal, QubicAcquisition, PlanckAcquisition,
    QubicPlanckAcquisition, QubicScene, QubicInstrument)
from qubic.data import PATH
from qubic.io import read_map
import healpy as hp
import matplotlib.pyplot as mp
import numpy as np

racenter = 0.0      # deg
deccenter = -57.0   # deg
center = equ2gal(racenter, deccenter)
maxiter = 1000

nside = 1024

sampling = create_random_pointings([racenter, deccenter], 5000, 5)
scene = QubicScene(nside, kind='I')

#sky = read_map(PATH + 'syn256_pol.fits')[:,0]
sky = np.zeros(12*nside**2)
ip0=hp.ang2pix(nside, np.radians(90.-center[1]), np.radians(center[0]))
v0 = np.array(hp.pix2vec(nside, ip0))
sky[ip0] = 1000
#hp.gnomview(sky, rot=center, reso=5, xsize=800)

instrument = QubicInstrument(filter_nu=150e9,
                            detector_nep=1e-30)

acq_qubic = QubicAcquisition(instrument, sampling, scene, effective_duration=1, photon_noise=False)

coverage = acq_qubic.get_coverage()
Exemple #23
0
        f_sky = np.sum(mask) / npixel
        apodization_factor = np.sum(mask) / np.sum(mask**2)
        hp.write_map('maschera.fits', mask)
    else:
        raise ValueError("who must be: kaplan or me ")
    omega = 4 * np.pi * f_sky
    return f_sky, omega, apodization_factor


nside = 256
npixel = 12 * nside**2
scene = MultiQubicScene(nside)

racenter = 0.0  # deg
deccenter = -57.0  # deg
sampling = create_random_pointings([racenter, deccenter], 1000, 10)
maxiter = 1000

years = 2
time = 60 * 60 * 24 * 365 * years
detector_nep = 4.7e-17
detector_noise = detector_nep * np.sqrt(len(sampling) * sampling.period / time)

r = 0.1
lmin = 2
lmax = nside * 2
ell = np.arange(lmin, lmax + 1)
delta_ell = 20

NFREQS = [1, 3]
NPOINTS = 1
Exemple #24
0
    P.matrix.pack(mask)
    P_packed = ProjectionInMemoryOperator(P.matrix)
    unpack = UnpackOperator(mask)
    # data
    solution = pcg(P_packed.T * P_packed, P_packed.T(tod), M=DiagonalOperator(1/coverage[~mask]), disp=disp)
    output_map = unpack(solution['x'])
    output_map[mask] = np.nan
    coverage[mask]=np.nan
    return(output_map,mask,coverage)


#### test
nside=128
npoints=1000
ini=hp.synfast(spectra[4],nside,fwhm=0,pixwin=True)
true_pointings = create_random_pointings(npoints, 20)
tod,iniconv,P=map2TOD(ini,true_pointings)
out,mask,coverage=TOD2map(tod,true_pointings,128,P=P)

mapin=hp.ud_grade(iniconv,nside_out=128,order_in='RING',order_out='RING')
mapin[mask]=np.nan

hp.gnomview(out,rot=[0,90],reso=30,min=-0.5,max=0.5)
hp.gnomview(mapin,rot=[0,90],reso=30,min=-0.5,max=0.5)
hp.gnomview(out-mapin,rot=[0,90],reso=30,min=-0.05,max=0.05)
hp.gnomview(coverage,rot=[0,90],reso=30,min=0)



from Homogeneity import fitting
l=np.arange(3*nside)