v0.9.1
Functions | Variables
convert Namespace Reference

Functions

def print_progress (iteration, total, decimals=1, bar_length=50)
 
def is_not_h5m (file)
 
def is_older_than_vtk (file)
 
def mb_convert (file)
 
def init (l)
 
def filterfalse_comp (fun, file_list)
 

Variables

 parser
 
 help
 
 nargs
 
 type
 
 int
 
 default
 
 args = parser.parse_args()
 
 file_list = list(filterfalse_comp(is_not_h5m, args.file))
 
 N = Value('i', len(file_list))
 
 n = Value('i', 0)
 
 l = mp.Lock()
 
 pool = mp.Pool(processes=args.np, initializer=init, initargs=(l,))
 

Function Documentation

◆ filterfalse_comp()

def convert.filterfalse_comp (   fun,
  file_list 
)

Definition at line 53 of file convert.py.

53 def filterfalse_comp(fun, file_list):
54  try:
55  # Python 3
56  return filterfalse(fun, file_list)
57  except NameError:
58  # Python 2
59  return ifilterfalse(fun, file_list)
60 
def filterfalse_comp(fun, file_list)
Definition: convert.py:53

◆ init()

def convert.init (   l)

Definition at line 49 of file convert.py.

49 def init(l):
50  global lock
51  lock = l
52 
def init(l)
Definition: convert.py:49

◆ is_not_h5m()

def convert.is_not_h5m (   file)

Definition at line 28 of file convert.py.

28 def is_not_h5m(file):
29  return not file.endswith('h5m')
30 
def is_not_h5m(file)
Definition: convert.py:28

◆ is_older_than_vtk()

def convert.is_older_than_vtk (   file)

Definition at line 31 of file convert.py.

31 def is_older_than_vtk(file):
32  file_vtk = path.splitext(file)[0] + ".vtk"
33  if path.exists(file_vtk):
34  return path.getmtime(file) < path.getmtime(file_vtk)
35  return False
36 
def is_older_than_vtk(file)
Definition: convert.py:31

◆ mb_convert()

def convert.mb_convert (   file)

Definition at line 37 of file convert.py.

37 def mb_convert(file):
38  file = path.splitext(file)[0]
39  p = subprocess.Popen(["mbconvert", file + ".h5m", file + ".vtk"],
40  stdout=subprocess.PIPE, stderr=subprocess.PIPE)
41  (out, err) = p.communicate()
42  lock.acquire()
43  if p.returncode:
44  print('\n' + err.decode())
45  n.value += 1
46  print_progress(n.value, N.value)
47  lock.release()
48 
def mb_convert(file)
Definition: convert.py:37
def print_progress(iteration, total, decimals=1, bar_length=50)
Definition: convert.py:18

◆ print_progress()

def convert.print_progress (   iteration,
  total,
  decimals = 1,
  bar_length = 50 
)

Definition at line 18 of file convert.py.

18 def print_progress(iteration, total, decimals=1, bar_length=50):
19  str_format = "{0:." + str(decimals) + "f}"
20  percents = str_format.format(100 * (iteration / float(total)))
21  filled_length = int(round(bar_length * iteration / float(total)))
22  bar = '█' * filled_length + '-' * (bar_length - filled_length)
23 
24  sys.stdout.write('\r |%s| %s%s (%s of %s)' %
25  (bar, percents, '%', str(iteration), str(total)))
26  sys.stdout.flush()
27 
def print_progress(iteration, total, decimals=1, bar_length=50)
Definition: convert.py:18

Variable Documentation

◆ args

convert.args = parser.parse_args()

Definition at line 67 of file convert.py.

◆ default

convert.default

Definition at line 66 of file convert.py.

◆ file_list

convert.file_list = list(filterfalse_comp(is_not_h5m, args.file))

Definition at line 69 of file convert.py.

◆ help

convert.help

Definition at line 65 of file convert.py.

◆ int

convert.int

◆ l

convert.l = mp.Lock()

Definition at line 82 of file convert.py.

◆ N

convert.N = Value('i', len(file_list))

Definition at line 79 of file convert.py.

◆ n

convert.n = Value('i', 0)

Definition at line 80 of file convert.py.

◆ nargs

convert.nargs

Definition at line 65 of file convert.py.

◆ parser

convert.parser
Initial value:
1 = argparse.ArgumentParser(
2  description="Convert multiple h5m files to vtk using mbconvert and multiprocessing")

Definition at line 62 of file convert.py.

◆ pool

convert.pool = mp.Pool(processes=args.np, initializer=init, initargs=(l,))

Definition at line 83 of file convert.py.

◆ type

convert.type