Skip to content

Commit

Permalink
Merge pull request #630 from bccp/fix-complex-mesh-save
Browse files Browse the repository at this point in the history
Fix wrong shape of complex mesh save.
  • Loading branch information
rainwoodman committed Aug 19, 2020
2 parents ba9b817 + 49beb2e commit 9b53312
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions nbodykit/base/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,11 @@ def save(self, output, dataset='Field', mode='real'):
field.ravel(out=data)
with ff.create_from_array(dataset, data) as bb:
if isinstance(field, RealField):
bb.attrs['ndarray.shape'] = field.pm.Nmesh
bb.attrs['ndarray.shape'] = field.cshape
bb.attrs['BoxSize'] = field.pm.BoxSize
bb.attrs['Nmesh'] = field.pm.Nmesh
elif isinstance(field, BaseComplexField):
bb.attrs['ndarray.shape'] = field.Nmesh, field.Nmesh, field.Nmesh // 2 + 1
bb.attrs['ndarray.shape'] = field.cshape
bb.attrs['BoxSize'] = field.pm.BoxSize
bb.attrs['Nmesh'] = field.pm.Nmesh

Expand Down
6 changes: 3 additions & 3 deletions nbodykit/base/tests/test_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_real_save(comm):
shutil.rmtree(tmpfile)

@MPITest([1,4])
def test_real_save(comm):
def test_complex_save(comm):

cosmo = cosmology.Planck15

Expand All @@ -94,7 +94,7 @@ def test_real_save(comm):
source.attrs['empty'] = None

# save to bigfile
source.save(tmpfile, mode='real')
source.save(tmpfile, mode='complex')

# load as a BigFileMesh
source2 = BigFileMesh(tmpfile, dataset='Field', comm=comm)
Expand All @@ -104,7 +104,7 @@ def test_real_save(comm):
assert_array_equal(source2.attrs[k], source.attrs[k])

# check data
assert_array_equal(source2.compute(mode='real'), source.compute(mode='real'))
assert_array_equal(source2.compute(mode='complex'), source.compute(mode='complex'))

# cleanup
comm.barrier()
Expand Down

0 comments on commit 9b53312

Please sign in to comment.