Skip to content

Commit

Permalink
Adding validation node for TR of bold outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
birajstha committed Sep 11, 2024
1 parent a442aea commit e848147
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
13 changes: 12 additions & 1 deletion CPAC/pipeline/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,7 @@ def gather_pipes(self, wf, cfg, all=False, add_incl=None, add_excl=None):
except OSError as os_error:
WFLOGGER.warning(os_error)
continue

write_json_imports = ["import os", "import json"]
write_json = pe.Node(
Function(
Expand All @@ -1371,6 +1371,17 @@ def gather_pipes(self, wf, cfg, all=False, add_incl=None, add_excl=None):
write_json.inputs.json_data = json_info

wf.connect(id_string, "out_filename", write_json, "filename")

# Node to validate TR (and other scan parameters)
validate_bold_header = pe.Node(
Function(
input_names=["input_resource", "RawSource"],
output_names=["output_resource"],
function=validate_bold_header,
),
name=f"validate_bold_header_{resource_idx}_{pipe_x}",
)

ds = pe.Node(DataSink(), name=f"sinker_{resource_idx}_{pipe_x}")
ds.inputs.parameterization = False
ds.inputs.base_directory = out_dct["out_dir"]
Expand Down
13 changes: 8 additions & 5 deletions CPAC/pipeline/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,22 @@ def update_pixel_dim4(file_path, new_pixdim4):

def validate_outputs(input_bold, RawSource_bold):
"""Match pixdim[4]/TR of the input_bold with RawSource_bold."""
input_pixdim4 = find_pixel_dim4(input_bold)

output_bold = input_bold
output_pixdim4 = find_pixel_dim4(output_bold)
source_pixdim4 = find_pixel_dim4(RawSource_bold)

if input_pixdim4 != source_pixdim4:
if output_pixdim4 != source_pixdim4:
print(f"TR mismatch detected between input_bold and RawSource_bold.")
print(f"input_bold TR: {input_pixdim4} seconds")
print(f"input_bold TR: {output_pixdim4} seconds")
print(f"RawSource_bold TR: {source_pixdim4} seconds")
print(f"Attempting to update the TR of input_bold to match RawSource_bold.")
update_pixel_dim4(input_bold, source_pixdim4)
update_pixel_dim4(output_bold, source_pixdim4)
else:
print(f"TR match detected between input_bold and RawSource_bold.")
print(f"input_bold TR: {input_pixdim4} seconds")
print(f"input_bold TR: {output_pixdim4} seconds")
print(f"RawSource_bold TR: {source_pixdim4} seconds")
return output_bold

def name_fork(resource_idx, cfg, json_info, out_dct):
"""Create and insert entities for forkpoints.
Expand Down

0 comments on commit e848147

Please sign in to comment.