lama/registration_pipeline/run_lama.py
def generate_elx_parameters(config: LamaConfig,
                            do_pairwise: bool = False,
                            ) -> OrderedDict:
    """
    Generate an ordered dictionary of elastix parameters for each stage.
    Merge global parameters into each stage.
    Inherit parameters from previous stages when required (if inherit_elx_params is specified)
    Overide globals parameters with stage-specific parameters.

    Parameters
    ----------
    config: dict
        the main config
    do_pairwise: Bool
        if True set elestix parameters to write result image

    Returns
    -------
    dict:
        elastix parameters for each stage
        stage_id: {elastix paramters}...
    """
    stage_params = OrderedDict()
    for i, reg_stage in enumerate(config['registration_stage_params']):

        stage_id = reg_stage['stage_id']
        elxparams_formated = []
        # param_vals = []  # The parameters to format
        params = {}


        inherit_stage = reg_stage.get('inherit_elx_params')
        if inherit_stage:  # Use another stage's params as a starting point

            # Find the referenced stage's parameters
            referenced_stage_found = False
            for stage in config['registration_stage_params']:
                if stage['stage_id'] == inherit_stage:
                    referenced_stage_found = True
                    inherited_params = copy.deepcopy(stage['elastix_parameters'])
                    #  Overwrite the inherited params with this stage-specific ones
                    for k, v in reg_stage['elastix_parameters'].items():
                        inherited_params[k] = v
                    # Now replace the stage-specific params with the merged new param dict
                    reg_stage['elastix_parameters'] = inherited_params

            if not referenced_stage_found:
                sys.exit("Cannot inherit parameters from the stage: {}. Stage Not found. Check the config file".format(
                    stage_params['inherit_elx_params']))

        # Merge the global and stage-specific parameters
        global_params = config['global_elastix_params']

        # Make sure result image is written if using taregt based registration. Needed for the moving images of the
        # next stage
        if (do_pairwise and reg_stage['elastix_parameters']['Transform'] == 'EulerTransform') or (not do_pairwise):
            reg_stage['elastix_parameters']['WriteResultImage'] = 'true'
        else:
            reg_stage['elastix_parameters']['WriteResultImage'] = 'false'
        global_params.pop('WriteResultImage', None)

        # global_params.update(extra_global_params)
        params.update(reg_stage['elastix_parameters'])
        params.update(global_params)

        # for p in param_vals:
        for param_name, param_value in params.items():
            if isinstance(param_value, list):  # parameter with multiple values for each resolution
                # check whether we have didgets or strings, the latter need quoting
                if all(common.is_number(v) for v in param_value):
                    val_list = [str(s).format() for s in param_value]
                    val_string = ' '.join(val_list)
                else:
                    val_list = [str(s).format() for s in param_value]
                    val_quoted = ['"{}"'.format(s) for s in val_list]
                    val_string = ' '.join(val_quoted)
                elxparams_formated.append('({0}  {1})\n'.format(param_name, val_string))
            else:  # Find a nicer way to do this
                if common.is_number(param_value):
                    elxparams_formated.append('({0}  {1})\n'.format(param_name, param_value))
                else:
                    elxparams_formated.append('({0}  "{1}")\n'.format(param_name, param_value))

        stage_params[stage_id] = ''.join(elxparams_formated)
    return stage_params

    Generate an ordered dictionary of elastix parameters for each stage.
    Merge global parameters into each stage.
    Inherit parameters from previous stages when required (if inherit_elx_params is specified)
    Overide globals parameters with stage-specific parameters.

    Parameters
    ----------
    config: dict
        the main config
    do_pairwise: Bool
        if True set elestix parameters to write result image

    Returns
    -------
    dict:
        elastix parameters for each stage
        stage_id: {elastix paramters}...
    
Generate an ordered dictionary of elastix parameters for each stage.
Merge global parameters into each stage.
Inherit parameters from previous stages when required (if inherit_elx_params is specified)
Overide globals parameters with stage-specific parameters.

Parameters

dict
the main config
do_pairwise: Bool
if True set elestix parameters to write result image

Returns

elastix parameters for each stage
stage_id: {elastix paramters}
Generate an ordered dictionary of elastix parameters for each stage . Merge global parameters into each stage . Inherit parameters from previous stages when required ( if inherit_elx_params is specified ) Overide globals parameters with stage - specific parameters . Parameters dict the main config do_pairwise : Bool if True set elestix parameters to write result image Returns elastix parameters for each stage stage_id : { elastix paramters }
def generate_elx_parameters(config: LamaConfig,
                            do_pairwise: bool = False,
                            ) -> OrderedDict:
    stage_params = OrderedDict()
    for i, reg_stage in enumerate(config['registration_stage_params']):
        stage_id = reg_stage['stage_id']
        elxparams_formated = []
        params = {}
        inherit_stage = reg_stage.get('inherit_elx_params')
        if inherit_stage:  
            referenced_stage_found = False
            for stage in config['registration_stage_params']:
                if stage['stage_id'] == inherit_stage:
                    referenced_stage_found = True
                    inherited_params = copy.deepcopy(stage['elastix_parameters'])
                    for k, v in reg_stage['elastix_parameters'].items():
                        inherited_params[k] = v
                    reg_stage['elastix_parameters'] = inherited_params
            if not referenced_stage_found:
                sys.exit("Cannot inherit parameters from the stage: {}. Stage Not found. Check the config file".format(
                    stage_params['inherit_elx_params']))
        global_params = config['global_elastix_params']
        if (do_pairwise and reg_stage['elastix_parameters']['Transform'] == 'EulerTransform') or (not do_pairwise):
            reg_stage['elastix_parameters']['WriteResultImage'] = 'true'
        else:
            reg_stage['elastix_parameters']['WriteResultImage'] = 'false'
        global_params.pop('WriteResultImage', None)
        params.update(reg_stage['elastix_parameters'])
        params.update(global_params)
        for param_name, param_value in params.items():
            if isinstance(param_value, list):  
                if all(common.is_number(v) for v in param_value):
                    val_list = [str(s).format() for s in param_value]
                    val_string = ' '.join(val_list)
                else:
                    val_list = [str(s).format() for s in param_value]
                    val_quoted = ['"{}"'.format(s) for s in val_list]
                    val_string = ' '.join(val_quoted)
                elxparams_formated.append('({0}  {1})\n'.format(param_name, val_string))
            else:  
                if common.is_number(param_value):
                    elxparams_formated.append('({0}  {1})\n'.format(param_name, param_value))
                else:
                    elxparams_formated.append('({0}  "{1}")\n'.format(param_name, param_value))
        stage_params[stage_id] = ''.join(elxparams_formated)
    return stage_params
def generate_elx_parameters ( config : LamaConfig , do_pairwise : bool = False , ) -> OrderedDict : stage_params = OrderedDict ( ) for i , reg_stage in enumerate ( config [ 'registration_stage_params' ] ) : stage_id = reg_stage [ 'stage_id' ] elxparams_formated = [ ] params = { } inherit_stage = reg_stage . get ( 'inherit_elx_params' ) if inherit_stage : referenced_stage_found = False for stage in config [ 'registration_stage_params' ] : if stage [ 'stage_id' ] == inherit_stage : referenced_stage_found = True inherited_params = copy . deepcopy ( stage [ 'elastix_parameters' ] ) for k , v in reg_stage [ 'elastix_parameters' ] . items ( ) : inherited_params [ k ] = v reg_stage [ 'elastix_parameters' ] = inherited_params if not referenced_stage_found : sys . exit ( "Cannot inherit parameters from the stage: {}. Stage Not found. Check the config file" . format ( stage_params [ 'inherit_elx_params' ] ) ) global_params = config [ 'global_elastix_params' ] if ( do_pairwise and reg_stage [ 'elastix_parameters' ] [ 'Transform' ] == 'EulerTransform' ) or ( not do_pairwise ) : reg_stage [ 'elastix_parameters' ] [ 'WriteResultImage' ] = 'true' else : reg_stage [ 'elastix_parameters' ] [ 'WriteResultImage' ] = 'false' global_params . pop ( 'WriteResultImage' , None ) params . update ( reg_stage [ 'elastix_parameters' ] ) params . update ( global_params ) for param_name , param_value in params . items ( ) : if isinstance ( param_value , list ) : if all ( common . is_number ( v ) for v in param_value ) : val_list = [ str ( s ) . format ( ) for s in param_value ] val_string = ' ' . join ( val_list ) else : val_list = [ str ( s ) . format ( ) for s in param_value ] val_quoted = [ '"{}"' . format ( s ) for s in val_list ] val_string = ' ' . join ( val_quoted ) elxparams_formated . append ( '({0}  {1})\n' . format ( param_name , val_string ) ) else : if common . is_number ( param_value ) : elxparams_formated . append ( '({0}  {1})\n' . format ( param_name , param_value ) ) else : elxparams_formated . append ( '({0}  "{1}")\n' . format ( param_name , param_value ) ) stage_params [ stage_id ] = '' . join ( elxparams_formated ) return stage_params
Generate an ordered dictionary of elastix parameters for each stage.
Generate an ordered dictionary of elastix parameters for each stage .
"""
    Generate an ordered dictionary of elastix parameters for each stage.
    Merge global parameters into each stage.
    Inherit parameters from previous stages when required (if inherit_elx_params is specified)
    Overide globals parameters with stage-specific parameters.

    Parameters
    ----------
    config: dict
        the main config
    do_pairwise: Bool
        if True set elestix parameters to write result image

    Returns
    -------
    dict:
        elastix parameters for each stage
        stage_id: {elastix paramters}...
    """ # param_vals = []  # The parameters to format # Use another stage's params as a starting point # Find the referenced stage's parameters #  Overwrite the inherited params with this stage-specific ones # Now replace the stage-specific params with the merged new param dict # Merge the global and stage-specific parameters # Make sure result image is written if using taregt based registration. Needed for the moving images of the # next stage # global_params.update(extra_global_params) # for p in param_vals: # parameter with multiple values for each resolution # check whether we have didgets or strings, the latter need quoting # Find a nicer way to do this
config
LamaConfig
do_pairwise
bool