Skip to content

Commit

Permalink
Save the baseline image to a file.
Browse files Browse the repository at this point in the history
  • Loading branch information
FredLoney committed May 24, 2017
1 parent 46528e9 commit da47165
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions qipipe/pipeline/modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,15 +465,15 @@ def _create_bolero_workflow(self, **opts):
setattr(input_spec.inputs, field, value)

# Create the DCE baseline image.
make_base_xfc = Function(
make_baseline_xfc = Function(
input_names=['time_series', 'baseline_end_idx'],
output_names=['baseline'], function=make_baseline
)
make_base = pe.Node(make_base_xfc, name='make_base')
make_baseline = pe.Node(make_baseline_xfc, name='make_baseline')
workflow.connect(input_spec, 'time_series',
make_base, 'time_series')
make_baseline, 'time_series')
workflow.connect(input_spec, 'baseline_end_idx',
make_base, 'baseline_end_idx')
make_baseline, 'baseline_end_idx')

# If we are not using a fixed r1_0 value, then compute a map
# from a proton density weighted scan and the baseline of the
Expand All @@ -486,7 +486,7 @@ def _create_bolero_workflow(self, **opts):
)
get_r1_0 = pe.Node(get_r1_0_xfc, name='get_r1_0')
workflow.connect(input_spec, 'pd_nii', get_r1_0, 'pdw_image')
workflow.connect(make_base, 'baseline', get_r1_0, 't1w_image')
workflow.connect(make_baseline, 'baseline', get_r1_0, 't1w_image')
workflow.connect(input_spec, 'max_r1_0', get_r1_0, 'max_r1_0')
workflow.connect(input_spec, 'mask', get_r1_0, 'mask')

Expand All @@ -498,7 +498,7 @@ def _create_bolero_workflow(self, **opts):
)
r1_series = pe.Node(r1_series_xfc, name='r1_series')
workflow.connect(input_spec, 'time_series', r1_series, 'time_series')
workflow.connect(make_base, 'baseline', r1_series, 'baseline')
workflow.connect(make_baseline, 'baseline', r1_series, 'baseline')
workflow.connect(input_spec, 'mask', r1_series, 'mask')
if use_fixed_r1_0:
workflow.connect(input_spec, 'r1_0_val', r1_series, 'r1_0')
Expand Down Expand Up @@ -580,7 +580,7 @@ def _create_bolero_workflow(self, **opts):
output_spec, 'delta_k_trans')
# If we are inferring R1_0, then make the DCE baseline.
if not use_fixed_r1_0:
workflow.connect(make_base, 'baseline',
workflow.connect(make_baseline, 'baseline',
output_spec, 'dce_baseline')
workflow.connect(get_r1_0, 'r1_0_map', output_spec, 'r1_0')

Expand Down Expand Up @@ -749,6 +749,7 @@ def make_baseline(time_series, baseline_end_idx):
:raise ModelingError: if the end index is a negative number
"""
from dcmstack.dcmmeta import NiftiWrapper
import nibabel as nb

if baseline_end_idx <= 0:
raise ModelingError("The R1_0 computation baseline end index"
Expand All @@ -765,12 +766,12 @@ def make_baseline(time_series, baseline_end_idx):

if len(baselines) == 1:
return baselines[0]
else:
baseline = NiftiWrapper.from_sequence(baselines)
baseline_img = path.join(os.getcwd(), 'baseline.nii.gz')
nb.save(baseline, baseline_img)

return baseline_img
baseline_nw = NiftiWrapper.from_sequence(baselines)
baseline_path = path.join(os.getcwd(), 'baseline.nii.gz')
nb.save(baseline_nw, baseline_path)

return baseline_path

def get_r1_0(pdw_image, t1w_image, max_r1_0, mask=None):
"""
Expand Down

0 comments on commit da47165

Please sign in to comment.