Mercurial > repos > rv43 > chess_tomo
comparison workflow/run_tomo.py @ 29:551d1ea2416d draft
planemo upload for repository https://github.com/rolfverberg/galaxytools commit f8c4bdb31c20c468045ad5e6eb255a293244bc6c-dirty
| author | rv43 |
|---|---|
| date | Tue, 21 Mar 2023 18:46:02 +0000 |
| parents | 562fc79de827 |
| children | 3342c0518d4c |
comparison
equal
deleted
inserted
replaced
| 28:562fc79de827 | 29:551d1ea2416d |
|---|---|
| 299 if not isinstance(nxroot, NXroot): | 299 if not isinstance(nxroot, NXroot): |
| 300 raise ValueError(f'Invalid parameter nxroot ({nxroot})') | 300 raise ValueError(f'Invalid parameter nxroot ({nxroot})') |
| 301 nxentry = nxroot[nxroot.attrs['default']] | 301 nxentry = nxroot[nxroot.attrs['default']] |
| 302 if not isinstance(nxentry, NXentry): | 302 if not isinstance(nxentry, NXentry): |
| 303 raise ValueError(f'Invalid nxentry ({nxentry})') | 303 raise ValueError(f'Invalid nxentry ({nxentry})') |
| 304 if self.galaxy_flag: | 304 if center_rows is not None: |
| 305 if center_rows is not None: | 305 if self.galaxy_flag |
| 306 center_rows = tuple(center_rows) | 306 is not is_int_pair(center_rows, ge=-1): |
| 307 if not is_int_pair(center_rows): | |
| 308 raise ValueError(f'Invalid parameter center_rows ({center_rows})') | 307 raise ValueError(f'Invalid parameter center_rows ({center_rows})') |
| 309 elif center_rows is not None: | 308 if (center_rows[0] != -1 and center_rows[1] != -1 and |
| 310 logger.warning(f'Ignoring parameter center_rows ({center_rows})') | 309 center_rows[0] > center_rows[1]): |
| 311 center_rows = None | 310 center_rows = (center_rows[1], center_rows[0]) |
| 311 else: | |
| 312 center_rows = tuple(center_rows) | |
| 313 else: | |
| 314 logger.warning(f'Ignoring parameter center_rows ({center_rows})') | |
| 315 center_rows = None | |
| 312 if self.galaxy_flag: | 316 if self.galaxy_flag: |
| 313 if center_stack_index is not None and not is_int(center_stack_index, ge=0): | 317 if center_stack_index is not None and not is_int(center_stack_index, ge=0): |
| 314 raise ValueError(f'Invalid parameter center_stack_index ({center_stack_index})') | 318 raise ValueError(f'Invalid parameter center_stack_index ({center_stack_index})') |
| 315 elif center_stack_index is not None: | 319 elif center_stack_index is not None: |
| 316 logger.warning(f'Ignoring parameter center_stack_index ({center_stack_index})') | 320 logger.warning(f'Ignoring parameter center_stack_index ({center_stack_index})') |
| 375 lower_row = self.test_config['lower_row'] | 379 lower_row = self.test_config['lower_row'] |
| 376 elif self.galaxy_flag: | 380 elif self.galaxy_flag: |
| 377 if center_rows is None or center_rows[0] == -1: | 381 if center_rows is None or center_rows[0] == -1: |
| 378 lower_row = 0 | 382 lower_row = 0 |
| 379 else: | 383 else: |
| 380 lower_row = min(center_rows) | 384 lower_row = center_rows[0] |
| 381 if not 0 <= lower_row < tomo_fields_shape[2]-1: | 385 if not 0 <= lower_row < tomo_fields_shape[2]-1: |
| 382 raise ValueError(f'Invalid parameter center_rows ({center_rows})') | 386 raise ValueError(f'Invalid parameter center_rows ({center_rows})') |
| 383 else: | 387 else: |
| 384 lower_row = select_one_image_bound( | 388 lower_row = select_one_image_bound( |
| 385 nxentry.reduced_data.data.tomo_fields[center_stack_index,0,:,:], 0, bound=0, | 389 nxentry.reduced_data.data.tomo_fields[center_stack_index,0,:,:], 0, bound=0, |
| 386 title=f'theta={round(thetas[0], 2)+0}', | 390 title=f'theta={round(thetas[0], 2)+0}', |
| 387 bound_name='row index to find lower center', default=default, raise_error=True) | 391 bound_name='row index to find lower center', default=default, raise_error=True) |
| 388 logger.debug('Finding center...') | 392 logger.debug('Finding center...') |
| 389 t0 = time() | 393 t0 = time() |
| 390 lower_center_offset = self._find_center_one_plane( | 394 lower_center_offset = self._find_center_one_plane( |
| 391 #np.asarray(nxentry.reduced_data.data.tomo_fields[center_stack_index,:,lower_row,:]), | |
| 392 nxentry.reduced_data.data.tomo_fields[center_stack_index,:,lower_row,:], | 395 nxentry.reduced_data.data.tomo_fields[center_stack_index,:,lower_row,:], |
| 393 lower_row, thetas, eff_pixel_size, cross_sectional_dim, path=path, | 396 lower_row, thetas, eff_pixel_size, cross_sectional_dim, path=path, |
| 394 num_core=self.num_core) | 397 num_core=self.num_core) |
| 395 logger.debug(f'... done in {time()-t0:.2f} seconds') | 398 logger.debug(f'... done in {time()-t0:.2f} seconds') |
| 396 logger.debug(f'lower_row = {lower_row:.2f}') | 399 logger.debug(f'lower_row = {lower_row:.2f}') |
| 401 upper_row = self.test_config['upper_row'] | 404 upper_row = self.test_config['upper_row'] |
| 402 elif self.galaxy_flag: | 405 elif self.galaxy_flag: |
| 403 if center_rows is None or center_rows[1] == -1: | 406 if center_rows is None or center_rows[1] == -1: |
| 404 upper_row = tomo_fields_shape[2]-1 | 407 upper_row = tomo_fields_shape[2]-1 |
| 405 else: | 408 else: |
| 406 upper_row = max(center_rows) | 409 upper_row = center_rows[1] |
| 407 if not lower_row < upper_row < tomo_fields_shape[2]: | 410 if not lower_row < upper_row < tomo_fields_shape[2]: |
| 408 raise ValueError(f'Invalid parameter center_rows ({center_rows})') | 411 raise ValueError(f'Invalid parameter center_rows ({center_rows})') |
| 409 else: | 412 else: |
| 410 upper_row = select_one_image_bound( | 413 upper_row = select_one_image_bound( |
| 411 nxentry.reduced_data.data.tomo_fields[center_stack_index,0,:,:], 0, | 414 nxentry.reduced_data.data.tomo_fields[center_stack_index,0,:,:], 0, |
| 511 tomo_recon_stacks[i] = tomo_recon_stack | 514 tomo_recon_stacks[i] = tomo_recon_stack |
| 512 | 515 |
| 513 # Resize the reconstructed tomography data | 516 # Resize the reconstructed tomography data |
| 514 # reconstructed data order in each stack: row/z,x,y | 517 # reconstructed data order in each stack: row/z,x,y |
| 515 if self.test_mode: | 518 if self.test_mode: |
| 516 x_bounds = self.test_config.get('x_bounds') | 519 x_bounds = tuple(self.test_config.get('x_bounds')) |
| 517 y_bounds = self.test_config.get('y_bounds') | 520 y_bounds = tuple(self.test_config.get('y_bounds')) |
| 518 z_bounds = None | 521 z_bounds = None |
| 519 elif self.galaxy_flag: | 522 elif self.galaxy_flag: |
| 520 if x_bounds is not None and not is_int_pair(x_bounds, ge=-1, | 523 x_max = tomo_recon_stacks[0].shape[1] |
| 521 lt=tomo_recon_stacks[0].shape[1]): | 524 if x_bounds is None: |
| 525 x_bounds = (0, x_max) | |
| 526 elif is_int_pair(x_bounds, ge=-1, le=x_max): | |
| 527 x_bounds = tuple(x_bounds) | |
| 528 if x_bounds[0] == -1: | |
| 529 x_bounds = (0, x_bounds[1]) | |
| 530 if x_bounds[1] == -1: | |
| 531 x_bounds = (x_bounds[0], x_max) | |
| 532 if not is_index_range(x_bounds, ge=0, le=x_max): | |
| 522 raise ValueError(f'Invalid parameter x_bounds ({x_bounds})') | 533 raise ValueError(f'Invalid parameter x_bounds ({x_bounds})') |
| 523 if y_bounds is not None and not is_int_pair(y_bounds, ge=-1, | 534 y_max = tomo_recon_stacks[0].shape[1] |
| 524 lt=tomo_recon_stacks[0].shape[1]): | 535 if y_bounds is None: |
| 536 y_bounds = (0, y_max) | |
| 537 elif is_int_pair(y_bounds, ge=-1, le=y_max): | |
| 538 y_bounds = tuple(y_bounds) | |
| 539 if y_bounds[0] == -1: | |
| 540 y_bounds = (0, y_bounds[1]) | |
| 541 if y_bounds[1] == -1: | |
| 542 y_bounds = (y_bounds[0], y_max) | |
| 543 if not is_index_range(y_bounds, ge=0, le=y_max): | |
| 525 raise ValueError(f'Invalid parameter y_bounds ({y_bounds})') | 544 raise ValueError(f'Invalid parameter y_bounds ({y_bounds})') |
| 526 z_bounds = None | 545 z_bounds = None |
| 527 else: | 546 else: |
| 528 x_bounds, y_bounds, z_bounds = self._resize_reconstructed_data(tomo_recon_stacks) | 547 x_bounds, y_bounds, z_bounds = self._resize_reconstructed_data(tomo_recon_stacks) |
| 529 if x_bounds is None: | 548 if x_bounds is None: |
| 987 x_sum_max = x_sum.max() | 1006 x_sum_max = x_sum.max() |
| 988 if self.galaxy_flag: | 1007 if self.galaxy_flag: |
| 989 if img_x_bounds is None: | 1008 if img_x_bounds is None: |
| 990 img_x_bounds = (0, first_image.shape[0]) | 1009 img_x_bounds = (0, first_image.shape[0]) |
| 991 elif is_int_pair(img_x_bounds, ge=-1, le=first_image.shape[0]): | 1010 elif is_int_pair(img_x_bounds, ge=-1, le=first_image.shape[0]): |
| 1011 img_x_bounds = tuple(img_x_bounds) | |
| 992 if img_x_bounds[0] == -1: | 1012 if img_x_bounds[0] == -1: |
| 993 img_x_bounds[0] = 0 | 1013 img_x_bounds = (0, img_x_bounds[1]) |
| 994 if img_x_bounds[1] == -1: | 1014 if img_x_bounds[1] == -1: |
| 995 img_x_bounds[1] = first_image.shape[0] | 1015 img_x_bounds = (img_x_bounds[0], first_image.shape[0]) |
| 996 if not is_index_range(img_x_bounds, ge=0, le=first_image.shape[0]): | 1016 if not is_index_range(img_x_bounds, ge=0, le=first_image.shape[0]): |
| 997 raise ValueError(f'Invalid parameter img_x_bounds ({img_x_bounds})') | 1017 raise ValueError(f'Invalid parameter img_x_bounds ({img_x_bounds})') |
| 998 else: | 1018 else: |
| 999 quick_imshow(first_image, title=title) | 1019 quick_imshow(first_image, title=title) |
| 1000 print('Select vertical data reduction range from first tomography image') | 1020 print('Select vertical data reduction range from first tomography image') |
