Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
empyre
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Teresa Weßels
empyre
Commits
335cc5e3
Commit
335cc5e3
authored
4 years ago
by
Teresa Weßels
Browse files
Options
Downloads
Patches
Plain Diff
Added capablity to accept bounds for interpolation
parent
7531a074
No related branches found
No related tags found
No related merge requests found
Pipeline
#31120
failed
4 years ago
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
setup.cfg
+1
-1
1 addition, 1 deletion
setup.cfg
src/empyre/io/field_plugins/vtk.py
+6
-2
6 additions, 2 deletions
src/empyre/io/field_plugins/vtk.py
src/empyre/utils/misc.py
+37
-1
37 additions, 1 deletion
src/empyre/utils/misc.py
with
44 additions
and
4 deletions
setup.cfg
+
1
−
1
View file @
335cc5e3
...
...
@@ -7,7 +7,7 @@
[metadata]
name
=
empyre
version
=
0.3.
0
version
=
0.3.
1
author
=
Jan Caron
author-email
=
j.caron@fz-juelich.de
description
=
Electron Microscopy Python Reconstruction
...
...
This diff is collapsed.
Click to expand it.
src/empyre/io/field_plugins/vtk.py
+
6
−
2
View file @
335cc5e3
...
...
@@ -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:
overview: https://docs.enthought.com/mayavi/mayavi/data.html
...
...
@@ -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
:
_log
.
info
(
'
Restrict data
'
)
point_array
,
data_array
=
restrict_points
(
point_array
,
data_array
,
bounds
)
data
=
interp_to_regular_grid
(
point_array
,
data_array
,
scale
,
**
kwargs
)
else
:
raise
TypeError
(
'
Data type of {} not understood!
'
.
format
(
output
))
...
...
This diff is collapsed.
Click to expand it.
src/empyre/utils/misc.py
+
37
−
1
View file @
335cc5e3
...
...
@@ -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
Parameters
----------
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.
Returns
-------
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
.
append
(
pos
)
data_restricted
.
append
(
data_array
[
i
])
point_restricted
=
np
.
array
(
point_restricted
)
data_restricted
=
np
.
array
(
data_restricted
)
return
point_restricted
,
data_restricted
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment