Created
February 7, 2017 11:45
-
-
Save Finwood/e70b6675edbdd6ec63b7539a2557be01 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python3 | |
# coding: utf-8 | |
import numpy as np | |
STEPSIZE = 5e-3 | |
def _get_indexer(lower_bound, upper_bound, stepsize): | |
def indexer(value): | |
val_norm = min(max(lower_bound, value), upper_bound-stepsize) | |
return int((val_norm - lower_bound) / stepsize) | |
return indexer | |
def create_mesh(xlim, ylim, zlim, d): | |
nx = int((xlim[1]-xlim[0]) / d) | |
ny = int((ylim[1]-ylim[0]) / d) | |
nz = int((zlim[1]-zlim[0]) / d) | |
mesh = np.zeros((nx, ny, nz), dtype='uint8') | |
ix = _get_indexer(xlim[0], xlim[1], d) | |
iy = _get_indexer(ylim[0], ylim[1], d) | |
iz = _get_indexer(zlim[0], zlim[1], d) | |
return mesh, (ix, iy, iz) | |
data = np.load('xzy_orig_1of100_2.npy').T | |
xlim, zlim, ylim = np.array((np.min(data, 0), np.max(data, 0))).T | |
mesh, indexers = create_mesh(xlim, ylim, zlim, STEPSIZE) | |
for x, z, y in data: | |
pos = tuple(ix(v) for ix, v in zip(indexers, (x, y, z))) | |
mesh[pos] += 1 | |
np.save('mesh', mesh) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment