Mercurial > repos > imgteam > imagej2_find_maxima
annotate imagej2_bunwarpj_compose_raw.py @ 0:2395ccf9ccc1 draft default tip
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
| author | imgteam | 
|---|---|
| date | Tue, 17 Sep 2019 16:57:59 -0400 | 
| parents | |
| children | 
| rev | line source | 
|---|---|
| 
0
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
1 #!/usr/bin/env python | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
2 import argparse | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
3 import subprocess | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
4 import tempfile | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
5 import imagej2_base_utils | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
6 | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
7 # Parse Command Line. | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
8 parser = argparse.ArgumentParser() | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
9 parser.add_argument( '--source_image', dest='source_image', help='Source image' ) | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
10 parser.add_argument( '--source_image_format', dest='source_image_format', help='Source image format' ) | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
11 parser.add_argument( '--target_image', dest='target_image', help='Target image' ) | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
12 parser.add_argument( '--target_image_format', dest='target_image_format', help='Target image format' ) | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
13 parser.add_argument( '--source_raw_transformation', dest='source_raw_transformation', help='Direct source transformation matrix' ) | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
14 parser.add_argument( '--target_raw_transformation', dest='target_raw_transformation', help='Inverse target transformation matrix' ) | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
15 parser.add_argument( '--output', dest='output', help='Warping index' ) | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
16 | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
17 args = parser.parse_args() | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
18 | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
19 tmp_dir = imagej2_base_utils.get_temp_dir() | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
20 source_image_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.source_image, args.source_image_format ) | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
21 target_image_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.target_image, args.target_image_format ) | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
22 source_raw_transformation_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.source_raw_transformation, 'txt' ) | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
23 target_raw_transformation_path = imagej2_base_utils.get_input_image_path( tmp_dir, args.target_raw_transformation, 'txt' ) | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
24 | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
25 # Define command response buffers. | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
26 tmp_out = tempfile.NamedTemporaryFile().name | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
27 tmp_stdout = open( tmp_out, 'wb' ) | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
28 tmp_err = tempfile.NamedTemporaryFile().name | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
29 tmp_stderr = open( tmp_err, 'wb' ) | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
30 | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
31 # Build the command line to compose the two raw transformations. | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
32 cmd = imagej2_base_utils.get_base_cmd_bunwarpj( None ) | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
33 if cmd is None: | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
34 imagej2_base_utils.stop_err( "bUnwarpJ not found!" ) | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
35 cmd += ' -compose_raw' | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
36 # Target is sent before source. | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
37 cmd += ' %s' % target_image_path | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
38 cmd += ' %s' % source_image_path | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
39 cmd += ' %s' % target_raw_transformation_path | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
40 cmd += ' %s' % source_raw_transformation_path | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
41 cmd += ' %s' % args.output | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
42 | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
43 # Compose the two raw transformations into another raw transformation using bUnwarpJ. | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
44 proc = subprocess.Popen( args=cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True ) | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
45 rc = proc.wait() | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
46 if rc != 0: | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
47 error_message = imagej2_base_utils.get_stderr_exception( tmp_err, tmp_stderr, tmp_out, tmp_stdout ) | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
48 imagej2_base_utils.stop_err( error_message ) | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
49 | 
| 
 
2395ccf9ccc1
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/image_processing/imagej2 commit b08f0e6d1546caaf627b21f8c94044285d5d5b9c-dirty"
 
imgteam 
parents:  
diff
changeset
 | 
50 imagej2_base_utils.cleanup_before_exit( tmp_dir ) | 
