Skip to content

Commit

Permalink
Merge 1ed0997 into 399a3e8
Browse files Browse the repository at this point in the history
  • Loading branch information
nickhand committed Apr 4, 2017
2 parents 399a3e8 + 1ed0997 commit fcfe1a2
Show file tree
Hide file tree
Showing 40 changed files with 885 additions and 549 deletions.
10 changes: 5 additions & 5 deletions nbodykit/algorithms/fftpower.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ def __init__(self, first, mode, Nmesh=None, BoxSize=None, second=None, los=[0, 0
----------
comm :
the MPI communicator
first : ParticleSource, MeshSource
the source for the first field. ParticleSource is automatically converted
first : CatalogSource, MeshSource
the source for the first field. CatalogSource is automatically converted to MeshSource
mode : {'1d', '2d'}
compute either 1d or 2d power spectra
Nmesh : int
the number of cells per side in the particle mesh used to paint the source
second : ParticleSource, MeshSource; optional
second : CatalogSource, MeshSource; optional
the second source for cross-correlations
los : array_like ; optional
the direction to use as the line-of-sight
Expand All @@ -86,7 +86,7 @@ def __init__(self, first, mode, Nmesh=None, BoxSize=None, second=None, los=[0, 0
# grab comm from first source
self.comm = first.comm

# if input is ParticleSource, use defaults to make it into a mesh
# if input is CatalogSource, use defaults to make it into a mesh
if not hasattr(first, 'paint'):
first = first.to_mesh(BoxSize=BoxSize, Nmesh=Nmesh, dtype='f8', compensated=True)

Expand Down Expand Up @@ -297,7 +297,7 @@ def _compute_3d_power(self):
Parameters
----------
sources : list of ParticleSource or MeshSource
sources : list of CatalogSource or MeshSource
the list of sources which the 3D power will be computed
pm : ParticleMesh
the particle mesh object that handles the painting and FFTs
Expand Down
12 changes: 6 additions & 6 deletions nbodykit/algorithms/fibercollisions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from nbodykit import CurrentMPIComm
from nbodykit.base.particles import ParticleSource
from nbodykit.source import Array
from nbodykit.base.catalog import CatalogSource
from nbodykit.source import ArrayCatalog

from nbodykit.transform import SkyToUnitSphere
import numpy
Expand Down Expand Up @@ -41,14 +41,14 @@ def __init__(self, ra, dec, collision_radius=62/60./60., seed=None, degrees=True
the random seed
"""
# compute the pos
ra = ParticleSource.make_column(ra)
dec = ParticleSource.make_column(dec)
ra = CatalogSource.make_column(ra)
dec = CatalogSource.make_column(dec)
pos = SkyToUnitSphere(ra, dec, degrees=degrees).compute()

# make the source
dt = numpy.dtype([('Position', (pos.dtype.str, 3))])
pos = numpy.squeeze(pos.view(dtype=dt))
source = Array(pos, BoxSize=numpy.array([2., 2., 2.]))
source = ArrayCatalog(pos, BoxSize=numpy.array([2., 2., 2.]))

self.source = source
self.comm = source.comm
Expand Down Expand Up @@ -116,7 +116,7 @@ def run(self):
for col, x in d: result[col] = x

# make a particle source
self.labels = Array(result, comm=self.comm, **self.source.attrs)
self.labels = ArrayCatalog(result, comm=self.comm, **self.source.attrs)

def _assign_fibers(self, Label):
"""
Expand Down
16 changes: 8 additions & 8 deletions nbodykit/algorithms/fof.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy
import logging
from mpi4py import MPI
from nbodykit.source import Array
from nbodykit.source import ArrayCatalog

class FOF(object):
"""
Expand All @@ -25,7 +25,7 @@ def __init__(self, source, linking_length, nmin, absolute=False):
"""
Parameters
----------
source : ParticleSource
source : CatalogSource
the source to run the FOF algorithm on; must support 'Position'
linking_length : float
the linking length, either in absolute units, or relative
Expand Down Expand Up @@ -84,7 +84,7 @@ def find_features(self):
Returns
-------
ParticleSource :
CatalogSource :
a source holding the ('Position', 'Velocity', 'Length')
of each halo
"""
Expand All @@ -94,7 +94,7 @@ def find_features(self):
# return a Source
attrs = self._source.attrs.copy()
attrs.update(self.attrs)
return Array(halos, comm=self.comm, **attrs)
return ArrayCatalog(halos, comm=self.comm, **attrs)

def to_halos(self, particle_mass, cosmo, redshift, mdef='vir'):
"""
Expand All @@ -107,7 +107,7 @@ def to_halos(self, particle_mass, cosmo, redshift, mdef='vir'):
Parameters
----------
source : ParticleSource
source : CatalogSource
the source containing info about the particles in each halo
particle_mass : float
the particle mass, used to compute the number of particles in
Expand Down Expand Up @@ -136,7 +136,7 @@ def to_halos(self, particle_mass, cosmo, redshift, mdef='vir'):
# the center-of-mass (Position, Velocity, Length) for each halo
data = fof_catalog(self._source, self.labels, self.comm)
data = data[data['Length'] > 0]
halos = Array(data, **attrs)
halos = ArrayCatalog(data, **attrs)

# add the halo mass column
halos['Mass'] = particle_mass * halos['Length']
Expand Down Expand Up @@ -291,7 +291,7 @@ def fof(source, linking_length, comm):
Parameters
----------
source: ParticleSource
source: CatalogSource
the input source of particles; must support 'Position' column;
``source.attrs['BoxSize']`` is also used
linking_length: float
Expand Down Expand Up @@ -345,7 +345,7 @@ def fof_catalog(source, label, comm,
Parameters
----------
source: ParticleSource
source: CatalogSource
the parent source of particles from which the center-of-mass
position and velocity are computed for each halo
label : array_like
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def test_selection(comm):
CurrentMPIComm.set(comm)
cosmo = cosmology.Planck15

data = Source.RandomParticles(NDATA, seed=42)
randoms = Source.RandomParticles(NDATA*10, seed=84)
data = RandomCatalog(NDATA, seed=42)
randoms = RandomCatalog(NDATA*10, seed=84)

# add the random columns
for s in [data, randoms]:
Expand All @@ -38,7 +38,7 @@ def test_selection(comm):
s['Selection'] = (s['z'] > 0.4)&(s['z'] < 0.6)

# the FKP source
fkp = Source.FKPCatalog(data, randoms)
fkp = FKPCatalog(data, randoms)
fkp = fkp.to_mesh(Nmesh=128, dtype='f8', nbar='NZ', selection='Selection')

# compute the multipoles
Expand All @@ -64,8 +64,8 @@ def test_run(comm):
CurrentMPIComm.set(comm)
cosmo = cosmology.Planck15

data = Source.RandomParticles(NDATA, seed=42)
randoms = Source.RandomParticles(NDATA*10, seed=84)
data = RandomCatalog(NDATA, seed=42)
randoms = RandomCatalog(NDATA*10, seed=84)

# add the random columns
for s in [data, randoms]:
Expand All @@ -86,7 +86,7 @@ def test_run(comm):
s['Weight'] = (1 + P0*s['NZ'])**2

# the FKP source
fkp = Source.FKPCatalog(data, randoms)
fkp = FKPCatalog(data, randoms)
fkp = fkp.to_mesh(Nmesh=128, dtype='f8', nbar='NZ', fkp_weight='FKPWeight', comp_weight='Weight', selection='Selection')

# compute the multipoles
Expand Down Expand Up @@ -117,8 +117,8 @@ def test_with_zhist(comm):
CurrentMPIComm.set(comm)
cosmo = cosmology.Planck15

data = Source.RandomParticles(NDATA, seed=42, use_cache=True)
randoms = Source.RandomParticles(NDATA*10, seed=84, use_cache=True)
data = RandomCatalog(NDATA, seed=42, use_cache=True)
randoms = RandomCatalog(NDATA*10, seed=84, use_cache=True)

# add the random columns
for s in [data, randoms]:
Expand All @@ -132,7 +132,7 @@ def test_with_zhist(comm):
s['Position'] = transform.SkyToCartesion(s['ra'], s['dec'], s['z'], cosmo=cosmo)

# initialize the FKP source
fkp = Source.FKPCatalog(data, randoms)
fkp = FKPCatalog(data, randoms)

# compute NZ from randoms
zhist = RedshiftHistogram(fkp.randoms, FSKY, cosmo, redshift='z')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
def test_fftpower_poles(comm):

CurrentMPIComm.set(comm)
source = Source.UniformParticles(nbar=3e-3, BoxSize=512., seed=42)
source = UniformCatalog(nbar=3e-3, BoxSize=512., seed=42)

r = FFTPower(source, mode='2d', BoxSize=1024, Nmesh=32, poles=[0,2,4])
pkmu = r.power['power'].real
Expand All @@ -27,7 +27,7 @@ def test_fftpower_poles(comm):
def test_fftpower_padding(comm):

CurrentMPIComm.set(comm)
source = Source.UniformParticles(nbar=3e-3, BoxSize=512., seed=42)
source = UniformCatalog(nbar=3e-3, BoxSize=512., seed=42)

r = FFTPower(source, mode='1d', BoxSize=1024, Nmesh=32)
assert r.attrs['N1'] != 0
Expand All @@ -37,7 +37,7 @@ def test_fftpower_padding(comm):
def test_fftpower_padding(comm):

CurrentMPIComm.set(comm)
source = Source.UniformParticles(nbar=3e-3, BoxSize=512., seed=42)
source = UniformCatalog(nbar=3e-3, BoxSize=512., seed=42)

r = FFTPower(source, mode='1d', BoxSize=1024, Nmesh=32)
assert r.attrs['N1'] != 0
Expand All @@ -47,7 +47,7 @@ def test_fftpower_padding(comm):
def test_fftpower_save(comm):

CurrentMPIComm.set(comm)
source = Source.UniformParticles(nbar=3e-3, BoxSize=512., seed=42)
source = UniformCatalog(nbar=3e-3, BoxSize=512., seed=42)

r = FFTPower(source, mode='2d', Nmesh=32)
r.save('fftpower-test.json')
Expand All @@ -63,7 +63,7 @@ def test_fftpower_save(comm):
def test_fftpower(comm):

CurrentMPIComm.set(comm)
source = Source.UniformParticles(nbar=3e-3, BoxSize=512., seed=42)
source = UniformCatalog(nbar=3e-3, BoxSize=512., seed=42)

r = FFTPower(source, mode='1d', Nmesh=32)
# the zero mode is cleared
Expand All @@ -76,7 +76,7 @@ def test_fftpower_mismatch_boxsize(comm):
CurrentMPIComm.set(comm)

# input sources
source1 = Source.UniformParticles(nbar=3e-3, BoxSize=512., seed=42)
source2 = Source.LinearMesh(cosmology.NoWiggleEHPower(cosmo, 0.55), BoxSize=1024, Nmesh=32, seed=33)
source1 = UniformCatalog(nbar=3e-3, BoxSize=512., seed=42)
source2 = LinearMesh(cosmology.NoWiggleEHPower(cosmo, 0.55), BoxSize=1024, Nmesh=32, seed=33)

r = FFTPower(source1, second=source2, mode='1d', BoxSize=1024, Nmesh=32)
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test_fof(comm):
CurrentMPIComm.set(comm)

# lognormal particles
source = Source.LogNormal(Plin=cosmology.EHPower(cosmo, 0.55),
source = LogNormalCatalog(Plin=cosmology.EHPower(cosmo, 0.55),
nbar=3e-3, BoxSize=512., Nmesh=128, seed=42)

# compute P(k,mu) and multipoles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_save(comm):
cosmo = cosmology.Planck15

# create the source
source = Source.RandomParticles(N, seed=42)
source = RandomCatalog(N, seed=42)
source['z'] = source.rng.normal(loc=0.5, scale=0.1, size=source.size)

# compute the histogram
Expand All @@ -43,7 +43,7 @@ def test_unweighted(comm):
cosmo = cosmology.Planck15

# create the source
source = Source.RandomParticles(N, seed=42)
source = RandomCatalog(N, seed=42)
source['z'] = source.rng.normal(loc=0.5, scale=0.1, size=source.size)

# compute the histogram
Expand All @@ -62,7 +62,7 @@ def test_weighted(comm):
cosmo = cosmology.Planck15

# create the source
source = Source.RandomParticles(N, seed=42)
source = RandomCatalog(N, seed=42)
source['z'] = source.rng.normal(loc=0.5, scale=0.1, size=source.size)
source['weight'] = source.rng.uniform(0, high=1., size=source.size)

Expand Down
2 changes: 1 addition & 1 deletion nbodykit/algorithms/threeptcf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self, source, poles, edges, BoxSize=None, periodic=True, weight='We
"""
Parameters
----------
source : ParticleSource
source : CatalogSource
the input source of particles providing the 'Position' column
poles : list of int
the list of multipole numbers to compute
Expand Down
2 changes: 1 addition & 1 deletion nbodykit/algorithms/zhist.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __init__(self, source, fsky, cosmo, bins=None, redshift='Redshift', weight=N
"""
Parameters
----------
source : ParticleSource
source : CatalogSource
the source of particles holding the redshift column to histogram
fsky : float
the sky area fraction, which is used in the volume calculation when
Expand Down
Loading

0 comments on commit fcfe1a2

Please sign in to comment.