def convert_bigfile_to_npy(in_file,out_file):
    orig_mesh = nbk.BigFileMesh(in_file,'Field')
    orig_field = orig_mesh.compute(mode='real')
    print('Finished reading bigfile grid')
    # Note that Yu recommends not using preview for exporting computed grids
    # (see https://github.com/bccp/nbodykit/issues/599), but it actually
    # worked fine for our numerical tests (i.e. bispectra measured from 
    # the bigfile and numpy files agreed at close to numerical precision).
    orig_npy_array = orig_field.preview()
    np.save(out_file,orig_npy_array)
    print('Converted grid %s to npy file %s' % (in_file,out_file))
예제 #2
0
parser.add_argument('in_file',
                    help='input bigfile')
parser.add_argument('out_file',
                    help='output bigfile')
parser.add_argument('n_mesh',type=int,
                    help='resolution of downsampled mesh')

# Parse arguments
args = parser.parse_args()
in_file = args.in_file
out_file = args.out_file
n_mesh = args.n_mesh

comm = CurrentMPIComm.get()

# Set start time, and print first status message
start_time = time.time()
print_status(comm,start_time,'Starting script')

# Import mesh from file
orig_mesh = nbk.BigFileMesh(in_file,'Field')
print_status(comm,start_time,'Imported mesh from %s with Nmesh %d' % (in_file,orig_mesh.attrs['Nmesh'][0]))

# Define new FieldMesh from downsampled version of original mesh
new_mesh = nbk.FieldMesh(orig_mesh.compute(mode='real',Nmesh=n_mesh))
print_status(comm,start_time,'Created new mesh with Nmesh %d' % new_mesh.attrs['Nmesh'][0])

# Save mesh to disk, as bigfile (actual computation of downsampling happens in this step)
new_mesh.save(out_file,dataset='Field',mode='real')
print_status(comm,start_time,'Wrote mesh to %s' % out_file)
예제 #3
0
        raise ValueError('need second mesh if third mesh is input!')
    num_fields += 1

# Get particle catalogs, or meshes, if working with bigfiles
for i in range(num_fields):
    if snap_type == 'illustris':
        cat[i] = HDFCatalog(snap_prefix[i]+'*')
        mesh[i] = cat[i].to_mesh(Nmesh=Nmesh,BoxSize=BoxSize/pos_fac,
                                     window='cic',compensated=True,
                                     position='PartType1/Coordinates')
    elif snap_type == 'gadget':
        cat[i] = Gadget1Catalog(snap_prefix[i]+'*')
        mesh[i] = cat[i].to_mesh(Nmesh=Nmesh,BoxSize=BoxSize,
                                     window='cic',compensated=True)
    elif snap_type == 'bigfile_grid':
        mesh[i] = nbk.BigFileMesh(snap_prefix[i],'Field')
        if do_cic:
            # Apply CIC window compensation to mesh
            mesh[i] = mesh[i].apply(CompensateCICShotnoiseNgrid,kind='circular',mode='complex')
            print_status(comm,start_time,'Applied CIC compensation to mesh %d' % i)

print_status(comm,start_time,'Finished input')
print_status(comm,start_time,'Starting initial paints')

# Paint meshes (and cross-meshes, if present) to fields    
for i in range(num_fields):
    field[i] = mesh[i].compute(mode='real')
    
# Initialize container dict for submeshes
sub_mesh = {}
for n in range(3):
예제 #4
0
    original syntax, and Jing et al. 2005 Eq. 20 for formula reference.
    """
    for i in range(3):
        wi = w[i]
        v = v / (1 - 2. / 3 * np.sin(0.5 * wi * Nmesh / NmeshCIC)**2)**0.5
    return v


comm = CurrentMPIComm.get()

# Set start time, and print first status message
start_time = time.time()
print_status(comm, start_time, 'Starting script')

# Import mesh from file
mesh = nbk.BigFileMesh(in_file, 'Field')
print_status(comm, start_time, 'Read input grid from %s' % in_file)
if (cross_in_file is not None):
    cross_mesh = nbk.BigFileMesh(cross_in_file, 'Field')
    print_status(comm, start_time, 'Read input grid from %s' % cross_in_file)

if do_cic:
    # Apply CIC window compensation to mesh
    mesh = mesh.apply(CompensateCICShotnoiseNgrid,
                      kind='circular',
                      mode='complex')
    print_status(comm, start_time, 'Applied CIC compensation to mesh')
    if (cross_in_file is not None):
        cross_mesh = cross_mesh.apply(CompensateCICShotnoiseNgrid,
                                      kind='circular',
                                      mode='complex')