-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #221 from rainwoodman/improvgrid
WIP: Improving the Grid to support reading k and Fourier resampling
- Loading branch information
Showing
10 changed files
with
385 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
Nmesh: 64 | ||
output: ${NBKIT_HOME}/examples/output/test_paint_fastpm | ||
|
||
Nmesh : 64 | ||
paintNmesh: 128 | ||
DataSource: | ||
plugin: FastPM | ||
path: ${NBKIT_CACHE}/data/fastpm_1.0000 | ||
|
||
Nfile : 4 | ||
Painter: | ||
plugin: DefaultPainter | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
Nmesh: 64 | ||
paintNmesh : 128 | ||
output: ${NBKIT_HOME}/examples/output/test_paint_grid | ||
nfile : 4 | ||
DataSource: | ||
plugin: BigFileGrid | ||
path: ${NBKIT_CACHE}/data/bigfile_grid | ||
dataset: PaintGrid | ||
|
||
Painter: | ||
plugin: DefaultPainter | ||
normalize : true | ||
setMean : 1.0 # useful for over density inputs. | ||
fk : exp(- 0.5 * (k * 8) ** 2) | ||
frho : (rho - 1) ** 2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Nmesh: 32 | ||
output: ${NBKIT_HOME}/examples/output/test_paint_grid_32 | ||
nfile : 4 | ||
DataSource: | ||
plugin: BigFileGrid | ||
path: ${NBKIT_CACHE}/data/bigfile_grid | ||
dataset: PaintGrid | ||
Painter: | ||
plugin: DefaultPainter | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Nmesh: 128 | ||
output: ${NBKIT_HOME}/examples/output/test_paint_grid_128 | ||
nfile : 4 | ||
DataSource: | ||
plugin: BigFileGrid | ||
path: ${NBKIT_CACHE}/data/bigfile_grid | ||
dataset: PaintGrid | ||
Painter: | ||
plugin: DefaultPainter | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Nmesh: 64 | ||
paintNmesh : 128 | ||
output: ${NBKIT_HOME}/examples/output/test_paint_gridk | ||
nfile : 4 | ||
DataSource: | ||
plugin: BigFileGrid | ||
path: ${NBKIT_CACHE}/data/bigfile_gridk | ||
dataset: LinearDensityK | ||
Painter: | ||
plugin: DefaultPainter | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,50 @@ | ||
from nbodykit.extensionpoints import GridSource | ||
from nbodykit import resampler | ||
import numpy | ||
|
||
class BigFileGridSource(GridSource): | ||
""" | ||
Class to read field gridded data from a binary file | ||
Notes | ||
----- | ||
* Reading is designed to be done by `GridPainter`, which | ||
reads gridded quantity straight into the `ParticleMesh` | ||
""" | ||
plugin_name = "BigFileGrid" | ||
|
||
def __init__(self, path, dataset): | ||
import bigfile | ||
f = bigfile.BigFileMPI(self.comm, self.path) | ||
self.dataset = dataset | ||
self.path = path | ||
|
||
with f[self.dataset] as d: | ||
self.BoxSize = d.attrs['BoxSize'] | ||
self.Nmesh = d.attrs['Nmesh'][0] | ||
self.Ntot = d.attrs['Ntot'][0] | ||
self.Nmesh = int(d.attrs['Nmesh'][0]) | ||
if 'Ntot' in d.attrs: | ||
self.Ntot = d.attrs['Ntot'][0] | ||
else: | ||
self.Ntot = 0 | ||
|
||
# Is this a complex field or a real field? | ||
if d.dtype.kind == 'c': | ||
self.isfourier = True | ||
else: | ||
self.isfourier = False | ||
|
||
@classmethod | ||
def register(cls): | ||
s = cls.schema | ||
s.description = "read gridded field data from a binary file" | ||
s.description = "read gridded field data from a binary file. Fourier resampling is applied if necessary." | ||
|
||
s.add_argument("path", type=str, help="the file path to load the data from") | ||
s.add_argument("dataset", type=str, help="the file path to load the data from") | ||
|
||
def read(self, pm): | ||
if pm.Nmesh != self.Nmesh: | ||
raise ValueError("The Grid has a mesh size of %d, but ParticleMesh has %d" % (self.Nmesh, pm.Nmesh)) | ||
|
||
import bigfile | ||
import mpsort | ||
f = bigfile.BigFileMPI(self.comm, self.path) | ||
|
||
istart = pm.partition.local_i_start | ||
|
||
x3d = numpy.empty(pm.real.shape, dtype='f4') | ||
|
||
ind = numpy.zeros(x3d.shape, dtype='i8') | ||
|
||
for d in range(3): | ||
i = numpy.arange(istart[d], istart[d] + x3d.shape[d]) | ||
i = i.reshape([-1 if dd == d else 1 for dd in range(3)]) | ||
ind[...] *= pm.Nmesh | ||
ind[...] += i | ||
|
||
ind = ind.ravel() | ||
x3d = x3d.ravel() | ||
|
||
start = sum(self.comm.allgather(x3d.size)[:self.comm.rank]) | ||
end = start + x3d.size | ||
|
||
originind = numpy.arange(start, end, dtype='i8') | ||
|
||
mpsort.sort(originind, orderby=ind, comm=self.comm) | ||
if self.comm.rank == 0: | ||
self.logger.info("Reading from Nmesh = %d to Nmesh = %d" %(self.Nmesh, pm.Nmesh)) | ||
|
||
f = bigfile.BigFileMPI(self.comm, self.path) | ||
with f[self.dataset] as ds: | ||
x3d[:] = ds[start: end] | ||
|
||
mpsort.sort(x3d, orderby=originind, comm=self.comm) | ||
resampler.read(pm, ds, self.Nmesh, self.isfourier) | ||
|
||
pm.real.flat[:] = x3d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.