generated from FNNDSC/python-chrisapp-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_tetra_wrapper.py
executable file
·71 lines (56 loc) · 2.24 KB
/
create_tetra_wrapper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python
import sys
from pathlib import Path
from argparse import ArgumentParser, Namespace, ArgumentDefaultsHelpFormatter
from importlib.metadata import Distribution
import subprocess as sp
import shlex
import functools
from chris_plugin import chris_plugin
__pkg = Distribution.from_name(__package__)
__version__ = __pkg.version
DISPLAY_TITLE = r"""
_ _ _
| | | | | |
___ _ __ ___ __ _| |_ ___ | |_ ___| |_ _ __ __ _
/ __| '__/ _ \/ _` | __/ _ \| __/ _ \ __| '__/ _` |
| (__| | | __/ (_| | || __/| || __/ |_| | | (_| |
\___|_| \___|\__,_|\__\___| \__\___|\__|_| \__,_|
______
|______|
"""
parser = ArgumentParser(description='A ChRIS fs plugin wrapper for create_tetra',
formatter_class=ArgumentDefaultsHelpFormatter)
parser.add_argument('-c', '--center', default='0,0,0', type=str,
help='center of sphere')
parser.add_argument('-r', '--radius', default='1,1,1', type=str,
help='radius of sphere')
parser.add_argument('-t', '--triangles', default=81920, type=int,
help='number of triangles')
parser.add_argument('-o', '--output', default='sphere_81920.obj',
help='output file name')
parser.add_argument('-V', '--version', action='version',
version=f'%(prog)s {__version__}')
@chris_plugin(
parser=parser,
title='create_tetra',
category='Modeling',
min_memory_limit='100Mi',
min_cpu_limit='1000m',
min_gpu_limit=0
)
def main(options: Namespace, outputdir: Path):
print(DISPLAY_TITLE, file=sys.stderr)
create_tetra = ('create_tetra',)
filename = (outputdir / options.output,)
center = parse_triplet(options.center)
radius = parse_triplet(options.radius)
n_triangles = (str(options.triangles),)
cmd = functools.reduce(lambda l, r: l + r, (create_tetra, filename, center, radius, n_triangles))
print('$> ' + shlex.join(map(str, cmd)), file=sys.stderr)
sp.run(cmd, check=True)
def parse_triplet(s: str) -> tuple[str, str, str]:
x, y, z = s.split(',')
return x, y, z
if __name__ == '__main__':
main()