Skip to content

Commit

Permalink
Add --keep-mask
Browse files Browse the repository at this point in the history
  • Loading branch information
Jennings Zhang authored and Jennings Zhang committed Jun 8, 2022
1 parent 45db8ae commit 1f44e77
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ Arguments to pass to `inflate_to_sphere_implicit`. The default value `(200, 200)
should work for fetal brains. While it shouldn't be necessary, increasing the
values shouldn't do any harm, and would help compensate for larger brain sizes.

#### `--keep-mask`

Copy input mask file to output directory.

`--keep-mask` is a workaround for using `pl-fetal-cp-surface-extract` as part of a
_ChRIS_ pipeline. It eliminates the need for an extra _ts_ plugin step.

## Local Usage

To get started with local command-line usage, use [Apptainer](https://apptainer.org/)
Expand Down
2 changes: 2 additions & 0 deletions extract_cp/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
parser.add_argument('--inflate_to_sphere_implicit', dest='inflate_to_sphere_implicit', type=str, default='200,200',
help='Parameters for inflate_to_sphere_implicit. Larger values are necessary '
'for larger brain size.')
parser.add_argument('-k', '--keep-mask', dest='keep_mask', action='store_true',
help='Copy input mask file to output directory')
parser.add_argument('--no-fail', dest='no_fail', action='store_true',
help='Exit normally even when failed to process a subject')
parser.add_argument('-V', '--version', action='version',
Expand Down
3 changes: 3 additions & 0 deletions extract_cp/extract_surface.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import shutil
from pathlib import Path
from typing import Optional, Sequence, BinaryIO
from civet.extraction.hemisphere import Side, HemisphereMask
Expand All @@ -22,6 +23,8 @@ def extract_surface(mask: Path, surface: Path, params: Parameters):
.adapt_object_mesh(*params.adapt_object_mesh)\
.interpolate_with_sphere(chosen_side, *params.inflate_to_sphere_implicit)\
.save(surface, shell=__curry_log(log))
if params.keep_mask:
shutil.copy(mask, surface.with_name(mask.name))
logger.info('Completed {}', surface)
except Exception as e:
logger.exception('Failed to process {}', mask)
Expand Down
10 changes: 7 additions & 3 deletions extract_cp/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Parameters:
mincmorph_iterations: int
adapt_object_mesh: tuple[int, int, int]
inflate_to_sphere_implicit: tuple[int, int]
keep_mask: bool

def __post_init__(self):
if not len(self.adapt_object_mesh) == 3:
Expand All @@ -28,13 +29,15 @@ def new(
side: SideStr,
mincmorph_iterations: int,
adapt_object_mesh: str,
inflate_to_sphere_implicit: str
inflate_to_sphere_implicit: str,
keep_mask: bool
) -> 'Parameters':
return cls(
side=side,
mincmorph_iterations=mincmorph_iterations,
adapt_object_mesh=_str2ints(adapt_object_mesh),
inflate_to_sphere_implicit=_str2ints(inflate_to_sphere_implicit)
inflate_to_sphere_implicit=_str2ints(inflate_to_sphere_implicit),
keep_mask=keep_mask
)

@classmethod
Expand All @@ -43,7 +46,8 @@ def from_obj(cls, options) -> 'Parameters':
side=options.side,
mincmorph_iterations=options.mincmorph_iterations,
adapt_object_mesh=options.adapt_object_mesh,
inflate_to_sphere_implicit=options.inflate_to_sphere_implicit
inflate_to_sphere_implicit=options.inflate_to_sphere_implicit,
keep_mask=options.keep_mask
)


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='extract_cp',
version='1.0.0',
version='1.1.0',
description='Fetal brain MRI CP surface extraction using CIVET marching-cubes',
author='Jennings Zhang',
author_email='Jennings.Zhang@childrens.harvard.edu',
Expand Down

0 comments on commit 1f44e77

Please sign in to comment.