Beispiel #1
0
def test_zero1():
    z = ZeroOperator()
    o = Operator(shapein=3, shapeout=6)
    zo = z(o)
    assert_is_instance(zo, ZeroOperator)
    assert_equal(zo.shapein, o.shapein)
    assert_is_none(zo.shapeout)
Beispiel #2
0
def test_zero2():
    z = ZeroOperator(shapein=3, shapeout=6)
    o = Operator()
    zo = z(o)
    assert_is_instance(zo, ZeroOperator)
    assert_is_none(zo.shapein, 'in')
    assert_equal(zo.shapeout, z.shapeout, 'out')
 def f(cls, func, axis, m):
     keywords_array = {'unit': 'u'}
     if cls is Tod:
         keywords_array['mask'] = m
     array = cls(data, **keywords_array)
     keywords_func = {'axis': axis} if func is not np.round else {}
     result = func(array, **keywords_func)
     if cls is Tod:
         ref = func(np.ma.MaskedArray(array.magnitude, mask=m),
                    **keywords_func)
         if not isinstance(ref, np.ndarray):
             ref = np.ma.MaskedArray(ref)
     else:
         ref = func(array.magnitude, **keywords_func)
     assert_equal(result.view(np.ndarray), ref)
     if np.isscalar(result):
         return
     if func is np.var:
         assert result._unit == {'u': 2}
     else:
         assert result._unit == {'u': 1}
     if cls is Map:
         assert_is_none(result.coverage)
         assert_is_none(result.error)
     elif cls is Tod:
         if result.mask is None:
             assert not ref.mask
         else:
             assert_eq(result.mask, ref.mask)
Beispiel #4
0
 def f(cls, func, axis, m):
     keywords_array = {'unit': 'u'}
     if cls is Tod:
         keywords_array['mask'] = m
     array = cls(data, **keywords_array)
     keywords_func = {'axis': axis} if func is not np.round else {}
     result = func(array, **keywords_func)
     if cls is Tod:
         ref = func(np.ma.MaskedArray(array.magnitude, mask=m),
                    **keywords_func)
         if not isinstance(ref, np.ndarray):
             ref = np.ma.MaskedArray(ref)
     else:
         ref = func(array.magnitude, **keywords_func)
     assert_equal(result.view(np.ndarray), ref)
     if np.isscalar(result):
         return
     if func is np.var:
         assert result._unit == {'u': 2}
     else:
         assert result._unit == {'u': 1}
     if cls is Map:
         assert_is_none(result.coverage)
         assert_is_none(result.error)
     elif cls is Tod:
         if result.mask is None:
             assert not ref.mask
         else:
             assert_eq(result.mask, ref.mask)
 def func(s, v):
     layout = PackedTable((6, 6), key=v)
     assert 'key' in layout._special_attributes
     assert_equal(layout.key, v)
     assert_equal(layout.all.key, v)
     s(layout, 'key', None)
     assert_is_none(layout.key)
     assert_is_none(layout.all.key)
 def func1(fmt, ra):
     args, keywords = fmt(ra)
     if len(args) > 0 and isscalarlike(args[0]):
         p = SamplingEquatorial(*args, **keywords)
         assert_is_none(p.ra)
         assert_is_none(p.dec)
         assert_equal(p.pa, 0)
         return
     assert_raises(ValueError, SamplingEquatorial, *args, **keywords)
Beispiel #7
0
def test_zero5():
    z = ZeroOperator()
    o = Operator(shapein=3, shapeout=6, flags='linear')
    zo = z*o
    oz = o*z
    assert_is_instance(zo, ZeroOperator, 'zo')
    assert_equal(zo.shapein, o.shapein, 'zo in')
    assert_is_none(zo.shapeout, 'zo out')
    assert_is_instance(oz, ZeroOperator, 'oz')
    assert_is_none(oz.shapein, 'oz, in')
    assert_equal(oz.shapeout, o.shapeout, 'oz, out')
Beispiel #8
0
 def func(h, partial):
     with tempfile.NamedTemporaryFile('a+b') as tmpfile:
         hp.write_map(tmpfile.name, (np.arange(12), np.arange(12) + 1),
                      coord='E')
         actual = read_map(tmpfile.name, partial=partial)
         expected = hp.read_map(tmpfile.name, h=h, field=(0, 1))
     if partial:
         assert_is_none(actual[1])
         actual = actual[0]
     if h:
         assert actual.header == expected[-1]
         assert_equal(actual, np.column_stack(expected[:-1]))
     else:
         assert_equal(actual, np.column_stack(expected))
Beispiel #9
0
 def func(broadcast, values):
     if broadcast == 'rightward':
         expected = (values.T*(diag.T+1)*3).T
     else:
         expected = values*(diag+1)*3
     op = DiagonalNumexprOperator(diag, expr, broadcast=broadcast)
     if broadcast in ('leftward', 'rightward'):
         assert op.broadcast == broadcast
         assert_is_none(op.shapein)
     else:
         assert op.broadcast == 'disabled'
         assert_eq(op.shapein, diag.shape)
         assert_eq(op.shapeout, diag.shape)
     assert_inplace_outplace(op, values, expected)
Beispiel #10
0
 def func(broadcast, values):
     if broadcast == 'rightward':
         expected = (values.T * (diag.T + 1) * 3).T
     else:
         expected = values * (diag + 1) * 3
     op = DiagonalNumexprOperator(diag, expr, broadcast=broadcast)
     if broadcast in ('leftward', 'rightward'):
         assert op.broadcast == broadcast
         assert_is_none(op.shapein)
     else:
         assert op.broadcast == 'disabled'
         assert_eq(op.shapein, diag.shape)
         assert_eq(op.shapeout, diag.shape)
     assert_inplace_outplace(op, values, expected)
Beispiel #11
0
 def func(h, partial):
     with tempfile.NamedTemporaryFile('a+b') as tmpfile:
         hp.write_map(tmpfile.name, (np.arange(12), np.arange(12) + 1),
                      coord='E')
         actual = read_map(tmpfile.name, partial=partial)
         expected = hp.read_map(tmpfile.name, h=h, field=(0, 1))
     if partial:
         assert_is_none(actual[1])
         actual = actual[0]
     if h:
         assert actual.header == expected[-1]
         assert_equal(actual, np.column_stack(expected[:-1]))
     else:
         assert_equal(actual, np.column_stack(expected))
Beispiel #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)
Beispiel #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)
Beispiel #14
0
 def func(c, s, b, sameshapein, sameshapeout):
     x = np.arange(product(s)).reshape(s)
     op = get_operator(c, x, broadcast=b)
     if len(s) == 0 or c in (HomothetyOperator, IdentityOperator,
                             ZeroOperator):
         assert_equal(op.broadcast, 'scalar')
         assert_is_none(op.shapein)
         assert_is_none(op.shapeout)
     elif b in ('leftward', 'rightward'):
         assert_equal(op.broadcast, b)
         assert_is_none(op.shapein)
         assert_is_none(op.shapeout)
     else:
         assert_equal(op.broadcast, 'disabled')
         if sameshapein:
             assert_equal(op.shapein, s)
         if sameshapeout:
             assert_equal(op.shapeout, s)
def test_pack_none():
    layout = PackedTable((3, 3))
    assert_is_none(layout.pack(None))
    assert_is_none(layout.unpack(None))