Mercurial > repos > iuc > icqsol_rotate_shape
comparison icqsol_utils.py @ 0:f63d4da328a3 draft default tip
Uploaded
author | iuc |
---|---|
date | Tue, 23 Aug 2016 15:02:48 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f63d4da328a3 |
---|---|
1 import os | |
2 import sys | |
3 import tempfile | |
4 | |
5 from icqsol.shapes.icqShapeManager import ShapeManager | |
6 from icqsol.bem.icqLaplaceSolver import LaplaceSolver | |
7 | |
8 PLY = 'ply' | |
9 POLYDATA = 'POLYDATA' | |
10 VTK = 'vtk' | |
11 | |
12 | |
13 def asbool(val): | |
14 return str(val).lower() in ['yes', 'true'] | |
15 | |
16 | |
17 def get_format_and_type(galaxy_ext): | |
18 # Define the output file format and type. | |
19 format = None | |
20 datatype = None | |
21 if galaxy_ext in ['vtkascii', 'vtkbinary']: | |
22 format = VTK | |
23 elif galaxy_ext in ['plyascii', 'plybinary']: | |
24 format = PLY | |
25 if galaxy_ext in ['vtkascii', 'plyascii']: | |
26 datatype = 'ascii' | |
27 elif galaxy_ext in ['vtkbinary', 'plybinary']: | |
28 datatype = 'binary' | |
29 return format, datatype | |
30 | |
31 | |
32 def get_input_file_path(tmp_dir, input_file, format): | |
33 """ | |
34 iCqSol uses file extensions (e.g., .ply, .vtk) when reading and | |
35 writing files, so the Galaxy dataset naming convention of | |
36 setting all file extensions as .dat must be handled. | |
37 """ | |
38 file_path = get_temporary_file_path(tmp_dir, format) | |
39 # Remove the file so we can create a symlink. | |
40 os.remove(file_path) | |
41 os.symlink(input_file, file_path) | |
42 return file_path | |
43 | |
44 | |
45 def get_laplace_solver(shape_data, max_edge_length=float('inf')): | |
46 return LaplaceSolver(shape_data, max_edge_length=max_edge_length) | |
47 | |
48 | |
49 def get_shape_manager(format=None, dataset_type=None): | |
50 # Instantiate a ShapeManager. | |
51 return ShapeManager(file_format=format, vtk_dataset_type=dataset_type) | |
52 | |
53 | |
54 def get_temp_dir(prefix='tmp-vtk-', dir=None): | |
55 """ | |
56 Return a temporary directory. | |
57 """ | |
58 return tempfile.mkdtemp(prefix=prefix, dir=dir) | |
59 | |
60 | |
61 def get_tempfilename(dir=None, suffix=None): | |
62 """ | |
63 Return a temporary file name. | |
64 """ | |
65 if suffix is None: | |
66 s = None | |
67 elif suffix.startswith('.'): | |
68 s = suffix | |
69 else: | |
70 s = '.%s' % suffix | |
71 fd, name = tempfile.mkstemp(suffix=s, dir=dir) | |
72 os.close(fd) | |
73 return name | |
74 | |
75 | |
76 def get_temporary_file_path(tmp_dir, file_extension): | |
77 """ | |
78 Return the path to a temporary file with a valid VTK format | |
79 file extension. | |
80 """ | |
81 return get_tempfilename(tmp_dir, file_extension) | |
82 | |
83 | |
84 def stop_err(msg): | |
85 sys.stderr.write("%s\n" % msg) | |
86 sys.exit() |