changeset 68:ba5866d0251d draft

"planemo upload for repository https://github.com/rolfverberg/galaxytools commit 3fde3e85030608a8a4d8e59308353b0144314dfe"
author rv43
date Fri, 19 Aug 2022 20:16:56 +0000
parents 87a4acead65c
children fba792d5f83b
files general.py tomo_combine.py tomo_combine.xml tomo_find_center.py tomo_find_center.xml tomo_macros.xml tomo_reconstruct.py tomo_reconstruct.xml tomo_setup.py tomo_setup.xml
diffstat 10 files changed, 65 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/general.py	Thu Aug 18 15:40:59 2022 +0000
+++ b/general.py	Fri Aug 19 20:16:56 2022 +0000
@@ -739,7 +739,7 @@
     # Find available index range
     if filetype == 'tif':
         if not isinstance(path, str) or not os.path.isdir(path):
-            illegal_value(path, 'path', 'findImageRange')
+            illegal_value(path, 'path', 'findImageFiles')
             return -1, 0, []
         indexRegex = re.compile(r'\d+')
         # At this point only tiffs
@@ -762,7 +762,7 @@
         paths = [os.path.join(path, f) for f in files]
     elif filetype == 'h5':
         if not isinstance(path, str) or not os.path.isfile(path):
-            illegal_value(path, 'path', 'findImageRange')
+            illegal_value(path, 'path', 'findImageFiles')
             return -1, 0, []
         # At this point only h5 in alamo2 detector style
         first_index = 0
@@ -771,7 +771,7 @@
             last_index = num_imgs-1
         paths = [path]
     else:
-        illegal_value(filetype, 'filetype', 'findImageRange')
+        illegal_value(filetype, 'filetype', 'findImageFiles')
         return -1, 0, []
     logging.debug('\nNumber of available'+name+f'images: {num_imgs}')
     logging.debug('Index range of available'+name+f'images: [{first_index}, '+
--- a/tomo_combine.py	Thu Aug 18 15:40:59 2022 +0000
+++ b/tomo_combine.py	Fri Aug 19 20:16:56 2022 +0000
@@ -45,8 +45,8 @@
     logging.basicConfig(format=logging_format, level=level, force=True,
             handlers=[logging.StreamHandler()])
 
+    logging.debug(f'config = {args.config}')
     logging.debug(f'input_stacks = {args.input_stacks}')
-    logging.debug(f'config = {args.config}')
     logging.debug(f'x_bounds = {args.x_bounds} {type(args.x_bounds)}')
     logging.debug(f'y_bounds = {args.y_bounds} {type(args.y_bounds)}')
     logging.debug(f'z_bounds = {args.z_bounds} {type(args.z_bounds)}')
@@ -68,7 +68,7 @@
     # Combined reconstructed tomography stacks
     galaxy_param = {'x_bounds' : args.x_bounds, 'y_bounds' : args.y_bounds,
             'z_bounds' : args.z_bounds, 'output_name' : args.output_data}
-    logging.info(f'galaxy_param = {galaxy_param}')
+    logging.debug(f'galaxy_param = {galaxy_param}')
     tomo.combineTomoStacks(galaxy_param)
 
     # Displaying memory usage
--- a/tomo_combine.xml	Thu Aug 18 15:40:59 2022 +0000
+++ b/tomo_combine.xml	Fri Aug 19 20:16:56 2022 +0000
@@ -38,7 +38,7 @@
         <collection name="combine_pngs" type="list" label="Recontructed slices midway in each combined dimension">
             <discover_datasets pattern="__name_and_ext__" directory="combine_pngs"/>
         </collection>
-        <data name="output_config" format="yaml" label="Output config combine reconstruction" from_work_dir="output_config.yaml"/>
+        <data name="output_config" format="tomo.config.yaml" label="Output config combine reconstruction" from_work_dir="output_config.yaml"/>
     </outputs>
     <help><![CDATA[
         Combine reconstructed tomography images.
--- a/tomo_find_center.py	Thu Aug 18 15:40:59 2022 +0000
+++ b/tomo_find_center.py	Fri Aug 19 20:16:56 2022 +0000
@@ -47,8 +47,8 @@
     logging.basicConfig(format=logging_format, level=level, force=True,
             handlers=[logging.StreamHandler()])
 
+    logging.debug(f'config = {args.config}')
     logging.debug(f'input_stacks = {args.input_stacks}')
-    logging.debug(f'config = {args.config}')
     logging.debug(f'row_bounds = {args.row_bounds} {type(args.row_bounds)}')
     logging.debug(f'center_rows = {args.center_rows} {type(args.center_rows)}')
     logging.debug(f'center_type_selector = {args.center_type_selector}')
--- a/tomo_find_center.xml	Thu Aug 18 15:40:59 2022 +0000
+++ b/tomo_find_center.xml	Fri Aug 19 20:16:56 2022 +0000
@@ -60,7 +60,7 @@
         <collection name="find_center_pngs" type="list" label="Recontructed slices at various centers">
             <discover_datasets pattern="__name_and_ext__" directory="find_center_pngs"/>
         </collection>
-        <data name="output_config" format="yaml" label="Output config find center" from_work_dir="output_config.yaml"/>
+        <data name="output_config" format="tomo.config.yaml" label="Output config find center" from_work_dir="output_config.yaml"/>
     </outputs>
     <help><![CDATA[
         Find the center axis for a tomography reconstruction.
--- a/tomo_macros.xml	Thu Aug 18 15:40:59 2022 +0000
+++ b/tomo_macros.xml	Fri Aug 19 20:16:56 2022 +0000
@@ -17,10 +17,7 @@
         </citations>
     </xml>
     <xml name="common_inputs">
-        <!--
-        <param name="config" type='data' format='yaml' optional='false' label="Input config"/>
-        -->
-        <param name="config" type='data' format='tomo.config.yaml' optional='true' label="Input config"/>
+        <param name="config" type='data' format='tomo.config.yaml' optional='false' label="Input config"/>
     </xml>
     <xml name="common_outputs">
         <data name="log" format="txt" label="Log"/>
--- a/tomo_reconstruct.py	Thu Aug 18 15:40:59 2022 +0000
+++ b/tomo_reconstruct.py	Fri Aug 19 20:16:56 2022 +0000
@@ -18,7 +18,7 @@
     parser.add_argument('-c', '--config',
             help='Input config')
     parser.add_argument('--center_offsets',
-            required=True, nargs=2, type=float, help='Reconstruction center axis offsets')
+            nargs=2, type=float, help='Reconstruction center axis offsets')
     parser.add_argument('--output_config',
             help='Output config')
     parser.add_argument('--output_data',
@@ -41,8 +41,8 @@
     logging.basicConfig(format=logging_format, level=level, force=True,
             handlers=[logging.StreamHandler()])
 
+    logging.debug(f'config = {args.config}')
     logging.debug(f'input_stacks = {args.input_stacks}')
-    logging.debug(f'config = {args.config}')
     logging.debug(f'center_offsets = {args.center_offsets} {type(args.center_offsets)}')
     logging.debug(f'output_config = {args.output_config}')
     logging.debug(f'output_data = {args.output_data}')
@@ -56,12 +56,22 @@
         raise ValueError('Invalid config file provided.')
     logging.debug(f'config:\n{tomo.config}')
 
+    # Set reconstruction center axis offsets
+    if args.center_offsets is None:
+        find_center = tomo.config.get('find_center')
+        if find_center is None:
+            raise ValueError('Invalid config file provided (missing find_center).')
+        center_offsets = [float(find_center.get('lower_center_offset')),
+                float(find_center.get('upper_center_offset'))]
+    else:
+        center_offsets = args.center_offsets
+
     # Load preprocessed image files
     tomo.loadTomoStacks(args.input_stacks)
 
     # Reconstruct tomography stacks
-    galaxy_param = {'center_offsets' : args.center_offsets, 'output_name' : args.output_data}
-    logging.info(f'galaxy_param = {galaxy_param}')
+    galaxy_param = {'center_offsets' : center_offsets, 'output_name' : args.output_data}
+    logging.debug(f'galaxy_param = {galaxy_param}')
     tomo.reconstructTomoStacks(galaxy_param)
 
     # Displaying memory usage
--- a/tomo_reconstruct.xml	Thu Aug 18 15:40:59 2022 +0000
+++ b/tomo_reconstruct.xml	Fri Aug 19 20:16:56 2022 +0000
@@ -9,7 +9,9 @@
         $__tool_directory__/tomo_reconstruct.py
         -i '$red_stacks'
         -c '$config'
-        --center_offsets $center_offsets.lower_center_offset $center_offsets.upper_center_offset
+        #if str($center_offsets.type_selector) == "offsets_manual"
+            --center_offsets $center_offsets.lower_center_offset $center_offsets.upper_center_offset
+        #end if
         --output_data 'output_data.npz'
         --output_config 'output_config.yaml'
         -l '$log'
@@ -17,10 +19,17 @@
     <inputs>
         <expand macro="common_inputs"/>
         <param name="red_stacks" type='data' format='npz' optional='false' label="Reduced stacks"/>
-        <section name="center_offsets" title="Reconstruction center axis offsets">
-            <param name="lower_center_offset" type="float" value = "0" optional="false" label="Lower center offset"/>
-            <param name="upper_center_offset" type="float" value = "0" optional="false" label="Upper center offset"/>
-        </section>
+        <conditional name="center_offsets">
+            <param name="type_selector" type="select" label="Read reconstruction center axis offsets from file or enter enter manually">
+                <option value="offsets_from_file" selected="true">Read center axis offsets from file</option>
+                <option value="offsets_manual">Manually enter center axis offsets</option>
+            </param>
+            <when value="offsets_from_file"/>
+            <when value="offsets_manual">
+                <param name="lower_center_offset" type="float" value = "0" optional="false" label="Lower center offset"/>
+                <param name="upper_center_offset" type="float" value = "0" optional="false" label="Upper center offset"/>
+            </when>
+        </conditional>
     </inputs>
     <outputs>
         <expand macro="common_outputs"/>
@@ -28,7 +37,7 @@
         <collection name="center_slice_pngs" type="list" label="Recontructed slices midway in each dimension">
             <discover_datasets pattern="__name_and_ext__" directory="center_slice_pngs"/>
         </collection>
-        <data name="output_config" format="yaml" label="Output config reconstruction" from_work_dir="output_config.yaml"/>
+        <data name="output_config" format="tomo.config.yaml" label="Output config reconstruction" from_work_dir="output_config.yaml"/>
     </outputs>
     <help><![CDATA[
         Reconstruct tomography images.
--- a/tomo_setup.py	Thu Aug 18 15:40:59 2022 +0000
+++ b/tomo_setup.py	Fri Aug 19 20:16:56 2022 +0000
@@ -57,19 +57,19 @@
             handlers=[logging.StreamHandler()])
 
     # Check command line arguments
-    logging.info(f'config = {args.config}')
+    logging.debug(f'config = {args.config}')
     if args.detector is None:
-        logging.info(f'detector = {args.detector}')
+        logging.debug(f'detector = {args.detector}')
     else:
-        logging.info(f'detector = {args.detector.split()}')
-    logging.info(f'num_theta = {args.num_theta}')
+        logging.debug(f'detector = {args.detector.split()}')
+    logging.debug(f'num_theta = {args.num_theta}')
     if args.theta_range is None:
-        logging.info(f'theta_range = {args.theta_range}')
+        logging.debug(f'theta_range = {args.theta_range}')
     else:
-        logging.info(f'theta_range = {args.theta_range.split()}')
-    logging.info(f'output_config = {args.output_config}')
-    logging.info(f'output_data = {args.output_data}')
-    logging.info(f'log = {args.log}')
+        logging.debug(f'theta_range = {args.theta_range.split()}')
+    logging.debug(f'output_config = {args.output_config}')
+    logging.debug(f'output_data = {args.output_data}')
+    logging.debug(f'log = {args.log}')
     logging.debug(f'is log stdout? {args.log is sys.stdout}')
     if args.detector is not None and len(args.detector.split()) != 3:
         raise ValueError(f'Invalid detector: {args.detector}')
@@ -97,13 +97,13 @@
         assert(args.theta_range is not None)
     else:
         ref_heights = None
-    logging.info(f'config_type = {config_type} {type(config_type)}')
-    logging.info(f'input_type = {input_type} {type(input_type)}')
-    logging.info(f'num_stack = {num_stack} {type(num_stack)}')
-    logging.info(f'stack_types = {stack_types} {type(stack_types)}')
-    logging.info(f'num_imgs = {num_imgs} {type(num_imgs)}')
-    logging.info(f'img_offsets = {img_offsets} {type(img_offsets)}')
-    logging.info(f'ref_heights = {ref_heights} {type(ref_heights)}')
+    logging.debug(f'config_type = {config_type} {type(config_type)}')
+    logging.debug(f'input_type = {input_type} {type(input_type)}')
+    logging.debug(f'num_stack = {num_stack} {type(num_stack)}')
+    logging.debug(f'stack_types = {stack_types} {type(stack_types)}')
+    logging.debug(f'num_imgs = {num_imgs} {type(num_imgs)}')
+    logging.debug(f'img_offsets = {img_offsets} {type(img_offsets)}')
+    logging.debug(f'ref_heights = {ref_heights} {type(ref_heights)}')
     if config_type != 'config_file' and config_type != 'config_manual':
         raise ValueError('Invalid input config provided.')
     if input_type != 'collections' and input_type != 'files':
@@ -198,8 +198,10 @@
         if config_type == 'config_file':
             assert(dark_field is not None)
             assert(dark_field['data_path'] is None)
-            assert(dark_field['img_start'] == -1)
-            assert(not dark_field['num'])
+            if dark_field.get('img_start') is None or dark_field['img_start'] != -1:
+                dark_field['img_start'] = -1
+            if dark_field.get('num') is None or dark_field['num'] != 0:
+                dark_field['num'] = 0
         else:
             tomo.config['dark_field'] = {'data_path' : None, 'img_start' : -1, 'num' : 0}
         tdf_files = [None]
@@ -208,7 +210,8 @@
         if config_type == 'config_file':
             assert(dark_field is not None)
             assert(dark_field['data_path'] is not None)
-            assert(dark_field.get('img_start') is not None)
+            if dark_field.get('img_start') is None:
+                dark_field['img_start'] = 0
         else:
             tomo.config['dark_field'] = {'data_path' : tdf_files[0], 'img_start' : 0}
             dark_field = tomo.config['dark_field']
@@ -229,7 +232,8 @@
     if config_type == 'config_file':
         assert(bright_field is not None)
         assert(bright_field['data_path'] is not None)
-        assert(bright_field.get('img_start') is not None)
+        if bright_field.get('img_start') is None:
+            bright_field['img_start'] = 0
     else:
         tomo.config['bright_field'] = {'data_path' : tbf_files[0], 'img_start' : 0}
         bright_field = tomo.config['bright_field']
@@ -251,7 +255,8 @@
         assert(stack_info.get('stacks') is not None)
         for stack in stack_info['stacks']:
             assert(stack['data_path'] is not None)
-            assert(stack.get('img_start') is not None)
+            if stack.get('img_start') is None:
+                stack['img_start'] = 0
             assert(stack.get('index') is not None)
             assert(stack.get('ref_height') is not None)
     else:
--- a/tomo_setup.xml	Thu Aug 18 15:40:59 2022 +0000
+++ b/tomo_setup.xml	Fri Aug 19 20:16:56 2022 +0000
@@ -216,7 +216,7 @@
         <collection name="setup_pngs" type="list" label="Tomo setup images">
             <discover_datasets pattern="__name_and_ext__" directory="setup_pngs"/>
         </collection>
-        <data name="output_config" format="yaml" label="Output config setup" from_work_dir="output_config.yaml"/>
+        <data name="output_config" format="tomo.config.yaml" label="Output config setup" from_work_dir="output_config.yaml"/>
         <data name="output_data" format="npz" label="Preprocessed tomography data" from_work_dir="output_data.npz"/>
     </outputs>
     <help>