In [1]:
# this cell is hidden by meta-data
import tempfile, os
startdir = os.path.abspath('.')
tmpdir = tempfile.mkdtemp()
os.chdir(tmpdir)

In [2]:
from nbodykit.lab import UniformCatalog, FFTPower

cat = UniformCatalog(nbar=100, BoxSize=1.0, seed=42)

r = FFTPower(cat, mode='2d', Nmesh=32, Nmu=5, poles=[0,2,4])


/home/yfeng1/anaconda3/install/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters

In [3]:
# the 2D power spectrum results
print("power = ", r.power)
print("variables = ", r.power.variables)
for name in r.power.variables:
    var = r.power[name]
    print("'%s' has shape %s and dtype %s" %(name, var.shape, var.dtype))


power =  <BinnedStatistic: dims: (k: 16, mu: 5), variables: ('k', 'mu', 'power', 'modes')>
variables =  ['k', 'mu', 'power', 'modes']
'k' has shape (16, 5) and dtype float64
'mu' has shape (16, 5) and dtype float64
'power' has shape (16, 5) and dtype complex128
'modes' has shape (16, 5) and dtype int64

In [4]:
# the multipole results
print("poles = ", r.poles)
print("variables = ", r.poles.variables)
for name in r.poles.variables:
    var = r.poles[name]
    print("'%s' has shape %s and dtype %s" %(name, var.shape, var.dtype))


poles =  <BinnedStatistic: dims: (k: 16), variables: 5 total>
variables =  ['k', 'power_0', 'power_2', 'power_4', 'modes']
'k' has shape (16,) and dtype float64
'power_0' has shape (16,) and dtype complex128
'power_2' has shape (16,) and dtype complex128
'power_4' has shape (16,) and dtype complex128
'modes' has shape (16,) and dtype int64

In [5]:
for k in r.power.attrs:
  print("%s = %s" %(k, str(r.power.attrs[k])))


Nmesh = [32 32 32]
BoxSize = [1. 1. 1.]
Lx = 1.0
Ly = 1.0
Lz = 1.0
volume = 1.0
mode = 2d
los = [0, 0, 1]
Nmu = 5
poles = [0, 2, 4]
dk = 6.283185307179586
kmin = 0.0
N1 = 96
N2 = 96
shotnoise = 0.010416666666666666

In [6]:
# save to file
r.save("fftpower-example.json")

# load from file
r2 = FFTPower.load("fftpower-example.json")

print("power = ", r2.power)
print("poles = ", r2.poles)
print("attrs = ", r2.attrs)


power =  <BinnedStatistic: dims: (k: 16, mu: 5), variables: ('k', 'mu', 'power', 'modes')>
poles =  <BinnedStatistic: dims: (k: 16), variables: 5 total>
attrs =  {'Nmesh': array([32, 32, 32]), 'BoxSize': array([1., 1., 1.]), 'Lx': 1.0, 'Ly': 1.0, 'Lz': 1.0, 'volume': 1.0, 'mode': '2d', 'los': [0, 0, 1], 'Nmu': 5, 'poles': [0, 2, 4], 'dk': 6.283185307179586, 'kmin': 0.0, 'N1': 96, 'N2': 96, 'shotnoise': 0.010416666666666666}

In [7]:
import shutil
os.chdir(startdir)
shutil.rmtree(tmpdir)