From 060b0cc9f24b695803d577705534bf7cc00975d7 Mon Sep 17 00:00:00 2001 From: Eilidh MacNicol Date: Mon, 8 Feb 2021 18:00:43 +0000 Subject: [PATCH 1/7] enh: update sigma scaling equation --- nirodents/workflows/brainextraction.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nirodents/workflows/brainextraction.py b/nirodents/workflows/brainextraction.py index c6e08d3..49fc818 100644 --- a/nirodents/workflows/brainextraction.py +++ b/nirodents/workflows/brainextraction.py @@ -474,4 +474,4 @@ def _lap_sigma(in_file): img = nb.load(in_file) min_vox = np.amin(img.header.get_zooms()) - return str(0.3508 * math.exp(1.4652 * min_vox)) + return str(1.5 * min_vox ** 0.5) From bf05fd2f60d90ca7a37c988601c76d7ffac4d3e2 Mon Sep 17 00:00:00 2001 From: Eilidh MacNicol Date: Wed, 10 Feb 2021 09:41:22 +0000 Subject: [PATCH 2/7] ENH: N4 improvements --- nirodents/workflows/brainextraction.py | 28 +++++++++++++------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/nirodents/workflows/brainextraction.py b/nirodents/workflows/brainextraction.py index 49fc818..d1c735b 100644 --- a/nirodents/workflows/brainextraction.py +++ b/nirodents/workflows/brainextraction.py @@ -137,7 +137,6 @@ def init_rodent_brain_extraction_wf( norm_lap_target = pe.Node(niu.Function(function=_trunc), name="norm_lap_target") norm_lap_target.inputs.out_max = 1.0 norm_lap_target.inputs.percentiles = (1, 99.99) - norm_lap_target.inputs.clip_max = None # Set up initial spatial normalization ants_params = "testing" if debug else "precise" @@ -167,8 +166,8 @@ def init_rodent_brain_extraction_wf( clip_tmpl.inputs.percentiles = (35.0, 90.0) # set INU bspline grid based on voxel size - init_bspline_grid = pe.Node(niu.Function(function=_bspline_distance), name="init_bspline_grid") - init_bspline_grid.inputs.slice_dir = slice_direction + bspline_grid = pe.Node(niu.Function(function=_bspline_grid), name="bspline_grid") + # init_bspline_grid.inputs.slice_dir = slice_direction # INU correction of the target image init_n4 = pe.Node( @@ -200,8 +199,8 @@ def init_rodent_brain_extraction_wf( wf.connect([ # Target image massaging (inputnode, clip_target, [(("in_files", _pop), "in_file")]), - (inputnode, init_bspline_grid, [(("in_files", _pop), "in_file")]), - (init_bspline_grid, init_n4, [("out", "args")]), + (inputnode, bspline_grid, [(("in_files", _pop), "in_file")]), + (bspline_grid, init_n4, [("out", "args")]), (clip_target, denoise, [("out", "input_image")]), (denoise, init_n4, [("output_image", "input_image")]), (init_n4, clip_inu, [("output_image", "in_file")]), @@ -274,6 +273,7 @@ def init_rodent_brain_extraction_wf( # fmt: off wf.connect([ (inputnode, map_brainmask, [(("in_files", _pop), "reference_image")]), + (bspline_grid, final_n4, [("out", "args")]), (denoise, final_n4, [("output_image", "input_image")]), # Project template's brainmask into subject space (norm, map_brainmask, [("reverse_transforms", "transforms"), @@ -453,18 +453,18 @@ def _pop(in_files): return in_files -def _bspline_distance(in_file, spacings=(8, 10, 8), slice_dir=1): - import numpy as np +def _bspline_grid(in_file): import nibabel as nb + import numpy as np img = nb.load(in_file) - zooms = img.header.get_zooms()[:3] - zooms_round = [round(x, 3) for x in zooms] - extent = (np.array(img.shape[:3]) - 1) * zooms - if zooms_round.count(zooms_round[0]) != 3 and np.argmax(zooms) != slice_dir: - extent[np.argmax(zooms)], extent[slice_dir] = extent[slice_dir], extent[np.argmax(zooms)] - retval = [f"{v}" for v in np.ceil(extent / np.array(spacings)).astype(int)] - return f"-b [{'x'.join(retval)}]" + slices = img.header.get_data_shape() + # get slice ratio + ratio = [s / slices[np.argmax(slices)] for s in slices] + ratio_factor = ratio[np.argmax(ratio)]/ratio[np.argmin(ratio)] + # turn into integer resolution + mesh_res = [ f"{round(i * ratio_factor)}" for i in ratio ] + return f"-b [{'x'.join(mesh_res)}]" def _lap_sigma(in_file): From 740617df14aca43484dc000be3d30f24b4717108 Mon Sep 17 00:00:00 2001 From: Eilidh MacNicol Date: Wed, 10 Feb 2021 09:44:51 +0000 Subject: [PATCH 3/7] ENH: laplacian improvements --- nirodents/data/artsBrainExtraction_precise_T2w.json | 2 +- nirodents/workflows/brainextraction.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/nirodents/data/artsBrainExtraction_precise_T2w.json b/nirodents/data/artsBrainExtraction_precise_T2w.json index 50c965c..47ee3e8 100644 --- a/nirodents/data/artsBrainExtraction_precise_T2w.json +++ b/nirodents/data/artsBrainExtraction_precise_T2w.json @@ -12,7 +12,7 @@ "metric_weight": [ 1, 1, - [0.5, 0.5] + [0.4, 0.6] ], "number_of_iterations": [ [1000, 500, 250, 100], diff --git a/nirodents/workflows/brainextraction.py b/nirodents/workflows/brainextraction.py index d1c735b..1970970 100644 --- a/nirodents/workflows/brainextraction.py +++ b/nirodents/workflows/brainextraction.py @@ -128,7 +128,7 @@ def init_rodent_brain_extraction_wf( norm_lap_tmpl = pe.Node(niu.Function(function=_trunc), name="norm_lap_tmpl") norm_lap_tmpl.inputs.out_max = 1.0 norm_lap_tmpl.inputs.percentiles = (1, 99.99) - norm_lap_tmpl.inputs.clip_max = None + norm_lap_tmpl.inputs.clip_max = 99.9 target_sigma = pe.Node(niu.Function(function=_lap_sigma), name="target_sigma", run_without_submitting=True) lap_target = pe.Node( @@ -137,6 +137,7 @@ def init_rodent_brain_extraction_wf( norm_lap_target = pe.Node(niu.Function(function=_trunc), name="norm_lap_target") norm_lap_target.inputs.out_max = 1.0 norm_lap_target.inputs.percentiles = (1, 99.99) + norm_lap_tmpl.inputs.clip_max = 99.9 # Set up initial spatial normalization ants_params = "testing" if debug else "precise" @@ -474,4 +475,4 @@ def _lap_sigma(in_file): img = nb.load(in_file) min_vox = np.amin(img.header.get_zooms()) - return str(1.5 * min_vox ** 0.5) + return str(1.5 * min_vox ** 0.75) From 61d4e454313f583d646547d67bff019fafc3409d Mon Sep 17 00:00:00 2001 From: Eilidh MacNicol Date: Wed, 10 Feb 2021 09:48:51 +0000 Subject: [PATCH 4/7] MAINT: tidy up and remove unused cli args --- nirodents/cli/brainextraction.py | 11 ----------- nirodents/workflows/brainextraction.py | 4 +--- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/nirodents/cli/brainextraction.py b/nirodents/cli/brainextraction.py index e4ebc0e..1bc16d2 100644 --- a/nirodents/cli/brainextraction.py +++ b/nirodents/cli/brainextraction.py @@ -122,16 +122,6 @@ def get_parser(): default=(0, 4, 4), help="Specify ants-ai Search Grid parameter", ) - - parser.add_argument( - "--slice-direction", - dest="slice_direction", - action="store", - type=int, - default=1, - choices=[0, 1, 2], - help="Specify slice direction: 0 = Sagittal (R-L), 1 = Coronal (A-P), 2 = Axial (S-I)", - ) return parser @@ -148,7 +138,6 @@ def main(): arc=opts.antsai_arcfrac, step=opts.antsai_step, grid=tuple(opts.antsai_grid), - slice_direction=opts.slice_direction, debug=opts.debug, mri_scheme=opts.mri_scheme, omp_nthreads=opts.omp_nthreads, diff --git a/nirodents/workflows/brainextraction.py b/nirodents/workflows/brainextraction.py index 1970970..f64133a 100644 --- a/nirodents/workflows/brainextraction.py +++ b/nirodents/workflows/brainextraction.py @@ -48,7 +48,6 @@ def init_rodent_brain_extraction_wf( arc=0.12, step=4, grid=(0, 4, 4), - slice_direction=1, debug=False, interim_checkpoints=True, mem_gb=3.0, @@ -137,7 +136,7 @@ def init_rodent_brain_extraction_wf( norm_lap_target = pe.Node(niu.Function(function=_trunc), name="norm_lap_target") norm_lap_target.inputs.out_max = 1.0 norm_lap_target.inputs.percentiles = (1, 99.99) - norm_lap_tmpl.inputs.clip_max = 99.9 + norm_lap_target.inputs.clip_max = 99.9 # Set up initial spatial normalization ants_params = "testing" if debug else "precise" @@ -168,7 +167,6 @@ def init_rodent_brain_extraction_wf( # set INU bspline grid based on voxel size bspline_grid = pe.Node(niu.Function(function=_bspline_grid), name="bspline_grid") - # init_bspline_grid.inputs.slice_dir = slice_direction # INU correction of the target image init_n4 = pe.Node( From a058c547dcc5707b0595c2b685a17096bf2b4b28 Mon Sep 17 00:00:00 2001 From: Eilidh MacNicol Date: Wed, 10 Feb 2021 09:58:49 +0000 Subject: [PATCH 5/7] maint: pep8 changes --- nirodents/workflows/brainextraction.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nirodents/workflows/brainextraction.py b/nirodents/workflows/brainextraction.py index f64133a..1b9240b 100644 --- a/nirodents/workflows/brainextraction.py +++ b/nirodents/workflows/brainextraction.py @@ -460,9 +460,9 @@ def _bspline_grid(in_file): slices = img.header.get_data_shape() # get slice ratio ratio = [s / slices[np.argmax(slices)] for s in slices] - ratio_factor = ratio[np.argmax(ratio)]/ratio[np.argmin(ratio)] + ratio_factor = ratio[np.argmax(ratio)] / ratio[np.argmin(ratio)] # turn into integer resolution - mesh_res = [ f"{round(i * ratio_factor)}" for i in ratio ] + mesh_res = [f"{round(i * ratio_factor)}" for i in ratio] return f"-b [{'x'.join(mesh_res)}]" From b98035da11d3c60fb8022a0c2b2ad24602d691cf Mon Sep 17 00:00:00 2001 From: Eilidh MacNicol Date: Thu, 11 Feb 2021 14:37:50 +0000 Subject: [PATCH 6/7] FIX: update dockerfile dependency versions --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1d040b8..634d221 100644 --- a/Dockerfile +++ b/Dockerfile @@ -77,9 +77,9 @@ ENV PATH=/usr/local/miniconda/bin:$PATH \ RUN conda install -y python=3.7.1 \ mkl=2018.0.3 \ mkl-service \ - numpy=1.15.4 \ + numpy>=1.16.5 \ scipy=1.1.0 \ - scikit-learn=0.19.1 \ + scikit-learn>=0.20 \ matplotlib=2.2.2 \ pandas=0.23.4 \ libxml2=2.9.8 \ From cd2551f15d14f76344724c81794b1b861438c671 Mon Sep 17 00:00:00 2001 From: Eilidh MacNicol Date: Tue, 23 Feb 2021 09:14:49 +0000 Subject: [PATCH 7/7] PIN: svgutils to previous version --- setup.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.cfg b/setup.cfg index 33fd2ce..41922d3 100644 --- a/setup.cfg +++ b/setup.cfg @@ -25,6 +25,7 @@ install_requires = nipype ~= 1.5.1 niworkflows ~= 1.3.2 templateflow ~= 0.6 + svgutils == 0.3.1 test_requires = coverage < 5 pytest >= 4.4