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
c1b3129b
Commit
c1b3129b
authored
Nov 05, 2018
by
Daniel Boeckenhoff
Browse files
added mkdir to library
parent
183fdd53
Pipeline
#38856
failed with stages
in 16 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
tfields/__main__.py
View file @
c1b3129b
...
...
@@ -25,7 +25,7 @@ def load_unittests(loader=None, suite=None):
parent
=
pathlib
.
Path
(
__file__
).
parent
.
parent
for
f
in
list
(
parent
.
glob
(
'*/test*.py'
)):
sys
.
path
.
insert
(
0
,
str
(
f
.
parent
))
mod
=
__import__
(
f
.
name
.
rstrip
(
'.py'
)
)
mod
=
__import__
(
f
.
name
[:
-
3
]
)
for
test
in
loader
.
loadTestsFromModule
(
mod
):
suite
.
addTests
(
test
)
sys
.
path
.
remove
(
str
(
f
.
parent
))
...
...
tfields/lib/in_out.py
View file @
c1b3129b
...
...
@@ -6,6 +6,7 @@ import shutil
import
subprocess
import
contextlib
import
logging
from
pathlib
import
Path
def
resolve
(
path
):
...
...
@@ -25,6 +26,7 @@ def resolve(path):
Also resolves symlincs which i will not test.
"""
# py27 pathlib.Path has no expanduser
# return str(Path(path).expanduser().resolve())
# resolve: relative paths, symlinks and ~
return
os
.
path
.
realpath
(
os
.
path
.
abspath
(
os
.
path
.
expanduser
(
path
)))
...
...
@@ -121,18 +123,40 @@ def ls(directory, recursive=False):
return
os
.
listdir
(
resolve
(
directory
))
def
dir
_structure
(
fileDir
):
def
mk
dir
(
path
,
isDir
=
False
):
"""
Creates a nested dictionary that represents the folder structure of fileDir
Notes:
if you want to create a dir, add '/' behind path or use isDir=True
Args:
path (str): directory or path to create.
isDir (str): tell mkdir that you are explicitly giving a directory.
"""
log
=
logging
.
getLogger
()
path
=
resolve
(
path
)
if
isDir
:
directory
=
path
else
:
directory
=
os
.
path
.
dirname
(
path
)
if
not
os
.
path
.
exists
(
directory
)
and
not
directory
==
''
:
log
.
info
(
"Create directory {0}"
.
format
(
directory
))
os
.
makedirs
(
directory
)
else
:
log
.
warning
(
"Directory {0} already exists"
.
format
(
directory
))
def
dir_structure
(
directory
):
"""
Creates a nested dictionary that represents the folder structure of
directory
"""
directory
=
{}
fileDir
=
fileDir
.
rstrip
(
os
.
sep
)
start
=
fileDir
.
rfind
(
os
.
sep
)
+
1
for
path
,
dirs
,
files
in
os
.
walk
(
fileDir
):
directory
=
directory
.
rstrip
(
os
.
sep
)
start
=
directory
.
rfind
(
os
.
sep
)
+
1
for
path
,
dirs
,
files
in
os
.
walk
(
directory
):
folders
=
path
[
start
:].
split
(
os
.
sep
)
subdir
=
dict
.
fromkeys
(
files
)
parent
=
reduce
(
dict
.
get
,
folders
[:
-
1
],
directory
)
parent
[
folders
[
-
1
]]
=
subdir
if
len
(
directory
)
==
0
:
return
{}
return
directory
[
directory
.
keys
()[
0
]]
# first entry is always
fileDir
return
directory
[
directory
.
keys
()[
0
]]
# first entry is always
directory
tfields/lib/sets.py
View file @
c1b3129b
...
...
@@ -3,7 +3,6 @@ Algorithms around set operations
"""
import
numpy
as
np
import
tfields
import
logging
class
UnionFind
(
object
):
...
...
@@ -101,11 +100,9 @@ class UnionFind(object):
Build unions for whole iterators of any size
"""
self
.
insert_objects
(
tfields
.
lib
.
util
.
flatten
(
iterator
))
log
=
logging
.
getLogger
(
"UnionFind.__call__"
)
i
=
0
n
=
len
(
iterator
)
for
item
in
iterator
:
log
.
info
(
"Step {i} / n"
)
for
i1
,
i2
in
tfields
.
lib
.
util
.
pairwise
(
item
):
self
.
union
(
i1
,
i2
)
i
+=
1
...
...
tfields/mesh3D.py
View file @
c1b3129b
...
...
@@ -700,7 +700,7 @@ class Mesh3D(tfields.TensorMaps):
for
i
,
face
in
enumerate
(
inst
.
maps
[
0
]):
"""
vertices_rejected is a mask for each face that is True, where
a
P
oint is on the rejected side of the plane
a
p
oint is on the rejected side of the plane
"""
vertices_rejected
=
[
~
mask
[
f
]
for
f
in
face
]
if
any
(
vertices_rejected
):
...
...
tfields/plotting/mpl.py
View file @
c1b3129b
...
...
@@ -49,6 +49,14 @@ def upgrade_style(style, source, dest=None):
source (str): full path to mplstyle file to use
dest (str): local directory to copy the file to. Matpotlib has to
search this directory for mplstyle files!
Examples:
>>> import tfields
>>> import os
>>> tfields.plotting.upgrade_style(
... 'tfields',
... os.path.join(os.path.dirname(tfields.plotting.__file__),
... 'tfields.mplstyle'))
"""
if
dest
is
None
:
dest
=
mpl
.
get_configdir
()
...
...
tfields/plotting/tfields.mplstyle
View file @
c1b3129b
...
...
@@ -33,7 +33,7 @@ image.cmap: viridis
# LATEX / LaTeX / latex
text.usetex : True
font.family :
'
serif
'
font.family : serif
font.size : 40 # 20 was a duplicate definition
# mathtext.fontset = 'custom'
# mathtext.rm = 'Bitstream Vera Sans'
...
...
Write
Preview
Supports
Markdown
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