Exemple #1
0
 def func(nwrite, nread):
     with tempfile.TemporaryFile('a+b') as tmpfile:
         write_map(tmpfile, np.arange(12*16), nest=nwrite)
         tmpfile.seek(0)
         actual = read_map(tmpfile, nest=nread)
     with tempfile.NamedTemporaryFile('a+b') as tmpfile:
         hp.write_map(tmpfile.name, np.arange(12*16), nest=nwrite)
         expected = hp.read_map(tmpfile.name, nest=nread)
     assert_equal(expected, actual)
Exemple #2
0
 def func(nwrite, nread):
     with tempfile.TemporaryFile('a+b') as tmpfile:
         write_map(tmpfile, np.arange(12 * 16), nest=nwrite)
         tmpfile.seek(0)
         actual = read_map(tmpfile, nest=nread)
     with tempfile.NamedTemporaryFile('a+b') as tmpfile:
         hp.write_map(tmpfile.name, np.arange(12 * 16), nest=nwrite)
         expected = hp.read_map(tmpfile.name, nest=nread)
     assert_equal(expected, actual)
Exemple #3
0
def test_read_header():
    with tempfile.TemporaryFile('a+b') as tmpfile:
        write_map(tmpfile, np.arange(12), coord='E')
        tmpfile.seek(0)
        actual = read_map(tmpfile)
    header = actual.header
    assert_equal(header['coordsys'], 'E')
    assert_equal(header['nmaps'], 1)
    assert not header['hasmask']
Exemple #4
0
def test_read_header():
    with tempfile.TemporaryFile('a+b') as tmpfile:
        write_map(tmpfile, np.arange(12), coord='E')
        tmpfile.seek(0)
        actual = read_map(tmpfile)
    header = actual.header
    assert_equal(header['coordsys'], 'E')
    assert_equal(header['nmaps'], 1)
    assert not header['hasmask']
def write_mono(beam, nside, nu, idet, theta_max, syb_f=None):
    path = '/home/fincardona/Qubic/Compare_poly/maps/poly'
    if syb_f is None: 
        return write_map(
            '%s/interfero/sb_nside{}_mono_{}Ghz_idet{}_tmax{}.fits'.
            format(nside, int(nu/1e9), idet, theta_max) % path, beam)
    else: 
        return write_map(
            '%s/direct_conv/dc_nside{}_mono_{}Ghz_idet{}_tmax{}_sybf{}.fits'.
            format(nside, int(nu/1e9), idet, theta_max, syb_f) % path, beam)
def write_mono(beam, nside, nu, idet, theta_max, syb_f=None):
    path = '/home/fincardona/Qubic/Compare_poly/maps/poly'
    if syb_f is None:
        return write_map(
            '%s/interfero/sb_nside{}_mono_{}Ghz_idet{}_tmax{}.fits'.format(
                nside, int(nu / 1e9), idet, theta_max) % path, beam)
    else:
        return write_map(
            '%s/direct_conv/dc_nside{}_mono_{}Ghz_idet{}_tmax{}_sybf{}.fits'.
            format(nside, int(nu / 1e9), idet, theta_max, syb_f) % path, beam)
Exemple #7
0
def write_poly(g, n, beam, nside, idet, theta_max, syb_f=None, NPOINTS=1):
    path = '/home/fincardona/Qubic/spatial_extension/maps/poly'
    if syb_f is None:
        return write_map(
            '%s/interfero/sb_nside{}_poly{}_{}Ghz_idet{}_tmax{}_Npoints{}.fits'.format(nside, int(n), int(np.mean(g)/1e9), idet, theta_max,
            NPOINTS) % path, beam)
    else: 
        return write_map(
            '%s/direct_conv/dc_nside{}_poly{}_{}Ghz_idet{}_tmax{}_sybf{}_Npoints{}.fits'.format(nside, int(n), int(np.mean(g)/1e9), idet, 
            theta_max, syb_f, NPOINTS) % path, beam)
def non_linear_integral(g, n, nside, T):
    f_norm = quadratic_grid(g[0], g[len(g)-1], n)
    weights = non_linear_weights(f_norm)
    bar = progress_bar(n)
    sb = np.zeros(12*nside**2)
    for i, f in enumerate(f_norm):
        sb_ = interpolation(g, f, nside)
        sb += sb_*deriv(f, nside, T)*weights[i]
        bar.update()
    write_map('sb_nside{}_poly{}_{}Ghz.fits'.format(
        nside, int(n), int(np.mean(grid)/1e9)), sb)
def linear_integral(g, nside, T):
    # Integral on a linear grid
    weights = linear_weights(g)
    sb = np.zeros(12*nside**2)
    bar = progress_bar(len(g))
    for i, nu in enumerate(g):
        sb_ = read_map('sb_nside{}_nu{:.3e}.fits'.format(nside, nu))
        sb += sb_*deriv(nu, nside, T)*weights[i]
        bar.update()
    write_map('sb_nside{}_poly{}_{}Ghz.fits'.format(
        nside, len(g), int(np.mean(grid)/1e9)), sb)
Exemple #10
0
 def func(dtype, field, map, msk):
     with tempfile.TemporaryFile('a+b') as tmpfile:
         write_map(tmpfile, map.astype(dtype), msk, dtype=None)
         tmpfile.seek(0)
         actual = read_map(tmpfile, field=field, dtype=None)
     assert actual.dtype == dtype
     if np.isscalar(field):
         assert_equal(actual, complete[..., field].astype(dtype))
     elif len(field) == 1:
         assert_equal(actual, complete[..., field[0]].astype(dtype))
     else:
         for i, f in enumerate(field):
             assert_equal(actual[..., i], complete[..., f].astype(dtype))
Exemple #11
0
 def func(dtype, field, map, msk):
     with tempfile.TemporaryFile('a+b') as tmpfile:
         write_map(tmpfile, map.astype(dtype), msk, dtype=None)
         tmpfile.seek(0)
         actual = read_map(tmpfile, field=field, dtype=None)
     assert actual.dtype == dtype
     if np.isscalar(field):
         assert_equal(actual, complete[..., field].astype(dtype))
     elif len(field) == 1:
         assert_equal(actual, complete[..., field[0]].astype(dtype))
     else:
         for i, f in enumerate(field):
             assert_equal(actual[..., i], complete[..., f].astype(dtype))
Exemple #12
0
 def func(map, msk, partial, compress):
     with tempfile.TemporaryFile('a+b') as tmpfile:
         write_map(tmpfile, map, msk, compress=compress)
         tmpfile.seek(0)
         actual = read_map(tmpfile, partial=partial)
     if partial:
         out, mask_ = actual
         if msk is None:
             assert_is_none(mask_)
             actual = out
         else:
             actual = np.full(mask_.shape, np.nan)
             actual[mask_] = out
     assert_equal(actual.dtype.byteorder, '=')
     assert_same(actual, complete)
Exemple #13
0
 def func(map, msk, partial, compress):
     with tempfile.TemporaryFile('a+b') as tmpfile:
         write_map(tmpfile, map, msk, compress=compress)
         tmpfile.seek(0)
         actual = read_map(tmpfile, partial=partial)
     if partial:
         out, mask_ = actual
         if msk is None:
             assert_is_none(mask_)
             actual = out
         else:
             actual = np.full(mask_.shape, np.nan)
             actual[mask_] = out
     assert_equal(actual.dtype.byteorder, '=')
     assert_same(actual, complete)
Exemple #14
0
def write(on, off, r, nside, idet, theta_max=45, syb_f=None, NPOINTS=1):
    path = '/home/fincardona/Qubic/spatial_extension/maps/mono'
    scene = SceneHealpixCMB(nside, kind='I')
    grid = np.concatenate([np.linspace(cut_on, cut_off, res) 
                           for cut_on, cut_off, res in zip(on, off, r)])
    for nu in grid:
        q = MyQubicInstrument(
            filter_nu=nu, filter_relative_bandwidth=1/nu, 
            synthbeam_dtype=float, synthbeam_fraction=syb_f)
        sb = q.get_synthbeam(scene, idet, theta_max, NPOINTS=NPOINTS)
        sb_direct_ga = q.direct_convolution(
            scene, idet, theta_max, NPOINTS=NPOINTS)
        write_map(
            '%s/interfero/sb_nside{}_nu{:.3e}_idet{}_tmax{}_Npoints{}.fits'.
            format(nside, nu, idet, theta_max, NPOINTS) % path, 
            np.sum(sb, axis=0))
        write_map(
            '%s/direct_conv/dc_nside{}_nu{:.3e}_idet{}_tmax{}_sybf{}_Npoints{}.fits'.format(nside, nu, idet, theta_max, syb_f, 
            NPOINTS) % path, np.sum(sb_direct_ga, axis=0))
Exemple #15
0
def write(on, off, r, nside, idet, theta_max=45, syb_f=None):
    path = '/home/fincardona/Qubic/Compare_poly/maps/mono'
    scene = SceneHealpixCMB(nside, kind='I')
    grid = np.concatenate([
        np.linspace(cut_on, cut_off, res)
        for cut_on, cut_off, res in zip(on, off, r)
    ])
    sb = np.empty(12 * nside**2)
    for nu in grid:
        q = MyQubicInstrument(filter_nu=nu,
                              filter_relative_bandwidth=1 / nu,
                              synthbeam_dtype=float,
                              synthbeam_fraction=syb_f)
        sb = q.get_synthbeam(scene, idet, theta_max)
        sb_direct_ga = q.direct_convolution(scene, idet, theta_max)
        write_map(
            '%s/interfero/sb_nside{}_nu{:.3e}_idet{}_tmax{}.fits'.format(
                nside, nu, idet, theta_max) % path, sb)
        write_map(
            '%s/direct_conv/dc_nside{}_nu{:.3e}_idet{}_tmax{}_sybf{}.fits'.
            format(nside, nu, idet, theta_max, syb_f) % path, sb_direct_ga)
N = [512,  1024, 2048]
T_cmb = 2.7255          # Kelvin

nu_cent = 150e9
cut_on = 130e9          # Ideal Filter 150 GHz - 25% bandwidht
cut_off = 170e9         
res = 401

#nu_cent = 220e9
#cut_on = 190e9         # Ideal Filter 220 GHz - 25% bandwidht
#cut_off = 250e9        
#res = 601

grid = np.linspace(cut_on, cut_off, res)
sample = np.unique(np.round(np.logspace(0, np.log10(res))))

for nside in N:
    bar = progress_bar(len(sample))
    for n in sample:
        if n == 1:
            sb = read_map('sb_nside{}_nu{:.3e}.fits'.format(nside, nu_cent))
            sb *= deriv(nu_cent, nside, T_cmb)*(cut_off - cut_on)
            write_map('sb_nside{}_mono_{}Ghz.fits'.format(nside, int(nu_cent/1e9)), 
                      sb)
        elif n == res:
            linear_integral(grid, nside, T_cmb)
        else:
            non_linear_integral(grid, n, nside, T_cmb)
            bar.update()
                                 kind='IQU',
                                 nside=nside,
                                 detector_nep=detector_nep,
                                 detector_fknee=fknee
                                )
    ndet = 992 if not debug_mode else 2
    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