changeset 33:50923144fb56 draft

planemo upload for repository https://github.com/rolfverberg/galaxytools commit f8c4bdb31c20c468045ad5e6eb255a293244bc6c
author rv43
date Wed, 22 Mar 2023 16:46:26 +0000
parents 98eee43a8c8c
children ee2d59b83719
files __pycache__/fit.cpython-39.pyc __pycache__/general.cpython-39.pyc run_link_to_galaxy run_tomo_combine run_tomo_find_center run_tomo_reconstruct run_tomo_reduce tomo_combine.xml tomo_find_center.xml tomo_macros.xml tomo_reconstruct.xml tomo_reduce.xml workflow/__pycache__/__version__.cpython-39.pyc workflow/__pycache__/models.cpython-39.pyc workflow/__pycache__/run_tomo.cpython-39.pyc workflow/run_tomo.py
diffstat 16 files changed, 140 insertions(+), 69 deletions(-) [+]
line wrap: on
line diff
Binary file __pycache__/fit.cpython-39.pyc has changed
Binary file __pycache__/general.cpython-39.pyc has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/run_link_to_galaxy	Wed Mar 22 16:46:26 2023 +0000
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+python -m workflow link_to_galaxy -i sobhani-3249-A_start.nxs -g 'https://galaxy-dev.classe.cornell.edu' -a 'bd404baf78eef76657277f33021d408f'
+python -m workflow link_to_galaxy -i tenstom_1304r-1_start.nxs -g 'https://galaxy-dev.classe.cornell.edu' -a 'bd404baf78eef76657277f33021d408f'
+python -m workflow link_to_galaxy -i tenstom_1304r-1_one_stack_start.nxs -g 'https://galaxy-dev.classe.cornell.edu' -a 'bd404baf78eef76657277f33021d408f'
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/run_tomo_combine	Wed Mar 22 16:46:26 2023 +0000
@@ -0,0 +1,9 @@
+#!/bin/bash
+
+# From workflow
+#python -m workflow run_tomo -i sobhani-3249-A_recon.nxs -o sobhani-3249-A_recon_combined.nxs -n 48 -s 'only' --combine_data
+#python -m workflow run_tomo -i tenstom_1304r-1_one_stack_recon.nxs -o tenstom_1304r-1_one_stack_recon_combined.nxs -n 48 -s 'only' --combine_data
+#python -m workflow run_tomo -i tenstom_1304r-1_recon.nxs -o tenstom_1304r-1_recon_combined.nxs -n 48 -s 'only' --combine_data
+
+# As Galaxy tool:
+python tomo_combine.py -i tenstom_1304r-1_recon.nxs -o tenstom_1304r-1_recon_combined.nxs --log_level INFO -l tomo.log --galaxy_flag
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/run_tomo_find_center	Wed Mar 22 16:46:26 2023 +0000
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+# From workflow
+#python -m workflow run_tomo -i sobhani-3249-A_reduce.nxs -o sobhani-3249-A_centers.yaml -n 48 -s 'only' --find_center
+#python -m workflow run_tomo -i tenstom_1304r-1_one_stack_reduce.nxs -o tenstom_1304r-1_one_stack_centers.yaml -n 48 -s 'only' --find_center
+#python -m workflow run_tomo -i tenstom_1304r-1_reduce.nxs -o tenstom_1304r-1_centers.yaml -n 48 -s 'only' --find_center
+
+# As Galaxy tool:
+#python tomo_find_center.py -i sobhani-3249-A_reduce.nxs -o sobhani-3249-A_centers.yaml --log_level INFO -l tomo.log --galaxy_flag --center_rows 50 270
+#python tomo_find_center.py -i tenstom_1304r-1_one_stack_reduce.nxs -o tenstom_1304r-1_one_stack_centers.yaml --log_level INFO -l tomo.log --galaxy_flag --center_rows 75 850
+python tomo_find_center.py -i tenstom_1304r-1_reduce.nxs -o tenstom_1304r-1_centers.yaml --log_level INFO -l tomo.log --galaxy_flag
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/run_tomo_reconstruct	Wed Mar 22 16:46:26 2023 +0000
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+# From workflow
+#python -m workflow run_tomo -i sobhani-3249-A_reduce.nxs -c sobhani-3249-A_centers.yaml -o sobhani-3249-A_recon.nxs -n 48 -s 'only' --reconstruct_data
+#python -m workflow run_tomo -i tenstom_1304r-1_one_stack_reduce.nxs -c tenstom_1304r-1_one_stack_centers.yaml -o tenstom_1304r-1_one_stack_recon.nxs -n 48 -s 'only' --reconstruct_data
+#python -m workflow run_tomo -i tenstom_1304r-1_reduce.nxs -c tenstom_1304r-1_centers.yaml -o tenstom_1304r-1_recon.nxs -n 48 -s 'only' --reconstruct_data
+
+# As Galaxy tool:
+#python tomo_reconstruct.py -i sobhani-3249-A_reduce.nxs -c sobhani-3249-A_centers.yaml -o sobhani-3249-A_recon.nxs --log_level INFO -l tomo.log --galaxy_flag --x_bounds 650 1050 --y_bounds 270 1430
+#python tomo_reconstruct.py -i tenstom_1304r-1_one_stack_reduce.nxs -c tenstom_1304r-1_one_stack_centers.yaml -o tenstom_1304r-1_one_stack_recon.nxs --log_level INFO -l tomo.log --galaxy_flag --x_bounds 629 1450 --y_bounds 606 1468
+python tomo_reconstruct.py -i tenstom_1304r-1_reduce.nxs -c tenstom_1304r-1_centers.yaml -o tenstom_1304r-1_recon.nxs --log_level INFO -l tomo.log --galaxy_flag --x_bounds 629 1450 --y_bounds 606 1468
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/run_tomo_reduce	Wed Mar 22 16:46:26 2023 +0000
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+# From workflow
+#python -m workflow run_tomo -i sobhani-3249-A.yaml -o sobhani-3249-A_reduce.nxs -n 48 -s 'only' --reduce_data
+#python -m workflow run_tomo -i tenstom_1304r-1_one_stack.yaml -o tenstom_1304r-1_one_stack_reduce.nxs -n 48 -s 'only' --reduce_data
+#python -m workflow run_tomo -i tenstom_1304r-1.yaml -o tenstom_1304r-1_reduce.nxs -n 48 -s 'only' --reduce_data
+
+# As Galaxy tool:
+python tomo_reduce.py -i sobhani-3249-A_start.nxs -o sobhani-3249-A_reduce.nxs --log_level INFO -l tomo.log --galaxy_flag --img_x_bounds 620 950
+python tomo_reduce.py -i tenstom_1304r-1_one_stack_start.nxs -o tenstom_1304r-1_one_stack_reduce.nxs --log_level INFO -l tomo.log --galaxy_flag #--img_x_bounds 582 1509
+python tomo_reduce.py -i tenstom_1304r-1_start.nxs -o tenstom_1304r-1_reduce.nxs --log_level INFO -l tomo.log --galaxy_flag #--img_x_bounds 713 1388
--- a/tomo_combine.xml	Wed Mar 22 12:56:22 2023 +0000
+++ b/tomo_combine.xml	Wed Mar 22 16:46:26 2023 +0000
@@ -1,43 +1,56 @@
-<tool id="tomo_combine" name="Tomo Combine Reconstructed Stacks" version="0.2.0" python_template_version="3.9">
+<tool id="tomo_combine" name="Tomo Combine Reconstructed Stacks" version="1.0.0" python_template_version="3.9">
     <description>Combine reconstructed tomography stacks</description>
     <macros>
         <import>tomo_macros.xml</import>
     </macros>
     <expand macro="requirements" />
-    <command detect_errors="exit_code"><![CDATA[
-        mkdir combine_pngs;
-        $__tool_directory__/tomo_combine.py
-        -i '$recon_stacks'
-        -c '$config'
-        --x_bounds $x_bounds.low $x_bounds.upp
-        --y_bounds $y_bounds.low $y_bounds.upp
-        --z_bounds $z_bounds.low $z_bounds.upp
-        --output_data 'output_data.npy'
-        --output_config 'output_config.yaml'
-        -l '$log'
-    ]]></command>
+    <command detect_errors="exit_code">
+        <![CDATA[
+            mkdir tomo_combine_plots;
+            $__tool_directory__/tomo_combine.py
+            --input_file "$input_file"
+            --output_file "output.nex"
+            --galaxy_flag
+            #if str($x_bounds.type_selector) == "enter_range"
+                --x_bounds $x_bounds.low $x_bounds.upp
+            #end if
+            #if str($y_bounds.type_selector) == "enter_range"
+                --y_bounds $y_bounds.low $y_bounds.upp
+            #end if
+            -l '$log'
+        ]]>
+    </command>
     <inputs>
-        <param name="recon_stacks" type='data' format='npz' optional='false' label="Reconstructed stacks"/>
-        <section name="x_bounds" title="Reconstructed range in x direction">
-            <param name="low" type="integer" value = "-1" label="Lower x-bound"/>
-            <param name="upp" type="integer" value = "-1" label="Upper x-bound"/>
-        </section>
-        <section name="y_bounds" title="Reconstructed range in y direction">
-            <param name="low" type="integer" value = "-1" label="Lower y-bound"/>
-            <param name="upp" type="integer" value = "-1" label="Upper y-bound"/>
-        </section>
-        <section name="z_bounds" title="Reconstructed range in z direction">
-            <param name="low" type="integer" value = "-1" label="Lower z-bound"/>
-            <param name="upp" type="integer" value = "-1" label="Upper z-bound"/>
-        </section>
+        <param name="input_file" type="data" format="nex" optional="false" label="Reconstructed tomography data"/>
+        <conditional name="x_bounds">
+            <param name="type_selector" type="select" label="Choose reconstructed image range in x-direction">
+                <option value="full_range" selected="true">Use the full image range</option>
+                <option value="enter_range">Manually enter the image range</option>
+            </param>
+            <when value="full_range"/>
+            <when value="enter_range">
+                <param name="low" type="integer" value="-1" optional="false" label="Lower image range index in x-direction"/>
+                <param name="upp" type="integer" value="-1" optional="false" label="Upper image range index in x-direction"/>
+            </when>
+        </conditional>
+        <conditional name="y_bounds">
+            <param name="type_selector" type="select" label="Choose reconstructed image range in y-direction">
+                <option value="full_range" selected="true">Use the full image range</option>
+                <option value="enter_range">Manually enter the image range</option>
+            </param>
+            <when value="full_range"/>
+            <when value="enter_range">
+                <param name="low" type="integer" value="-1" optional="false" label="Lower image range index in y-direction"/>
+                <param name="upp" type="integer" value="-1" optional="false" label="Upper image range index in y-direction"/>
+            </when>
+        </conditional>
     </inputs>
     <outputs>
         <expand macro="common_outputs"/>
-        <data name="output_data" format="npy" label="Combined tomography stacks" from_work_dir="output_data.npy"/>
-        <collection name="combine_pngs" type="list" label="Recontructed slices midway in each combined dimension">
-            <discover_datasets pattern="__name_and_ext__" directory="combine_pngs"/>
+        <collection name="tomo_combine_plots" type="list" label="Combine recontructed data images">
+            <discover_datasets pattern="__name_and_ext__" directory="tomo_combine_plots"/>
         </collection>
-        <data name="output_config" format="tomo.config.yaml" label="Output config combine reconstruction" from_work_dir="output_config.yaml"/>
+        <data name="output_file" format="nex" label="Reconstructed tomography data" from_work_dir="output.nex"/>
     </outputs>
     <help><![CDATA[
         Combine reconstructed tomography images.
--- a/tomo_find_center.xml	Wed Mar 22 12:56:22 2023 +0000
+++ b/tomo_find_center.xml	Wed Mar 22 16:46:26 2023 +0000
@@ -1,4 +1,4 @@
-<tool id="tomo_find_center" name="Tomo Find Center Axis" version="0.3.0" python_template_version="3.9">
+<tool id="tomo_find_center" name="Tomo Find Center Axis" version="1.0.0" python_template_version="3.9">
     <description>Find the center axis for a tomography reconstruction</description>
     <macros>
         <import>tomo_macros.xml</import>
--- a/tomo_macros.xml	Wed Mar 22 12:56:22 2023 +0000
+++ b/tomo_macros.xml	Wed Mar 22 16:46:26 2023 +0000
@@ -10,19 +10,13 @@
     <xml name="citations">
         <citations>
             <citation type="bibtex">
-@misc{github_files,
+@misc{chess_tomography,
   author = {Verberg, Rolf},
-  year = {2022},
+  year = {2023},
   title = {Tomo Reconstruction},
 }</citation>
         </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"/>
-    </xml>
-    -->
     <xml name="common_outputs">
         <data name="log" format="txt" label="Log"/>
     </xml>
--- a/tomo_reconstruct.xml	Wed Mar 22 12:56:22 2023 +0000
+++ b/tomo_reconstruct.xml	Wed Mar 22 16:46:26 2023 +0000
@@ -1,4 +1,4 @@
-<tool id="tomo_reconstruct" name="Tomo Reconstruction" version="0.3.0" python_template_version="3.9">
+<tool id="tomo_reconstruct" name="Tomo Reconstruction" version="1.0.0" python_template_version="3.9">
     <description>Perform a tomography reconstruction</description>
     <macros>
         <import>tomo_macros.xml</import>
@@ -49,7 +49,7 @@
     </inputs>
     <outputs>
         <expand macro="common_outputs"/>
-        <collection name="tomo_reconstruct_plots" type="list" label="Data recontructed images">
+        <collection name="tomo_reconstruct_plots" type="list" label="Data recontruction images">
             <discover_datasets pattern="__name_and_ext__" directory="tomo_reconstruct_plots"/>
         </collection>
         <data name="output_file" format="nex" label="Reconstructed tomography data" from_work_dir="output.nex"/>
--- a/tomo_reduce.xml	Wed Mar 22 12:56:22 2023 +0000
+++ b/tomo_reduce.xml	Wed Mar 22 16:46:26 2023 +0000
@@ -1,4 +1,4 @@
-<tool id="tomo_reduce" name="Tomo Reduce" version="0.1.5" python_template_version="3.9">
+<tool id="tomo_reduce" name="Tomo Reduce" version="1.0.0" python_template_version="3.9">
     <description>Reduce tomography images</description>
     <macros>
         <import>tomo_macros.xml</import>
@@ -19,15 +19,24 @@
     </command>
     <inputs>
         <param name="input_file" type="data" optional="false" label="Input file"/>
-        <conditional name="img_bounds">
-            <param name="type_selector" type="select" label="Choose image range for data reduction">
-                <option value="full_range" selected="true">Use the full image range</option>
-                <option value="enter_range">Manually enter the image range</option>
+        <conditional name="station">
+            <param name="type_selector" type="select" display="radio" label="Choose station">
+                <option value="id3a" selected="true">id3a (SMB)</option>
+                <option value="id3b">id3b (FMB)</option>
             </param>
-            <when value="full_range"/>
-            <when value="enter_range">
-                <param name="low" type="integer" value="-1" optional="false" label="Lower image range index in vertical direction"/>
-                <param name="upp" type="integer" value="-1" optional="false" label="Upper image range index in vertical direction"/>
+            <when value="id3a"/>
+            <when value="id3b">
+                <conditional name="img_bounds">
+                    <param name="type_selector" type="select" display="radio" label="Choose image range for data reduction">
+                        <option value="enter_range" selected="true">Manually enter the image range</option>
+                        <option value="full_range">Use the full image range</option>
+                    </param>
+                    <when value="enter_range">
+                        <param name="low" type="integer" value="-1" optional="false" label="Lower image range index in vertical direction"/>
+                        <param name="upp" type="integer" value="-1" optional="false" label="Upper image range index in vertical direction"/>
+                    </when>
+                    <when value="full_range"/>
+                </conditional>
             </when>
         </conditional>
     </inputs>
Binary file workflow/__pycache__/__version__.cpython-39.pyc has changed
Binary file workflow/__pycache__/models.cpython-39.pyc has changed
Binary file workflow/__pycache__/run_tomo.cpython-39.pyc has changed
--- a/workflow/run_tomo.py	Wed Mar 22 12:56:22 2023 +0000
+++ b/workflow/run_tomo.py	Wed Mar 22 16:46:26 2023 +0000
@@ -15,7 +15,7 @@
 
 from multiprocessing import cpu_count
 from nexusformat.nexus import *
-from os import mkdir
+from os import mkdir, environ
 from os import path as os_path
 try:
     from skimage.transform import iradon
@@ -99,7 +99,7 @@
             self.num_core = num_core
 
     def __enter__(self):
-        self.num_core_org = ne.set_num_threads(self.num_core)
+        self.num_core_org = ne.set_num_threads(min(self.num_core, ne.MAX_THREADS))
 
     def __exit__(self, exc_type, exc_value, traceback):
         ne.set_num_threads(self.num_core_org)
@@ -773,7 +773,7 @@
 
         # Take median
         if tdf_stack.ndim == 2:
-            tdf = tdf_stack
+            tdf = tdf_stack.astype('float64')
         elif tdf_stack.ndim == 3:
             tdf = np.median(tdf_stack, axis=0)
             del tdf_stack
@@ -841,7 +841,7 @@
            We don’t typically account for them but potentially could.
         """
         if tbf_stack.ndim == 2:
-            tbf = tbf_stack
+            tbf = tbf_stack.astype('float64')
         elif tbf_stack.ndim == 3:
             tbf = np.median(tbf_stack, axis=0)
             del tbf_stack
@@ -856,7 +856,7 @@
 
         # Set any non-positive values to one
         # (avoid negative bright field values for spikes in dark field)
-        tbf[tbf < 1] = 1
+        tbf[tbf < 1.0] = 1.0
 
         # Plot bright field
         if self.galaxy_flag:
@@ -1069,23 +1069,29 @@
         """
         # Get full bright field
         tbf = np.asarray(reduced_data.data.bright_field)
-        tbf_shape = tbf.shape
+        img_shape = tbf.shape
 
         # Get image bounds
-        img_x_bounds = tuple(reduced_data.get('img_x_bounds', (0, tbf_shape[0])))
-        img_y_bounds = tuple(reduced_data.get('img_y_bounds', (0, tbf_shape[1])))
+        img_x_bounds = tuple(reduced_data.get('img_x_bounds', (0, img_shape[0])))
+        img_y_bounds = tuple(reduced_data.get('img_y_bounds', (0, img_shape[1])))
+        if img_x_bounds == (0, img_shape[0]) and img_y_bounds == (0, img_shape[1]):
+            resize_flag = False
+        else:
+            resize_flag = True
 
         # Get resized dark field
-#        if 'dark_field' in data:
-#            tbf = np.asarray(reduced_data.data.dark_field[
-#                    img_x_bounds[0]:img_x_bounds[1],img_y_bounds[0]:img_y_bounds[1]])
-#        else:
-#            logger.warning('Dark field unavailable')
-#            tdf = None
-        tdf = None
+        if 'dark_field' in reduced_data.data:
+            if resize_flag:
+                tdf = np.asarray(reduced_data.data.dark_field[
+                        img_x_bounds[0]:img_x_bounds[1],img_y_bounds[0]:img_y_bounds[1]])
+            else:
+                tdf = np.asarray(reduced_data.data.dark_field)
+        else:
+            logger.warning('Dark field unavailable')
+            tdf = None
 
         # Resize bright field
-        if img_x_bounds != (0, tbf.shape[0]) or img_y_bounds != (0, tbf.shape[1]):
+        if resize_flag:
             tbf = tbf[img_x_bounds[0]:img_x_bounds[1],img_y_bounds[0]:img_y_bounds[1]]
 
         # Get the tomography images
@@ -1145,13 +1151,15 @@
         else:
             path = self.output_folder
         for i, tomo_stack in enumerate(tomo_stacks):
-            # Resize the tomography images
-            # Right now the range is the same for each set in the image stack.
-            if img_x_bounds != (0, tbf.shape[0]) or img_y_bounds != (0, tbf.shape[1]):
+            # Resize the tomography images as needed
+            # Right now the range is the same for each set in the image stack
+            if resize_flag:
                 t0 = time()
                 tomo_stack = tomo_stack[:,img_x_bounds[0]:img_x_bounds[1],
                         img_y_bounds[0]:img_y_bounds[1]].astype('float64')
                 logger.debug(f'Resizing tomography images took {time()-t0:.2f} seconds')
+            else:
+                tomo_stack = tomo_stack.astype('float64')
 
             # Subtract dark field
             if tdf is not None: