Skip to content

Commit 669fb6a

Browse files
committed
fixed bug in volinterp.py and volalign.py where the final set of tfm files was not defined in chunk_info
1 parent a6b34f8 commit 669fb6a

4 files changed

Lines changed: 32 additions & 34 deletions

File tree

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ python3 -m pip install requirements.txt
2525
python3 -m pip install -e .
2626
```
2727

28+
4) Install Morphint submodule
29+
```
30+
cd morphint
31+
python3 -m pip install -e .
32+
```
33+
34+
2835
## Useage
2936

3037
```python3

brainbuilder/interp/volinterp.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -518,14 +518,16 @@ def apply_interpolated_volumes_to_stx(
518518
.values[0]
519519
)
520520

521-
if not os.path.exists(interp_stx_fin) or clobber:
522-
cmd = f"antsApplyTransforms -d 3 -n {interpolation} -i {interp_nat_fin} -o {interp_stx_fin} -r {ref_vol_rsl_fn} -t {nl_3d_tfm_fn} --float 1"
523-
524-
print(cmd)
525521

526-
run(cmd, shell=True)
522+
utils.simple_ants_apply_transforms(
523+
interp_nat_fin,
524+
interp_stx_fin,
525+
ref_vol_rsl_fn,
526+
nl_3d_tfm_fn,
527+
interpolation=interpolation,
528+
clobber=clobber,
529+
)
527530

528-
assert nib.load(interp_stx_fin).get_fdata().sum() > 0, "Error: Empty Output"
529531

530532
return curr_chunk_info
531533

brainbuilder/utils/validate_inputs.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
import os
33
from typing import Union
44

5-
import nibabel as nib
65
import numpy as np
76
import pandas as pd
87
from joblib import Parallel, cpu_count, delayed
9-
from PIL import Image
108

119
import brainbuilder.utils.utils as utils
1210
from brainbuilder.utils.mesh_io import load_mesh_ext
1311
from brainbuilder.utils.utils import get_logger
12+
import nibabel as nib
13+
from PIL import Image
1414

1515
global chunk_info_required_columns
1616
global sect_info_required_columns
@@ -82,9 +82,9 @@ def val_func(x: Union[int, float, str]) -> bool:
8282
sub = Column("sub", None)
8383
hemisphere = Column("hemisphere", None)
8484
chunk = Column("chunk", None)
85-
# direction = Column("direction", None) #DEPRECIATED
86-
# pixel_size_0 = Column("pixel_size_0", float) #DEPRECIATED
87-
# pixel_size_1 = Column("pixel_size_1", float) #DEPRECIATED
85+
#direction = Column("direction", None) #DEPRECIATED
86+
#pixel_size_0 = Column("pixel_size_0", float) #DEPRECIATED
87+
#pixel_size_1 = Column("pixel_size_1", float) #DEPRECIATED
8888
section_thickness = Column("section_thickness", float)
8989
acquisition = Column("acquisition", None)
9090
sample = Column("sample", int)
@@ -94,13 +94,12 @@ def val_func(x: Union[int, float, str]) -> bool:
9494
struct_ref_vol = Column("struct_ref_vol", "volume")
9595

9696
# Surfaces
97-
# gm_surf = Column("gm_surf", "surface", False) #DEPRECIATED
98-
# wm_surf = Column("wm_surf", "surface", False) #DEPRECIATED
97+
#gm_surf = Column("gm_surf", "surface", False) #DEPRECIATED
98+
#wm_surf = Column("wm_surf", "surface", False) #DEPRECIATED
9999

100-
101-
chunk_info_required_columns = [sub, hemisphere, chunk, section_thickness]
102-
sect_info_required_columns = [acquisition, sub, hemisphere, chunk, raw, sample]
103-
hemi_info_required_columns = [sub, hemisphere, struct_ref_vol]
100+
chunk_info_required_columns = [sub, hemisphere, chunk, section_thickness ]
101+
sect_info_required_columns = [acquisition, sub, hemisphere, chunk, raw, sample ]
102+
hemi_info_required_columns = [sub, hemisphere, struct_ref_vol ]
104103

105104

106105
def validate_dataframe(
@@ -212,7 +211,6 @@ def _can_open_volume(path: str) -> bool:
212211
logger.critical(last_exc)
213212
return False
214213

215-
216214
def validate_volume(fn: str, check_not_empty: bool = False) -> bool:
217215
"""Validate that a volume exists and that it is not empty.
218216
@@ -227,13 +225,13 @@ def validate_volume(fn: str, check_not_empty: bool = False) -> bool:
227225
valid_inputs = False
228226
else:
229227
try:
230-
if check_not_empty:
228+
if check_not_empty :
231229
vol = utils.load_image(fn)
232230

233231
if np.sum(np.abs(vol)) == 0:
234232
valid_inputs = False
235233
logger.info(f"\tMissing input: empty template file {fn}")
236-
else:
234+
else :
237235
valid_inputs = _can_open_volume(fn)
238236

239237
except Exception as e:

brainbuilder/volalign.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,9 @@ def alignment_iteration(
462462

463463
chunk_info_out = paths.to_dataframe()
464464

465+
# set the nl_3d_tfm_fn column in chunk_info_out to the list of 3D transforms used for the current chunk and resolution
466+
chunk_info_out["nl_3d_tfm_fn"] = vol_tfm_list
467+
465468
sect_info_curr_resolution_csv = f"{output_dir}/sub-{sub}_hemi-{hemisphere}_chunk-{chunk}_{resolution}mm_sect_info.csv"
466469

467470
sect_info.to_csv(sect_info_curr_resolution_csv, index=False)
@@ -514,11 +517,6 @@ def align_chunk(
514517
qc_dir = f"{output_dir}/qc/"
515518
os.makedirs(qc_dir, exist_ok=True)
516519

517-
chunk_pass_df = pd.DataFrame()
518-
sect_pass_df = pd.DataFrame()
519-
chunk_pass_last_df = pd.DataFrame()
520-
sect_pass_last_df = pd.DataFrame()
521-
522520
sect_info_out = sect_info
523521
chunk_info_out = chunk_info_row
524522

@@ -604,15 +602,7 @@ def align_chunk(
604602
landmark_dir=landmark_dir,
605603
clobber=clobber,
606604
)
607-
chunk_info_out["pass"] = pass_step
608-
sect_info_out["pass"] = pass_step
609-
610-
chunk_pass_df = pd.concat([chunk_pass_df, chunk_info_out])
611-
sect_pass_df = pd.concat([sect_pass_df, sect_info_out])
612605

613-
if pass_step == n_passes - 1 and resolution == resolution_list[-1]:
614-
chunk_pass_last_df = pd.concat([chunk_pass_last_df, chunk_info_out])
615-
sect_pass_last_df = pd.concat([sect_pass_last_df, sect_info_out])
616606

617607
# un a final alignment
618608

@@ -660,6 +650,7 @@ def align_chunk(
660650
landmark_dir=landmark_dir,
661651
clobber=clobber,
662652
)
653+
chunk_info_out['pass'] = pass_step
663654
logger.info("Finished final alignment iteration at highest resolution")
664655

665-
return chunk_pass_last_df, sect_pass_last_df
656+
return chunk_info_out, sect_info_out

0 commit comments

Comments
 (0)