Esempio n. 1
0
def test_add_subtract_grid_operator():
    acq = QubicAcquisition(150, sampling, detector_ngrids=2)
    tod = map2tod(acq, input_map, convolution=False)
    add = acq.get_add_grids_operator()
    sub = acq.get_subtract_grids_operator()
    assert_same(add(tod), tod[:992] + tod[992:])
    assert_same(sub(tod), tod[:992] - tod[992:])
Esempio n. 2
0
 def func(p, n):
     p = np.asarray(p)
     smp = QubicSampling(azimuth=p[..., 0],
                         elevation=p[..., 1],
                         pitch=p[..., 2])
     acq = QubicAcquisition(qubic, smp)
     assert_equal(acq.block.n, n)
     assert_equal(len(acq.pointing), sum(n))
Esempio n. 3
0
def test_primary_beam():
    def primary_beam(theta, phi):
        import numpy as np
        with settingerr(invalid='ignore'):
            return theta <= np.radians(9)

    a = QubicAcquisition(150, s, primary_beam=primary_beam)
    p = a.get_projection_operator()
    assert_equal(p.matrix.ncolmax, 5)
Esempio n. 4
0
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)
Esempio n. 5
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)
Esempio n. 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)
Esempio n. 7
0
 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)
Esempio n. 8
0
 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)
Esempio n. 9
0
def test_load_save():
    info = 'test\nconfig'

    def func_acquisition(obs, info):
        filename_ = os.path.join(outpath, 'config-' + str(uuid1()))
        obs.save(filename_, info)
        obs2, info2 = QubicAcquisition.load(filename_)
        assert_equal(str(obs), str(obs2))
        assert_equal(info, info2)

    def func_observation(obs, tod, info):
        filename_ = os.path.join(outpath, 'obs-' + str(uuid1()))
        obs._save_observation(filename_, tod, info)
        obs2, tod2, info2 = QubicAcquisition._load_observation(filename_)
        assert_equal(str(obs), str(obs2))
        assert_equal(tod, tod2)
        assert_equal(info, info2)

    def func_simulation(obs, input_map, tod, info):
        filename_ = os.path.join(outpath, 'simul-' + str(uuid1()))
        obs.save_simulation(filename_, input_map, tod, info)
        obs2, input_map2, tod2, info2 = QubicAcquisition.load_simulation(
            filename_)
        assert_equal(str(obs), str(obs2))
        assert_equal(input_map, input_map2)
        assert_equal(tod, tod2)
        assert_equal(info, info2)

    for p in ptgs:
        p = np.asarray(p)
        smp = QubicSampling(azimuth=p[..., 0],
                            elevation=p[..., 1],
                            pitch=p[..., 2])
        acq = QubicAcquisition(qubic, smp)
        P = acq.get_projection_peak_operator()
        tod = P(input_map)
        yield func_acquisition, acq, info
        yield func_observation, acq, tod, info
        yield func_simulation, acq, input_map, tod, info
Esempio n. 10
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)
# 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 model
scene = QubicScene(hp.npix2nside(x0.size), kind='I')

# instrument model
instrument = QubicInstrument(filter_nu=150e9)

# acquisition model
acq = QubicAcquisition(instrument, sampling, scene)
x0_convolved = acq.get_convolution_peak_operator()(x0)
H = acq.get_operator()
coverage = H.T(np.ones(H.shapeout))
mask = coverage > 0

# restrict the scene to the observed pixels
acq_restricted = acq[..., mask]
H_restricted = acq_restricted.get_operator()
x0_restricted = x0[mask]
y = H_restricted(x0_restricted)
invntt = acq_restricted.get_invntt_operator()

# solve for x
A = H_restricted.T * invntt * H_restricted
b = H_restricted.T(invntt(y))
Esempio n. 12
0
nsweeps_el = 300
duration = 24  # hours
ts = 60  # seconds

# get the sampling model
np.random.seed(0)
sampling = create_sweeping_pointings([racenter, deccenter], duration, ts,
                                     angspeed, delta_az, nsweeps_el,
                                     angspeed_psi, maxpsi)
scene = QubicScene(nside)

# get the acquisition model
acquisition = QubicAcquisition(150,
                               sampling,
                               scene,
                               synthbeam_fraction=0.99,
                               detector_tau=0.01,
                               detector_nep=1.e-17,
                               detector_fknee=1.,
                               detector_fslope=1)

# simulate the timeline
tod, x0_convolved = acquisition.get_observation(x0,
                                                convolution=True,
                                                noiseless=True)

# reconstruct using two methods
map_all, cov_all = tod2map_all(acquisition, tod, tol=1e-2)
map_each, cov_each = tod2map_each(acquisition, tod, tol=1e-2)


# some display
Esempio n. 13
0
from __future__ import division
from qubic import (create_random_pointings, gal2equ, QubicAcquisition,
                   QubicScene, tod2map_all)
import numpy as np
import qubic

# read the input map
input_map = 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)
hit = acq.get_hitmap()

# Produce the Time-Ordered data
tod = acq.get_observation(input_map)
output_map, coverage = tod2map_all(acq, tod)

print(acq.comm.rank, output_map[coverage > 0][:5])
print(acq.comm.rank, hit[hit > 0][:10])
Esempio n. 14
0
pointings = create_sweeping_pointings(
    [racenter, deccenter], duration, ts, angspeed, delta_az, nsweeps_el,
    angspeed_psi, maxpsi)

tods = {}
pTxs = {}
pT1s = {}
pTx_pT1s = {}
cbiks = {}
outputs = {}
kinds = ['I', 'QU', 'IQU']
input_maps = [I,
              np.array([Q, U]).T,
              np.array([I, Q, U]).T]
for kind, input_map in zip(kinds, input_maps):
    acq = QubicAcquisition(150, pointings, kind=kind)
    P = acq.get_projection_operator()
    W = acq.get_hwp_operator()
    H = W * P
    coverage = P.pT1()
    tod = H(input_map)
    tods[kind] = tod
    pTxs[kind] = H.T(tod)[coverage > 0]
    if kind != 'QU':
        pTx_pT1 = P.pTx_pT1(tod)
        pTx_pT1s[kind] = pTx_pT1[0][coverage > 0], pTx_pT1[1][coverage > 0]
    cbik = P.canonical_basis_in_kernel()
    mask = coverage > 10
    P = P.restrict(mask, inplace=True)
    unpack = UnpackOperator(mask, broadcast='rightward')
    x0 = unpack.T(input_map)
Esempio n. 15
0
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)
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
delta_az = 15.
angspeed_psi = 0.1
maxpsi = 45.
nsweeps_el = 300
duration = 24  # hours
ts = 20  # seconds
sampling = create_sweeping_pointings([racenter, deccenter], duration, ts,
                                     angspeed, delta_az, nsweeps_el,
                                     angspeed_psi, maxpsi)
scene = QubicScene(nside, kind='I')

# acquisition model
acq = QubicAcquisition(150,
                       sampling,
                       scene,
                       synthbeam_fraction=0.99,
                       detector_fknee=fknee,
                       detector_fslope=fslope,
                       detector_ncorr=ncorr)
H_ga = acq.get_operator()
C = acq.get_convolution_peak_operator()
H = H_ga * C

# produce the Time-Ordered data
y = H(x0)

# noise
sigma = acq.instrument.detector.nep / np.sqrt(2 * sampling.period)
psd = _gaussian_psd_1f(len(acq.sampling),
                       sigma=sigma,
                       fknee=fknee,