コード例 #1
0
def mincblob(op : str, grid : MincAtom, subdir : str = "tmp") -> Result[MincAtom]:
    """
    Low-level mincblob wrapper with the one exception being the determinant option. By
    default the inner clockwork of mincblob subtracts 1 from all determinant values that
    are being calculated. As such, 1 needs to be added to the result of the mincblob call.
    We will do that here, because it makes most sense here.
    >>> stages = mincblob('determinant', MincAtom("/images/img_1.mnc", pipeline_sub_dir="/tmp")).stages
    >>> [s.render() for s in stages]
    ['mincblob -clobber -determinant /images/img_1.mnc /tmp/img_1/img_1_determinant.mnc']
    """
    if op not in ["determinant", "trace", "translation", "magnitude"]:
        raise ValueError('mincblob: invalid operation %s' % op)

    # if we are calculating the determinant, the first file produced is a temp file:
    if op == "determinant":
        out_file = grid.newname_with_suffix("_temp_det", subdir=subdir)
    else:
        out_file = grid.newname_with_suffix('_' + op, subdir=subdir)

    stage = CmdStage(inputs=(grid,), outputs=(out_file,),
                 cmd=['mincblob', '-clobber', '-' + op, grid.path, out_file.path])

    s = Stages([stage])
    # now create the proper determinant if that's what was asked for
    if op == "determinant":
        result_file = s.defer(mincmath(op='add',
                                       const=1,
                                       vols=[out_file],
                                       subdir=subdir,
                                       new_name=grid.filename_wo_ext + "_det"))
    else:
        result_file = out_file

    return Result(stages=s, output=result_file)
コード例 #2
0
ファイル: thickness.py プロジェクト: psteadman/pydpiper
def reconstitute_laplacian_grid(cortex  : MincAtom,
                                grid    : MincAtom,
                                midline : MincAtom) -> Result[MincAtom]:
    output_grid = grid.newname_with_suffix("_reconstituted")
    stage = CmdStage(inputs=(cortex, grid, midline), outputs=(output_grid,),
                     cmd=["reconstitute_laplacian_grid", midline.path, cortex.path, grid.path, output_grid.path])
    return Result(stages=Stages([stage]), output=output_grid)
コード例 #3
0
ファイル: analysis.py プロジェクト: MRImagingLi/pydpiper
def smooth_vector(source: MincAtom, fwhm: float) -> Result[MincAtom]:
    outf = source.newname_with_suffix(
        "_smooth_fwhm%s" % fwhm, subdir="tmp")  # TODO smooth_displacement_?
    cmd = [
        'smooth_vector', '--clobber', '--filter',
        '--fwhm=%s' % fwhm, source.path, outf.path
    ]
    stage = CmdStage(inputs=(source, ), outputs=(outf, ), cmd=cmd)
    return Result(stages=Stages([stage]), output=outf)
コード例 #4
0
ファイル: thickness.py プロジェクト: MRImagingLi/pydpiper
def reconstitute_laplacian_grid(cortex: MincAtom, grid: MincAtom,
                                midline: MincAtom) -> Result[MincAtom]:
    output_grid = grid.newname_with_suffix("_reconstituted")
    stage = CmdStage(inputs=(cortex, grid, midline),
                     outputs=(output_grid, ),
                     cmd=[
                         "reconstitute_laplacian_grid", midline.path,
                         cortex.path, grid.path, output_grid.path
                     ])
    return Result(stages=Stages([stage]), output=output_grid)
コード例 #5
0
ファイル: thickness.py プロジェクト: psteadman/pydpiper
def minclaplace(input_grid        : MincAtom,
                extra_args        : List[str] = [],
                solution_vertices : Optional[FileAtom] = None,
                create_surface    : bool = True,) -> Result[FileAtom]:
    # TODO the ambiguity of the return type is slightly annoying ...
    # best to create separate minclaplace_at_vertices for the case when `--solve-at-vertices` is used?
    solved = input_grid.newname_with_suffix("_solved", ext=".txt" if solution_vertices else ".mnc")
    if create_surface:
        out_surface = input_grid.newname_with_suffix("_surface", ext=".obj")
    stage = CmdStage(inputs=(input_grid,), outputs=(solved,) + ((out_surface,) if create_surface else ()),
                     cmd=["minclaplace"]
                         + (["--solve-at-vertices=%s" % solution_vertices.path]
                            if solution_vertices is not None else [])
                         + (["--create-surface=%s" % out_surface.path] if create_surface else [])
                         + extra_args
                         + [input_grid.path, solved.path])

    return Result(stages=Stages([stage]),
                  output=Namespace(solved=solved, surface=out_surface)
                         if create_surface else Namespace(solved=solved))
コード例 #6
0
ファイル: analysis.py プロジェクト: MRImagingLi/pydpiper
def mincblob(op: str, grid: MincAtom, subdir: str = "tmp") -> Result[MincAtom]:
    """
    Low-level mincblob wrapper with the one exception being the determinant option. By
    default the inner clockwork of mincblob subtracts 1 from all determinant values that
    are being calculated. As such, 1 needs to be added to the result of the mincblob call.
    We will do that here, because it makes most sense here.
    >>> stages = mincblob('determinant', MincAtom("/images/img_1.mnc", pipeline_sub_dir="/tmp")).stages
    >>> [s.render() for s in stages]
    ['mincblob -clobber -determinant /images/img_1.mnc /tmp/img_1/img_1_determinant.mnc']
    """
    if op not in ["determinant", "trace", "translation", "magnitude"]:
        raise ValueError('mincblob: invalid operation %s' % op)

    # if we are calculating the determinant, the first file produced is a temp file:
    if op == "determinant":
        out_file = grid.newname_with_suffix("_temp_det", subdir=subdir)
    else:
        out_file = grid.newname_with_suffix('_' + op, subdir=subdir)

    stage = CmdStage(
        inputs=(grid, ),
        outputs=(out_file, ),
        cmd=['mincblob', '-clobber', '-' + op, grid.path, out_file.path])

    s = Stages([stage])
    # now create the proper determinant if that's what was asked for
    if op == "determinant":
        result_file = s.defer(
            mincmath(op='add',
                     const=1,
                     vols=[out_file],
                     subdir=subdir,
                     new_name=grid.filename_wo_ext + "_det"))
    else:
        result_file = out_file

    return Result(stages=s, output=result_file)
コード例 #7
0
ファイル: thickness.py プロジェクト: MRImagingLi/pydpiper
def minclaplace(
    input_grid: MincAtom,
    extra_args: List[str] = [],
    solution_vertices: Optional[FileAtom] = None,
    create_surface: bool = True,
) -> Result[FileAtom]:
    # TODO the ambiguity of the return type is slightly annoying ...
    # best to create separate minclaplace_at_vertices for the case when `--solve-at-vertices` is used?
    solved = input_grid.newname_with_suffix(
        "_solved", ext=".txt" if solution_vertices else ".mnc")
    if create_surface:
        out_surface = input_grid.newname_with_suffix("_surface", ext=".obj")
    stage = CmdStage(
        inputs=(input_grid, ),
        outputs=(solved, ) + ((out_surface, ) if create_surface else ()),
        cmd=["minclaplace"] +
        (["--solve-at-vertices=%s" %
          solution_vertices.path] if solution_vertices is not None else []) +
        (["--create-surface=%s" % out_surface.path] if create_surface else [])
        + extra_args + [input_grid.path, solved.path])

    return Result(stages=Stages([stage]),
                  output=Namespace(solved=solved, surface=out_surface)
                  if create_surface else Namespace(solved=solved))
コード例 #8
0
def smooth_vector(source : MincAtom, fwhm : float) -> Result[MincAtom]:
    outf = source.newname_with_suffix("_smooth_fwhm%s" % fwhm, subdir="tmp") # TODO smooth_displacement_?
    cmd  = ['smooth_vector', '--clobber', '--filter', '--fwhm=%s' % fwhm,
            source.path, outf.path]
    stage = CmdStage(inputs=(source,), outputs=(outf,), cmd=cmd)
    return Result(stages=Stages([stage]), output=outf)