Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Daniel Boeckenhoff
tfields
Commits
d4100705
Commit
d4100705
authored
Jun 17, 2019
by
Daniel Boeckenhoff
Committed by
Daniel Boeckenhoff
Mar 18, 2020
Browse files
numpy vs 1.11.3 compatibility
parent
31d4b20a
Changes
4
Hide whitespace changes
Inline
Side-by-side
tfields/core.py
View file @
d4100705
...
...
@@ -182,7 +182,7 @@ class AbstractNdarray(np.ndarray):
if
n_old
>
0
:
for
latest_index
in
range
(
n_old
):
new_slot
=
added_slot_attrs
[
-
latest_index
]
warnings
.
warn
(
"Slots with names '{new_slot}' appears to have been"
warnings
.
warn
(
"Slots with names '{new_slot}' appears to have been
"
"added after the creation of the reduced state. "
"No corresponding state found in __setstate__."
.
format
(
**
locals
()))
...
...
@@ -2019,9 +2019,7 @@ class TensorMaps(TensorFields):
... [4, 4, 4],
... [5, 5, 5]])
True
>>> c.maps[0]
TensorFields([[0, 1, 2],
[0, 1, 3]])
>>> assert c.maps[0].equal([[0, 1, 2], [0, 1, 3]])
>>> assert c.maps[0].fields[0].equal([5, 9])
>>> assert c.maps[0].fields[1].equal([6, 0])
...
...
@@ -2063,9 +2061,7 @@ class TensorMaps(TensorFields):
... [4, 4, 4],
... [5, 5, 5]])
True
>>> c.maps[0]
TensorFields([[0, 1, 2],
[0, 1, 3]])
>>> assert c.maps[0].equal(np.array([[0, 1, 2], [0, 1, 3]]))
>>> assert c.maps[0].fields[0].equal([5, 9])
>>> assert c.maps[0].fields[1].equal([6, 0])
...
...
@@ -2206,7 +2202,7 @@ class Container(AbstractNdarray):
if
__name__
==
'__main__'
:
# pragma: no cover
import
doctest
doctest
.
testmod
()
# doctest.run_docstring_examples(
as_t
ensor
s_list
, globals())
# doctest.run_docstring_examples(
T
ensor
Fields.__getitem__
, globals())
# doctest.run_docstring_examples(Tensors._save_npz, globals())
# doctest.run_docstring_examples(TensorMaps.cut, globals())
# doctest.run_docstring_examples(AbstractNdarray._save_npz, globals())
tfields/mesh3D.py
View file @
d4100705
...
...
@@ -725,8 +725,10 @@ class Mesh3D(tfields.TensorMaps):
n_faces
=
len
(
self
.
maps
[
0
])
point_indices
=
np
.
arange
(
len
(
tensor_field
))
if
not
hasattr
(
tensor_field
,
'fields'
)
or
len
(
tensor_field
.
fields
)
==
0
:
fields
=
[
np
.
full
(
len
(
tensor_field
),
1
)]
empty_map_fields
=
[
tfields
.
Tensors
(
np
.
full
(
n_faces
,
0
))]
# if not fields is existing use int type fields and empty_map_fields
# in order to generate a sum
fields
=
[
np
.
full
(
len
(
tensor_field
),
1
,
dtype
=
int
)]
empty_map_fields
=
[
tfields
.
Tensors
(
np
.
full
(
n_faces
,
0
,
dtype
=
int
))]
if
merge_functions
is
None
:
merge_functions
=
[
np
.
sum
]
else
:
...
...
@@ -1179,7 +1181,6 @@ class Mesh3D(tfields.TensorMaps):
if
__name__
==
'__main__'
:
# pragma: no cover
import
doctest
doctest
.
run_docstring_examples
(
Mesh3D
.
project
,
globals
())
doctest
.
run_docstring_examples
(
Mesh3D
.
tree
,
globals
())
# doctest.testmod()
# doctest.run_docstring_examples(Mesh3D.project, globals())
# doctest.run_docstring_examples(Mesh3D.tree, globals())
doctest
.
testmod
()
tfields/points3D.py
View file @
d4100705
...
...
@@ -33,66 +33,67 @@ class Points3D(tfields.Tensors):
>>> import tfields
>>> import numpy as np
>>> p1 = tfields.Points3D([[1., 2., 3.], [4., 5., 6.], [1, 2, -6]])
>>> p1
Points3D([[ 1., 2., 3.],
[ 4., 5., 6.],
[ 1., 2., -6.]])
>>> assert p1.equal([[1., 2., 3.],
... [4., 5., 6.],
... [1., 2., -6.]])
Initializing with list of coordinates
>>> p2 = tfields.Points3D(np.array([[1., 2., 3., 4, 5,],
... [4., 5., 6., 7, 8],
... [1, 2, -6, -1, 0]]).T)
>>>
p2
Points3D(
[[ 1., 4., 1.],
[ 2., 5., 2.],
[ 3., 6., -6.],
[ 4., 7., -1.],
[ 5., 8., 0.]])
>>>
assert p2.equal(
...
[[ 1., 4., 1.],
...
[ 2., 5., 2.],
...
[ 3., 6., -6.],
...
[ 4., 7., -1.],
...
[ 5., 8., 0.]]
, atol=1e-8
)
>>> p2.transform(tfields.bases.CYLINDER)
>>>
p2
Points3D(
[[ 4.12310563,
1.32581766, 1.
],
[ 5.38516481,
1.19028995, 2.
],
[ 6.70820393,
1.10714872, -6.
],
[ 8.06225775,
1.05165021, -1.
],
[ 9.43398113,
1.01219701, 0.
]]
)
>>>
assert p2.equal(
...
[[ 4.12310563, 1.32581766, 1.],
...
[ 5.38516481, 1.19028995, 2.],
...
[ 6.70820393, 1.10714872, -6.],
...
[ 8.06225775, 1.05165021, -1.],
...
[ 9.43398113, 1.01219701, 0.
]], atol=1e-8
)
Copy constructor with one instance preserves coord_sys of instance
>>> assert tfields.Points3D(p2).coord_sys == p2.coord_sys
Unless you specify other:
>>> tfields.Points3D(p2, coord_sys=tfields.bases.CARTESIAN)
Points3D([[ 1., 4., 1.],
[ 2., 5., 2.],
[ 3., 6., -6.],
[ 4., 7., -1.],
[ 5., 8., 0.]])
>>> assert tfields.Points3D(p2,
... coord_sys=tfields.bases.CARTESIAN).equal(
... [[ 1., 4., 1.],
... [ 2., 5., 2.],
... [ 3., 6., -6.],
... [ 4., 7., -1.],
... [ 5., 8., 0.]], atol=1e-8)
Copy constructor with many instances chooses majority of coordinates
systems to avoid much transformation
>>> tfields.Points3D.merged(p1, p2, p1)
Points3D(
[[ 1., 2., 3.],
[ 4., 5., 6.],
[ 1., 2., -6.],
[ 1., 4., 1.],
[ 2., 5., 2.],
[ 3., 6., -6.],
[ 4., 7., -1.],
[ 5., 8., 0.],
[ 1., 2., 3.],
[ 4., 5., 6.],
[ 1., 2., -6.]])
>>>
assert
tfields.Points3D.merged(p1, p2, p1)
.equal(
...
[[ 1., 2., 3.],
...
[ 4., 5., 6.],
...
[ 1., 2., -6.],
...
[ 1., 4., 1.],
...
[ 2., 5., 2.],
...
[ 3., 6., -6.],
...
[ 4., 7., -1.],
...
[ 5., 8., 0.],
...
[ 1., 2., 3.],
...
[ 4., 5., 6.],
...
[ 1., 2., -6.]]
, atol=1e-8
)
>>> p1.transform(tfields.bases.CYLINDER)
... unless specified other. Here it is specified
>>> tfields.Points3D.merged(p1, p2, coord_sys=tfields.bases.CYLINDER)
Points3D([[ 2.23606798, 1.10714872, 3. ],
[ 6.40312424, 0.89605538, 6. ],
[ 2.23606798, 1.10714872, -6. ],
[ 4.12310563, 1.32581766, 1. ],
[ 5.38516481, 1.19028995, 2. ],
[ 6.70820393, 1.10714872, -6. ],
[ 8.06225775, 1.05165021, -1. ],
[ 9.43398113, 1.01219701, 0. ]])
>>> assert tfields.Points3D.merged(
... p1, p2, coord_sys=tfields.bases.CYLINDER).equal(
... [[ 2.23606798, 1.10714872, 3. ],
... [ 6.40312424, 0.89605538, 6. ],
... [ 2.23606798, 1.10714872, -6. ],
... [ 4.12310563, 1.32581766, 1. ],
... [ 5.38516481, 1.19028995, 2. ],
... [ 6.70820393, 1.10714872, -6. ],
... [ 8.06225775, 1.05165021, -1. ],
... [ 9.43398113, 1.01219701, 0. ]], atol=1e-8)
Shape is always (..., 3)
>>> p = tfields.Points3D([[1., 2., 3.], [4., 5., 6.],
...
...
@@ -109,14 +110,14 @@ class Points3D(tfields.Tensors):
>>> mp = p[mask].copy()
Copy constructor
>>>
mp
Points3D(
[[ 1., 2., 3.],
[ 1., 2., -6.],
[ 0., 1., -1.]])
>>> tfields.Points3D(mp)
Points3D(
[[ 1., 2., 3.],
[ 1., 2., -6.],
[ 0., 1., -1.]])
>>>
assert mp.equal(
...
[[ 1., 2., 3.],
...
[ 1., 2., -6.],
...
[ 0., 1., -1.]])
>>>
assert
tfields.Points3D(mp)
.equal(
...
[[ 1., 2., 3.],
...
[ 1., 2., -6.],
...
[ 0., 1., -1.]])
Coordinate system is implemented. Default is cartesian
>>> p_cart = p.copy()
...
...
@@ -141,10 +142,12 @@ class Points3D(tfields.Tensors):
def
balls
(
self
,
radius
,
spacing
=
(
5
,
3
)):
"""
Builds a sphere around each point with resolution
Args:
radius (float): radius of spheres
spacing (tuple of int): n_phi, n_theta
Returns:
tfields.Mesh3D: Builds a sphere around each point with a resolution
defined by spacing and given radius
"""
sphere
=
tfields
.
Mesh3D
.
grid
((
radius
,
radius
,
1
),
(
-
np
.
pi
,
np
.
pi
,
spacing
[
0
]),
...
...
tfields/triangles3D.py
View file @
d4100705
...
...
@@ -340,11 +340,11 @@ class Triangles3D(tfields.TensorFields):
Examples:
>>> m = tfields.Mesh3D([[0,0,0], [1,0,0], [-1,0,0], [0,1,0], [0,0,1]],
... faces=[[0, 1, 3],[0, 2, 3],[1,2,4], [1, 3, 4]]);
>>> m.triangles().centroids()
Points3D([[ 0.33333333, 0.3333333
3,
0.
],
[-
0.33333333, 0.3333333
3,
0.
],
[ 0.
,
0.
, 0.3333333
3],
[
0.33333333, 0.33333333, 0.3333333
3]])
>>>
assert
m.triangles().centroids()
.equal(
... [[1./3, 1./
3, 0.],
...
[-
1./3, 1./
3, 0.],
...
[0.
, 0.
, 1./
3],
...
[
1./3, 1./3, 1./
3]])
"""
return
self
.
_centroids
...
...
@@ -580,7 +580,8 @@ class Triangles3D(tfields.TensorFields):
if
all
(
~
barycentric_bools
):
return
barycentric_bools
if
min_dist_method
:
orthogonal_acceptance
=
np
.
full
(
barycentric_bools
.
shape
,
False
)
orthogonal_acceptance
=
np
.
full
(
barycentric_bools
.
shape
,
False
,
dtype
=
bool
)
closest_indices
=
np
.
argmin
(
abs
(
w
)[
barycentric_bools
])
# transform the indices to the whole array, not only the
# barycentric_bools selection
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment