lama/registration_pipeline/run_lama.py
def run(configfile: Path):
        """
        This is the main function Lama script for generating data from registering volumes
        It reads in the config file, creates directories, and initialises the registration process.

        Looks for paths to inputs relative the directory containing the config file

        Parameters
        ----------
        param config
            A toml config file
        """
        try:
            config = LamaConfig(configfile)
        except OSError as e:
            logging.error(f'Cannot open LAMA config file: {str(configfile)}\n{e}')
            raise
        except Exception as e:
            raise(LamaConfigError(e))

        config.mkdir('output_dir')
        qc_dir = config.mkdir('qc_dir')
        config.mkdir('average_folder')
        config.mkdir('root_reg_dir')

        # TODO find the histogram batch code
        # if not config['no_qc']:
        #     input_histogram_dir = config.mkdir('input_image_histograms')
        #     make_histograms(config['inputs'], input_histogram_dir)

        logpath = config.config_path.parent / LOG_FILE  # Make log in same directory as config file
        common.init_logging(logpath)

        if not common.test_installation('elastix'):
            raise OSError('Make sure elastix is installed')

        # Catch ctr-c signals so we can write that to logs
        # signal.signal(signal.SIGTERM, common.service_shutdown)
        signal.signal(signal.SIGINT, common.service_shutdown)

        mem_monitor = MonitorMemory(Path(config['output_dir']).absolute())

        # Disable QC output?
        no_qc: bool = config['no_qc']

        logging.info(common.git_log())  # If running from a git repo, log the branch and commit #

        logging.info("Registration started")

        first_stage_only = config['skip_forward_registration']
        # If we only want the reverse label propagation we just need the initial rigid registration to act as the
        # Fixed image for the moving populaiton average
        final_registration_dir = run_registration_schedule(config, first_stage_only=first_stage_only)

        if not first_stage_only:
            neg_jac = make_deformations_at_different_scales(config)
            folding_report(neg_jac, config['output_dir'], config['label_info'], outdir=config['output_dir'])

            create_glcms(config, final_registration_dir)

        # Write out the names of the registration dirs in the order they were run
        with open(config['root_reg_dir'] / REG_DIR_ORDER_CFG, 'w') as fh:
            for reg_stage in config['registration_stage_params']:
                fh.write(f'{reg_stage["stage_id"]}\n')
                if first_stage_only:
                    break

        if config['skip_transform_inversion']:
            logging.info('Skipping inversion of transforms')
        else:
            logging.info('inverting transforms')

            if config['label_propagation'] == 'reverse_registration':
                reverse_registration(config)
            else:  # invert_transform method is the default
                batch_invert_transform_parameters(config)

            logging.info('propagating volumes')
            invert_volumes(config)

            # Now that labels have been inverted, should we delete the transorm files?
            if config['delete_inverted_transforms']:
                shutil.rmtree(config['output_dir'] / 'inverted_transforms')

            if config['label_map']:

                generate_organ_volumes(config)

                if config['seg_plugin_dir']:
                    plugin_interface.secondary_segmentation(config)

        if not generate_staging_data(config):
            logging.warning('No staging data generated')

        if not no_qc:

            rev_reg = True if config['label_propagation'] == 'reverse_registration' else False
            make_qc_images(config.config_dir, config['fixed_volume'], qc_dir, mask=None,
                           reverse_reg_propagation=rev_reg)

        mem_monitor.stop()

        return True

        This is the main function Lama script for generating data from registering volumes
        It reads in the config file, creates directories, and initialises the registration process.

        Looks for paths to inputs relative the directory containing the config file

        Parameters
        ----------
        param config
            A toml config file
        
This is the main function Lama script for generating data from registering volumes
It reads in the config file, creates directories, and initialises the registration process.

Looks for paths to inputs relative the directory containing the config file

Parameters

param config
A toml config file
This is the main function Lama script for generating data from registering volumes It reads in the config file creates directories and initialises the registration process . Looks for paths to inputs relative the directory containing the config file Parameters param config A toml config file
def run(configfile: Path):
        try:
            config = LamaConfig(configfile)
        except OSError as e:
            logging.error(f'Cannot open LAMA config file: {str(configfile)}\n{e}')
            raise
        except Exception as e:
            raise(LamaConfigError(e))
        config.mkdir('output_dir')
        qc_dir = config.mkdir('qc_dir')
        config.mkdir('average_folder')
        config.mkdir('root_reg_dir')
        logpath = config.config_path.parent / LOG_FILE  
        common.init_logging(logpath)
        if not common.test_installation('elastix'):
            raise OSError('Make sure elastix is installed')
        signal.signal(signal.SIGINT, common.service_shutdown)
        mem_monitor = MonitorMemory(Path(config['output_dir']).absolute())
        no_qc: bool = config['no_qc']
        logging.info(common.git_log())  
        logging.info("Registration started")
        first_stage_only = config['skip_forward_registration']
        final_registration_dir = run_registration_schedule(config, first_stage_only=first_stage_only)
        if not first_stage_only:
            neg_jac = make_deformations_at_different_scales(config)
            folding_report(neg_jac, config['output_dir'], config['label_info'], outdir=config['output_dir'])
            create_glcms(config, final_registration_dir)
        with open(config['root_reg_dir'] / REG_DIR_ORDER_CFG, 'w') as fh:
            for reg_stage in config['registration_stage_params']:
                fh.write(f'{reg_stage["stage_id"]}\n')
                if first_stage_only:
                    break
        if config['skip_transform_inversion']:
            logging.info('Skipping inversion of transforms')
        else:
            logging.info('inverting transforms')
            if config['label_propagation'] == 'reverse_registration':
                reverse_registration(config)
            else:  
                batch_invert_transform_parameters(config)
            logging.info('propagating volumes')
            invert_volumes(config)
            if config['delete_inverted_transforms']:
                shutil.rmtree(config['output_dir'] / 'inverted_transforms')
            if config['label_map']:
                generate_organ_volumes(config)
                if config['seg_plugin_dir']:
                    plugin_interface.secondary_segmentation(config)
        if not generate_staging_data(config):
            logging.warning('No staging data generated')
        if not no_qc:
            rev_reg = True if config['label_propagation'] == 'reverse_registration' else False
            make_qc_images(config.config_dir, config['fixed_volume'], qc_dir, mask=None,
                           reverse_reg_propagation=rev_reg)
        mem_monitor.stop()
        return True
def run ( configfile : Path ) : try : config = LamaConfig ( configfile ) except OSError as e : logging . error ( f'Cannot open LAMA config file: {str(configfile)}\n{e}' ) raise except Exception as e : raise ( LamaConfigError ( e ) ) config . mkdir ( 'output_dir' ) qc_dir = config . mkdir ( 'qc_dir' ) config . mkdir ( 'average_folder' ) config . mkdir ( 'root_reg_dir' ) logpath = config . config_path . parent / LOG_FILE common . init_logging ( logpath ) if not common . test_installation ( 'elastix' ) : raise OSError ( 'Make sure elastix is installed' ) signal . signal ( signal . SIGINT , common . service_shutdown ) mem_monitor = MonitorMemory ( Path ( config [ 'output_dir' ] ) . absolute ( ) ) no_qc : bool = config [ 'no_qc' ] logging . info ( common . git_log ( ) ) logging . info ( "Registration started" ) first_stage_only = config [ 'skip_forward_registration' ] final_registration_dir = run_registration_schedule ( config , first_stage_only = first_stage_only ) if not first_stage_only : neg_jac = make_deformations_at_different_scales ( config ) folding_report ( neg_jac , config [ 'output_dir' ] , config [ 'label_info' ] , outdir = config [ 'output_dir' ] ) create_glcms ( config , final_registration_dir ) with open ( config [ 'root_reg_dir' ] / REG_DIR_ORDER_CFG , 'w' ) as fh : for reg_stage in config [ 'registration_stage_params' ] : fh . write ( f'{reg_stage["stage_id"]}\n' ) if first_stage_only : break if config [ 'skip_transform_inversion' ] : logging . info ( 'Skipping inversion of transforms' ) else : logging . info ( 'inverting transforms' ) if config [ 'label_propagation' ] == 'reverse_registration' : reverse_registration ( config ) else : batch_invert_transform_parameters ( config ) logging . info ( 'propagating volumes' ) invert_volumes ( config ) if config [ 'delete_inverted_transforms' ] : shutil . rmtree ( config [ 'output_dir' ] / 'inverted_transforms' ) if config [ 'label_map' ] : generate_organ_volumes ( config ) if config [ 'seg_plugin_dir' ] : plugin_interface . secondary_segmentation ( config ) if not generate_staging_data ( config ) : logging . warning ( 'No staging data generated' ) if not no_qc : rev_reg = True if config [ 'label_propagation' ] == 'reverse_registration' else False make_qc_images ( config . config_dir , config [ 'fixed_volume' ] , qc_dir , mask = None , reverse_reg_propagation = rev_reg ) mem_monitor . stop ( ) return True
This is the main function Lama script for generating data from registering volumes
It reads in the config file, creates directories, and initialises the registration process.
This is the main function Lama script for generating data from registering volumes It reads in the config file creates directories and initialises the registration process .
"""
        This is the main function Lama script for generating data from registering volumes
        It reads in the config file, creates directories, and initialises the registration process.

        Looks for paths to inputs relative the directory containing the config file

        Parameters
        ----------
        param config
            A toml config file
        """ # TODO find the histogram batch code # if not config['no_qc']: #     input_histogram_dir = config.mkdir('input_image_histograms') #     make_histograms(config['inputs'], input_histogram_dir) # Make log in same directory as config file # Catch ctr-c signals so we can write that to logs # signal.signal(signal.SIGTERM, common.service_shutdown) # Disable QC output? # If running from a git repo, log the branch and commit # # If we only want the reverse label propagation we just need the initial rigid registration to act as the # Fixed image for the moving populaiton average # Write out the names of the registration dirs in the order they were run # invert_transform method is the default # Now that labels have been inverted, should we delete the transorm files?
configfile
Path