def generate_training_data(): meshes = {} cube_features, cube_target = [[] for i in range(len(cube_sizes)) ], [[] for i in range(len(cube_sizes))] for seed in seeds: mesh = {} partp = tools.readbigfile(path + ftype % (bs, nc, seed, step) + 'dynamic/1/Position/') mesh['cic'] = tools.paintcic(partp, bs, ncp) #mesh['decic'] = tools.decic(mesh['cic'], kk, kny) mesh['R1'] = tools.fingauss(mesh['cic'], kk, R1, kny) #mesh['R2'] = tools.fingauss(mesh['cic'], kk, R2, kny) #mesh['GD'] = mesh['R1'] - mesh['R2'] hmesh = {} hpath = path + ftype % (bs, ncf, seed, stepf) + 'galaxies_n05/galcat/' hposd = tools.readbigfile(hpath + 'Position/') massd = tools.readbigfile(hpath + 'Mass/').reshape(-1) * 1e10 galtype = tools.readbigfile(hpath + 'gal_type/').reshape(-1).astype(bool) hmesh['pnn'] = tools.paintnn(hposd, bs, ncp) hmesh['mnn'] = tools.paintnn(hposd, bs, ncp, massd) hmesh['pnnsat'] = tools.paintnn(hposd[galtype], bs, ncp) hmesh['pnncen'] = tools.paintnn(hposd[~galtype], bs, ncp) meshes[seed] = [mesh, hmesh] print('All the mesh have been generated for seed = %d' % seed) #Create training voxels ftlist = [mesh[i].copy() for i in ftname] ftlistpad = [np.pad(i, pad, 'wrap') for i in ftlist] # targetmesh = hmesh['pnn'] targetmesh = [hmesh[i].copy() for i in tgname] for i, size in enumerate(cube_sizes): print('For size = ', size) if size == nc: features = [np.stack(ftlistpad, axis=-1)] target = [np.stack(targetmesh, axis=-1)] else: numcubes = int(num_cubes / size * 4) features, target = dtools.randomvoxels(ftlistpad, targetmesh, numcubes, max_offset[i], size, cube_sizesft[i], seed=seed, rprob=0) cube_features[i] = cube_features[i] + features cube_target[i] = cube_target[i] + target # # for i in range(cube_sizes.size): cube_target[i] = np.stack(cube_target[i], axis=0) cube_features[i] = np.stack(cube_features[i], axis=0) print(cube_features[i].shape, cube_target[i].shape) return meshes, cube_features, cube_target
def generate_training_data(): meshes = {} cube_features, cube_target = [[] for i in range(len(cube_sizes)) ], [[] for i in range(len(cube_sizes))] for seed in seeds: mesh, hmesh = get_meshes(seed) meshes[seed] = [mesh, hmesh] print('All the mesh have been generated for seed = %d' % seed) #Create training voxels ftlist = [mesh[i].copy() for i in ftname] ftlistpad = [np.pad(i, pad, 'wrap') for i in ftlist] targetmesh = [hmesh[i].copy() for i in tgname] for i, size in enumerate(cube_sizes): print('For size = ', size) if size == nc: features = [np.stack(ftlistpad, axis=-1)] target = [np.stack(targetmesh, axis=-1)] else: numcubes = int(num_cubes / size * 4) if size == 16: numcubes = 100 features, target = dtools.randomvoxels(ftlistpad, targetmesh, numcubes, max_offset[i], size, cube_sizesft[i], seed=seed, rprob=0) cube_features[i] = cube_features[i] + features cube_target[i] = cube_target[i] + target for i in range(cube_sizes.size): cube_target[i] = np.stack(cube_target[i], axis=0) cube_features[i] = np.stack(cube_features[i], axis=0) print(cube_features[i].shape, cube_target[i].shape) return meshes, cube_features, cube_target
meshes[seed] = [mesh, hmesh] print('All the mesh have been generated for seed = %d' % seed, file=fname) #Create training voxels ftlist = [mesh[i].copy() for i in ftname] ftlistpad = [np.pad(i, pad, 'wrap') for i in ftlist] targetmesh = hmesh['pnn'] #Round off things to 1 again targetmesh[targetmesh > 1] = 1 features, target = dtools.randomvoxels(ftlistpad, targetmesh, num_cubes, max_offset, cube_size, cube_sizeft, seed=seed, rprob=rprob) cube_features = cube_features + features cube_target = cube_target + target # cube_target = np.stack(cube_target, axis=0).reshape( (-1, cube_size, cube_size, cube_size, 1)) print(cube_target.sum(), cube_target.size, targetmesh.sum()) print(len(cube_features)) print(cube_features[0].shape) cube_features = np.stack(cube_features, axis=0).reshape( (-1, cube_sizeft, cube_sizeft, cube_sizeft, nchannels)) trainingsize = cube_features.shape[0]