def run(self, prefix=None): """ Parameters ---------- prefix: str A prefix that is added to the stats volumes. To locate correct transform inversion files, look for files with this prefix missing """ # inverting_names = os.listdir(self.inverted_tform_stage_dirs[ # 0]) # for i, vol_name in enumerate(inverting_names): # if self.batch_invert: # invertable = self.invertables # else: # invertable = self.invertables[vol_name] volname, ext = splitext(basename(self.invertables)) if prefix and volname.startswith(prefix): original_vol_name = volname[len(prefix):] # remove the prfix to get the original vol name to find the tf else: original_vol_name = volname invertable = self.invertables for inversion_stage in self.inverted_tform_stage_dirs: invert_stage_out = join(self.out_dir, basename(inversion_stage)) common.mkdir_if_not_exists(invert_stage_out) inv_tform_dir = join(inversion_stage, original_vol_name) transform_file = join(inv_tform_dir, IMAGE_INVERTED_TRANSFORM) invert_vol_out_dir = join(invert_stage_out, volname) common.mkdir_if_not_exists(invert_vol_out_dir) invertable = self._invert(invertable, transform_file, invert_vol_out_dir, self.threads)
def run(self): """ """ done_file = self.out_dir / 'invert.done' common.touch(done_file) vol_ids = os.listdir(self._transform_dirs()[0]) logging.info('inverting volumes') for i, id_ in enumerate(vol_ids): invertable = self.invertables for inversion_stage in self._transform_dirs(): invert_stage_out = self.out_dir / inversion_stage.name common.mkdir_if_not_exists(invert_stage_out) invert_vol_out_dir = invert_stage_out / id_ common.mkdir_if_not_exists(invert_vol_out_dir) transform_file = inversion_stage / id_ / self.invert_transform_name # logging.info('inverting {}'.format(transform_file)) invertable = self._invert(invertable, transform_file, invert_vol_out_dir, self.threads) if not invertable: # If inversion failed or there is nocobber, will get None continue self.last_invert_dir = invert_stage_out
def __init__(self, config_path: Path, invertable, outdir, threads=None, noclobber=False): """ Inverts a series of volumes. A yaml config file specifies the order of inverted transform parameters to use. This config file should be in the root of the directory containing these inverted tform dirs. Also need to input a directory containing volumes/label maps etc to invert. These need to be in directories named with the same name as the corresponding inverted tform file directories Parameters ---------- config_path path to yaml config containing the oder of the inverted directories to use. The directories containing propagation tfransfrom files should be in the same diretory threads: str/ None number of threas to use. If None, use all available threads invertable: str path to object to invert (raw image, mask, label map etc) outdir where to store inverted volumes invertable: str dir or path. If dir, invert all objects within the subdirectories. If path to object (eg. labelmap) invert that instead noclobber: bool if True do not overwrite already inverted labels """ self.noclobber = noclobber common.test_installation('transformix') self.config = cfg_load(config_path) self.invertables = invertable self.config_dir = config_path.parent # The dir containing the inverted elx param files self.threads = threads self.out_dir = outdir common.mkdir_if_not_exists(self.out_dir) self.elx_param_prefix = ELX_PARAM_PREFIX self.PROPAGATION_TFORM_NAME = None # Set in subclasses self.last_invert_dir = None # I thik this is used as a way to find volumes to do organ vol calculation on