示例#1
0
def test_healpix_cartesian_rules():
    op = Healpix2CartesianOperator(NSIDE)
    assert_is_type(op.I, Cartesian2HealpixOperator)
    assert_equal(op.I.nside, op.nside)
    assert_is_type(
        Healpix2CartesianOperator(NSIDE)(Cartesian2HealpixOperator(2 * NSIDE)),
        CompositionOperator)
    assert_is_type(
        Healpix2CartesianOperator(NSIDE)(Cartesian2HealpixOperator(NSIDE)),
        IdentityOperator)
示例#2
0
 def healpix(self, nside):
     time = self.date_obs + TimeDelta(self.time, format='sec')
     c2h = Cartesian2HealpixOperator(nside)
     e2g = CartesianEquatorial2GalacticOperator()
     h2e = CartesianHorizontal2EquatorialOperator('NE', time, self.latitude,
                                                  self.longitude)
     rotation = c2h(e2g(h2e))
     return rotation(self.cartesian)
示例#3
0
def test_cartesian_healpix_error():
    op = Cartesian2HealpixOperator(NSIDE)

    def func(i, o):
        if i.shape == (3, ) and o.shape == ():
            op(i, o)
            return
        assert_raises(ValueError, op.__call__, i, o)

    for i, o in itertools.product((np.ones(()), np.ones(2), np.ones(3)),
                                  (np.empty(()), np.empty(2), np.empty(3))):
        yield func, i, o
示例#4
0
    def _get_projection_operator(rotation,
                                 scene,
                                 nu,
                                 position,
                                 synthbeam,
                                 horn,
                                 primary_beam,
                                 verbose=True):
        ndetectors = position.shape[0]
        ntimes = rotation.data.shape[0]
        nside = scene.nside

        thetas, phis, vals = QubicInstrument._peak_angles(
            scene, nu, position, synthbeam, horn, primary_beam)
        ncolmax = thetas.shape[-1]
        thetaphi = _pack_vector(thetas, phis)  # (ndetectors, ncolmax, 2)
        direction = Spherical2CartesianOperator('zenith,azimuth')(thetaphi)
        e_nf = direction[:, None, :, :]
        if nside > 8192:
            dtype_index = np.dtype(np.int64)
        else:
            dtype_index = np.dtype(np.int32)

        cls = {
            'I': FSRMatrix,
            'QU': FSRRotation2dMatrix,
            'IQU': FSRRotation3dMatrix
        }[scene.kind]
        ndims = len(scene.kind)
        nscene = len(scene)
        nscenetot = product(scene.shape[:scene.ndim])
        s = cls((ndetectors * ntimes * ndims, nscene * ndims),
                ncolmax=ncolmax,
                dtype=synthbeam.dtype,
                dtype_index=dtype_index,
                verbose=verbose)

        index = s.data.index.reshape((ndetectors, ntimes, ncolmax))
        c2h = Cartesian2HealpixOperator(nside)
        if nscene != nscenetot:
            table = np.full(nscenetot, -1, dtype_index)
            table[scene.index] = np.arange(len(scene), dtype=dtype_index)

        def func_thread(i):
            # e_nf[i] shape: (1, ncolmax, 3)
            # e_ni shape: (ntimes, ncolmax, 3)
            e_ni = rotation.T(e_nf[i].swapaxes(0, 1)).swapaxes(0, 1)
            if nscene != nscenetot:
                np.take(table, c2h(e_ni).astype(int), out=index[i])
            else:
                index[i] = c2h(e_ni)

        with pool_threading() as pool:
            pool.map(func_thread, xrange(ndetectors))

        if scene.kind == 'I':
            value = s.data.value.reshape(ndetectors, ntimes, ncolmax)
            value[...] = vals[:, None, :]
            shapeout = (ndetectors, ntimes)
        else:
            if str(dtype_index) not in ('int32', 'int64') or \
               str(synthbeam.dtype) not in ('float32', 'float64'):
                raise TypeError(
                    'The projection matrix cannot be created with types: {0} a'
                    'nd {1}.'.format(dtype_index, synthbeam.dtype))
            func = 'matrix_rot{0}d_i{1}_r{2}'.format(ndims,
                                                     dtype_index.itemsize,
                                                     synthbeam.dtype.itemsize)
            getattr(flib.polarization, func)(rotation.data.T, direction.T,
                                             s.data.ravel().view(np.int8),
                                             vals.T)

            if scene.kind == 'QU':
                shapeout = (ndetectors, ntimes, 2)
            else:
                shapeout = (ndetectors, ntimes, 3)
        return ProjectionOperator(s, shapeout=shapeout)
示例#5
0
 def func(n, v, s):
     h2c = Healpix2CartesianOperator(NSIDE, nest=n)
     c2h = Cartesian2HealpixOperator(NSIDE, nest=n)
     a = c2h(h2c(v))
     assert_equal(a.shape, s)
     assert_equal(a, v)
示例#6
0
 def func(n, v, s):
     c2h = Cartesian2HealpixOperator(NSIDE, nest=n)
     h2c = Healpix2CartesianOperator(NSIDE, nest=n)
     a = h2c(c2h(v))
     assert_equal(a.shape, s + (3, ))
     assert_allclose(a, v, atol=1e-1)