Exemple #1
0
def test_any_neq2():
    NaN = np.nan
    assert all_eq(NaN, NaN)
    assert all_eq([NaN], [NaN])
    assert all_eq([NaN,1], [NaN,1])
    assert any_neq([NaN,1,NaN], [NaN,1,3])
    assert all_eq(minmax([NaN, 1., 4., NaN, 10.]), [1., 10.])
Exemple #2
0
def test_pTx_pT1():
    obs1 = PacsObservation(data_dir + 'frames_blue.fits')
    obs2 = PacsObservation([data_dir + 'frames_blue.fits[1:41]',
                            data_dir + 'frames_blue.fits[42:43]',
                            data_dir + 'frames_blue.fits[44:360]'])
    obs1.pointing.chop = 0
    obs2.pointing.chop = 0
    header = obs1.get_map_header()

    tod = obs1.get_tod()

    model1 = obs1.get_projection_operator(downsampling=True, header=header)
    ref = mapper_naive(tod, model1, unit='Jy/arcsec^2')

    model1.apply_mask(tod.mask)
    tod.inunit('Jy/arcsec^2')
    b1, w1 = model1.get_pTx_pT1(tod)
    m1 = b1 / w1
    assert all_eq(ref, m1, tol)

    model2 = obs2.get_projection_operator(downsampling=True, header=header)
    model2.apply_mask(tod.mask)
    
    b2, w2 = model2.get_pTx_pT1(tod)
    m2 = b2 / w2
    assert all_eq(ref, m2, tol)

    model3 = obs2.get_projection_operator(downsampling=True, header=header,
                                          storage='on fly')
    MaskOperator(tod.mask)(tod, tod)
    b3, w3 = model3.get_pTx_pT1(tod)
    m3 = b3 / w3
    assert all_eq(ref, m3, tol)
Exemple #3
0
def test_any_neq2():
    NaN = np.nan
    assert all_eq(NaN, NaN)
    assert all_eq([NaN], [NaN])
    assert all_eq([NaN, 1], [NaN, 1])
    assert any_neq([NaN, 1, NaN], [NaN, 1, 3])
    assert all_eq(minmax([NaN, 1., 4., NaN, 10.]), [1., 10.])
Exemple #4
0
def test_detector_policy():
    map_naive_ref = Map(data_dir + '../../../core/test/data/frames_blue_map_naive.fits')
    obs = PacsObservation(data_dir + 'frames_blue.fits', reject_bad_line=False)
    obs.pointing.chop[:] = 0
    projection = obs.get_projection_operator(header=map_naive_ref.header,
                                             downsampling=True,
                                             npixels_per_sample=6)
    tod = obs.get_tod()
    masking = MaskOperator(tod.mask)
    model = masking * projection
    map_naive = mapper_naive(tod, model)
    assert all_eq(map_naive, map_naive_ref, tol)

    obs_rem = PacsObservation(data_dir + 'frames_blue.fits',
                              policy_bad_detector='remove',
                              reject_bad_line=False)
    obs_rem.pointing.chop[:] = 0
    projection_rem = obs_rem.get_projection_operator(header=map_naive.header,
                                                     downsampling=True,
                                                     npixels_per_sample=7)
    tod_rem = obs_rem.get_tod()
    masking_rem = MaskOperator(tod_rem.mask)
    model_rem = masking_rem * projection_rem
    map_naive_rem = mapper_naive(tod_rem, model_rem)
    assert all_eq(map_naive, map_naive_rem, tol)
Exemple #5
0
def test_any_neq3():
    for dtype in dtypes:
        arr = np.ones((2, 3), dtype=dtype)
        a = A(arr, info1='1', info2=True)
        b1 = A(arr, info1='1', info2=True)
        b1[0, 1] = 0
        b2 = A(arr, info1='2', info2=True)
        b3 = A(arr, info1='1', info2=False)

        def func1(a, b):
            assert any_neq(a, b)

        for b in (b1, b2, b3):
            yield func1, a, b
        b = a.copy()
        assert all_eq(a, b)
        a.info3 = b
        b1 = a.copy()
        b1.info3[0, 1] = 0
        b2 = a.copy()
        b2.info3.info1 = '2'
        b3 = a.copy()
        b3.info3.info2 = False

        def func2(a, b):
            assert any_neq(a, b)

        for b in (b1, b2, b3):
            yield func2, a, b
        b = a.copy()
        assert all_eq(a, b)
Exemple #6
0
def test():
    assert map_rls.header['NITER'] < 49
    ref = Map(data_dir + 'frames_blue_map_rls_cgs_tol1e-6.fits')
    ref.derived_units = map_rls.derived_units
    cov = ref.coverage > 80
    assert all_eq(ref[cov], map_rls[cov], 1.e-1)
    cov = ref.coverage > 125
    assert all_eq(ref[cov], map_rls[cov], 1.e-2)
Exemple #7
0
def test():
    assert map_rls.header['NITER'] < 49
    ref = Map(data_dir + 'frames_blue_map_rls_cgs_tol1e-6.fits')
    ref.derived_units = map_rls.derived_units
    cov = ref.coverage > 80
    assert all_eq(ref[cov], map_rls[cov], 1.e-1)
    cov = ref.coverage > 125
    assert all_eq(ref[cov], map_rls[cov], 1.e-2)
Exemple #8
0
def test_any_neq1():
    assert all_eq(1, 1 + 1.e-15)
    assert all_eq([1], [1 + 1.e-15])
    assert any_neq(1, 1 + 1.e-13)
    assert any_neq([1], [1 + 1.e-13])
    assert all_eq(1, np.asarray(1 + 1.e-8, dtype='float32'))
    assert all_eq([1], [np.asarray(1 + 1.e-8, dtype='float32')])
    assert any_neq(1, np.asarray(1 + 1.e-6, dtype='float32'))
    assert any_neq([1], [np.asarray(1 + 1.e-6, dtype='float32')])
Exemple #9
0
def test_any_neq1():
    assert all_eq(1, 1+1.e-15)
    assert all_eq([1], [1+1.e-15])
    assert any_neq(1, 1+1.e-13)
    assert any_neq([1], [1+1.e-13])
    assert all_eq(1, np.asarray(1+1.e-8, dtype='float32'))
    assert all_eq([1], [np.asarray(1+1.e-8, dtype='float32')])
    assert any_neq(1, np.asarray(1+1.e-6, dtype='float32'))
    assert any_neq([1], [np.asarray(1+1.e-6, dtype='float32')])
def test_invntt_uncorrelated():
    filter = np.array([0., 0.2, 0.3, 0.4, 0.4, 0.3, 0.2, 0]).reshape((1,-1))
    ncorrelations = 2
    invntt = InvNttUncorrelatedOperator(filter, ncorrelations, 3)
    invntt_todense = invntt.todense()
    assert all_eq(invntt_todense, invntt.todense(inplace=True))
    invntt2 = InvNttUncorrelatedPythonOperator(filter, ncorrelations, 3)
    invntt2_todense = invntt2.todense()
    assert all_eq(invntt2_todense, invntt2.todense(inplace=True))
    assert all_eq(invntt_todense, invntt2_todense)
Exemple #11
0
def test_pack():
    for channel, nrows, ncolumns in ('red',16,32), ('blue',32,64):
        obs = PacsSimulation(Pointing((0., 0., 0.), 0.), channel)
        for dt in (np.uint8, np.uint16, np.uint32, np.uint64):
            a = np.arange(nrows*ncolumns*3, dtype=dt) \
                  .reshape((nrows,ncolumns,-1))
            p = obs.pack(a)
            assert all_eq(a[1,0:16,:], p[16:32,:])
            u = obs.unpack(p)
            assert all_eq(a, u)
Exemple #12
0
def test_npixels_per_sample_is_zero():
    obs = PacsObservation(data_dir + 'frames_blue.fits')
    header = obs.get_map_header()
    header['crval1'] += 1
    proj2 = obs.get_projection_operator(header=header)
    assert proj2.matrix.shape[-1] == 0
    t = proj2(np.ones((header['NAXIS2'],header['NAXIS1'])))
    assert all_eq(minmax(t), [0,0])
    t[:] = 1
    assert all_eq(minmax(proj2.T(t)), [0,0])
Exemple #13
0
def test_slice1():
    obs = PacsObservation(data_dir+'frames_blue.fits[11:20]')
    tod = obs.get_tod()

    filename = 'obs-' + uuid + '.fits'
    obs.save(filename, tod)
    obs2 = PacsObservation(filename)
    tod2 = obs2.get_tod()
    assert all_eq(obs.status[10:20], obs2.status)
    assert all_eq(tod, tod2)
Exemple #14
0
def test_header():
    obs = PacsObservation(data_dir+'frames_blue.fits', reject_bad_line=False)
    obs.pointing.chop = 0
    header = obs.get_map_header()
    projection = obs.get_projection_operator(header=header, downsampling=True,
                                             npixels_per_sample=6)
    tod = obs.get_tod()

    map_naive = mapper_naive(tod, projection)

    header2 = header.copy()
    header2['NAXIS1'] += 500
    header2['CRPIX1'] += 250
    projection2 = obs.get_projection_operator(header=header2, downsampling=True)
    map_naive2 = mapper_naive(tod, MaskOperator(tod.mask) * projection2)
    map_naive2.inunit('Jy/arcsec^2')
    map_naive3 = map_naive2[:,250:header['NAXIS1']+250]
    assert all_eq(map_naive.tounit('Jy/arcsec^2'), map_naive3, 2.e-7)

    # test compatibility with photproject
    tod = obs.get_tod()
    map_naive4 = mapper_naive(tod, projection)
    hdu_ref = pyfits.open(data_dir + 'frames_blue_map_hcss_photproject.fits')[1]
    map_ref = Map(hdu_ref.data, hdu_ref.header, unit=hdu_ref.header['qtty____']+'/pixel')
    std_naive = np.std(map_naive4[40:60,40:60])
    std_ref = np.std(map_ref[40:60,40:60])
    assert abs(std_naive-std_ref) / std_ref < 0.025
Exemple #15
0
def test_save():
    obs = PacsObservation(data_dir+'frames_blue.fits', reject_bad_line=False)
    obs.pointing.ra += 0.1
    obs.pointing.dec -= 0.1
    obs.pointing.pa += 20
    obs.pointing.chop = 0
    tod = obs.get_tod()

    filename = 'obs-' + uuid + '.fits'
    obs.save(filename, tod)

    obs2 = PacsObservation(filename, reject_bad_line=False)
    tod2 = obs2.get_tod()

    assert all_eq(obs.pointing, obs2.pointing)

    obs.status.RaArray = obs.pointing.ra
    obs.status.DecArray = obs.pointing.dec
    obs.status.PaArray = obs.pointing.pa
    obs.status.CHOPFPUANGLE = obs.pointing.chop
    assert all_eq(obs.status, obs2.status)
    assert all_eq(tod, tod2)
Exemple #16
0
def test_slice2():
    obs1 = PacsObservation(data_dir + 'frames_blue.fits')
    obs2 = PacsObservation([data_dir + 'frames_blue.fits[1:41]',
                            data_dir + 'frames_blue.fits[42:43]',
                            data_dir + 'frames_blue.fits[44:360]'])
    assert all_eq(obs1.pointing, obs2.pointing[~obs2.pointing.removed])
    obs1.pointing.chop = 0
    obs2.pointing.chop = 0

    tod1 = obs1.get_tod()
    tod2 = obs2.get_tod()
    assert all_eq(tod1, tod2)

    header = obs1.get_map_header()

    proj1 = obs1.get_projection_operator(header=header)
    proj2 = obs2.get_projection_operator(header=header)
    proj3 = obs2.get_projection_operator(header=header, storage='on fly')
    assert all_eq(proj1.get_mask(), proj2.get_mask())
    assert all_eq(proj1.get_mask(), proj3.get_mask())
    assert all_eq(proj1.matrix, np.concatenate([p.matrix for p in \
                  proj2.operands], axis=1))
    assert all_eq(proj1.matrix, np.concatenate([p.matrix for p in \
                  proj3.operands], axis=1))

    model1 = CompressionAverageOperator(obs1.slice.compression_factor) * proj1
    model2 = CompressionAverageOperator(obs2.slice.compression_factor) * proj2
    model3 = CompressionAverageOperator(obs2.slice.compression_factor) * proj3
    
    m1 = model1.T(tod1)
    m2 = model2.T(tod2)
    m3 = model3.T(tod2)
    assert all_eq(m1, m2, tol)
    assert all_eq(m1, m3, tol)
    assert all_eq(model1(m1), model2(m1))
    assert all_eq(model1(m1), model3(m1))
Exemple #17
0
def test_any_neq3():
    for dtype in dtypes:
        arr = np.ones((2,3), dtype=dtype)
        a = A(arr, info1='1', info2=True)
        b1 = A(arr, info1='1', info2=True)
        b1[0,1] = 0
        b2 = A(arr, info1='2', info2=True)
        b3 = A(arr, info1='1', info2=False)
        def func1(a, b):
            assert any_neq(a, b)
        for b in (b1, b2, b3):
            yield func1, a, b
        b = a.copy()
        assert all_eq(a,b)
        a.info3 = b
        b1 = a.copy(); b1.info3[0,1] = 0
        b2 = a.copy(); b2.info3.info1 = '2'
        b3 = a.copy(); b3.info3.info2 = False
        def func2(a, b):
            assert any_neq(a, b)
        for b in (b1, b2, b3):
            yield func2, a, b
        b = a.copy()
        assert all_eq(a,b)
def test_packing():

    p = PackOperator([False, True, True, False])
    assert all_eq(p([1,2,3,4]), [1,4])
    assert all_eq(p.T([1,4]), [1,0,0,4])

    u = UnpackOperator([False, True, True, False])
    assert all_eq(u([1,4]), [1,0,0,4])
    assert all_eq(u.T([1,2,3,4]), [1,4])

    pdense = p.todense()
    udense = u.todense()
    assert all_eq(pdense, p.todense(inplace=True))
    assert all_eq(udense, u.todense(inplace=True))
    assert all_eq(pdense, udense.T)

    assert_is_instance(p*u, IdentityOperator)
    assert_is_instance(u*p, MaskOperator)
    m = u * p
    assert all_eq(np.dot(udense, pdense), m.todense())
Exemple #19
0
def test_madcap2():
    assert all_eq(map_naive_2d, map_ref)
Exemple #20
0
def test_madcap2():
    assert all_eq(map_naive_2d, map_ref)
Exemple #21
0
 def func(x, m, a):
     assert all_eq(median(x, mask=m, axis=a), _median(x, m, a))
Exemple #22
0
def test_madcap1():
    assert all_eq(map_naive, map_ref)
Exemple #23
0
 def func(x, m, a):
     assert all_eq(median(x, mask=m, axis=a), _median(x, m, a))
Exemple #24
0
def test_madcap1():
    assert all_eq(map_naive, map_ref)