Skip to content
GitLab
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
03cc96cd
Commit
03cc96cd
authored
Aug 07, 2018
by
Daniel Boeckenhoff
Browse files
before publishing. especially saving npz neat now
parent
31f2b698
Changes
7
Hide whitespace changes
Inline
Side-by-side
tfields/__init__.py
View file @
03cc96cd
__version__
=
'0.1.0.dev
5
'
__version__
=
'0.1.0.dev
6
'
__author__
=
"Daniel Boeckenhoff"
__email__
=
"daniel.boeckenhoff@ipp.mpg.de"
...
...
tfields/bases/bases.py
View file @
03cc96cd
...
...
@@ -42,13 +42,13 @@ def get_coord_system_name(base):
str: name of base
"""
if
isinstance
(
base
,
sympy
.
diffgeom
.
CoordSystem
):
base
=
str
(
getattr
(
base
,
'name'
)
)
base
=
getattr
(
base
,
'name'
)
# if not (isinstance(base, string_types) or base is None):
# baseType = type(base)
# raise ValueError("Coordinate system must be string_type."
# " Retrieved value '{base}' of type {baseType}."
# .format(**locals()))
return
base
return
str
(
base
)
def
lambdifiedTrafo
(
base_old
,
base_new
):
...
...
tfields/core.py
View file @
03cc96cd
...
...
@@ -277,9 +277,11 @@ class AbstractNdarray(np.ndarray):
>>> _ = out_file_maps.seek(0)
>>> m1 = tfields.TensorMaps.load(out_file_maps.name)
>>> assert m.equal(m1)
>>> assert m.maps[0].dtype == m1.maps[0].dtype
"""
np
.
savez
(
path
,
**
self
.
_as_dict
())
content_dict
=
self
.
_as_dict
()
np
.
savez
(
path
,
**
content_dict
)
@
classmethod
def
_load_npz
(
cls
,
path
,
**
load_kwargs
):
...
...
@@ -454,7 +456,10 @@ class Tensors(AbstractNdarray):
dtype
=
tensors
.
dtype
else
:
if
dtype
is
None
:
dtype
=
np
.
float64
if
hasattr
(
tensors
,
'dtype'
):
dtype
=
tensors
.
dtype
else
:
dtype
=
np
.
float64
''' demand iterable structure '''
try
:
...
...
@@ -980,7 +985,7 @@ class Tensors(AbstractNdarray):
"""
coords
=
sympy
.
symbols
(
'x y z'
)
with
self
.
tmp_transform
(
coord_sys
or
self
.
coord_sys
):
mask
=
tfields
.
evalf
(
self
,
expression
,
coords
=
coords
)
mask
=
tfields
.
evalf
(
np
.
array
(
self
)
,
expression
,
coords
=
coords
)
return
mask
def
cut
(
self
,
expression
,
coord_sys
=
None
):
...
...
@@ -1087,7 +1092,7 @@ class Tensors(AbstractNdarray):
return
d
[
d
>
0
].
reshape
(
d
.
shape
[
0
],
-
1
).
min
(
axis
=
1
)
except
MemoryError
:
min_dists
=
np
.
empty
(
self
.
shape
[
0
])
for
i
,
point
in
enumerate
(
other
):
for
i
,
point
in
enumerate
(
np
.
array
(
other
)
)
:
d
=
self
.
distances
([
point
],
**
kwargs
)
min_dists
[
i
]
=
d
[
d
>
0
].
reshape
(
-
1
).
min
()
return
min_dists
...
...
@@ -1762,7 +1767,7 @@ class TensorMaps(TensorFields):
indices
=
np
.
array
(
range
(
len
(
self
)))
keep_indices
=
indices
[
mask
]
if
isinstance
(
keep_indices
,
int
):
keep_indices
=
[
keep_indices
]
keep_indices
=
np
.
array
(
[
keep_indices
]
)
delete_indices
=
set
(
indices
.
flat
).
difference
(
set
(
keep_indices
.
flat
))
masks
=
[]
...
...
@@ -1832,5 +1837,6 @@ class TensorMaps(TensorFields):
if
__name__
==
'__main__'
:
# pragma: no cover
import
doctest
doctest
.
testmod
()
# doctest.run_docstring_examples(Tensors._save_npz, globals())
# doctest.run_docstring_examples(TensorMaps.cut, globals())
# doctest.run_docstring_examples(AbstractNdarray._save_npz, globals())
tfields/lib/util.py
View file @
03cc96cd
...
...
@@ -57,10 +57,12 @@ def flatten(seq, container=None, keep_types=None):
def
multi_sort
(
array
,
*
others
,
**
kwargs
):
"""
Sort both lists with list 1
Sort all given lists parralel with array sorting, ie rearrange the items in
the other lists in the same way, you rearrange them for array due to array
sorting
Args:
array
*others
array
(list)
*others
(list)
**kwargs:
method (function): sorting function. Default is 'sorted'
...: further arguments are passed to method. Default rest is
...
...
tfields/plotting/__init__.py
View file @
03cc96cd
...
...
@@ -206,12 +206,12 @@ class PlotOptions(object):
else
:
return
self
.
pop
(
attr
,
default
)
def
retrieve
C
hain
(
self
,
*
args
,
**
kwargs
):
def
retrieve
_c
hain
(
self
,
*
args
,
**
kwargs
):
default
=
kwargs
.
pop
(
'default'
,
None
)
keep
=
kwargs
.
pop
(
'keep'
,
True
)
if
len
(
args
)
>
1
:
return
self
.
retrieve
(
args
[
0
],
self
.
retrieve
C
hain
(
*
args
[
1
:],
self
.
retrieve
_c
hain
(
*
args
[
1
:],
default
=
default
,
keep
=
keep
),
keep
=
keep
)
...
...
tfields/plotting/mpl.py
View file @
03cc96cd
...
...
@@ -191,6 +191,8 @@ def plot_mesh(vertices, faces, **kwargs):
vmin
vmax
"""
vertices
=
np
.
array
(
vertices
)
faces
=
np
.
array
(
faces
)
if
faces
.
shape
[
0
]
==
0
:
warnings
.
warn
(
"No faces to plot"
)
return
None
...
...
@@ -201,9 +203,9 @@ def plot_mesh(vertices, faces, **kwargs):
full
=
True
mesh
=
tfields
.
Mesh3D
(
vertices
,
faces
=
faces
)
xAxis
,
yAxis
,
zAxis
=
po
.
getXYZAxis
()
facecolors
=
po
.
retrieve
C
hain
(
'facecolors'
,
'color'
,
default
=
0
,
keep
=
False
)
facecolors
=
po
.
retrieve
_c
hain
(
'facecolors'
,
'color'
,
default
=
0
,
keep
=
False
)
if
full
:
# implementation that will sort the triangles by zAxis
centroids
=
mesh
.
centroids
()
...
...
@@ -212,8 +214,13 @@ def plot_mesh(vertices, faces, **kwargs):
axesIndices
.
pop
(
axesIndices
.
index
(
yAxis
))
zAxis
=
axesIndices
[
0
]
zs
=
centroids
[:,
zAxis
]
zs
,
faces
,
facecolors
=
tfields
.
lib
.
util
.
multi_sort
(
zs
,
faces
,
facecolors
)
try
:
iter
(
facecolors
)
zs
,
faces
,
facecolors
=
tfields
.
lib
.
util
.
multi_sort
(
zs
,
faces
,
facecolors
)
except
TypeError
:
zs
,
faces
=
tfields
.
lib
.
util
.
multi_sort
(
zs
,
faces
)
nFacesInitial
=
len
(
faces
)
else
:
# cut away "back sides" implementation
...
...
@@ -246,9 +253,9 @@ def plot_mesh(vertices, faces, **kwargs):
artist
=
plot_array
(
vertices
,
**
d
)
elif
po
.
dim
==
3
:
label
=
po
.
pop
(
'label'
,
None
)
color
=
po
.
retrieve
C
hain
(
'color'
,
'c'
,
'facecolors'
,
default
=
'grey'
,
keep
=
False
)
color
=
po
.
retrieve
_c
hain
(
'color'
,
'c'
,
'facecolors'
,
default
=
'grey'
,
keep
=
False
)
color
=
po
.
formatColors
(
color
,
fmt
=
'rgba'
,
length
=
len
(
faces
))
...
...
tfields/triangles3D.py
View file @
03cc96cd
...
...
@@ -488,7 +488,6 @@ class Triangles3D(tfields.TensorFields):
not invertable matrices the you will always get False
>>> m3 = tfields.Mesh3D([[0,0,0], [2,0,0], [4,0,0], [0,1,0]],
... faces=[[0, 1, 2], [0, 1, 3]]);
>>> import pytest
>>> mask = m3.triangles()._in_triangles(np.array([0.2, 0.2, 0]), delta=0.3)
>>> assert np.array_equal(mask,
... np.array([False, True], dtype=bool))
...
...
@@ -550,7 +549,7 @@ class Triangles3D(tfields.TensorFields):
For Example, if you want to know the number of points in one
face, just do:
>> tris.in_triangles(poits).sum(axis=0)
>> tris.in_triangles(poits).sum(axis=0)
[face_index]
"""
if
self
.
ntriangles
()
==
0
:
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment