Skip to content

Commit

Permalink
Updated running scripts for niftymic (target resolution specified) an…
Browse files Browse the repository at this point in the history
…d nesvor (properly define the slices output folder if specified)
  • Loading branch information
t-sanchez committed May 15, 2023
1 parent 0794cc9 commit 74f9b69
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
4 changes: 1 addition & 3 deletions fetal_brain_utils/cli/run_nesvor_from_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,10 @@ def crop_input(sub, ses, output_path, img_list, mask_list, fake_run):
imc = crop_path(im, m)
maskc = crop_path(m, m)
# Masking

if imc is None:
print(f"Skipping image {im_file} (empty crop)")
continue
imc = ni.Nifti1Image(imc.get_fdata() * maskc.get_fdata(), imc.affine)
print(im_file, imc.shape)
ni.save(imc, cropped_im_path)
ni.save(maskc, cropped_mask_path)
if imc is not None:
Expand Down Expand Up @@ -208,7 +206,7 @@ def iterate_subject(
img_str = " ".join([str(im) for im in img_list])
mask_str = " ".join([str(m) for m in mask_list])
model = output_sub_ses / f"{sub_ses_path}_{run_path}_model.pt"
sigmas = output_sub_ses / "slices"
sigmas = output_sub_ses / f"slices_run-{run_id}"
for i, res in enumerate(target_res):
res_str = str(res).replace(".", "p")
output_str = (
Expand Down
20 changes: 16 additions & 4 deletions fetal_brain_utils/cli/run_niftymic.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def iterate_subject(
alpha,
participant_label,
use_preprocessed,
resolution,
fake_run,
):
if participant_label:
Expand Down Expand Up @@ -142,7 +143,9 @@ def iterate_subject(
os.makedirs(mask_cropped_path, exist_ok=True)

# Get in-plane resolution to be set as target resolution.
resolution = ni.load(img_list[0]).header["pixdim"][1]
resolution = (
ni.load(img_list[0]).header["pixdim"][1] if resolution is None else resolution
)

# Construct the path to each data point and mask in
# the filesystem of the docker image
Expand Down Expand Up @@ -276,6 +279,13 @@ def main(argv=None):
type=int,
)

p.add_argument(
"--resolution",
default=None,
help="Target resolution (default = in-plane resolution)",
type=float,
)

p.add_argument(
"--use_preprocessed",
action="store_true",
Expand All @@ -285,21 +295,22 @@ def main(argv=None):

args = p.parse_args(argv)
data_path = Path(args.data_path).resolve()
config = Path(args.config)
config = Path(args.config).resolve()
masks_folder = Path(args.masks_path).resolve()
out_path = Path(args.out_path).resolve()
alpha = args.alpha
participant_label = args.participant_label
use_preprocessed = args.use_preprocessed
resolution = args.resolution
nprocs = args.nprocs
fake_run = args.fake_run

# Load a dictionary of subject-session-paths
# sub_ses_dict = iter_dir(data_path, add_run_only=True)

bids_layout = BIDSLayout(data_path, validate=True)
bids_layout = BIDSLayout(data_path, validate=False)

with open(data_path / "code" / config, "r") as f:
with open(config, "r") as f:
params = json.load(f)
# Iterate over all subjects and sessions
iterate = partial(
Expand All @@ -312,6 +323,7 @@ def main(argv=None):
alpha=alpha,
participant_label=participant_label,
use_preprocessed=use_preprocessed,
resolution=resolution,
fake_run=fake_run,
)
if nprocs > 1:
Expand Down

0 comments on commit 74f9b69

Please sign in to comment.