changeset 21:3caba2116858 draft

"planemo upload for repository https://github.com/rolfverberg/galaxytools commit e32e37ee46f47b185f924884685eb1d464761e86"
author rv43
date Mon, 18 Apr 2022 19:43:15 +0000
parents c033f8843dc0
children ac2f726f9054
files tomo.py tomo_reconstruct.py tomo_reconstruct.xml
diffstat 3 files changed, 28 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/tomo.py	Mon Apr 18 18:10:07 2022 +0000
+++ b/tomo.py	Mon Apr 18 19:43:15 2022 +0000
@@ -1883,15 +1883,17 @@
     def reconstructTomoStacks(self, galaxy_param=None, num_core=None):
         """Reconstruct tomography stacks.
         """
-        print('OK1')
         if num_core is None:
             num_core = self.num_core
+        if self.galaxy_flag:
+            assert(galaxy_param)
+            if not os.path.exists('center_slice_pngs'):
+                os.mkdir('center_slice_pngs')
         logging.debug('Reconstruct tomography stacks')
         stacks = self.config['stack_info']['stacks']
         assert(len(self.tomo_stacks) == self.config['stack_info']['num'])
         assert(len(self.tomo_stacks) == len(stacks))
         assert(len(self.tomo_recon_stacks) == len(stacks))
-        print('OK2')
         if self.galaxy_flag:
             assert(isinstance(galaxy_param, dict))
             # Get rotation axis centers
@@ -1907,7 +1909,6 @@
                 galaxy_param = None
             lower_center_offset = None
             upper_center_offset = None
-        print('OK3')
 
         # Get rotation axis rows and centers
         find_center = self.config['find_center']
@@ -1934,7 +1935,6 @@
         center_slope = (upper_center_offset-lower_center_offset)/(upper_row-lower_row)
 
         # Set thetas (in radians)
-        print('OK4')
         theta_range = self.config['theta_range']
         theta_start = theta_range['start']
         theta_end = theta_range['end']
@@ -1943,11 +1943,10 @@
         thetas = np.radians(np.linspace(theta_start, theta_end,
                 int(num_theta/(num_theta_skip+1)), endpoint=False))
 
-        print('OK5')
         # Reconstruct tomo stacks
         zoom_perc = self.config['preprocess'].get('zoom_perc', 100)
         if zoom_perc == 100:
-            basetitle = 'recon stack full'
+            basetitle = 'recon stack fullres'
         else:
             basetitle = f'recon stack {zoom_perc}p'
         load_error = False
@@ -1971,7 +1970,6 @@
             if not self.tomo_stacks[i].size:
                 self.tomo_stacks[i], available = self._loadTomo('red stack', index,
                         required=True)
-            print(f'self.tomo_stacks.shape = {self.tomo_stacks[i].shape}')
             if not self.tomo_stacks[i].size:
                 logging.error(f'Unable to load tomography stack {index} for reconstruction')
                 stack[i]['preprocessed'] = False
@@ -1985,23 +1983,32 @@
                     thetas, center_offsets=center_offsets, sigma=0.1, num_core=num_core,
                     algorithm='gridrec', run_secondary_sirt=True, secondary_iter=25)
             logging.info(f'Reconstruction of stack {index} took {time()-t0:.2f} seconds!')
-            if not self.test_mode and not self.galaxy_flag:
-                row_slice = int(self.tomo_stacks[i].shape[0]/2) 
-                title = f'{basetitle} {index} slice{row_slice}'
-                msnc.quickImshow(self.tomo_recon_stacks[i][row_slice,:,:], title=title,
+            if self.galaxy_flag:
+                x_slice = int(self.tomo_stacks[i].shape[0]/2) 
+                title = f'{basetitle} {index} xslice{x_slice}'
+                msnc.quickImshow(self.tomo_recon_stacks[i][x_slice,:,:], title=title,
+                        path='center_slice_pngs', save_fig=True, save_only=True)
+                y_slice = int(self.tomo_stacks[i].shape[0]/2) 
+                title = f'{basetitle} {index} yslice{y_slice}'
+                msnc.quickImshow(self.tomo_recon_stacks[i][:,y_slice,:], title=title,
+                        path='center_slice_pngs', save_fig=True, save_only=True)
+                z_slice = int(self.tomo_stacks[i].shape[0]/2) 
+                title = f'{basetitle} {index} zslice{z_slice}'
+                msnc.quickImshow(self.tomo_recon_stacks[i][:,:,z_slice], title=title,
+                        path='center_slice_pngs', save_fig=True, save_only=True)
+            elif not self.test_mode:
+                x_slice = int(self.tomo_stacks[i].shape[0]/2) 
+                title = f'{basetitle} {index} xslice{x_slice}'
+                msnc.quickImshow(self.tomo_recon_stacks[i][x_slice,:,:], title=title,
                         path=self.output_folder, save_fig=self.save_plots,
                         save_only=self.save_plots_only)
                 msnc.quickPlot(self.tomo_recon_stacks[i]
-                        [row_slice,int(self.tomo_recon_stacks[i].shape[2]/2),:],
+                        [x_slice,int(self.tomo_recon_stacks[i].shape[2]/2),:],
                         title=f'{title} cut{int(self.tomo_recon_stacks[i].shape[2]/2)}',
                         path=self.output_folder, save_fig=self.save_plots,
                         save_only=self.save_plots_only)
                 self._saveTomo('recon stack', self.tomo_recon_stacks[i], index)
-#            else:
-#                np.savetxt(self.output_folder+f'recon_stack_{index}.txt',
-#                        self.tomo_recon_stacks[i][row_slice,:,:], fmt='%.6e')
             self.tomo_stacks[i] = np.array([])
-            print('OK6')
 
             # Update config and save to file
             stack['reconstructed'] = True
@@ -2010,7 +2017,6 @@
                 combine_stacks['stacks'].remove(index)
             self.cf.saveFile(self.config_out)
 
-        print('OK7')
         # Save reconstructed tomography stack to file
         if self.galaxy_flag:
             t0 = time()
--- a/tomo_reconstruct.py	Mon Apr 18 18:10:07 2022 +0000
+++ b/tomo_reconstruct.py	Mon Apr 18 19:43:15 2022 +0000
@@ -61,10 +61,8 @@
 
     # Reconstruct tomography stacks
     galaxy_param = {'center_offsets' : args.center_offsets, 'output_name' : args.output_data}
-    print(f'Here galaxy_param = {galaxy_param}')
     logging.info(f'galaxy_param = {galaxy_param}')
     tomo.reconstructTomoStacks(galaxy_param)
-    print('Here')
 
     # Displaying memory usage
     logging.info(f'Memory usage: {tracemalloc.get_traced_memory()}')
--- a/tomo_reconstruct.xml	Mon Apr 18 18:10:07 2022 +0000
+++ b/tomo_reconstruct.xml	Mon Apr 18 19:43:15 2022 +0000
@@ -5,11 +5,12 @@
     </macros>
     <expand macro="requirements" />
     <command detect_errors="exit_code"><![CDATA[
+        mkdir center_slice_pngs;
         $__tool_directory__/tomo_reconstruct.py
         -i '$red_stacks'
         -c '$config'
         --center_offsets $center_offsets.lower_center_offset $center_offsets.upper_center_offset
-        --output_data 'output.npz'
+        --output_data 'output_data.npz'
         --output_config 'output_config.yaml'
         -l '$log'
     ]]></command>
@@ -24,6 +25,9 @@
     <outputs>
         <expand macro="common_outputs"/>
         <data name="output_data" format="npz" label="Reconstructed tomography stacks" from_work_dir="output_data.npz"/>
+        <collection name="recon_slices" type="list" label="Recontructed slices midway in each dimension">
+            <discover_datasets pattern="__name_and_ext__" directory="center_slice_pngs"/>
+        </collection>
     </outputs>
     <help><![CDATA[
         Reconstruct tomography images.