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