コード例 #1
0
def test_polarizer():
    sampling = QubicSampling(0, 0, 0)
    scene = QubicScene(150, kind='I')
    instruments = [
        QubicInstrument(polarizer=False, detector_ngrids=2),
        QubicInstrument(polarizer=True, detector_ngrids=2),
        QubicInstrument(polarizer=False),
        QubicInstrument(polarizer=True),
        QubicInstrument(polarizer=False, detector_ngrids=2)[:992],
        QubicInstrument(polarizer=True, detector_ngrids=2)[:992]
    ]

    n = len(instruments[0])
    expecteds = [
        np.r_[np.ones(n // 2), np.zeros(n // 2)],
        np.full(n, 0.5),
        np.ones(n // 2),
        np.full(n // 2, 0.5),
        np.ones(n // 2),
        np.full(n // 2, 0.5)
    ]

    def func(instrument, expected):
        op = instrument.get_polarizer_operator(sampling, scene)
        sky = np.ones((len(instrument), 1))
        assert_equal(op(sky).ravel(), expected)

    for instrument, expected in zip(instruments, expecteds):
        yield func, instrument, expected
コード例 #2
0
def create_acquisition_operator_TOD(pointing, parameters):
    s = QubicScene(nside=parameters['nside'], kind='IQU')
    ### Operators for TOD creation #######################################################
    ## number of sub frequencies to build the TOD
    Nf = int(parameters['nf_sub_build'])
    band = parameters['band']
    relative_bandwidth = parameters['relative_bandwidth']
    Nbfreq_in, nus_edge_in, nus_in, deltas_in, Delta_in, Nbbands_in = compute_freq(
        band, relative_bandwidth, Nf)

    # Polychromatic instrument model
    q = QubicMultibandInstrument(
        filter_nus=nus_in * 1e9,
        filter_relative_bandwidths=deltas_in / nus_in,
        #TD = parameters['TD'],
        ripples=parameters['ripples']
    )  # The peaks of the synthesized beam are modeled with "ripples"

    # Multi-band acquisition model for TOD fabrication
    atod = QubicMultibandAcquisition(
        q,
        pointing,
        s,
        nus_edge_in,
        effective_duration=parameters['effective_duration'],
        photon_noise=False)
    ######################################################################################

    return atod
コード例 #3
0
    def _direct_convolution_(scene,
                             position,
                             area,
                             nu,
                             bandwidth,
                             horn,
                             primary_beam,
                             secondary_beam,
                             synthbeam,
                             theta_max=30):

        rotation = DenseBlockDiagonalOperator(np.eye(3)[None, ...])
        aperture = MultiQubicInstrument._get_aperture_integration_operator(
            horn)
        scene_nopol = QubicScene(scene.nside, kind='I')
        projection = MultiQubicInstrument._get_projection_operator(
            rotation,
            scene_nopol,
            nu,
            position,
            synthbeam,
            horn,
            primary_beam,
            verbose=False)
        masked_sky = MultiQubicInstrument._mask(scene, theta_max)
        peak_pos = projection.matrix.data.index
        pos = MultiQubicInstrument._check_peak(scene,
                                               peak_pos,
                                               peak_pos,
                                               theta_max,
                                               dtype=np.int32)
        value = MultiQubicInstrument._check_peak(scene,
                                                 projection.matrix.data.value,
                                                 peak_pos,
                                                 theta_max,
                                                 dtype=np.float64)
        integ = MultiQubicInstrument._get_detector_integration_operator(
            position, area, secondary_beam)
        b = BeamGaussian(synthbeam.peak150.fwhm / nu * 150e9)
        theta0, phi0, uvec0 = MultiQubicInstrument._index2coord(
            scene.nside, pos)
        theta, phi, uvec = MultiQubicInstrument._index2coord(
            scene.nside, masked_sky)
        dot = np.dot(uvec0, uvec.T)
        dot[dot > 1] = 1
        dtheta = np.arccos(dot)  # (#npeaks, #pixels_inside_mask)
        maps = b(dtheta, 0)
        maps /= np.sum(maps, axis=-1)[..., None]
        Map = np.sum((maps * value[..., None]), axis=1)
        Map = integ(aperture(Map))
        Map *= bandwidth * deriv_and_const(nu, scene.nside)
        return MultiQubicInstrument._masked_beam(scene, Map, theta_max)
コード例 #4
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)
コード例 #5
0
# 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)
maps_recon = a.tod2map(TOD, tol=tol)

cov = a.get_coverage().sum(axis=0)

mp.figure(1)
_max = [300, 5, 5]
for i, (inp, rec, iqu) in enumerate(zip(maps_convolved.T, maps_recon.T, 'IQU')):
コード例 #6
0
import numpy as np
import qubic

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

# 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]
コード例 #7
0
racenter = 0.0  # deg
deccenter = -57.0  # deg
angspeed = 1  # deg/sec
delta_az = 15.  # deg
angspeed_psi = 0.1  # deg/sec
maxpsi = 45.  # deg
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)
コード例 #8
0
def deriv_and_const(nu, nside):
    # Power contribution for each pixel of the sky
    T = QubicScene().T_cmb
    return (8 * np.pi / (12 * nside**2) * 1e-6 * h**2 * nu**4 /
            (k * c**2 * T**2) * np.exp(h * nu / (k * T)) /
            (np.expm1(h * nu / (k * T)))**2)
コード例 #9
0
ファイル: script_mpi.py プロジェクト: mwrightqub/qubic
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])
コード例 #10
0
for i in xrange(len(allfiles)):
    print(i, len(allfiles))
    maps = getmapsready(allfiles[i], newns, pixok)
    allmaps[i,:,:] = maps[pixok,:].T

meanmaps = np.mean(allmaps,axis=0)
iqumeanmaps = np.zeros((12*newns**2, 3))
for i in [0,1,2]: iqumeanmaps[pixok, i] = meanmaps[i,:]
display(iqumeanmaps, range=[1, 1, 1])


from qubic import (QubicAcquisition,
                   PlanckAcquisition,
                   QubicPlanckAcquisition, QubicScene)
nside = 256
scene = QubicScene(nside)
sky = scene.zeros()
acq_planck = PlanckAcquisition(150, scene, true_sky=sky)
obs_planck = acq_planck.get_observation()
Iplanck = hp.ud_grade(obs_planck[:,0], nside_out=newns)
Qplanck = hp.ud_grade(obs_planck[:,1], nside_out=newns)
Uplanck = hp.ud_grade(obs_planck[:,2], nside_out=newns)
planckmaps = np.array([Iplanck, Qplanck, Uplanck]).T

figure()
clf()
display(iqumeanmaps, range=[1, 1, 1])
figure()
clf()
display(iqumeanmaps-planckmaps, range=[1, 1, 1])
コード例 #11
0
                total_integrals(
                    grid, n, nside, T, idet, theta_max, NPOINTS=NPOINTS)

            elif kind == 'direct_conv':
                total_integrals(
                    grid, n, nside, T, idet, theta_max, syb_f=syb_f, 
                    NPOINTS=NPOINTS)

            else: print('ERROR')
            gc.collect()

if __name__ == "__main__":

    # Parameters
    nside = 1024
    T_cmb = QubicScene().T_cmb         # Kelvin
    
    idet = 231

    syb_f = 0.99
    theta_max = 30
    
    NPOINTS = [4, 9, 16, 25, 36]
    
    on = [130e9, 190e9]
    off = [170e9, 250e9]
    r = [401, 601]

    # Synthesized Beams
    sc = SparkContext(appName="WriteMultiPolyBeams")
    sc.parallelize(NPOINTS).map(lambda x: write(