def test_shift4(): a = np.array([[0.,0,0],[0,1,0],[0,0,0]]) b = np.empty_like(a) shift(a, b, 1, axis=1) assert_all_eq(b, np.roll(a,1,axis=1)) shift(b, b, -2, axis=1) assert_all_eq(b, np.roll(a,-1,axis=1))
def test_shift4(): a = np.array([[0., 0, 0], [0, 1, 0], [0, 0, 0]]) b = np.empty_like(a) shift(a, b, 1, axis=1) assert_all_eq(b, np.roll(a, 1, axis=1)) shift(b, b, -2, axis=1) assert_all_eq(b, np.roll(a, -1, axis=1))
def test_write(): filename2 = 'test-' + id + '.fits' lmap.save(filename2) ref2 = Map(filename2, comm=MPI.COMM_SELF) lmap2 = Map(filename2, comm=MPI.COMM_WORLD) lmap2.save('test' + str(rank) + 'fits', comm=MPI.COMM_SELF) assert_all_eq(lmap, lmap2) assert_all_eq(ref, ref2)
def test_write(): filename2 = 'test-' + id + '.fits' lmap.save(filename2) ref2 = Map(filename2, comm=MPI.COMM_SELF) lmap2 = Map(filename2, comm=MPI.COMM_WORLD) lmap2.save('test'+str(rank)+'fits', comm=MPI.COMM_SELF) assert_all_eq(lmap, lmap2) assert_all_eq(ref, ref2)
def test_read(): shape_global = ref.shape shape_local = distribute_shape(shape_global) assert_equal(shape_local, lmap.shape) lmaps = MPI.COMM_WORLD.allgather(lmap) gmap = np.concatenate(lmaps, axis=0).magnitude assert_all_eq(ref, gmap)
def func(naxis, axis): shape = [i + 8 for i in range(naxis)] a = np.random.random_integers(1, 10, size=shape).astype(float) ref = -np.diff(a, axis=axis) diff(a, a, axis=axis) s = tuple([slice(0, s) for s in ref.shape]) print s, a.shape, ref.shape a[s] -= ref assert_all_eq(a, 0)
def func(naxis, axis): shape = [i+8 for i in range(naxis)] a=np.random.random_integers(1, 10, size=shape).astype(float) ref = -np.diff(a, axis=axis) diff(a, a, axis=axis) s = tuple([slice(0,s) for s in ref.shape]) print s, a.shape, ref.shape a[s] -= ref assert_all_eq(a, 0)
def test1(): comm_map = MPI.COMM_SELF for obs, tod in ((obs1, tod1), (obs2, tod2)): proj = obs.get_projection_operator(downsampling=True, npixels_per_sample=6, header=map_ref_global.header, commin=comm_map) proj.apply_mask(tod.mask) m = mapper_naive(tod, proj) yield check_map_global, m assert_all_eq(proj.get_mask(), mask_ref_global)
def test1(): comm_map = MPI.COMM_SELF for obs, tod in ((obs1, tod1), (obs2, tod2)): proj = obs.get_projection_operator( downsampling=True, npixels_per_sample=6, header=map_ref_global.header, commin=comm_map ) proj.apply_mask(tod.mask) m = mapper_naive(tod, proj) yield check_map_global, m assert_all_eq(proj.get_mask(), mask_ref_global)
def func(x): y = filter_nonfinite(x) y_expected = np.asanyarray(x).copy() y_expected[~np.isfinite(x)] = 0 if hasattr(x, 'mask') and x.mask is not None: y_expected.mask = x.mask.copy() y_expected.mask[~np.isfinite(x)] = True assert_all_eq(y, y_expected) x = np.asanyarray(x) filter_nonfinite(x, out=x) assert_all_eq(x, y_expected)
def func(a, s): b = np.empty_like(a) shift(b, b, s, axis=-1) assert_all_eq(b, 0)
def check_map_local(m): assert_all_eq(m.magnitude, map_ref_local.magnitude, mtol) assert_all_eq(m.coverage, cov_ref_local, mtol)
from pyoperators.utils.mpi import MPI from pysimulators import FitsArray, Map, Tod from tamasis.utils import assert_all_eq raise SkipTest tamasis.var.verbose = True rank = MPI.COMM_WORLD.Get_rank() size = MPI.COMM_WORLD.Get_size() # test DistributedArray shapes = [ (10,), (5,4), (3,4,2) ] dtypes = (int, float, complex) for shape in shapes: for dtype in dtypes: for order in ('c', 'f'): a = np.random.random_sample(shape).astype(dtype) a = MPI.COMM_WORLD.bcast(a) objs = [ FitsArray(a, dtype=dtype, order=order), Map(a, dtype=dtype, order=order, error=a, coverage=a), Tod(a, dtype=dtype, order=order, mask=a.astype(np.bool)) ] for obj in objs: if isinstance(obj, Tod) and obj.ndim == 1: continue local = obj.tolocal() globa = local.toglobal() assert_all_eq(obj, globa)
def check_map_local(m): assert_all_eq(m.magnitude, map_ref_local.magnitude, 1e-10) assert_all_eq(m.coverage, map_ref_local.coverage, 1e-10) assert_all_eq(m.tounit('Jy/arcsec^2'), map_ref_local.tounit('Jy/arcsec^2'), 1e-10)
def check_map_local(m): assert_all_eq(m.magnitude, map_ref_local.magnitude, 1e-10) assert_all_eq(m.coverage, map_ref_local.coverage, 1e-10) assert_all_eq(m.tounit("Jy/arcsec^2"), map_ref_local.tounit("Jy/arcsec^2"), 1e-10)
def test_shift2(): a = np.array([[1.,1.,1.,1.],[2.,2.,2.,2.]]) shift(a, a, [1,-1], axis=1) assert_all_eq(a, [[0,1,1,1],[2,2,2,0]])
def test_shift2(): a = np.array([[1., 1., 1., 1.], [2., 2., 2., 2.]]) shift(a, a, [1, -1], axis=1) assert_all_eq(a, [[0, 1, 1, 1], [2, 2, 2, 0]])