Mercurial > repos > rv43 > chess_tomo
diff workflow/run_tomo.py @ 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 |
line wrap: on
line diff
--- 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:
