lama/elastix/invert_transforms.py
def _modify_inverted_tform_file(elx_tform_file: Path, newfile_name: str=None):
    """
    Remove "NoInitialTransform" from the output transform parameter file
    Set output image format to unsigned char. Writes out a modified elastix transform parameter file
    that can be used for inverting volumes

    Parameters
    ----------
    elx_tform_file: str
        path to elastix transform file
    newfile_mame: str
        path to save modified transform file
    """

    if not newfile_name:  # Write to temporary file before overwriting
        new_file = tempfile.NamedTemporaryFile().name
    else:
        new_file = newfile_name

    try:

        with open(new_file, "w+") as new_tform_param_fh,  open(elx_tform_file, "r") as tform_param_fh:

            for line in tform_param_fh:
                if line.startswith('(InitialTransformParametersFileName'):
                    line = '(InitialTransformParametersFileName "NoInitialTransform")\n'
                new_tform_param_fh.write(line)
            new_tform_param_fh.close()
            tform_param_fh.close()

    except IOError:
        logging.warning("Error reading or writing transform files {}".format(elx_tform_file))
        return False

    return True

    Remove "NoInitialTransform" from the output transform parameter file
    Set output image format to unsigned char. Writes out a modified elastix transform parameter file
    that can be used for inverting volumes

    Parameters
    ----------
    elx_tform_file: str
        path to elastix transform file
    newfile_mame: str
        path to save modified transform file
    
Remove "NoInitialTransform" from the output transform parameter file
Set output image format to unsigned char. Writes out a modified elastix transform parameter file
that can be used for inverting volumes

Parameters

str
path to elastix transform file
newfile_mame: str
path to save modified transform file
Remove " NoInitialTransform " from the output transform parameter file Set output image format to unsigned char . Writes out a modified elastix transform parameter file that can be used for inverting volumes Parameters str path to elastix transform file newfile_mame : str path to save modified transform file
def _modify_inverted_tform_file(elx_tform_file: Path, newfile_name: str=None):
    if not newfile_name:  
        new_file = tempfile.NamedTemporaryFile().name
    else:
        new_file = newfile_name
    try:
        with open(new_file, "w+") as new_tform_param_fh,  open(elx_tform_file, "r") as tform_param_fh:
            for line in tform_param_fh:
                if line.startswith('(InitialTransformParametersFileName'):
                    line = '(InitialTransformParametersFileName "NoInitialTransform")\n'
                new_tform_param_fh.write(line)
            new_tform_param_fh.close()
            tform_param_fh.close()
    except IOError:
        logging.warning("Error reading or writing transform files {}".format(elx_tform_file))
        return False
    return True
def _modify_inverted_tform_file ( elx_tform_file : Path , newfile_name : str = None ) : if not newfile_name : new_file = tempfile . NamedTemporaryFile ( ) . name else : new_file = newfile_name try : with open ( new_file , "w+" ) as new_tform_param_fh , open ( elx_tform_file , "r" ) as tform_param_fh : for line in tform_param_fh : if line . startswith ( '(InitialTransformParametersFileName' ) : line = '(InitialTransformParametersFileName "NoInitialTransform")\n' new_tform_param_fh . write ( line ) new_tform_param_fh . close ( ) tform_param_fh . close ( ) except IOError : logging . warning ( "Error reading or writing transform files {}" . format ( elx_tform_file ) ) return False return True
Remove "NoInitialTransform" from the output transform parameter file
Set output image format to unsigned char.
Remove " NoInitialTransform " from the output transform parameter file Set output image format to unsigned char .
"""
    Remove "NoInitialTransform" from the output transform parameter file
    Set output image format to unsigned char. Writes out a modified elastix transform parameter file
    that can be used for inverting volumes

    Parameters
    ----------
    elx_tform_file: str
        path to elastix transform file
    newfile_mame: str
        path to save modified transform file
    """ # Write to temporary file before overwriting
elx_tform_file
Path
newfile_name
str