Skip to content

Commit 78a3492

Browse files
committed
Clean up catalogmesh tests.
1 parent ef10f2d commit 78a3492

1 file changed

Lines changed: 8 additions & 84 deletions

File tree

nbodykit/base/tests/test_catalogmesh.py

Lines changed: 8 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -9,63 +9,11 @@
99
setup_logging("debug")
1010

1111

12-
@MPITest([1, 4])
13-
def test_gslice(comm):
14-
CurrentMPIComm.set(comm)
15-
16-
# the catalog to slice
17-
d = UniformCatalog(1000, 1.0, seed=42)
18-
d = d.to_mesh(Nmesh=32)
19-
20-
sels = [(0,10,1), (None,10,1), (0,50,4), (0,50,-1), (-10,-1,1), (-10,None,1)]
21-
for (start,stop,end) in sels:
22-
23-
sliced = d.gslice(start,stop,end)
24-
25-
for col in d:
26-
data1 = numpy.concatenate(comm.allgather(d[col]), axis=0)
27-
data2 = numpy.concatenate(comm.allgather(sliced[col]), axis=0)
28-
29-
sl = slice(start,stop,end)
30-
assert_array_equal(data1[sl], data2, err_msg="using slice= "+str(sl))
31-
32-
# empty slice
33-
sliced = d.gslice(0,0)
34-
assert len(sliced) == 0
35-
36-
@MPITest([1, 4])
37-
def test_sort_ascending(comm):
38-
CurrentMPIComm.set(comm)
39-
40-
# the mesh to sort
41-
d = UniformCatalog(100, 1.0)
42-
d['mass'] = 10**(d.rng.uniform(low=12, high=15, size=d.size))
43-
mesh = d.to_mesh(Nmesh=32)
44-
45-
# invalid sort key
46-
with pytest.raises(ValueError):
47-
mesh2 = mesh.sort('BadColumn', reverse=False)
48-
49-
# duplicate sort keys
50-
with pytest.raises(ValueError):
51-
mesh2 = mesh.sort(['mass', 'mass'])
52-
53-
# sort in ascending order by mass
54-
mesh2 = mesh.sort('mass', reverse=False)
55-
56-
# make sure we have all the columns
57-
assert all(col in mesh2 for col in mesh)
58-
59-
mass = numpy.concatenate(comm.allgather(mesh['mass']))
60-
sorted_mass = numpy.concatenate(comm.allgather(mesh2['mass']))
61-
assert_array_equal(numpy.sort(mass), sorted_mass)
62-
63-
6412
@MPITest([4])
6513
def test_tsc_interlacing(comm):
6614

6715
CurrentMPIComm.set(comm)
68-
source = UniformCatalog(nbar=3e-2, BoxSize=512., seed=42)
16+
source = UniformCatalog(nbar=3e-4, BoxSize=512., seed=42)
6917

7018
# interlacing with TSC
7119
mesh = source.to_mesh(window='tsc', Nmesh=64, interlaced=True, compensated=True)
@@ -78,7 +26,7 @@ def test_tsc_interlacing(comm):
7826
def test_paint_chunksize(comm):
7927

8028
CurrentMPIComm.set(comm)
81-
source = UniformCatalog(nbar=3e-2, BoxSize=512., seed=42)
29+
source = UniformCatalog(nbar=3e-4, BoxSize=512., seed=42)
8230

8331
# interlacing with TSC
8432
mesh = source.to_mesh(window='tsc', Nmesh=64, interlaced=True, compensated=True)
@@ -95,7 +43,7 @@ def test_paint_chunksize(comm):
9543
def test_cic_interlacing(comm):
9644

9745
CurrentMPIComm.set(comm)
98-
source = UniformCatalog(nbar=3e-2, BoxSize=512., seed=42)
46+
source = UniformCatalog(nbar=3e-4, BoxSize=512., seed=42)
9947

10048
# interlacing with TSC
10149
mesh = source.to_mesh(window='cic', Nmesh=64, interlaced=True, compensated=True)
@@ -108,7 +56,7 @@ def test_cic_interlacing(comm):
10856
def test_setters(comm):
10957

11058
CurrentMPIComm.set(comm)
111-
source = UniformCatalog(nbar=3e-2, BoxSize=512., seed=42)
59+
source = UniformCatalog(nbar=3e-4, BoxSize=512., seed=42)
11260

11361
# make the mesh
11462
mesh = source.to_mesh(window='cic', Nmesh=64, interlaced=True, compensated=True)
@@ -129,7 +77,7 @@ def test_setters(comm):
12977
def test_bad_window(comm):
13078

13179
CurrentMPIComm.set(comm)
132-
source = UniformCatalog(nbar=3e-2, BoxSize=512., seed=42)
80+
source = UniformCatalog(nbar=3e-4, BoxSize=512., seed=42)
13381

13482
# make the mesh
13583
mesh = source.to_mesh(window='cic', Nmesh=64, interlaced=True, compensated=True)
@@ -142,7 +90,7 @@ def test_bad_window(comm):
14290
def test_no_compensation(comm):
14391

14492
CurrentMPIComm.set(comm)
145-
source = UniformCatalog(nbar=3e-2, BoxSize=512., seed=42)
93+
source = UniformCatalog(nbar=3e-4, BoxSize=512., seed=42)
14694

14795
# make the mesh
14896
mesh = source.to_mesh(window='cic', Nmesh=64, interlaced=True, compensated=True)
@@ -154,26 +102,6 @@ def test_no_compensation(comm):
154102
with pytest.raises(ValueError):
155103
actions = mesh.actions
156104

157-
@MPITest([4])
158-
def test_slice(comm):
159-
CurrentMPIComm.set(comm)
160-
161-
# the CatalogSource
162-
source = UniformCatalog(nbar=0.2e-3, BoxSize=1024., seed=42)
163-
source['TEST'] = 10.
164-
165-
# the mesh
166-
source = source.to_mesh(Nmesh=32)
167-
168-
# slice a subset
169-
subset = source[:10]
170-
assert all(col in subset for col in source.columns)
171-
assert isinstance(subset, source.__class__)
172-
assert len(subset) == 10
173-
assert_array_equal(subset['Position'], source['Position'].compute()[:10])
174-
175-
subset = source[[0,1,2]]
176-
assert_array_equal(subset['Position'], source['Position'].compute()[[0,1,2]])
177105

178106
@MPITest([4])
179107
def test_view(comm):
@@ -190,17 +118,13 @@ def test_view(comm):
190118
# view
191119
view = mesh.view()
192120
assert view.base is mesh
193-
assert isinstance(view, mesh.__class__)
121+
from nbodykit.base.mesh import MeshSource
122+
assert isinstance(view, MeshSource)
194123

195124
# check meta-data
196125
for k in mesh.attrs:
197126
assert k in view.attrs
198127

199-
# adding columns to the view changes original source
200-
view['TEST2'] = 5.0
201-
assert 'TEST2' in source
202-
class CodeReached(BaseException): pass
203-
204128
@MPITest([1, 4])
205129
def test_apply_nocompensation(comm):
206130
CurrentMPIComm.set(comm)

0 commit comments

Comments
 (0)