Commit 7f40b76f authored by Jan Caron's avatar Jan Caron

Merge branch 'vtk_bounds' into 'master'

Added capablity to accept bounds for interpolation

Possibility to restrict data range before interpolation for the vtk reader. There is a new function restrict_data in `io.utils.misc`.

See merge request empyre/empyre!37
parents 7531a074 20f545d9
Pipeline #31123 passed with stages
in 4 minutes
......@@ -7,7 +7,7 @@
name = empyre
version = 0.3.0
version = 0.3.1
author = Jan Caron
author-email =
description = Electron Microscopy Python Reconstruction
......@@ -11,7 +11,7 @@ from numbers import Number
import numpy as np
from ...fields.field import Field
from ...utils.misc import interp_to_regular_grid
from ...utils.misc import interp_to_regular_grid, restrict_points
from ...vis import colors
......@@ -20,7 +20,7 @@ _log = logging.getLogger(__name__)
file_extensions = ('.vtk',) # Recognised file extensions
def reader(filename, scale=None, vector=None, **kwargs):
def reader(filename, scale=None, vector=None, bounds=None, **kwargs):
"""More infos at:
......@@ -88,6 +88,10 @@ def reader(filename, scale=None, vector=None, **kwargs):
scale = (scale,) * 3
elif isinstance(scale, tuple):
assert len(scale) == 3, f'Each dimension (z, y, x) needs a scale, but {scale} was given!'
# Crop data to required range, if necessary
if bounds is not None:'Restrict data')
point_array, data_array = restrict_points(point_array, data_array, bounds)
data = interp_to_regular_grid(point_array, data_array, scale, **kwargs)
raise TypeError('Data type of {} not understood!'.format(output))
......@@ -15,7 +15,7 @@ from scipy.spatial import cKDTree, qhull
from scipy.interpolate import LinearNDInterpolator
__all__ = ['levi_civita', 'interp_to_regular_grid']
__all__ = ['levi_civita', 'interp_to_regular_grid', 'restrict_points']
_log = logging.getLogger(__name__)
......@@ -121,3 +121,39 @@ def interp_to_regular_grid(points, values, scale, scale_factor=1, step=1, convex
# Set these points to zero (NOTE: This can take a looooong time):
interpolation[mask, :] = 0
return np.squeeze(interpolation)
def restrict_points(point_array, data_array, bounds):
"""Restrict range of point_array and data_array
points_array : np.ndarray, (N, 3)
Array of points, describing the location of the values that should be interpolated. Three columns x, y, z!
data_array : np.ndarray, (N, c)
Array of values that should be interpolated to the new grid. `c` is the number of components (`1` for scalar
fields, `3` for normal 3D vector fields).
bounds : tuple of 6 values
Restrict data range to given bounds, x0, x1, y0, y1, z0, z1.
point_restricted: np.ndarray
Cut out of the array of points inside the bounds, describing the location of the values that should be
interpolated. Three columns x, y, z!
value_restricted: np.ndarray
Cut out of the array of values inside the bounds, describing the location of the values that should be
interpolated. Three columns x, y, z!
point_restricted = []
data_restricted = []
for i, pos in enumerate(point_array):
if bounds[0] <= pos[0] <= bounds[1]:
if bounds[2] <= pos[1] <= bounds[3]:
if bounds[4] <= pos[2] <= bounds[5]:
point_restricted = np.array(point_restricted)
data_restricted = np.array(data_restricted)
return point_restricted, data_restricted
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment