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
bd352e6e
Commit
bd352e6e
authored
Oct 23, 2020
by
dboe
Browse files
core is lintfree
parent
f22b88c5
Changes
1
Hide whitespace changes
Inline
Side-by-side
tfields/core.py
View file @
bd352e6e
...
...
@@ -8,7 +8,7 @@ core of tfields library
contains numpy ndarray derived bases of the tfields package
Notes:
It could be worthwhile concidering `np.li.mixins.NDArrayOperatorsMixin ...
*
It could be worthwhile concidering `np.li.mixins.NDArrayOperatorsMixin ...
<https://docs.scipy.org/doc/numpy-1.15.1/reference/generated/...
... numpy.lib.mixins.NDArrayOperatorsMixin.html>`_
"""
...
...
@@ -250,9 +250,11 @@ class AbstractObject(object): # pylint: disable=useless-object-inheritance
# Found under nt. ???
obj_type
=
obj_type
.
decode
(
"UTF-8"
)
obj_type
=
getattr
(
tfields
,
obj_type
)
attr_value
=
obj_type
.
_from_dict
(
here
[
attr
][
key
]
)
# noqa: E501 pylint: disable=protected-access
attr_value
=
(
obj_type
.
_from_dict
(
# pylint: disable=protected-access
here
[
attr
][
key
]
)
)
else
:
# if len(here[attr][key]) == 1:
attr_value
=
here
[
attr
][
key
].
pop
(
""
)
here
[
attr
][
key
]
=
attr_value
...
...
@@ -303,12 +305,14 @@ class AbstractObject(object): # pylint: disable=useless-object-inheritance
bulk_type
=
bulk_type
.
decode
(
"UTF-8"
)
bulk_type
=
getattr
(
tfields
,
bulk_type
)
list_dict
[
key
].
append
(
bulk_type
.
_from_dict_legacy
(
**
sub_dict
[
index
])
)
# noqa: E501 pylint: disable=protected-access
bulk_type
.
_from_dict_legacy
(
**
sub_dict
[
index
]
)
# noqa: E501 pylint: disable=protected-access
)
with
cls
.
_bypass_setters
(
with
cls
.
_bypass_setters
(
# pylint: disable=protected-access,no-member
"fields"
,
demand_existence
=
False
):
# noqa: E501 pylint: disable=protected-access,no-member
):
# Build the normal way
bulk
=
kwargs
.
pop
(
"bulk"
)
bulk_type
=
kwargs
.
pop
(
"bulk_type"
)
...
...
@@ -366,9 +370,9 @@ class AbstractNdarray(np.ndarray, AbstractObject):
setattr
(
self
,
attr
,
getattr
(
obj
,
attr
,
None
))
def
__array_wrap__
(
self
,
out_arr
,
context
=
None
):
# pylint: disable=arguments-differ
return
np
.
ndarray
.
__array_wrap__
(
return
np
.
ndarray
.
__array_wrap__
(
# pylint: disable=too-many-function-args
self
,
out_arr
,
context
)
# noqa: E501 pylint: disable=too-many-function-args
)
@
classmethod
def
_iter_slots
(
cls
):
...
...
@@ -1047,8 +1051,11 @@ class Tensors(AbstractNdarray): # pylint: disable=too-many-public-methods
"""
# scalars empty already there
if
(
self
.
rank
==
0
or
self
.
shape
[
0
]
==
0
or
self
.
coord_sys
==
coord_sys
):
# noqa: E501 pylint: disable=access-member-before-definition
self
.
rank
==
0
or
self
.
shape
[
0
]
==
0
or
self
.
coord_sys
==
coord_sys
# noqa: E501 pylint: disable=access-member-before-definition
):
self
.
coord_sys
=
coord_sys
# pylint: disable=attribute-defined-outside-init
return
...
...
@@ -1339,9 +1346,9 @@ class Tensors(AbstractNdarray): # pylint: disable=too-many-public-methods
"""
with
other
.
tmp_transform
(
self
.
coord_sys
):
# balanced_tree option gives huge speedup!
kd_tree
=
scipy
.
spatial
.
cKDTree
(
kd_tree
=
scipy
.
spatial
.
cKDTree
(
# noqa: E501 pylint: disable=no-member
other
,
1000
,
balanced_tree
=
False
)
# noqa: E501 pylint: disable=no-member
)
res
=
kd_tree
.
query
(
self
,
**
kwargs
)
array
=
res
[
1
]
...
...
@@ -1906,9 +1913,9 @@ class TensorFields(Tensors):
@
classmethod
def
merged
(
cls
,
*
objects
,
**
kwargs
):
if
not
all
([
isinstance
(
o
,
cls
)
for
o
in
objects
]):
types
=
[
types
=
[
# pylint: disable=possibly-unused-variable
type
(
o
)
for
o
in
objects
]
# pylint: disable=possibly-unused-variable
]
# Note: could allow if all map_fields are none
raise
TypeError
(
"Merge constructor only accepts {cls} instances."
...
...
@@ -2016,9 +2023,9 @@ class TensorFields(Tensors):
"different dimension. No coord_sys check performed."
)
if
field
.
dim
<=
3
:
artist
=
rna
.
plotting
.
plot_tensor_field
(
artist
=
rna
.
plotting
.
plot_tensor_field
(
# noqa: E501 pylint: disable=no-member
self
,
field
,
**
kwargs
)
# noqa: E501 pylint: disable=no-member
)
else
:
raise
NotImplementedError
(
"Field of dimension {field.dim}"
.
format
(
**
locals
())
...
...
@@ -2282,7 +2289,7 @@ class TensorMaps(TensorFields):
"""
item
=
super
(
TensorMaps
,
self
).
__getitem__
(
index
)
if
issubclass
(
type
(
item
),
TensorMaps
):
if
issubclass
(
type
(
item
),
TensorMaps
):
# pylint: disable=too-many-nested-blocks
if
isinstance
(
index
,
tuple
):
index
=
index
[
0
]
if
item
.
maps
:
...
...
@@ -2299,9 +2306,9 @@ class TensorMaps(TensorFields):
map_delete_mask
=
np
.
full
(
(
len
(
self
.
maps
[
map_dim
]),),
False
,
dtype
=
bool
)
for
i
,
mp
in
enumerate
(
for
i
,
mp
in
enumerate
(
# pylint: disable=invalid-name
self
.
maps
[
map_dim
]
):
# pylint: disable=invalid-name
):
for
node_index
in
mp
:
if
node_index
in
delete_indices
:
map_delete_mask
[
i
]
=
True
...
...
@@ -2320,7 +2327,9 @@ class TensorMaps(TensorFields):
return
item
@
classmethod
def
merged
(
cls
,
*
objects
,
**
kwargs
):
def
merged
(
cls
,
*
objects
,
**
kwargs
):
# pylint: disable=too-many-locals,too-many-branches
if
not
all
([
isinstance
(
o
,
cls
)
for
o
in
objects
]):
# Note: could allow if all face_fields are none
raise
TypeError
(
...
...
@@ -2356,9 +2365,9 @@ class TensorMaps(TensorFields):
)
if
return_templates
:
(
mp
,
mp
,
# pylint: disable=invalid-name
dimension_map_templates
,
)
=
return_value
# pylint: disable=invalid-name
)
=
return_value
for
i
in
range
(
len
(
objects
)):
template_maps_list
[
i
].
append
(
(
dimension
,
dimension_map_templates
[
i
])
...
...
@@ -2421,14 +2430,14 @@ class TensorMaps(TensorFields):
index_lut
=
np
.
full
(
len
(
self
),
np
.
nan
)
# float type
index_lut
[
template
.
fields
[
0
]]
=
np
.
arange
(
len
(
template
.
fields
[
0
]))
for
mp_dim
,
mp
in
self
.
maps
.
items
():
# pylint: disable=invalid-name
mp
=
mp
.
_cut_template
(
mp
=
mp
.
_cut_template
(
# pylint: disable=invalid-name,protected-access
template
.
maps
[
mp_dim
]
)
# noqa: E501 pylint: disable=invalid-name,protected-access
)
if
template
.
fields
:
# correct
mp
=
Maps
.
to_map
(
mp
=
Maps
.
to_map
(
# pylint: disable=invalid-name
index_lut
[
mp
],
*
mp
.
fields
)
# pylint: disable=invalid-name
)
inst
.
maps
[
mp_dim
]
=
mp
return
inst
...
...
@@ -2524,7 +2533,7 @@ class TensorMaps(TensorFields):
# map
remove_mask
=
self
.
stale
()
inst
=
self
.
removed
(
remove_mask
)
if
duplicates
:
if
duplicates
:
# pylint: disable=too-many-nested-blocks
# remove duplicates in order to not have any artificial separations
if
not
stale
:
# we have not yet made a copy but want to work on inst
...
...
@@ -2539,9 +2548,9 @@ class TensorMaps(TensorFields):
# self.maps in case stale vertices where removed
for
map_dim
in
inst
.
maps
:
for
face_index
in
range
(
len
(
inst
.
maps
[
map_dim
])):
# face index
mp
=
np
.
array
(
mp
=
np
.
array
(
# noqa: E501 pylint: disable=invalid-name
inst
.
maps
[
map_dim
],
dtype
=
int
)
# noqa: E501 pylint: disable=invalid-name
)
if
tensor_index
in
mp
[
face_index
]:
index
=
tfields
.
lib
.
util
.
index
(
mp
[
face_index
],
tensor_index
...
...
@@ -2669,7 +2678,9 @@ class TensorMaps(TensorFields):
maps_list
=
tfields
.
lib
.
sets
.
disjoint_group_indices
(
self
.
maps
[
map_dim
])
return
(
map_dim
,
maps_list
)
def
paths
(
self
,
map_dim
):
def
paths
(
self
,
map_dim
):
# noqa: E501 pylint: disable=too-many-locals,too-many-branches,too-many-statements
"""
Find the minimal amount of graphs building the original graph with
maximum of two links per node i.e.
...
...
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